/-! # Erdős 94, regular `n`-gon variant: reusable infrastructure Paste-ready body for a `Main.lean` (it goes inside `namespace Bounty`, after the task header `import Mathlib`, `import FormalConjectures.ErdosProblems.«94»`, `import TaskSupport`). It passes the validator's static token policy: no attributes, instances, `set_option`, `#`-commands, notation, `sorry`, or references to the forbidden source theorem. * (a) `rngon_card`, `ngonPt_dist`, `rngon_dist_of_mem`: the regular `n`-gon has `n` vertices and the vertices `k`, `l` are `2 |sin (π (k - l) / n)|` apart. * (b) `rngon_sum_sq`: `∑ f(u)² = ngonValue n`, which is `n · C(n,2)` for odd `n` and `n · C(n,2) - n²/4` for even `n` (`ngonValue_odd`, `ngonValue_even`). Route: `sum_sq_mult_eq` (for any finite set, `∑ f(u)² = E/4` where `E` counts ordered pairs of ordered pairs at equal distance) and `rngon_pairEnergy` (`E = n²(2(n-1) - [n even])`). Explicit forms: `rngon_sum_sq_odd`, `rngon_sum_sq_even`. Per-chord ("equivalently") form: `rngon_mult_chord` (chord `2 sin (π j / n)`, `0 < j < n/2`, has multiplicity `n`), `rngon_mult_diameter` (even `n`: the diameter `2` has multiplicity `n/2`), `rngon_mult_le` (no distance of the regular `n`-gon has multiplicity above `n`). * (c) `sum_sq_le_of_mult_le` / `sum_sq_le_rngon`: if every distance class of an `n`-point set has at most `n` pairs, then `∑ f(u)² ≤ ngonValue n` = the regular `n`-gon value. * Reductions of the task statement: `target_iff_closed_form` (RHS replaced by `ngonValue n`), `target_of_large_class` (proof mode: only sets with a class of more than `n` pairs remain), `not_target_of_frequently` (counterexample mode: beat `ngonValue n` for infinitely many `n`). * Helpers for explicit point sets: `pairEnergy_eq_sq` (squared distances), `dist_vec2_sq`. All lemmas live in `Bounty.Erdos94Infra` and use only `propext`, `Classical.choice`, `Quot.sound`. -/ namespace Erdos94Infra open Finset /-! ### (a) The regular `n`-gon: vertices, chord lengths, cardinality -/ /-- The `k`-th vertex of `Erdos94.regularNGon n`, written exactly as in its definition. -/ noncomputable def ngonPt (n k : ℕ) : EuclideanSpace ℝ (Fin 2) := !₂[Real.cos (2 * Real.pi * k / n), Real.sin (2 * Real.pi * k / n)] theorem rngon_eq_image_range (n : ℕ) : Erdos94.regularNGon n = (range n).image (ngonPt n) := rfl theorem chord_sq (c d : ℝ) : (Real.cos (c + d) - Real.cos (c - d)) ^ 2 + (Real.sin (c + d) - Real.sin (c - d)) ^ 2 = (2 * Real.sin d) ^ 2 := by rw [Real.cos_add, Real.cos_sub, Real.sin_add, Real.sin_sub] linear_combination (4 * Real.sin d ^ 2) * Real.sin_sq_add_cos_sq c /-- Chord length: the vertices `k` and `l` of the regular `n`-gon are `2 |sin (π (k - l) / n)|` apart. -/ theorem ngonPt_dist (n k l : ℕ) : dist (ngonPt n k) (ngonPt n l) = 2 * |Real.sin (Real.pi * ((k : ℝ) - l) / n)| := by rw [EuclideanSpace.dist_eq] simp only [ngonPt, Fin.sum_univ_two, Real.dist_eq, sq_abs, WithLp.ofLp_toLp, Matrix.cons_val_zero, Matrix.cons_val_one] have hk : 2 * Real.pi * (k : ℝ) / n = Real.pi * ((k : ℝ) + l) / n + Real.pi * ((k : ℝ) - l) / n := by ring have hl : 2 * Real.pi * (l : ℝ) / n = Real.pi * ((k : ℝ) + l) / n - Real.pi * ((k : ℝ) - l) / n := by ring rw [hk, hl, chord_sq, Real.sqrt_sq_eq_abs, abs_mul, abs_two] theorem ngonPt_injOn (n : ℕ) : Set.InjOn (ngonPt n) (range n : Set ℕ) := by intro k hk l hl hkl simp only [coe_range, Set.mem_Iio] at hk hl have hn : (0 : ℝ) < n := by exact_mod_cast (show 0 < n by omega) have h0 : dist (ngonPt n k) (ngonPt n l) = 0 := by rw [hkl, dist_self] rw [ngonPt_dist] at h0 have hs : Real.sin (Real.pi * ((k : ℝ) - l) / n) = 0 := by have : |Real.sin (Real.pi * ((k : ℝ) - l) / n)| = 0 := by linarith [abs_nonneg (Real.sin (Real.pi * ((k : ℝ) - l) / n))] exact abs_eq_zero.mp this obtain ⟨m, hm⟩ := Real.sin_eq_zero_iff.mp hs have hm2 : (m : ℝ) * Real.pi * n = Real.pi * ((k : ℝ) - l) := (eq_div_iff hn.ne').mp hm have hm3 : Real.pi * ((m : ℝ) * n - ((k : ℝ) - l)) = 0 := by linear_combination hm2 have hm4 : (m : ℝ) * n = (k : ℝ) - l := by rcases mul_eq_zero.mp hm3 with h | h · exact absurd h Real.pi_ne_zero · linarith have hmz : m * (n : ℤ) = (k : ℤ) - l := by exact_mod_cast hm4 have hm0 : m = 0 := by rcases lt_trichotomy m 0 with h | h | h · have : m * (n : ℤ) ≤ -(n : ℤ) := by nlinarith omega · exact h · have : (n : ℤ) ≤ m * (n : ℤ) := by nlinarith omega subst hm0 omega /-- The regular `n`-gon has exactly `n` vertices (for every `n`, including `0`). -/ theorem rngon_card (n : ℕ) : (Erdos94.regularNGon n).card = n := by rw [rngon_eq_image_range, card_image_of_injOn (ngonPt_injOn n), card_range] /-- Every pair of vertices of the regular `n`-gon is `(ngonPt n k, ngonPt n l)` with `k, l < n`, at distance `2 |sin (π (k - l) / n)|`. -/ theorem rngon_dist_of_mem (n : ℕ) {x y : EuclideanSpace ℝ (Fin 2)} (hx : x ∈ Erdos94.regularNGon n) (hy : y ∈ Erdos94.regularNGon n) : ∃ k < n, ∃ l < n, x = ngonPt n k ∧ y = ngonPt n l ∧ dist x y = 2 * |Real.sin (Real.pi * ((k : ℝ) - l) / n)| := by rw [rngon_eq_image_range, mem_image] at hx hy obtain ⟨k, hk, rfl⟩ := hx obtain ⟨l, hl, rfl⟩ := hy exact ⟨k, mem_range.mp hk, l, mem_range.mp hl, rfl, rfl, ngonPt_dist n k l⟩ /-- The chord from vertex `0` to vertex `j ≤ n` has length `2 sin (π j / n)`. -/ theorem ngonPt_dist_zero (n j : ℕ) (hj : j ≤ n) : dist (ngonPt n j) (ngonPt n 0) = 2 * Real.sin (Real.pi * j / n) := by rw [ngonPt_dist, Nat.cast_zero, sub_zero, abs_of_nonneg] apply Real.sin_nonneg_of_nonneg_of_le_pi · positivity · rcases Nat.eq_zero_or_pos n with rfl | hn · simp [Real.pi_pos.le] · rw [div_le_iff₀ (by exact_mod_cast hn)] have : (j : ℝ) ≤ n := by exact_mod_cast hj nlinarith [Real.pi_pos] /-! ### Energy: `∑ f(u)²` for an arbitrary finite set -/ section Energy variable {X : Type*} [MetricSpace X] /-- Number of ordered pairs `(x, y)` of ordered pairs of distinct points with `dist x.1 x.2 = dist y.1 y.2`. -/ noncomputable def pairEnergy (P : Finset X) : ℕ := ∑ x ∈ P.offDiag, ∑ y ∈ P.offDiag, if dist x.1 x.2 = dist y.1 y.2 then 1 else 0 theorem sum_card_sq_eq_pairEnergy (P : Finset X) : ∑ u ∈ distanceSet P, (P.offDiag.filter (fun x => dist x.1 x.2 = u)).card ^ 2 = pairEnergy P := by unfold pairEnergy simp_rw [card_filter, sq, sum_mul_sum] rw [sum_comm] refine sum_congr rfl (fun x hx => ?_) rw [sum_comm] refine sum_congr rfl (fun y _ => ?_) have hxD : dist x.1 x.2 ∈ distanceSet P := mem_image_of_mem _ hx rw [sum_eq_single (dist x.1 x.2)] · simp [eq_comm] · intro u _ hu simp [Ne.symm hu] · intro h exact absurd hxD h /-- `distanceMultiplicity` is exactly half the number of ordered pairs at that distance. -/ theorem mult_cast (P : Finset X) (u : ℝ) : (distanceMultiplicity P u : ℝ) = ((P.offDiag.filter (fun x => dist x.1 x.2 = u)).card : ℝ) / 2 := by unfold distanceMultiplicity obtain ⟨r, hr⟩ := even_card_offDiag_filter_dist_eq P u rw [hr, show r + r = 2 * r by ring, Nat.mul_div_cancel_left _ (by norm_num)] push_cast ring /-- For any finite set, `∑ f(u)² = E / 4`. -/ theorem sum_sq_mult_eq (P : Finset X) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 = (pairEnergy P : ℝ) / 4 := by rw [← sum_card_sq_eq_pairEnergy, Nat.cast_sum, sum_div] refine sum_congr rfl (fun u _ => ?_) rw [mult_cast] push_cast ring theorem offDiag_image_of_injective {ι : Type*} [DecidableEq X] (s : Finset ι) {q : ι → X} (hq : Function.Injective q) : (s.image q).offDiag = s.offDiag.image (Prod.map q q) := by ext ⟨a, b⟩ simp only [mem_offDiag, mem_image, Prod.exists, Prod.map_apply, Prod.mk.injEq] constructor · rintro ⟨⟨i, hi, rfl⟩, ⟨j, hj, rfl⟩, hne⟩ exact ⟨i, j, ⟨hi, hj, fun h => hne (by rw [h])⟩, rfl, rfl⟩ · rintro ⟨i, j, ⟨hi, hj, hij⟩, rfl, rfl⟩ exact ⟨⟨i, hi, rfl⟩, ⟨j, hj, rfl⟩, fun h => hij (hq h)⟩ theorem pairEnergy_image {ι : Type*} [DecidableEq X] (s : Finset ι) {q : ι → X} (hq : Function.Injective q) : pairEnergy (s.image q) = ∑ x ∈ s.offDiag, ∑ y ∈ s.offDiag, if dist (q x.1) (q x.2) = dist (q y.1) (q y.2) then 1 else 0 := by unfold pairEnergy rw [offDiag_image_of_injective s hq, sum_image (fun x _ y _ h => (hq.prodMap hq) h)] refine sum_congr rfl (fun x _ => ?_) rw [sum_image (fun x _ y _ h => (hq.prodMap hq) h)] rfl theorem card_filter_dist_image {ι : Type*} [DecidableEq X] (s : Finset ι) {q : ι → X} (hq : Function.Injective q) (u : ℝ) : ((s.image q).offDiag.filter (fun x => dist x.1 x.2 = u)).card = ∑ x ∈ s.offDiag, if dist (q x.1) (q x.2) = u then 1 else 0 := by rw [card_filter, offDiag_image_of_injective s hq, sum_image (fun x _ y _ h => (hq.prodMap hq) h)] rfl /-- `pairEnergy` with squared distances (handy for explicit point sets: no square roots). -/ theorem pairEnergy_eq_sq (P : Finset X) : pairEnergy P = ∑ x ∈ P.offDiag, ∑ y ∈ P.offDiag, if dist x.1 x.2 ^ 2 = dist y.1 y.2 ^ 2 then 1 else 0 := by unfold pairEnergy refine sum_congr rfl (fun x _ => sum_congr rfl (fun y _ => ?_)) have key : dist x.1 x.2 = dist y.1 y.2 ↔ dist x.1 x.2 ^ 2 = dist y.1 y.2 ^ 2 := by rw [sq_eq_sq_iff_abs_eq_abs, abs_of_nonneg dist_nonneg, abs_of_nonneg dist_nonneg] by_cases h : dist x.1 x.2 = dist y.1 y.2 · rw [if_pos h, if_pos (key.mp h)] · rw [if_neg h, if_neg (fun h' => h (key.mpr h'))] end Energy /-- Squared distance of explicit points of the plane. -/ theorem dist_vec2_sq (a b c d : ℝ) : dist (!₂[a, b] : EuclideanSpace ℝ (Fin 2)) !₂[c, d] ^ 2 = (a - c) ^ 2 + (b - d) ^ 2 := by rw [EuclideanSpace.dist_eq, Real.sq_sqrt (by positivity)] simp [Fin.sum_univ_two, Real.dist_eq, sq_abs] /-! ### (b) The regular `n`-gon, indexed by `ZMod n` -/ section ZModIndex variable (n : ℕ) [NeZero n] theorem rngon_eq_image_zmod : Erdos94.regularNGon n = (univ : Finset (ZMod n)).image (fun z => ngonPt n z.val) := by rw [rngon_eq_image_range] ext x simp only [mem_image, mem_range, mem_univ, true_and] constructor · rintro ⟨k, hk, rfl⟩ exact ⟨(k : ZMod n), by rw [ZMod.val_natCast, Nat.mod_eq_of_lt hk]⟩ · rintro ⟨z, rfl⟩ exact ⟨z.val, ZMod.val_lt z, rfl⟩ theorem zq_injective : Function.Injective (fun z : ZMod n => ngonPt n z.val) := by intro z w h apply ZMod.val_injective exact ngonPt_injOn n (by simp [ZMod.val_lt z]) (by simp [ZMod.val_lt w]) h theorem sin_sq_eq_half (x : ℝ) : Real.sin x ^ 2 = (1 - Real.cos (2 * x)) / 2 := by rw [Real.cos_two_mul] linarith [Real.sin_sq_add_cos_sq x] theorem two_pi_div_eq_iff (a b k : ℤ) : 2 * (Real.pi * b / n) = 2 * k * Real.pi + 2 * (Real.pi * a / n) ↔ b = k * n + a := by have hn : (n : ℝ) ≠ 0 := by exact_mod_cast NeZero.ne n have hc : (2 * Real.pi / n : ℝ) ≠ 0 := div_ne_zero (by positivity) hn have key : 2 * (Real.pi * b / n) - (2 * k * Real.pi + 2 * (Real.pi * a / n)) = (2 * Real.pi / n) * ((b : ℝ) - (k * n + a)) := by field_simp rw [← sub_eq_zero, key, mul_eq_zero, or_iff_right hc, sub_eq_zero] constructor · intro h exact_mod_cast h · intro h rw [h] push_cast ring theorem two_pi_div_eq_iff' (a b k : ℤ) : 2 * (Real.pi * b / n) = 2 * k * Real.pi - 2 * (Real.pi * a / n) ↔ b = k * n - a := by have h := two_pi_div_eq_iff n (-a) b k push_cast at h rw [show (2 * k * Real.pi - 2 * (Real.pi * a / n) : ℝ) = 2 * k * Real.pi + 2 * (Real.pi * -(a : ℝ) / n) by ring, h] constructor <;> intro h' <;> linarith /-- The key arithmetic characterisation of equal chords. -/ theorem abs_sin_eq_iff (a b : ℤ) : |Real.sin (Real.pi * a / n)| = |Real.sin (Real.pi * b / n)| ↔ ((a : ZMod n) = b ∨ (a : ZMod n) = -b) := by rw [← sq_eq_sq_iff_abs_eq_abs, sin_sq_eq_half, sin_sq_eq_half] have step : (1 - Real.cos (2 * (Real.pi * a / n))) / 2 = (1 - Real.cos (2 * (Real.pi * b / n))) / 2 ↔ Real.cos (2 * (Real.pi * a / n)) = Real.cos (2 * (Real.pi * b / n)) := by constructor <;> intro h <;> linarith rw [step, Real.cos_eq_cos_iff] have hneg : ((a : ZMod n) = -b) ↔ ((-b : ℤ) : ZMod n) = a := by push_cast exact eq_comm rw [hneg, ZMod.intCast_eq_intCast_iff_dvd_sub, ZMod.intCast_eq_intCast_iff_dvd_sub] constructor · rintro ⟨k, hk | hk⟩ · left exact ⟨k, by rw [(two_pi_div_eq_iff n a b k).mp hk]; ring⟩ · right exact ⟨k, by rw [(two_pi_div_eq_iff' n a b k).mp hk]; ring⟩ · rintro (⟨k, hk⟩ | ⟨k, hk⟩) · exact ⟨k, Or.inl ((two_pi_div_eq_iff n a b k).mpr (by linarith))⟩ · exact ⟨k, Or.inr ((two_pi_div_eq_iff' n a b k).mpr (by linarith))⟩ theorem zq_dist (z w : ZMod n) : dist (ngonPt n z.val) (ngonPt n w.val) = 2 * |Real.sin (Real.pi * ((((z.val : ℤ) - w.val : ℤ)) : ℝ) / n)| := by rw [ngonPt_dist] push_cast ring_nf theorem zq_dist_eq_iff (z w z' w' : ZMod n) : dist (ngonPt n z.val) (ngonPt n w.val) = dist (ngonPt n z'.val) (ngonPt n w'.val) ↔ (z - w = z' - w' ∨ z - w = -(z' - w')) := by rw [zq_dist, zq_dist] have h2 : ∀ x y : ℝ, 2 * |x| = 2 * |y| ↔ |x| = |y| := fun x y => by constructor <;> intro h <;> linarith rw [h2, abs_sin_eq_iff] have hz : ∀ z w : ZMod n, ((((z.val : ℤ) - w.val : ℤ)) : ZMod n) = z - w := by intro z w push_cast simp rw [hz, hz] /-- Summing a function of the difference over ordered pairs of distinct residues. -/ theorem sum_offDiag_sub (F : ZMod n → ℕ) : ∑ x ∈ (univ : Finset (ZMod n)).offDiag, F (x.1 - x.2) = n * ∑ d ∈ (univ : Finset (ZMod n)).erase 0, F d := by have h1 : (univ : Finset (ZMod n)).offDiag = (univ ×ˢ univ).filter (fun x : ZMod n × ZMod n => x.1 ≠ x.2) := by ext x simp rw [h1, sum_filter, univ_product_univ, Fintype.sum_prod_type] have h2 : ∀ a : ZMod n, (∑ b : ZMod n, if a ≠ b then F (a - b) else 0) = ∑ d ∈ (univ : Finset (ZMod n)).erase 0, F d := by intro a rw [← filter_ne' univ 0, sum_filter] exact Fintype.sum_equiv (Equiv.subLeft a) _ _ (fun b => by simp [sub_eq_zero]) rw [sum_congr rfl (fun a _ => h2 a), sum_const, card_univ, ZMod.card, smul_eq_mul] theorem card_neg_eq_self : ((univ.erase (0 : ZMod n)).filter (fun d => d = -d)).card = if Even n then 1 else 0 := by have key : ∀ d : ZMod n, (d ∈ univ.erase 0 ∧ d = -d) ↔ 2 * d.val = n := by intro d rw [mem_erase, eq_comm (a := d) (b := -d), ZMod.neg_eq_self_iff] constructor · rintro ⟨⟨hd, -⟩, h | h⟩ · exact absurd h hd · exact h · intro h refine ⟨⟨?_, mem_univ _⟩, Or.inr h⟩ rintro rfl rw [ZMod.val_zero] at h exact NeZero.ne n (by omega) split_ifs with he · obtain ⟨m, hm⟩ := he have hm0 : 0 < m := by have := NeZero.ne n omega have hmv : (m : ZMod n).val = m := by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] rw [card_eq_one] refine ⟨(m : ZMod n), ?_⟩ ext d rw [mem_filter, key d, mem_singleton] constructor · intro h apply ZMod.val_injective rw [hmv] omega · rintro rfl rw [hmv] omega · rw [card_eq_zero, filter_eq_empty_iff] intro d hd hdd have := (key d).mp ⟨hd, hdd⟩ exact he ⟨d.val, by omega⟩ theorem sum_pair_count : (∑ d ∈ (univ : Finset (ZMod n)).erase 0, if d = -d then (1 : ℕ) else 2) = 2 * (n - 1) - if Even n then 1 else 0 := by rw [sum_ite, sum_const, sum_const, smul_eq_mul, smul_eq_mul, mul_one, card_neg_eq_self] have htot := card_filter_add_card_filter_not (s := (univ : Finset (ZMod n)).erase 0) (fun d => d = -d) rw [card_erase_of_mem (mem_univ _), card_univ, ZMod.card, card_neg_eq_self] at htot split_ifs at htot ⊢ <;> omega theorem zmod_pair_count : (∑ x ∈ (univ : Finset (ZMod n)).offDiag, ∑ y ∈ (univ : Finset (ZMod n)).offDiag, if x.1 - x.2 = y.1 - y.2 ∨ x.1 - x.2 = -(y.1 - y.2) then (1 : ℕ) else 0) = n * n * (2 * (n - 1) - if Even n then 1 else 0) := by have inner : ∀ d : ZMod n, (∑ y ∈ (univ : Finset (ZMod n)).offDiag, if d = y.1 - y.2 ∨ d = -(y.1 - y.2) then (1 : ℕ) else 0) = n * ∑ e ∈ (univ : Finset (ZMod n)).erase 0, if d = e ∨ d = -e then (1 : ℕ) else 0 := fun d => sum_offDiag_sub n (fun e => if d = e ∨ d = -e then (1 : ℕ) else 0) rw [sum_congr rfl (fun x _ => inner (x.1 - x.2))] rw [sum_offDiag_sub n (fun d => n * ∑ e ∈ (univ : Finset (ZMod n)).erase 0, if d = e ∨ d = -e then (1 : ℕ) else 0)] have pair : ∀ d ∈ (univ : Finset (ZMod n)).erase 0, n * (∑ e ∈ (univ : Finset (ZMod n)).erase 0, if d = e ∨ d = -e then (1 : ℕ) else 0) = n * (if d = -d then 1 else 2) := by intro d hd have hd0 : d ≠ 0 := (mem_erase.mp hd).1 rw [sum_boole] have hset : ((univ : Finset (ZMod n)).erase 0).filter (fun e => d = e ∨ d = -e) = {d, -d} := by ext e simp only [mem_filter, mem_erase, mem_univ, and_true, mem_insert, mem_singleton] constructor · rintro ⟨-, h | h⟩ · exact Or.inl h.symm · right rw [h, neg_neg] · rintro (rfl | rfl) · exact ⟨hd0, Or.inl rfl⟩ · exact ⟨neg_ne_zero.mpr hd0, Or.inr (neg_neg _).symm⟩ rw [hset] split_ifs with h · rw [← h, pair_eq_singleton, card_singleton] rfl · rw [card_pair h] rfl rw [sum_congr rfl pair, ← mul_sum, sum_pair_count] ring theorem rngon_pairEnergy : pairEnergy (Erdos94.regularNGon n) = n * n * (2 * (n - 1) - if Even n then 1 else 0) := by rw [rngon_eq_image_zmod, pairEnergy_image _ (zq_injective n), ← zmod_pair_count] refine sum_congr rfl (fun x _ => sum_congr rfl (fun y _ => ?_)) by_cases h : x.1 - x.2 = y.1 - y.2 ∨ x.1 - x.2 = -(y.1 - y.2) · rw [if_pos ((zq_dist_eq_iff n x.1 x.2 y.1 y.2).mpr h), if_pos h] · rw [if_neg (fun h' => h ((zq_dist_eq_iff n x.1 x.2 y.1 y.2).mp h')), if_neg h] theorem card_filter_pm (d : ZMod n) (hd : d ≠ 0) : (((univ : Finset (ZMod n)).erase 0).filter (fun e => e = d ∨ e = -d)).card = if d = -d then 1 else 2 := by have hset : ((univ : Finset (ZMod n)).erase 0).filter (fun e => e = d ∨ e = -d) = {d, -d} := by ext e simp only [mem_filter, mem_erase, mem_univ, and_true, mem_insert, mem_singleton] constructor · rintro ⟨-, h⟩ exact h · rintro (rfl | rfl) · exact ⟨hd, Or.inl rfl⟩ · exact ⟨neg_ne_zero.mpr hd, Or.inr rfl⟩ rw [hset] split_ifs with h · rw [← h, pair_eq_singleton, card_singleton] · rw [card_pair h] /-- Ordered pairs of distinct vertices at the chord of residue `d ≠ 0`: `n` or `2n` of them. -/ theorem rngon_card_filter_residue (d : ZMod n) (hd : d ≠ 0) : ((Erdos94.regularNGon n).offDiag.filter (fun x => dist x.1 x.2 = dist (ngonPt n d.val) (ngonPt n 0))).card = n * (if d = -d then 1 else 2) := by rw [rngon_eq_image_zmod, card_filter_dist_image _ (zq_injective n)] have h0 : ngonPt n 0 = ngonPt n (0 : ZMod n).val := by rw [ZMod.val_zero] rw [h0] have hterm : ∀ x ∈ (univ : Finset (ZMod n)).offDiag, (if dist (ngonPt n x.1.val) (ngonPt n x.2.val) = dist (ngonPt n d.val) (ngonPt n (0 : ZMod n).val) then (1 : ℕ) else 0) = if x.1 - x.2 = d ∨ x.1 - x.2 = -d then (1 : ℕ) else 0 := by intro x _ have key := zq_dist_eq_iff n x.1 x.2 d 0 rw [sub_zero] at key by_cases h : x.1 - x.2 = d ∨ x.1 - x.2 = -d · rw [if_pos (key.mpr h), if_pos h] · rw [if_neg (fun h' => h (key.mp h')), if_neg h] rw [sum_congr rfl hterm, sum_offDiag_sub n (fun e => if e = d ∨ e = -d then (1 : ℕ) else 0), sum_boole, card_filter_pm n d hd, Nat.cast_id] /-- Multiplicity of the chord of residue `d ≠ 0`: `n`, or `n / 2` for the diameter `d = -d`. -/ theorem rngon_mult_residue (d : ZMod n) (hd : d ≠ 0) : distanceMultiplicity (Erdos94.regularNGon n) (dist (ngonPt n d.val) (ngonPt n 0)) = if d = -d then n / 2 else n := by unfold distanceMultiplicity rw [rngon_card_filter_residue n d hd] split_ifs <;> omega end ZModIndex /-- Each chord `2 sin (π j / n)` with `0 < j < n / 2` has multiplicity exactly `n`. -/ theorem rngon_mult_chord (n j : ℕ) (hj : 0 < j) (hjn : 2 * j < n) : distanceMultiplicity (Erdos94.regularNGon n) (2 * Real.sin (Real.pi * j / n)) = n := by have : NeZero n := ⟨by omega⟩ have hjv : (j : ZMod n).val = j := by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] have hd : (j : ZMod n) ≠ 0 := by intro h have := congrArg ZMod.val h rw [hjv, ZMod.val_zero] at this omega have hnd : ¬ ((j : ZMod n) = -(j : ZMod n)) := by intro h rcases (ZMod.neg_eq_self_iff (j : ZMod n)).mp h.symm with h' | h' · exact hd h' · rw [hjv] at h' omega rw [← ngonPt_dist_zero n j (by omega), ← hjv, rngon_mult_residue n _ hd, if_neg hnd] /-- For even `n > 0` the diameter `2` has multiplicity exactly `n / 2`. -/ theorem rngon_mult_diameter (n : ℕ) (he : Even n) (hn : 0 < n) : distanceMultiplicity (Erdos94.regularNGon n) 2 = n / 2 := by obtain ⟨m, hm⟩ := he have : NeZero n := ⟨by omega⟩ have hmv : (m : ZMod n).val = m := by rw [ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] have hd : (m : ZMod n) ≠ 0 := by intro h have := congrArg ZMod.val h rw [hmv, ZMod.val_zero] at this omega have hnd : (m : ZMod n) = -(m : ZMod n) := ((ZMod.neg_eq_self_iff (m : ZMod n)).mpr (Or.inr (by rw [hmv]; omega))).symm have hm0 : (0 : ℝ) < m := by exact_mod_cast (show 0 < m by omega) have h2 : (2 : ℝ) = dist (ngonPt n (m : ZMod n).val) (ngonPt n 0) := by rw [hmv, ngonPt_dist_zero n m (by omega)] have hpi : Real.pi * (m : ℝ) / n = Real.pi / 2 := by rw [hm, Nat.cast_add, div_eq_div_iff (ne_of_gt (by linarith)) (by norm_num)] ring rw [hpi, Real.sin_pi_div_two] ring rw [h2, rngon_mult_residue n _ hd, if_pos hnd] /-- No distance of the regular `n`-gon has multiplicity above `n`. -/ theorem rngon_mult_le (n : ℕ) (u : ℝ) : distanceMultiplicity (Erdos94.regularNGon n) u ≤ n := by rcases Nat.eq_zero_or_pos n with rfl | hn · simp [distanceMultiplicity, Erdos94.regularNGon] have : NeZero n := ⟨hn.ne'⟩ by_cases hne : ((Erdos94.regularNGon n).offDiag.filter (fun x => dist x.1 x.2 = u)).Nonempty · obtain ⟨x, hx⟩ := hne rw [mem_filter, mem_offDiag] at hx obtain ⟨⟨hx1, hx2, hx12⟩, hxu⟩ := hx rw [rngon_eq_image_zmod] at hx1 hx2 simp only [mem_image, mem_univ, true_and] at hx1 hx2 obtain ⟨z, hz⟩ := hx1 obtain ⟨w, hw⟩ := hx2 have hzw : z - w ≠ 0 := by intro h apply hx12 rw [← hz, ← hw, sub_eq_zero.mp h] have hu : u = dist (ngonPt n (z - w).val) (ngonPt n 0) := by rw [← hxu, ← hz, ← hw] have key := (zq_dist_eq_iff n z w (z - w) 0).mpr (Or.inl (by rw [sub_zero])) rw [key, ZMod.val_zero] rw [hu, rngon_mult_residue n _ hzw] split_ifs <;> omega · rw [not_nonempty_iff_eq_empty] at hne unfold distanceMultiplicity rw [hne, card_empty] omega /-- The right-hand side in closed form: `n · C(n,2)` for odd `n`, `n · C(n,2) - n²/4` for even `n`. -/ noncomputable def ngonValue (n : ℕ) : ℝ := if Even n then (n : ℝ) * (n.choose 2 : ℝ) - (n : ℝ) ^ 2 / 4 else (n : ℝ) * (n.choose 2 : ℝ) theorem ngonValue_even {n : ℕ} (h : Even n) : ngonValue n = (n : ℝ) * (n.choose 2 : ℝ) - (n : ℝ) ^ 2 / 4 := if_pos h theorem ngonValue_odd {n : ℕ} (h : ¬ Even n) : ngonValue n = (n : ℝ) * (n.choose 2 : ℝ) := if_neg h /-- (b) The right-hand side of the conjecture: the regular `n`-gon's `∑ f(u)²` in closed form. -/ theorem rngon_sum_sq (n : ℕ) : ∑ u ∈ distanceSet (Erdos94.regularNGon n), (distanceMultiplicity (Erdos94.regularNGon n) u : ℝ) ^ 2 = ngonValue n := by rcases Nat.eq_zero_or_pos n with rfl | hn · simp [Erdos94.regularNGon, distanceSet, ngonValue] · have : NeZero n := ⟨hn.ne'⟩ rw [sum_sq_mult_eq, rngon_pairEnergy, ngonValue, Nat.cast_choose_two] split_ifs with he · have h1 : 1 ≤ 2 * (n - 1) := by obtain ⟨m, hm⟩ := he omega rw [Nat.cast_mul, Nat.cast_mul, Nat.cast_sub h1, Nat.cast_mul, Nat.cast_sub (by omega : 1 ≤ n)] push_cast ring · rw [Nat.sub_zero, Nat.cast_mul, Nat.cast_mul, Nat.cast_mul, Nat.cast_sub (by omega : 1 ≤ n)] push_cast ring theorem rngon_sum_sq_odd (n : ℕ) (h : ¬ Even n) : ∑ u ∈ distanceSet (Erdos94.regularNGon n), (distanceMultiplicity (Erdos94.regularNGon n) u : ℝ) ^ 2 = (n : ℝ) * (n.choose 2 : ℝ) := by rw [rngon_sum_sq, ngonValue_odd h] theorem rngon_sum_sq_even (n : ℕ) (h : Even n) : ∑ u ∈ distanceSet (Erdos94.regularNGon n), (distanceMultiplicity (Erdos94.regularNGon n) u : ℝ) ^ 2 = (n : ℝ) * (n.choose 2 : ℝ) - (n : ℝ) ^ 2 / 4 := by rw [rngon_sum_sq, ngonValue_even h] /-! ### (c) Majorization: classes of size `≤ n` force `∑ f(u)² ≤ ngonValue n` -/ theorem pair_mod_bound (n x r : ℕ) (hx : x ≤ n) (hr : r ≤ n) : (x + r) % n * (n - (x + r) % n) ≤ x * (n - x) + r * (n - r) := by rcases Nat.eq_zero_or_pos n with rfl | hn · simp rcases lt_or_ge (x + r) n with h | h · rw [Nat.mod_eq_of_lt h] have e1 : ((n - (x + r) : ℕ) : ℤ) = n - (x + r) := by push_cast [h.le]; ring have e2 : ((n - x : ℕ) : ℤ) = n - x := by push_cast [hx]; ring have e3 : ((n - r : ℕ) : ℤ) = n - r := by push_cast [hr]; ring zify rw [e1, e2, e3] nlinarith [mul_nonneg (Int.natCast_nonneg x) (Int.natCast_nonneg r)] · rcases lt_or_ge (x + r) (2 * n) with h2 | h2 · have hm : (x + r) % n = x + r - n := by rw [Nat.mod_eq_sub_mod h, Nat.mod_eq_of_lt (by omega)] rw [hm] have e0 : ((x + r - n : ℕ) : ℤ) = x + r - n := by push_cast [h]; ring have e1 : ((n - (x + r - n) : ℕ) : ℤ) = 2 * n - (x + r) := by have : x + r - n ≤ n := by omega push_cast [this, h] ring have e2 : ((n - x : ℕ) : ℤ) = n - x := by push_cast [hx]; ring have e3 : ((n - r : ℕ) : ℤ) = n - r := by push_cast [hr]; ring zify rw [e0, e1, e2, e3] have hx' : (x : ℤ) ≤ n := by exact_mod_cast hx have hr' : (r : ℤ) ≤ n := by exact_mod_cast hr nlinarith [mul_nonneg (sub_nonneg.mpr hx') (sub_nonneg.mpr hr')] · have hxr : x + r = 2 * n := by omega rw [hxr, Nat.mul_mod_left] simp theorem sum_mod_bound {ι : Type*} (S : Finset ι) (f : ι → ℕ) (n : ℕ) (hn : 0 < n) (hf : ∀ i ∈ S, f i ≤ n) : (∑ i ∈ S, f i) % n * (n - (∑ i ∈ S, f i) % n) ≤ ∑ i ∈ S, f i * (n - f i) := by classical induction S using Finset.induction_on with | empty => simp | insert a s ha ih => rw [sum_insert ha, sum_insert ha] have hfa := hf a (mem_insert_self a s) have ih' := ih (fun i hi => hf i (mem_insert_of_mem hi)) have hr : (∑ i ∈ s, f i) % n ≤ n := (Nat.mod_lt _ hn).le calc (f a + ∑ i ∈ s, f i) % n * (n - (f a + ∑ i ∈ s, f i) % n) = (f a + (∑ i ∈ s, f i) % n) % n * (n - (f a + (∑ i ∈ s, f i) % n) % n) := by rw [Nat.add_mod_mod] _ ≤ f a * (n - f a) + (∑ i ∈ s, f i) % n * (n - (∑ i ∈ s, f i) % n) := pair_mod_bound n _ _ hfa hr _ ≤ f a * (n - f a) + ∑ i ∈ s, f i * (n - f i) := Nat.add_le_add_left ih' _ theorem choose_two_mod_of_even {n : ℕ} (he : Even n) : n.choose 2 % n = n / 2 := by obtain ⟨m, rfl⟩ := he rcases Nat.eq_zero_or_pos m with rfl | hm · simp obtain ⟨k, rfl⟩ : ∃ k, m = k + 1 := ⟨m - 1, by omega⟩ have hC : (k + 1 + (k + 1)).choose 2 = (k + 1) + (k + 1 + (k + 1)) * k := by rw [Nat.choose_two_right] have : k + 1 + (k + 1) - 1 = 2 * k + 1 := by omega rw [this] have : (k + 1 + (k + 1)) * (2 * k + 1) = 2 * ((k + 1) + (k + 1 + (k + 1)) * k) := by ring rw [this, Nat.mul_div_cancel_left _ (by norm_num)] rw [hC, Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt (by omega)] omega /-- (c) Majorization lemma (any metric space, any `n`): if every realised distance class of the `n`-point set `P` has at most `n` pairs, then `∑ f(u)² ≤ ngonValue n`. -/ theorem sum_sq_le_of_mult_le {X : Type*} [MetricSpace X] (P : Finset X) (n : ℕ) (hcard : P.card = n) (hmult : ∀ u ∈ distanceSet P, distanceMultiplicity P u ≤ n) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ ngonValue n := by have hsum : ∑ u ∈ distanceSet P, distanceMultiplicity P u = n.choose 2 := by rw [← hcard] exact sum_distanceMultiplicity P have hid : ∑ u ∈ distanceSet P, distanceMultiplicity P u ^ 2 + ∑ u ∈ distanceSet P, distanceMultiplicity P u * (n - distanceMultiplicity P u) = n * n.choose 2 := by rw [← sum_add_distrib, ← hsum, mul_sum] refine sum_congr rfl (fun u hu => ?_) have hle := hmult u hu have e : ((n - distanceMultiplicity P u : ℕ) : ℤ) = n - distanceMultiplicity P u := by push_cast [hle] ring zify rw [e] ring have hcast : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 = ((∑ u ∈ distanceSet P, distanceMultiplicity P u ^ 2 : ℕ) : ℝ) := by push_cast rfl rw [hcast, ngonValue] split_ifs with he · rcases Nat.eq_zero_or_pos n with h0 | hn · subst h0 have : ∑ u ∈ distanceSet P, distanceMultiplicity P u ^ 2 = 0 := by simpa using hid rw [this] simp have hb := sum_mod_bound (distanceSet P) (distanceMultiplicity P) n hn hmult rw [hsum, choose_two_mod_of_even he] at hb obtain ⟨m, hm⟩ := he have hh : n / 2 = m := by omega have hh' : n - m = m := by omega rw [hh, hh'] at hb have h1 : ∑ u ∈ distanceSet P, distanceMultiplicity P u ^ 2 + m * m ≤ n * n.choose 2 := by omega have h2 : ((∑ u ∈ distanceSet P, distanceMultiplicity P u ^ 2 : ℕ) : ℝ) + (m : ℝ) * m ≤ (n : ℝ) * (n.choose 2 : ℝ) := by exact_mod_cast h1 have h3 : (n : ℝ) = m + m := by exact_mod_cast hm have h4 : (n : ℝ) ^ 2 / 4 = (m : ℝ) * m := by rw [h3] ring rw [h4] linarith · have h1 : ∑ u ∈ distanceSet P, distanceMultiplicity P u ^ 2 ≤ n * n.choose 2 := by omega exact_mod_cast h1 /-- (c), stated against the conjecture's right-hand side: in the plane, if every distance has multiplicity at most `n = P.card`, then `P` does no better than the regular `n`-gon. -/ theorem sum_sq_le_rngon (P : Finset (EuclideanSpace ℝ (Fin 2))) (n : ℕ) (hcard : P.card = n) (hmult : ∀ u, distanceMultiplicity P u ≤ n) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ ∑ u ∈ distanceSet (Erdos94.regularNGon n), (distanceMultiplicity (Erdos94.regularNGon n) u : ℝ) ^ 2 := by rw [rngon_sum_sq] exact sum_sq_le_of_mult_le P n hcard (fun u _ => hmult u) /-! ### Reductions of the task statement (usable in either mode) -/ /-- The conjecture with its right-hand side in closed form. -/ theorem target_iff_closed_form : (fcTypeOfName% "Erdos94.erdos_94.variants.regular_ngon") ↔ ∀ᶠ n : ℕ in Filter.atTop, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ ngonValue n := by simp only [rngon_sum_sq] /-- Proof mode: by (c) it suffices to handle convex sets having a distance class with more than `n` pairs. -/ theorem target_of_large_class (N : ℕ) (h : ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → (∃ u ∈ distanceSet P, n < distanceMultiplicity P u) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ ngonValue n) : fcTypeOfName% "Erdos94.erdos_94.variants.regular_ngon" := by rw [target_iff_closed_form, Filter.eventually_atTop] refine ⟨N, fun n hn P hcard hconv => ?_⟩ by_cases hbig : ∃ u ∈ distanceSet P, n < distanceMultiplicity P u · exact h n hn P hcard hconv hbig · simp only [not_exists, not_and, not_lt] at hbig exact sum_sq_le_of_mult_le P n hcard hbig /-- Counterexample mode: infinitely many `n` with a convex `n`-set beating `ngonValue n`. -/ theorem not_target_of_frequently (h : ∀ N : ℕ, ∃ n ≥ N, ∃ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n ∧ EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) ∧ ngonValue n < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2) : ¬ (fcTypeOfName% "Erdos94.erdos_94.variants.regular_ngon") := by rw [target_iff_closed_form, Filter.eventually_atTop] rintro ⟨N, hN⟩ obtain ⟨n, hn, P, hcard, hconv, hlt⟩ := h N exact absurd (hN n hn P hcard hconv) (not_le.mpr hlt) end Erdos94Infra /-! THEOREM-A Lean pieces (needs the Erdos94Infra body before it): (G1), (T), (G5), Lemma C1, Lemma C1′, isometry module in ℂ, (I1), (I3), Lemma B, cross-pair lemma (12.3), two good axes (12.2), cross-pair summation (12.1), bisector reflections on a circle, energy bound (12.4), R1 (units bridge), R2 (roots of unity), R3 (chord criterion), R4 (centre in hull), (G2), concyclic theorem (4.2). -/ /-! THEOREM-A scratch: (G1) no three collinear points in a convex-independent set, and (T) a nonzero translation maps at most two points of a convex-independent set into it. Body is written to sit inside `namespace Bounty` of a Main.lean (static-policy clean). -/ namespace Erdos94ThmA open EuclideanGeometry theorem mem_diff_singleton_of_ne {S : Set (EuclideanSpace ℝ (Fin 2))} {a b : EuclideanSpace ℝ (Fin 2)} (ha : a ∈ S) (hab : a ≠ b) : a ∈ S \ {b} := ⟨ha, fun h => hab (Set.mem_singleton_iff.mp h)⟩ /-- (G1) Three distinct points of a convex-independent set are never collinear. -/ theorem convexIndep_not_collinear {S : Set (EuclideanSpace ℝ (Fin 2))} (hS : ConvexIndep S) {a b c : EuclideanSpace ℝ (Fin 2)} (ha : a ∈ S) (hb : b ∈ S) (hc : c ∈ S) (hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (hcol : Collinear ℝ ({a, b, c} : Set (EuclideanSpace ℝ (Fin 2)))) : False := by rcases hcol.wbtw_or_wbtw_or_wbtw with h | h | h · exact hS b hb (segment_subset_convexHull (mem_diff_singleton_of_ne ha hab) (mem_diff_singleton_of_ne hc hbc.symm) (mem_segment_iff_wbtw.mpr h)) · exact hS c hc (segment_subset_convexHull (mem_diff_singleton_of_ne hb hbc) (mem_diff_singleton_of_ne ha hac) (mem_segment_iff_wbtw.mpr h)) · exact hS a ha (segment_subset_convexHull (mem_diff_singleton_of_ne hc hac.symm) (mem_diff_singleton_of_ne hb hab.symm) (mem_segment_iff_wbtw.mpr h)) /-! ### The determinant of two plane vectors -/ /-- `cross u v = det(u, v)`. -/ noncomputable def cross (u v : EuclideanSpace ℝ (Fin 2)) : ℝ := u 0 * v 1 - u 1 * v 0 theorem ext2 {u v : EuclideanSpace ℝ (Fin 2)} (h0 : u 0 = v 0) (h1 : u 1 = v 1) : u = v := by ext i fin_cases i · exact h0 · exact h1 theorem cross_add_right (u v w : EuclideanSpace ℝ (Fin 2)) : cross u (v + w) = cross u v + cross u w := by simp only [cross, PiLp.add_apply] ring theorem cross_sub_right (u v w : EuclideanSpace ℝ (Fin 2)) : cross u (v - w) = cross u v - cross u w := by simp only [cross, PiLp.sub_apply] ring theorem cross_self (u : EuclideanSpace ℝ (Fin 2)) : cross u u = 0 := by simp only [cross] ring theorem cross_add_self (u p : EuclideanSpace ℝ (Fin 2)) : cross u (p + u) = cross u p := by rw [cross_add_right, cross_self, add_zero] /-- Cramer's rule, multiplied out. -/ theorem decomp_mul (t w v : EuclideanSpace ℝ (Fin 2)) : cross t w • v = cross t v • w + cross v w • t := by apply ext2 <;> simp only [PiLp.add_apply, PiLp.smul_apply, smul_eq_mul, cross] <;> ring theorem decomp {t w : EuclideanSpace ℝ (Fin 2)} (v : EuclideanSpace ℝ (Fin 2)) (h : cross t w ≠ 0) : v = (cross t v / cross t w) • w + (cross v w / cross t w) • t := by calc v = (cross t w)⁻¹ • (cross t w • v) := by rw [smul_smul, inv_mul_cancel₀ h, one_smul] _ = (cross t w)⁻¹ • (cross t v • w + cross v w • t) := by rw [decomp_mul] _ = (cross t v / cross t w) • w + (cross v w / cross t w) • t := by rw [smul_add, smul_smul, smul_smul, div_eq_inv_mul, div_eq_inv_mul] theorem smul_eq_smul_of_cross (t v : EuclideanSpace ℝ (Fin 2)) (h : cross t v = 0) : t 0 • v = v 0 • t ∧ t 1 • v = v 1 • t := by simp only [cross] at h constructor <;> apply ext2 <;> simp only [PiLp.smul_apply, smul_eq_mul] <;> linarith theorem eq_smul_of_cross_eq_zero {t v : EuclideanSpace ℝ (Fin 2)} (ht : t ≠ 0) (h : cross t v = 0) : ∃ c : ℝ, v = c • t := by obtain ⟨h0, h1⟩ := smul_eq_smul_of_cross t v h by_cases ht0 : t 0 = 0 · have ht1 : t 1 ≠ 0 := by intro ht1 apply ht apply ext2 · rw [ht0] rfl · rw [ht1] rfl refine ⟨v 1 / t 1, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, ← h1, smul_smul, inv_mul_cancel₀ ht1, one_smul] · refine ⟨v 0 / t 0, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, ← h0, smul_smul, inv_mul_cancel₀ ht0, one_smul] theorem self_ne_add_vec {p t : EuclideanSpace ℝ (Fin 2)} (ht : t ≠ 0) : p ≠ p + t := by intro h apply ht have h2 : p + t = p + 0 := by rw [add_zero]; exact h.symm exact add_left_cancel h2 theorem mem_diff_of_cross_ne {S : Set (EuclideanSpace ℝ (Fin 2))} {t p q : EuclideanSpace ℝ (Fin 2)} (hp : p ∈ S) (h : cross t p ≠ cross t q) : p ∈ S \ {q} := mem_diff_singleton_of_ne hp (fun hpq => h (by rw [hpq])) /-! ### (T), parallel case: two of the points differ by a multiple of `t` -/ theorem parallel_case {S : Set (EuclideanSpace ℝ (Fin 2))} (hS : ConvexIndep S) {t x y : EuclideanSpace ℝ (Fin 2)} (ht : t ≠ 0) (hx : x ∈ S) (hy : y ∈ S) (hxt : x + t ∈ S) (hyt : y + t ∈ S) (hxy : x ≠ y) (hc : cross t (y - x) = 0) : False := by obtain ⟨c, hcv⟩ := eq_smul_of_cross_eq_zero ht hc have hy' : y = x + c • t := by rw [← hcv]; abel by_cases hc1 : c = 1 · rw [hc1, one_smul] at hy' refine convexIndep_not_collinear hS hx hy hyt hxy ?_ (self_ne_add_vec ht) ?_ · intro h apply ht have h2' : x = x + t + t := by rw [hy'] at h; exact h have h2 : x + (t + t) = x + 0 := by rw [add_zero, ← add_assoc]; exact h2'.symm have h3 : (2 : ℝ) • t = 0 := by rw [two_smul]; exact add_left_cancel h2 exact (smul_eq_zero.mp h3).resolve_left two_ne_zero · rw [collinear_iff_of_mem (Set.mem_insert x _)] refine ⟨t, fun p hp => ?_⟩ simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hp rcases hp with h | h | h · exact ⟨0, by rw [h, zero_smul, vadd_eq_add, zero_add]⟩ · exact ⟨1, by rw [h, hy', one_smul, vadd_eq_add, add_comm]⟩ · exact ⟨2, by rw [h, hy', two_smul, vadd_eq_add]; abel⟩ · refine convexIndep_not_collinear hS hx hy hxt hxy (self_ne_add_vec ht) ?_ ?_ · intro h apply hc1 have h2 : c • t = t := by have h3 : x + c • t = x + t := by rw [← hy']; exact h exact add_left_cancel h3 have h4 : (c - 1) • t = 0 := by rw [sub_smul, one_smul, h2, sub_self] rcases smul_eq_zero.mp h4 with h5 | h5 · linarith · exact absurd h5 ht · rw [collinear_iff_of_mem (Set.mem_insert x _)] refine ⟨t, fun p hp => ?_⟩ simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hp rcases hp with h | h | h · exact ⟨0, by rw [h, zero_smul, vadd_eq_add, zero_add]⟩ · exact ⟨c, by rw [h, hy', vadd_eq_add, add_comm]⟩ · exact ⟨1, by rw [h, one_smul, vadd_eq_add, add_comm]⟩ /-! ### (T), generic case: the three points are at distinct heights `cross t ·` -/ theorem core_case {S : Set (EuclideanSpace ℝ (Fin 2))} (hS : ConvexIndep S) {t x y z : EuclideanSpace ℝ (Fin 2)} (ht : t ≠ 0) (hx : x ∈ S) (hy : y ∈ S) (hz : z ∈ S) (hxt : x + t ∈ S) (hyt : y + t ∈ S) (hzt : z + t ∈ S) (h1 : cross t x < cross t y) (h2 : cross t y < cross t z) : False := by have hD : 0 < cross t (z - x) := by rw [cross_sub_right]; linarith have hdec := decomp (y - x) hD.ne' set a := cross t (y - x) / cross t (z - x) with ha_def set b := cross (y - x) (z - x) / cross t (z - x) with hb_def have ha0 : 0 ≤ a := div_nonneg (by rw [cross_sub_right]; linarith) hD.le have ha1 : a ≤ 1 := by rw [ha_def, div_le_one hD, cross_sub_right, cross_sub_right] linarith set m := x + a • (z - x) with hm_def have hym : y = m + b • t := by calc y = x + (y - x) := by abel _ = x + (a • (z - x) + b • t) := by rw [← hdec] _ = m + b • t := by rw [hm_def, add_assoc] -- heights of the translated points have cxt : cross t (x + t) = cross t x := cross_add_self t x have cyt : cross t (y + t) = cross t y := cross_add_self t y have czt : cross t (z + t) = cross t z := cross_add_self t z -- the two hull points `m` and `m + t`, for any excluded point `q` of height `cross t y` have hull_m : ∀ q, cross t q = cross t y → m ∈ convexHull ℝ (S \ {q}) ∧ m + t ∈ convexHull ℝ (S \ {q}) := by intro q hq have hc := convex_convexHull ℝ (S \ {q}) have mx : x ∈ convexHull ℝ (S \ {q}) := subset_convexHull ℝ _ (mem_diff_of_cross_ne hx (by rw [hq]; exact h1.ne)) have mz : z ∈ convexHull ℝ (S \ {q}) := subset_convexHull ℝ _ (mem_diff_of_cross_ne hz (by rw [hq]; exact h2.ne')) have mxt : x + t ∈ convexHull ℝ (S \ {q}) := subset_convexHull ℝ _ (mem_diff_of_cross_ne hxt (by rw [hq, cxt]; exact h1.ne)) have mzt : z + t ∈ convexHull ℝ (S \ {q}) := subset_convexHull ℝ _ (mem_diff_of_cross_ne hzt (by rw [hq, czt]; exact h2.ne')) refine ⟨hc.add_smul_sub_mem mx mz ⟨ha0, ha1⟩, ?_⟩ have h5 := hc.add_smul_sub_mem mxt mzt ⟨ha0, ha1⟩ have e : x + t + a • (z + t - (x + t)) = m + t := by rw [add_sub_add_right_eq_sub, hm_def] abel rwa [e] at h5 by_cases hb0 : 0 ≤ b · by_cases hb1 : b ≤ 1 · -- case A: `y` lies on the segment `[m, m + t]` apply hS y hy obtain ⟨mm, mmt⟩ := hull_m y rfl have h5 := (convex_convexHull ℝ (S \ {y})).add_smul_sub_mem mm mmt ⟨hb0, hb1⟩ have e : m + b • (m + t - m) = y := by rw [add_sub_cancel_left, hym] rwa [e] at h5 · -- case B: `y` lies on the segment `[y + t, m + t]` have hb1 := not_le.mp hb1 apply hS y hy obtain ⟨_, mmt⟩ := hull_m y rfl have myt : y + t ∈ convexHull ℝ (S \ {y}) := subset_convexHull ℝ _ (mem_diff_singleton_of_ne hyt (self_ne_add_vec ht).symm) have hbpos : 0 < b := by linarith have hmu : (1 / b) ∈ Set.Icc (0 : ℝ) 1 := ⟨div_nonneg zero_le_one hbpos.le, (div_le_one hbpos).mpr hb1.le⟩ have h5 := (convex_convexHull ℝ (S \ {y})).add_smul_sub_mem myt mmt hmu have e1 : m + t - (y + t) = (-b) • t := by rw [hym, neg_smul]; abel have e2 : 1 / b * -b = -1 := by rw [mul_neg, one_div_mul_cancel hbpos.ne'] have e : y + t + (1 / b) • (m + t - (y + t)) = y := by rw [e1, smul_smul, e2, neg_one_smul] abel rwa [e] at h5 · have hb0 := not_le.mp hb0 by_cases hb2 : -1 ≤ b · -- case C: `y + t` lies on the segment `[m, m + t]` apply hS (y + t) hyt obtain ⟨mm, mmt⟩ := hull_m (y + t) cyt have hmu : b + 1 ∈ Set.Icc (0 : ℝ) 1 := ⟨by linarith, by linarith⟩ have h5 := (convex_convexHull ℝ (S \ {y + t})).add_smul_sub_mem mm mmt hmu have e : m + (b + 1) • (m + t - m) = y + t := by rw [add_sub_cancel_left, add_smul, one_smul, hym] abel rwa [e] at h5 · -- case D: `y + t` lies on the segment `[y, m]` have hb2 := not_le.mp hb2 apply hS (y + t) hyt obtain ⟨mm, _⟩ := hull_m (y + t) cyt have my : y ∈ convexHull ℝ (S \ {y + t}) := subset_convexHull ℝ _ (mem_diff_singleton_of_ne hy (self_ne_add_vec ht)) have hnb : 0 < -b := by linarith have hmu : (1 / (-b)) ∈ Set.Icc (0 : ℝ) 1 := ⟨div_nonneg zero_le_one hnb.le, (div_le_one hnb).mpr (by linarith)⟩ have h5 := (convex_convexHull ℝ (S \ {y + t})).add_smul_sub_mem my mm hmu have e1 : m - y = (-b) • t := by rw [hym, neg_smul]; abel have e : y + (1 / (-b)) • (m - y) = y + t := by rw [e1, smul_smul, one_div_mul_cancel hnb.ne', one_smul] rwa [e] at h5 /-- (T) A nonzero translation maps at most two points of a convex-independent set into it. -/ theorem translate_card_le_two {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) {t : EuclideanSpace ℝ (Fin 2)} (ht : t ≠ 0) : (P.filter (fun x => x + t ∈ P)).card ≤ 2 := by by_contra hcon obtain ⟨x, y, z, hx, hy, hz, hxy, hxz, hyz⟩ := Finset.two_lt_card_iff.mp (not_le.mp hcon) rw [Finset.mem_filter] at hx hy hz have m : ∀ {p : EuclideanSpace ℝ (Fin 2)}, p ∈ P → p ∈ (P : Set (EuclideanSpace ℝ (Fin 2))) := fun hp => Finset.mem_coe.mpr hp have par : ∀ {p q : EuclideanSpace ℝ (Fin 2)}, p ∈ P ∧ p + t ∈ P → q ∈ P ∧ q + t ∈ P → p ≠ q → cross t p ≠ cross t q := by intro p q hp hq hpq hc exact parallel_case hP ht (m hp.1) (m hq.1) (m hp.2) (m hq.2) hpq (by rw [cross_sub_right, hc, sub_self]) have h12 := par hx hy hxy have h13 := par hx hz hxz have h23 := par hy hz hyz have core : ∀ {p q r : EuclideanSpace ℝ (Fin 2)}, p ∈ P ∧ p + t ∈ P → q ∈ P ∧ q + t ∈ P → r ∈ P ∧ r + t ∈ P → cross t p < cross t q → cross t q < cross t r → False := by intro p q r hp hq hr hpq hqr exact core_case hP ht (m hp.1) (m hq.1) (m hr.1) (m hp.2) (m hq.2) (m hr.2) hpq hqr rcases lt_or_gt_of_ne h12 with a | a <;> rcases lt_or_gt_of_ne h13 with b | b <;> rcases lt_or_gt_of_ne h23 with c | c · exact core hx hy hz a c · exact core hx hz hy b c · linarith · exact core hz hx hy b a · exact core hy hx hz a b · linarith · exact core hy hz hx c b · exact core hz hy hx c a end Erdos94ThmA /-! THEOREM-A scratch: (G5) chain counting and Lemma C1 (near-maximal energy ⇒ near-coset of a finite subgroup) in any commutative group, via Mathlib's Freiman 3/2 lemma (`Finset.invMulSubgroup`). Static-policy shaped body (to sit inside `namespace Bounty`). -/ namespace Erdos94ThmA open Finset open scoped Pointwise /-! ### (G5) chain counting: `r(g ∘ f) + n ≥ r(f) + r(g)` for injective `f` -/ theorem card_filter_comp_add_card {α : Type*} [DecidableEq α] (P : Finset α) (f g : α → α) (hf : Function.Injective f) : (P.filter (fun x => f x ∈ P)).card + (P.filter (fun x => g x ∈ P)).card ≤ (P.filter (fun x => g (f x) ∈ P)).card + P.card := by have h2 := card_filter_add_card_filter_not (s := P.filter (fun x => f x ∈ P)) (fun x => g (f x) ∈ P) have h3 : ((P.filter (fun x => f x ∈ P)).filter (fun x => g (f x) ∈ P)).card ≤ (P.filter (fun x => g (f x) ∈ P)).card := card_le_card (filter_subset_filter _ (filter_subset _ _)) have h1 : ((P.filter (fun x => f x ∈ P)).filter (fun x => ¬ g (f x) ∈ P)).card ≤ (P.filter (fun y => ¬ g y ∈ P)).card := by apply card_le_card_of_injOn f · intro x hx simp only [mem_coe, mem_filter] at hx ⊢ exact ⟨hx.1.2, hx.2⟩ · exact hf.injOn have h4 := card_filter_add_card_filter_not (s := P) (fun y => g y ∈ P) omega section C1 variable {G : Type*} [CommGroup G] [DecidableEq G] /-- `rep A x = #{b ∈ A : x * b ∈ A}` = the number of `(a, b) ∈ A × A` with `a * b⁻¹ = x`. -/ def rep (A : Finset G) (x : G) : ℕ := (A.filter (fun b => x * b ∈ A)).card /-- The (multiplicative) energy `∑_{a, b ∈ A} rep A (a * b⁻¹) = ∑_x rep A x ^ 2`. -/ def energy (A : Finset G) : ℕ := ∑ b ∈ A, ∑ a ∈ A, rep A (a * b⁻¹) theorem rep_le (A : Finset G) (x : G) : rep A x ≤ A.card := card_filter_le _ _ theorem rep_one (A : Finset G) : rep A 1 = A.card := by unfold rep congr 1 exact filter_true_of_mem (fun b hb => by rw [one_mul]; exact hb) /-- (5.1) `rep(x y) ≥ rep(x) + rep(y) − |A|`. -/ theorem rep_mul (A : Finset G) (x y : G) : rep A x + rep A y ≤ rep A (x * y) + A.card := by have h : (A.filter (fun b => y * b ∈ A)).card + (A.filter (fun b => x * b ∈ A)).card ≤ (A.filter (fun b => x * (y * b) ∈ A)).card + A.card := card_filter_comp_add_card A (fun b => y * b) (fun b => x * b) (mul_right_injective y) have e : A.filter (fun b => x * (y * b) ∈ A) = A.filter (fun b => x * y * b ∈ A) := filter_congr (fun b _ => by rw [mul_assoc]) unfold rep rw [e] at h omega theorem mem_mul_inv_of_rep_pos {A : Finset G} {x : G} (h : 0 < rep A x) : x ∈ A * A⁻¹ := by obtain ⟨b, hb⟩ := card_pos.mp h rw [mem_filter] at hb rw [mem_mul] exact ⟨x * b, hb.2, b⁻¹, inv_mem_inv hb.1, by rw [mul_inv_cancel_right]⟩ theorem card_filter_mul_mem (A H : Finset G) (b : G) : (H.filter (fun x => x * b ∈ A)).card = (A.filter (fun a => a * b⁻¹ ∈ H)).card := by apply card_nbij' (fun x => x * b) (fun a => a * b⁻¹) · intro x hx simp only [mem_coe, mem_filter] at hx ⊢ exact ⟨hx.2, by rw [mul_inv_cancel_right]; exact hx.1⟩ · intro a ha simp only [mem_coe, mem_filter] at ha ⊢ exact ⟨ha.2, by rw [inv_mul_cancel_right]; exact ha.1⟩ · intro x _ simp only [mul_inv_cancel_right] · intro a _ simp only [inv_mul_cancel_right] /-- `∑_{x ∈ H} rep A x` counts the pairs `(a, b) ∈ A × A` with `a * b⁻¹ ∈ H`. -/ theorem sum_rep_eq (A H : Finset G) : ∑ x ∈ H, rep A x = ∑ b ∈ A, (A.filter (fun a => a * b⁻¹ ∈ H)).card := by calc ∑ x ∈ H, rep A x = ∑ x ∈ H, ∑ b ∈ A, (if x * b ∈ A then 1 else 0) := by refine sum_congr rfl (fun x _ => ?_) unfold rep rw [card_filter] _ = ∑ b ∈ A, ∑ x ∈ H, (if x * b ∈ A then 1 else 0) := sum_comm _ = ∑ b ∈ A, (H.filter (fun x => x * b ∈ A)).card := by refine sum_congr rfl (fun b _ => ?_) rw [card_filter] _ = ∑ b ∈ A, (A.filter (fun a => a * b⁻¹ ∈ H)).card := sum_congr rfl (fun b _ => card_filter_mul_mem A H b) theorem sum_rep_le (A H : Finset G) : ∑ x ∈ H, rep A x ≤ A.card * A.card := by rw [sum_rep_eq] calc ∑ b ∈ A, (A.filter (fun a => a * b⁻¹ ∈ H)).card ≤ ∑ _b ∈ A, A.card := sum_le_sum (fun b _ => card_filter_le _ _) _ = A.card * A.card := by rw [sum_const, smul_eq_mul] /-- Popular differences `{x : rep A x ≥ c}`. -/ noncomputable def popular (A : Finset G) (c : ℝ) : Finset G := (A * A⁻¹).filter (fun x => c ≤ (rep A x : ℝ)) theorem le_rep_of_mem_popular {A : Finset G} {c : ℝ} {x : G} (hx : x ∈ popular A c) : c ≤ (rep A x : ℝ) := (mem_filter.mp hx).2 theorem filter_popular (A : Finset G) (c : ℝ) (b : G) (hb : b ∈ A) : (A.filter (fun a => a * b⁻¹ ∈ popular A c)).card + (A.filter (fun a => (rep A (a * b⁻¹) : ℝ) < c)).card = A.card := by have e : A.filter (fun a => a * b⁻¹ ∈ popular A c) = A.filter (fun a => ¬ ((rep A (a * b⁻¹) : ℝ) < c)) := by apply filter_congr intro a ha unfold popular rw [mem_filter, not_lt] constructor · exact fun h => h.2 · exact fun h => ⟨mul_mem_mul ha (inv_mem_inv hb), h⟩ rw [e, add_comm] exact card_filter_add_card_filter_not _ theorem sum_popular_add_bad (A : Finset G) (c : ℝ) : ∑ x ∈ popular A c, rep A x + ∑ b ∈ A, (A.filter (fun a => (rep A (a * b⁻¹) : ℝ) < c)).card = A.card * A.card := by rw [sum_rep_eq, ← sum_add_distrib, sum_congr rfl (fun b hb => filter_popular A c b hb), sum_const, smul_eq_mul] /-- (5.2) energy deficit controls the unpopular pairs. -/ theorem energy_add_bad_le (A : Finset G) (s : ℝ) : (energy A : ℝ) + s * A.card * ((∑ b ∈ A, (A.filter (fun a => (rep A (a * b⁻¹) : ℝ) < (1 - s) * A.card)).card : ℕ) : ℝ) ≤ (A.card : ℝ) ^ 3 := by have h : (energy A : ℝ) ≤ ∑ b ∈ A, ∑ a ∈ A, ((A.card : ℝ) - s * A.card * (if (rep A (a * b⁻¹) : ℝ) < (1 - s) * A.card then 1 else 0)) := by unfold energy push_cast apply sum_le_sum intro b _ apply sum_le_sum intro a _ have hr : (rep A (a * b⁻¹) : ℝ) ≤ A.card := by exact_mod_cast rep_le A (a * b⁻¹) split_ifs with hlt · linarith · linarith have e1 : ∀ b ∈ A, ∑ a ∈ A, ((A.card : ℝ) - s * A.card * (if (rep A (a * b⁻¹) : ℝ) < (1 - s) * A.card then 1 else 0)) = (A.card : ℝ) * A.card - s * A.card * ((A.filter (fun a => (rep A (a * b⁻¹) : ℝ) < (1 - s) * A.card)).card : ℝ) := by intro b _ rw [sum_sub_distrib, sum_const, nsmul_eq_mul, ← mul_sum, sum_boole] rw [sum_congr rfl e1, sum_sub_distrib, sum_const, nsmul_eq_mul, ← mul_sum] at h push_cast nlinarith [h] /-- The arithmetic step of C1: the doubling of `B` is below `3/2`. -/ theorem doubling_arith {X Y K t : ℝ} (ht0 : 0 < t) (ht1 : t ≤ 1 / 10) (hK : 0 < K) (hX : X * (1 - 2 * t) ≤ K) (hY : (1 - t) * K ≤ Y) : 2 * X < 3 * Y := by have h12 : 0 < 1 - 2 * t := by linarith have h1 : 2 * X * (1 - 2 * t) ≤ 2 * K := by linarith have h2 : 3 * ((1 - t) * K) * (1 - 2 * t) ≤ 3 * Y * (1 - 2 * t) := by have := mul_le_mul_of_nonneg_right hY h12.le linarith have h3 : 2 * K < 3 * ((1 - t) * K) * (1 - 2 * t) := by have hc : 2 < 3 * (1 - t) * (1 - 2 * t) := by nlinarith have := mul_lt_mul_of_pos_right hc hK nlinarith have h4 : 2 * X * (1 - 2 * t) < 3 * Y * (1 - 2 * t) := by linarith exact lt_of_mul_lt_mul_right h4 h12.le /-- **Lemma C1.** If `E(A) ≥ (1 − t²)|A|³` with `0 < t ≤ 1/10`, then `G` has a finite subgroup `H = D` with `(1 − t)|A| ≤ |D|`, `|D|(1 − 2t) ≤ |A|`, and a coset `D b` containing at least `(1 − 2t)|A|` points of `A`. -/ theorem C1 (A : Finset G) (hA : A.Nonempty) (t : ℝ) (ht0 : 0 < t) (ht1 : t ≤ 1 / 10) (hE : (1 - t ^ 2) * (A.card : ℝ) ^ 3 ≤ (energy A : ℝ)) : ∃ H : Subgroup G, ∃ D : Finset G, (∀ x, x ∈ H ↔ x ∈ D) ∧ (1 - t) * (A.card : ℝ) ≤ D.card ∧ (D.card : ℝ) * (1 - 2 * t) ≤ A.card ∧ ∃ b ∈ A, (1 - 2 * t) * (A.card : ℝ) ≤ (A.filter (fun a => a * b⁻¹ ∈ D)).card := by have hKpos : (0 : ℝ) < A.card := by exact_mod_cast hA.card_pos -- the popular set `B = H_t` and the bad pairs for threshold `(1 - t)|A|` have hbad := energy_add_bad_le A t have hsum := sum_popular_add_bad A ((1 - t) * A.card) have hsumR : ((∑ x ∈ popular A ((1 - t) * A.card), rep A x : ℕ) : ℝ) + ((∑ b ∈ A, (A.filter (fun a => (rep A (a * b⁻¹) : ℝ) < (1 - t) * A.card)).card : ℕ) : ℝ) = (A.card : ℝ) * A.card := by exact_mod_cast hsum set Nb : ℕ := ∑ b ∈ A, (A.filter (fun a => (rep A (a * b⁻¹) : ℝ) < (1 - t) * A.card)).card with hNb set B := popular A ((1 - t) * A.card) with hB -- Nb ≤ t |A|² have hNb_le : (Nb : ℝ) ≤ t * A.card * A.card := by have h1 : t * A.card * (Nb : ℝ) ≤ t ^ 2 * (A.card : ℝ) ^ 3 := by nlinarith have h2 : 0 < t * (A.card : ℝ) := mul_pos ht0 hKpos have h3 : t * A.card * (Nb : ℝ) ≤ t * A.card * (t * A.card * A.card) := by nlinarith exact le_of_mul_le_mul_left h3 h2 -- |B| ≥ (1 - t)|A| have hsumB : (∑ x ∈ B, rep A x : ℕ) ≤ B.card * A.card := by have := sum_le_card_nsmul B (fun x => rep A x) A.card (fun x _ => rep_le A x) rwa [smul_eq_mul] at this have hB_card : (1 - t) * (A.card : ℝ) ≤ B.card := by have h1 : ((∑ x ∈ B, rep A x : ℕ) : ℝ) ≤ (B.card : ℝ) * A.card := by exact_mod_cast hsumB have h2 : (1 - t) * (A.card : ℝ) * A.card ≤ (B.card : ℝ) * A.card := by nlinarith exact le_of_mul_le_mul_right h2 hKpos -- the second popular set `B2 = H_{2t}` has `|B2|(1 - 2t)|A| ≤ |A|²` set B2 := popular A ((1 - 2 * t) * A.card) with hB2 have hB2_card : (B2.card : ℝ) * (1 - 2 * t) ≤ A.card := by have h1 : ((B2.card : ℕ) : ℝ) * ((1 - 2 * t) * A.card) ≤ ((∑ x ∈ B2, rep A x : ℕ) : ℝ) := by have := card_nsmul_le_sum B2 (fun x => (rep A x : ℝ)) ((1 - 2 * t) * A.card) (fun x hx => le_rep_of_mem_popular hx) rw [nsmul_eq_mul] at this push_cast exact this have h2 : ((∑ x ∈ B2, rep A x : ℕ) : ℝ) ≤ (A.card : ℝ) * A.card := by exact_mod_cast sum_rep_le A B2 have h3 : (B2.card : ℝ) * (1 - 2 * t) * A.card ≤ (A.card : ℝ) * A.card := by nlinarith exact le_of_mul_le_mul_right h3 hKpos -- B * B ⊆ B2 have hBB : B * B ⊆ B2 := by intro z hz obtain ⟨x, hx, y, hy, rfl⟩ := mem_mul.mp hz have hxr := le_rep_of_mem_popular hx have hyr := le_rep_of_mem_popular hy have hm : ((rep A x + rep A y : ℕ) : ℝ) ≤ ((rep A (x * y) + A.card : ℕ) : ℝ) := by exact_mod_cast rep_mul A x y push_cast at hm have hxy : (1 - 2 * t) * (A.card : ℝ) ≤ rep A (x * y) := by linarith have hpos : 0 < rep A (x * y) := by have : (0 : ℝ) < rep A (x * y) := by have : 0 < (1 - 2 * t) * (A.card : ℝ) := mul_pos (by linarith) hKpos linarith exact_mod_cast this exact mem_filter.mpr ⟨mem_mul_inv_of_rep_pos hpos, hxy⟩ have hBB_card : ((B * B).card : ℝ) * (1 - 2 * t) ≤ A.card := by have h1 : ((B * B).card : ℝ) ≤ B2.card := by exact_mod_cast card_le_card hBB nlinarith -- doubling < 3/2 have hdoubR : 2 * ((B * B).card : ℝ) < 3 * B.card := doubling_arith ht0 ht1 hKpos hBB_card hB_card have hdoubN : 2 * (B * B).card < 3 * B.card := by exact_mod_cast hdoubR have hQ : ((B * B).card : ℚ) < (3 / 2 : ℚ) * B.card := by have : ((2 * (B * B).card : ℕ) : ℚ) < ((3 * B.card : ℕ) : ℚ) := by exact_mod_cast hdoubN push_cast at this linarith -- the subgroup `H = B⁻¹ * B` refine ⟨invMulSubgroup B hQ, B⁻¹ * B, ?_, ?_, ?_, ?_⟩ · intro x have e : ((invMulSubgroup B hQ : Subgroup G) : Set G) = ((B⁻¹ * B : Finset G) : Set G) := by rw [invMulSubgroup_eq_inv_mul, coe_mul, coe_inv] rw [← SetLike.mem_coe, e, mem_coe] · -- 1 ∈ B, hence B ⊆ B⁻¹ * B have h1B : (1 : G) ∈ B := by obtain ⟨a, ha⟩ := hA refine mem_filter.mpr ⟨?_, ?_⟩ · rw [mem_mul] exact ⟨a, ha, a⁻¹, inv_mem_inv ha, mul_inv_cancel a⟩ · rw [rep_one] nlinarith have hsub : B ⊆ B⁻¹ * B := by intro x hx have := mul_mem_mul (inv_mem_inv h1B) hx rwa [inv_one, one_mul] at this have : (B.card : ℝ) ≤ (B⁻¹ * B).card := by exact_mod_cast card_le_card hsub linarith · rw [card_inv_mul_of_doubling_lt_three_halves hQ] exact hBB_card · -- averaging over cosets have h1B : (1 : G) ∈ B := by obtain ⟨a, ha⟩ := hA refine mem_filter.mpr ⟨?_, ?_⟩ · rw [mem_mul] exact ⟨a, ha, a⁻¹, inv_mem_inv ha, mul_inv_cancel a⟩ · rw [rep_one] nlinarith have hsub : B ⊆ B⁻¹ * B := by intro x hx have := mul_mem_mul (inv_mem_inv h1B) hx rwa [inv_one, one_mul] at this have hs1 : ∑ x ∈ B, rep A x ≤ ∑ x ∈ B⁻¹ * B, rep A x := sum_le_sum_of_subset hsub have hs2 : (B.card : ℝ) * ((1 - t) * A.card) ≤ ((∑ x ∈ B, rep A x : ℕ) : ℝ) := by have := card_nsmul_le_sum B (fun x => (rep A x : ℝ)) ((1 - t) * A.card) (fun x hx => le_rep_of_mem_popular hx) rw [nsmul_eq_mul] at this push_cast exact this have hs3 : ((∑ x ∈ B, rep A x : ℕ) : ℝ) ≤ ((∑ x ∈ B⁻¹ * B, rep A x : ℕ) : ℝ) := by exact_mod_cast hs1 rw [sum_rep_eq A (B⁻¹ * B)] at hs3 push_cast at hs2 hs3 have hlow : ∑ _b ∈ A, (1 - 2 * t) * (A.card : ℝ) ≤ ∑ b ∈ A, ((A.filter (fun a => a * b⁻¹ ∈ B⁻¹ * B)).card : ℝ) := by rw [sum_const, nsmul_eq_mul] have hB0 : (0 : ℝ) ≤ (1 - t) * A.card := mul_nonneg (by linarith) hKpos.le have h5 : (1 - t) * (A.card : ℝ) * ((1 - t) * A.card) ≤ (B.card : ℝ) * ((1 - t) * A.card) := mul_le_mul_of_nonneg_right hB_card hB0 nlinarith [sq_nonneg (t * (A.card : ℝ))] obtain ⟨b, hb, hle⟩ := exists_le_of_sum_le hA hlow exact ⟨b, hb, hle⟩ end C1 end Erdos94ThmA /-! ### Lemma C1′ (THEOREM_A §12.5): wider range and O(δ) defects -/ namespace Erdos94ThmA open Finset open scoped Pointwise section C1p variable {G : Type*} [CommGroup G] [DecidableEq G] theorem rep_inv (A : Finset G) (x : G) : rep A x⁻¹ = rep A x := by unfold rep apply card_nbij' (fun b => x⁻¹ * b) (fun c => x * c) · intro b hb simp only [mem_coe, mem_filter] at hb ⊢ exact ⟨hb.2, by rw [mul_inv_cancel_left]; exact hb.1⟩ · intro c hc simp only [mem_coe, mem_filter] at hc ⊢ exact ⟨hc.2, by rw [inv_mul_cancel_left]; exact hc.1⟩ · intro b _ simp only [mul_inv_cancel_left] · intro c _ simp only [inv_mul_cancel_left] /-- Weighted version of `sum_rep_eq`. -/ theorem sum_rep_mul_eq (A H : Finset G) (g : G → ℝ) : ∑ x ∈ H, (rep A x : ℝ) * g x = ∑ b ∈ A, ∑ a ∈ A.filter (fun a => a * b⁻¹ ∈ H), g (a * b⁻¹) := by calc ∑ x ∈ H, (rep A x : ℝ) * g x = ∑ x ∈ H, ∑ b ∈ A, (if x * b ∈ A then g x else 0) := by refine sum_congr rfl (fun x _ => ?_) unfold rep rw [← sum_filter, sum_const, nsmul_eq_mul] _ = ∑ b ∈ A, ∑ x ∈ H, (if x * b ∈ A then g x else 0) := sum_comm _ = ∑ b ∈ A, ∑ a ∈ A.filter (fun a => a * b⁻¹ ∈ H), g (a * b⁻¹) := by refine sum_congr rfl (fun b _ => ?_) rw [← sum_filter] apply sum_nbij' (fun x => x * b) (fun a => a * b⁻¹) · intro x hx simp only [mem_coe, mem_filter] at hx ⊢ exact ⟨hx.2, by rw [mul_inv_cancel_right]; exact hx.1⟩ · intro a ha simp only [mem_coe, mem_filter] at ha ⊢ exact ⟨ha.2, by rw [inv_mul_cancel_right]; exact ha.1⟩ · intro x _ simp only [mul_inv_cancel_right] · intro a _ simp only [inv_mul_cancel_right] · intro x _ simp only [mul_inv_cancel_right] /-- The energy deficit: `K³ − E = ∑_{(a, b)} (K − rep(a b⁻¹))`. -/ theorem energy_deficit (A : Finset G) : (A.card : ℝ) ^ 3 - energy A = ∑ b ∈ A, ∑ a ∈ A, ((A.card : ℝ) - rep A (a * b⁻¹)) := by simp only [sum_sub_distrib, sum_const, nsmul_eq_mul] unfold energy push_cast ring /-- C1′ step 1: the popular set `B = H_t` is large and carries most of the pairs. -/ theorem c1p_B (A : Finset G) (hA : A.Nonempty) (t δ : ℝ) (ht0 : 0 < t) (hE : (1 - δ) * (A.card : ℝ) ^ 3 ≤ (energy A : ℝ)) : (1 - δ / t) * (A.card : ℝ) * A.card ≤ ∑ x ∈ popular A ((1 - t) * A.card), (rep A x : ℝ) ∧ (1 - δ / t) * (A.card : ℝ) ≤ (popular A ((1 - t) * A.card)).card := by have hKpos : (0 : ℝ) < A.card := by exact_mod_cast hA.card_pos have hbad := energy_add_bad_le A t have hsum := sum_popular_add_bad A ((1 - t) * A.card) set Nb : ℕ := ∑ b ∈ A, (A.filter (fun a => (rep A (a * b⁻¹) : ℝ) < (1 - t) * A.card)).card with hNb have hsumR : (∑ x ∈ popular A ((1 - t) * A.card), (rep A x : ℝ)) + (Nb : ℝ) = (A.card : ℝ) * A.card := by have h' : ((∑ x ∈ popular A ((1 - t) * A.card), rep A x + Nb : ℕ) : ℝ) = ((A.card * A.card : ℕ) : ℝ) := by rw [hsum] push_cast at h' linarith have h1 : t * A.card * (Nb : ℝ) ≤ δ * (A.card : ℝ) ^ 3 := by linarith have hNb' : (Nb : ℝ) ≤ δ / t * A.card * A.card := by rw [div_mul_eq_mul_div, div_mul_eq_mul_div, le_div_iff₀ ht0] have h2 : t * A.card * (Nb : ℝ) ≤ δ * A.card * A.card * A.card := by have : δ * (A.card : ℝ) ^ 3 = δ * A.card * A.card * A.card := by ring linarith have h3 : (Nb : ℝ) * t * A.card ≤ δ * A.card * A.card * A.card := by linarith nlinarith have hS : (1 - δ / t) * (A.card : ℝ) * A.card ≤ ∑ x ∈ popular A ((1 - t) * A.card), (rep A x : ℝ) := by have : (1 - δ / t) * (A.card : ℝ) * A.card = A.card * A.card - δ / t * A.card * A.card := by ring linarith refine ⟨hS, ?_⟩ have hsumB := sum_le_card_nsmul (popular A ((1 - t) * A.card)) (fun x => (rep A x : ℝ)) (A.card : ℝ) (fun x _ => by exact_mod_cast rep_le A x) rw [nsmul_eq_mul] at hsumB have h2 : (1 - δ / t) * (A.card : ℝ) * A.card ≤ ((popular A ((1 - t) * A.card)).card : ℝ) * A.card := le_trans hS hsumB exact le_of_mul_le_mul_right h2 hKpos /-- C1′ step 2: `rep (x y) ≥ (1 − 2t) K` on `B · B`, and the doubling of `B` is below `3/2`. -/ theorem c1p_doubling (A : Finset G) (hA : A.Nonempty) (t δ : ℝ) (ht2 : 2 * t < 1) (h32 : 2 < 3 * (1 - 2 * t) * (1 - δ / t)) (hB : (1 - δ / t) * (A.card : ℝ) ≤ (popular A ((1 - t) * A.card)).card) : (∀ x ∈ popular A ((1 - t) * A.card), ∀ y ∈ popular A ((1 - t) * A.card), (1 - 2 * t) * (A.card : ℝ) ≤ rep A (x * y)) ∧ ((popular A ((1 - t) * A.card) * popular A ((1 - t) * A.card)).card : ℚ) < (3 / 2 : ℚ) * (popular A ((1 - t) * A.card)).card := by have hKpos : (0 : ℝ) < A.card := by exact_mod_cast hA.card_pos set B := popular A ((1 - t) * A.card) with hBdef set B2 := popular A ((1 - 2 * t) * A.card) with hB2def have hrep_mul : ∀ x ∈ B, ∀ y ∈ B, (1 - 2 * t) * (A.card : ℝ) ≤ rep A (x * y) := by intro x hx y hy have hxr := le_rep_of_mem_popular hx have hyr := le_rep_of_mem_popular hy have hm : ((rep A x + rep A y : ℕ) : ℝ) ≤ ((rep A (x * y) + A.card : ℕ) : ℝ) := by exact_mod_cast rep_mul A x y push_cast at hm linarith refine ⟨hrep_mul, ?_⟩ have hB2_card : (B2.card : ℝ) * ((1 - 2 * t) * A.card) ≤ (A.card : ℝ) * A.card := by have h1 := card_nsmul_le_sum B2 (fun x => (rep A x : ℝ)) ((1 - 2 * t) * A.card) (fun x hx => le_rep_of_mem_popular hx) rw [nsmul_eq_mul] at h1 have h2 : ((∑ x ∈ B2, rep A x : ℕ) : ℝ) ≤ ((A.card * A.card : ℕ) : ℝ) := by exact_mod_cast sum_rep_le A B2 push_cast at h2 linarith have hBB : B * B ⊆ B2 := by intro z hz obtain ⟨x, hx, y, hy, rfl⟩ := mem_mul.mp hz have hxy := hrep_mul x hx y hy have hpos : 0 < rep A (x * y) := by have : (0 : ℝ) < rep A (x * y) := by have : 0 < (1 - 2 * t) * (A.card : ℝ) := mul_pos (by linarith) hKpos linarith exact_mod_cast this exact mem_filter.mpr ⟨mem_mul_inv_of_rep_pos hpos, hxy⟩ have h1 : ((B * B).card : ℝ) ≤ B2.card := by exact_mod_cast card_le_card hBB have h12 : 0 < 1 - 2 * t := by linarith have hBB_card : ((B * B).card : ℝ) * ((1 - 2 * t) * A.card) ≤ (A.card : ℝ) * A.card := by have := mul_le_mul_of_nonneg_right h1 (le_of_lt (mul_pos h12 hKpos)) linarith -- 2|BB| (1−2t) K ≤ 2K² < 3 (1−2t)(1−δ/t) K² ≤ 3 (1−2t) |B| K have e2 : 3 * ((1 - 2 * t) * A.card) * ((1 - δ / t) * A.card) ≤ 3 * ((1 - 2 * t) * A.card) * (B.card : ℝ) := mul_le_mul_of_nonneg_left hB (by positivity) have e3 : 2 * ((A.card : ℝ) * A.card) < 3 * ((1 - 2 * t) * A.card) * ((1 - δ / t) * A.card) := by have hK2 : (0 : ℝ) < A.card * A.card := mul_pos hKpos hKpos have := mul_lt_mul_of_pos_right h32 hK2 linarith have e4 : 2 * ((B * B).card : ℝ) * ((1 - 2 * t) * A.card) < 3 * (B.card : ℝ) * ((1 - 2 * t) * A.card) := by linarith have hdoubR : 2 * ((B * B).card : ℝ) < 3 * B.card := lt_of_mul_lt_mul_right e4 (le_of_lt (mul_pos h12 hKpos)) have hdoubN : 2 * (B * B).card < 3 * B.card := by exact_mod_cast hdoubR have : ((2 * (B * B).card : ℕ) : ℚ) < ((3 * B.card : ℕ) : ℚ) := by exact_mod_cast hdoubN push_cast at this linarith /-- C1′ step 3: if every element of `D` is popular at level `2t`, then `|D| ≤ (1 + δ/(1 − 2t)) K`. -/ theorem c1p_card_le (A D : Finset G) (hA : A.Nonempty) (t δ : ℝ) (ht2 : 2 * t < 1) (hrepD : ∀ d ∈ D, (1 - 2 * t) * (A.card : ℝ) ≤ rep A d) (hE : (1 - δ) * (A.card : ℝ) ^ 3 ≤ (energy A : ℝ)) : (D.card : ℝ) * (1 - 2 * t) * A.card ≤ (1 - 2 * t) * (A.card : ℝ) ^ 2 + δ * (A.card : ℝ) ^ 2 := by have hKpos : (0 : ℝ) < A.card := by exact_mod_cast hA.card_pos have hdef := energy_deficit A have hw := sum_rep_mul_eq A D (fun d => (A.card : ℝ) - rep A d) have hle1 : ∑ x ∈ D, (rep A x : ℝ) * ((A.card : ℝ) - rep A x) ≤ δ * (A.card : ℝ) ^ 3 := by rw [hw] have : ∑ b ∈ A, ∑ a ∈ A.filter (fun a => a * b⁻¹ ∈ D), ((A.card : ℝ) - rep A (a * b⁻¹)) ≤ ∑ b ∈ A, ∑ a ∈ A, ((A.card : ℝ) - rep A (a * b⁻¹)) := by apply sum_le_sum intro b _ apply sum_le_sum_of_subset_of_nonneg (filter_subset _ _) intro a _ _ have : (rep A (a * b⁻¹) : ℝ) ≤ A.card := by exact_mod_cast rep_le A (a * b⁻¹) linarith linarith have hle2 : (1 - 2 * t) * (A.card : ℝ) * ∑ x ∈ D, ((A.card : ℝ) - rep A x) ≤ ∑ x ∈ D, (rep A x : ℝ) * ((A.card : ℝ) - rep A x) := by rw [mul_sum] apply sum_le_sum intro x hx have h1 := hrepD x hx have h2 : (rep A x : ℝ) ≤ A.card := by exact_mod_cast rep_le A x exact mul_le_mul_of_nonneg_right h1 (by linarith) have hle3 : ∑ x ∈ D, (rep A x : ℝ) ≤ (A.card : ℝ) * A.card := by have h' : ((∑ x ∈ D, rep A x : ℕ) : ℝ) ≤ ((A.card * A.card : ℕ) : ℝ) := by exact_mod_cast sum_rep_le A D push_cast at h' exact h' have hsplit : ∑ x ∈ D, ((A.card : ℝ) - rep A x) = (D.card : ℝ) * A.card - ∑ x ∈ D, (rep A x : ℝ) := by rw [sum_sub_distrib, sum_const, nsmul_eq_mul] rw [hsplit] at hle2 have h12 : 0 ≤ (1 - 2 * t) * (A.card : ℝ) := mul_nonneg (by linarith) hKpos.le have h4 : (1 - 2 * t) * (A.card : ℝ) * ∑ x ∈ D, (rep A x : ℝ) ≤ (1 - 2 * t) * (A.card : ℝ) * ((A.card : ℝ) * A.card) := mul_le_mul_of_nonneg_left hle3 h12 have e : (D.card : ℝ) * (1 - 2 * t) * A.card * A.card = (1 - 2 * t) * (A.card : ℝ) * ((D.card : ℝ) * A.card) := by ring have h5 : (D.card : ℝ) * (1 - 2 * t) * A.card * A.card ≤ ((1 - 2 * t) * (A.card : ℝ) ^ 2 + δ * (A.card : ℝ) ^ 2) * A.card := by have : ((1 - 2 * t) * (A.card : ℝ) ^ 2 + δ * (A.card : ℝ) ^ 2) * A.card = (1 - 2 * t) * (A.card : ℝ) * ((A.card : ℝ) * A.card) + δ * (A.card : ℝ) ^ 3 := by ring rw [e, this] linarith exact le_of_mul_le_mul_right h5 hKpos /-- C1′ step 4a: outside the fullest coset, `rep d ≤ 2 m`. -/ theorem c1p_rep_out (A D : Finset G) (hDmul : ∀ x ∈ D, ∀ y ∈ D, x * y ∈ D) (hDinv : ∀ x ∈ D, x⁻¹ ∈ D) (b₀ d : G) (hd : ¬ (d ∈ D)) : rep A d ≤ 2 * (A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card := by unfold rep have hsp := card_filter_add_card_filter_not (s := A.filter (fun b => d * b ∈ A)) (fun b => b * b₀⁻¹ ∈ D) have h1 : ((A.filter (fun b => d * b ∈ A)).filter (fun b => ¬ (b * b₀⁻¹ ∈ D))).card ≤ (A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card := by apply card_le_card intro b hb simp only [mem_filter] at hb ⊢ exact ⟨hb.1.1, hb.2⟩ have h2 : ((A.filter (fun b => d * b ∈ A)).filter (fun b => b * b₀⁻¹ ∈ D)).card ≤ (A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card := by apply card_le_card_of_injOn (fun b => d * b) · intro b hb simp only [mem_coe, mem_filter] at hb ⊢ refine ⟨hb.1.2, fun hdb => hd ?_⟩ have := hDmul _ hdb _ (hDinv _ hb.2) have e : d * b * b₀⁻¹ * (b * b₀⁻¹)⁻¹ = d := by group rwa [e] at this · exact (mul_right_injective d).injOn omega /-- C1′ step 4b: coset counting `c₀² ≤ ∑_b c(b) ≤ c₀² + m²`. -/ theorem c1p_cosets (A D : Finset G) (hDmul : ∀ x ∈ D, ∀ y ∈ D, x * y ∈ D) (hDinv : ∀ x ∈ D, x⁻¹ ∈ D) (b₀ : G) (hmax : ∀ b ∈ A, (A.filter (fun a => a * b⁻¹ ∈ D)).card ≤ (A.filter (fun a => a * b₀⁻¹ ∈ D)).card) : ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) ^ 2 ≤ ∑ b ∈ A, ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) ∧ ∑ b ∈ A, ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) ≤ ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) ^ 2 + ((A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card : ℝ) ^ 2 := by set c₀ := (A.filter (fun a => a * b₀⁻¹ ∈ D)).card with hc₀ set mo := (A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card with hmo have hsp := sum_filter_add_sum_filter_not A (fun b => b * b₀⁻¹ ∈ D) (fun b => ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ)) have hconst : ∀ b ∈ A.filter (fun b => b * b₀⁻¹ ∈ D), ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) = c₀ := by intro b hb rw [mem_filter] at hb have : A.filter (fun a => a * b⁻¹ ∈ D) = A.filter (fun a => a * b₀⁻¹ ∈ D) := by apply filter_congr intro a _ constructor · intro h have := hDmul _ h _ hb.2 have e : a * b⁻¹ * (b * b₀⁻¹) = a * b₀⁻¹ := by group rwa [e] at this · intro h have := hDmul _ h _ (hDinv _ hb.2) have e : a * b₀⁻¹ * (b * b₀⁻¹)⁻¹ = a * b⁻¹ := by group rwa [e] at this rw [this] have hin : ∑ b ∈ A.filter (fun b => b * b₀⁻¹ ∈ D), ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) = (c₀ : ℝ) * c₀ := by rw [sum_congr rfl hconst, sum_const, nsmul_eq_mul] have hout_le : ∀ b ∈ A.filter (fun b => ¬ (b * b₀⁻¹ ∈ D)), ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) ≤ mo := by intro b hb rw [mem_filter] at hb have : A.filter (fun a => a * b⁻¹ ∈ D) ⊆ A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D)) := by intro a ha rw [mem_filter] at ha ⊢ refine ⟨ha.1, fun hab₀ => hb.2 ?_⟩ have := hDmul _ (hDinv _ ha.2) _ hab₀ have e : (a * b⁻¹)⁻¹ * (a * b₀⁻¹) = b * b₀⁻¹ := by group rwa [e] at this exact_mod_cast card_le_card this have hout : ∑ b ∈ A.filter (fun b => ¬ (b * b₀⁻¹ ∈ D)), ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) ≤ (mo : ℝ) * mo := by have := sum_le_card_nsmul (A.filter (fun b => ¬ (b * b₀⁻¹ ∈ D))) (fun b => ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ)) (mo : ℝ) hout_le rw [nsmul_eq_mul] at this exact this have hout0 : 0 ≤ ∑ b ∈ A.filter (fun b => ¬ (b * b₀⁻¹ ∈ D)), ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) := sum_nonneg (fun b _ => Nat.cast_nonneg _) constructor · rw [← hsp, hin]; nlinarith · rw [← hsp, hin]; nlinarith /-- C1′ step 4c: `E ≤ K ∑c + 2m (K² − ∑c)`. -/ theorem c1p_energy_le (A D : Finset G) (hDmul : ∀ x ∈ D, ∀ y ∈ D, x * y ∈ D) (hDinv : ∀ x ∈ D, x⁻¹ ∈ D) (b₀ : G) : (energy A : ℝ) ≤ (A.card : ℝ) * ∑ b ∈ A, ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) + 2 * ((A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card : ℝ) * ((A.card : ℝ) ^ 2 - ∑ b ∈ A, ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ)) := by set mo := (A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card with hmo have hper : ∀ b ∈ A, ∑ a ∈ A, (rep A (a * b⁻¹) : ℝ) ≤ (A.card : ℝ) * ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) + 2 * (mo : ℝ) * ((A.card : ℝ) - ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ)) := by intro b _ have hsp := sum_filter_add_sum_filter_not A (fun a => a * b⁻¹ ∈ D) (fun a => (rep A (a * b⁻¹) : ℝ)) rw [← hsp] have h1 := sum_le_card_nsmul (A.filter (fun a => a * b⁻¹ ∈ D)) (fun a => (rep A (a * b⁻¹) : ℝ)) (A.card : ℝ) (fun a _ => by exact_mod_cast rep_le A (a * b⁻¹)) rw [nsmul_eq_mul] at h1 have h2 := sum_le_card_nsmul (A.filter (fun a => ¬ (a * b⁻¹ ∈ D))) (fun a => (rep A (a * b⁻¹) : ℝ)) (2 * (mo : ℝ)) (fun a ha => by exact_mod_cast c1p_rep_out A D hDmul hDinv b₀ _ (mem_filter.mp ha).2) rw [nsmul_eq_mul] at h2 have hcard := card_filter_add_card_filter_not (s := A) (fun a => a * b⁻¹ ∈ D) have hcard' : ((A.filter (fun a => ¬ (a * b⁻¹ ∈ D))).card : ℝ) = (A.card : ℝ) - ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) := by have h' : ((A.filter (fun a => a * b⁻¹ ∈ D)).card + (A.filter (fun a => ¬ (a * b⁻¹ ∈ D))).card : ℝ) = (A.card : ℝ) := by exact_mod_cast hcard linarith rw [hcard'] at h2 have e : (A.card : ℝ) * ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) = ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) * A.card := by ring linarith have hsum := sum_le_sum hper have hdef : (energy A : ℝ) = ∑ b ∈ A, ∑ a ∈ A, (rep A (a * b⁻¹) : ℝ) := by unfold energy push_cast rfl rw [hdef] refine le_trans hsum (le_of_eq ?_) rw [sum_add_distrib, ← mul_sum, ← mul_sum, sum_sub_distrib, sum_const, nsmul_eq_mul] ring /-- C1′ step 4d: arithmetic, `2 m K − 6 m² ≤ δ K²`. -/ theorem c1p_arith {K c₀ mo S E δ : ℝ} (hK : 0 < K) (hcm : c₀ + mo = K) (hmo0 : 0 ≤ mo) (hhalf : 2 * mo ≤ K) (hS1 : c₀ ^ 2 ≤ S) (hS2 : S ≤ c₀ ^ 2 + mo ^ 2) (hE1 : E ≤ K * S + 2 * mo * (K ^ 2 - S)) (hE2 : (1 - δ) * K ^ 3 ≤ E) : 2 * mo * K - 6 * mo ^ 2 ≤ δ * K ^ 2 := by have hK2m : 0 ≤ K - 2 * mo := by linarith have h1 : K * S + 2 * mo * (K ^ 2 - S) = (K - 2 * mo) * S + 2 * mo * K ^ 2 := by ring have h2 : (K - 2 * mo) * S ≤ (K - 2 * mo) * (c₀ ^ 2 + mo ^ 2) := mul_le_mul_of_nonneg_left hS2 hK2m have hc : c₀ = K - mo := by linarith rw [hc] at h2 have h3 : (1 - δ) * K ^ 3 ≤ K ^ 3 - 2 * mo * K ^ 2 + 6 * mo ^ 2 * K - 4 * mo ^ 3 := by nlinarith have h4 : (2 * mo * K - 6 * mo ^ 2) * K ≤ δ * K ^ 2 * K := by nlinarith [pow_nonneg hmo0 3] exact le_of_mul_le_mul_right h4 hK /-- **Lemma C1′.** If `E(A) ≥ (1 − δ)K³`, `0 < t`, `2t < 1`, `0 ≤ δ` and `2 < 3 (1 − 2t)(1 − δ/t)`, then there is a subgroup `H = D` with `(1 − δ/t)K ≤ |D|`, `|D|(1 − 2t)K ≤ (1 − 2t)K² + δK²`, every `d ∈ D` has `rep d ≥ (1 − 2t)K`, and a coset `D b` with `#(A ∩ D b) ≥ (1 − δ/t)K` whose defect `m = K − #(A ∩ D b)` satisfies `2 m K − 6 m² ≤ δ K²`. -/ theorem C1p (A : Finset G) (hA : A.Nonempty) (t δ : ℝ) (ht0 : 0 < t) (ht2 : 2 * t < 1) (hδ0 : 0 ≤ δ) (h32 : 2 < 3 * (1 - 2 * t) * (1 - δ / t)) (hE : (1 - δ) * (A.card : ℝ) ^ 3 ≤ (energy A : ℝ)) : ∃ H : Subgroup G, ∃ D : Finset G, (∀ x, x ∈ H ↔ x ∈ D) ∧ (1 - δ / t) * (A.card : ℝ) ≤ D.card ∧ (D.card : ℝ) * (1 - 2 * t) * A.card ≤ (1 - 2 * t) * (A.card : ℝ) ^ 2 + δ * (A.card : ℝ) ^ 2 ∧ (∀ d ∈ D, (1 - 2 * t) * (A.card : ℝ) ≤ rep A d) ∧ ∃ b ∈ A, (1 - δ / t) * (A.card : ℝ) ≤ (A.filter (fun a => a * b⁻¹ ∈ D)).card ∧ 2 * ((A.card : ℝ) - (A.filter (fun a => a * b⁻¹ ∈ D)).card) * A.card - 6 * ((A.card : ℝ) - (A.filter (fun a => a * b⁻¹ ∈ D)).card) ^ 2 ≤ δ * (A.card : ℝ) ^ 2 := by have hKpos : (0 : ℝ) < A.card := by exact_mod_cast hA.card_pos obtain ⟨hSB, hB⟩ := c1p_B A hA t δ ht0 hE obtain ⟨hrep_mul, hQ⟩ := c1p_doubling A hA t δ ht2 h32 hB set B := popular A ((1 - t) * A.card) with hBdef set D := B⁻¹ * B with hD have hmemD : ∀ x, x ∈ invMulSubgroup B hQ ↔ x ∈ D := by intro x have e : ((invMulSubgroup B hQ : Subgroup G) : Set G) = ((B⁻¹ * B : Finset G) : Set G) := by rw [invMulSubgroup_eq_inv_mul, coe_mul, coe_inv] rw [← SetLike.mem_coe, e, mem_coe] have hDmul : ∀ x ∈ D, ∀ y ∈ D, x * y ∈ D := by intro x hx y hy rw [← hmemD] at hx hy ⊢ exact (invMulSubgroup B hQ).mul_mem hx hy have hDinv : ∀ x ∈ D, x⁻¹ ∈ D := by intro x hx rw [← hmemD] at hx ⊢ exact (invMulSubgroup B hQ).inv_mem hx have h1B : (1 : G) ∈ B := by obtain ⟨a, ha⟩ := hA refine mem_filter.mpr ⟨?_, ?_⟩ · rw [mem_mul] exact ⟨a, ha, a⁻¹, inv_mem_inv ha, mul_inv_cancel a⟩ · rw [rep_one] nlinarith have hsub : B ⊆ D := by intro x hx have := mul_mem_mul (inv_mem_inv h1B) hx rwa [inv_one, one_mul] at this have hD_lower : (1 - δ / t) * (A.card : ℝ) ≤ D.card := by have : (B.card : ℝ) ≤ D.card := by exact_mod_cast card_le_card hsub linarith have hrepD : ∀ d ∈ D, (1 - 2 * t) * (A.card : ℝ) ≤ rep A d := by intro d hd obtain ⟨x, hx, y, hy, rfl⟩ := mem_mul.mp hd have hx' : x⁻¹ ∈ B := Finset.mem_inv'.mp hx have hxr : (1 - t) * (A.card : ℝ) ≤ rep A x := by have h1 := le_rep_of_mem_popular hx' rwa [rep_inv] at h1 have hyr := le_rep_of_mem_popular hy have hm : ((rep A x + rep A y : ℕ) : ℝ) ≤ ((rep A (x * y) + A.card : ℕ) : ℝ) := by exact_mod_cast rep_mul A x y push_cast at hm linarith have hD_upper := c1p_card_le A D hA t δ ht2 hrepD hE obtain ⟨b₀, hb₀, hmax⟩ := exists_max_image A (fun b => (A.filter (fun a => a * b⁻¹ ∈ D)).card) hA -- the fullest coset holds at least (1 − δ/t) K points have hsumc : ∑ b ∈ A, ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ) = ∑ x ∈ D, (rep A x : ℝ) := by have h' : ((∑ x ∈ D, rep A x : ℕ) : ℝ) = ((∑ b ∈ A, (A.filter (fun a => a * b⁻¹ ∈ D)).card : ℕ) : ℝ) := by rw [sum_rep_eq] push_cast at h' linarith have hBD : ∑ x ∈ B, (rep A x : ℝ) ≤ ∑ x ∈ D, (rep A x : ℝ) := sum_le_sum_of_subset_of_nonneg hsub (fun x _ _ => Nat.cast_nonneg _) have hmaxR := sum_le_card_nsmul A (fun b => ((A.filter (fun a => a * b⁻¹ ∈ D)).card : ℝ)) ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) (fun b hb => by exact_mod_cast hmax b hb) rw [nsmul_eq_mul] at hmaxR have hc0' : (1 - δ / t) * (A.card : ℝ) * A.card ≤ ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) * A.card := by have : (1 - δ / t) * (A.card : ℝ) * A.card ≤ (A.card : ℝ) * ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) := by linarith linarith have hc0 : (1 - δ / t) * (A.card : ℝ) ≤ ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) := le_of_mul_le_mul_right hc0' hKpos refine ⟨invMulSubgroup B hQ, D, hmemD, hD_lower, hD_upper, hrepD, b₀, hb₀, hc0, ?_⟩ -- defect arithmetic obtain ⟨hS1, hS2⟩ := c1p_cosets A D hDmul hDinv b₀ hmax have hE1 := c1p_energy_le A D hDmul hDinv b₀ have hcard := card_filter_add_card_filter_not (s := A) (fun a => a * b₀⁻¹ ∈ D) have hcm : ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) + ((A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card : ℝ) = A.card := by exact_mod_cast hcard have hhalf : 2 * ((A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card : ℝ) ≤ A.card := by have hδt : 1 / 2 < 1 - δ / t := by by_contra h have h' : 1 - δ / t ≤ 1 / 2 := not_lt.mp h have h3 : 3 * (1 - 2 * t) * (1 - δ / t) ≤ 3 * (1 - 2 * t) * (1 / 2) := mul_le_mul_of_nonneg_left h' (le_of_lt (by linarith : (0 : ℝ) < 3 * (1 - 2 * t))) linarith nlinarith have hmo0 : (0 : ℝ) ≤ ((A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card : ℝ) := Nat.cast_nonneg _ have key := c1p_arith hKpos hcm hmo0 hhalf hS1 hS2 hE1 hE have e : (A.card : ℝ) - ((A.filter (fun a => a * b₀⁻¹ ∈ D)).card : ℝ) = ((A.filter (fun a => ¬ (a * b₀⁻¹ ∈ D))).card : ℝ) := by linarith rw [e] linarith end C1p end Erdos94ThmA /-! THEOREM-A scratch: the isometry module for Lemma B, done in `ℂ`. Reflections are the maps `z ↦ a + ζ * conj z` with `ζ * conj ζ = 1` and `a + ζ * conj a = 0`. * `six_chain`: for reflections σ₁ σ₂ σ₃ and `g = σ₂ ∘ σ₁`, the map `g ∘ σ₃ ∘ g ∘ σ₃` is a translation. * `par_translation` (I3 input): if `σ₂ ∘ σ₁` has trivial rotation part and `σ₁ ≠ σ₂`, it is a nonzero translation. * `chain_translation_ne` (I1 input): if the rotation part is nontrivial and `σ₃` moves the fixed point of `σ₂ ∘ σ₁`, the six-chain is a nonzero translation. * `bis p q`: reflection in the perpendicular bisector of `p ≠ q`; `bis p q p = q`, involutive, and `bis p q w = w ↔ ‖w - p‖ = ‖w - q‖`. Static-policy shaped body (to sit inside `namespace Bounty`). -/ namespace Erdos94ThmA open Complex /-- The orientation-reversing affine map `z ↦ a + ζ * conj z`. -/ noncomputable def arefl (a ζ : ℂ) (z : ℂ) : ℂ := a + ζ * (starRingEnd ℂ) z theorem arefl_arefl (a₁ ζ₁ a₂ ζ₂ z : ℂ) : arefl a₂ ζ₂ (arefl a₁ ζ₁ z) = (a₂ + ζ₂ * (starRingEnd ℂ) a₁) + (ζ₂ * (starRingEnd ℂ) ζ₁) * z := by simp only [arefl, map_add, map_mul, Complex.conj_conj] ring /-- A reflection is an involution. -/ theorem arefl_invol {a ζ : ℂ} (hζ : ζ * (starRingEnd ℂ) ζ = 1) (ha : a + ζ * (starRingEnd ℂ) a = 0) (z : ℂ) : arefl a ζ (arefl a ζ z) = z := by rw [arefl_arefl, ha, hζ, zero_add, one_mul] /-- The six-chain `σ₂σ₁σ₃σ₂σ₁σ₃` (i.e. `g σ₃ g σ₃` with `g = σ₂σ₁`) is a translation. -/ theorem six_chain (a₁ ζ₁ a₂ ζ₂ a₃ ζ₃ : ℂ) (h₁ : ζ₁ * (starRingEnd ℂ) ζ₁ = 1) (h₂ : ζ₂ * (starRingEnd ℂ) ζ₂ = 1) (h₃ : ζ₃ * (starRingEnd ℂ) ζ₃ = 1) (z : ℂ) : arefl a₂ ζ₂ (arefl a₁ ζ₁ (arefl a₃ ζ₃ (arefl a₂ ζ₂ (arefl a₁ ζ₁ (arefl a₃ ζ₃ z))))) = z + arefl a₂ ζ₂ (arefl a₁ ζ₁ (arefl a₃ ζ₃ (arefl a₂ ζ₂ (arefl a₁ ζ₁ (arefl a₃ ζ₃ 0))))) := by simp only [arefl, map_add, map_mul, Complex.conj_conj, map_zero, mul_zero, add_zero] linear_combination (z * (ζ₂ * (starRingEnd ℂ) ζ₂) * (ζ₃ * (starRingEnd ℂ) ζ₃)) * h₁ + (z * (ζ₃ * (starRingEnd ℂ) ζ₃)) * h₂ + z * h₃ /-- Parallel case: trivial rotation part and distinct reflections give a nonzero translation. -/ theorem par_translation {a₁ ζ₁ a₂ ζ₂ : ℂ} (h₂ : ζ₂ * (starRingEnd ℂ) ζ₂ = 1) (ha₂ : a₂ + ζ₂ * (starRingEnd ℂ) a₂ = 0) (hω : ζ₂ * (starRingEnd ℂ) ζ₁ = 1) (hne : arefl a₁ ζ₁ ≠ arefl a₂ ζ₂) : ∃ c : ℂ, c ≠ 0 ∧ ∀ z, arefl a₂ ζ₂ (arefl a₁ ζ₁ z) = z + c := by refine ⟨a₂ + ζ₂ * (starRingEnd ℂ) a₁, ?_, fun z => ?_⟩ · intro hc apply hne funext z have h := arefl_arefl a₁ ζ₁ a₂ ζ₂ z rw [hc, hω, zero_add, one_mul] at h -- σ₂ (σ₁ z) = z, apply σ₂ have := congrArg (arefl a₂ ζ₂) h rwa [arefl_invol h₂ ha₂] at this · rw [arefl_arefl, hω, one_mul, add_comm] /-- The rotation `σ₂ σ₁` (nontrivial rotation part `ω ≠ 1`) has the fixed point `w`. -/ theorem fixed_of_rot {a₁ ζ₁ a₂ ζ₂ : ℂ} (hω : ζ₂ * (starRingEnd ℂ) ζ₁ ≠ 1) : arefl a₂ ζ₂ (arefl a₁ ζ₁ ((a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁))) = (a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁) := by have h1 : (1 - ζ₂ * (starRingEnd ℂ) ζ₁) ≠ 0 := sub_ne_zero.mpr (Ne.symm hω) rw [arefl_arefl] field_simp ring /-- ... and it is the only one. -/ theorem fixed_unique {a₁ ζ₁ a₂ ζ₂ x : ℂ} (hω : ζ₂ * (starRingEnd ℂ) ζ₁ ≠ 1) (hx : arefl a₂ ζ₂ (arefl a₁ ζ₁ x) = x) : x = (a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁) := by have h1 : (1 - ζ₂ * (starRingEnd ℂ) ζ₁) ≠ 0 := sub_ne_zero.mpr (Ne.symm hω) rw [arefl_arefl] at hx rw [eq_div_iff h1] linear_combination -hx /-- (I1) input: if `σ₃` moves the fixed point of the nontrivial rotation `g = σ₂σ₁`, then `g σ₃ g σ₃` is a translation by a nonzero vector. -/ theorem chain_translation_ne {a₁ ζ₁ a₂ ζ₂ a₃ ζ₃ : ℂ} (h₁ : ζ₁ * (starRingEnd ℂ) ζ₁ = 1) (h₂ : ζ₂ * (starRingEnd ℂ) ζ₂ = 1) (h₃ : ζ₃ * (starRingEnd ℂ) ζ₃ = 1) (ha₃ : a₃ + ζ₃ * (starRingEnd ℂ) a₃ = 0) (hω : ζ₂ * (starRingEnd ℂ) ζ₁ ≠ 1) (hmove : arefl a₃ ζ₃ ((a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁)) ≠ (a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁)) : ∃ c : ℂ, c ≠ 0 ∧ ∀ z, arefl a₂ ζ₂ (arefl a₁ ζ₁ (arefl a₃ ζ₃ (arefl a₂ ζ₂ (arefl a₁ ζ₁ (arefl a₃ ζ₃ z))))) = z + c := by set w := (a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁) with hw refine ⟨_, ?_, six_chain a₁ ζ₁ a₂ ζ₂ a₃ ζ₃ h₁ h₂ h₃⟩ intro hc apply hmove -- evaluate the chain at `σ₃ w`: it equals `g (σ₃ w)`, and also `σ₃ w` have hchain := six_chain a₁ ζ₁ a₂ ζ₂ a₃ ζ₃ h₁ h₂ h₃ (arefl a₃ ζ₃ w) rw [hc, add_zero, arefl_invol h₃ ha₃, fixed_of_rot hω] at hchain -- hchain : g (σ₃ w) = σ₃ w, so σ₃ w is a fixed point of g exact fixed_unique hω hchain /-! ### Reflection in the perpendicular bisector of `p ≠ q` -/ /-- The rotation part `ζ = -(q - p) / conj (q - p)` of the bisector reflection. -/ noncomputable def bisZ (p q : ℂ) : ℂ := -(q - p) / (starRingEnd ℂ) (q - p) /-- The translation part `a = m - ζ conj m`, `m = (p + q)/2`. -/ noncomputable def bisA (p q : ℂ) : ℂ := (p + q) / 2 - bisZ p q * (starRingEnd ℂ) ((p + q) / 2) /-- Reflection in the perpendicular bisector of `p` and `q`. -/ noncomputable def bis (p q : ℂ) : ℂ → ℂ := arefl (bisA p q) (bisZ p q) theorem conj_ne_zero_of_ne {p q : ℂ} (h : p ≠ q) : (starRingEnd ℂ) (q - p) ≠ 0 := by rw [map_ne_zero] exact sub_ne_zero.mpr (Ne.symm h) theorem bisZ_norm {p q : ℂ} (h : p ≠ q) : bisZ p q * (starRingEnd ℂ) (bisZ p q) = 1 := by have h1 : q - p ≠ 0 := sub_ne_zero.mpr (Ne.symm h) have h2 := conj_ne_zero_of_ne h simp only [bisZ, map_div₀, map_neg, Complex.conj_conj] field_simp theorem bisA_invol {p q : ℂ} (h : p ≠ q) : bisA p q + bisZ p q * (starRingEnd ℂ) (bisA p q) = 0 := by have hz := bisZ_norm h simp only [bisA, map_sub, map_mul, Complex.conj_conj] linear_combination (-(p + q) / 2) * hz theorem bis_invol {p q : ℂ} (h : p ≠ q) (z : ℂ) : bis p q (bis p q z) = z := arefl_invol (bisZ_norm h) (bisA_invol h) z theorem bis_apply_left {p q : ℂ} (h : p ≠ q) : bis p q p = q := by have h1 : q - p ≠ 0 := sub_ne_zero.mpr (Ne.symm h) have h2 := conj_ne_zero_of_ne h simp only [bis, arefl, bisA, bisZ] field_simp simp only [map_sub, map_add, map_div₀, map_ofNat] ring /-- `σ_{pq}` fixes `w` exactly when `w` is equidistant from `p` and `q`. -/ theorem bis_fixed_iff {p q : ℂ} (h : p ≠ q) (w : ℂ) : bis p q w = w ↔ (w - p) * (starRingEnd ℂ) (w - p) = (w - q) * (starRingEnd ℂ) (w - q) := by have h2 := conj_ne_zero_of_ne h have key : bis p q w - w = -((w - p) * (starRingEnd ℂ) (w - p) - (w - q) * (starRingEnd ℂ) (w - q)) / (starRingEnd ℂ) (q - p) := by simp only [bis, arefl, bisA, bisZ] field_simp simp only [map_sub, map_add, map_div₀, map_ofNat] ring constructor · intro hw have : bis p q w - w = 0 := sub_eq_zero.mpr hw rw [key, div_eq_zero_iff] at this rcases this with h3 | h3 · exact sub_eq_zero.mp (neg_eq_zero.mp h3) · exact absurd h3 h2 · intro hw have : bis p q w - w = 0 := by rw [key, hw, sub_self, neg_zero, zero_div] exact sub_eq_zero.mp this end Erdos94ThmA /-! ### Counting with maps of `ℂ`: (G5), (T), (I3), (I1) -/ namespace Erdos94ThmA open Finset /-- `rC Q f = #{z ∈ Q : f z ∈ Q}`. -/ noncomputable def rC (Q : Finset ℂ) (f : ℂ → ℂ) : ℕ := (Q.filter (fun z => f z ∈ Q)).card /-- `muC Q f = #{z ∈ Q : f z ∉ Q}`. -/ noncomputable def muC (Q : Finset ℂ) (f : ℂ → ℂ) : ℕ := (Q.filter (fun z => f z ∉ Q)).card theorem rC_add_muC (Q : Finset ℂ) (f : ℂ → ℂ) : rC Q f + muC Q f = Q.card := card_filter_add_card_filter_not _ theorem rC_comp (Q : Finset ℂ) (f g : ℂ → ℂ) (hf : Function.Injective f) : rC Q f + rC Q g ≤ rC Q (fun z => g (f z)) + Q.card := card_filter_comp_add_card Q f g hf theorem rC_translate {Q : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (Q.filter (fun z => z + t ∈ Q)).card ≤ 2) {F : ℂ → ℂ} {c : ℂ} (hc : c ≠ 0) (hF : ∀ z, F z = z + c) : rC Q F ≤ 2 := by unfold rC have e : Q.filter (fun z => F z ∈ Q) = Q.filter (fun z => z + c ∈ Q) := filter_congr (fun z _ => by rw [hF]) rw [e] exact hT c hc theorem arefl_injective {a ζ : ℂ} (hζ : ζ * (starRingEnd ℂ) ζ = 1) (ha : a + ζ * (starRingEnd ℂ) a = 0) : Function.Injective (arefl a ζ) := Function.LeftInverse.injective (arefl_invol hζ ha) /-- Six-step chain counting: if `σ₂σ₁σ₃σ₂σ₁σ₃` is a nonzero translation then `2 (r σ₁ + r σ₂ + r σ₃) ≤ 5 n + 2`. -/ theorem chain6 {Q : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (Q.filter (fun z => z + t ∈ Q)).card ≤ 2) (σ₁ σ₂ σ₃ : ℂ → ℂ) (i₁ : Function.Injective σ₁) (i₂ : Function.Injective σ₂) (i₃ : Function.Injective σ₃) {c : ℂ} (hc : c ≠ 0) (hF : ∀ z, σ₂ (σ₁ (σ₃ (σ₂ (σ₁ (σ₃ z))))) = z + c) : 2 * (rC Q σ₁ + rC Q σ₂ + rC Q σ₃) ≤ 5 * Q.card + 2 := by have e1 : rC Q σ₃ + rC Q σ₁ ≤ rC Q (fun z => σ₁ (σ₃ z)) + Q.card := rC_comp Q _ _ i₃ have e2 : rC Q (fun z => σ₁ (σ₃ z)) + rC Q σ₂ ≤ rC Q (fun z => σ₂ (σ₁ (σ₃ z))) + Q.card := rC_comp Q _ _ (i₁.comp i₃) have e3 : rC Q (fun z => σ₂ (σ₁ (σ₃ z))) + rC Q σ₃ ≤ rC Q (fun z => σ₃ (σ₂ (σ₁ (σ₃ z)))) + Q.card := rC_comp Q _ _ (i₂.comp (i₁.comp i₃)) have e4 : rC Q (fun z => σ₃ (σ₂ (σ₁ (σ₃ z)))) + rC Q σ₁ ≤ rC Q (fun z => σ₁ (σ₃ (σ₂ (σ₁ (σ₃ z))))) + Q.card := rC_comp Q _ _ (i₃.comp (i₂.comp (i₁.comp i₃))) have e5 : rC Q (fun z => σ₁ (σ₃ (σ₂ (σ₁ (σ₃ z))))) + rC Q σ₂ ≤ rC Q (fun z => σ₂ (σ₁ (σ₃ (σ₂ (σ₁ (σ₃ z)))))) + Q.card := rC_comp Q _ _ (i₁.comp (i₃.comp (i₂.comp (i₁.comp i₃)))) have e6 : rC Q (fun z => σ₂ (σ₁ (σ₃ (σ₂ (σ₁ (σ₃ z)))))) ≤ 2 := rC_translate hT hc hF omega /-- (I3) in `ℂ`: two distinct reflections with trivial rotation part. -/ theorem I3_C {Q : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (Q.filter (fun z => z + t ∈ Q)).card ≤ 2) {a₁ ζ₁ a₂ ζ₂ : ℂ} (h₁ : ζ₁ * (starRingEnd ℂ) ζ₁ = 1) (ha₁ : a₁ + ζ₁ * (starRingEnd ℂ) a₁ = 0) (h₂ : ζ₂ * (starRingEnd ℂ) ζ₂ = 1) (ha₂ : a₂ + ζ₂ * (starRingEnd ℂ) a₂ = 0) (hω : ζ₂ * (starRingEnd ℂ) ζ₁ = 1) (hne : arefl a₁ ζ₁ ≠ arefl a₂ ζ₂) : rC Q (arefl a₁ ζ₁) + rC Q (arefl a₂ ζ₂) ≤ Q.card + 2 := by obtain ⟨c, hc, hF⟩ := par_translation h₂ ha₂ hω hne have h := rC_comp Q (arefl a₁ ζ₁) (arefl a₂ ζ₂) (arefl_injective h₁ ha₁) have h2 : rC Q (fun z => arefl a₂ ζ₂ (arefl a₁ ζ₁ z)) ≤ 2 := rC_translate hT hc hF omega /-- (I1) in `ℂ`, for `g = σ₂σ₁` with nontrivial rotation part and `σ₃` moving its centre. -/ theorem I1_C {Q : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (Q.filter (fun z => z + t ∈ Q)).card ≤ 2) {a₁ ζ₁ a₂ ζ₂ a₃ ζ₃ : ℂ} (h₁ : ζ₁ * (starRingEnd ℂ) ζ₁ = 1) (ha₁ : a₁ + ζ₁ * (starRingEnd ℂ) a₁ = 0) (h₂ : ζ₂ * (starRingEnd ℂ) ζ₂ = 1) (ha₂ : a₂ + ζ₂ * (starRingEnd ℂ) a₂ = 0) (h₃ : ζ₃ * (starRingEnd ℂ) ζ₃ = 1) (ha₃ : a₃ + ζ₃ * (starRingEnd ℂ) a₃ = 0) (hω : ζ₂ * (starRingEnd ℂ) ζ₁ ≠ 1) (hmove : arefl a₃ ζ₃ ((a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁)) ≠ (a₂ + ζ₂ * (starRingEnd ℂ) a₁) / (1 - ζ₂ * (starRingEnd ℂ) ζ₁)) : 2 * (rC Q (arefl a₁ ζ₁) + rC Q (arefl a₂ ζ₂) + rC Q (arefl a₃ ζ₃)) ≤ 5 * Q.card + 2 := by obtain ⟨c, hc, hF⟩ := chain_translation_ne h₁ h₂ h₃ ha₃ hω hmove exact chain6 hT _ _ _ (arefl_injective h₁ ha₁) (arefl_injective h₂ ha₂) (arefl_injective h₃ ha₃) hc hF /-! ### Lemma B -/ /-- Total reflection defect over ordered pairs (`= 2 M(P)`). -/ noncomputable def Mord (Q : Finset ℂ) : ℕ := ∑ pq ∈ Q.offDiag, muC Q (bis pq.1 pq.2) open Classical in theorem fiber_le (Q : Finset ℂ) (σ : ℂ → ℂ) (S : Finset (ℂ × ℂ)) (hS : S ⊆ Q.offDiag) : (S.filter (fun pq : ℂ × ℂ => bis pq.1 pq.2 = σ)).card ≤ Q.card := by apply card_le_card_of_injOn Prod.fst · intro pq hpq simp only [mem_coe, mem_filter] at hpq exact (mem_offDiag.mp (hS hpq.1)).1 · intro pq hpq pq' hpq' h simp only [mem_coe, mem_filter] at hpq hpq' have hne := (mem_offDiag.mp (hS hpq.1)).2.2 have hne' := (mem_offDiag.mp (hS hpq'.1)).2.2 have e1 : pq.2 = σ pq.1 := by rw [← hpq.2, bis_apply_left hne] have e2 : pq'.2 = σ pq'.1 := by rw [← hpq'.2, bis_apply_left hne'] exact Prod.ext h (by rw [e1, e2, h]) theorem norm_eq_of_mul_conj_eq {z z' : ℂ} (h : z * (starRingEnd ℂ) z = z' * (starRingEnd ℂ) z') : ‖z‖ = ‖z'‖ := by rw [Complex.mul_conj', Complex.mul_conj'] at h have h3 : ‖z‖ ^ 2 = ‖z'‖ ^ 2 := by exact_mod_cast h exact (sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)).mp h3 theorem ring_bound (Q : Finset ℂ) (w : ℂ) (hQ : Q.Nonempty) : ∃ q₀ ∈ Q, ((Q ×ˢ Q).filter (fun pq : ℂ × ℂ => ‖pq.1 - w‖ = ‖pq.2 - w‖)).card ≤ Q.card * (Q.filter (fun z => ‖z - w‖ = ‖q₀ - w‖)).card := by obtain ⟨q₀, hq₀, hmax⟩ := exists_max_image Q (fun q => (Q.filter (fun z => ‖z - w‖ = ‖q - w‖)).card) hQ refine ⟨q₀, hq₀, ?_⟩ have e : ((Q ×ˢ Q).filter (fun pq : ℂ × ℂ => ‖pq.1 - w‖ = ‖pq.2 - w‖)).card = ∑ q ∈ Q, (Q.filter (fun z => ‖z - w‖ = ‖q - w‖)).card := by rw [card_filter, sum_product_right] simp only [card_filter] rw [e] calc ∑ q ∈ Q, (Q.filter (fun z => ‖z - w‖ = ‖q - w‖)).card ≤ ∑ _q ∈ Q, (Q.filter (fun z => ‖z - w‖ = ‖q₀ - w‖)).card := sum_le_sum (fun q hq => hmax q hq) _ = Q.card * (Q.filter (fun z => ‖z - w‖ = ‖q₀ - w‖)).card := by rw [sum_const, smul_eq_mul] /-- Few bad pairs. -/ theorem bad_le (Q : Finset ℂ) (hQ : 0 < Q.card) (η : ℝ) (hM : (Mord Q : ℝ) ≤ 2 * η * (Q.card : ℝ) ^ 3) : ((Q.offDiag.filter (fun pq : ℂ × ℂ => ¬ (7 * (muC Q (bis pq.1 pq.2) : ℝ) ≤ Q.card))).card : ℝ) ≤ 14 * η * (Q.card : ℝ) ^ 2 := by set bad := Q.offDiag.filter (fun pq : ℂ × ℂ => ¬ (7 * (muC Q (bis pq.1 pq.2) : ℝ) ≤ Q.card)) with hbad have hnR : (0 : ℝ) < Q.card := by exact_mod_cast hQ have h1 : ∑ pq ∈ bad, muC Q (bis pq.1 pq.2) ≤ Mord Q := sum_le_sum_of_subset (filter_subset _ _) have h2 : (bad.card : ℝ) * ((Q.card : ℝ) / 7) ≤ ∑ pq ∈ bad, (muC Q (bis pq.1 pq.2) : ℝ) := by have := card_nsmul_le_sum bad (fun pq : ℂ × ℂ => (muC Q (bis pq.1 pq.2) : ℝ)) ((Q.card : ℝ) / 7) (fun pq hpq => by have h := not_le.mp (mem_filter.mp hpq).2 linarith) rwa [nsmul_eq_mul] at this have h3 : (∑ pq ∈ bad, (muC Q (bis pq.1 pq.2) : ℝ)) ≤ (Mord Q : ℝ) := by exact_mod_cast h1 have h4 : (bad.card : ℝ) * ((Q.card : ℝ) / 7) ≤ 2 * η * (Q.card : ℝ) ^ 3 := by linarith have h5 : (bad.card : ℝ) * Q.card ≤ 14 * η * (Q.card : ℝ) ^ 2 * Q.card := by nlinarith exact le_of_mul_le_mul_right h5 hnR /-- **Lemma B** (in `ℂ`, for any point set satisfying the translation lemma). If `|Q| = n ≥ 15`, `η < 1/28` and the ordered reflection defect is at most `2ηn³` (i.e. `M ≤ ηn³`), then some circle of positive radius contains at least `n − 14ηn` points of `Q`. -/ theorem lemmaB (Q : Finset ℂ) (hT : ∀ t : ℂ, t ≠ 0 → (Q.filter (fun z => z + t ∈ Q)).card ≤ 2) (hn : 15 ≤ Q.card) (η : ℝ) (hη : η < 1 / 28) (hM : (Mord Q : ℝ) ≤ 2 * η * (Q.card : ℝ) ^ 3) : ∃ O : ℂ, ∃ ρ : ℝ, 0 < ρ ∧ (Q.card : ℝ) - 14 * η * Q.card ≤ ((Q.filter (fun z => ‖z - O‖ = ρ)).card : ℝ) := by have hnR : (15 : ℝ) ≤ Q.card := by exact_mod_cast hn have hQpos : 0 < Q.card := by omega set good := Q.offDiag.filter (fun pq : ℂ × ℂ => 7 * (muC Q (bis pq.1 pq.2) : ℝ) ≤ Q.card) with hgood set bad := Q.offDiag.filter (fun pq : ℂ × ℂ => ¬ (7 * (muC Q (bis pq.1 pq.2) : ℝ) ≤ Q.card)) with hbad have hbad_le : (bad.card : ℝ) ≤ 14 * η * (Q.card : ℝ) ^ 2 := bad_le Q hQpos η hM have hgb : good.card + bad.card = Q.offDiag.card := card_filter_add_card_filter_not _ have hoff : Q.offDiag.card + Q.card = Q.card * Q.card := by rw [offDiag_card, Nat.sub_add_cancel (Nat.le_mul_self _)] -- good pairs: many, and each has `7 r ≥ 6 n` have hgoodR : (Q.card : ℝ) < good.card := by have h1 : ((good.card + bad.card : ℕ) : ℝ) + Q.card = (Q.card : ℝ) * Q.card := by rw [hgb]; exact_mod_cast hoff push_cast at h1 nlinarith [mul_lt_mul_of_pos_right hη (by positivity : (0 : ℝ) < (Q.card : ℝ) ^ 2), mul_le_mul_of_nonneg_right hnR (by positivity : (0 : ℝ) ≤ Q.card)] have hr_good : ∀ pq ∈ good, 6 * Q.card ≤ 7 * rC Q (bis pq.1 pq.2) := by intro pq hpq have h := (mem_filter.mp hpq).2 have h2 := rC_add_muC Q (bis pq.1 pq.2) have h3 : (7 * muC Q (bis pq.1 pq.2) : ℝ) ≤ Q.card := by exact_mod_cast h have h4 : 7 * muC Q (bis pq.1 pq.2) ≤ Q.card := by exact_mod_cast h3 omega have hne_pq : ∀ pq ∈ good, pq.1 ≠ pq.2 := fun pq hpq => (mem_offDiag.mp (mem_filter.mp hpq).1).2.2 -- two good pairs with different bisector reflections have hgood_ne : good.Nonempty := by rw [← card_pos] have : (0 : ℝ) < good.card := by linarith exact_mod_cast this obtain ⟨pq₁, hpq₁⟩ := hgood_ne have hfib := fiber_le Q (bis pq₁.1 pq₁.2) good (filter_subset _ _) have hQg : Q.card < good.card := by have : (Q.card : ℝ) < good.card := hgoodR exact_mod_cast this have hlt := lt_of_le_of_lt hfib hQg obtain ⟨pq₂, hpq₂, hpq₂n⟩ := exists_mem_notMem_of_card_lt_card hlt have hσ : bis pq₂.1 pq₂.2 ≠ bis pq₁.1 pq₁.2 := by intro h classical exact hpq₂n (mem_filter.mpr ⟨hpq₂, h⟩) have h₁ := bisZ_norm (hne_pq pq₁ hpq₁) have ha₁ := bisA_invol (hne_pq pq₁ hpq₁) have h₂ := bisZ_norm (hne_pq pq₂ hpq₂) have ha₂ := bisA_invol (hne_pq pq₂ hpq₂) have hr₁ := hr_good pq₁ hpq₁ have hr₂ := hr_good pq₂ hpq₂ by_cases hω : bisZ pq₂.1 pq₂.2 * (starRingEnd ℂ) (bisZ pq₁.1 pq₁.2) = 1 · -- parallel bisectors: (I3) contradicts `7 r ≥ 6 n` exfalso have h := I3_C (Q := Q) hT h₁ ha₁ h₂ ha₂ hω (fun h => hσ h.symm) have h' : rC Q (bis pq₁.1 pq₁.2) + rC Q (bis pq₂.1 pq₂.2) ≤ Q.card + 2 := h omega · -- concurrent bisectors through `w` set w := (bisA pq₂.1 pq₂.2 + bisZ pq₂.1 pq₂.2 * (starRingEnd ℂ) (bisA pq₁.1 pq₁.2)) / (1 - bisZ pq₂.1 pq₂.2 * (starRingEnd ℂ) (bisZ pq₁.1 pq₁.2)) with hw have hfix : ∀ pq ∈ good, bis pq.1 pq.2 w = w := by intro pq hpq by_contra hmove have h₃ := bisZ_norm (hne_pq pq hpq) have ha₃ := bisA_invol (hne_pq pq hpq) have h := I1_C (Q := Q) hT h₁ ha₁ h₂ ha₂ h₃ ha₃ hω hmove have h' : 2 * (rC Q (bis pq₁.1 pq₁.2) + rC Q (bis pq₂.1 pq₂.2) + rC Q (bis pq.1 pq.2)) ≤ 5 * Q.card + 2 := h have hr₃ := hr_good pq hpq omega -- pairs in different rings around `w` are bad have hcross : ((Q ×ˢ Q).filter (fun pq : ℂ × ℂ => ¬ (‖pq.1 - w‖ = ‖pq.2 - w‖))) ⊆ bad := by intro pq hpq rw [mem_filter, mem_product] at hpq have hpq_ne : pq.1 ≠ pq.2 := by intro h apply hpq.2 rw [h] refine mem_filter.mpr ⟨mem_offDiag.mpr ⟨hpq.1.1, hpq.1.2, hpq_ne⟩, ?_⟩ intro hgoodpred have hg : pq ∈ good := mem_filter.mpr ⟨mem_offDiag.mpr ⟨hpq.1.1, hpq.1.2, hpq_ne⟩, hgoodpred⟩ have hf := hfix pq hg rw [bis_fixed_iff hpq_ne] at hf have := norm_eq_of_mul_conj_eq hf apply hpq.2 rw [norm_sub_rev, this, norm_sub_rev] obtain ⟨q₀, hq₀, hring⟩ := ring_bound Q w (card_pos.mp hQpos) have hsplit := card_filter_add_card_filter_not (s := Q ×ˢ Q) (fun pq : ℂ × ℂ => ‖pq.1 - w‖ = ‖pq.2 - w‖) rw [card_product] at hsplit have hcross_card := card_le_card hcross set n₁ := (Q.filter (fun z => ‖z - w‖ = ‖q₀ - w‖)).card with hn₁def -- n · n₁ ≥ n² − #bad have hmain : (Q.card : ℝ) * Q.card - 14 * η * (Q.card : ℝ) ^ 2 ≤ (Q.card : ℝ) * n₁ := by have e1 : (((Q ×ˢ Q).filter (fun pq : ℂ × ℂ => ‖pq.1 - w‖ = ‖pq.2 - w‖)).card : ℝ) + (((Q ×ˢ Q).filter (fun pq : ℂ × ℂ => ¬ (‖pq.1 - w‖ = ‖pq.2 - w‖))).card : ℝ) = (Q.card : ℝ) * Q.card := by exact_mod_cast hsplit have e2 : (((Q ×ˢ Q).filter (fun pq : ℂ × ℂ => ‖pq.1 - w‖ = ‖pq.2 - w‖)).card : ℝ) ≤ (Q.card : ℝ) * n₁ := by exact_mod_cast hring have e3 : (((Q ×ˢ Q).filter (fun pq : ℂ × ℂ => ¬ (‖pq.1 - w‖ = ‖pq.2 - w‖))).card : ℝ) ≤ bad.card := by exact_mod_cast hcross_card linarith have hn₁ : (Q.card : ℝ) - 14 * η * Q.card ≤ n₁ := by have hpos : (0 : ℝ) < Q.card := by linarith have h2 : ((Q.card : ℝ) - 14 * η * Q.card) * Q.card ≤ (n₁ : ℝ) * Q.card := by nlinarith exact le_of_mul_le_mul_right h2 hpos refine ⟨w, ‖q₀ - w‖, ?_, hn₁⟩ -- the radius is positive: a ring of radius 0 has at most one point rcases (norm_nonneg (q₀ - w)).lt_or_eq with hρ | hρ · exact hρ · exfalso have hsub : Q.filter (fun z => ‖z - w‖ = ‖q₀ - w‖) ⊆ {w} := by intro z hz rw [mem_filter, ← hρ, norm_eq_zero, sub_eq_zero] at hz exact mem_singleton.mpr hz.2 have h1 : n₁ ≤ 1 := by have := card_le_card hsub rwa [card_singleton] at this have h2 : (n₁ : ℝ) ≤ 1 := by exact_mod_cast h1 nlinarith [mul_lt_mul_of_pos_right hη (by linarith : (0 : ℝ) < Q.card)] /-! ### Transfer from the plane `EuclideanSpace ℝ (Fin 2)` to `ℂ` -/ theorem translate_card_le_two_C {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) {t : ℂ} (ht : t ≠ 0) : ((P.image Complex.orthonormalBasisOneI.repr.symm).filter (fun z => z + t ∈ P.image Complex.orthonormalBasisOneI.repr.symm)).card ≤ 2 := by set e := Complex.orthonormalBasisOneI.repr.symm with he have ht' : e.symm t ≠ 0 := by intro h apply ht have := congrArg e h rwa [LinearIsometryEquiv.apply_symm_apply, map_zero] at this refine le_trans ?_ (translate_card_le_two hP ht') apply card_le_card_of_injOn e.symm · intro z hz simp only [mem_coe, mem_filter, mem_image] at hz ⊢ obtain ⟨⟨x, hx, rfl⟩, ⟨y, hy, hxy⟩⟩ := hz refine ⟨by rw [LinearIsometryEquiv.symm_apply_apply]; exact hx, ?_⟩ have h1 : e.symm (e x + t) = y := by rw [← hxy, LinearIsometryEquiv.symm_apply_apply] rw [map_add, LinearIsometryEquiv.symm_apply_apply] at h1 rw [LinearIsometryEquiv.symm_apply_apply, h1] exact hy · exact e.symm.injective.injOn /-- **Lemma B** for a convex-independent set of the plane (identified with `ℂ`). -/ theorem lemmaB_plane {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) (hn : 15 ≤ P.card) (η : ℝ) (hη : η < 1 / 28) (hM : (Mord (P.image Complex.orthonormalBasisOneI.repr.symm) : ℝ) ≤ 2 * η * (P.card : ℝ) ^ 3) : ∃ O : ℂ, ∃ ρ : ℝ, 0 < ρ ∧ (P.card : ℝ) - 14 * η * P.card ≤ (((P.image Complex.orthonormalBasisOneI.repr.symm).filter (fun z => ‖z - O‖ = ρ)).card : ℝ) := by have hcard : (P.image Complex.orthonormalBasisOneI.repr.symm).card = P.card := card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective have h := lemmaB (P.image Complex.orthonormalBasisOneI.repr.symm) (fun t ht => translate_card_le_two_C hP ht) (by rw [hcard]; exact hn) η hη (by rw [hcard]; exact hM) rwa [hcard] at h end Erdos94ThmA /-! ### Theorem A′ (THEOREM_A §12.3): the cross-pair lemma -/ namespace Erdos94ThmA open Finset /-- (12.3) If two bisector reflections with distinct axes both fix `O`, and `p, p'` are at different distances from `O`, then `2 (r σ₁ + r σ₂ + r σ_{pp'}) ≤ 5 n + 2`, i.e. `μ(σ_{pp'}) ≥ n/2 − 1 − μ(σ₁) − μ(σ₂)`. -/ theorem cross_pair {Q : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (Q.filter (fun z => z + t ∈ Q)).card ≤ 2) {O p₁ q₁ p₂ q₂ p p' : ℂ} (h₁ : p₁ ≠ q₁) (h₂ : p₂ ≠ q₂) (hO₁ : bis p₁ q₁ O = O) (hO₂ : bis p₂ q₂ O = O) (hne : bis p₁ q₁ ≠ bis p₂ q₂) (hpp : p ≠ p') (hO : ‖p - O‖ ≠ ‖p' - O‖) : 2 * (rC Q (bis p₁ q₁) + rC Q (bis p₂ q₂) + rC Q (bis p p')) ≤ 5 * Q.card + 2 := by have hz₁ := bisZ_norm h₁ have ha₁ := bisA_invol h₁ have hz₂ := bisZ_norm h₂ have ha₂ := bisA_invol h₂ have hz₃ := bisZ_norm hpp have ha₃ := bisA_invol hpp have hfix : arefl (bisA p₂ q₂) (bisZ p₂ q₂) (arefl (bisA p₁ q₁) (bisZ p₁ q₁) O) = O := by show bis p₂ q₂ (bis p₁ q₁ O) = O rw [hO₁, hO₂] -- the rotation part of σ₂ σ₁ is nontrivial have hω : bisZ p₂ q₂ * (starRingEnd ℂ) (bisZ p₁ q₁) ≠ 1 := by intro hω obtain ⟨c, hc, hF⟩ := par_translation hz₂ ha₂ hω hne apply hc have h3 := hF O rw [hfix] at h3 have h4 : O + c = O + 0 := by rw [add_zero]; exact h3.symm exact add_left_cancel h4 -- its centre is `O` have hwO : (bisA p₂ q₂ + bisZ p₂ q₂ * (starRingEnd ℂ) (bisA p₁ q₁)) / (1 - bisZ p₂ q₂ * (starRingEnd ℂ) (bisZ p₁ q₁)) = O := (fixed_unique hω hfix).symm have hmove : arefl (bisA p p') (bisZ p p') ((bisA p₂ q₂ + bisZ p₂ q₂ * (starRingEnd ℂ) (bisA p₁ q₁)) / (1 - bisZ p₂ q₂ * (starRingEnd ℂ) (bisZ p₁ q₁))) ≠ (bisA p₂ q₂ + bisZ p₂ q₂ * (starRingEnd ℂ) (bisA p₁ q₁)) / (1 - bisZ p₂ q₂ * (starRingEnd ℂ) (bisZ p₁ q₁)) := by rw [hwO] intro hfixO have h3 : bis p p' O = O := hfixO rw [bis_fixed_iff hpp] at h3 have h4 := norm_eq_of_mul_conj_eq h3 apply hO rw [norm_sub_rev, h4, norm_sub_rev] exact I1_C hT hz₁ ha₁ hz₂ ha₂ hz₃ ha₃ hω hmove /-- (12.3), in defect form: `2 μ(σ_{pp'}) + 2 μ(σ₁) + 2 μ(σ₂) + 2 ≥ n`. -/ theorem cross_pair_mu {Q : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (Q.filter (fun z => z + t ∈ Q)).card ≤ 2) {O p₁ q₁ p₂ q₂ p p' : ℂ} (h₁ : p₁ ≠ q₁) (h₂ : p₂ ≠ q₂) (hO₁ : bis p₁ q₁ O = O) (hO₂ : bis p₂ q₂ O = O) (hne : bis p₁ q₁ ≠ bis p₂ q₂) (hpp : p ≠ p') (hO : ‖p - O‖ ≠ ‖p' - O‖) : Q.card ≤ 2 * (muC Q (bis p p') + muC Q (bis p₁ q₁) + muC Q (bis p₂ q₂)) + 2 := by have h := cross_pair hT h₁ h₂ hO₁ hO₂ hne hpp hO have e1 := rC_add_muC Q (bis p₁ q₁) have e2 := rC_add_muC Q (bis p₂ q₂) have e3 := rC_add_muC Q (bis p p') omega end Erdos94ThmA /-! ### Bridge: bisector reflections of points on a circle (for THEOREM_A §12.4) -/ namespace Erdos94ThmA open Finset theorem conj_eq_of_norm {w : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = ρ) : (starRingEnd ℂ) w = (ρ : ℂ) ^ 2 / w := by have hw0 : w ≠ 0 := by intro h rw [h, norm_zero] at hw linarith rw [eq_div_iff hw0, mul_comm, Complex.mul_conj', hw] /-- On the circle `‖z − O‖ = ρ`, the bisector reflection of `p ≠ q` is `z ↦ O + ((p − O)(q − O)/ρ²) · conj (z − O)`. -/ theorem bis_circle {O p q : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hp : ‖p - O‖ = ρ) (hq : ‖q - O‖ = ρ) (hpq : p ≠ q) (z : ℂ) : bis p q z = O + ((p - O) * (q - O) / (ρ : ℂ) ^ 2) * (starRingEnd ℂ) (z - O) := by have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' have ha0 : p - O ≠ 0 := by intro h rw [h, norm_zero] at hp linarith have hb0 : q - O ≠ 0 := by intro h rw [h, norm_zero] at hq linarith have hab : (q - O) - (p - O) ≠ 0 := by intro h apply hpq have : q - p = 0 := by rw [← h]; ring exact (sub_eq_zero.mp this).symm have hA := conj_eq_of_norm hρ hp have hB := conj_eq_of_norm hρ hq have hpq' : p - q ≠ 0 := sub_ne_zero.mpr hpq have e1 : q - p = (q - O) - (p - O) := by ring have hc : (starRingEnd ℂ) (q - p) = (ρ : ℂ) ^ 2 * (p - q) / ((q - O) * (p - O)) := by rw [e1, map_sub, hA, hB] field_simp ring have hζ : bisZ p q = (p - O) * (q - O) / (ρ : ℂ) ^ 2 := by rw [bisZ, hc] field_simp ring have hm : (starRingEnd ℂ) ((p + q) / 2) = (starRingEnd ℂ) O + ((ρ : ℂ) ^ 2 / (p - O) + (ρ : ℂ) ^ 2 / (q - O)) / 2 := by rw [show (p + q) / 2 = O + ((p - O) + (q - O)) / 2 by ring, map_add, map_div₀, map_add, hA, hB] simp only [map_ofNat] have hz : (starRingEnd ℂ) z = (starRingEnd ℂ) (z - O) + (starRingEnd ℂ) O := by rw [← map_add, sub_add_cancel] simp only [bis, arefl, bisA] rw [hζ, hm, hz] field_simp ring end Erdos94ThmA /-! ### Theorem A′ (THEOREM_A §12.4): the reflection defect of the circle part bounds its energy -/ namespace Erdos94ThmA open Finset /-- Normalised position on the circle. -/ noncomputable def unorm (O : ℂ) (ρ : ℝ) (z : ℂ) : ℂ := (z - O) / (ρ : ℂ) /-- Multiplicative energy of the normalised circle part: `#{(a, b, c, d) ∈ U⁴ : c d = a b}`. -/ noncomputable def energyC (C : Finset ℂ) (O : ℂ) (ρ : ℝ) : ℕ := ∑ ab ∈ C.image (unorm O ρ) ×ˢ C.image (unorm O ρ), ((C.image (unorm O ρ) ×ˢ C.image (unorm O ρ)).filter (fun cd : ℂ × ℂ => cd.1 * cd.2 = ab.1 * ab.2)).card theorem unorm_injective (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) : Function.Injective (unorm O ρ) := by intro z z' h have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' unfold unorm at h have := (div_left_inj' hρ0).mp h exact sub_left_injective this theorem bis_circle_norm {O p q z : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hp : ‖p - O‖ = ρ) (hq : ‖q - O‖ = ρ) (hpq : p ≠ q) (hz : ‖z - O‖ = ρ) : ‖bis p q z - O‖ = ρ := by rw [bis_circle hρ hp hq hpq z, add_sub_cancel_left, norm_mul, norm_div, norm_mul, hp, hq, Complex.norm_conj, hz, norm_pow, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hρ] field_simp theorem unorm_mul_bis {O p q z : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hp : ‖p - O‖ = ρ) (hq : ‖q - O‖ = ρ) (hpq : p ≠ q) (hz : ‖z - O‖ = ρ) : unorm O ρ z * unorm O ρ (bis p q z) = unorm O ρ p * unorm O ρ q := by have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' have hzz : (z - O) * (starRingEnd ℂ) (z - O) = (ρ : ℂ) ^ 2 := by rw [Complex.mul_conj', hz] unfold unorm rw [bis_circle hρ hp hq hpq z, add_sub_cancel_left] calc (z - O) / (ρ : ℂ) * ((p - O) * (q - O) / (ρ : ℂ) ^ 2 * (starRingEnd ℂ) (z - O) / (ρ : ℂ)) = (p - O) * (q - O) / (ρ : ℂ) ^ 2 * ((z - O) * (starRingEnd ℂ) (z - O)) / ((ρ : ℂ) * ρ) := by ring _ = (p - O) * (q - O) / (ρ : ℂ) ^ 2 * (ρ : ℂ) ^ 2 / ((ρ : ℂ) * ρ) := by rw [hzz] _ = (p - O) / (ρ : ℂ) * ((q - O) / (ρ : ℂ)) := by field_simp /-- Per pair: `K ≤ #{(c, d) ∈ U² : c d = u_p u_q} + μ(σ_{pq})`. -/ theorem pair_energy_bound (P C : Finset ℂ) (hCP : C ⊆ P) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hC : ∀ z ∈ C, ‖z - O‖ = ρ) (hPC : ∀ z ∈ P, ‖z - O‖ = ρ → z ∈ C) {p q : ℂ} (hp : p ∈ C) (hq : q ∈ C) (hpq : p ≠ q) : C.card ≤ ((C.image (unorm O ρ) ×ˢ C.image (unorm O ρ)).filter (fun cd : ℂ × ℂ => cd.1 * cd.2 = unorm O ρ p * unorm O ρ q)).card + muC P (bis p q) := by have hsplit := card_filter_add_card_filter_not (s := C) (fun z => bis p q z ∈ C) have hout : (C.filter (fun z => ¬ (bis p q z ∈ C))).card ≤ muC P (bis p q) := by apply card_le_card intro z hz rw [mem_filter] at hz ⊢ refine ⟨hCP hz.1, fun hzP => hz.2 (hPC _ hzP ?_)⟩ exact bis_circle_norm hρ (hC p hp) (hC q hq) hpq (hC z hz.1) have hin : (C.filter (fun z => bis p q z ∈ C)).card ≤ ((C.image (unorm O ρ) ×ˢ C.image (unorm O ρ)).filter (fun cd : ℂ × ℂ => cd.1 * cd.2 = unorm O ρ p * unorm O ρ q)).card := by apply card_le_card_of_injOn (fun z => (unorm O ρ z, unorm O ρ (bis p q z))) · intro z hz simp only [mem_coe, mem_filter] at hz simp only [mem_coe, mem_filter, mem_product, mem_image] exact ⟨⟨⟨z, hz.1, rfl⟩, ⟨bis p q z, hz.2, rfl⟩⟩, unorm_mul_bis hρ (hC p hp) (hC q hq) hpq (hC z hz.1)⟩ · intro z _ z' _ h exact unorm_injective O hρ (congrArg Prod.fst h) omega /-- **(12.4)** `K · K(K − 1) ≤ E(U) + Σ_{ordered pairs of C} μ(σ_{pq})`, i.e. `E ≥ K²(K−1) − 2M_Q`. -/ theorem energy_bound (P C : Finset ℂ) (hCP : C ⊆ P) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hC : ∀ z ∈ C, ‖z - O‖ = ρ) (hPC : ∀ z ∈ P, ‖z - O‖ = ρ → z ∈ C) : C.card * C.offDiag.card ≤ energyC C O ρ + ∑ pq ∈ C.offDiag, muC P (bis pq.1 pq.2) := by have h1 : ∀ pq ∈ C.offDiag, C.card ≤ ((C.image (unorm O ρ) ×ˢ C.image (unorm O ρ)).filter (fun cd : ℂ × ℂ => cd.1 * cd.2 = unorm O ρ pq.1 * unorm O ρ pq.2)).card + muC P (bis pq.1 pq.2) := by intro pq hpq rw [mem_offDiag] at hpq exact pair_energy_bound P C hCP O hρ hC hPC hpq.1 hpq.2.1 hpq.2.2 have h2 := sum_le_sum h1 rw [sum_const, smul_eq_mul, sum_add_distrib, mul_comm] at h2 have h3 : ∑ pq ∈ C.offDiag, ((C.image (unorm O ρ) ×ˢ C.image (unorm O ρ)).filter (fun cd : ℂ × ℂ => cd.1 * cd.2 = unorm O ρ pq.1 * unorm O ρ pq.2)).card ≤ energyC C O ρ := by unfold energyC have hinj : Set.InjOn (fun pq : ℂ × ℂ => (unorm O ρ pq.1, unorm O ρ pq.2)) (C.offDiag : Set (ℂ × ℂ)) := by intro x _ y _ h simp only [Prod.mk.injEq] at h exact Prod.ext (unorm_injective O hρ h.1) (unorm_injective O hρ h.2) rw [← sum_image (f := fun ab : ℂ × ℂ => ((C.image (unorm O ρ) ×ˢ C.image (unorm O ρ)).filter (fun cd : ℂ × ℂ => cd.1 * cd.2 = ab.1 * ab.2)).card) hinj] apply sum_le_sum_of_subset intro ab hab rw [mem_image] at hab obtain ⟨pq, hpq, rfl⟩ := hab rw [mem_offDiag] at hpq exact mem_product.mpr ⟨mem_image_of_mem _ hpq.1, mem_image_of_mem _ hpq.2.1⟩ omega end Erdos94ThmA /-! ### Theorem A′ (THEOREM_A §12.2, (12.1)): the cross pairs eat the M-budget -/ namespace Erdos94ThmA open Finset /-- (12.2) Two good axes: two ordered pairs of `C` with distinct bisector reflections whose defects sum to at most `2 Mord_C / (K (K − 2))`. -/ theorem two_axes (P C : Finset ℂ) (hK : 3 ≤ C.card) : ∃ pq₁ ∈ C.offDiag, ∃ pq₂ ∈ C.offDiag, bis pq₁.1 pq₁.2 ≠ bis pq₂.1 pq₂.2 ∧ ((muC P (bis pq₁.1 pq₁.2) : ℝ) + muC P (bis pq₂.1 pq₂.2)) * ((C.card : ℝ) * (C.card - 2)) ≤ 2 * ∑ pq ∈ C.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := by classical have hoff : C.offDiag.card + C.card = C.card * C.card := by rw [offDiag_card, Nat.sub_add_cancel (Nat.le_mul_self _)] have hne : C.offDiag.Nonempty := by rw [← card_pos] have : C.card < C.card * C.card := by nlinarith omega obtain ⟨pq₁, h₁, hmin₁⟩ := exists_min_image C.offDiag (fun pq => muC P (bis pq.1 pq.2)) hne have hfib := fiber_le C (bis pq₁.1 pq₁.2) C.offDiag (subset_refl _) have hsplit := card_filter_add_card_filter_not (s := C.offDiag) (fun pq : ℂ × ℂ => bis pq.1 pq.2 = bis pq₁.1 pq₁.2) set R := C.offDiag.filter (fun pq : ℂ × ℂ => ¬ (bis pq.1 pq.2 = bis pq₁.1 pq₁.2)) with hR have hRcard : C.card * C.card ≤ R.card + 2 * C.card := by omega have hRne : R.Nonempty := by rw [← card_pos] have : 3 * C.card ≤ C.card * C.card := Nat.mul_le_mul_right _ hK omega obtain ⟨pq₂, h₂, hmin₂⟩ := exists_min_image R (fun pq => muC P (bis pq.1 pq.2)) hRne have h₂' := mem_filter.mp h₂ refine ⟨pq₁, h₁, pq₂, h₂'.1, fun h => h₂'.2 h.symm, ?_⟩ have hμ : (muC P (bis pq₁.1 pq₁.2) : ℝ) ≤ muC P (bis pq₂.1 pq₂.2) := by exact_mod_cast hmin₁ pq₂ h₂'.1 have hsumR : (R.card : ℝ) * muC P (bis pq₂.1 pq₂.2) ≤ ∑ pq ∈ R, (muC P (bis pq.1 pq.2) : ℝ) := by have := card_nsmul_le_sum R (fun pq => (muC P (bis pq.1 pq.2) : ℝ)) (muC P (bis pq₂.1 pq₂.2)) (fun pq hpq => by exact_mod_cast hmin₂ pq hpq) rwa [nsmul_eq_mul] at this have hRsub : ∑ pq ∈ R, (muC P (bis pq.1 pq.2) : ℝ) ≤ ∑ pq ∈ C.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun _ _ _ => Nat.cast_nonneg _) have hRcardR : (C.card : ℝ) * (C.card - 2) ≤ R.card := by have : ((C.card * C.card : ℕ) : ℝ) ≤ ((R.card + 2 * C.card : ℕ) : ℝ) := by exact_mod_cast hRcard push_cast at this linarith have hμ2 : (0 : ℝ) ≤ muC P (bis pq₂.1 pq₂.2) := Nat.cast_nonneg _ have hK2 : (0 : ℝ) ≤ (C.card : ℝ) * (C.card - 2) := by have : (3 : ℝ) ≤ C.card := by exact_mod_cast hK nlinarith have e1 : ((muC P (bis pq₁.1 pq₁.2) : ℝ) + muC P (bis pq₂.1 pq₂.2)) * ((C.card : ℝ) * (C.card - 2)) ≤ 2 * (muC P (bis pq₂.1 pq₂.2) : ℝ) * ((C.card : ℝ) * (C.card - 2)) := by have := mul_le_mul_of_nonneg_right (by linarith : (muC P (bis pq₁.1 pq₁.2) : ℝ) + muC P (bis pq₂.1 pq₂.2) ≤ 2 * muC P (bis pq₂.1 pq₂.2)) hK2 linarith have e2 : (muC P (bis pq₂.1 pq₂.2) : ℝ) * ((C.card : ℝ) * (C.card - 2)) ≤ (muC P (bis pq₂.1 pq₂.2) : ℝ) * R.card := mul_le_mul_of_nonneg_left hRcardR hμ2 nlinarith /-- **(12.1)** With `K = |C| ≥ 3` points on a circle about `O`, `k = |P| − K` points off it, and `M_C = ∑_{ordered pairs of C} μ`: `(K − 2)(M_C + kK(n − 2) − Mord P) ≤ 4 k M_C`, i.e. `Mord ≥ (1 − 4k/(K−2)) M_C + kK(n − 2)` (twice the unordered statement). -/ theorem cross_sum (P C : Finset ℂ) (hT : ∀ t : ℂ, t ≠ 0 → (P.filter (fun z => z + t ∈ P)).card ≤ 2) (hCP : C ⊆ P) (O : ℂ) {ρ : ℝ} (hC : ∀ z ∈ C, ‖z - O‖ = ρ) (hE : ∀ z ∈ P, z ∉ C → ‖z - O‖ ≠ ρ) (hK : 3 ≤ C.card) : ((C.card : ℝ) - 2) * (∑ pq ∈ C.offDiag, (muC P (bis pq.1 pq.2) : ℝ) + ((P.card : ℝ) - C.card) * C.card * ((P.card : ℝ) - 2) - Mord P) ≤ 4 * ((P.card : ℝ) - C.card) * ∑ pq ∈ C.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := by classical obtain ⟨pq₁, h₁, pq₂, h₂, hne, hax⟩ := two_axes P C hK set MC := ∑ pq ∈ C.offDiag, (muC P (bis pq.1 pq.2) : ℝ) with hMC set s := (muC P (bis pq₁.1 pq₁.2) : ℝ) + muC P (bis pq₂.1 pq₂.2) with hs have h₁' := mem_offDiag.mp h₁ have h₂' := mem_offDiag.mp h₂ -- both axes pass through `O` have hfixO : ∀ p q, p ∈ C → q ∈ C → p ≠ q → bis p q O = O := by intro p q hp hq hpq rw [bis_fixed_iff hpq] rw [Complex.mul_conj', Complex.mul_conj', norm_sub_rev, hC p hp, norm_sub_rev, hC q hq] have hO₁ := hfixO _ _ h₁'.1 h₁'.2.1 h₁'.2.2 have hO₂ := hfixO _ _ h₂'.1 h₂'.2.1 h₂'.2.2 -- every cross pair has defect ≥ (n − 2)/2 − s have hcross : ∀ p p', p ∈ P → p' ∈ P → ‖p - O‖ ≠ ‖p' - O‖ → ((P.card : ℝ) - 2) / 2 - s ≤ muC P (bis p p') := by intro p p' _ _ hO have hpp : p ≠ p' := fun h => hO (by rw [h]) have h := cross_pair_mu hT h₁'.2.2 h₂'.2.2 hO₁ hO₂ hne hpp hO have h' : (P.card : ℝ) ≤ 2 * ((muC P (bis p p') : ℝ) + muC P (bis pq₁.1 pq₁.2) + muC P (bis pq₂.1 pq₂.2)) + 2 := by exact_mod_cast h rw [hs] linarith -- the cross pairs set X1 := (P \ C) ×ˢ C with hX1 set X2 := C ×ˢ (P \ C) with hX2 have hdisj12 : Disjoint X1 X2 := by rw [disjoint_left] intro pq h1 h2 rw [mem_product, mem_sdiff] at h1 h2 exact h1.1.2 h2.1 have hdisjC : Disjoint C.offDiag (X1 ∪ X2) := by rw [disjoint_left] intro pq h1 h2 rw [mem_offDiag] at h1 rw [mem_union, mem_product, mem_product, mem_sdiff, mem_sdiff] at h2 rcases h2 with h2 | h2 · exact h2.1.2 h1.1 · exact h2.2.2 h1.2.1 have hsubP : C.offDiag ∪ (X1 ∪ X2) ⊆ P.offDiag := by intro pq hpq rw [mem_union] at hpq rw [mem_offDiag] rcases hpq with h | h · rw [mem_offDiag] at h exact ⟨hCP h.1, hCP h.2.1, h.2.2⟩ · rw [mem_union, mem_product, mem_product, mem_sdiff, mem_sdiff] at h rcases h with h | h · exact ⟨h.1.1, hCP h.2, fun he => h.1.2 (by rw [he]; exact h.2)⟩ · exact ⟨hCP h.1, h.2.1, fun he => h.2.2 (by rw [← he]; exact h.1)⟩ have hsum : MC + ∑ pq ∈ X1 ∪ X2, (muC P (bis pq.1 pq.2) : ℝ) ≤ (Mord P : ℝ) := by have h1 : ∑ pq ∈ C.offDiag ∪ (X1 ∪ X2), (muC P (bis pq.1 pq.2) : ℝ) ≤ ∑ pq ∈ P.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := sum_le_sum_of_subset_of_nonneg hsubP (fun _ _ _ => Nat.cast_nonneg _) rw [sum_union hdisjC] at h1 have h2 : (Mord P : ℝ) = ∑ pq ∈ P.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := by unfold Mord push_cast rfl rw [h2] exact h1 have hcardX : ((X1 ∪ X2).card : ℝ) = 2 * ((P.card : ℝ) - C.card) * C.card := by rw [card_union_of_disjoint hdisj12, hX1, hX2, card_product, card_product, card_sdiff_of_subset hCP] have : C.card ≤ P.card := card_le_card hCP push_cast [Nat.cast_sub this] ring have hXlow : ((X1 ∪ X2).card : ℝ) * (((P.card : ℝ) - 2) / 2 - s) ≤ ∑ pq ∈ X1 ∪ X2, (muC P (bis pq.1 pq.2) : ℝ) := by have := card_nsmul_le_sum (X1 ∪ X2) (fun pq => (muC P (bis pq.1 pq.2) : ℝ)) (((P.card : ℝ) - 2) / 2 - s) (fun pq hpq => by rw [mem_union, mem_product, mem_product, mem_sdiff, mem_sdiff] at hpq rcases hpq with h | h · exact hcross _ _ h.1.1 (hCP h.2) (by rw [hC _ h.2]; exact hE _ h.1.1 h.1.2) · exact hcross _ _ (hCP h.1) h.2.1 (by rw [hC _ h.1]; exact (hE _ h.2.1 h.2.2).symm)) rwa [nsmul_eq_mul] at this rw [hcardX] at hXlow have hK3 : (3 : ℝ) ≤ C.card := by exact_mod_cast hK have hk0 : (0 : ℝ) ≤ (P.card : ℝ) - C.card := by have : (C.card : ℝ) ≤ P.card := by exact_mod_cast card_le_card hCP linarith -- (K − 2)(MC + kK(n−2) − Mord) ≤ (K − 2)(2kK s) = 2k (s K (K − 2)) ≤ 4 k MC have hstep : MC + ((P.card : ℝ) - C.card) * C.card * ((P.card : ℝ) - 2) - Mord P ≤ 2 * ((P.card : ℝ) - C.card) * C.card * s := by nlinarith have hK2 : (0 : ℝ) ≤ (C.card : ℝ) - 2 := by linarith have h3 := mul_le_mul_of_nonneg_left hstep hK2 have h4 : ((C.card : ℝ) - 2) * (2 * ((P.card : ℝ) - C.card) * C.card * s) = 2 * ((P.card : ℝ) - C.card) * (s * ((C.card : ℝ) * (C.card - 2))) := by ring have h5 : 2 * ((P.card : ℝ) - C.card) * (s * ((C.card : ℝ) * (C.card - 2))) ≤ 2 * ((P.card : ℝ) - C.card) * (2 * MC) := by apply mul_le_mul_of_nonneg_left hax linarith linarith end Erdos94ThmA /-! ### (R1) The circle part as a finite subset of the group `ℂˣ`; energy bound in `C1p`'s terms -/ namespace Erdos94ThmA open Finset /-- Total map `ℂ → ℂˣ`, the identity on nonzero numbers. -/ noncomputable def toUnit (w : ℂ) : ℂˣ := if h : w = 0 then 1 else Units.mk0 w h theorem toUnit_val {w : ℂ} (hw : w ≠ 0) : ((toUnit w : ℂˣ) : ℂ) = w := by unfold toUnit rw [dif_neg hw] rfl theorem unorm_ne_zero {O z : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hz : ‖z - O‖ = ρ) : unorm O ρ z ≠ 0 := by have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' have hz0 : z - O ≠ 0 := by intro h rw [h, norm_zero] at hz linarith exact div_ne_zero hz0 hρ0 /-- The normalised circle part, as a finite subset of `ℂˣ`. -/ noncomputable def unitSet (C : Finset ℂ) (O : ℂ) (ρ : ℝ) : Finset ℂˣ := C.image (fun z => toUnit (unorm O ρ z)) theorem toUnit_unorm_injOn (C : Finset ℂ) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hC : ∀ z ∈ C, ‖z - O‖ = ρ) : Set.InjOn (fun z => toUnit (unorm O ρ z)) (C : Set ℂ) := by intro z hz z' hz' h have h' := congrArg (fun u : ℂˣ => (u : ℂ)) h simp only at h' rw [toUnit_val (unorm_ne_zero hρ (hC z hz)), toUnit_val (unorm_ne_zero hρ (hC z' hz'))] at h' exact unorm_injective O hρ h' theorem unitSet_card (C : Finset ℂ) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hC : ∀ z ∈ C, ‖z - O‖ = ρ) : (unitSet C O ρ).card = C.card := card_image_of_injOn (toUnit_unorm_injOn C O hρ hC) section Rplus variable {G : Type*} [CommGroup G] [DecidableEq G] /-- Sum-representation count `#{c ∈ V : s c⁻¹ ∈ V}` (= `#{(c, d) ∈ V² : c d = s}`). -/ def rplus (V : Finset G) (s : G) : ℕ := (V.filter (fun c => s * c⁻¹ ∈ V)).card /-- `∑_{a, b} r₊(a b) = ∑_{a, b} rep(a b⁻¹)`: both count `{a c = b d}`. -/ theorem sum_rplus_eq_energy (V : Finset G) : ∑ a ∈ V, ∑ b ∈ V, rplus V (a * b) = energy V := by unfold energy rplus rep rw [sum_comm (s := V) (t := V) (f := fun b a => (V.filter (fun c => a * b⁻¹ * c ∈ V)).card)] refine sum_congr rfl (fun a _ => ?_) simp only [card_filter] rw [sum_comm] refine sum_congr rfl (fun x _ => sum_congr rfl (fun y _ => ?_)) rw [mul_right_comm] end Rplus /-- **(R1) Energy bound, group form.** `K · K(K − 1) ≤ E(V) + Σ_{ordered C-pairs} μ` with `V ⊂ ℂˣ` the normalised circle part and `E = energy` (the hypothesis form of `C1p`). -/ theorem energy_bound_units (P C : Finset ℂ) (hCP : C ⊆ P) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hC : ∀ z ∈ C, ‖z - O‖ = ρ) (hPC : ∀ z ∈ P, ‖z - O‖ = ρ → z ∈ C) : C.card * C.offDiag.card ≤ energy (unitSet C O ρ) + ∑ pq ∈ C.offDiag, muC P (bis pq.1 pq.2) := by set V := unitSet C O ρ with hV set v : ℂ → ℂˣ := fun z => toUnit (unorm O ρ z) with hv have hvval : ∀ z ∈ C, ((v z : ℂˣ) : ℂ) = unorm O ρ z := fun z hz => toUnit_val (unorm_ne_zero hρ (hC z hz)) have hvmem : ∀ z ∈ C, v z ∈ V := fun z hz => mem_image_of_mem _ hz -- per pair have h1 : ∀ pq ∈ C.offDiag, C.card ≤ rplus V (v pq.1 * v pq.2) + muC P (bis pq.1 pq.2) := by intro pq hpq rw [mem_offDiag] at hpq obtain ⟨hp, hq, hpq'⟩ := hpq have hsplit := card_filter_add_card_filter_not (s := C) (fun z => bis pq.1 pq.2 z ∈ C) have hout : (C.filter (fun z => ¬ (bis pq.1 pq.2 z ∈ C))).card ≤ muC P (bis pq.1 pq.2) := by apply card_le_card intro z hz rw [mem_filter] at hz ⊢ refine ⟨hCP hz.1, fun hzP => hz.2 (hPC _ hzP ?_)⟩ exact bis_circle_norm hρ (hC _ hp) (hC _ hq) hpq' (hC z hz.1) have hin : (C.filter (fun z => bis pq.1 pq.2 z ∈ C)).card ≤ rplus V (v pq.1 * v pq.2) := by unfold rplus apply card_le_card_of_injOn v · intro z hz simp only [mem_coe, mem_filter] at hz ⊢ refine ⟨hvmem z hz.1, ?_⟩ have hbz := hz.2 have key : v pq.1 * v pq.2 * (v z)⁻¹ = v (bis pq.1 pq.2 z) := by apply Units.ext rw [Units.val_mul, Units.val_mul, Units.val_inv_eq_inv_val, hvval _ hp, hvval _ hq, hvval _ hz.1, hvval _ hbz] have hmul := unorm_mul_bis hρ (hC _ hp) (hC _ hq) hpq' (hC z hz.1) have hz0 := unorm_ne_zero hρ (hC z hz.1) rw [← hmul] field_simp rw [key] exact hvmem _ hbz · exact Set.InjOn.mono (coe_subset.mpr (filter_subset _ _)) (toUnit_unorm_injOn C O hρ hC) omega have h2 := sum_le_sum h1 rw [sum_const, smul_eq_mul, sum_add_distrib, mul_comm] at h2 -- ∑_{ordered C-pairs} r₊(v_p v_q) ≤ ∑_{a, b ∈ V} r₊(a b) = E(V) have h3 : ∑ pq ∈ C.offDiag, rplus V (v pq.1 * v pq.2) ≤ energy V := by rw [← sum_rplus_eq_energy V, ← sum_product' (f := fun a b => rplus V (a * b))] have hinj : Set.InjOn (fun pq : ℂ × ℂ => (v pq.1, v pq.2)) (C.offDiag : Set (ℂ × ℂ)) := by intro x hx y hy h simp only [Prod.mk.injEq] at h rw [mem_coe, mem_offDiag] at hx hy exact Prod.ext (toUnit_unorm_injOn C O hρ hC hx.1 hy.1 h.1) (toUnit_unorm_injOn C O hρ hC hx.2.1 hy.2.1 h.2) rw [← sum_image (f := fun ab : ℂˣ × ℂˣ => rplus V (ab.1 * ab.2)) hinj] apply sum_le_sum_of_subset intro ab hab rw [mem_image] at hab obtain ⟨pq, hpq, rfl⟩ := hab rw [mem_offDiag] at hpq exact mem_product.mpr ⟨hvmem _ hpq.1, hvmem _ hpq.2.1⟩ omega end Erdos94ThmA /-! ### (R2) A finite subgroup of `ℂˣ` of order `g` is the group of `g`-th roots of unity -/ namespace Erdos94ThmA open Finset /-- **(R2)** If `H` is a subgroup of `ℂˣ` whose elements are those of the finset `D`, then `D` is exactly the set of `|D|`-th roots of unity. -/ theorem subgroup_eq_roots (H : Subgroup ℂˣ) (D : Finset ℂˣ) (hmem : ∀ x, x ∈ H ↔ x ∈ D) (hg : 0 < D.card) : ∀ x : ℂˣ, x ∈ D ↔ x ∈ rootsOfUnity D.card ℂ := by have hNZ : NeZero D.card := ⟨hg.ne'⟩ have hcardH : Nat.card H = D.card := by rw [← Nat.card_eq_finsetCard] exact Nat.card_congr (Equiv.subtypeEquivRight hmem) have hsub : ∀ x ∈ D, x ∈ rootsOfUnity D.card ℂ := by intro x hx rw [_root_.mem_rootsOfUnity] have hxH : x ∈ H := (hmem x).mpr hx have h1 := pow_card_eq_one' (G := H) (x := ⟨x, hxH⟩) rw [hcardH] at h1 have h2 := congrArg Subtype.val h1 simpa using h2 intro x refine ⟨hsub x, fun hx => ?_⟩ by_contra hxD have hR : Nat.card (rootsOfUnity D.card ℂ) = D.card := Complex.card_rootsOfUnity D.card have hins : ∀ y ∈ insert x D, y ∈ rootsOfUnity D.card ℂ := by intro y hy rw [mem_insert] at hy rcases hy with rfl | hy · exact hx · exact hsub y hy have hfin : (insert x D).card ≤ Nat.card (rootsOfUnity D.card ℂ) := by rw [← Nat.card_eq_finsetCard] exact Nat.card_le_card_of_injective (fun y : (insert x D : Finset ℂˣ) => (⟨y.1, hins y.1 y.2⟩ : rootsOfUnity D.card ℂ)) (fun a b h => by apply Subtype.ext have h' := congrArg (fun z : rootsOfUnity D.card ℂ => (z : ℂˣ)) h simpa using h') rw [card_insert_of_notMem hxD, hR] at hfin omega /-- Every element of such a `D` is `exp (2πi j/g)` for some `j < g`. -/ theorem subgroup_elem_exp (H : Subgroup ℂˣ) (D : Finset ℂˣ) (hmem : ∀ x, x ∈ H ↔ x ∈ D) (hg : 0 < D.card) {d : ℂˣ} (hd : d ∈ D) : ∃ j < D.card, Complex.exp (2 * Real.pi * Complex.I * (j / D.card)) = (d : ℂ) := by have hNZ : NeZero D.card := ⟨hg.ne'⟩ exact (Complex.mem_rootsOfUnity D.card d).mp ((subgroup_eq_roots H D hmem hg d).mp hd) /-- ... and every `exp (2πi j/g)`, `j < g`, lies in `D`. -/ theorem exp_mem_subgroup (H : Subgroup ℂˣ) (D : Finset ℂˣ) (hmem : ∀ x, x ∈ H ↔ x ∈ D) (hg : 0 < D.card) {j : ℕ} (hj : j < D.card) : toUnit (Complex.exp (2 * Real.pi * Complex.I * (j / D.card))) ∈ D := by have hNZ : NeZero D.card := ⟨hg.ne'⟩ rw [subgroup_eq_roots H D hmem hg, Complex.mem_rootsOfUnity D.card] exact ⟨j, hj, (toUnit_val (Complex.exp_ne_zero _)).symm⟩ end Erdos94ThmA /-! ### (R3) Chord criterion on a circle and `pairEnergy(Q) ≤ 2 (E − K²)` -/ namespace Erdos94ThmA open Finset /-- For unit complex numbers, equal chords force equal or inverse "ratios" `a conj b`. -/ theorem chord_criterion {a b c d : ℂ} (ha : a * (starRingEnd ℂ) a = 1) (hb : b * (starRingEnd ℂ) b = 1) (hc : c * (starRingEnd ℂ) c = 1) (hd : d * (starRingEnd ℂ) d = 1) (h : (a - b) * (starRingEnd ℂ) (a - b) = (c - d) * (starRingEnd ℂ) (c - d)) : a * (starRingEnd ℂ) b = c * (starRingEnd ℂ) d ∨ a * (starRingEnd ℂ) b = d * (starRingEnd ℂ) c := by set x := a * (starRingEnd ℂ) b with hx set y := c * (starRingEnd ℂ) d with hy have hxx : x * (starRingEnd ℂ) x = 1 := by rw [hx, map_mul, Complex.conj_conj] linear_combination (b * (starRingEnd ℂ) b) * ha + hb have hyy : y * (starRingEnd ℂ) y = 1 := by rw [hy, map_mul, Complex.conj_conj] linear_combination (d * (starRingEnd ℂ) d) * hc + hd have hsum : x + (starRingEnd ℂ) x = y + (starRingEnd ℂ) y := by rw [hx, hy, map_mul, map_mul, Complex.conj_conj, Complex.conj_conj] simp only [map_sub] at h linear_combination -h + ha + hb - hc - hd have key : (x - y) * (x - (starRingEnd ℂ) y) = 0 := by linear_combination x * hsum - hxx + hyy rcases mul_eq_zero.mp key with h1 | h1 · exact Or.inl (sub_eq_zero.mp h1) · right rw [sub_eq_zero.mp h1, hy, map_mul, Complex.conj_conj, mul_comm] theorem unorm_mul_conj {O z : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hz : ‖z - O‖ = ρ) : unorm O ρ z * (starRingEnd ℂ) (unorm O ρ z) = 1 := by have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' have hzz : (z - O) * (starRingEnd ℂ) (z - O) = (ρ : ℂ) ^ 2 := by rw [Complex.mul_conj', hz] unfold unorm rw [map_div₀, Complex.conj_ofReal] field_simp rw [hzz] theorem conj_eq_inv_of_unit {u : ℂ} (hu : u * (starRingEnd ℂ) u = 1) : (starRingEnd ℂ) u = u⁻¹ := by have hu0 : u ≠ 0 := by intro h rw [h, zero_mul] at hu exact zero_ne_one hu exact eq_inv_of_mul_eq_one_left (by rw [mul_comm]; exact hu) /-- The "ratio" map `(p, q) ↦ v_p v_q⁻¹` of an ordered pair of circle points. -/ noncomputable def ratioU (O : ℂ) (ρ : ℝ) (pq : ℂ × ℂ) : ℂˣ := toUnit (unorm O ρ pq.1) * (toUnit (unorm O ρ pq.2))⁻¹ theorem ratioU_val {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) {p q : ℂ} (hp : ‖p - O‖ = ρ) (hq : ‖q - O‖ = ρ) : ((ratioU O ρ (p, q) : ℂˣ) : ℂ) = unorm O ρ p * (starRingEnd ℂ) (unorm O ρ q) := by unfold ratioU rw [Units.val_mul, Units.val_inv_eq_inv_val, toUnit_val (unorm_ne_zero hρ hp), toUnit_val (unorm_ne_zero hρ hq), conj_eq_inv_of_unit (unorm_mul_conj hρ hq)] /-- Equal chord lengths of circle points ⇒ equal ratio or swapped ratio. -/ theorem ratio_of_dist_eq {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) {p q p' q' : ℂ} (hp : ‖p - O‖ = ρ) (hq : ‖q - O‖ = ρ) (hp' : ‖p' - O‖ = ρ) (hq' : ‖q' - O‖ = ρ) (h : dist p q = dist p' q') : ratioU O ρ (p, q) = ratioU O ρ (p', q') ∨ ratioU O ρ (p, q) = ratioU O ρ (q', p') := by have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' have hd : (unorm O ρ p - unorm O ρ q) * (starRingEnd ℂ) (unorm O ρ p - unorm O ρ q) = (unorm O ρ p' - unorm O ρ q') * (starRingEnd ℂ) (unorm O ρ p' - unorm O ρ q') := by have e1 : unorm O ρ p - unorm O ρ q = (p - q) / (ρ : ℂ) := by unfold unorm; ring have e2 : unorm O ρ p' - unorm O ρ q' = (p' - q') / (ρ : ℂ) := by unfold unorm; ring rw [e1, e2, Complex.mul_conj', Complex.mul_conj', norm_div, norm_div, ← dist_eq_norm, ← dist_eq_norm, h] rcases chord_criterion (unorm_mul_conj hρ hp) (unorm_mul_conj hρ hq) (unorm_mul_conj hρ hp') (unorm_mul_conj hρ hq') hd with h1 | h1 · left apply Units.ext rw [ratioU_val hρ hp hq, ratioU_val hρ hp' hq', h1] · right apply Units.ext rw [ratioU_val hρ hp hq, ratioU_val hρ hq' hp', h1] /-- **(R3)** For a concyclic `C` with normalised set `V ⊂ ℂˣ`: `pairEnergy(C) + 2K² ≤ 2 E(V)`, i.e. `4 S(C) ≤ 2 (E − K²)`. -/ theorem pairEnergy_circle_le (C : Finset ℂ) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hC : ∀ z ∈ C, ‖z - O‖ = ρ) : (∑ x ∈ C.offDiag, ∑ y ∈ C.offDiag, if dist x.1 x.2 = dist y.1 y.2 then 1 else 0) + 2 * (C.card * C.card) ≤ 2 * energy (unitSet C O ρ) := by classical set V := unitSet C O ρ with hV set v : ℂ → ℂˣ := fun z => toUnit (unorm O ρ z) with hv have hvmem : ∀ z ∈ C, v z ∈ V := fun z hz => mem_image_of_mem _ hz have hinjC := toUnit_unorm_injOn C O hρ hC -- per ordered pair `x`, the matches with ratio `R x` have hcount : ∀ x ∈ C.offDiag, (C.offDiag.filter (fun y => ratioU O ρ y = ratioU O ρ x)).card ≤ rep V (ratioU O ρ x) := by intro x _ unfold rep apply card_le_card_of_injOn (fun y => v y.2) · intro y hy simp only [mem_coe, mem_filter, mem_offDiag] at hy ⊢ refine ⟨hvmem _ hy.1.2.1, ?_⟩ rw [← hy.2] have e : ratioU O ρ y * v y.2 = v y.1 := by unfold ratioU rw [inv_mul_cancel_right] rw [e] exact hvmem _ hy.1.1 · intro y hy y' hy' h simp only [mem_coe, mem_filter, mem_offDiag] at hy hy' have h2 : y.2 = y'.2 := hinjC hy.1.2.1 hy'.1.2.1 h have h1 : v y.1 = v y'.1 := by have e1 : v y.1 = ratioU O ρ y * v y.2 := by unfold ratioU; rw [inv_mul_cancel_right] have e2 : v y'.1 = ratioU O ρ y' * v y'.2 := by unfold ratioU; rw [inv_mul_cancel_right] rw [e1, e2, hy.2, hy'.2] simp only [h] exact Prod.ext (hinjC hy.1.1 hy'.1.1 h1) h2 -- the swap is a bijection of `C.offDiag` have hswap : ∀ x ∈ C.offDiag, (C.offDiag.filter (fun y => ratioU O ρ x = ratioU O ρ (y.2, y.1))).card = (C.offDiag.filter (fun y => ratioU O ρ y = ratioU O ρ x)).card := by intro x _ apply card_nbij' (fun y => (y.2, y.1)) (fun y => (y.2, y.1)) · intro y hy simp only [mem_coe, mem_filter, mem_offDiag] at hy ⊢ exact ⟨⟨hy.1.2.1, hy.1.1, Ne.symm hy.1.2.2⟩, hy.2.symm⟩ · intro y hy simp only [mem_coe, mem_filter, mem_offDiag] at hy ⊢ exact ⟨⟨hy.1.2.1, hy.1.1, Ne.symm hy.1.2.2⟩, hy.2.symm⟩ · intro y _ rfl · intro y _ rfl -- pointwise: [dist eq] ≤ [ratio eq] + [swapped ratio eq] have hpt : ∀ x ∈ C.offDiag, (∑ y ∈ C.offDiag, if dist x.1 x.2 = dist y.1 y.2 then 1 else 0) ≤ 2 * rep V (ratioU O ρ x) := by intro x hx have hx' := mem_offDiag.mp hx have h1 : (∑ y ∈ C.offDiag, if dist x.1 x.2 = dist y.1 y.2 then 1 else 0) ≤ (C.offDiag.filter (fun y => ratioU O ρ y = ratioU O ρ x)).card + (C.offDiag.filter (fun y => ratioU O ρ x = ratioU O ρ (y.2, y.1))).card := by rw [card_filter, card_filter, ← sum_add_distrib] apply sum_le_sum intro y hy have hy' := mem_offDiag.mp hy by_cases hd : dist x.1 x.2 = dist y.1 y.2 · rw [if_pos hd] rcases ratio_of_dist_eq hρ (hC _ hx'.1) (hC _ hx'.2.1) (hC _ hy'.1) (hC _ hy'.2.1) hd with h | h · have : ratioU O ρ y = ratioU O ρ x := by have e : (x.1, x.2) = x := rfl rw [e] at h exact h.symm rw [if_pos this] omega · have : ratioU O ρ x = ratioU O ρ (y.2, y.1) := by have e : (x.1, x.2) = x := rfl rw [e] at h exact h rw [if_pos this] omega · rw [if_neg hd] omega rw [hswap x hx] at h1 have := hcount x hx omega -- sum over `x`, compare with the energy have hsum := sum_le_sum hpt rw [← mul_sum] at hsum have hE : ∑ x ∈ C.offDiag, rep V (ratioU O ρ x) + C.card * C.card ≤ energy V := by have hdiag : ∑ a ∈ V, rep V (a * a⁻¹) = C.card * C.card := by simp only [mul_inv_cancel, rep_one, sum_const, smul_eq_mul] rw [hV, unitSet_card C O hρ hC] unfold energy rw [← sum_product' (f := fun b a => rep V (a * b⁻¹))] -- split `V ×ˢ V` into the diagonal and the image of `C.offDiag` have hinj : Set.InjOn (fun pq : ℂ × ℂ => (v pq.2, v pq.1)) (C.offDiag : Set (ℂ × ℂ)) := by intro x hx y hy h simp only [Prod.mk.injEq] at h rw [mem_coe, mem_offDiag] at hx hy exact Prod.ext (hinjC hx.1 hy.1 h.2) (hinjC hx.2.1 hy.2.1 h.1) have himg : ∑ x ∈ C.offDiag, rep V (ratioU O ρ x) = ∑ ba ∈ C.offDiag.image (fun pq : ℂ × ℂ => (v pq.2, v pq.1)), rep V (ba.2 * ba.1⁻¹) := by rw [sum_image hinj] rfl have hdisj : Disjoint (C.offDiag.image (fun pq : ℂ × ℂ => (v pq.2, v pq.1))) ((V ×ˢ V).filter (fun ba => ba.1 = ba.2)) := by rw [disjoint_left] intro ba h1 h2 rw [mem_image] at h1 obtain ⟨pq, hpq, rfl⟩ := h1 rw [mem_filter] at h2 rw [mem_offDiag] at hpq exact hpq.2.2 (hinjC hpq.1 hpq.2.1 h2.2.symm) have hsub : C.offDiag.image (fun pq : ℂ × ℂ => (v pq.2, v pq.1)) ∪ (V ×ˢ V).filter (fun ba => ba.1 = ba.2) ⊆ V ×ˢ V := by intro ba h rw [mem_union] at h rcases h with h | h · rw [mem_image] at h obtain ⟨pq, hpq, rfl⟩ := h rw [mem_offDiag] at hpq exact mem_product.mpr ⟨hvmem _ hpq.2.1, hvmem _ hpq.1⟩ · exact (mem_filter.mp h).1 have hdiag' : ∑ ba ∈ (V ×ˢ V).filter (fun ba => ba.1 = ba.2), rep V (ba.2 * ba.1⁻¹) = C.card * C.card := by rw [← hdiag] apply sum_nbij' (fun ba => ba.1) (fun a => (a, a)) · intro ba h simp only [mem_coe, mem_filter, mem_product] at h exact h.1.1 · intro a h simp only [mem_coe, mem_filter, mem_product] exact ⟨⟨h, h⟩, by simp⟩ · intro ba h simp only [mem_coe, mem_filter, mem_product] at h exact Prod.ext rfl h.2 · intro a _ rfl · intro ba h simp only [mem_coe, mem_filter, mem_product] at h rw [h.2] calc ∑ x ∈ C.offDiag, rep V (ratioU O ρ x) + C.card * C.card = ∑ ba ∈ C.offDiag.image (fun pq : ℂ × ℂ => (v pq.2, v pq.1)) ∪ (V ×ˢ V).filter (fun ba => ba.1 = ba.2), rep V (ba.2 * ba.1⁻¹) := by rw [sum_union hdisj, himg, hdiag'] _ ≤ ∑ ba ∈ V ×ˢ V, rep V (ba.2 * ba.1⁻¹) := sum_le_sum_of_subset hsub omega end Erdos94ThmA /-! ### (R4) The centre is not a vertex: a near-full regular polygon about `O` has `O` in its hull -/ namespace Erdos94ThmA open Finset theorem unorm_inv {O z : ℂ} {ρ : ℝ} (hρ : 0 < ρ) : z = O + (ρ : ℂ) * unorm O ρ z := by have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' unfold unorm field_simp ring /-- The segment step: if `z₁ = O + ρu`, `z₂ = O + ρue^{iα}`, `z₃ = O + ρue^{−iα}` lie in a set and `cos α < 0`, then `O` is in its convex hull. -/ theorem center_mem_hull_of_triple (S : Set ℂ) {O u : ℂ} {ρ α : ℝ} (h1 : O + (ρ : ℂ) * u ∈ convexHull ℝ S) (h2 : O + (ρ : ℂ) * (u * Complex.exp (α * Complex.I)) ∈ convexHull ℝ S) (h3 : O + (ρ : ℂ) * (u * Complex.exp (-α * Complex.I)) ∈ convexHull ℝ S) (hcos : Real.cos α < 0) : O ∈ convexHull ℝ S := by have hc := convex_convexHull ℝ S have hM := hc.add_smul_sub_mem h2 h3 (show (1 / 2 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) have eM : O + (ρ : ℂ) * (u * Complex.exp (α * Complex.I)) + (1 / 2 : ℝ) • (O + (ρ : ℂ) * (u * Complex.exp (-α * Complex.I)) - (O + (ρ : ℂ) * (u * Complex.exp (α * Complex.I)))) = O + (ρ : ℂ) * u * (Real.cos α : ℂ) := by rw [Complex.ofReal_cos, show Complex.cos (α : ℂ) = (Complex.exp (α * Complex.I) + Complex.exp (-α * Complex.I)) / 2 by rw [← Complex.two_cos]; ring, Complex.real_smul] push_cast ring rw [eM] at hM have hl0 : (0 : ℝ) ≤ 1 / (1 - Real.cos α) := by apply div_nonneg zero_le_one linarith have hl1 : 1 / (1 - Real.cos α) ≤ 1 := by rw [div_le_one (by linarith)] linarith have h := hc.add_smul_sub_mem h1 hM ⟨hl0, hl1⟩ have e : O + (ρ : ℂ) * u + (1 / (1 - Real.cos α) : ℝ) • (O + (ρ : ℂ) * u * (Real.cos α : ℂ) - (O + (ρ : ℂ) * u)) = O := by have hne : (1 : ℂ) - Complex.cos (α : ℂ) ≠ 0 := by rw [← Complex.ofReal_cos] have : (1 : ℝ) - Real.cos α ≠ 0 := by linarith exact_mod_cast this rw [Complex.real_smul] push_cast field_simp ring rwa [e] at h /-- **(R4)** Let `D = H` be a subgroup of `ℂˣ` of order `g ≥ 3` and `b₀ ∈ ℂˣ`. If fewer than `g/3` points of the regular polygon `b₀ D` are missing from the normalised circle part `V` of `C`, then `O ∈ conv C`. -/ theorem center_mem_hull (C : Finset ℂ) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hC : ∀ z ∈ C, ‖z - O‖ = ρ) (H : Subgroup ℂˣ) (D : Finset ℂˣ) (hmem : ∀ x, x ∈ H ↔ x ∈ D) (hg : 3 ≤ D.card) (b₀ : ℂˣ) (hmiss : 3 * (D.filter (fun d => ¬ (b₀ * d ∈ unitSet C O ρ))).card < D.card) : O ∈ convexHull ℝ (C : Set ℂ) := by classical set V := unitSet C O ρ with hV set g := D.card with hgdef have hg0 : 0 < g := by omega set j : ℕ := (g + 2) / 3 with hj have hjg : j < g := by omega set ω : ℂˣ := toUnit (Complex.exp (2 * Real.pi * Complex.I * (j / g))) with hω have hωD : ω ∈ D := exp_mem_subgroup H D hmem hg0 hjg have hDmul : ∀ x ∈ D, ∀ y ∈ D, x * y ∈ D := by intro x hx y hy rw [← hmem] at hx hy ⊢ exact H.mul_mem hx hy have hDinv : ∀ x ∈ D, x⁻¹ ∈ D := by intro x hx rw [← hmem] at hx ⊢ exact H.inv_mem hx have hωiD := hDinv ω hωD -- the three "missing" sets have the same size have hshift : ∀ c ∈ D, (D.filter (fun d => ¬ (b₀ * (d * c) ∈ V))).card = (D.filter (fun d => ¬ (b₀ * d ∈ V))).card := by intro c hc apply card_nbij' (fun d => d * c) (fun d => d * c⁻¹) · intro d hd simp only [mem_coe, mem_filter] at hd ⊢ exact ⟨hDmul _ hd.1 _ hc, hd.2⟩ · intro d hd simp only [mem_coe, mem_filter] at hd ⊢ refine ⟨hDmul _ hd.1 _ (hDinv _ hc), ?_⟩ rw [inv_mul_cancel_right] exact hd.2 · intro d _ simp only [mul_inv_cancel_right] · intro d _ simp only [inv_mul_cancel_right] set bad := D.filter (fun d => ¬ (b₀ * d ∈ V) ∨ ¬ (b₀ * (d * ω) ∈ V) ∨ ¬ (b₀ * (d * ω⁻¹) ∈ V)) with hbad have hbad_le : bad.card ≤ 3 * (D.filter (fun d => ¬ (b₀ * d ∈ V))).card := by have hsub : bad ⊆ D.filter (fun d => ¬ (b₀ * d ∈ V)) ∪ (D.filter (fun d => ¬ (b₀ * (d * ω) ∈ V)) ∪ D.filter (fun d => ¬ (b₀ * (d * ω⁻¹) ∈ V))) := by intro d hd rw [mem_filter] at hd rw [mem_union, mem_union, mem_filter, mem_filter, mem_filter] rcases hd.2 with h | h | h · exact Or.inl ⟨hd.1, h⟩ · exact Or.inr (Or.inl ⟨hd.1, h⟩) · exact Or.inr (Or.inr ⟨hd.1, h⟩) have := card_le_card hsub have h1 := card_union_le (D.filter (fun d => ¬ (b₀ * d ∈ V))) (D.filter (fun d => ¬ (b₀ * (d * ω) ∈ V)) ∪ D.filter (fun d => ¬ (b₀ * (d * ω⁻¹) ∈ V))) have h2 := card_union_le (D.filter (fun d => ¬ (b₀ * (d * ω) ∈ V))) (D.filter (fun d => ¬ (b₀ * (d * ω⁻¹) ∈ V))) rw [hshift ω hωD, hshift ω⁻¹ hωiD] at h2 omega have hlt : bad.card < D.card := by omega obtain ⟨d, hdD, hdbad⟩ := exists_mem_notMem_of_card_lt_card hlt have hgood : b₀ * d ∈ V ∧ b₀ * (d * ω) ∈ V ∧ b₀ * (d * ω⁻¹) ∈ V := by by_contra hn apply hdbad rw [mem_filter] refine ⟨hdD, ?_⟩ tauto -- pull back to points of `C` have pull : ∀ y ∈ V, ∃ z ∈ C, toUnit (unorm O ρ z) = y := by intro y hy rw [hV, unitSet, mem_image] at hy exact hy obtain ⟨z₁, hz₁, e₁⟩ := pull _ hgood.1 obtain ⟨z₂, hz₂, e₂⟩ := pull _ hgood.2.1 obtain ⟨z₃, hz₃, e₃⟩ := pull _ hgood.2.2 set u : ℂ := ((b₀ * d : ℂˣ) : ℂ) with hu have hval : ∀ z ∈ C, ∀ y : ℂˣ, toUnit (unorm O ρ z) = y → unorm O ρ z = (y : ℂ) := by intro z hz y hy rw [← hy, toUnit_val (unorm_ne_zero hρ (hC z hz))] have hωval : (ω : ℂ) = Complex.exp (2 * Real.pi * Complex.I * (j / g)) := toUnit_val (Complex.exp_ne_zero _) set α : ℝ := 2 * Real.pi * j / g with hα have hαe : (2 * Real.pi * Complex.I * (j / g) : ℂ) = (α : ℂ) * Complex.I := by rw [hα] push_cast ring have hS : ∀ z ∈ C, z ∈ convexHull ℝ (C : Set ℂ) := fun z hz => subset_convexHull ℝ _ (mem_coe.mpr hz) apply center_mem_hull_of_triple (C : Set ℂ) (u := u) (ρ := ρ) (α := α) · have := unorm_inv (O := O) (z := z₁) hρ rw [hval z₁ hz₁ _ e₁] at this rw [← this] exact hS z₁ hz₁ · have := unorm_inv (O := O) (z := z₂) hρ rw [hval z₂ hz₂ _ e₂, Units.val_mul, Units.val_mul, hωval, hαe] at this have e : (ρ : ℂ) * (u * Complex.exp (α * Complex.I)) = (ρ : ℂ) * ((b₀ : ℂ) * ((d : ℂ) * Complex.exp (α * Complex.I))) := by rw [hu, Units.val_mul] ring rw [e, ← this] exact hS z₂ hz₂ · have := unorm_inv (O := O) (z := z₃) hρ rw [hval z₃ hz₃ _ e₃, Units.val_mul, Units.val_mul, Units.val_inv_eq_inv_val, hωval, hαe, ← Complex.exp_neg] at this have e : (ρ : ℂ) * (u * Complex.exp (-α * Complex.I)) = (ρ : ℂ) * ((b₀ : ℂ) * ((d : ℂ) * Complex.exp (-(α * Complex.I)))) := by rw [hu, Units.val_mul, neg_mul] ring rw [e, ← this] exact hS z₃ hz₃ · -- cos α < 0 since g/3 ≤ j ≤ (g + 2)/3 have hgR : (3 : ℝ) ≤ g := by exact_mod_cast hg have hj1 : (g : ℝ) ≤ 3 * j := by have : g ≤ 3 * j := by omega exact_mod_cast this have hj2 : 3 * (j : ℝ) ≤ g + 2 := by have : 3 * j ≤ g + 2 := by omega exact_mod_cast this have hgpos : (0 : ℝ) < g := by linarith apply Real.cos_neg_of_pi_div_two_lt_of_lt · rw [hα, lt_div_iff₀ hgpos] nlinarith [Real.pi_pos] · rw [hα, div_lt_iff₀ hgpos] nlinarith [Real.pi_pos] /-- ConvexIndep transfers to the image in `ℂ`. -/ theorem convexIndep_image_C {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) {z : ℂ} (hz : z ∈ P.image Complex.orthonormalBasisOneI.repr.symm) : z ∉ convexHull ℝ ((P.image Complex.orthonormalBasisOneI.repr.symm : Set ℂ) \ {z}) := by set e := Complex.orthonormalBasisOneI.repr.symm with he rw [mem_image] at hz obtain ⟨x, hx, rfl⟩ := hz intro hmem apply hP x hx have hset : ((P.image e : Finset ℂ) : Set ℂ) \ {e x} = e.toLinearEquiv.toLinearMap '' ((P : Set _) \ {x}) := by ext w simp only [coe_image, Set.mem_diff, Set.mem_image, Set.mem_singleton_iff, mem_coe] constructor · rintro ⟨⟨y, hy, rfl⟩, hne⟩ exact ⟨y, ⟨hy, fun h => hne (by rw [h])⟩, rfl⟩ · rintro ⟨y, ⟨hy, hne⟩, rfl⟩ exact ⟨⟨y, hy, rfl⟩, fun h => hne (e.injective h)⟩ rw [hset, ← LinearMap.image_convexHull] at hmem obtain ⟨y, hy, hyx⟩ := hmem have : y = x := e.injective hyx rwa [this] at hy end Erdos94ThmA /-! ### (G2) and the concyclic theorem (4.2): `S(Q) ≤ R(|Q|)` for every concyclic `Q` -/ namespace Erdos94ThmA open Finset /-- (G2) A point `x ≠ O` sees each distance at most twice among points of a circle centred at `O`. -/ theorem card_sphere_inter_le_two {Q : Finset (EuclideanSpace ℝ (Fin 2))} {O x : EuclideanSpace ℝ (Fin 2)} {ρ u : ℝ} (hQ : ∀ q ∈ Q, dist q O = ρ) (hx : x ≠ O) : (Q.filter (fun q => dist x q = u)).card ≤ 2 := by by_contra hcon obtain ⟨a, b, c, ha, hb, hc, hab, hac, hbc⟩ := Finset.two_lt_card_iff.mp (not_le.mp hcon) rw [Finset.mem_filter] at ha hb hc have ha' : dist a x = u := by rw [dist_comm]; exact ha.2 have hb' : dist b x = u := by rw [dist_comm]; exact hb.2 have hc' : dist c x = u := by rw [dist_comm]; exact hc.2 have key := EuclideanGeometry.eq_of_dist_eq_of_dist_eq_of_finrank_eq_two finrank_euclideanSpace_fin hx hab ha' hb' hc' (hQ a ha.1) (hQ b hb.1) (hQ c hc.1) rcases key with h | h · exact hac h.symm · exact hbc h.symm /-- In a concyclic set every distance occurs at most `|Q|` times. -/ theorem concyclic_mult_le {Q : Finset (EuclideanSpace ℝ (Fin 2))} {O : EuclideanSpace ℝ (Fin 2)} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, dist q O = ρ) (u : ℝ) : distanceMultiplicity Q u ≤ Q.card := by have h1 : (Q.offDiag.filter (fun x => dist x.1 x.2 = u)).card ≤ 2 * Q.card := by calc (Q.offDiag.filter (fun x => dist x.1 x.2 = u)).card ≤ ((Q ×ˢ Q).filter (fun x => dist x.1 x.2 = u)).card := card_le_card (filter_subset_filter _ (fun x hx => by rw [mem_offDiag] at hx exact mem_product.mpr ⟨hx.1, hx.2.1⟩)) _ = ∑ a ∈ Q, (Q.filter (fun b => dist a b = u)).card := by rw [card_filter, sum_product] simp only [card_filter] _ ≤ ∑ _a ∈ Q, 2 := by apply sum_le_sum intro a ha have haO : a ≠ O := by intro h have := hQ a ha rw [h, dist_self] at this linarith exact card_sphere_inter_le_two hQ haO _ = 2 * Q.card := by rw [sum_const, smul_eq_mul, mul_comm] unfold distanceMultiplicity omega /-- **Concyclic theorem (4.2).** Every concyclic set does no better than the regular polygon with the same number of points: `∑ f(u)² ≤ ngonValue |Q|` (= `R(|Q|)`). -/ theorem concyclic_sum_sq_le {Q : Finset (EuclideanSpace ℝ (Fin 2))} {O : EuclideanSpace ℝ (Fin 2)} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, dist q O = ρ) : ∑ u ∈ distanceSet Q, (distanceMultiplicity Q u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue Q.card := Erdos94Infra.sum_sq_le_of_mult_le Q Q.card rfl (fun u _ => concyclic_mult_le hρ hQ u) end Erdos94ThmA /-! ### (R5, analytic core) A quadratic form in `(cos t, sin t)` with a nonzero `cos·sin` or `sin` coefficient vanishes at most four times on `[0, 2π)` -/ namespace Erdos94ThmA open Finset Polynomial theorem cos_sin_via_exp (t : ℝ) : Complex.cos (t : ℂ) = (Complex.exp (t * Complex.I) + (Complex.exp (t * Complex.I))⁻¹) / 2 ∧ Complex.sin (t : ℂ) = ((Complex.exp (t * Complex.I))⁻¹ - Complex.exp (t * Complex.I)) * Complex.I / 2 := by constructor · rw [← Complex.exp_neg, ← neg_mul] have := Complex.two_cos (t : ℂ) linear_combination this / 2 · rw [← Complex.exp_neg, ← neg_mul] have := Complex.two_sin (t : ℂ) linear_combination this / 2 /-- The polynomial `Q` with `Q(e^{it}) = 4 e^{2it} (A c² + B c s + F c + H s + K₀)`. -/ noncomputable def trigPoly (A B F H K₀ : ℝ) : Polynomial ℂ := C ((A : ℂ) - B * Complex.I) * X ^ 4 + C (2 * (F : ℂ) - 2 * H * Complex.I) * X ^ 3 + C (2 * (A : ℂ) + 4 * K₀) * X ^ 2 + C (2 * (F : ℂ) + 2 * H * Complex.I) * X + C ((A : ℂ) + B * Complex.I) theorem trigPoly_eval (A B F H K₀ t : ℝ) : (trigPoly A B F H K₀).eval (Complex.exp (t * Complex.I)) = 4 * (Complex.exp (t * Complex.I)) ^ 2 * ((A * Real.cos t ^ 2 + B * Real.cos t * Real.sin t + F * Real.cos t + H * Real.sin t + K₀ : ℝ) : ℂ) := by obtain ⟨hc, hs⟩ := cos_sin_via_exp t have hz : Complex.exp (t * Complex.I) ≠ 0 := Complex.exp_ne_zero _ push_cast rw [hc, hs] simp only [trigPoly, eval_add, eval_mul, eval_C, eval_pow, eval_X] field_simp ring theorem trigPoly_coeff4 (A B F H K₀ : ℝ) : (trigPoly A B F H K₀).coeff 4 = (A : ℂ) - B * Complex.I := by simp only [trigPoly, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X, coeff_C] norm_num theorem trigPoly_coeff3 (A B F H K₀ : ℝ) : (trigPoly A B F H K₀).coeff 3 = 2 * (F : ℂ) - 2 * H * Complex.I := by simp only [trigPoly, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X, coeff_C] norm_num theorem trigPoly_ne_zero {A B F H K₀ : ℝ} (hBH : B ≠ 0 ∨ H ≠ 0) : trigPoly A B F H K₀ ≠ 0 := by intro hQ rcases hBH with hB | hH · have h4 := trigPoly_coeff4 A B F H K₀ rw [hQ, coeff_zero] at h4 have h4i := congrArg Complex.im h4 simp at h4i exact hB h4i · have h3 := trigPoly_coeff3 A B F H K₀ rw [hQ, coeff_zero] at h3 have h3i := congrArg Complex.im h3 simp at h3i exact hH h3i theorem trigPoly_natDegree_le (A B F H K₀ : ℝ) : (trigPoly A B F H K₀).natDegree ≤ 4 := by unfold trigPoly compute_degree theorem exp_injOn_Ico : Set.InjOn (fun t : ℝ => Complex.exp (t * Complex.I)) (Set.Ico 0 (2 * Real.pi)) := by intro t ht t' ht' h simp only at h obtain ⟨m, hm⟩ := Complex.exp_eq_exp_iff_exists_int.mp h have hm' : t = t' + m * (2 * Real.pi) := by have := congrArg Complex.im hm simp at this linarith have hpi := Real.pi_pos have h1 : (m : ℝ) * (2 * Real.pi) < 2 * Real.pi := by linarith [ht.2, ht'.1] have h2 : -(2 * Real.pi) < (m : ℝ) * (2 * Real.pi) := by linarith [ht.1, ht'.2] have hm1 : (m : ℝ) < 1 := by nlinarith have hm2 : -1 < (m : ℝ) := by nlinarith have hm0 : m = 0 := by have : m < 1 := by exact_mod_cast hm1 have : -1 < m := by exact_mod_cast hm2 omega rw [hm0] at hm' simpa using hm' /-- **(TC)** If `B ≠ 0` or `H ≠ 0`, then `A cos²t + B cos t sin t + F cos t + H sin t + K₀` has at most four zeros in `[0, 2π)`. -/ theorem trig_zeros_le_four {A B F H K₀ : ℝ} (hBH : B ≠ 0 ∨ H ≠ 0) (T : Finset ℝ) (hT : ∀ t ∈ T, 0 ≤ t ∧ t < 2 * Real.pi) (hzero : ∀ t ∈ T, A * Real.cos t ^ 2 + B * Real.cos t * Real.sin t + F * Real.cos t + H * Real.sin t + K₀ = 0) : T.card ≤ 4 := by classical have hQ0 := trigPoly_ne_zero (A := A) (F := F) (K₀ := K₀) hBH have hroot : ∀ t ∈ T, Complex.exp (t * Complex.I) ∈ (trigPoly A B F H K₀).roots.toFinset := by intro t ht rw [Multiset.mem_toFinset, mem_roots hQ0, IsRoot.def, trigPoly_eval, hzero t ht] simp have hinj : Set.InjOn (fun t : ℝ => Complex.exp (t * Complex.I)) (T : Set ℝ) := Set.InjOn.mono (fun t ht => Set.mem_Ico.mpr (hT t (mem_coe.mp ht))) exp_injOn_Ico calc T.card = (T.image (fun t : ℝ => Complex.exp (t * Complex.I))).card := (card_image_of_injOn hinj).symm _ ≤ (trigPoly A B F H K₀).roots.toFinset.card := card_le_card (fun z hz => by rw [mem_image] at hz obtain ⟨t, ht, rfl⟩ := hz exact hroot t ht) _ ≤ Multiset.card (trigPoly A B F H K₀).roots := Multiset.toFinset_card_le _ _ ≤ (trigPoly A B F H K₀).natDegree := card_roots' _ _ ≤ 4 := trigPoly_natDegree_le A B F H K₀ end Erdos94ThmA /-! ### (R5) A `k`-step of Lemma C2 is a zero of a fixed TC form -/ namespace Erdos94ThmA open Finset /-- Coefficients of the step form (depending only on `d`, `δ` and `κ = kδ`). -/ noncomputable def stepCo (d δ κ : ℝ) : ℝ × ℝ × ℝ × ℝ × ℝ := let e := (1 - d ^ 2) / 2 let α := d * (Real.cos κ - Real.cos δ) let β := e * (Real.cos κ - 1) let γ := d * Real.sin δ let S := Real.sin κ ^ 2 if Real.sin κ = 0 then (0, 0, α, γ, β) else (S * d ^ 2 + α ^ 2 - γ ^ 2, 2 * α * γ, 2 * S * e * d + 2 * α * β, 2 * β * γ, S * e ^ 2 + β ^ 2 + γ ^ 2 - S) theorem step_zero {d δ κ t φ : ℝ} (h1 : d ^ 2 + 1 - 2 * d * Real.cos t = 2 - 2 * Real.cos φ) (h2 : d ^ 2 + 1 - 2 * d * Real.cos (t + δ) = 2 - 2 * Real.cos (φ + κ)) : (stepCo d δ κ).1 * Real.cos t ^ 2 + (stepCo d δ κ).2.1 * Real.cos t * Real.sin t + (stepCo d δ κ).2.2.1 * Real.cos t + (stepCo d δ κ).2.2.2.1 * Real.sin t + (stepCo d δ κ).2.2.2.2 = 0 := by have hcφ : Real.cos φ = (1 - d ^ 2) / 2 + d * Real.cos t := by linarith have hcφκ : Real.cos (φ + κ) = (1 - d ^ 2) / 2 + d * Real.cos (t + δ) := by linarith rw [Real.cos_add, Real.cos_add, hcφ] at hcφκ have hL : Real.sin φ * Real.sin κ = d * (Real.cos κ - Real.cos δ) * Real.cos t + (1 - d ^ 2) / 2 * (Real.cos κ - 1) + d * Real.sin δ * Real.sin t := by linear_combination -hcφκ have hpφ := Real.sin_sq_add_cos_sq φ have hpt := Real.sin_sq_add_cos_sq t unfold stepCo by_cases hκ : Real.sin κ = 0 · simp only [hκ, if_true] rw [hκ, mul_zero] at hL linear_combination -hL · simp only [hκ, if_false] linear_combination (Real.sin κ ^ 2) * hpφ - (Real.sin φ * Real.sin κ + (d * (Real.cos κ - Real.cos δ) * Real.cos t + (1 - d ^ 2) / 2 * (Real.cos κ - 1) + d * Real.sin δ * Real.sin t)) * hL - (Real.sin κ ^ 2) * (Real.cos φ + ((1 - d ^ 2) / 2 + d * Real.cos t)) * hcφ - (d * Real.sin δ) ^ 2 * hpt theorem stepCo_BH {d δ κ : ℝ} (hd : 0 < d) (hd1 : d ≠ 1) (hδ0 : 0 < δ) (hδπ : δ < Real.pi) : (stepCo d δ κ).2.1 ≠ 0 ∨ (stepCo d δ κ).2.2.2.1 ≠ 0 := by have hγ : d * Real.sin δ ≠ 0 := mul_ne_zero hd.ne' (Real.sin_pos_of_pos_of_lt_pi hδ0 hδπ).ne' unfold stepCo by_cases hκ : Real.sin κ = 0 · simp only [hκ, if_true] exact Or.inr hγ · simp only [hκ, if_false] by_contra hcon push_neg at hcon obtain ⟨hB, hH⟩ := hcon have hα : d * (Real.cos κ - Real.cos δ) = 0 := by have : 2 * (d * (Real.cos κ - Real.cos δ)) * (d * Real.sin δ) = 0 := hB rcases mul_eq_zero.mp this with h | h · linarith · exact absurd h hγ have hβ : (1 - d ^ 2) / 2 * (Real.cos κ - 1) = 0 := by have : 2 * ((1 - d ^ 2) / 2 * (Real.cos κ - 1)) * (d * Real.sin δ) = 0 := hH rcases mul_eq_zero.mp this with h | h · linarith · exact absurd h hγ have hcκ : Real.cos κ = Real.cos δ := by rcases mul_eq_zero.mp hα with h | h · linarith · linarith have hcδ : Real.cos δ < 1 := by have := Real.cos_lt_cos_of_nonneg_of_le_pi (le_refl 0) hδπ.le hδ0 rwa [Real.cos_zero] at this rcases mul_eq_zero.mp hβ with h | h · apply hd1 have : d ^ 2 = 1 := by linarith have h' : (d - 1) * (d + 1) = 0 := by linear_combination this rcases mul_eq_zero.mp h' with h'' | h'' · linarith · linarith · linarith /-- **k-steps are rare.** All positions `t ∈ [0, 2π)` at which a `k`-step occurs (for one fixed `κ`) number at most four. -/ theorem steps_le_four {d δ κ : ℝ} (hd : 0 < d) (hd1 : d ≠ 1) (hδ0 : 0 < δ) (hδπ : δ < Real.pi) (T : Finset ℝ) (hT : ∀ t ∈ T, 0 ≤ t ∧ t < 2 * Real.pi) (hstep : ∀ t ∈ T, ∃ φ : ℝ, d ^ 2 + 1 - 2 * d * Real.cos t = 2 - 2 * Real.cos φ ∧ d ^ 2 + 1 - 2 * d * Real.cos (t + δ) = 2 - 2 * Real.cos (φ + κ)) : T.card ≤ 4 := trig_zeros_le_four (stepCo_BH (κ := κ) hd hd1 hδ0 hδπ) T hT (fun t ht => by obtain ⟨φ, h1, h2⟩ := hstep t ht exact step_zero h1 h2) end Erdos94ThmA /-! ### (R5) Counting on one arc: few steps force few matches -/ namespace Erdos94ThmA open Finset theorem arc_steps_many (J : ℕ) (Mt : Finset ℕ) (hMt : Mt ⊆ range J) : 2 * Mt.card ≤ J + 1 + (Mt.filter (fun j => j + 1 ∈ Mt)).card := by classical have hsplit := card_filter_add_card_filter_not (s := Mt) (fun j => j + 1 ∈ Mt) have hN : (Mt.filter (fun j => ¬ (j + 1 ∈ Mt))).card ≤ (range (J + 1) \ Mt).card := by apply card_le_card_of_injOn (fun j => j + 1) · intro j hj simp only [mem_coe, mem_filter] at hj have := mem_range.mp (hMt hj.1) simp only [mem_coe, mem_sdiff, mem_range] exact ⟨by omega, hj.2⟩ · intro a _ b _ h simp only at h omega have hsub : Mt ⊆ range (J + 1) := fun j hj => mem_range.mpr (by have := mem_range.mp (hMt hj); omega) have hsd : (range (J + 1) \ Mt).card = J + 1 - Mt.card := by rw [card_sdiff_of_subset hsub, card_range] have hle : Mt.card ≤ J + 1 := by have := card_le_card hsub rwa [card_range] at this omega theorem arc_sum_incr_le (L : ℕ) (Mt : Finset ℕ) (s : ℕ → ℕ) (hs1 : ∀ j ∈ Mt, 1 ≤ s j) (hsL : ∀ j ∈ Mt, s j ≤ L) (hmono : ∀ j ∈ Mt, ∀ j' ∈ Mt, j < j' → s j < s j') : ∑ j ∈ Mt.filter (fun j => j + 1 ∈ Mt), (s (j + 1) - s j) ≤ L := by classical have hdisj : ((Mt.filter (fun j => j + 1 ∈ Mt)) : Set ℕ).PairwiseDisjoint (fun j => Ico (s j) (s (j + 1))) := by intro j hj j' hj' hne simp only [Function.onFun] rw [disjoint_left] intro x hx hx' rw [mem_Ico] at hx hx' rw [mem_coe, mem_filter] at hj hj' rcases lt_or_gt_of_ne hne with h | h · have : s (j + 1) ≤ s j' := by rcases (show j + 1 = j' ∨ j + 1 < j' by omega) with h' | h' · rw [h'] · exact (hmono _ hj.2 _ hj'.1 h').le omega · have : s (j' + 1) ≤ s j := by rcases (show j' + 1 = j ∨ j' + 1 < j by omega) with h' | h' · rw [h'] · exact (hmono _ hj'.2 _ hj.1 h').le omega have hcard := card_biUnion hdisj have hsub : (Mt.filter (fun j => j + 1 ∈ Mt)).biUnion (fun j => Ico (s j) (s (j + 1))) ⊆ Ico 1 (L + 1) := by intro x hx rw [mem_biUnion] at hx obtain ⟨j, hj, hx⟩ := hx rw [mem_Ico] at hx ⊢ rw [mem_filter] at hj have := hs1 j hj.1 have := hsL (j + 1) hj.2 omega have h1 := card_le_card hsub rw [hcard, Nat.card_Ico] at h1 have h2 : ∑ j ∈ Mt.filter (fun j => j + 1 ∈ Mt), (s (j + 1) - s j) = ∑ j ∈ Mt.filter (fun j => j + 1 ∈ Mt), (Ico (s j) (s (j + 1))).card := by simp only [Nat.card_Ico] omega /-- **Arc counting.** `Mt ⊆ [0, J)` with an order-preserving `s : Mt → [1, L]` such that, for every `k ≥ 1`, at most four `j` have `j, j+1 ∈ Mt` and `s(j+1) = s(j) + k`. Then for every `K₀`: `(K₀ + 1) · 2|Mt| ≤ (K₀ + 1)(J + 1 + 4K₀) + L`. -/ theorem arc_count (J L K₀ : ℕ) (Mt : Finset ℕ) (s : ℕ → ℕ) (hMt : Mt ⊆ range J) (hs1 : ∀ j ∈ Mt, 1 ≤ s j) (hsL : ∀ j ∈ Mt, s j ≤ L) (hmono : ∀ j ∈ Mt, ∀ j' ∈ Mt, j < j' → s j < s j') (h4 : ∀ k, 1 ≤ k → (Mt.filter (fun j => j + 1 ∈ Mt ∧ s (j + 1) = s j + k)).card ≤ 4) : (K₀ + 1) * (2 * Mt.card) ≤ (K₀ + 1) * (J + 1 + 4 * K₀) + L := by classical obtain ⟨steps, hsteps⟩ : ∃ st, st = Mt.filter (fun j => j + 1 ∈ Mt) := ⟨_, rfl⟩ have ha := arc_steps_many J Mt hMt rw [← hsteps] at ha have hsumk := arc_sum_incr_le L Mt s hs1 hsL hmono rw [← hsteps] at hsumk have hinc : ∀ j ∈ steps, s j < s (j + 1) := by intro j hj rw [hsteps, mem_filter] at hj exact hmono j hj.1 (j + 1) hj.2 (by omega) have hsl := card_filter_add_card_filter_not (s := steps) (fun j => s (j + 1) - s j ≤ K₀) -- small steps: at most 4 for each increment `k ∈ [1, K₀]` have hsmall_le : (steps.filter (fun j => s (j + 1) - s j ≤ K₀)).card ≤ 4 * K₀ := by have hfib : (steps.filter (fun j => s (j + 1) - s j ≤ K₀)).card = ∑ k ∈ Icc 1 K₀, ((steps.filter (fun j => s (j + 1) - s j ≤ K₀)).filter (fun j => s (j + 1) - s j = k)).card := by apply card_eq_sum_card_fiberwise intro j hj rw [mem_coe, mem_filter] at hj have := hinc j hj.1 have h2 := hj.2 simp only [mem_coe, mem_Icc] omega rw [hfib] calc ∑ k ∈ Icc 1 K₀, ((steps.filter (fun j => s (j + 1) - s j ≤ K₀)).filter (fun j => s (j + 1) - s j = k)).card ≤ ∑ _k ∈ Icc 1 K₀, 4 := by apply sum_le_sum intro k hk rw [mem_Icc] at hk refine le_trans (card_le_card ?_) (h4 k hk.1) intro j hj rw [mem_filter, mem_filter] at hj have hj1 := hj.1.1 rw [hsteps, mem_filter] at hj1 rw [mem_filter] refine ⟨hj1.1, hj1.2, ?_⟩ have := hinc j hj.1.1 omega _ = 4 * K₀ := by rw [sum_const, Nat.card_Icc, smul_eq_mul]; omega -- large steps: each costs more than `K₀` of the total increment have hlarge_le : (K₀ + 1) * (steps.filter (fun j => ¬ (s (j + 1) - s j ≤ K₀))).card ≤ L := by have h1 : ∑ _j ∈ steps.filter (fun j => ¬ (s (j + 1) - s j ≤ K₀)), (K₀ + 1) ≤ ∑ j ∈ steps.filter (fun j => ¬ (s (j + 1) - s j ≤ K₀)), (s (j + 1) - s j) := by apply sum_le_sum intro j hj rw [mem_filter] at hj omega have h2 : ∑ j ∈ steps.filter (fun j => ¬ (s (j + 1) - s j ≤ K₀)), (s (j + 1) - s j) ≤ ∑ j ∈ steps, (s (j + 1) - s j) := sum_le_sum_of_subset (filter_subset _ _) rw [sum_const, smul_eq_mul] at h1 rw [mul_comm] omega nlinarith end Erdos94ThmA /-! ### (R5) Lemma C2, angle form: one arc -/ namespace Erdos94ThmA open Finset /-- `t` is matched: the distance `√(d² + 1 − 2d cos t)` is a chord length `2 sin(sπ/g)`, `1 ≤ s ≤ g/2`. -/ def matchedAng (d : ℝ) (g : ℕ) (t : ℝ) : Prop := ∃ s : ℕ, 1 ≤ s ∧ s ≤ g / 2 ∧ d ^ 2 + 1 - 2 * d * Real.cos t = 2 - 2 * Real.cos (s * (2 * Real.pi / g)) /-- The matched positions on the arc `(0, π)` with offset `c`. -/ noncomputable def arcSet (d : ℝ) (g : ℕ) (c : ℝ) : Finset ℕ := by classical exact (range (g / 2 + 1)).filter (fun j => 0 < c + j * (2 * Real.pi / g) ∧ c + j * (2 * Real.pi / g) < Real.pi ∧ matchedAng d g (c + j * (2 * Real.pi / g))) theorem chord_index_lt {g : ℕ} (hg : 3 ≤ g) {s s' : ℕ} (hs : s ≤ g / 2) (hs' : s' ≤ g / 2) (h : Real.cos (s * (2 * Real.pi / g)) > Real.cos (s' * (2 * Real.pi / g))) : s < s' := by have hgR : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) by_contra hcon have hle : s' ≤ s := by omega have hπ := Real.pi_pos have hsR : (s : ℝ) * (2 * Real.pi / g) ≤ Real.pi := by have : (s : ℝ) ≤ g / 2 := by have : 2 * s ≤ g := by omega have : (2 * s : ℝ) ≤ g := by exact_mod_cast this linarith rw [mul_div_assoc'] rw [div_le_iff₀ hgR] nlinarith have h0 : (0 : ℝ) ≤ s' * (2 * Real.pi / g) := by positivity have hle' : (s' : ℝ) * (2 * Real.pi / g) ≤ s * (2 * Real.pi / g) := by apply mul_le_mul_of_nonneg_right _ (by positivity) exact_mod_cast hle have := Real.cos_le_cos_of_nonneg_of_le_pi h0 hsR hle' linarith /-- **One arc.** For an offset `c ∈ [0, δ)` (`δ = 2π/g`) and every `K₀`, `(K₀ + 1) · 2 |arcSet| ≤ (K₀ + 1)(g/2 + 2 + 4K₀) + g/2`. -/ theorem arcSet_bound {d : ℝ} (hd : 0 < d) (hd1 : d ≠ 1) {g : ℕ} (hg : 3 ≤ g) {c : ℝ} (K₀ : ℕ) : (K₀ + 1) * (2 * (arcSet d g c).card) ≤ (K₀ + 1) * (g / 2 + 1 + 1 + 4 * K₀) + g / 2 := by classical set δ : ℝ := 2 * Real.pi / g with hδ have hgR : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) have hδ0 : 0 < δ := by positivity have hδπ : δ < Real.pi := by rw [hδ, div_lt_iff₀ hgR] have : (3 : ℝ) ≤ g := by exact_mod_cast hg nlinarith [Real.pi_pos] -- the chosen chord index let s : ℕ → ℕ := fun j => if h : matchedAng d g (c + j * δ) then Classical.choose h else 0 have hs_spec : ∀ j ∈ arcSet d g c, 1 ≤ s j ∧ s j ≤ g / 2 ∧ d ^ 2 + 1 - 2 * d * Real.cos (c + j * δ) = 2 - 2 * Real.cos (s j * δ) := by intro j hj unfold arcSet at hj rw [mem_filter] at hj have hm : matchedAng d g (c + j * δ) := hj.2.2.2 simp only [s] rw [dif_pos hm] exact Classical.choose_spec hm have harc : ∀ j ∈ arcSet d g c, 0 < c + j * δ ∧ c + j * δ < Real.pi := by intro j hj unfold arcSet at hj rw [mem_filter] at hj exact ⟨hj.2.1, hj.2.2.1⟩ have hmono : ∀ j ∈ arcSet d g c, ∀ j' ∈ arcSet d g c, j < j' → s j < s j' := by intro j hj j' hj' hjj obtain ⟨_, hsj, ej⟩ := hs_spec j hj obtain ⟨_, hsj', ej'⟩ := hs_spec j' hj' have ht : c + j * δ < c + j' * δ := by have : (j : ℝ) < j' := by exact_mod_cast hjj nlinarith have hcos := Real.cos_lt_cos_of_nonneg_of_le_pi (harc j hj).1.le (harc j' hj').2.le ht apply chord_index_lt hg hsj hsj' nlinarith have h4 : ∀ k, 1 ≤ k → ((arcSet d g c).filter (fun j => j + 1 ∈ arcSet d g c ∧ s (j + 1) = s j + k)).card ≤ 4 := by intro k _ set F := (arcSet d g c).filter (fun j => j + 1 ∈ arcSet d g c ∧ s (j + 1) = s j + k) with hF have hinj : Set.InjOn (fun j : ℕ => c + j * δ) (F : Set ℕ) := by intro a _ b _ h simp only at h have : (a : ℝ) = b := by have := mul_right_cancel₀ hδ0.ne' (show (a : ℝ) * δ = b * δ by linarith) exact this exact_mod_cast this rw [← card_image_of_injOn hinj] apply steps_le_four (κ := k * δ) hd hd1 hδ0 hδπ · intro t ht rw [mem_image] at ht obtain ⟨j, hj, rfl⟩ := ht rw [hF, mem_filter] at hj have := harc j hj.1 exact ⟨this.1.le, by linarith [Real.pi_pos]⟩ · intro t ht rw [mem_image] at ht obtain ⟨j, hj, rfl⟩ := ht rw [hF, mem_filter] at hj obtain ⟨_, _, ej⟩ := hs_spec j hj.1 obtain ⟨_, _, ej1⟩ := hs_spec (j + 1) hj.2.1 refine ⟨s j * δ, ej, ?_⟩ have e1 : c + j * δ + δ = c + ((j + 1 : ℕ) : ℝ) * δ := by push_cast; ring have e2 : (s j : ℝ) * δ + k * δ = (s (j + 1) : ℝ) * δ := by rw [hj.2.2] push_cast ring rw [e1, e2] exact ej1 have hsub : arcSet d g c ⊆ range (g / 2 + 1) := by unfold arcSet exact filter_subset _ _ have := arc_count (g / 2 + 1) (g / 2) K₀ (arcSet d g c) s hsub (fun j hj => (hs_spec j hj).1) (fun j hj => (hs_spec j hj).2.1) hmono h4 omega end Erdos94ThmA /-! ### (R5) Lemma C2, angle form: all vertices -/ namespace Erdos94ThmA open Finset theorem vertex_index_eq {g : ℕ} (hg : 0 < g) {i i' : ℕ} (hi : i < g) (hi' : i' < g) {D D' : ℤ} (h : (i : ℝ) * (2 * Real.pi / g) - D * (2 * Real.pi) = i' * (2 * Real.pi / g) - D' * (2 * Real.pi)) : i = i' := by have hgR : (g : ℝ) ≠ 0 := by exact_mod_cast hg.ne' have hπ : (2 * Real.pi) ≠ 0 := by positivity have h2 : ((i : ℤ) : ℝ) - ((i' : ℤ) : ℝ) = ((D - D') * g : ℤ) := by push_cast have := h field_simp at this linarith have h3 : (i : ℤ) - i' = (D - D') * g := by exact_mod_cast h2 have h4 : D - D' = 0 := by by_contra hne have : (g : ℤ) ≤ |(D - D') * g| := by rw [abs_mul] have : 1 ≤ |D - D'| := Int.one_le_abs hne have hg' : (0 : ℤ) ≤ g := by positivity rw [abs_of_nonneg hg'] nlinarith rw [← h3] at this have : |(i : ℤ) - i'| < g := by rw [abs_lt] constructor <;> omega omega rw [h4, zero_mul] at h3 omega /-- Reduction of a vertex angle onto an arc of offset `toIcoMod δ 0 φ₀`. -/ theorem arc_index {g : ℕ} (hg : 3 ≤ g) (φ₀ : ℝ) {t : ℝ} (i : ℕ) (D : ℤ) (ht : t = φ₀ + i * (2 * Real.pi / g) - D * (2 * Real.pi)) (hpos : 0 < t) (hlt : t < Real.pi) : ∃ j : ℕ, j < g / 2 + 1 ∧ toIcoMod (show (0 : ℝ) < 2 * Real.pi / g by positivity) 0 φ₀ + j * (2 * Real.pi / g) = t := by have hgR : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) set δ : ℝ := 2 * Real.pi / g with hδ have hδ0 : 0 < δ := by positivity set c := toIcoMod hδ0 0 φ₀ with hc have hcmem := toIcoMod_mem_Ico hδ0 0 φ₀ rw [zero_add] at hcmem have hcdiv := self_sub_toIcoMod_eq_mul hδ0 0 φ₀ set E := toIcoDiv hδ0 0 φ₀ with hE -- t − c = (i − D g + E) δ have h2π : 2 * Real.pi = g * δ := by rw [hδ]; field_simp set n : ℤ := (i : ℤ) - D * g + E with hn have htc : t - c = n * δ := by rw [hn] push_cast rw [ht, h2π] linarith have hn0 : 0 ≤ n := by by_contra hneg push_neg at hneg have : (n : ℝ) ≤ -1 := by exact_mod_cast (show n ≤ -1 by omega) have : (n : ℝ) * δ ≤ -δ := by nlinarith linarith [hcmem.2] have hnlt : (n : ℝ) * δ < Real.pi := by linarith [hcmem.1] refine ⟨n.toNat, ?_, ?_⟩ · have hnR : (n.toNat : ℝ) = n := by exact_mod_cast Int.toNat_of_nonneg hn0 have h0 : (n.toNat : ℝ) * δ < Real.pi := by rw [hnR]; exact hnlt have hδg : δ * g = 2 * Real.pi := by rw [hδ]; field_simp have h1 : (n.toNat : ℝ) * (δ * g) < Real.pi * g := by nlinarith rw [hδg] at h1 have h' : (n.toNat : ℝ) * 2 < g := by nlinarith [Real.pi_pos] have h'' : n.toNat * 2 < g := by exact_mod_cast h' omega · have hnR : (n.toNat : ℝ) = n := by exact_mod_cast Int.toNat_of_nonneg hn0 rw [hnR] linarith open Classical in /-- **Lemma C2, angle form.** For `g ≥ 3`, `d > 0`, `d ≠ 1`, any `φ₀` and `K₀`: `(K₀ + 1) · #{i < g : matched(φ₀ + iδ)} ≤ (K₀ + 1)(g/2 + 4 + 4K₀) + g/2`. -/ theorem C2_angle {d : ℝ} (hd : 0 < d) (hd1 : d ≠ 1) {g : ℕ} (hg : 3 ≤ g) (φ₀ : ℝ) (K₀ : ℕ) : (K₀ + 1) * ((range g).filter (fun i : ℕ => matchedAng d g (φ₀ + (i : ℝ) * (2 * Real.pi / g)))).card ≤ (K₀ + 1) * (g / 2 + 4 + 4 * K₀) + g / 2 := by classical have hgR : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) set δ : ℝ := 2 * Real.pi / g with hδ have hδ0 : 0 < δ := by positivity have h2π : (0 : ℝ) < 2 * Real.pi := by positivity set Mset := (range g).filter (fun i : ℕ => matchedAng d g (φ₀ + (i : ℝ) * δ)) with hMset -- reduced angle in [−π, π) let t : ℕ → ℝ := fun i => toIcoMod h2π (-Real.pi) (φ₀ + i * δ) have ht_mem : ∀ i : ℕ, -Real.pi ≤ t i ∧ t i < Real.pi := by intro i have := toIcoMod_mem_Ico h2π (-Real.pi) (φ₀ + i * δ) exact ⟨this.1, by linarith [this.2]⟩ have ht_eq : ∀ i : ℕ, t i = φ₀ + i * δ - (toIcoDiv h2π (-Real.pi) (φ₀ + i * δ) : ℝ) * (2 * Real.pi) := by intro i have := self_sub_toIcoMod_eq_mul h2π (-Real.pi) (φ₀ + i * δ) simp only [t] linarith have ht_cos : ∀ i : ℕ, Real.cos (t i) = Real.cos (φ₀ + i * δ) := by intro i rw [ht_eq i, Real.cos_sub_int_mul_two_pi] have ht_inj : Set.InjOn t (range g : Set ℕ) := by intro i hi i' hi' h rw [coe_range, Set.mem_Iio] at hi hi' have := (ht_eq i).symm.trans (h.trans (ht_eq i')) have key : (i : ℝ) * δ - (toIcoDiv h2π (-Real.pi) (φ₀ + i * δ) : ℝ) * (2 * Real.pi) = (i' : ℝ) * δ - (toIcoDiv h2π (-Real.pi) (φ₀ + i' * δ) : ℝ) * (2 * Real.pi) := by linarith exact vertex_index_eq (show 0 < g by omega) hi hi' key have hmatch_t : ∀ i : ℕ, matchedAng d g (φ₀ + i * δ) → matchedAng d g (t i) := by intro i hm obtain ⟨s, h1, h2, h3⟩ := hm exact ⟨s, h1, h2, by rw [ht_cos]; exact h3⟩ have hmatch_neg : ∀ i : ℕ, matchedAng d g (φ₀ + i * δ) → matchedAng d g (-t i) := by intro i hm obtain ⟨s, h1, h2, h3⟩ := hm exact ⟨s, h1, h2, by rw [Real.cos_neg, ht_cos]; exact h3⟩ -- the three parts obtain ⟨U, hU⟩ : ∃ U, U = Mset.filter (fun i => 0 < t i) := ⟨_, rfl⟩ obtain ⟨R, hR⟩ : ∃ R, R = Mset.filter (fun i => ¬ (0 < t i)) := ⟨_, rfl⟩ obtain ⟨Lw, hLw⟩ : ∃ L, L = R.filter (fun i => -Real.pi < t i ∧ t i ≠ 0) := ⟨_, rfl⟩ obtain ⟨Ax, hAx⟩ : ∃ A, A = R.filter (fun i => ¬ (-Real.pi < t i ∧ t i ≠ 0)) := ⟨_, rfl⟩ have hcover : Mset.card ≤ U.card + Lw.card + Ax.card := by have h1 := card_filter_add_card_filter_not (s := Mset) (fun i => 0 < t i) rw [← hU, ← hR] at h1 have h2 := card_filter_add_card_filter_not (s := R) (fun i => -Real.pi < t i ∧ t i ≠ 0) rw [← hLw, ← hAx] at h2 omega have memU : ∀ i ∈ U, (i ∈ range g ∧ matchedAng d g (φ₀ + i * δ)) ∧ 0 < t i := by intro i hi rw [hU, mem_filter, hMset, mem_filter] at hi exact hi have memL : ∀ i ∈ Lw, ((i ∈ range g ∧ matchedAng d g (φ₀ + i * δ)) ∧ ¬ (0 < t i)) ∧ (-Real.pi < t i ∧ t i ≠ 0) := by intro i hi rw [hLw, mem_filter, hR, mem_filter, hMset, mem_filter] at hi exact hi have memA : ∀ i ∈ Ax, ((i ∈ range g ∧ matchedAng d g (φ₀ + i * δ)) ∧ ¬ (0 < t i)) ∧ ¬ (-Real.pi < t i ∧ t i ≠ 0) := by intro i hi rw [hAx, mem_filter, hR, mem_filter, hMset, mem_filter] at hi exact hi -- upper arc have hU_le : U.card ≤ (arcSet d g (toIcoMod hδ0 0 φ₀)).card := by have key : ∀ i ∈ U, ∃ j ∈ arcSet d g (toIcoMod hδ0 0 φ₀), toIcoMod hδ0 0 φ₀ + j * δ = t i := by intro i hi have hi := memU i hi obtain ⟨j, hj, hjt⟩ := arc_index hg φ₀ i _ (ht_eq i) hi.2 (ht_mem i).2 refine ⟨j, ?_, hjt⟩ unfold arcSet rw [mem_filter] refine ⟨mem_range.mpr hj, by rw [hjt]; exact hi.2, by rw [hjt]; exact (ht_mem i).2, ?_⟩ rw [hjt] exact hmatch_t i hi.1.2 choose! f hf hft using key apply card_le_card_of_injOn f · intro i hi exact hf i hi · intro i hi i' hi' h have e1 := hft i hi have e2 := hft i' hi' rw [h] at e1 have hti : t i = t i' := e1.symm.trans e2 exact ht_inj (mem_coe.mpr (memU i hi).1.1) (mem_coe.mpr (memU i' hi').1.1) hti -- lower arc (negated angles) have hL_le : Lw.card ≤ (arcSet d g (toIcoMod hδ0 0 (-φ₀))).card := by have key : ∀ i ∈ Lw, ∃ j ∈ arcSet d g (toIcoMod hδ0 0 (-φ₀)), toIcoMod hδ0 0 (-φ₀) + j * δ = -t i := by intro i hi have hi := memL i hi have htneg : 0 < -t i := by have : t i < 0 := lt_of_le_of_ne (not_lt.mp hi.1.2) hi.2.2 linarith have htlt : -t i < Real.pi := by linarith [hi.2.1] have hrange := mem_range.mp hi.1.1.1 have hdiv : ∃ D : ℤ, -t i = -φ₀ + (g - i : ℕ) * δ - D * (2 * Real.pi) := by refine ⟨1 - toIcoDiv h2π (-Real.pi) (φ₀ + i * δ), ?_⟩ rw [ht_eq i] have h2πe : 2 * Real.pi = g * δ := by rw [hδ]; field_simp push_cast [Nat.cast_sub hrange.le] linear_combination h2πe obtain ⟨D, hD⟩ := hdiv obtain ⟨j, hj, hjt⟩ := arc_index hg (-φ₀) (g - i) D hD htneg htlt refine ⟨j, ?_, hjt⟩ unfold arcSet rw [mem_filter] refine ⟨mem_range.mpr hj, by rw [hjt]; exact htneg, by rw [hjt]; exact htlt, ?_⟩ rw [hjt] exact hmatch_neg i hi.1.1.2 choose! f hf hft using key apply card_le_card_of_injOn f · intro i hi exact hf i hi · intro i hi i' hi' h have e1 := hft i hi have e2 := hft i' hi' rw [h] at e1 have hti : t i = t i' := by linarith exact ht_inj (mem_coe.mpr (memL i hi).1.1.1) (mem_coe.mpr (memL i' hi').1.1.1) hti -- axis: at most two vertices have hAx_le : Ax.card ≤ 2 := by have hsub : Ax.image t ⊆ {0, -Real.pi} := by intro x hx rw [mem_image] at hx obtain ⟨i, hi, rfl⟩ := hx have hi := memA i hi have h1 := (ht_mem i).1 rw [mem_insert, mem_singleton] by_cases h0 : t i = 0 · exact Or.inl h0 · right have : ¬ (-Real.pi < t i) := fun h => hi.2 ⟨h, h0⟩ linarith [not_lt.mp this] have hinj : Set.InjOn t (Ax : Set ℕ) := fun i hi i' hi' h => ht_inj (mem_coe.mpr (memA i (mem_coe.mp hi)).1.1.1) (mem_coe.mpr (memA i' (mem_coe.mp hi')).1.1.1) h have := card_le_card hsub rw [card_image_of_injOn hinj] at this exact le_trans this (card_insert_le _ _) have hAU := arcSet_bound hd hd1 hg (c := toIcoMod hδ0 0 φ₀) K₀ have hAL := arcSet_bound hd hd1 hg (c := toIcoMod hδ0 0 (-φ₀)) K₀ nlinarith end Erdos94ThmA /-! ### Lemma C2, plane form (THEOREM_A §6) -/ namespace Erdos94ThmA open Finset /-- Squared distance from `d e^{iθ}` to `e^{iα}`. -/ theorem norm_sub_exp_sq (d θ α : ℝ) : ‖(d : ℂ) * Complex.exp (θ * Complex.I) - Complex.exp (α * Complex.I)‖ ^ 2 = d ^ 2 + 1 - 2 * d * Real.cos (α - θ) := by rw [Complex.sq_norm, Complex.normSq_apply] simp only [Complex.sub_re, Complex.sub_im, Complex.mul_re, Complex.mul_im, Complex.ofReal_re, Complex.ofReal_im, Complex.exp_ofReal_mul_I_re, Complex.exp_ofReal_mul_I_im] rw [Real.cos_sub] linear_combination d ^ 2 * Real.sin_sq_add_cos_sq θ + Real.sin_sq_add_cos_sq α /-- `(2 sin a)² = 2 − 2 cos 2a`. -/ theorem chord_sq (a : ℝ) : (2 * Real.sin a) ^ 2 = 2 - 2 * Real.cos (2 * a) := by rw [Real.cos_two_mul] linear_combination 4 * Real.sin_sq_add_cos_sq a /-- Squared distance from `x` to the point `O + ρ w e^{iα}` of the circle `C(O, ρ)`, `|w| = 1`. -/ theorem dist_vertex_sq {O w x : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = 1) (α : ℝ) : dist x (O + ρ * (w * Complex.exp (α * Complex.I))) ^ 2 = ρ ^ 2 * ((‖x - O‖ / ρ) ^ 2 + 1 - 2 * (‖x - O‖ / ρ) * Real.cos (Complex.arg w + α - Complex.arg (x - O))) := by have hw' : w = Complex.exp (Complex.arg w * Complex.I) := by have := Complex.norm_mul_exp_arg_mul_I w rw [hw, Complex.ofReal_one, one_mul] at this exact this.symm have e2 : (ρ : ℂ) * (((‖x - O‖ / ρ : ℝ) : ℂ) * Complex.exp (Complex.arg (x - O) * Complex.I)) = x - O := by rw [← mul_assoc, ← Complex.ofReal_mul, show ρ * (‖x - O‖ / ρ) = ‖x - O‖ by field_simp] exact Complex.norm_mul_exp_arg_mul_I _ have e3 : w * Complex.exp (α * Complex.I) = Complex.exp ((Complex.arg w + α : ℝ) * Complex.I) := by rw [Complex.ofReal_add, add_mul, Complex.exp_add, ← hw'] have key : x - (O + ρ * (w * Complex.exp (α * Complex.I))) = (ρ : ℂ) * (((‖x - O‖ / ρ : ℝ) : ℂ) * Complex.exp (Complex.arg (x - O) * Complex.I) - Complex.exp ((Complex.arg w + α : ℝ) * Complex.I)) := by rw [mul_sub, e2, ← e3] ring rw [dist_eq_norm, key, norm_mul, mul_pow, norm_sub_exp_sq, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hρ] /-- The vertex set of the regular `N`-gon `O + ρ w e^{2πij/N}` (`|w| = 1`) inscribed in `C(O, ρ)`. -/ noncomputable def regPoly (O w : ℂ) (ρ : ℝ) (N : ℕ) : Finset ℂ := (range N).image (fun j : ℕ => O + ρ * (w * Complex.exp (2 * Real.pi * Complex.I * (j / N)))) /-- Its chord lengths `CL = {2ρ sin(πs/N) : 1 ≤ s ≤ ⌊N/2⌋}`. -/ def chordLen (ρ : ℝ) (N : ℕ) : Set ℝ := {u | ∃ s : ℕ, 1 ≤ s ∧ s ≤ N / 2 ∧ u = 2 * ρ * Real.sin (Real.pi * s / N)} /-- A vertex at a chord length from `x` gives a matched angle. -/ theorem vertex_matched {O w x : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = 1) {N : ℕ} (j : ℕ) (h : dist x (O + ρ * (w * Complex.exp (2 * Real.pi * Complex.I * (j / N)))) ∈ chordLen ρ N) : matchedAng (‖x - O‖ / ρ) N (Complex.arg w - Complex.arg (x - O) + (j : ℝ) * (2 * Real.pi / N)) := by obtain ⟨s, hs1, hs2, hu⟩ := h refine ⟨s, hs1, hs2, ?_⟩ have hexp : (2 * Real.pi * Complex.I * (j / N) : ℂ) = (((j : ℝ) * (2 * Real.pi / N) : ℝ) : ℂ) * Complex.I := by push_cast ring rw [hexp] at hu have h2 := dist_vertex_sq (x := x) (O := O) hρ hw ((j : ℝ) * (2 * Real.pi / N)) rw [hu, show Complex.arg w + (j : ℝ) * (2 * Real.pi / N) - Complex.arg (x - O) = Complex.arg w - Complex.arg (x - O) + (j : ℝ) * (2 * Real.pi / N) by ring] at h2 have hc := chord_sq (Real.pi * s / N) rw [show 2 * (Real.pi * s / N) = (s : ℝ) * (2 * Real.pi / N) by ring] at hc have hρ2 : ρ ^ 2 ≠ 0 := pow_ne_zero 2 hρ.ne' apply mul_left_cancel₀ hρ2 rw [← h2, ← hc] ring open Classical in /-- **Lemma C2**, counting form: for every `K₀`, `(K₀+1)·M(x) ≤ (K₀+1)(⌊N/2⌋ + 4 + 4K₀) + ⌊N/2⌋`. -/ theorem lemmaC2_nat {O w x : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = 1) {N : ℕ} (hN : 3 ≤ N) (hxC : ‖x - O‖ ≠ ρ) (hxO : x ≠ O) (K₀ : ℕ) : (K₀ + 1) * ((regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N)).card ≤ (K₀ + 1) * (N / 2 + 4 + 4 * K₀) + N / 2 := by have hd : 0 < ‖x - O‖ / ρ := div_pos (norm_pos_iff.mpr (sub_ne_zero.mpr hxO)) hρ have hd1 : ‖x - O‖ / ρ ≠ 1 := by intro h apply hxC rw [div_eq_one_iff_eq hρ.ne'] at h exact h have hle : ((regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N)).card ≤ ((range N).filter (fun i : ℕ => matchedAng (‖x - O‖ / ρ) N (Complex.arg w - Complex.arg (x - O) + (i : ℝ) * (2 * Real.pi / N)))).card := by have hsub : (regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N) ⊆ ((range N).filter (fun i : ℕ => matchedAng (‖x - O‖ / ρ) N (Complex.arg w - Complex.arg (x - O) + (i : ℝ) * (2 * Real.pi / N)))).image (fun j : ℕ => O + ρ * (w * Complex.exp (2 * Real.pi * Complex.I * (j / N)))) := by intro q hq rw [mem_filter] at hq obtain ⟨hq1, hq2⟩ := hq unfold regPoly at hq1 rw [mem_image] at hq1 obtain ⟨j, hj, rfl⟩ := hq1 rw [mem_image] exact ⟨j, mem_filter.mpr ⟨hj, vertex_matched hρ hw j hq2⟩, rfl⟩ exact le_trans (card_le_card hsub) card_image_le exact le_trans (Nat.mul_le_mul le_rfl hle) (C2_angle hd hd1 hN (Complex.arg w - Complex.arg (x - O)) K₀) open Classical in /-- **Lemma C2** (THEOREM_A §6). Let `N ≥ 3`, `R_N` a regular `N`-gon inscribed in `C(O, ρ)`, `CL` its set of chord lengths, and `x ∉ C ∪ {O}`. Then `M(x) := #{q ∈ R_N : |xq| ∈ CL} ≤ N/2 + 4.5√N + 7`. -/ theorem lemmaC2 {O w x : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = 1) {N : ℕ} (hN : 3 ≤ N) (hxC : ‖x - O‖ ≠ ρ) (hxO : x ≠ O) : (((regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N)).card : ℝ) ≤ N / 2 + 4.5 * Real.sqrt N + 7 := by obtain ⟨M, hM⟩ : ∃ M, M = ((regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N)).card := ⟨_, rfl⟩ rw [← hM] obtain ⟨r, hr⟩ : ∃ r, r = Nat.sqrt N := ⟨_, rfl⟩ have h := lemmaC2_nat hρ hw hN hxC hxO r rw [← hM] at h have hr1 : r * r ≤ N := by rw [hr]; exact Nat.sqrt_le N have hr2 : N < (r + 1) * (r + 1) := by rw [hr]; exact Nat.lt_succ_sqrt N have hsq : (r : ℝ) ≤ Real.sqrt N := by apply Real.le_sqrt_of_sq_le rw [sq] exact_mod_cast hr1 have hN2 : ((N / 2 : ℕ) : ℝ) ≤ (N : ℝ) / 2 := Nat.cast_div_le have hR : ((r : ℝ) + 1) * (M : ℝ) ≤ ((r : ℝ) + 1) * (((N / 2 : ℕ) : ℝ) + 4 + 4 * r) + ((N / 2 : ℕ) : ℝ) := by exact_mod_cast h have hr2' : (N : ℝ) < ((r : ℝ) + 1) * ((r : ℝ) + 1) := by exact_mod_cast hr2 have hpos : (0 : ℝ) < (r : ℝ) + 1 := by positivity have key : ((r : ℝ) + 1) * (M : ℝ) ≤ ((r : ℝ) + 1) * ((N : ℝ) / 2 + 4.5 * r + 4.5) := by nlinarith [mul_le_mul_of_nonneg_left hN2 hpos.le] have hM' : (M : ℝ) ≤ (N : ℝ) / 2 + 4.5 * r + 4.5 := le_of_mul_le_mul_left key hpos linarith end Erdos94ThmA /-! ### (R6) Prop. C bookkeeping, part 1: energies of families of ordered pairs; (G1), (G2) in `ℂ`; `pairEnergy(E) ≤ 3k²(k−1)` (THEOREM_A §7.1 (iii)) -/ namespace Erdos94ThmA open Finset /-- `pe S T = #{(x, y) ∈ S × T : |x₁x₂| = |y₁y₂|}` for finite sets `S`, `T` of ordered pairs. -/ noncomputable def pe (S T : Finset (ℂ × ℂ)) : ℕ := ∑ x ∈ S, ∑ y ∈ T, if dist x.1 x.2 = dist y.1 y.2 then 1 else 0 /-- `cnt T u = #{y ∈ T : |y₁y₂| = u}`. -/ noncomputable def cnt (T : Finset (ℂ × ℂ)) (u : ℝ) : ℕ := (T.filter (fun y => dist y.1 y.2 = u)).card theorem pe_eq_sum_cnt (S T : Finset (ℂ × ℂ)) : pe S T = ∑ x ∈ S, cnt T (dist x.1 x.2) := by unfold pe cnt refine sum_congr rfl (fun x _ => ?_) rw [card_filter] refine sum_congr rfl (fun y _ => ?_) by_cases h : dist x.1 x.2 = dist y.1 y.2 · rw [if_pos h, if_pos h.symm] · rw [if_neg h, if_neg (Ne.symm h)] theorem pe_comm (S T : Finset (ℂ × ℂ)) : pe S T = pe T S := by unfold pe rw [sum_comm] refine sum_congr rfl (fun y _ => sum_congr rfl (fun x _ => ?_)) by_cases h : dist x.1 x.2 = dist y.1 y.2 · rw [if_pos h, if_pos h.symm] · rw [if_neg h, if_neg (Ne.symm h)] theorem pe_mono_left {S S' : Finset (ℂ × ℂ)} (h : S ⊆ S') (T : Finset (ℂ × ℂ)) : pe S T ≤ pe S' T := by unfold pe exact sum_le_sum_of_subset h theorem pe_mono_right (S : Finset (ℂ × ℂ)) {T T' : Finset (ℂ × ℂ)} (h : T ⊆ T') : pe S T ≤ pe S T' := by rw [pe_comm S T, pe_comm S T'] exact pe_mono_left h S theorem pe_union_left_le (S₁ S₂ T : Finset (ℂ × ℂ)) : pe (S₁ ∪ S₂) T ≤ pe S₁ T + pe S₂ T := by unfold pe rw [← sum_union_inter] exact Nat.le_add_right _ _ theorem pe_union_right_le (S T₁ T₂ : Finset (ℂ × ℂ)) : pe S (T₁ ∪ T₂) ≤ pe S T₁ + pe S T₂ := by rw [pe_comm S (T₁ ∪ T₂), pe_comm S T₁, pe_comm S T₂] exact pe_union_left_le T₁ T₂ S theorem pe_le_of_cnt_le (S T : Finset (ℂ × ℂ)) (c : ℕ) (h : ∀ x ∈ S, cnt T (dist x.1 x.2) ≤ c) : pe S T ≤ S.card * c := by rw [pe_eq_sum_cnt] calc ∑ x ∈ S, cnt T (dist x.1 x.2) ≤ ∑ _x ∈ S, c := sum_le_sum h _ = S.card * c := by rw [sum_const, smul_eq_mul] theorem pe_le_card_mul (S T : Finset (ℂ × ℂ)) : pe S T ≤ S.card * T.card := pe_le_of_cnt_le S T T.card (fun _ _ => card_filter_le _ _) theorem pe_eq_sum_fiber (S T : Finset (ℂ × ℂ)) (U : Finset ℝ) (hU : ∀ x ∈ S, dist x.1 x.2 ∈ U) : pe S T = ∑ u ∈ U, cnt S u * cnt T u := by rw [pe_eq_sum_cnt, ← sum_fiberwise_of_maps_to hU] refine sum_congr rfl (fun u _ => ?_) have h : ∀ x ∈ S.filter (fun x => dist x.1 x.2 = u), cnt T (dist x.1 x.2) = cnt T u := fun x hx => by rw [(mem_filter.mp hx).2] rw [sum_congr rfl h, sum_const, smul_eq_mul] rfl /-- Cauchy–Schwarz for distance counts: `2 pe(S, T) ≤ pe(S, S) + pe(T, T)`. -/ theorem two_pe_le (S T : Finset (ℂ × ℂ)) : 2 * pe S T ≤ pe S S + pe T T := by classical obtain ⟨U, hU⟩ : ∃ U : Finset ℝ, U = (S ∪ T).image (fun x => dist x.1 x.2) := ⟨_, rfl⟩ have hS : ∀ x ∈ S, dist x.1 x.2 ∈ U := fun x hx => by rw [hU] exact mem_image_of_mem _ (mem_union_left _ hx) have hT : ∀ x ∈ T, dist x.1 x.2 ∈ U := fun x hx => by rw [hU] exact mem_image_of_mem _ (mem_union_right _ hx) rw [pe_eq_sum_fiber S T U hS, pe_eq_sum_fiber S S U hS, pe_eq_sum_fiber T T U hT, mul_sum, ← sum_add_distrib] apply sum_le_sum intro u _ have h := two_mul_le_add_sq (cnt S u) (cnt T u) nlinarith [h] theorem pe_union_self_le (X Y : Finset (ℂ × ℂ)) : pe (X ∪ Y) (X ∪ Y) ≤ 2 * pe X X + 2 * pe Y Y := by have h1 := pe_union_left_le X Y (X ∪ Y) have h2 := pe_union_right_le X X Y have h3 := pe_union_right_le Y X Y have h4 := two_pe_le X Y have h5 := pe_comm Y X omega theorem pe_swap_left (S T : Finset (ℂ × ℂ)) : pe (S.image Prod.swap) T = pe S T := by unfold pe rw [sum_image (fun x _ y _ h => Prod.swap_injective h)] refine sum_congr rfl (fun x _ => sum_congr rfl (fun y _ => ?_)) rw [Prod.fst_swap, Prod.snd_swap, dist_comm x.2 x.1] theorem pe_swap_right (S T : Finset (ℂ × ℂ)) : pe S (T.image Prod.swap) = pe S T := by rw [pe_comm, pe_swap_left, pe_comm] theorem cnt_product_le (E Q : Finset ℂ) (c : ℕ) (h : ∀ e ∈ E, ∀ u : ℝ, (Q.filter (fun q => dist e q = u)).card ≤ c) (u : ℝ) : cnt (E ×ˢ Q) u ≤ E.card * c := by unfold cnt rw [card_filter, sum_product] calc ∑ e ∈ E, ∑ q ∈ Q, (if dist (e, q).1 (e, q).2 = u then 1 else 0) ≤ ∑ _e ∈ E, c := by apply sum_le_sum intro e he have := h e he u rw [card_filter] at this exact this _ = E.card * c := by rw [sum_const, smul_eq_mul] /-- (G2) in `ℂ`: a point `x ≠ O` sees each distance at most twice on a circle centred at `O`. -/ theorem card_circle_dist_le_two {Q : Finset ℂ} {O x : ℂ} {ρ : ℝ} (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hx : x ≠ O) (u : ℝ) : (Q.filter (fun q => dist x q = u)).card ≤ 2 := by by_contra hcon obtain ⟨a, b, c, ha, hb, hc, hab, hac, hbc⟩ := Finset.two_lt_card_iff.mp (not_le.mp hcon) rw [Finset.mem_filter] at ha hb hc have ha' : dist a x = u := by rw [dist_comm]; exact ha.2 have hb' : dist b x = u := by rw [dist_comm]; exact hb.2 have hc' : dist c x = u := by rw [dist_comm]; exact hc.2 have hQ' : ∀ q ∈ Q, dist q O = ρ := fun q hq => by rw [dist_eq_norm]; exact hQ q hq have key := EuclideanGeometry.eq_of_dist_eq_of_dist_eq_of_finrank_eq_two Complex.finrank_real_complex hx hab ha' hb' hc' (hQ' a ha.1) (hQ' b hb.1) (hQ' c hc.1) rcases key with h | h · exact hac h.symm · exact hbc h.symm /-- (G1) in `ℂ`: three distinct points of a convex-independent set are never collinear. -/ theorem convexIndepC_not_collinear {S : Set ℂ} (hS : ∀ a ∈ S, a ∉ convexHull ℝ (S \ {a})) {a b c : ℂ} (ha : a ∈ S) (hb : b ∈ S) (hc : c ∈ S) (hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (hcol : Collinear ℝ ({a, b, c} : Set ℂ)) : False := by have m : ∀ {x y : ℂ}, x ∈ S → x ≠ y → x ∈ S \ {y} := fun hx hxy => ⟨hx, fun h => hxy (Set.mem_singleton_iff.mp h)⟩ rcases hcol.wbtw_or_wbtw_or_wbtw with h | h | h · exact hS b hb (segment_subset_convexHull (m ha hab) (m hc hbc.symm) (mem_segment_iff_wbtw.mpr h)) · exact hS c hc (segment_subset_convexHull (m hb hbc) (m ha hac) (mem_segment_iff_wbtw.mpr h)) · exact hS a ha (segment_subset_convexHull (m hc hac.symm) (m hb hab.symm) (mem_segment_iff_wbtw.mpr h)) /-- Points equidistant from `y ≠ y'` are collinear (they lie on the perpendicular bisector). -/ theorem collinear_of_equidist {y y' : ℂ} (hyy : y ≠ y') {s : Set ℂ} (hs : ∀ p ∈ s, dist p y = dist p y') : Collinear ℝ s := by have hsub : s ⊆ (AffineSubspace.perpBisector y y' : Set ℂ) := fun p hp => AffineSubspace.mem_perpBisector_iff_dist_eq.mpr (hs p hp) apply Collinear.subset hsub rw [collinear_iff_finrank_le_one] have hdir : vectorSpan ℝ (AffineSubspace.perpBisector y y' : Set ℂ) = (ℝ ∙ (y' -ᵥ y))ᗮ := by rw [← AffineSubspace.direction_perpBisector] rfl rw [hdir] have : Fact (Module.finrank ℝ ℂ = 1 + 1) := ⟨Complex.finrank_real_complex⟩ have hv : y' -ᵥ y ≠ 0 := by rw [vsub_eq_sub] exact sub_ne_zero.mpr hyy.symm rw [Submodule.finrank_orthogonal_span_singleton (𝕜 := ℝ) (E := ℂ) (n := 1) hv] /-- A perpendicular bisector contains at most two points of a convex-independent set. -/ theorem bisector_card_le_two {E : Finset ℂ} (hE : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a})) {y y' : ℂ} (hyy : y ≠ y') : (E.filter (fun x => dist x y = dist x y')).card ≤ 2 := by by_contra hcon obtain ⟨a, b, c, ha, hb, hc, hab, hac, hbc⟩ := Finset.two_lt_card_iff.mp (not_le.mp hcon) rw [Finset.mem_filter] at ha hb hc apply convexIndepC_not_collinear hE (mem_coe.mpr ha.1) (mem_coe.mpr hb.1) (mem_coe.mpr hc.1) hab hac hbc apply collinear_of_equidist hyy intro p hp simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hp rcases hp with rfl | rfl | rfl · exact ha.2 · exact hb.2 · exact hc.2 /-- Row `a` of `E.offDiag`. -/ noncomputable def row (E : Finset ℂ) (a : ℂ) : Finset (ℂ × ℂ) := (E.erase a).image (fun b => (a, b)) theorem offDiag_eq_biUnion_row (E : Finset ℂ) : E.offDiag = E.biUnion (row E) := by ext ⟨a, b⟩ rw [mem_offDiag, mem_biUnion] constructor · rintro ⟨ha, hb, hab⟩ refine ⟨a, ha, ?_⟩ unfold row rw [mem_image] exact ⟨b, mem_erase.mpr ⟨fun h => hab h.symm, hb⟩, rfl⟩ · rintro ⟨a', ha', hp⟩ unfold row at hp rw [mem_image] at hp obtain ⟨b', hb', h⟩ := hp rw [mem_erase] at hb' have h1 : a' = a := congrArg Prod.fst h have h2 : b' = b := congrArg Prod.snd h subst h1 h2 exact ⟨ha', hb'.2, fun h => hb'.1 h.symm⟩ theorem row_disjoint (E : Finset ℂ) : (E : Set ℂ).PairwiseDisjoint (row E) := by intro a _ a' _ haa rw [Function.onFun, disjoint_left] intro p hp hp' unfold row at hp hp' rw [mem_image] at hp hp' obtain ⟨b, _, rfl⟩ := hp obtain ⟨b', _, h⟩ := hp' exact haa (congrArg Prod.fst h).symm theorem pe_offDiag_left (E : Finset ℂ) (T : Finset (ℂ × ℂ)) : pe E.offDiag T = ∑ a ∈ E, pe (row E a) T := by unfold pe rw [offDiag_eq_biUnion_row, sum_biUnion (row_disjoint E)] theorem pe_row_row (E : Finset ℂ) (a a' : ℂ) : pe (row E a) (row E a') = ∑ b ∈ E.erase a, ∑ b' ∈ E.erase a', if dist a b = dist a' b' then 1 else 0 := by unfold pe row rw [sum_image (fun x _ y _ h => congrArg Prod.snd h)] refine sum_congr rfl (fun b _ => ?_) rw [sum_image (fun x _ y _ h => congrArg Prod.snd h)] theorem sum_sum_add_eq (E : Finset ℂ) (f : ℂ → ℕ) : ∑ a ∈ E, ∑ a' ∈ E, (f a + f a') = 2 * E.card * ∑ a ∈ E, f a := by have h : ∀ a ∈ E, ∑ a' ∈ E, (f a + f a') = E.card * f a + ∑ a' ∈ E, f a' := by intro a _ rw [sum_add_distrib, sum_const, smul_eq_mul] rw [sum_congr rfl h, sum_add_distrib, sum_const, smul_eq_mul, ← mul_sum] ring /-- Cauchy–Schwarz over rows: `pe(E°, E°) ≤ |E| Σ_a pe(row a, row a)`. -/ theorem pe_offDiag_le_rows (E : Finset ℂ) : pe E.offDiag E.offDiag ≤ E.card * ∑ a ∈ E, pe (row E a) (row E a) := by have h1 : ∀ a ∈ E, pe (row E a) E.offDiag = ∑ a' ∈ E, pe (row E a) (row E a') := by intro a _ rw [pe_comm, pe_offDiag_left] exact sum_congr rfl (fun a' _ => pe_comm _ _) have h2 : 2 * pe E.offDiag E.offDiag ≤ 2 * E.card * ∑ a ∈ E, pe (row E a) (row E a) := by rw [pe_offDiag_left, sum_congr rfl h1, mul_sum] calc ∑ a ∈ E, 2 * ∑ a' ∈ E, pe (row E a) (row E a') = ∑ a ∈ E, ∑ a' ∈ E, 2 * pe (row E a) (row E a') := by refine sum_congr rfl (fun a _ => ?_) rw [mul_sum] _ ≤ ∑ a ∈ E, ∑ a' ∈ E, (pe (row E a) (row E a) + pe (row E a') (row E a')) := sum_le_sum (fun a _ => sum_le_sum (fun a' _ => two_pe_le _ _)) _ = 2 * E.card * ∑ a ∈ E, pe (row E a) (row E a) := sum_sum_add_eq E (fun a => pe (row E a) (row E a)) have h3 : 2 * pe E.offDiag E.offDiag ≤ 2 * (E.card * ∑ a ∈ E, pe (row E a) (row E a)) := by rw [← mul_assoc] exact h2 omega end Erdos94ThmA /-! ### (R6) Prop. C bookkeeping, part 2: `4S(E) ≤ 3k²(k−1)` and the decomposition (7.1) -/ namespace Erdos94ThmA open Finset theorem pe_row_self_le (E : Finset ℂ) (a : ℂ) (ha : a ∈ E) : pe (row E a) (row E a) ≤ (E.card - 1) + (E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card := by rw [pe_row_row] have h1 : (∑ b ∈ E.erase a, ∑ b' ∈ E.erase a, if dist a b = dist a b' then 1 else 0) = (((E.erase a) ×ˢ (E.erase a)).filter (fun p => dist a p.1 = dist a p.2)).card := by rw [card_filter, sum_product] rw [h1] have hsub : ((E.erase a) ×ˢ (E.erase a)).filter (fun p => dist a p.1 = dist a p.2) ⊆ (E.erase a).diag ∪ E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2) := by intro p hp rw [mem_filter, mem_product, mem_erase, mem_erase] at hp obtain ⟨⟨⟨h1a, h1E⟩, ⟨h2a, h2E⟩⟩, hd⟩ := hp rw [mem_union] by_cases hpp : p.1 = p.2 · left rw [mem_diag] exact ⟨mem_erase.mpr ⟨h1a, h1E⟩, hpp⟩ · right rw [mem_filter, mem_offDiag] exact ⟨⟨h1E, h2E, hpp⟩, fun h => h1a h.symm, fun h => h2a h.symm, hd⟩ calc _ ≤ ((E.erase a).diag ∪ E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card := card_le_card hsub _ ≤ (E.erase a).diag.card + (E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card := card_union_le _ _ _ = (E.card - 1) + (E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card := by rw [diag_card, card_erase_of_mem ha] theorem sum_T_le {E : Finset ℂ} (hE : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a})) : ∑ a ∈ E, (E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card ≤ 2 * (E.card * E.card - E.card) := by have h : ∀ a ∈ E, (E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card = ∑ p ∈ E.offDiag, if (a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2) then 1 else 0 := fun a _ => card_filter _ _ rw [sum_congr rfl h, sum_comm] calc ∑ p ∈ E.offDiag, ∑ a ∈ E, (if (a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2) then 1 else 0) ≤ ∑ _p ∈ E.offDiag, 2 := by apply sum_le_sum intro p hp rw [← card_filter] have hp' := mem_offDiag.mp hp calc (E.filter (fun a => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card ≤ (E.filter (fun x => dist x p.1 = dist x p.2)).card := card_le_card (fun x hx => by rw [mem_filter] at hx ⊢ exact ⟨hx.1, hx.2.2.2⟩) _ ≤ 2 := bisector_card_le_two hE hp'.2.2 _ = 2 * (E.card * E.card - E.card) := by rw [sum_const, smul_eq_mul, offDiag_card, mul_comm] /-- **(iii)** `4 S(E) = pe(E°, E°) ≤ 3 k (k² − k)` for convex-independent `E` (THEOREM_A §7.1 (iii)). -/ theorem pe_offDiag_le {E : Finset ℂ} (hE : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a})) : pe E.offDiag E.offDiag ≤ 3 * E.card * (E.card * E.card - E.card) := by have h1 := pe_offDiag_le_rows E have h2 : ∑ a ∈ E, pe (row E a) (row E a) ≤ ∑ a ∈ E, ((E.card - 1) + (E.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card) := sum_le_sum (fun a ha => pe_row_self_le E a ha) rw [sum_add_distrib, sum_const, smul_eq_mul] at h2 have h3 := sum_T_le hE have h4 : E.card * (E.card - 1) = E.card * E.card - E.card := by rw [Nat.mul_sub_one] rw [h4] at h2 calc pe E.offDiag E.offDiag ≤ E.card * ∑ a ∈ E, pe (row E a) (row E a) := h1 _ ≤ E.card * ((E.card * E.card - E.card) + 2 * (E.card * E.card - E.card)) := Nat.mul_le_mul le_rfl (by linarith) _ = 3 * E.card * (E.card * E.card - E.card) := by ring theorem cnt_mono {T T' : Finset (ℂ × ℂ)} (h : T ⊆ T') (u : ℝ) : cnt T u ≤ cnt T' u := card_le_card (filter_subset_filter _ h) theorem cnt_product_le' (Q E : Finset ℂ) (c : ℕ) (h : ∀ e ∈ E, ∀ u : ℝ, (Q.filter (fun q => dist e q = u)).card ≤ c) (u : ℝ) : cnt (Q ×ˢ E) u ≤ E.card * c := by unfold cnt rw [card_filter, sum_product_right] calc ∑ e ∈ E, ∑ q ∈ Q, (if dist (q, e).1 (q, e).2 = u then 1 else 0) ≤ ∑ _e ∈ E, c := by apply sum_le_sum intro e he have := h e he u rw [card_filter] at this calc ∑ q ∈ Q, (if dist (q, e).1 (q, e).2 = u then 1 else 0) = ∑ q ∈ Q, (if dist e q = u then 1 else 0) := by refine sum_congr rfl (fun q _ => ?_) rw [dist_comm] _ ≤ c := this _ = E.card * c := by rw [sum_const, smul_eq_mul] theorem circle_ne_center {O z : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hz : ‖z - O‖ = ρ) : z ≠ O := by intro h rw [h, sub_self, norm_zero] at hz linarith theorem cnt_offDiag_circle_le {Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (u : ℝ) : cnt Q.offDiag u ≤ Q.card * 2 := calc cnt Q.offDiag u ≤ cnt (Q ×ˢ Q) u := cnt_mono (fun p hp => by rw [mem_offDiag] at hp exact mem_product.mpr ⟨hp.1, hp.2.1⟩) u _ ≤ Q.card * 2 := cnt_product_le Q Q 2 (fun e he u => card_circle_dist_le_two hQ (circle_ne_center hρ (hQ e he)) u) u /-- **(7.1)** in ordered-pair form: with `B = E×Q ∪ Q×E ∪ E°`, `pairEnergy(Q ∪ E) ≤ pe(Q°,Q°) + 4 pe(E×Q, Q°) + 2 pe(E°, Q°) + 8 pe(E×Q, E×Q) + 2 pe(E°, E°)`. -/ theorem pe_decomp (Q E : Finset ℂ) (hQE : Disjoint Q E) : pe (Q ∪ E).offDiag (Q ∪ E).offDiag ≤ pe Q.offDiag Q.offDiag + 4 * pe (E ×ˢ Q) Q.offDiag + 2 * pe E.offDiag Q.offDiag + 8 * pe (E ×ˢ Q) (E ×ˢ Q) + 2 * pe E.offDiag E.offDiag := by have hsw : Q ×ˢ E = (E ×ˢ Q).image Prod.swap := (image_swap_product Q E).symm have hsub : (Q ∪ E).offDiag ⊆ Q.offDiag ∪ (((E ×ˢ Q) ∪ (Q ×ˢ E)) ∪ E.offDiag) := by rw [offDiag_union hQE] intro p hp simp only [mem_union] at hp ⊢ tauto have h0 := le_trans (pe_mono_left hsub _) (pe_mono_right _ hsub) have h1 := pe_union_left_le Q.offDiag (((E ×ˢ Q) ∪ (Q ×ˢ E)) ∪ E.offDiag) (Q.offDiag ∪ (((E ×ˢ Q) ∪ (Q ×ˢ E)) ∪ E.offDiag)) have h2 := pe_union_right_le Q.offDiag Q.offDiag (((E ×ˢ Q) ∪ (Q ×ˢ E)) ∪ E.offDiag) have h3 := pe_union_right_le (((E ×ˢ Q) ∪ (Q ×ˢ E)) ∪ E.offDiag) Q.offDiag (((E ×ˢ Q) ∪ (Q ×ˢ E)) ∪ E.offDiag) have h4 := pe_comm Q.offDiag (((E ×ˢ Q) ∪ (Q ×ˢ E)) ∪ E.offDiag) have h5 := pe_union_left_le ((E ×ˢ Q) ∪ (Q ×ˢ E)) E.offDiag Q.offDiag have h6 := pe_union_left_le (E ×ˢ Q) (Q ×ˢ E) Q.offDiag have h7 : pe (Q ×ˢ E) Q.offDiag = pe (E ×ˢ Q) Q.offDiag := by rw [hsw, pe_swap_left] have h8 := pe_union_self_le ((E ×ˢ Q) ∪ (Q ×ˢ E)) E.offDiag have h9 := pe_union_self_le (E ×ˢ Q) (Q ×ˢ E) have h10 : pe (Q ×ˢ E) (Q ×ˢ E) = pe (E ×ˢ Q) (E ×ˢ Q) := by rw [hsw, pe_swap_left, pe_swap_right] omega theorem pe_EQ_Qo_eq (E Q : Finset ℂ) : pe (E ×ˢ Q) Q.offDiag = ∑ e ∈ E, ∑ q ∈ Q, cnt Q.offDiag (dist e q) := by rw [pe_eq_sum_cnt, sum_product] theorem pe_Eo_Qo_le {Q E : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) : pe E.offDiag Q.offDiag ≤ (E.card * E.card - E.card) * (Q.card * 2) := by rw [← offDiag_card] exact pe_le_of_cnt_le _ _ _ (fun x _ => cnt_offDiag_circle_le hρ hQ _) /-- Near case (`O ∉ E`): `pe(E×Q, E×Q) = Σ_u (b^{EQ}_u)² ≤ 2k·kK`. -/ theorem pe_EQ_EQ_le_near {Q E : Finset ℂ} {O : ℂ} {ρ : ℝ} (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hE : ∀ e ∈ E, e ≠ O) : pe (E ×ˢ Q) (E ×ˢ Q) ≤ (E.card * Q.card) * (E.card * 2) := by rw [← card_product] exact pe_le_of_cnt_le _ _ _ (fun x _ => cnt_product_le E Q 2 (fun e he u => card_circle_dist_le_two hQ (hE e he) u) _) /-- Far case: `pe(E×Q, E×Q) ≤ 2K² + 4k²K` (the centre may lie in `E`). -/ theorem pe_EQ_EQ_le_far {Q E : Finset ℂ} {O : ℂ} {ρ : ℝ} (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) : pe (E ×ˢ Q) (E ×ˢ Q) ≤ 2 * (Q.card * Q.card) + 2 * ((E.card * Q.card) * (E.card * 2)) := by classical have hsplit : E ×ˢ Q = ((E.filter (fun e => e = O)) ×ˢ Q) ∪ ((E.filter (fun e => e ≠ O)) ×ˢ Q) := by rw [← union_product, filter_union_filter_not_eq] have hO : (E.filter (fun e => e = O)).card ≤ 1 := card_le_one.mpr (fun a ha b hb => (mem_filter.mp ha).2.trans (mem_filter.mp hb).2.symm) have h1 := pe_union_self_le ((E.filter (fun e => e = O)) ×ˢ Q) ((E.filter (fun e => e ≠ O)) ×ˢ Q) rw [← hsplit] at h1 have h2 := pe_le_card_mul ((E.filter (fun e => e = O)) ×ˢ Q) ((E.filter (fun e => e = O)) ×ˢ Q) rw [card_product] at h2 have h3 : pe ((E.filter (fun e => e ≠ O)) ×ˢ Q) ((E.filter (fun e => e ≠ O)) ×ˢ Q) ≤ ((E.filter (fun e => e ≠ O)).card * Q.card) * ((E.filter (fun e => e ≠ O)).card * 2) := pe_EQ_EQ_le_near hQ (fun e he => (mem_filter.mp he).2) have h4 : (E.filter (fun e => e ≠ O)).card ≤ E.card := card_filter_le _ _ have h5 : (E.filter (fun e => e = O)).card * Q.card * ((E.filter (fun e => e = O)).card * Q.card) ≤ Q.card * Q.card := by have := Nat.mul_le_mul hO (le_refl Q.card) rw [one_mul] at this exact Nat.mul_le_mul this this have h6 : ((E.filter (fun e => e ≠ O)).card * Q.card) * ((E.filter (fun e => e ≠ O)).card * 2) ≤ (E.card * Q.card) * (E.card * 2) := Nat.mul_le_mul (Nat.mul_le_mul h4 le_rfl) (Nat.mul_le_mul h4 le_rfl) omega end Erdos94ThmA /-! ### (R6) Prop. C bookkeeping, part 3: chords of the regular polygon; the outlier bound `F_Q(x) ≤ K·M(x) + 3K|Q₂|` (THEOREM_A §7.5, ordered pairs: `Σ_q cnt(|xq|) ≤ 2K·M(x) + 6K|Q₂|`) -/ namespace Erdos94ThmA open Finset theorem exp_chord (α β : ℝ) : ‖Complex.exp (α * Complex.I) - Complex.exp (β * Complex.I)‖ ^ 2 = (2 * Real.sin ((β - α) / 2)) ^ 2 := by have h := norm_sub_exp_sq 1 α β rw [Complex.ofReal_one, one_mul] at h rw [h, chord_sq, show 2 * ((β - α) / 2) = β - α by ring] ring theorem regPoly_pt_dist {O w : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = 1) (α β : ℝ) : dist (O + ρ * (w * Complex.exp (α * Complex.I))) (O + ρ * (w * Complex.exp (β * Complex.I))) = ρ * |2 * Real.sin ((β - α) / 2)| := by rw [dist_eq_norm, show O + ρ * (w * Complex.exp (α * Complex.I)) - (O + ρ * (w * Complex.exp (β * Complex.I))) = ((ρ : ℂ) * w) * (Complex.exp (α * Complex.I) - Complex.exp (β * Complex.I)) by ring, norm_mul, norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hρ, hw, mul_one] congr 1 rw [← Real.sqrt_sq (norm_nonneg _), exp_chord, Real.sqrt_sq_eq_abs] theorem exp_arg_eq (j g : ℕ) : (2 * Real.pi * Complex.I * (j / g) : ℂ) = ((2 * Real.pi * j / g : ℝ) : ℂ) * Complex.I := by push_cast ring theorem chord_of_lt {ρ : ℝ} {g j j' : ℕ} (hjj : j < j') (hj' : j' < g) : ρ * |2 * Real.sin ((2 * Real.pi * j' / g - 2 * Real.pi * j / g) / 2)| ∈ chordLen ρ g := by have hg : (0 : ℝ) < g := by exact_mod_cast (lt_of_le_of_lt (Nat.zero_le _) hj') have hd1 : 1 ≤ j' - j := by omega have hd2 : j' - j < g := by omega have harg : (2 * Real.pi * j' / g - 2 * Real.pi * j / g) / 2 = Real.pi * ((j' - j : ℕ) : ℝ) / g := by rw [Nat.cast_sub hjj.le] field_simp rw [harg] have hdpos : (0 : ℝ) < ((j' - j : ℕ) : ℝ) := by exact_mod_cast hd1 have hdlt : ((j' - j : ℕ) : ℝ) < g := by exact_mod_cast hd2 have hpos : 0 < Real.sin (Real.pi * ((j' - j : ℕ) : ℝ) / g) := by apply Real.sin_pos_of_pos_of_lt_pi · positivity · rw [div_lt_iff₀ hg] nlinarith [Real.pi_pos] rw [abs_of_pos (by linarith : 0 < 2 * Real.sin (Real.pi * ((j' - j : ℕ) : ℝ) / g))] by_cases hs : j' - j ≤ g / 2 · exact ⟨j' - j, hd1, hs, by ring⟩ · refine ⟨g - (j' - j), by omega, by omega, ?_⟩ have e : Real.sin (Real.pi * ((g - (j' - j) : ℕ) : ℝ) / g) = Real.sin (Real.pi * ((j' - j : ℕ) : ℝ) / g) := by rw [Nat.cast_sub hd2.le, show Real.pi * ((g : ℝ) - ((j' - j : ℕ) : ℝ)) / g = Real.pi - Real.pi * ((j' - j : ℕ) : ℝ) / g by field_simp, Real.sin_pi_sub] rw [e] ring /-- Two distinct vertices of the regular polygon are at a chord length. -/ theorem regPoly_dist_mem {O w : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = 1) {g : ℕ} {a b : ℂ} (ha : a ∈ regPoly O w ρ g) (hb : b ∈ regPoly O w ρ g) (hab : a ≠ b) : dist a b ∈ chordLen ρ g := by unfold regPoly at ha hb rw [mem_image] at ha hb obtain ⟨j, hj, rfl⟩ := ha obtain ⟨j', hj', rfl⟩ := hb rw [mem_range] at hj hj' rw [exp_arg_eq, exp_arg_eq] at hab ⊢ rcases lt_trichotomy j j' with h | h | h · rw [regPoly_pt_dist hρ hw] exact chord_of_lt h hj' · exact absurd (by rw [h]) hab · rw [dist_comm, regPoly_pt_dist hρ hw] exact chord_of_lt h hj open Classical in /-- **The outlier bound (§7.5)**: for any `x`, any finite `C₀` whose pairs have lengths in `CL`, `Σ_{q ∈ Q} cnt(Q°, |xq|) ≤ 2K·#{q ∈ C₀ : |xq| ∈ CL} + 6K·|Q ∖ C₀|` (`Q` on a circle). -/ theorem F_bound {Q C₀ : Finset ℂ} {O x : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (CL : Set ℝ) (hCL : ∀ a ∈ C₀, ∀ b ∈ C₀, a ≠ b → dist a b ∈ CL) : ∑ q ∈ Q, cnt Q.offDiag (dist x q) ≤ Q.card * 2 * (C₀.filter (fun q => dist x q ∈ CL)).card + 6 * Q.card * (Q.filter (fun q => q ∉ C₀)).card := by have hall : ∀ q ∈ Q, cnt Q.offDiag (dist x q) ≤ Q.card * 2 := fun q _ => cnt_offDiag_circle_le hρ hQ _ have hQ2c : ∀ e ∈ Q.filter (fun q => q ∉ C₀), ∀ v : ℝ, (Q.filter (fun q => dist e q = v)).card ≤ 2 := fun e he v => card_circle_dist_le_two hQ (circle_ne_center hρ (hQ e (mem_filter.mp he).1)) v have hnot : ∀ u : ℝ, u ∉ CL → cnt Q.offDiag u ≤ 4 * (Q.filter (fun q => q ∉ C₀)).card := by intro u hu have hsub : Q.offDiag.filter (fun y => dist y.1 y.2 = u) ⊆ (((Q.filter (fun q => q ∉ C₀)) ×ˢ Q).filter (fun y => dist y.1 y.2 = u)) ∪ ((Q ×ˢ (Q.filter (fun q => q ∉ C₀))).filter (fun y => dist y.1 y.2 = u)) := by intro p hp rw [mem_filter, mem_offDiag] at hp obtain ⟨⟨h1, h2, h12⟩, hd⟩ := hp rw [mem_union, mem_filter, mem_filter, mem_product, mem_product] by_cases hp1 : p.1 ∈ C₀ · by_cases hp2 : p.2 ∈ C₀ · exact absurd (hd ▸ hCL _ hp1 _ hp2 h12) hu · right exact ⟨⟨h1, mem_filter.mpr ⟨h2, hp2⟩⟩, hd⟩ · left exact ⟨⟨mem_filter.mpr ⟨h1, hp1⟩, h2⟩, hd⟩ calc cnt Q.offDiag u ≤ ((((Q.filter (fun q => q ∉ C₀)) ×ˢ Q).filter (fun y => dist y.1 y.2 = u)) ∪ ((Q ×ˢ (Q.filter (fun q => q ∉ C₀))).filter (fun y => dist y.1 y.2 = u))).card := card_le_card hsub _ ≤ cnt ((Q.filter (fun q => q ∉ C₀)) ×ˢ Q) u + cnt (Q ×ˢ (Q.filter (fun q => q ∉ C₀))) u := card_union_le _ _ _ ≤ (Q.filter (fun q => q ∉ C₀)).card * 2 + (Q.filter (fun q => q ∉ C₀)).card * 2 := add_le_add (cnt_product_le _ Q 2 hQ2c u) (cnt_product_le' Q _ 2 hQ2c u) _ = 4 * (Q.filter (fun q => q ∉ C₀)).card := by ring rw [← sum_filter_add_sum_filter_not Q (fun q => q ∈ C₀), ← sum_filter_add_sum_filter_not (Q.filter (fun q => q ∈ C₀)) (fun q => dist x q ∈ CL)] have s1 : ∑ q ∈ (Q.filter (fun q => q ∈ C₀)).filter (fun q => dist x q ∈ CL), cnt Q.offDiag (dist x q) ≤ (C₀.filter (fun q => dist x q ∈ CL)).card * (Q.card * 2) := by calc _ ≤ ∑ _q ∈ (Q.filter (fun q => q ∈ C₀)).filter (fun q => dist x q ∈ CL), Q.card * 2 := sum_le_sum (fun q hq => hall q (mem_filter.mp (mem_filter.mp hq).1).1) _ = ((Q.filter (fun q => q ∈ C₀)).filter (fun q => dist x q ∈ CL)).card * (Q.card * 2) := by rw [sum_const, smul_eq_mul] _ ≤ (C₀.filter (fun q => dist x q ∈ CL)).card * (Q.card * 2) := Nat.mul_le_mul (card_le_card (fun q hq => by rw [mem_filter] at hq ⊢ exact ⟨(mem_filter.mp hq.1).2, hq.2⟩)) le_rfl have s2 : ∑ q ∈ (Q.filter (fun q => q ∈ C₀)).filter (fun q => ¬ dist x q ∈ CL), cnt Q.offDiag (dist x q) ≤ Q.card * (4 * (Q.filter (fun q => q ∉ C₀)).card) := by calc _ ≤ ∑ _q ∈ (Q.filter (fun q => q ∈ C₀)).filter (fun q => ¬ dist x q ∈ CL), 4 * (Q.filter (fun q => q ∉ C₀)).card := sum_le_sum (fun q hq => hnot _ (mem_filter.mp hq).2) _ = ((Q.filter (fun q => q ∈ C₀)).filter (fun q => ¬ dist x q ∈ CL)).card * (4 * (Q.filter (fun q => q ∉ C₀)).card) := by rw [sum_const, smul_eq_mul] _ ≤ Q.card * (4 * (Q.filter (fun q => q ∉ C₀)).card) := Nat.mul_le_mul (le_trans (card_filter_le _ _) (card_filter_le _ _)) le_rfl have s3 : ∑ q ∈ Q.filter (fun q => ¬ q ∈ C₀), cnt Q.offDiag (dist x q) ≤ (Q.filter (fun q => q ∉ C₀)).card * (Q.card * 2) := by calc _ ≤ ∑ _q ∈ Q.filter (fun q => ¬ q ∈ C₀), Q.card * 2 := sum_le_sum (fun q hq => hall q (mem_filter.mp hq).1) _ = (Q.filter (fun q => q ∉ C₀)).card * (Q.card * 2) := by rw [sum_const, smul_eq_mul] calc _ ≤ (C₀.filter (fun q => dist x q ∈ CL)).card * (Q.card * 2) + Q.card * (4 * (Q.filter (fun q => q ∉ C₀)).card) + (Q.filter (fun q => q ∉ C₀)).card * (Q.card * 2) := add_le_add (add_le_add s1 s2) s3 _ = Q.card * 2 * (C₀.filter (fun q => dist x q ∈ CL)).card + 6 * Q.card * (Q.filter (fun q => q ∉ C₀)).card := by ring end Erdos94ThmA /-! ### (R6) Prop. C bookkeeping, part 4: the near case yields a regular `g`-gon `C₀` on the circle with `0.99K ≤ g ≤ 1.0002K`, `|Q ∖ C₀| ≤ K/10⁴`, and `O ∈ conv Q` (THEOREM_A §7.3–§7.4 with `C1p`) -/ namespace Erdos94ThmA open Finset theorem unitSet_norm {Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) {b : ℂˣ} (hb : b ∈ unitSet Q O ρ) : ‖(b : ℂ)‖ = 1 := by unfold unitSet at hb rw [mem_image] at hb obtain ⟨q, hq, rfl⟩ := hb rw [toUnit_val (unorm_ne_zero hρ (hQ q hq))] unfold unorm rw [norm_div, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hρ, hQ q hq, div_self hρ.ne'] theorem mem_regPoly_of_mem_coset {Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (H : Subgroup ℂˣ) (D : Finset ℂˣ) (hmem : ∀ x, x ∈ H ↔ x ∈ D) (hg : 0 < D.card) (b : ℂˣ) {q : ℂ} (hq : q ∈ Q) (hd : toUnit (unorm O ρ q) * b⁻¹ ∈ D) : q ∈ regPoly O (b : ℂ) ρ D.card := by obtain ⟨j, hj, hexp⟩ := subgroup_elem_exp H D hmem hg hd unfold regPoly rw [mem_image] refine ⟨j, mem_range.mpr hj, ?_⟩ rw [hexp, Units.val_mul, Units.val_inv_eq_inv_val, toUnit_val (unorm_ne_zero hρ (hQ q hq))] unfold unorm have hb0 : (b : ℂ) ≠ 0 := b.ne_zero have hρ0 : (ρ : ℂ) ≠ 0 := by exact_mod_cast hρ.ne' field_simp ring open Classical in /-- **Near case structure.** If `E(A) ≥ (1 − 10⁻⁴)K³` for the normalised circle part `A` of `Q` (`K = |Q| ≥ 4`), there are `g ≥ 3` and `|w| = 1` with `g ≤ (1 + 2·10⁻⁴)K`, at most `K/10⁴` points of `Q` off the regular `g`-gon `regPoly O w ρ g`, and `O ∈ conv Q`. -/ theorem near_structure (Q : Finset ℂ) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hK : 4 ≤ Q.card) (hE : (1 - 1 / 10000) * (Q.card : ℝ) ^ 3 ≤ energy (unitSet Q O ρ)) : ∃ g : ℕ, ∃ w : ℂ, ‖w‖ = 1 ∧ 3 ≤ g ∧ (g : ℝ) ≤ (1 + 2 / 10000) * Q.card ∧ ((Q.filter (fun q => q ∉ regPoly O w ρ g)).card : ℝ) ≤ Q.card / 10000 ∧ O ∈ convexHull ℝ (Q : Set ℂ) := by have hA : (unitSet Q O ρ).card = Q.card := card_image_of_injOn (toUnit_unorm_injOn Q O hρ hQ) have hAne : (unitSet Q O ρ).Nonempty := by rw [← card_pos, hA] omega have hKpos : (0 : ℝ) < Q.card := by exact_mod_cast (show 0 < Q.card by omega) obtain ⟨H, D, hmem, h1, h2, -, b, hb, h4, h5⟩ := C1p (unitSet Q O ρ) hAne (1 / 100) (1 / 10000) (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by rw [hA]; exact hE) rw [hA] at h1 h2 h4 h5 obtain ⟨N₁, hN₁⟩ : ∃ N₁, N₁ = ((unitSet Q O ρ).filter (fun a => a * b⁻¹ ∈ D)).card := ⟨_, rfl⟩ rw [← hN₁] at h4 h5 have hN₁K : N₁ ≤ Q.card := by rw [hN₁, ← hA] exact card_filter_le _ _ have hN₁K' : (N₁ : ℝ) ≤ Q.card := by exact_mod_cast hN₁K have h1' : (99 / 100) * (Q.card : ℝ) ≤ D.card := by have := h1 norm_num at this linarith have h4' : (99 / 100) * (Q.card : ℝ) ≤ N₁ := by have := h4 norm_num at this linarith have hg2 : (D.card : ℝ) ≤ (1 + 2 / 10000) * Q.card := by have h2' : (D.card : ℝ) * (49 / 50) * Q.card ≤ (49 / 50) * (Q.card : ℝ) ^ 2 + (1 / 10000) * (Q.card : ℝ) ^ 2 := by have := h2 norm_num at this ⊢ linarith nlinarith have hg3 : 3 ≤ D.card := by have h4K : (4 : ℝ) ≤ Q.card := by exact_mod_cast hK have : (3 : ℝ) ≤ D.card := by linarith exact_mod_cast this have hm : (Q.card : ℝ) - N₁ ≤ Q.card / 10000 := by have hm0 : 0 ≤ (Q.card : ℝ) - N₁ := by linarith have hm1 : (Q.card : ℝ) - N₁ ≤ Q.card / 100 := by linarith have h5' : 2 * ((Q.card : ℝ) - N₁) * Q.card - 6 * ((Q.card : ℝ) - N₁) ^ 2 ≤ (1 / 10000) * (Q.card : ℝ) ^ 2 := by have := h5 norm_num at this ⊢ linarith nlinarith [mul_nonneg hm0 (by linarith : (0 : ℝ) ≤ Q.card / 100 - (Q.card - N₁))] have hQ2 : ((Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card)).card : ℝ) ≤ Q.card - N₁ := by have hsub : Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card) ⊆ Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D) := by intro q hq rw [mem_filter] at hq ⊢ exact ⟨hq.1, fun hd => hq.2 (mem_regPoly_of_mem_coset hρ hQ H D hmem (by omega) b hq.1 hd)⟩ have e1 : (unitSet Q O ρ).filter (fun a => a * b⁻¹ ∈ D) = (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∈ D)).image (fun z => toUnit (unorm O ρ z)) := by unfold unitSet rw [filter_image] have e2 : N₁ = (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∈ D)).card := by rw [hN₁, e1, card_image_of_injOn] exact (toUnit_unorm_injOn Q O hρ hQ).mono (coe_subset.mpr (filter_subset _ _)) have hcard : (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card + N₁ = Q.card := by rw [e2, add_comm] exact card_filter_add_card_filter_not _ have hc1 := card_le_card hsub have hc2 : ((Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card : ℝ) + N₁ = Q.card := by exact_mod_cast hcard have hc3 : ((Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card)).card : ℝ) ≤ (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card := by exact_mod_cast hc1 linarith have hmiss : 3 * (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card < D.card := by have hinj : N₁ ≤ (D.filter (fun d => b * d ∈ unitSet Q O ρ)).card := by rw [hN₁] apply card_le_card_of_injOn (fun a => a * b⁻¹) · intro a ha have ha' := mem_filter.mp ha refine mem_filter.mpr ⟨ha'.2, ?_⟩ show b * (a * b⁻¹) ∈ unitSet Q O ρ rw [mul_comm a b⁻¹, ← mul_assoc, mul_inv_cancel, one_mul] exact ha'.1 · intro a _ a' _ h exact mul_right_cancel h have hsplit := card_filter_add_card_filter_not (s := D) (fun d => b * d ∈ unitSet Q O ρ) have hs : ((D.filter (fun d => b * d ∈ unitSet Q O ρ)).card : ℝ) + (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card = D.card := by exact_mod_cast hsplit have hinjR : (N₁ : ℝ) ≤ (D.filter (fun d => b * d ∈ unitSet Q O ρ)).card := by exact_mod_cast hinj have : (3 : ℝ) * (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card < D.card := by linarith exact_mod_cast this have hO := center_mem_hull Q O hρ hQ H D hmem hg3 b hmiss exact ⟨D.card, (b : ℂ), unitSet_norm hρ hQ hb, hg3, hg2, by linarith, hO⟩ end Erdos94ThmA /-! ### (R7) Prop. C arithmetic (THEOREM_A §7.1 (v), §7.2, §7.5), as small real-number lemmas -/ namespace Erdos94ThmA open Finset theorem ngonValue_ge (n : ℕ) : (n : ℝ) ^ 2 * (n - 1) / 2 - (n : ℝ) ^ 2 / 4 ≤ Erdos94Infra.ngonValue n := by unfold Erdos94Infra.ngonValue rw [Nat.cast_choose_two] split_ifs · nlinarith [sq_nonneg (n : ℝ)] · nlinarith [sq_nonneg (n : ℝ)] theorem ngonValue_le (n : ℕ) : Erdos94Infra.ngonValue n ≤ (n : ℝ) ^ 2 * (n - 1) / 2 := by unfold Erdos94Infra.ngonValue rw [Nat.cast_choose_two] split_ifs · nlinarith [sq_nonneg (n : ℝ)] · nlinarith [sq_nonneg (n : ℝ)] /-- Near case (§7.5): the outlier bound with `g ≤ (1 + 2·10⁻⁴)K`, `m ≤ K/10⁴`. -/ theorem near_X_le {K k g s m X : ℝ} (hK0 : 0 ≤ K) (hk0 : 0 ≤ k) (hg : g ≤ (1 + 2 / 10000) * K) (hs0 : 0 ≤ s) (hss : s ^ 2 = g) (hm : m ≤ K / 10000) (hX : X ≤ k * (2 * K * (g / 2 + 4.5 * s + 7) + 6 * K * m)) : X ≤ k * (1.02332 * K ^ 2 + 914 * K) := by have hs : s ≤ g / 400 + 100 := by nlinarith [sq_nonneg (s - 200)] have hM : g / 2 + 4.5 * s + 7 ≤ 0.51136 * K + 457 := by linarith have h1 := mul_le_mul_of_nonneg_left hM (by linarith : (0 : ℝ) ≤ 2 * K) have h2 := mul_le_mul_of_nonneg_left hm (by linarith : (0 : ℝ) ≤ 6 * K) have h3 : 2 * K * (g / 2 + 4.5 * s + 7) + 6 * K * m ≤ 1.02332 * K ^ 2 + 914 * K := by nlinarith have h4 := mul_le_mul_of_nonneg_left h3 hk0 linarith /-- Near case (§7.5), final inequality. -/ theorem near_arith {n K k X A0 A1 A2 A3 : ℝ} (hn : 161000 ≤ n) (hk1 : 1 ≤ k) (hkn : 50000 * k ≤ n) (hnK : n = K + k) (hX : X ≤ k * (1.02332 * K ^ 2 + 914 * K)) (hA0 : A0 ≤ 2 * (K ^ 2 * (K - 1))) (hA1 : A1 ≤ k ^ 2 * (2 * K)) (hA2 : A2 ≤ (k * K) * (k * 2)) (hA3 : A3 ≤ 3 * k * k ^ 2) : A0 + 4 * X + 2 * A1 + 8 * A2 + 2 * A3 ≤ 2 * (n ^ 2 * (n - 1)) - n ^ 2 := by subst hnK have hK1 : 49999 * k ≤ K := by linarith have hK2 : 160996 ≤ K := by linarith have hk0 : 0 ≤ k := by linarith have hK0 : 0 ≤ K := by linarith have hkK : 0 ≤ k * K := mul_nonneg hk0 hK0 have p1 := mul_le_mul_of_nonneg_right hk1 (sq_nonneg K) have p2 := mul_le_mul_of_nonneg_left hK1 hkK have p3 := mul_le_mul_of_nonneg_left hK1 (sq_nonneg k) have p4 := mul_le_mul_of_nonneg_left hK2 hkK have p5 : 0 ≤ k * K ^ 2 := mul_nonneg hk0 (sq_nonneg K) nlinarith /-- Far case (§7.2), final inequality. -/ theorem far_arith {n K k X A0 A1 A2 A3 : ℝ} (hn : 161000 ≤ n) (hk0 : 0 ≤ k) (hkn : 50000 * k ≤ n) (hnK : n = K + k) (hX : X ≤ (k * K) * (K * 2)) (hA0 : A0 ≤ 2 * ((1 - 1 / 10000) * K ^ 3) - 2 * K ^ 2) (hA1 : A1 ≤ k ^ 2 * (2 * K)) (hA2 : A2 ≤ 2 * K ^ 2 + 2 * ((k * K) * (k * 2))) (hA3 : A3 ≤ 3 * k * k ^ 2) : A0 + 4 * X + 2 * A1 + 8 * A2 + 2 * A3 ≤ 2 * (n ^ 2 * (n - 1)) - n ^ 2 := by subst hnK have hK1 : 49999 * k ≤ K := by linarith have hK2 : 160996 ≤ K := by linarith have hK0 : 0 ≤ K := by linarith have hkK : 0 ≤ k * K := mul_nonneg hk0 hK0 have q1 := mul_le_mul_of_nonneg_left hK1 (sq_nonneg K) have q2 := mul_le_mul_of_nonneg_left hK1 hkK have q3 := mul_le_mul_of_nonneg_left hK1 (sq_nonneg k) have q4 := mul_le_mul_of_nonneg_left hK2 (sq_nonneg K) have q5 := mul_le_mul_of_nonneg_left hK2 hkK have q6 : 0 ≤ k ^ 2 := sq_nonneg k nlinarith end Erdos94ThmA /-! ### (R6) Prop. C bookkeeping, part 5: the individual terms of (7.1) as real-number bounds (separate declarations, so that the assemblies stay far inside the default heartbeats) -/ namespace Erdos94ThmA open Finset /-- (4.2) in `ℂ`: a concyclic `Q` has `pairEnergy(Q) = 4 S(Q) ≤ 4 R(|Q|)`. -/ theorem pe_circle_le {Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) : (pe Q.offDiag Q.offDiag : ℝ) ≤ 4 * Erdos94Infra.ngonValue Q.card := by have hmult : ∀ u ∈ distanceSet Q, distanceMultiplicity Q u ≤ Q.card := by intro u _ have h1 : (Q.offDiag.filter (fun x => dist x.1 x.2 = u)).card ≤ 2 * Q.card := by have := cnt_offDiag_circle_le hρ hQ u unfold cnt at this omega unfold distanceMultiplicity omega have h := Erdos94Infra.sum_sq_le_of_mult_le Q Q.card rfl hmult rw [Erdos94Infra.sum_sq_mult_eq] at h have e : (Erdos94Infra.pairEnergy Q : ℝ) = (pe Q.offDiag Q.offDiag : ℝ) := rfl linarith theorem decomp_R {P Q E : Finset ℂ} (hdisj : Disjoint Q E) (hPQE : P = Q ∪ E) : (pe P.offDiag P.offDiag : ℝ) ≤ pe Q.offDiag Q.offDiag + 4 * pe (E ×ˢ Q) Q.offDiag + 2 * pe E.offDiag Q.offDiag + 8 * pe (E ×ˢ Q) (E ×ˢ Q) + 2 * pe E.offDiag E.offDiag := by have hdec := pe_decomp Q E hdisj rw [← hPQE] at hdec exact_mod_cast hdec theorem bnd_A1 {Q E : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) : (pe E.offDiag Q.offDiag : ℝ) ≤ (E.card : ℝ) ^ 2 * (2 * Q.card) := by have h' : pe E.offDiag Q.offDiag ≤ (E.card * E.card) * (Q.card * 2) := le_trans (pe_Eo_Qo_le hρ hQ) (Nat.mul_le_mul (Nat.sub_le _ _) le_rfl) have h'' : (pe E.offDiag Q.offDiag : ℝ) ≤ ((E.card : ℝ) * E.card) * (Q.card * 2) := by exact_mod_cast h' nlinarith theorem bnd_A3 {E : Finset ℂ} (hE : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a})) : (pe E.offDiag E.offDiag : ℝ) ≤ 3 * E.card * (E.card : ℝ) ^ 2 := by have h' : pe E.offDiag E.offDiag ≤ 3 * E.card * (E.card * E.card) := le_trans (pe_offDiag_le hE) (Nat.mul_le_mul le_rfl (Nat.sub_le _ _)) have h'' : (pe E.offDiag E.offDiag : ℝ) ≤ 3 * E.card * ((E.card : ℝ) * E.card) := by exact_mod_cast h' nlinarith theorem bnd_A0_near {Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) : (pe Q.offDiag Q.offDiag : ℝ) ≤ 2 * ((Q.card : ℝ) ^ 2 * (Q.card - 1)) := by have h1 := pe_circle_le hρ hQ have h2 := ngonValue_le Q.card linarith theorem bnd_A0_far {Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) {δ : ℝ} (hfar : (energy (unitSet Q O ρ) : ℝ) < (1 - δ) * (Q.card : ℝ) ^ 3) : (pe Q.offDiag Q.offDiag : ℝ) ≤ 2 * ((1 - δ) * (Q.card : ℝ) ^ 3) - 2 * (Q.card : ℝ) ^ 2 := by have hR3 : pe Q.offDiag Q.offDiag + 2 * (Q.card * Q.card) ≤ 2 * energy (unitSet Q O ρ) := pairEnergy_circle_le Q O hρ hQ have hR3' : (pe Q.offDiag Q.offDiag : ℝ) + 2 * ((Q.card : ℝ) * Q.card) ≤ 2 * (energy (unitSet Q O ρ) : ℝ) := by exact_mod_cast hR3 nlinarith theorem bnd_X_far {Q E : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) : (pe (E ×ˢ Q) Q.offDiag : ℝ) ≤ ((E.card : ℝ) * Q.card) * (Q.card * 2) := by have h := pe_le_of_cnt_le (E ×ˢ Q) Q.offDiag (Q.card * 2) (fun x _ => cnt_offDiag_circle_le hρ hQ _) rw [card_product] at h exact_mod_cast h theorem bnd_A2_far {Q E : Finset ℂ} {O : ℂ} {ρ : ℝ} (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) : (pe (E ×ˢ Q) (E ×ˢ Q) : ℝ) ≤ 2 * (Q.card : ℝ) ^ 2 + 2 * (((E.card : ℝ) * Q.card) * (E.card * 2)) := by have h' : (pe (E ×ˢ Q) (E ×ˢ Q) : ℝ) ≤ 2 * ((Q.card : ℝ) * Q.card) + 2 * (((E.card : ℝ) * Q.card) * (E.card * 2)) := by exact_mod_cast pe_EQ_EQ_le_far (E := E) hQ nlinarith theorem bnd_A2_near {Q E : Finset ℂ} {O : ℂ} {ρ : ℝ} (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hEO : ∀ e ∈ E, e ≠ O) : (pe (E ×ˢ Q) (E ×ˢ Q) : ℝ) ≤ ((E.card : ℝ) * Q.card) * (E.card * 2) := by exact_mod_cast pe_EQ_EQ_le_near hQ hEO open Classical in /-- Near case: `pe(E×Q, Q°) = 2Σ_e F_Q(e) ≤ k (2K(g/2 + 4.5√g + 7) + 6K·cK)` from `F_bound` and Lemma C2. -/ theorem bnd_X_near {Q E : Finset ℂ} {O w : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hw : ‖w‖ = 1) {g : ℕ} (hg3 : 3 ≤ g) (c : ℝ) (hQ2 : ((Q.filter (fun q => q ∉ regPoly O w ρ g)).card : ℝ) ≤ c * Q.card) (hEc : ∀ e ∈ E, ‖e - O‖ ≠ ρ) (hEO : ∀ e ∈ E, e ≠ O) : (pe (E ×ˢ Q) Q.offDiag : ℝ) ≤ E.card * (2 * Q.card * (g / 2 + 4.5 * Real.sqrt g + 7) + 6 * Q.card * (c * Q.card)) := by have hXe : ∀ e ∈ E, ((∑ q ∈ Q, cnt Q.offDiag (dist e q) : ℕ) : ℝ) ≤ 2 * Q.card * (g / 2 + 4.5 * Real.sqrt g + 7) + 6 * Q.card * (c * Q.card) := by intro e he have hF := F_bound (C₀ := regPoly O w ρ g) (x := e) hρ hQ (chordLen ρ g) (fun a ha b hb hab => regPoly_dist_mem hρ hw ha hb hab) have hC2 := lemmaC2 hρ hw hg3 (hEc e he) (hEO e he) have hFR : ((∑ q ∈ Q, cnt Q.offDiag (dist e q) : ℕ) : ℝ) ≤ Q.card * 2 * ((regPoly O w ρ g).filter (fun q => dist e q ∈ chordLen ρ g)).card + 6 * Q.card * (Q.filter (fun q => q ∉ regPoly O w ρ g)).card := by exact_mod_cast hF have hK0 : (0 : ℝ) ≤ Q.card := Nat.cast_nonneg _ have e1 := mul_le_mul_of_nonneg_left hC2 (by linarith : (0 : ℝ) ≤ Q.card * 2) have e2 := mul_le_mul_of_nonneg_left hQ2 (by linarith : (0 : ℝ) ≤ 6 * Q.card) linarith rw [pe_EQ_Qo_eq, Nat.cast_sum] calc _ ≤ ∑ _e ∈ E, (2 * Q.card * (g / 2 + 4.5 * Real.sqrt g + 7) + 6 * Q.card * (c * Q.card) : ℝ) := sum_le_sum hXe _ = _ := by rw [sum_const, nsmul_eq_mul] /-- The centre is not a vertex when it lies in the hull of the circle part. -/ theorem center_not_mem {P Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hP : ∀ z ∈ P, z ∉ convexHull ℝ ((P : Set ℂ) \ {z})) (hQP : Q ⊆ P) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hO : O ∈ convexHull ℝ (Q : Set ℂ)) : O ∉ P := by intro hOP apply hP O hOP apply convexHull_mono _ hO intro q hq exact ⟨hQP hq, fun h => circle_ne_center hρ (hQ q hq) (Set.mem_singleton_iff.mp h)⟩ /-- Far case of Theorem A′: (12.4) `E ≥ K²(K−1) − M_C` and `E < (1 − δ₁)K³` give `M_C ≥ δ₁K³ − K²`. -/ theorem bnd_y_far {P Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQP : Q ⊆ P) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hPC : ∀ z ∈ P, ‖z - O‖ = ρ → z ∈ Q) (hfar : (energy (unitSet Q O ρ) : ℝ) < (1 - 16 / 1000) * (Q.card : ℝ) ^ 3) : 16 / 1000 * (Q.card : ℝ) ^ 3 - (Q.card : ℝ) ^ 2 ≤ ∑ pq ∈ Q.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := by have hEB := energy_bound_units P Q hQP O hρ hQ hPC have hoff : Q.offDiag.card + Q.card = Q.card * Q.card := by rw [offDiag_card, Nat.sub_add_cancel (Nat.le_mul_self _)] have hoffR : (Q.offDiag.card : ℝ) + Q.card = (Q.card : ℝ) * Q.card := by exact_mod_cast hoff have hEBR : (Q.card : ℝ) * Q.offDiag.card ≤ (energy (unitSet Q O ρ) : ℝ) + ∑ pq ∈ Q.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := by exact_mod_cast hEB have hoffR' : (Q.offDiag.card : ℝ) = (Q.card : ℝ) * Q.card - Q.card := by linarith rw [hoffR'] at hEBR nlinarith end Erdos94ThmA /-! ### (R8) Proposition C (THEOREM_A §7): near-concyclic convex-independent sets satisfy `S(P) ≤ R(n)` -/ namespace Erdos94ThmA open Finset open Classical in /-- **Proposition C in `ℂ`** (THEOREM_A §7, κ = 2·10⁻⁵): if `P ⊂ ℂ` is convex independent, `|P| = n ≥ 161 000`, and all but `k ≤ n/50 000` points of `P` lie on a circle `C(O, ρ)`, then `pairEnergy(P) = 4 S(P) ≤ 4 R(n)`. -/ theorem propC_C (P : Finset ℂ) (hP : ∀ z ∈ P, z ∉ convexHull ℝ ((P : Set ℂ) \ {z})) (hn : 161000 ≤ P.card) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hk : ((P.filter (fun z => ‖z - O‖ ≠ ρ)).card : ℝ) ≤ P.card / 50000) : (pe P.offDiag P.offDiag : ℝ) ≤ 4 * Erdos94Infra.ngonValue P.card := by obtain ⟨Q, hQdef⟩ : ∃ Q, Q = P.filter (fun z => ‖z - O‖ = ρ) := ⟨_, rfl⟩ obtain ⟨E, hEdef⟩ : ∃ E, E = P.filter (fun z => ‖z - O‖ ≠ ρ) := ⟨_, rfl⟩ rw [← hEdef] at hk have hQ : ∀ q ∈ Q, ‖q - O‖ = ρ := fun q hq => by rw [hQdef] at hq exact (mem_filter.mp hq).2 have hEc : ∀ e ∈ E, ‖e - O‖ ≠ ρ := fun e he => by rw [hEdef] at he exact (mem_filter.mp he).2 have hEP : E ⊆ P := by rw [hEdef] exact filter_subset _ _ have hQP : Q ⊆ P := by rw [hQdef] exact filter_subset _ _ have hPQE : P = Q ∪ E := by ext z rw [mem_union, hQdef, hEdef, mem_filter, mem_filter] by_cases h : ‖z - O‖ = ρ · exact ⟨fun hz => Or.inl ⟨hz, h⟩, fun hz => hz.elim (fun h' => h'.1) (fun h' => h'.1)⟩ · exact ⟨fun hz => Or.inr ⟨hz, h⟩, fun hz => hz.elim (fun h' => h'.1) (fun h' => h'.1)⟩ have hdisj : Disjoint Q E := by rw [disjoint_left] intro z hzQ hzE exact hEc z hzE (hQ z hzQ) have hcard : P.card = Q.card + E.card := by rw [hPQE, card_union_of_disjoint hdisj] have hEind : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a}) := fun a ha h => hP a (hEP ha) (convexHull_mono (Set.diff_subset_diff_left (coe_subset.mpr hEP)) h) have hnR : (161000 : ℝ) ≤ P.card := by exact_mod_cast hn have hcardR : (P.card : ℝ) = Q.card + E.card := by exact_mod_cast hcard have hkn : 50000 * (E.card : ℝ) ≤ P.card := by linarith have hRn := ngonValue_ge P.card have hdecR := decomp_R hdisj hPQE have hA1 := bnd_A1 (E := E) hρ hQ have hA3 := bnd_A3 hEind rcases Nat.eq_zero_or_pos E.card with hk0 | hk1 · have hE0 : E = ∅ := card_eq_zero.mp hk0 rw [hE0, union_empty] at hPQE rw [hPQE] exact pe_circle_le hρ hQ · have hk1R : (1 : ℝ) ≤ E.card := by exact_mod_cast hk1 have hK4 : 4 ≤ Q.card := by have : (4 : ℝ) ≤ Q.card := by linarith exact_mod_cast this by_cases hnear : (1 - 1 / 10000) * (Q.card : ℝ) ^ 3 ≤ energy (unitSet Q O ρ) · obtain ⟨g, w, hw, hg3, hg, hQ2, hOhull⟩ := near_structure Q O hρ hQ hK4 hnear have hOP := center_not_mem hρ hP hQP hQ hOhull have hEO : ∀ e ∈ E, e ≠ O := fun e he h => hOP (h ▸ hEP he) have hQ2' : ((Q.filter (fun q => q ∉ regPoly O w ρ g)).card : ℝ) ≤ 1 / 10000 * Q.card := by linarith have hX := bnd_X_near hρ hQ hw hg3 (1 / 10000) hQ2' hEc hEO have hX' := near_X_le (Nat.cast_nonneg Q.card) (Nat.cast_nonneg E.card) hg (Real.sqrt_nonneg _) (Real.sq_sqrt (Nat.cast_nonneg g)) (le_of_eq (by ring)) hX have hA0 := bnd_A0_near hρ hQ have hA2 := bnd_A2_near (E := E) hQ hEO have := near_arith hnR hk1R hkn hcardR hX' hA0 hA1 hA2 hA3 linarith · have hfar : (energy (unitSet Q O ρ) : ℝ) < (1 - 1 / 10000) * (Q.card : ℝ) ^ 3 := not_le.mp hnear have hA0 := bnd_A0_far hρ hQ hfar have hX := bnd_X_far (E := E) hρ hQ have hA2 := bnd_A2_far (E := E) hQ have := far_arith hnR (Nat.cast_nonneg _) hkn hcardR hX hA0 hA1 hA2 hA3 linarith /-- `pairEnergy` is invariant under the isometry `ℝ² → ℂ`. -/ theorem pairEnergy_image_C (P : Finset (EuclideanSpace ℝ (Fin 2))) : Erdos94Infra.pairEnergy (P.image Complex.orthonormalBasisOneI.repr.symm) = Erdos94Infra.pairEnergy P := by classical rw [Erdos94Infra.pairEnergy_image P Complex.orthonormalBasisOneI.repr.symm.injective] unfold Erdos94Infra.pairEnergy refine sum_congr rfl (fun x _ => sum_congr rfl (fun y _ => ?_)) rw [Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq, Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] open Classical in /-- **Proposition C** (THEOREM_A §7). Let `κ = 2·10⁻⁵`. If `P` is ConvexIndep, `|P| = n ≥ 161 000`, and some circle `C(O, ρ)` contains all but `k ≤ κn` points of `P`, then `S(P) ≤ R(n)`. -/ theorem propC {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) (hn : 161000 ≤ P.card) {O : EuclideanSpace ℝ (Fin 2)} {ρ : ℝ} (hρ : 0 < ρ) (hk : ((P.filter (fun p => dist p O ≠ ρ)).card : ℝ) ≤ 2 / 100000 * P.card) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue P.card := by obtain ⟨φ, hφ⟩ : ∃ φ, φ = Complex.orthonormalBasisOneI.repr.symm := ⟨_, rfl⟩ have hcard : (P.image Complex.orthonormalBasisOneI.repr.symm).card = P.card := card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective have hfilt : ((P.image Complex.orthonormalBasisOneI.repr.symm).filter (fun z => ‖z - Complex.orthonormalBasisOneI.repr.symm O‖ ≠ ρ)).card = (P.filter (fun p => dist p O ≠ ρ)).card := by rw [filter_image, card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective] congr 1 refine filter_congr (fun p _ => ?_) rw [← dist_eq_norm, Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] have h := propC_C (P.image Complex.orthonormalBasisOneI.repr.symm) (fun z hz => convexIndep_image_C hP hz) (by rw [hcard]; exact hn) (Complex.orthonormalBasisOneI.repr.symm O) hρ (by rw [hfilt, hcard]; linarith) rw [hcard] at h rw [Erdos94Infra.sum_sq_mult_eq, ← pairEnergy_image_C] have e : (Erdos94Infra.pairEnergy (P.image Complex.orthonormalBasisOneI.repr.symm) : ℝ) = (pe (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag : ℝ) := rfl rw [e] linarith end Erdos94ThmA /-! ### (R7′) Theorem A′ (THEOREM_A §12): near-case structure with `C1′` at `t = 0.09`, `δ₁ = 0.016`, and the arithmetic of §12.2, §12.6, §12.7 -/ namespace Erdos94ThmA open Finset open Classical in /-- **Near case structure for Theorem A′ (§12.6).** If `E(A) ≥ (1 − 0.016)K³` (`K = |Q| ≥ 4`), then `C1′` with `t = 0.09` gives `g ≥ 3`, `|w| = 1`, `g ≤ 1.0196K`, at most `0.0172K` points of `Q` off `regPoly O w ρ g`, and `O ∈ conv Q`. -/ theorem near_structure' (Q : Finset ℂ) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hK : 4 ≤ Q.card) (hE : (1 - 16 / 1000) * (Q.card : ℝ) ^ 3 ≤ energy (unitSet Q O ρ)) : ∃ g : ℕ, ∃ w : ℂ, ‖w‖ = 1 ∧ 3 ≤ g ∧ (g : ℝ) ≤ (1 + 196 / 10000) * Q.card ∧ ((Q.filter (fun q => q ∉ regPoly O w ρ g)).card : ℝ) ≤ 172 / 10000 * Q.card ∧ O ∈ convexHull ℝ (Q : Set ℂ) := by have hA : (unitSet Q O ρ).card = Q.card := card_image_of_injOn (toUnit_unorm_injOn Q O hρ hQ) have hAne : (unitSet Q O ρ).Nonempty := by rw [← card_pos, hA] omega have hKpos : (0 : ℝ) < Q.card := by exact_mod_cast (show 0 < Q.card by omega) obtain ⟨H, D, hmem, h1, h2, -, b, hb, h4, h5⟩ := C1p (unitSet Q O ρ) hAne (9 / 100) (16 / 1000) (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by rw [hA]; exact hE) rw [hA] at h1 h2 h4 h5 obtain ⟨N₁, hN₁⟩ : ∃ N₁, N₁ = ((unitSet Q O ρ).filter (fun a => a * b⁻¹ ∈ D)).card := ⟨_, rfl⟩ rw [← hN₁] at h4 h5 have hN₁K : N₁ ≤ Q.card := by rw [hN₁, ← hA] exact card_filter_le _ _ have hN₁K' : (N₁ : ℝ) ≤ Q.card := by exact_mod_cast hN₁K have h1' : (37 / 45) * (Q.card : ℝ) ≤ D.card := by have := h1 norm_num at this linarith have h4' : (37 / 45) * (Q.card : ℝ) ≤ N₁ := by have := h4 norm_num at this linarith have hg2 : (D.card : ℝ) ≤ (1 + 196 / 10000) * Q.card := by have h2' : (D.card : ℝ) * (41 / 50) * Q.card ≤ (41 / 50) * (Q.card : ℝ) ^ 2 + (16 / 1000) * (Q.card : ℝ) ^ 2 := by have := h2 norm_num at this ⊢ linarith nlinarith have hg3 : 3 ≤ D.card := by have h4K : (4 : ℝ) ≤ Q.card := by exact_mod_cast hK have : (3 : ℝ) ≤ D.card := by linarith exact_mod_cast this have hm : (Q.card : ℝ) - N₁ ≤ 172 / 10000 * Q.card := by have hm0 : 0 ≤ (Q.card : ℝ) - N₁ := by linarith have hm1 : (Q.card : ℝ) - N₁ ≤ 8 / 45 * Q.card := by linarith have h5' : 2 * ((Q.card : ℝ) - N₁) * Q.card - 6 * ((Q.card : ℝ) - N₁) ^ 2 ≤ (16 / 1000) * (Q.card : ℝ) ^ 2 := by have := h5 norm_num at this ⊢ linarith nlinarith [mul_nonneg hm0 (by linarith : (0 : ℝ) ≤ 8 / 45 * Q.card - (Q.card - N₁))] have hQ2 : ((Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card)).card : ℝ) ≤ Q.card - N₁ := by have hsub : Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card) ⊆ Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D) := by intro q hq rw [mem_filter] at hq ⊢ exact ⟨hq.1, fun hd => hq.2 (mem_regPoly_of_mem_coset hρ hQ H D hmem (by omega) b hq.1 hd)⟩ have e1 : (unitSet Q O ρ).filter (fun a => a * b⁻¹ ∈ D) = (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∈ D)).image (fun z => toUnit (unorm O ρ z)) := by unfold unitSet rw [filter_image] have e2 : N₁ = (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∈ D)).card := by rw [hN₁, e1, card_image_of_injOn] exact (toUnit_unorm_injOn Q O hρ hQ).mono (coe_subset.mpr (filter_subset _ _)) have hcard : (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card + N₁ = Q.card := by rw [e2, add_comm] exact card_filter_add_card_filter_not _ have hc1 := card_le_card hsub have hc2 : ((Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card : ℝ) + N₁ = Q.card := by exact_mod_cast hcard have hc3 : ((Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card)).card : ℝ) ≤ (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card := by exact_mod_cast hc1 linarith have hmiss : 3 * (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card < D.card := by have hinj : N₁ ≤ (D.filter (fun d => b * d ∈ unitSet Q O ρ)).card := by rw [hN₁] apply card_le_card_of_injOn (fun a => a * b⁻¹) · intro a ha have ha' := mem_filter.mp ha refine mem_filter.mpr ⟨ha'.2, ?_⟩ show b * (a * b⁻¹) ∈ unitSet Q O ρ rw [mul_comm a b⁻¹, ← mul_assoc, mul_inv_cancel, one_mul] exact ha'.1 · intro a _ a' _ h exact mul_right_cancel h have hsplit := card_filter_add_card_filter_not (s := D) (fun d => b * d ∈ unitSet Q O ρ) have hs : ((D.filter (fun d => b * d ∈ unitSet Q O ρ)).card : ℝ) + (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card = D.card := by exact_mod_cast hsplit have hinjR : (N₁ : ℝ) ≤ (D.filter (fun d => b * d ∈ unitSet Q O ρ)).card := by exact_mod_cast hinj have : (3 : ℝ) * (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card < D.card := by linarith exact_mod_cast this have hO := center_mem_hull Q O hρ hQ H D hmem hg3 b hmiss exact ⟨D.card, (b : ℂ), unitSet_norm hρ hQ hb, hg3, hg2, by linarith, hO⟩ /-- §12.6: the outlier bound with `g ≤ 1.0196K`, `m ≤ 0.0172K`. -/ theorem near_X_le' {K k g s m X : ℝ} (hK0 : 0 ≤ K) (hk0 : 0 ≤ k) (hg : g ≤ (1 + 196 / 10000) * K) (hss : s ^ 2 = g) (hm : m ≤ 172 / 10000 * K) (hX : X ≤ k * (2 * K * (g / 2 + 4.5 * s + 7) + 6 * K * m)) : X ≤ k * (1.1458 * K ^ 2 + 914 * K) := by have hs : s ≤ g / 400 + 100 := by nlinarith [sq_nonneg (s - 200)] have hM : g / 2 + 4.5 * s + 7 ≤ 0.5213 * K + 457 := by linarith have h1 := mul_le_mul_of_nonneg_left hM (by linarith : (0 : ℝ) ≤ 2 * K) have h2 := mul_le_mul_of_nonneg_left hm (by linarith : (0 : ℝ) ≤ 6 * K) have h3 : 2 * K * (g / 2 + 4.5 * s + 7) + 6 * K * m ≤ 1.1458 * K ^ 2 + 914 * K := by nlinarith have h4 := mul_le_mul_of_nonneg_left h3 hk0 linarith /-- **(12.2)** From (12.1) (`cross_sum`) and `M ≤ n³/100`: `k ≤ 0.020421 n`. -/ theorem kbound_general {n K k y Mo : ℝ} (hn : 100000 ≤ n) (hk0 : 0 ≤ k) (hk : k ≤ 14 / 100 * n) (hnK : n = K + k) (hy0 : 0 ≤ y) (hMo : Mo ≤ 2 * (1 / 100) * n ^ 3) (hcs : (K - 2) * (y + k * K * (n - 2) - Mo) ≤ 4 * k * y) : k ≤ 20421 / 1000000 * n := by have t1 : 0 ≤ K - 2 - 4 * k := by linarith have t1' : 0 < K - 2 := by linarith have t2 : (K - 2) * (k * K * (n - 2)) ≤ (K - 2) * Mo := by nlinarith [mul_nonneg t1 hy0] have t3 : k * K * (n - 2) ≤ 2 * (1 / 100) * n ^ 3 := by have := le_of_mul_le_mul_left t2 t1' linarith have hkK : 0 ≤ k * K := mul_nonneg hk0 (by linarith) have t4 : k * K * (99998 / 100000 * n) ≤ 2 * (1 / 100) * n ^ 3 := by have : k * K * (99998 / 100000 * n) ≤ k * K * (n - 2) := mul_le_mul_of_nonneg_left (by linarith) hkK linarith have hnpos : 0 < n := by linarith have t5 : k * K ≤ 200005 / 10000000 * n ^ 2 := by by_contra hcon have hlt : 200005 / 10000000 * n ^ 2 < k * K := not_le.mp hcon have := mul_lt_mul_of_pos_right hlt (by positivity : (0 : ℝ) < 99998 / 100000 * n) nlinarith [pow_pos hnpos 3] by_contra hcon have hgt : 20421 / 1000000 * n < k := not_le.mp hcon have h1 : 0 < k - 20421 / 1000000 * n := by linarith have h2 : 0 < n - 20421 / 1000000 * n - k := by linarith nlinarith [mul_pos h1 h2] /-- §12.7: in the far case the `M`-budget forces `k ≤ 0.0067 n`. -/ theorem far_kbound {n K k y Mo : ℝ} (hn : 100000 ≤ n) (hk0 : 0 ≤ k) (hk : k ≤ 20421 / 1000000 * n) (hnK : n = K + k) (hy0 : 0 ≤ y) (hy : 16 / 1000 * K ^ 3 - K ^ 2 ≤ y) (hMo : Mo ≤ 2 * (1 / 100) * n ^ 3) (hcs : (K - 2) * (y + k * K * (n - 2) - Mo) ≤ 4 * k * y) : k ≤ 67 / 10000 * n := by have hK : 979579 / 1000000 * n ≤ K := by linarith have s1 : 9 / 10 * (K - 2) ≤ K - 2 - 4 * k := by linarith have s1' : 0 < K - 2 := by linarith have s2 : 9 / 10 * (K - 2) * y ≤ (K - 2 - 4 * k) * y := mul_le_mul_of_nonneg_right s1 hy0 have s3 : (K - 2) * (9 / 10 * y + k * K * (n - 2)) ≤ (K - 2) * (2 * (1 / 100) * n ^ 3) := by nlinarith have s4 : 9 / 10 * y + k * K * (n - 2) ≤ 2 * (1 / 100) * n ^ 3 := le_of_mul_le_mul_left s3 s1' have hK0 : 0 ≤ K := by linarith have s6 : 939970 / 1000000 * n ^ 3 ≤ K ^ 3 := by have h := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ 979579 / 1000000 * n) hK 3 have e : (979579 / 1000000 * n) ^ 3 = (979579 / 1000000) ^ 3 * n ^ 3 := by ring rw [e] at h nlinarith [pow_nonneg (by linarith : (0 : ℝ) ≤ n) 3] have s6' : K ^ 2 ≤ n ^ 2 := by nlinarith have s7 : 97955 / 100000 * n ^ 2 ≤ K * (n - 2) := by nlinarith have s8 : k * (97955 / 100000 * n ^ 2) ≤ k * (K * (n - 2)) := mul_le_mul_of_nonneg_left s7 hk0 have hnpos : 0 < n := by linarith by_contra hcon have hgt : 67 / 10000 * n < k := not_le.mp hcon have := mul_lt_mul_of_pos_right hgt (by positivity : (0 : ℝ) < 97955 / 100000 * n ^ 2) nlinarith /-- §12.6, final inequality. -/ theorem near_arith' {n K k X A0 A1 A2 A3 : ℝ} (hn : 100000 ≤ n) (hk1 : 1 ≤ k) (hk : k ≤ 20421 / 1000000 * n) (hnK : n = K + k) (hX : X ≤ k * (1.1458 * K ^ 2 + 914 * K)) (hA0 : A0 ≤ 2 * (K ^ 2 * (K - 1))) (hA1 : A1 ≤ k ^ 2 * (2 * K)) (hA2 : A2 ≤ (k * K) * (k * 2)) (hA3 : A3 ≤ 3 * k * k ^ 2) : A0 + 4 * X + 2 * A1 + 8 * A2 + 2 * A3 ≤ 2 * (n ^ 2 * (n - 1)) - n ^ 2 := by subst hnK have hK1 : 47 * k ≤ K := by linarith have hK2 : 97950 ≤ K := by linarith have hk0 : 0 ≤ k := by linarith have hK0 : 0 ≤ K := by linarith have hkK : 0 ≤ k * K := mul_nonneg hk0 hK0 have p1 := mul_le_mul_of_nonneg_right hk1 (sq_nonneg K) have p2 := mul_le_mul_of_nonneg_left hK1 hkK have p3 := mul_le_mul_of_nonneg_left hK1 (sq_nonneg k) have p4 := mul_le_mul_of_nonneg_left hK2 hkK have p5 : 0 ≤ k * K ^ 2 := mul_nonneg hk0 (sq_nonneg K) nlinarith /-- §12.7, final inequality. -/ theorem far_arith' {n K k X A0 A1 A2 A3 : ℝ} (hn : 100000 ≤ n) (hk0 : 0 ≤ k) (hk : k ≤ 67 / 10000 * n) (hnK : n = K + k) (hX : X ≤ (k * K) * (K * 2)) (hA0 : A0 ≤ 2 * ((1 - 16 / 1000) * K ^ 3) - 2 * K ^ 2) (hA1 : A1 ≤ k ^ 2 * (2 * K)) (hA2 : A2 ≤ 2 * K ^ 2 + 2 * ((k * K) * (k * 2))) (hA3 : A3 ≤ 3 * k * k ^ 2) : A0 + 4 * X + 2 * A1 + 8 * A2 + 2 * A3 ≤ 2 * (n ^ 2 * (n - 1)) - n ^ 2 := by subst hnK have hK1 : 148 * k ≤ K := by linarith have hK2 : 99330 ≤ K := by linarith have hK0 : 0 ≤ K := by linarith have hkK : 0 ≤ k * K := mul_nonneg hk0 hK0 have q1 := mul_le_mul_of_nonneg_left hK1 (sq_nonneg K) have q2 := mul_le_mul_of_nonneg_left hK1 hkK have q3 := mul_le_mul_of_nonneg_left hK1 (sq_nonneg k) have q4 := mul_le_mul_of_nonneg_left hK2 (sq_nonneg K) have q5 := mul_le_mul_of_nonneg_left hK2 hkK have q6 : 0 ≤ k ^ 2 := sq_nonneg k nlinarith end Erdos94ThmA /-! ### (R8′) Theorem A′ (THEOREM_A §12): `M(P) ≤ n³/100`, `n ≥ 10⁵` ⇒ `S(P) ≤ R(n)` -/ namespace Erdos94ThmA open Finset open Classical in /-- **Theorem A′ in `ℂ`** (THEOREM_A §12): `P ⊂ ℂ` convex independent with the translation property (T), `n ≥ 10⁵`, and `Mord P = 2M(P) ≤ 2n³/100` ⇒ `pairEnergy(P) = 4S(P) ≤ 4R(n)`. -/ theorem thmAp_C (P : Finset ℂ) (hP : ∀ z ∈ P, z ∉ convexHull ℝ ((P : Set ℂ) \ {z})) (hT : ∀ t : ℂ, t ≠ 0 → (P.filter (fun z => z + t ∈ P)).card ≤ 2) (hn : 100000 ≤ P.card) (hM : (Mord P : ℝ) ≤ 2 * (1 / 100) * (P.card : ℝ) ^ 3) : (pe P.offDiag P.offDiag : ℝ) ≤ 4 * Erdos94Infra.ngonValue P.card := by obtain ⟨O, ρ, hρ, hKlow⟩ := lemmaB P hT (by omega) (1 / 100) (by norm_num) hM obtain ⟨Q, hQdef⟩ : ∃ Q, Q = P.filter (fun z => ‖z - O‖ = ρ) := ⟨_, rfl⟩ obtain ⟨E, hEdef⟩ : ∃ E, E = P.filter (fun z => ‖z - O‖ ≠ ρ) := ⟨_, rfl⟩ rw [← hQdef] at hKlow have hQ : ∀ q ∈ Q, ‖q - O‖ = ρ := fun q hq => by rw [hQdef] at hq exact (mem_filter.mp hq).2 have hEc : ∀ e ∈ E, ‖e - O‖ ≠ ρ := fun e he => by rw [hEdef] at he exact (mem_filter.mp he).2 have hEP : E ⊆ P := by rw [hEdef] exact filter_subset _ _ have hQP : Q ⊆ P := by rw [hQdef] exact filter_subset _ _ have hPC : ∀ z ∈ P, ‖z - O‖ = ρ → z ∈ Q := fun z hz h => by rw [hQdef] exact mem_filter.mpr ⟨hz, h⟩ have hnotQ : ∀ z ∈ P, z ∉ Q → ‖z - O‖ ≠ ρ := fun z hz hzQ h => hzQ (hPC z hz h) have hPQE : P = Q ∪ E := by ext z rw [mem_union, hQdef, hEdef, mem_filter, mem_filter] by_cases h : ‖z - O‖ = ρ · exact ⟨fun hz => Or.inl ⟨hz, h⟩, fun hz => hz.elim (fun h' => h'.1) (fun h' => h'.1)⟩ · exact ⟨fun hz => Or.inr ⟨hz, h⟩, fun hz => hz.elim (fun h' => h'.1) (fun h' => h'.1)⟩ have hdisj : Disjoint Q E := by rw [disjoint_left] intro z hzQ hzE exact hEc z hzE (hQ z hzQ) have hcard : P.card = Q.card + E.card := by rw [hPQE, card_union_of_disjoint hdisj] have hEind : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a}) := fun a ha h => hP a (hEP ha) (convexHull_mono (Set.diff_subset_diff_left (coe_subset.mpr hEP)) h) have hnR : (100000 : ℝ) ≤ P.card := by exact_mod_cast hn have hcardR : (P.card : ℝ) = Q.card + E.card := by exact_mod_cast hcard have hk014 : (E.card : ℝ) ≤ 14 / 100 * P.card := by linarith have hRn := ngonValue_ge P.card have hdecR := decomp_R hdisj hPQE have hA1 := bnd_A1 (E := E) hρ hQ have hA3 := bnd_A3 hEind rcases Nat.eq_zero_or_pos E.card with hk0 | hk1 · have hE0 : E = ∅ := card_eq_zero.mp hk0 rw [hE0, union_empty] at hPQE rw [hPQE] exact pe_circle_le hρ hQ · have hk1R : (1 : ℝ) ≤ E.card := by exact_mod_cast hk1 have hK4 : 4 ≤ Q.card := by have : (4 : ℝ) ≤ Q.card := by linarith exact_mod_cast this have hcs := cross_sum P Q hT hQP O hQ hnotQ (by omega) have hkE : (P.card : ℝ) - Q.card = E.card := by linarith rw [hkE] at hcs have hy0 : (0 : ℝ) ≤ ∑ pq ∈ Q.offDiag, (muC P (bis pq.1 pq.2) : ℝ) := sum_nonneg (fun _ _ => Nat.cast_nonneg _) have hkb := kbound_general hnR (Nat.cast_nonneg _) hk014 hcardR hy0 hM hcs by_cases hnear : (1 - 16 / 1000) * (Q.card : ℝ) ^ 3 ≤ energy (unitSet Q O ρ) · obtain ⟨g, w, hw, hg3, hg, hQ2, hOhull⟩ := near_structure' Q O hρ hQ hK4 hnear have hOP := center_not_mem hρ hP hQP hQ hOhull have hEO : ∀ e ∈ E, e ≠ O := fun e he h => hOP (h ▸ hEP he) have hX := bnd_X_near hρ hQ hw hg3 (172 / 10000) hQ2 hEc hEO have hX' := near_X_le' (Nat.cast_nonneg Q.card) (Nat.cast_nonneg E.card) hg (Real.sq_sqrt (Nat.cast_nonneg g)) le_rfl hX have hA0 := bnd_A0_near hρ hQ have hA2 := bnd_A2_near (E := E) hQ hEO have := near_arith' hnR hk1R hkb hcardR hX' hA0 hA1 hA2 hA3 linarith · have hfar : (energy (unitSet Q O ρ) : ℝ) < (1 - 16 / 1000) * (Q.card : ℝ) ^ 3 := not_le.mp hnear have hy := bnd_y_far hρ hQP hQ hPC hfar have hkf := far_kbound hnR (Nat.cast_nonneg _) hkb hcardR hy0 hy hM hcs have hA0 := bnd_A0_far hρ hQ hfar have hX := bnd_X_far (E := E) hρ hQ have hA2 := bnd_A2_far (E := E) hQ have := far_arith' hnR (Nat.cast_nonneg _) hkf hcardR hX hA0 hA1 hA2 hA3 linarith /-- **Theorem A′** (THEOREM_A §12). Let `η₁ = 1/100`, `n₁ = 10⁵`. Every ConvexIndep `P ⊂ ℝ²` with `|P| = n ≥ n₁` and `M(P) ≤ η₁n³` has `S(P) ≤ R(n)`, for both parities. Here `M(P)` is computed on the image of `P` in `ℂ` (`Mord = 2M`, as in `lemmaB_plane`). -/ theorem thmAp {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) (hn : 100000 ≤ P.card) (hM : (Mord (P.image Complex.orthonormalBasisOneI.repr.symm) : ℝ) ≤ 2 * (1 / 100) * (P.card : ℝ) ^ 3) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue P.card := by have hcard : (P.image Complex.orthonormalBasisOneI.repr.symm).card = P.card := card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective have h := thmAp_C (P.image Complex.orthonormalBasisOneI.repr.symm) (fun z hz => convexIndep_image_C hP hz) (fun t ht => translate_card_le_two_C hP ht) (by rw [hcard]; exact hn) (by rw [hcard]; exact hM) rw [hcard] at h rw [Erdos94Infra.sum_sq_mult_eq, ← pairEnergy_image_C] have e : (Erdos94Infra.pairEnergy (P.image Complex.orthonormalBasisOneI.repr.symm) : ℝ) = (pe (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag : ℝ) := rfl rw [e] linarith end Erdos94ThmA /-! ### Theorem A (THEOREM_A §8) as the special case `η₀ = 1/700 000`, `n₀ = 200 000` of Theorem A′ -/ namespace Erdos94ThmA open Finset /-- **Theorem A** (THEOREM_A §8). Every ConvexIndep `P ⊂ ℝ²` with `|P| = n ≥ 200 000` and `M(P) ≤ n³/700 000` has `S(P) ≤ R(n)`, for both parities (`M` via `Mord = 2M` on the image in `ℂ`). -/ theorem thmA {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) (hn : 200000 ≤ P.card) (hM : (Mord (P.image Complex.orthonormalBasisOneI.repr.symm) : ℝ) ≤ 2 * (1 / 700000) * (P.card : ℝ) ^ 3) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue P.card := by have h3 : (0 : ℝ) ≤ (P.card : ℝ) ^ 3 := pow_nonneg (Nat.cast_nonneg _) 3 exact thmAp hP (by omega) (by linarith) end Erdos94ThmA /-! ### Lemma 8.2 (INVERSE §7c): an off-circle point sees `≤ 10 N^{2/3} + 12` chord lengths of `R_N` -/ namespace Erdos94ThmA open Finset open Classical in /-- The matched vertices split over the two open arcs and the axis: `#{i < g : matched(φ₀ + iδ)} ≤ |arcSet(c_U)| + |arcSet(c_L)| + 2`. -/ theorem C2_split {d : ℝ} {g : ℕ} (hg : 3 ≤ g) (φ₀ : ℝ) : ((range g).filter (fun i : ℕ => matchedAng d g (φ₀ + (i : ℝ) * (2 * Real.pi / g)))).card ≤ (arcSet d g (toIcoMod (show (0:ℝ) < 2 * Real.pi / g by have : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) positivity) 0 φ₀)).card + (arcSet d g (toIcoMod (show (0:ℝ) < 2 * Real.pi / g by have : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) positivity) 0 (-φ₀))).card + 2 := by classical have hgR : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) set δ : ℝ := 2 * Real.pi / g with hδ have hδ0 : 0 < δ := by positivity have h2π : (0 : ℝ) < 2 * Real.pi := by positivity set Mset := (range g).filter (fun i : ℕ => matchedAng d g (φ₀ + (i : ℝ) * δ)) with hMset -- reduced angle in [−π, π) let t : ℕ → ℝ := fun i => toIcoMod h2π (-Real.pi) (φ₀ + i * δ) have ht_mem : ∀ i : ℕ, -Real.pi ≤ t i ∧ t i < Real.pi := by intro i have := toIcoMod_mem_Ico h2π (-Real.pi) (φ₀ + i * δ) exact ⟨this.1, by linarith [this.2]⟩ have ht_eq : ∀ i : ℕ, t i = φ₀ + i * δ - (toIcoDiv h2π (-Real.pi) (φ₀ + i * δ) : ℝ) * (2 * Real.pi) := by intro i have := self_sub_toIcoMod_eq_mul h2π (-Real.pi) (φ₀ + i * δ) simp only [t] linarith have ht_cos : ∀ i : ℕ, Real.cos (t i) = Real.cos (φ₀ + i * δ) := by intro i rw [ht_eq i, Real.cos_sub_int_mul_two_pi] have ht_inj : Set.InjOn t (range g : Set ℕ) := by intro i hi i' hi' h rw [coe_range, Set.mem_Iio] at hi hi' have := (ht_eq i).symm.trans (h.trans (ht_eq i')) have key : (i : ℝ) * δ - (toIcoDiv h2π (-Real.pi) (φ₀ + i * δ) : ℝ) * (2 * Real.pi) = (i' : ℝ) * δ - (toIcoDiv h2π (-Real.pi) (φ₀ + i' * δ) : ℝ) * (2 * Real.pi) := by linarith exact vertex_index_eq (show 0 < g by omega) hi hi' key have hmatch_t : ∀ i : ℕ, matchedAng d g (φ₀ + i * δ) → matchedAng d g (t i) := by intro i hm obtain ⟨s, h1, h2, h3⟩ := hm exact ⟨s, h1, h2, by rw [ht_cos]; exact h3⟩ have hmatch_neg : ∀ i : ℕ, matchedAng d g (φ₀ + i * δ) → matchedAng d g (-t i) := by intro i hm obtain ⟨s, h1, h2, h3⟩ := hm exact ⟨s, h1, h2, by rw [Real.cos_neg, ht_cos]; exact h3⟩ -- the three parts obtain ⟨U, hU⟩ : ∃ U, U = Mset.filter (fun i => 0 < t i) := ⟨_, rfl⟩ obtain ⟨R, hR⟩ : ∃ R, R = Mset.filter (fun i => ¬ (0 < t i)) := ⟨_, rfl⟩ obtain ⟨Lw, hLw⟩ : ∃ L, L = R.filter (fun i => -Real.pi < t i ∧ t i ≠ 0) := ⟨_, rfl⟩ obtain ⟨Ax, hAx⟩ : ∃ A, A = R.filter (fun i => ¬ (-Real.pi < t i ∧ t i ≠ 0)) := ⟨_, rfl⟩ have hcover : Mset.card ≤ U.card + Lw.card + Ax.card := by have h1 := card_filter_add_card_filter_not (s := Mset) (fun i => 0 < t i) rw [← hU, ← hR] at h1 have h2 := card_filter_add_card_filter_not (s := R) (fun i => -Real.pi < t i ∧ t i ≠ 0) rw [← hLw, ← hAx] at h2 omega have memU : ∀ i ∈ U, (i ∈ range g ∧ matchedAng d g (φ₀ + i * δ)) ∧ 0 < t i := by intro i hi rw [hU, mem_filter, hMset, mem_filter] at hi exact hi have memL : ∀ i ∈ Lw, ((i ∈ range g ∧ matchedAng d g (φ₀ + i * δ)) ∧ ¬ (0 < t i)) ∧ (-Real.pi < t i ∧ t i ≠ 0) := by intro i hi rw [hLw, mem_filter, hR, mem_filter, hMset, mem_filter] at hi exact hi have memA : ∀ i ∈ Ax, ((i ∈ range g ∧ matchedAng d g (φ₀ + i * δ)) ∧ ¬ (0 < t i)) ∧ ¬ (-Real.pi < t i ∧ t i ≠ 0) := by intro i hi rw [hAx, mem_filter, hR, mem_filter, hMset, mem_filter] at hi exact hi -- upper arc have hU_le : U.card ≤ (arcSet d g (toIcoMod hδ0 0 φ₀)).card := by have key : ∀ i ∈ U, ∃ j ∈ arcSet d g (toIcoMod hδ0 0 φ₀), toIcoMod hδ0 0 φ₀ + j * δ = t i := by intro i hi have hi := memU i hi obtain ⟨j, hj, hjt⟩ := arc_index hg φ₀ i _ (ht_eq i) hi.2 (ht_mem i).2 refine ⟨j, ?_, hjt⟩ unfold arcSet rw [mem_filter] refine ⟨mem_range.mpr hj, by rw [hjt]; exact hi.2, by rw [hjt]; exact (ht_mem i).2, ?_⟩ rw [hjt] exact hmatch_t i hi.1.2 choose! f hf hft using key apply card_le_card_of_injOn f · intro i hi exact hf i hi · intro i hi i' hi' h have e1 := hft i hi have e2 := hft i' hi' rw [h] at e1 have hti : t i = t i' := e1.symm.trans e2 exact ht_inj (mem_coe.mpr (memU i hi).1.1) (mem_coe.mpr (memU i' hi').1.1) hti -- lower arc (negated angles) have hL_le : Lw.card ≤ (arcSet d g (toIcoMod hδ0 0 (-φ₀))).card := by have key : ∀ i ∈ Lw, ∃ j ∈ arcSet d g (toIcoMod hδ0 0 (-φ₀)), toIcoMod hδ0 0 (-φ₀) + j * δ = -t i := by intro i hi have hi := memL i hi have htneg : 0 < -t i := by have : t i < 0 := lt_of_le_of_ne (not_lt.mp hi.1.2) hi.2.2 linarith have htlt : -t i < Real.pi := by linarith [hi.2.1] have hrange := mem_range.mp hi.1.1.1 have hdiv : ∃ D : ℤ, -t i = -φ₀ + (g - i : ℕ) * δ - D * (2 * Real.pi) := by refine ⟨1 - toIcoDiv h2π (-Real.pi) (φ₀ + i * δ), ?_⟩ rw [ht_eq i] have h2πe : 2 * Real.pi = g * δ := by rw [hδ]; field_simp push_cast [Nat.cast_sub hrange.le] linear_combination h2πe obtain ⟨D, hD⟩ := hdiv obtain ⟨j, hj, hjt⟩ := arc_index hg (-φ₀) (g - i) D hD htneg htlt refine ⟨j, ?_, hjt⟩ unfold arcSet rw [mem_filter] refine ⟨mem_range.mpr hj, by rw [hjt]; exact htneg, by rw [hjt]; exact htlt, ?_⟩ rw [hjt] exact hmatch_neg i hi.1.1.2 choose! f hf hft using key apply card_le_card_of_injOn f · intro i hi exact hf i hi · intro i hi i' hi' h have e1 := hft i hi have e2 := hft i' hi' rw [h] at e1 have hti : t i = t i' := by linarith exact ht_inj (mem_coe.mpr (memL i hi).1.1.1) (mem_coe.mpr (memL i' hi').1.1.1) hti -- axis: at most two vertices have hAx_le : Ax.card ≤ 2 := by have hsub : Ax.image t ⊆ {0, -Real.pi} := by intro x hx rw [mem_image] at hx obtain ⟨i, hi, rfl⟩ := hx have hi := memA i hi have h1 := (ht_mem i).1 rw [mem_insert, mem_singleton] by_cases h0 : t i = 0 · exact Or.inl h0 · right have : ¬ (-Real.pi < t i) := fun h => hi.2 ⟨h, h0⟩ linarith [not_lt.mp this] have hinj : Set.InjOn t (Ax : Set ℕ) := fun i hi i' hi' h => ht_inj (mem_coe.mpr (memA i (mem_coe.mp hi)).1.1.1) (mem_coe.mpr (memA i' (mem_coe.mp hi')).1.1.1) h have := card_le_card hsub rw [card_image_of_injOn hinj] at this exact le_trans this (card_insert_le _ _) linarith [hcover, hU_le, hL_le, hAx_le] end Erdos94ThmA /-! ### Lemma 8.2, counting: steps `(g_i, k_i)` with every pair at most 4 times (INVERSE §7c) -/ namespace Erdos94ThmA open Finset /-- Two-dimensional step counting with real thresholds `G₀, K₀ > 0`: if `Mt ⊆ [0, J)`, `s` is strictly increasing on `Mt` with values `≤ L`, and every step `(gap, Δs) = (gg, kk)` occurs at most 4 times, then `|Mt| ≤ 1 + 4 G₀K₀ + J/G₀ + (L + 1)/K₀`. -/ theorem arc_count2 (Mt : Finset ℕ) (s : ℕ → ℕ) (J L : ℕ) (hMt : Mt ⊆ range J) (hsL : ∀ j ∈ Mt, s j ≤ L) (hmono : ∀ j ∈ Mt, ∀ j' ∈ Mt, j < j' → s j < s j') (h4 : ∀ gg kk : ℕ, 1 ≤ gg → 1 ≤ kk → (Mt.filter (fun j => j + gg ∈ Mt ∧ s (j + gg) = s j + kk)).card ≤ 4) (G₀ K₀ : ℝ) (hG : 0 < G₀) (hK : 0 < K₀) : (Mt.card : ℝ) ≤ 1 + 4 * (G₀ * K₀) + J / G₀ + ((L : ℝ) + 1) / K₀ := by classical let nx : ℕ → ℕ := fun j => if h : (Mt.filter (fun i => j < i)).Nonempty then (Mt.filter (fun i => j < i)).min' h else j obtain ⟨Mt', hMt'⟩ : ∃ X, X = Mt.filter (fun j => (Mt.filter (fun i => j < i)).Nonempty) := ⟨_, rfl⟩ have hnx : ∀ j ∈ Mt', nx j ∈ Mt ∧ j < nx j ∧ ∀ i ∈ Mt, j < i → nx j ≤ i := by intro j hj rw [hMt', mem_filter] at hj have hne := hj.2 have e : nx j = (Mt.filter (fun i => j < i)).min' hne := by simp only [nx] rw [dif_pos hne] have hmem := min'_mem _ hne rw [mem_filter] at hmem refine ⟨by rw [e]; exact hmem.1, by rw [e]; exact hmem.2, fun i hi hji => ?_⟩ rw [e] exact min'_le _ _ (mem_filter.mpr ⟨hi, hji⟩) have hM'sub : Mt' ⊆ Mt := by rw [hMt'] exact filter_subset _ _ have hcard1 : Mt.card ≤ Mt'.card + 1 := by have hle : (Mt.filter (fun j => ¬ (Mt.filter (fun i => j < i)).Nonempty)).card ≤ 1 := by apply card_le_one.mpr intro a ha b hb rw [mem_filter] at ha hb by_contra hab rcases lt_or_gt_of_ne hab with h | h · exact ha.2 ⟨b, mem_filter.mpr ⟨hb.1, h⟩⟩ · exact hb.2 ⟨a, mem_filter.mpr ⟨ha.1, h⟩⟩ have := card_filter_add_card_filter_not (s := Mt) (fun j => (Mt.filter (fun i => j < i)).Nonempty) rw [← hMt'] at this omega have hgap : ∑ j ∈ Mt', (nx j - j) ≤ J := by have hdisj : (Mt' : Set ℕ).PairwiseDisjoint (fun j => Ico j (nx j)) := by intro a ha b hb hab rw [Function.onFun, disjoint_left] intro x hxa hxb rw [mem_Ico] at hxa hxb have ha' := hnx a ha have hb' := hnx b hb rcases lt_or_gt_of_ne hab with h | h · have := ha'.2.2 b (hM'sub hb) h omega · have := hb'.2.2 a (hM'sub ha) h omega have hsub : Mt'.biUnion (fun j => Ico j (nx j)) ⊆ range J := by intro x hx rw [mem_biUnion] at hx obtain ⟨j, hj, hx⟩ := hx rw [mem_Ico] at hx have := mem_range.mp (hMt (hnx j hj).1) exact mem_range.mpr (by omega) have := card_le_card hsub rw [card_biUnion hdisj, card_range] at this simpa [Nat.card_Ico] using this have hkap : ∑ j ∈ Mt', (s (nx j) - s j) ≤ L + 1 := by have hdisj : (Mt' : Set ℕ).PairwiseDisjoint (fun j => Ico (s j) (s (nx j))) := by intro a ha b hb hab rw [Function.onFun, disjoint_left] intro x hxa hxb rw [mem_Ico] at hxa hxb have ha' := hnx a ha have hb' := hnx b hb rcases lt_or_gt_of_ne hab with h | h · have h1 := ha'.2.2 b (hM'sub hb) h have h2 : s (nx a) ≤ s b := by rcases eq_or_lt_of_le h1 with e | e · rw [e] · exact (hmono _ ha'.1 _ (hM'sub hb) e).le omega · have h1 := hb'.2.2 a (hM'sub ha) h have h2 : s (nx b) ≤ s a := by rcases eq_or_lt_of_le h1 with e | e · rw [e] · exact (hmono _ hb'.1 _ (hM'sub ha) e).le omega have hsub : Mt'.biUnion (fun j => Ico (s j) (s (nx j))) ⊆ range (L + 1) := by intro x hx rw [mem_biUnion] at hx obtain ⟨j, hj, hx⟩ := hx rw [mem_Ico] at hx have := hsL _ (hnx j hj).1 exact mem_range.mpr (by omega) have := card_le_card hsub rw [card_biUnion hdisj, card_range] at this simpa [Nat.card_Ico] using this -- the three classes of steps obtain ⟨A, hA⟩ : ∃ X, X = Mt'.filter (fun j => ((nx j - j : ℕ) : ℝ) ≤ G₀ ∧ ((s (nx j) - s j : ℕ) : ℝ) ≤ K₀) := ⟨_, rfl⟩ obtain ⟨Bg, hBg⟩ : ∃ X, X = Mt'.filter (fun j => G₀ < ((nx j - j : ℕ) : ℝ)) := ⟨_, rfl⟩ obtain ⟨Bk, hBk⟩ : ∃ X, X = Mt'.filter (fun j => K₀ < ((s (nx j) - s j : ℕ) : ℝ)) := ⟨_, rfl⟩ have hcov : Mt' ⊆ A ∪ Bg ∪ Bk := by intro j hj rw [mem_union, mem_union, hA, hBg, hBk, mem_filter, mem_filter, mem_filter] by_cases h1 : ((nx j - j : ℕ) : ℝ) ≤ G₀ · by_cases h2 : ((s (nx j) - s j : ℕ) : ℝ) ≤ K₀ · exact Or.inl (Or.inl ⟨hj, h1, h2⟩) · exact Or.inr ⟨hj, not_le.mp h2⟩ · exact Or.inl (Or.inr ⟨hj, not_le.mp h1⟩) have hcovc : Mt'.card ≤ A.card + Bg.card + Bk.card := le_trans (card_le_card hcov) (le_trans (card_union_le _ _) (by have := card_union_le A Bg omega)) -- Markov for the long gaps and the long s-steps have hBgR : (Bg.card : ℝ) * G₀ ≤ J := by have h1 : ∑ j ∈ Bg, G₀ ≤ ∑ j ∈ Bg, ((nx j - j : ℕ) : ℝ) := by apply sum_le_sum intro j hj rw [hBg, mem_filter] at hj exact hj.2.le have h2 : ∑ j ∈ Bg, ((nx j - j : ℕ) : ℝ) ≤ ∑ j ∈ Mt', ((nx j - j : ℕ) : ℝ) := sum_le_sum_of_subset_of_nonneg (by rw [hBg]; exact filter_subset _ _) (fun _ _ _ => Nat.cast_nonneg _) have h3 : ∑ j ∈ Mt', ((nx j - j : ℕ) : ℝ) ≤ J := by exact_mod_cast hgap rw [sum_const, nsmul_eq_mul] at h1 linarith have hBkR : (Bk.card : ℝ) * K₀ ≤ (L : ℝ) + 1 := by have h1 : ∑ j ∈ Bk, K₀ ≤ ∑ j ∈ Bk, ((s (nx j) - s j : ℕ) : ℝ) := by apply sum_le_sum intro j hj rw [hBk, mem_filter] at hj exact hj.2.le have h2 : ∑ j ∈ Bk, ((s (nx j) - s j : ℕ) : ℝ) ≤ ∑ j ∈ Mt', ((s (nx j) - s j : ℕ) : ℝ) := sum_le_sum_of_subset_of_nonneg (by rw [hBk]; exact filter_subset _ _) (fun _ _ _ => Nat.cast_nonneg _) have h3 : ∑ j ∈ Mt', ((s (nx j) - s j : ℕ) : ℝ) ≤ (L : ℝ) + 1 := by exact_mod_cast hkap rw [sum_const, nsmul_eq_mul] at h1 linarith -- the short steps: at most 4 per value of (gap, Δs) ∈ [1, ⌊G₀⌋] × [1, ⌊K₀⌋] have hAc : A.card ≤ 4 * (⌊G₀⌋₊ * ⌊K₀⌋₊) := by have himg : A.image (fun j => (nx j - j, s (nx j) - s j)) ⊆ (Icc 1 ⌊G₀⌋₊) ×ˢ (Icc 1 ⌊K₀⌋₊) := by intro p hp rw [mem_image] at hp obtain ⟨j, hj, rfl⟩ := hp rw [hA, mem_filter] at hj have hj' := hnx j hj.1 have hs' := hmono _ (hM'sub hj.1) _ hj'.1 hj'.2.1 rw [mem_product, mem_Icc, mem_Icc] refine ⟨⟨by omega, Nat.le_floor hj.2.1⟩, ⟨by omega, Nat.le_floor hj.2.2⟩⟩ have hfib : ∀ p ∈ A.image (fun j => (nx j - j, s (nx j) - s j)), (A.filter (fun j => (nx j - j, s (nx j) - s j) = p)).card ≤ 4 := by intro p hp have hp' := himg hp rw [mem_product, mem_Icc, mem_Icc] at hp' apply le_trans _ (h4 p.1 p.2 hp'.1.1 hp'.2.1) apply card_le_card intro j hj rw [mem_filter] at hj ⊢ have hjA := hj.1 rw [hA, mem_filter] at hjA have hj' := hnx j hjA.1 have hs' := hmono _ (hM'sub hjA.1) _ hj'.1 hj'.2.1 have e1 : nx j - j = p.1 := congrArg Prod.fst hj.2 have e2 : s (nx j) - s j = p.2 := congrArg Prod.snd hj.2 have e3 : j + p.1 = nx j := by omega refine ⟨hM'sub hjA.1, ?_, ?_⟩ · rw [e3] exact hj'.1 · rw [e3] omega have := card_le_mul_card_image A 4 hfib have h2 := card_le_card himg rw [card_product, Nat.card_Icc, Nat.card_Icc] at h2 simp only [Nat.add_sub_cancel] at h2 nlinarith have hAR : (A.card : ℝ) ≤ 4 * (G₀ * K₀) := by have h1 : (A.card : ℝ) ≤ 4 * ((⌊G₀⌋₊ : ℝ) * ⌊K₀⌋₊) := by exact_mod_cast hAc have h2 : (⌊G₀⌋₊ : ℝ) ≤ G₀ := Nat.floor_le hG.le have h3 : (⌊K₀⌋₊ : ℝ) ≤ K₀ := Nat.floor_le hK.le have h4' : (⌊G₀⌋₊ : ℝ) * ⌊K₀⌋₊ ≤ G₀ * K₀ := mul_le_mul h2 h3 (Nat.cast_nonneg _) hG.le linarith have hBg' : (Bg.card : ℝ) ≤ J / G₀ := by rw [le_div_iff₀ hG]; exact hBgR have hBk' : (Bk.card : ℝ) ≤ ((L : ℝ) + 1) / K₀ := by rw [le_div_iff₀ hK]; exact hBkR have hcR : (Mt.card : ℝ) ≤ Mt'.card + 1 := by exact_mod_cast hcard1 have hcovR : (Mt'.card : ℝ) ≤ A.card + Bg.card + Bk.card := by exact_mod_cast hcovc linarith end Erdos94ThmA /-! ### Lemma 8.2: one arc, all vertices, and the plane form `M(x) ≤ 10 N^{2/3} + 12` -/ namespace Erdos94ThmA open Finset /-- **One arc, Lemma 8.2 form.** For real thresholds `G₀, K₀ > 0`: `|arcSet| ≤ 1 + 4G₀K₀ + (⌊g/2⌋ + 1)/G₀ + (⌊g/2⌋ + 1)/K₀`. -/ theorem arcSet_bound2 {d : ℝ} (hd : 0 < d) (hd1 : d ≠ 1) {g : ℕ} (hg : 3 ≤ g) {c : ℝ} (G₀ K₀ : ℝ) (hG : 0 < G₀) (hK : 0 < K₀) : ((arcSet d g c).card : ℝ) ≤ 1 + 4 * (G₀ * K₀) + ((g / 2 + 1 : ℕ) : ℝ) / G₀ + (((g / 2 : ℕ) : ℝ) + 1) / K₀ := by classical set δ : ℝ := 2 * Real.pi / g with hδ have hgR : (0 : ℝ) < g := by exact_mod_cast (show 0 < g by omega) have hδ0 : 0 < δ := by positivity let s : ℕ → ℕ := fun j => if h : matchedAng d g (c + j * δ) then Classical.choose h else 0 have hs_spec : ∀ j ∈ arcSet d g c, 1 ≤ s j ∧ s j ≤ g / 2 ∧ d ^ 2 + 1 - 2 * d * Real.cos (c + j * δ) = 2 - 2 * Real.cos (s j * δ) := by intro j hj unfold arcSet at hj rw [mem_filter] at hj have hm : matchedAng d g (c + j * δ) := hj.2.2.2 simp only [s] rw [dif_pos hm] exact Classical.choose_spec hm have harc : ∀ j ∈ arcSet d g c, 0 < c + j * δ ∧ c + j * δ < Real.pi := by intro j hj unfold arcSet at hj rw [mem_filter] at hj exact ⟨hj.2.1, hj.2.2.1⟩ have hmono : ∀ j ∈ arcSet d g c, ∀ j' ∈ arcSet d g c, j < j' → s j < s j' := by intro j hj j' hj' hjj obtain ⟨_, hsj, ej⟩ := hs_spec j hj obtain ⟨_, hsj', ej'⟩ := hs_spec j' hj' have ht : c + j * δ < c + j' * δ := by have : (j : ℝ) < j' := by exact_mod_cast hjj nlinarith have hcos := Real.cos_lt_cos_of_nonneg_of_le_pi (harc j hj).1.le (harc j' hj').2.le ht apply chord_index_lt hg hsj hsj' nlinarith have h4 : ∀ gg kk : ℕ, 1 ≤ gg → 1 ≤ kk → ((arcSet d g c).filter (fun j => j + gg ∈ arcSet d g c ∧ s (j + gg) = s j + kk)).card ≤ 4 := by intro gg kk hgg _ obtain ⟨F, hF⟩ : ∃ F, F = (arcSet d g c).filter (fun j => j + gg ∈ arcSet d g c ∧ s (j + gg) = s j + kk) := ⟨_, rfl⟩ rw [← hF] rcases F.eq_empty_or_nonempty with hF0 | ⟨j₀, hj₀⟩ · rw [hF0, card_empty] omega have hj₀' := hj₀ rw [hF, mem_filter] at hj₀' have hggπ : (gg : ℝ) * δ < Real.pi := by have h1 := (harc j₀ hj₀'.1).1 have h2 := (harc (j₀ + gg) hj₀'.2.1).2 push_cast at h2 nlinarith have hgg0 : 0 < (gg : ℝ) * δ := by have : (1 : ℝ) ≤ gg := by exact_mod_cast hgg positivity have hinj : Set.InjOn (fun j : ℕ => c + j * δ) (F : Set ℕ) := by intro a _ b _ h simp only at h have : (a : ℝ) = b := by have := mul_right_cancel₀ hδ0.ne' (show (a : ℝ) * δ = b * δ by linarith) exact this exact_mod_cast this rw [← card_image_of_injOn hinj] apply steps_le_four (κ := kk * δ) hd hd1 hgg0 hggπ · intro t ht rw [mem_image] at ht obtain ⟨j, hj, rfl⟩ := ht rw [hF, mem_filter] at hj have := harc j hj.1 exact ⟨this.1.le, by linarith [Real.pi_pos]⟩ · intro t ht rw [mem_image] at ht obtain ⟨j, hj, rfl⟩ := ht rw [hF, mem_filter] at hj obtain ⟨_, _, ej⟩ := hs_spec j hj.1 obtain ⟨_, _, ej1⟩ := hs_spec (j + gg) hj.2.1 refine ⟨s j * δ, ej, ?_⟩ have e1 : c + j * δ + gg * δ = c + ((j + gg : ℕ) : ℝ) * δ := by push_cast; ring have e2 : (s j : ℝ) * δ + kk * δ = (s (j + gg) : ℝ) * δ := by rw [hj.2.2] push_cast ring rw [e1, e2] exact ej1 have hsub : arcSet d g c ⊆ range (g / 2 + 1) := by unfold arcSet exact filter_subset _ _ exact arc_count2 (arcSet d g c) s (g / 2 + 1) (g / 2) hsub (fun j hj => (hs_spec j hj).2.1) hmono h4 G₀ K₀ hG hK open Classical in /-- **Lemma 8.2** (INVERSE §7c). Let `N ≥ 3`, `R_N` a regular `N`-gon inscribed in `C(O, ρ)`, `CL` its chord lengths, and `x ∉ C ∪ {O}`. Then `M(x) := #{q ∈ R_N : |xq| ∈ CL} ≤ 10 N^{2/3} + 12`. -/ theorem lemma82 {O w x : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hw : ‖w‖ = 1) {N : ℕ} (hN : 3 ≤ N) (hxC : ‖x - O‖ ≠ ρ) (hxO : x ≠ O) : (((regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N)).card : ℝ) ≤ 10 * (N : ℝ) ^ ((2 : ℝ) / 3) + 12 := by have hd : 0 < ‖x - O‖ / ρ := div_pos (norm_pos_iff.mpr (sub_ne_zero.mpr hxO)) hρ have hd1 : ‖x - O‖ / ρ ≠ 1 := by intro h apply hxC rw [div_eq_one_iff_eq hρ.ne'] at h exact h have hle : ((regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N)).card ≤ ((range N).filter (fun i : ℕ => matchedAng (‖x - O‖ / ρ) N (Complex.arg w - Complex.arg (x - O) + (i : ℝ) * (2 * Real.pi / N)))).card := by have hsub : (regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N) ⊆ ((range N).filter (fun i : ℕ => matchedAng (‖x - O‖ / ρ) N (Complex.arg w - Complex.arg (x - O) + (i : ℝ) * (2 * Real.pi / N)))).image (fun j : ℕ => O + ρ * (w * Complex.exp (2 * Real.pi * Complex.I * (j / N)))) := by intro q hq rw [mem_filter] at hq obtain ⟨hq1, hq2⟩ := hq unfold regPoly at hq1 rw [mem_image] at hq1 obtain ⟨j, hj, rfl⟩ := hq1 rw [mem_image] exact ⟨j, mem_filter.mpr ⟨hj, vertex_matched hρ hw j hq2⟩, rfl⟩ exact le_trans (card_le_card hsub) card_image_le have hsplit := C2_split (d := ‖x - O‖ / ρ) hN (Complex.arg w - Complex.arg (x - O)) have hNR : (3 : ℝ) ≤ N := by exact_mod_cast hN obtain ⟨c, hc⟩ : ∃ c : ℝ, c = (N : ℝ) ^ ((1 : ℝ) / 3) := ⟨_, rfl⟩ have hc0 : 0 < c := by rw [hc]; exact Real.rpow_pos_of_pos (by linarith) _ have hc1 : 1 ≤ c := by rw [hc]; exact Real.one_le_rpow (by linarith) (by norm_num) have hc3 : c ^ 3 = N := by rw [hc, ← Real.rpow_natCast, ← Real.rpow_mul (by linarith)] norm_num have hc2 : c ^ 2 = (N : ℝ) ^ ((2 : ℝ) / 3) := by rw [hc, ← Real.rpow_natCast, ← Real.rpow_mul (by linarith)] norm_num have hU := arcSet_bound2 hd hd1 hN (c := toIcoMod (show (0:ℝ) < 2 * Real.pi / N by have : (0 : ℝ) < N := by exact_mod_cast (show 0 < N by omega) positivity) 0 (Complex.arg w - Complex.arg (x - O))) c c hc0 hc0 have hL := arcSet_bound2 hd hd1 hN (c := toIcoMod (show (0:ℝ) < 2 * Real.pi / N by have : (0 : ℝ) < N := by exact_mod_cast (show 0 < N by omega) positivity) 0 (-(Complex.arg w - Complex.arg (x - O)))) c c hc0 hc0 have hJ : ((N / 2 + 1 : ℕ) : ℝ) ≤ (N : ℝ) / 2 + 1 := by have : ((N / 2 : ℕ) : ℝ) ≤ (N : ℝ) / 2 := Nat.cast_div_le push_cast linarith have hJ' : ((N / 2 : ℕ) : ℝ) + 1 ≤ (N : ℝ) / 2 + 1 := by have : ((N / 2 : ℕ) : ℝ) ≤ (N : ℝ) / 2 := Nat.cast_div_le linarith have hfrac : ((N : ℝ) / 2 + 1) / c ≤ c ^ 2 / 2 + 1 := by rw [div_le_iff₀ hc0] nlinarith have hJc : ((N / 2 + 1 : ℕ) : ℝ) / c ≤ c ^ 2 / 2 + 1 := le_trans (div_le_div_of_nonneg_right hJ hc0.le) hfrac have hJc' : (((N / 2 : ℕ) : ℝ) + 1) / c ≤ c ^ 2 / 2 + 1 := le_trans (div_le_div_of_nonneg_right hJ' hc0.le) hfrac have hsplitR : (((range N).filter (fun i : ℕ => matchedAng (‖x - O‖ / ρ) N (Complex.arg w - Complex.arg (x - O) + (i : ℝ) * (2 * Real.pi / N)))).card : ℝ) ≤ (arcSet (‖x - O‖ / ρ) N (toIcoMod (show (0:ℝ) < 2 * Real.pi / N by have : (0 : ℝ) < N := by exact_mod_cast (show 0 < N by omega) positivity) 0 (Complex.arg w - Complex.arg (x - O)))).card + (arcSet (‖x - O‖ / ρ) N (toIcoMod (show (0:ℝ) < 2 * Real.pi / N by have : (0 : ℝ) < N := by exact_mod_cast (show 0 < N by omega) positivity) 0 (-(Complex.arg w - Complex.arg (x - O))))).card + 2 := by exact_mod_cast hsplit have hleR : (((regPoly O w ρ N).filter (fun q => dist x q ∈ chordLen ρ N)).card : ℝ) ≤ (((range N).filter (fun i : ℕ => matchedAng (‖x - O‖ / ρ) N (Complex.arg w - Complex.arg (x - O) + (i : ℝ) * (2 * Real.pi / N)))).card : ℝ) := by exact_mod_cast hle rw [← hc2] nlinarith end Erdos94ThmA /-! ### INVERSE Prop. 8.1 (big circle + near-full classes ⇒ near-concyclic), part 1: counting tools -/ namespace Erdos94ThmA open Finset theorem sum_cnt_eq (T : Finset (ℂ × ℂ)) (U : Finset ℝ) : ∑ u ∈ U, cnt T u = (T.filter (fun y => dist y.1 y.2 ∈ U)).card := by classical unfold cnt simp_rw [card_filter] rw [sum_comm] refine sum_congr rfl (fun y _ => ?_) rw [sum_ite_eq] theorem sum_cnt_le (T : Finset (ℂ × ℂ)) (U : Finset ℝ) : ∑ u ∈ U, cnt T u ≤ T.card := by rw [sum_cnt_eq] exact card_filter_le _ _ theorem cnt_union_le (S T : Finset (ℂ × ℂ)) (u : ℝ) : cnt (S ∪ T) u ≤ cnt S u + cnt T u := by unfold cnt rw [filter_union] exact card_union_le _ _ theorem cnt_swap (S : Finset (ℂ × ℂ)) (u : ℝ) : cnt (S.image Prod.swap) u = cnt S u := by have h := pe_swap_left S {((0 : ℂ), (u : ℂ))} unfold cnt rw [filter_image, card_image_of_injective _ Prod.swap_injective] congr 1 refine filter_congr (fun x _ => ?_) simp only [Function.comp, Prod.fst_swap, Prod.snd_swap] rw [dist_comm] theorem cnt_split {Q E : Finset ℂ} (hQE : Disjoint Q E) (u : ℝ) : cnt (Q ∪ E).offDiag u ≤ cnt Q.offDiag u + 2 * cnt (E ×ˢ Q) u + cnt E.offDiag u := by rw [offDiag_union hQE] have h1 := cnt_union_le (Q.offDiag ∪ E.offDiag ∪ Q ×ˢ E) (E ×ˢ Q) u have h2 := cnt_union_le (Q.offDiag ∪ E.offDiag) (Q ×ˢ E) u have h3 := cnt_union_le Q.offDiag E.offDiag u have h4 : cnt (Q ×ˢ E) u = cnt (E ×ˢ Q) u := by rw [← image_swap_product Q E, cnt_swap] omega open Classical in /-- A length outside `CL` is carried only by pairs touching `Q ∖ C₀`: `cnt(Q°, u) ≤ 4|Q ∖ C₀|`. -/ theorem cnt_not_CL {Q C₀ : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (CL : Set ℝ) (hCL : ∀ a ∈ C₀, ∀ b ∈ C₀, a ≠ b → dist a b ∈ CL) {u : ℝ} (hu : u ∉ CL) : cnt Q.offDiag u ≤ 4 * (Q.filter (fun q => q ∉ C₀)).card := by have hQ2c : ∀ e ∈ Q.filter (fun q => q ∉ C₀), ∀ v : ℝ, (Q.filter (fun q => dist e q = v)).card ≤ 2 := fun e he v => card_circle_dist_le_two hQ (circle_ne_center hρ (hQ e (mem_filter.mp he).1)) v have hsub : Q.offDiag.filter (fun y => dist y.1 y.2 = u) ⊆ (((Q.filter (fun q => q ∉ C₀)) ×ˢ Q).filter (fun y => dist y.1 y.2 = u)) ∪ ((Q ×ˢ (Q.filter (fun q => q ∉ C₀))).filter (fun y => dist y.1 y.2 = u)) := by intro p hp rw [mem_filter, mem_offDiag] at hp obtain ⟨⟨h1, h2, h12⟩, hd⟩ := hp rw [mem_union, mem_filter, mem_filter, mem_product, mem_product] by_cases hp1 : p.1 ∈ C₀ · by_cases hp2 : p.2 ∈ C₀ · exact absurd (hd ▸ hCL _ hp1 _ hp2 h12) hu · right exact ⟨⟨h1, mem_filter.mpr ⟨h2, hp2⟩⟩, hd⟩ · left exact ⟨⟨mem_filter.mpr ⟨h1, hp1⟩, h2⟩, hd⟩ calc cnt Q.offDiag u ≤ ((((Q.filter (fun q => q ∉ C₀)) ×ˢ Q).filter (fun y => dist y.1 y.2 = u)) ∪ ((Q ×ˢ (Q.filter (fun q => q ∉ C₀))).filter (fun y => dist y.1 y.2 = u))).card := card_le_card hsub _ ≤ cnt ((Q.filter (fun q => q ∉ C₀)) ×ˢ Q) u + cnt (Q ×ˢ (Q.filter (fun q => q ∉ C₀))) u := card_union_le _ _ _ ≤ (Q.filter (fun q => q ∉ C₀)).card * 2 + (Q.filter (fun q => q ∉ C₀)).card * 2 := add_le_add (cnt_product_le _ Q 2 hQ2c u) (cnt_product_le' Q _ 2 hQ2c u) _ = 4 * (Q.filter (fun q => q ∉ C₀)).card := by ring /-- `Σ_{u ∈ U'} cnt(E×Q, u) = Σ_{e ∈ E} #{q ∈ Q : |eq| ∈ U'}`. -/ theorem sum_cnt_EQ (E Q : Finset ℂ) (U : Finset ℝ) : ∑ u ∈ U, cnt (E ×ˢ Q) u = ∑ e ∈ E, (Q.filter (fun q => dist e q ∈ U)).card := by classical rw [sum_cnt_eq, card_filter, sum_product] refine sum_congr rfl (fun e _ => ?_) rw [card_filter] /-- `pe(Q°, Q°) ≥ Σ_{u ∈ U} cnt(Q°, u)²`. -/ theorem pe_ge_sum_sq (T : Finset (ℂ × ℂ)) (U : Finset ℝ) : ∑ u ∈ U, cnt T u * cnt T u ≤ pe T T := by classical rw [pe_eq_sum_fiber T T (U ∪ T.image (fun x => dist x.1 x.2)) (fun x hx => mem_union_right _ (mem_image_of_mem _ hx))] exact sum_le_sum_of_subset_of_nonneg subset_union_left (fun _ _ _ => Nat.zero_le _) end Erdos94ThmA /-! ### INVERSE Prop. 8.1, part 2: near-regular structure (C1′ at t = 0.09, δ = 1/100) and arithmetic -/ namespace Erdos94ThmA open Finset open Classical in /-- **Near-regular structure for Prop. 8.1.** If `E(A) ≥ 0.99K³` (`K = |Q| ≥ 4`), then `C1′` with `t = 0.09` gives `g ≥ 3`, `|w| = 1`, `(8/9)K ≤ g ≤ 1.013K`, at most `0.008K` points of `Q` off `regPoly O w ρ g`, and `O ∈ conv Q`. -/ theorem near_structure3 (Q : Finset ℂ) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (hK : 4 ≤ Q.card) (hE : (1 - 1 / 100) * (Q.card : ℝ) ^ 3 ≤ energy (unitSet Q O ρ)) : ∃ g : ℕ, ∃ w : ℂ, ‖w‖ = 1 ∧ 3 ≤ g ∧ 8 / 9 * (Q.card : ℝ) ≤ g ∧ (g : ℝ) ≤ (1 + 13 / 1000) * Q.card ∧ ((Q.filter (fun q => q ∉ regPoly O w ρ g)).card : ℝ) ≤ 8 / 1000 * Q.card ∧ O ∈ convexHull ℝ (Q : Set ℂ) := by have hA : (unitSet Q O ρ).card = Q.card := card_image_of_injOn (toUnit_unorm_injOn Q O hρ hQ) have hAne : (unitSet Q O ρ).Nonempty := by rw [← card_pos, hA] omega have hKpos : (0 : ℝ) < Q.card := by exact_mod_cast (show 0 < Q.card by omega) obtain ⟨H, D, hmem, h1, h2, -, b, hb, h4, h5⟩ := C1p (unitSet Q O ρ) hAne (9 / 100) (1 / 100) (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by rw [hA]; exact hE) rw [hA] at h1 h2 h4 h5 obtain ⟨N₁, hN₁⟩ : ∃ N₁, N₁ = ((unitSet Q O ρ).filter (fun a => a * b⁻¹ ∈ D)).card := ⟨_, rfl⟩ rw [← hN₁] at h4 h5 have hN₁K : N₁ ≤ Q.card := by rw [hN₁, ← hA] exact card_filter_le _ _ have hN₁K' : (N₁ : ℝ) ≤ Q.card := by exact_mod_cast hN₁K have h1' : (8 / 9) * (Q.card : ℝ) ≤ D.card := by have := h1 norm_num at this linarith have h4' : (8 / 9) * (Q.card : ℝ) ≤ N₁ := by have := h4 norm_num at this linarith have hg2 : (D.card : ℝ) ≤ (1 + 13 / 1000) * Q.card := by have h2' : (D.card : ℝ) * (41 / 50) * Q.card ≤ (41 / 50) * (Q.card : ℝ) ^ 2 + (1 / 100) * (Q.card : ℝ) ^ 2 := by have := h2 norm_num at this ⊢ linarith nlinarith have hg3 : 3 ≤ D.card := by have h4K : (4 : ℝ) ≤ Q.card := by exact_mod_cast hK have : (3 : ℝ) ≤ D.card := by linarith exact_mod_cast this have hm : (Q.card : ℝ) - N₁ ≤ 8 / 1000 * Q.card := by have hm0 : 0 ≤ (Q.card : ℝ) - N₁ := by linarith have hm1 : (Q.card : ℝ) - N₁ ≤ 1 / 9 * Q.card := by linarith have h5' : 2 * ((Q.card : ℝ) - N₁) * Q.card - 6 * ((Q.card : ℝ) - N₁) ^ 2 ≤ (1 / 100) * (Q.card : ℝ) ^ 2 := by have := h5 norm_num at this ⊢ linarith nlinarith [mul_nonneg hm0 (by linarith : (0 : ℝ) ≤ 1 / 9 * Q.card - (Q.card - N₁))] have hQ2 : ((Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card)).card : ℝ) ≤ Q.card - N₁ := by have hsub : Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card) ⊆ Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D) := by intro q hq rw [mem_filter] at hq ⊢ exact ⟨hq.1, fun hd => hq.2 (mem_regPoly_of_mem_coset hρ hQ H D hmem (by omega) b hq.1 hd)⟩ have e1 : (unitSet Q O ρ).filter (fun a => a * b⁻¹ ∈ D) = (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∈ D)).image (fun z => toUnit (unorm O ρ z)) := by unfold unitSet rw [filter_image] have e2 : N₁ = (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∈ D)).card := by rw [hN₁, e1, card_image_of_injOn] exact (toUnit_unorm_injOn Q O hρ hQ).mono (coe_subset.mpr (filter_subset _ _)) have hcard : (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card + N₁ = Q.card := by rw [e2, add_comm] exact card_filter_add_card_filter_not _ have hc1 := card_le_card hsub have hc2 : ((Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card : ℝ) + N₁ = Q.card := by exact_mod_cast hcard have hc3 : ((Q.filter (fun q => q ∉ regPoly O (b : ℂ) ρ D.card)).card : ℝ) ≤ (Q.filter (fun q => toUnit (unorm O ρ q) * b⁻¹ ∉ D)).card := by exact_mod_cast hc1 linarith have hmiss : 3 * (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card < D.card := by have hinj : N₁ ≤ (D.filter (fun d => b * d ∈ unitSet Q O ρ)).card := by rw [hN₁] apply card_le_card_of_injOn (fun a => a * b⁻¹) · intro a ha have ha' := mem_filter.mp ha refine mem_filter.mpr ⟨ha'.2, ?_⟩ show b * (a * b⁻¹) ∈ unitSet Q O ρ rw [mul_comm a b⁻¹, ← mul_assoc, mul_inv_cancel, one_mul] exact ha'.1 · intro a _ a' _ h exact mul_right_cancel h have hsplit := card_filter_add_card_filter_not (s := D) (fun d => b * d ∈ unitSet Q O ρ) have hs : ((D.filter (fun d => b * d ∈ unitSet Q O ρ)).card : ℝ) + (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card = D.card := by exact_mod_cast hsplit have hinjR : (N₁ : ℝ) ≤ (D.filter (fun d => b * d ∈ unitSet Q O ρ)).card := by exact_mod_cast hinj have : (3 : ℝ) * (D.filter (fun d => ¬ (b * d ∈ unitSet Q O ρ))).card < D.card := by linarith exact_mod_cast this have hO := center_mem_hull Q O hρ hQ H D hmem hg3 b hmiss exact ⟨D.card, (b : ℂ), unitSet_norm hρ hQ hb, hg3, h1', hg2, by linarith, hO⟩ /-- `10 g^{2/3} + 12 ≤ 10g/96 + 12` once `g ≥ 96³`. -/ theorem rpow23_le {g : ℝ} (hg : 884736 ≤ g) : 10 * g ^ ((2 : ℝ) / 3) + 12 ≤ 10 * (g / 96) + 12 := by have hg0 : 0 < g := by linarith obtain ⟨c, hc⟩ : ∃ c : ℝ, c = g ^ ((1 : ℝ) / 3) := ⟨_, rfl⟩ have hc0 : 0 < c := by rw [hc]; exact Real.rpow_pos_of_pos hg0 _ have hc3 : c ^ 3 = g := by rw [hc, ← Real.rpow_natCast, ← Real.rpow_mul hg0.le] norm_num have hc2 : c ^ 2 = g ^ ((2 : ℝ) / 3) := by rw [hc, ← Real.rpow_natCast, ← Real.rpow_mul hg0.le] norm_num have hc96 : 96 ≤ c := by by_contra hcon have hlt : c < 96 := not_le.mp hcon have := pow_lt_pow_left₀ hlt hc0.le (by norm_num : (3 : ℕ) ≠ 0) nlinarith rw [← hc2] have : c ^ 2 * 96 ≤ g := by nlinarith have : c ^ 2 ≤ g / 96 := by rw [le_div_iff₀ (by norm_num)]; linarith linarith /-- Step (1) of Prop. 8.1: the classes of `U` force `E(A) ≥ 0.99 K³`. -/ theorem p81_energy_arith {n K k ε η u₀ X Y Eg : ℝ} (hn : 1000000 ≤ n) (hε0 : 0 ≤ ε) (hε : ε ≤ 1 / 10000) (hη : η ≤ 1 / 10000) (hK0 : 0 ≤ K) (hK : K ≤ n) (hk0 : 0 ≤ k) (hk : k ≤ η * n) (hu₀ : (1 / 2 - ε) * n ≤ u₀) (hX : 2 * u₀ * (1 - ε) * n - 3 * k * n ≤ X) (hCS : X ^ 2 ≤ u₀ * Y) (hY : Y + 2 * K ^ 2 ≤ 2 * Eg) : (1 - 1 / 100) * K ^ 3 ≤ Eg := by have hnpos : 0 < n := by linarith have hu₀pos : 0 < u₀ := by nlinarith have hL0 : 0 ≤ 2 * u₀ * (1 - ε) * n - 3 * k * n := by have e1 : 4999 / 10000 * n ≤ u₀ := by nlinarith [mul_nonneg (by linarith : (0 : ℝ) ≤ 1 / 10000 - ε) hnpos.le] have e2 : (4999 / 10000 * n) * (9999 / 10000) ≤ u₀ * (1 - ε) := mul_le_mul e1 (by linarith) (by norm_num) (by linarith) have hk' : k ≤ 1 / 10000 * n := le_trans hk (mul_le_mul_of_nonneg_right hη hnpos.le) have e3 : k * n ≤ 1 / 10000 * n * n := mul_le_mul_of_nonneg_right hk' hnpos.le have e4 := mul_le_mul_of_nonneg_right e2 hnpos.le nlinarith have hX2 : (2 * u₀ * (1 - ε) * n - 3 * k * n) ^ 2 ≤ X ^ 2 := pow_le_pow_left₀ hL0 hX 2 have hY1 : u₀ * (4 * u₀ * (1 - ε) ^ 2 * n ^ 2 - 12 * (1 - ε) * k * n ^ 2) ≤ u₀ * Y := by nlinarith [sq_nonneg (3 * k * n)] have hY2 : 4 * u₀ * (1 - ε) ^ 2 * n ^ 2 - 12 * (1 - ε) * k * n ^ 2 ≤ Y := le_of_mul_le_mul_left hY1 hu₀pos have h1 : 4 * ((1 / 2 - ε) * n) * (1 - ε) ^ 2 * n ^ 2 ≤ 4 * u₀ * (1 - ε) ^ 2 * n ^ 2 := by have := mul_le_mul_of_nonneg_right hu₀ (by positivity : (0 : ℝ) ≤ 4 * (1 - ε) ^ 2 * n ^ 2) nlinarith have h2 : 12 * (1 - ε) * k * n ^ 2 ≤ 12 * (η * n) * n ^ 2 := by have : (1 - ε) * k ≤ η * n := by nlinarith nlinarith [sq_nonneg n] have h3 : K ^ 3 ≤ n ^ 3 := pow_le_pow_left₀ hK0 hK 3 have h4 : (1 - ε) ^ 2 ≥ 9998 / 10000 := by nlinarith have h5 : (1 / 2 - ε) * (1 - ε) ^ 2 ≥ 4999 / 10000 * (9998 / 10000) := by have : (1 / 2 - ε) ≥ 4999 / 10000 := by linarith nlinarith have h6 : 4 * ((1 / 2 - ε) * n) * (1 - ε) ^ 2 * n ^ 2 ≥ 4 * (4999 / 10000 * (9998 / 10000)) * n ^ 3 := by have : 4 * ((1 / 2 - ε) * n) * (1 - ε) ^ 2 * n ^ 2 = 4 * ((1 / 2 - ε) * (1 - ε) ^ 2) * n ^ 3 := by ring rw [this] nlinarith [pow_pos hnpos 3] have h7 : 12 * (η * n) * n ^ 2 ≤ 12 * (1 / 10000) * n ^ 3 := by have : 12 * (η * n) * n ^ 2 = 12 * η * n ^ 3 := by ring rw [this] nlinarith [pow_pos hnpos 3] nlinarith [sq_nonneg K] /-- Step (3) of Prop. 8.1, final arithmetic: `k ≤ 2εn + 3`. -/ theorem p81_final_arith {n K k ε η u₀ v w m Mx : ℝ} (hn : 1000000 ≤ n) (hnK : n = K + k) (hε0 : 0 ≤ ε) (hε : ε ≤ 1 / 10000) (hη : η ≤ 1 / 10000) (hk0 : 0 ≤ k) (hk : k ≤ η * n) (hu₀ : (1 / 2 - ε) * n ≤ u₀) (hw : u₀ ≤ w + v) (hv0 : 0 ≤ v) (hv : v * (2 * (1 - ε) * n - 4 * m) ≤ 3 * k * n) (hm0 : 0 ≤ m) (hm : m ≤ 8 / 1000 * K) (hMx : Mx ≤ 12 / 100 * n) (hmain : w * (2 * (1 - ε) * n - 2 * K) ≤ 2 * (k * (Mx + m) + K) + k ^ 2) : k ≤ 2 * ε * n + 3 := by have hnpos : 0 < n := by linarith have hK : K ≤ n := by linarith by_contra hcon have hgt : 2 * ε * n + 3 < k := not_le.mp hcon have s1 : 196 / 100 * n ≤ 2 * (1 - ε) * n - 4 * m := by nlinarith have s2 : v * (196 / 100 * n) ≤ 3 * k * n := le_trans (mul_le_mul_of_nonneg_left s1 hv0) hv have s2' : v * (196 / 100) ≤ 3 * k := by have : v * (196 / 100) * n ≤ 3 * k * n := by linarith exact le_of_mul_le_mul_right this hnpos have s3 : 49975 / 100000 * n ≤ w := by nlinarith have hb : 0 ≤ 2 * (1 - ε) * n - 2 * K := by nlinarith have s5 : 49975 / 100000 * n * (2 * (1 - ε) * n - 2 * K) ≤ w * (2 * (1 - ε) * n - 2 * K) := mul_le_mul_of_nonneg_right s3 hb have s6 : k * Mx ≤ k * (12 / 100 * n) := mul_le_mul_of_nonneg_left hMx hk0 have s7 : k * m ≤ k * (8 / 1000 * n) := mul_le_mul_of_nonneg_left (by linarith) hk0 have s8 : k ^ 2 ≤ k * (1 / 10000 * n) := by have : k ≤ 1 / 10000 * n := by nlinarith nlinarith have s9 : (2 * ε * n + 3) * n < k * n := mul_lt_mul_of_pos_right hgt hnpos have s10 : 0 ≤ ε * n * n := by positivity nlinarith end Erdos94ThmA /-! ### INVERSE Prop. 8.1, part 3: assembly -/ namespace Erdos94ThmA open Finset theorem cnt_offDiag_eq_two_mult (P : Finset ℂ) (u : ℝ) : (cnt P.offDiag u : ℝ) = 2 * (distanceMultiplicity P u : ℝ) := by rw [Erdos94Infra.mult_cast] unfold cnt ring open Classical in /-- **Proposition 8.1** (INVERSE §7c) in `ℂ`, with the explicit threshold `n₀ = 10⁶`: let `U` be at least `(1/2 − ε)n` distances with `f(u) ≥ (1 − ε)n`, and let a circle `C(O, ρ)` contain all but `k ≤ ηn` points of `P`. If `ε ≤ 10⁻⁴` and `η ≤ 10⁻⁴`, then `k ≤ 2εn + 3`. -/ theorem prop81_C (P : Finset ℂ) (hn : 1000000 ≤ P.card) {ε η : ℝ} (hε0 : 0 ≤ ε) (hε : ε ≤ 1 / 10000) (hη : η ≤ 1 / 10000) (U : Finset ℝ) (hU : (1 / 2 - ε) * P.card ≤ U.card) (hf : ∀ u ∈ U, (1 - ε) * P.card ≤ distanceMultiplicity P u) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hk : ((P.filter (fun z => ‖z - O‖ ≠ ρ)).card : ℝ) ≤ η * P.card) : ((P.filter (fun z => ‖z - O‖ ≠ ρ)).card : ℝ) ≤ 2 * ε * P.card + 3 := by obtain ⟨Q, hQdef⟩ : ∃ Q, Q = P.filter (fun z => ‖z - O‖ = ρ) := ⟨_, rfl⟩ obtain ⟨E, hEdef⟩ : ∃ E, E = P.filter (fun z => ‖z - O‖ ≠ ρ) := ⟨_, rfl⟩ rw [← hEdef] at hk ⊢ have hQ : ∀ q ∈ Q, ‖q - O‖ = ρ := fun q hq => by rw [hQdef] at hq exact (mem_filter.mp hq).2 have hEc : ∀ e ∈ E, ‖e - O‖ ≠ ρ := fun e he => by rw [hEdef] at he exact (mem_filter.mp he).2 have hPQE : P = Q ∪ E := by ext z rw [mem_union, hQdef, hEdef, mem_filter, mem_filter] by_cases h : ‖z - O‖ = ρ · exact ⟨fun hz => Or.inl ⟨hz, h⟩, fun hz => hz.elim (fun h' => h'.1) (fun h' => h'.1)⟩ · exact ⟨fun hz => Or.inr ⟨hz, h⟩, fun hz => hz.elim (fun h' => h'.1) (fun h' => h'.1)⟩ have hdisj : Disjoint Q E := by rw [disjoint_left] intro z hzQ hzE exact hEc z hzE (hQ z hzQ) have hcard : P.card = Q.card + E.card := by rw [hPQE, card_union_of_disjoint hdisj] have hnR : (1000000 : ℝ) ≤ P.card := by exact_mod_cast hn have hcardR : (P.card : ℝ) = Q.card + E.card := by exact_mod_cast hcard have hnpos : (0 : ℝ) < P.card := by linarith by_cases hkε : (E.card : ℝ) ≤ ε * P.card · nlinarith have hk0 : (0 : ℝ) ≤ E.card := Nat.cast_nonneg _ have hK0 : (0 : ℝ) ≤ Q.card := Nat.cast_nonneg _ have hKn : (Q.card : ℝ) ≤ P.card := by linarith have hkn' : (E.card : ℝ) ≤ 1 / 10000 * P.card := le_trans hk (mul_le_mul_of_nonneg_right hη hnpos.le) have hK4 : 4 ≤ Q.card := by have : (4 : ℝ) ≤ Q.card := by linarith exact_mod_cast this have hfU : ∀ u ∈ U, 2 * (1 - ε) * P.card ≤ (cnt P.offDiag u : ℝ) := fun u hu => by rw [cnt_offDiag_eq_two_mult] linarith [hf u hu] have hsplit : ∀ u, (cnt P.offDiag u : ℝ) ≤ cnt Q.offDiag u + (2 * (cnt (E ×ˢ Q) u : ℝ) + cnt E.offDiag u) := fun u => by have := cnt_split hdisj u rw [← hPQE] at this have h' : (cnt P.offDiag u : ℝ) ≤ cnt Q.offDiag u + 2 * cnt (E ×ˢ Q) u + cnt E.offDiag u := by exact_mod_cast this linarith have hBmass : ∀ S : Finset ℝ, (∑ u ∈ S, (2 * (cnt (E ×ˢ Q) u : ℝ) + cnt E.offDiag u)) ≤ 3 * E.card * P.card := by intro S have h1 := sum_cnt_le (E ×ˢ Q) S have h2 := sum_cnt_le E.offDiag S rw [card_product] at h1 rw [offDiag_card] at h2 have h1R : (∑ u ∈ S, (cnt (E ×ˢ Q) u : ℝ)) ≤ E.card * Q.card := by exact_mod_cast h1 have h2R : (∑ u ∈ S, (cnt E.offDiag u : ℝ)) ≤ E.card * E.card := by have : ∑ u ∈ S, cnt E.offDiag u ≤ E.card * E.card := le_trans h2 (Nat.sub_le _ _) exact_mod_cast this rw [sum_add_distrib, ← mul_sum] nlinarith -- (1) the angle set of `Q` has energy ≥ 0.99 K³ have hX : 2 * U.card * (1 - ε) * P.card - 3 * E.card * P.card ≤ (∑ u ∈ U, (cnt Q.offDiag u : ℝ)) := by have h1 : ∑ _u ∈ U, (2 * (1 - ε) * P.card : ℝ) ≤ ∑ u ∈ U, (cnt P.offDiag u : ℝ) := sum_le_sum hfU have h2 : ∑ u ∈ U, (cnt P.offDiag u : ℝ) ≤ ∑ u ∈ U, ((cnt Q.offDiag u : ℝ) + (2 * (cnt (E ×ˢ Q) u : ℝ) + cnt E.offDiag u)) := sum_le_sum (fun u _ => hsplit u) rw [sum_add_distrib] at h2 have h3 := hBmass U rw [sum_const, nsmul_eq_mul] at h1 nlinarith have hCS : (∑ u ∈ U, (cnt Q.offDiag u : ℝ)) ^ 2 ≤ U.card * (pe Q.offDiag Q.offDiag : ℝ) := by have h1 := sq_sum_le_card_mul_sum_sq (s := U) (f := fun u => (cnt Q.offDiag u : ℝ)) have h2 : ∑ u ∈ U, (cnt Q.offDiag u : ℝ) ^ 2 ≤ (pe Q.offDiag Q.offDiag : ℝ) := by have h0 := pe_ge_sum_sq Q.offDiag U have h' : ((∑ u ∈ U, cnt Q.offDiag u * cnt Q.offDiag u : ℕ) : ℝ) ≤ (pe Q.offDiag Q.offDiag : ℝ) := by exact_mod_cast h0 push_cast at h' simpa [sq] using h' calc _ ≤ U.card * ∑ u ∈ U, (cnt Q.offDiag u : ℝ) ^ 2 := h1 _ ≤ _ := mul_le_mul_of_nonneg_left h2 (Nat.cast_nonneg _) have hR3 : pe Q.offDiag Q.offDiag + 2 * (Q.card * Q.card) ≤ 2 * energy (unitSet Q O ρ) := pairEnergy_circle_le Q O hρ hQ have hR3' : (pe Q.offDiag Q.offDiag : ℝ) + 2 * (Q.card : ℝ) ^ 2 ≤ 2 * (energy (unitSet Q O ρ) : ℝ) := by have : (pe Q.offDiag Q.offDiag : ℝ) + 2 * ((Q.card : ℝ) * Q.card) ≤ 2 * (energy (unitSet Q O ρ) : ℝ) := by exact_mod_cast hR3 nlinarith have hE99 := p81_energy_arith hnR hε0 hε hη hK0 hKn hk0 hk hU hX hCS hR3' -- (2) a regular `g`-gon `C₀` carries all but `m ≤ 0.008K` points of `Q` obtain ⟨g, w, hw, hg3, hg1, hg, hQ2, -⟩ := near_structure3 Q O hρ hQ hK4 hE99 have hCL : ∀ a ∈ regPoly O w ρ g, ∀ b ∈ regPoly O w ρ g, a ≠ b → dist a b ∈ chordLen ρ g := fun a ha b hb hab => regPoly_dist_mem hρ hw ha hb hab have hm0 : (0 : ℝ) ≤ (Q.filter (fun q => q ∉ regPoly O w ρ g)).card := Nat.cast_nonneg _ -- classes of `U` outside `CL` have hv : ((U.filter (fun u => u ∉ chordLen ρ g)).card : ℝ) * (2 * (1 - ε) * P.card - 4 * (Q.filter (fun q => q ∉ regPoly O w ρ g)).card) ≤ 3 * E.card * P.card := by have h1 : ∀ u ∈ U.filter (fun u => u ∉ chordLen ρ g), 2 * (1 - ε) * P.card - 4 * ((Q.filter (fun q => q ∉ regPoly O w ρ g)).card : ℝ) ≤ 2 * (cnt (E ×ˢ Q) u : ℝ) + cnt E.offDiag u := by intro u hu rw [mem_filter] at hu have hc := cnt_not_CL hρ hQ (chordLen ρ g) hCL hu.2 have hcR : (cnt Q.offDiag u : ℝ) ≤ 4 * ((Q.filter (fun q => q ∉ regPoly O w ρ g)).card : ℝ) := by exact_mod_cast hc linarith [hfU u hu.1, hsplit u] have h2 := sum_le_sum h1 rw [sum_const, nsmul_eq_mul] at h2 linarith [hBmass (U.filter (fun u => u ∉ chordLen ρ g))] have hwU : (U.card : ℝ) ≤ (U.filter (fun u => u ∈ chordLen ρ g)).card + (U.filter (fun u => u ∉ chordLen ρ g)).card := by have := card_filter_add_card_filter_not (s := U) (fun u => u ∈ chordLen ρ g) have h' : ((U.filter (fun u => u ∈ chordLen ρ g)).card : ℝ) + (U.filter (fun u => u ∉ chordLen ρ g)).card = U.card := by exact_mod_cast this linarith -- (3) the classes of `U ∩ CL` need many pairs through `E` have hg884 : (884736 : ℝ) ≤ g := by linarith have hMx : 10 * ((g : ℝ) / 96) + 12 ≤ 12 / 100 * P.card := by linarith have hEe : ∀ e ∈ E, ((Q.filter (fun q => dist e q ∈ U.filter (fun u => u ∈ chordLen ρ g))).card : ℝ) ≤ (10 * ((g : ℝ) / 96) + 12 + (Q.filter (fun q => q ∉ regPoly O w ρ g)).card) + (if e = O then (Q.card : ℝ) else 0) := by intro e he by_cases heO : e = O · rw [if_pos heO] have : ((Q.filter (fun q => dist e q ∈ U.filter (fun u => u ∈ chordLen ρ g))).card : ℝ) ≤ Q.card := by exact_mod_cast card_filter_le _ _ have hpos : (0 : ℝ) ≤ 10 * ((g : ℝ) / 96) + 12 := by positivity linarith · rw [if_neg heO] have hsub : Q.filter (fun q => dist e q ∈ U.filter (fun u => u ∈ chordLen ρ g)) ⊆ (regPoly O w ρ g).filter (fun q => dist e q ∈ chordLen ρ g) ∪ Q.filter (fun q => q ∉ regPoly O w ρ g) := by intro q hq rw [mem_filter, mem_filter] at hq rw [mem_union, mem_filter, mem_filter] by_cases hqC : q ∈ regPoly O w ρ g · exact Or.inl ⟨hqC, hq.2.2⟩ · exact Or.inr ⟨hq.1, hqC⟩ have h1 := le_trans (card_le_card hsub) (card_union_le _ _) have h1R : ((Q.filter (fun q => dist e q ∈ U.filter (fun u => u ∈ chordLen ρ g))).card : ℝ) ≤ ((regPoly O w ρ g).filter (fun q => dist e q ∈ chordLen ρ g)).card + (Q.filter (fun q => q ∉ regPoly O w ρ g)).card := by exact_mod_cast h1 have h82 := lemma82 hρ hw hg3 (hEc e he) heO have hr := rpow23_le hg884 linarith have hmain : ((U.filter (fun u => u ∈ chordLen ρ g)).card : ℝ) * (2 * (1 - ε) * P.card - 2 * Q.card) ≤ 2 * (E.card * ((10 * ((g : ℝ) / 96) + 12) + (Q.filter (fun q => q ∉ regPoly O w ρ g)).card) + Q.card) + (E.card : ℝ) ^ 2 := by have h1 : ∀ u ∈ U.filter (fun u => u ∈ chordLen ρ g), 2 * (1 - ε) * P.card - 2 * (Q.card : ℝ) ≤ 2 * (cnt (E ×ˢ Q) u : ℝ) + cnt E.offDiag u := by intro u hu rw [mem_filter] at hu have hc := cnt_offDiag_circle_le hρ hQ u have hcR : (cnt Q.offDiag u : ℝ) ≤ Q.card * 2 := by exact_mod_cast hc linarith [hfU u hu.1, hsplit u] have h2 := sum_le_sum h1 rw [sum_const, nsmul_eq_mul, sum_add_distrib, ← mul_sum] at h2 have h3 := sum_cnt_EQ E Q (U.filter (fun u => u ∈ chordLen ρ g)) have h3R : (∑ u ∈ U.filter (fun u => u ∈ chordLen ρ g), (cnt (E ×ˢ Q) u : ℝ)) = ∑ e ∈ E, ((Q.filter (fun q => dist e q ∈ U.filter (fun u => u ∈ chordLen ρ g))).card : ℝ) := by exact_mod_cast h3 have h4 : ∑ e ∈ E, ((Q.filter (fun q => dist e q ∈ U.filter (fun u => u ∈ chordLen ρ g))).card : ℝ) ≤ ∑ e ∈ E, ((10 * ((g : ℝ) / 96) + 12 + (Q.filter (fun q => q ∉ regPoly O w ρ g)).card) + (if e = O then (Q.card : ℝ) else 0)) := sum_le_sum hEe rw [sum_add_distrib, sum_const, nsmul_eq_mul, sum_ite_eq'] at h4 have h5 : (if O ∈ E then (Q.card : ℝ) else 0) ≤ Q.card := by split_ifs · exact le_rfl · exact hK0 have h6 := sum_cnt_le E.offDiag (U.filter (fun u => u ∈ chordLen ρ g)) rw [offDiag_card] at h6 have h6R : (∑ u ∈ U.filter (fun u => u ∈ chordLen ρ g), (cnt E.offDiag u : ℝ)) ≤ (E.card : ℝ) * E.card := by have : ∑ u ∈ U.filter (fun u => u ∈ chordLen ρ g), cnt E.offDiag u ≤ E.card * E.card := le_trans h6 (Nat.sub_le _ _) exact_mod_cast this nlinarith exact p81_final_arith hnR hcardR hε0 hε hη hk0 hk hU hwU (Nat.cast_nonneg _) hv hm0 hQ2 hMx hmain /-- `distanceMultiplicity` is invariant under the isometry `ℝ² → ℂ`. -/ theorem mult_image_C (P : Finset (EuclideanSpace ℝ (Fin 2))) (u : ℝ) : distanceMultiplicity (P.image Complex.orthonormalBasisOneI.repr.symm) u = distanceMultiplicity P u := by classical unfold distanceMultiplicity rw [Erdos94Infra.card_filter_dist_image P Complex.orthonormalBasisOneI.repr.symm.injective u, card_filter] congr 1 refine sum_congr rfl (fun x _ => ?_) rw [Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] open Classical in /-- **Proposition 8.1** (INVERSE §7c; plane form, explicit `n₀ = 10⁶`). Let `U` be at least `(1/2 − ε)n` distances with `f(u) ≥ (1 − ε)n`, and suppose a circle `C(O, ρ)` contains `K = n − k` points of `P` with `k ≤ ηn`. If `ε ≤ 10⁻⁴`, `η ≤ 10⁻⁴` and `n ≥ 10⁶`, then `k ≤ 2εn + 3`. -/ theorem prop81 {P : Finset (EuclideanSpace ℝ (Fin 2))} (hn : 1000000 ≤ P.card) {ε η : ℝ} (hε0 : 0 ≤ ε) (hε : ε ≤ 1 / 10000) (hη : η ≤ 1 / 10000) (U : Finset ℝ) (hU : (1 / 2 - ε) * P.card ≤ U.card) (hf : ∀ u ∈ U, (1 - ε) * P.card ≤ distanceMultiplicity P u) {O : EuclideanSpace ℝ (Fin 2)} {ρ : ℝ} (hρ : 0 < ρ) (hk : ((P.filter (fun p => dist p O ≠ ρ)).card : ℝ) ≤ η * P.card) : ((P.filter (fun p => dist p O ≠ ρ)).card : ℝ) ≤ 2 * ε * P.card + 3 := by have hcard : (P.image Complex.orthonormalBasisOneI.repr.symm).card = P.card := card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective have hfilt : ((P.image Complex.orthonormalBasisOneI.repr.symm).filter (fun z => ‖z - Complex.orthonormalBasisOneI.repr.symm O‖ ≠ ρ)).card = (P.filter (fun p => dist p O ≠ ρ)).card := by rw [filter_image, card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective] congr 1 refine filter_congr (fun p _ => ?_) rw [← dist_eq_norm, Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] have h := prop81_C (P.image Complex.orthonormalBasisOneI.repr.symm) (by rw [hcard]; exact hn) hε0 hε hη U (by rw [hcard]; exact hU) (fun u hu => by rw [hcard, mult_image_C]; exact hf u hu) (Complex.orthonormalBasisOneI.repr.symm O) hρ (by rw [hfilt, hcard]; exact hk) rw [hfilt, hcard] at h exact h open Classical in /-- **Endgame of INVERSE Thm. 8.3 / Thm. 9.2 (Prop. 8.1, then Prop. C).** If `P` is ConvexIndep, `n ≥ 2·10⁶`, at least `(1/2 − ε)n` distances have `f(u) ≥ (1 − ε)n` with `ε ≤ 9·10⁻⁶`, and some circle contains all but at most `10⁻⁴n` points of `P`, then `S(P) ≤ R(n)`. -/ theorem endgame81C {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) (hn : 2000000 ≤ P.card) {ε : ℝ} (hε0 : 0 ≤ ε) (hε : ε ≤ 9 / 1000000) (U : Finset ℝ) (hU : (1 / 2 - ε) * P.card ≤ U.card) (hf : ∀ u ∈ U, (1 - ε) * P.card ≤ distanceMultiplicity P u) {O : EuclideanSpace ℝ (Fin 2)} {ρ : ℝ} (hρ : 0 < ρ) (hk : ((P.filter (fun p => dist p O ≠ ρ)).card : ℝ) ≤ 1 / 10000 * P.card) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue P.card := by have h81 := prop81 (by omega) hε0 (by linarith) (le_refl _) U hU hf hρ hk apply propC hP (by omega) (O := O) hρ have hnR : (2000000 : ℝ) ≤ P.card := by exact_mod_cast hn have := mul_le_mul_of_nonneg_right hε (by linarith : (0 : ℝ) ≤ P.card) nlinarith end Erdos94ThmA /-! ### INVERSE Prop. 9.1 (a): the excess over two sightings is small when few vertices see a distance three times. `m_u(c) = #{y ≠ c : |cy| = u}`, `E(u) := Σ_c (m_u(c) − 2)⁺ = 2e_u`, `Z = {c : ∃ u, m_u(c) ≥ 3}`. -/ namespace Erdos94ThmA open Finset /-- `m_u(c)`. -/ noncomputable def mU (P : Finset ℂ) (c : ℂ) (u : ℝ) : ℕ := ((P.erase c).filter (fun y => dist c y = u)).card /-- `E(u) = Σ_c (m_u(c) − 2)⁺ = 2 e_u`. -/ noncomputable def eU (P : Finset ℂ) (u : ℝ) : ℕ := ∑ c ∈ P, (mU P c u - 2) open Classical in /-- The vertices seeing some distance at least three times. -/ noncomputable def triplePts (P : Finset ℂ) : Finset ℂ := P.filter (fun c => ∃ u : ℝ, 3 ≤ mU P c u) theorem cnt_row_eq (P : Finset ℂ) (c : ℂ) (u : ℝ) : cnt (row P c) u = mU P c u := by classical unfold cnt row mU rw [filter_image, card_image_of_injective _ (fun a b h => congrArg Prod.snd h)] theorem eU_le (P : Finset ℂ) (u : ℝ) : eU P u ≤ cnt ((triplePts P).biUnion (row P)) u := by classical have hdisj : ((triplePts P : Finset ℂ) : Set ℂ).PairwiseDisjoint (row P) := (row_disjoint P).subset (coe_subset.mpr (filter_subset _ _)) have hcnt : cnt ((triplePts P).biUnion (row P)) u = ∑ c ∈ triplePts P, mU P c u := by unfold cnt rw [filter_biUnion, card_biUnion] · refine sum_congr rfl (fun c _ => ?_) rw [← cnt_row_eq] rfl · intro a ha b hb hab exact Finset.disjoint_filter_filter (hdisj ha hb hab) rw [hcnt] unfold eU rw [← sum_filter_add_sum_filter_not P (fun c => ∃ u : ℝ, 3 ≤ mU P c u)] have h0 : ∑ c ∈ P.filter (fun c => ¬ ∃ u : ℝ, 3 ≤ mU P c u), (mU P c u - 2) = 0 := by apply sum_eq_zero intro c hc rw [mem_filter] at hc have : mU P c u ≤ 2 := by by_contra h exact hc.2 ⟨u, by omega⟩ omega rw [h0, add_zero] exact sum_le_sum (fun c _ => Nat.sub_le _ _) /-- `Σ_u m_u(c) = n − 1` over the distance set. -/ theorem sum_mU (P : Finset ℂ) {c : ℂ} (hc : c ∈ P) : ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), mU P c u = P.card - 1 := by classical unfold mU rw [← card_erase_of_mem hc] symm apply card_eq_sum_card_fiberwise intro y hy have hy' := mem_erase.mp hy exact mem_image.mpr ⟨(c, y), mem_offDiag.mpr ⟨hc, hy'.2, fun h => hy'.1 h.symm⟩, rfl⟩ /-- **Prop. 9.1 (a), first half** (ordered form): `Σ_u E(u) ≤ |Z|(n − 1)`, i.e. `Σ_u e_u ≤ |Z| n/2`. -/ theorem p91a_sum (P : Finset ℂ) : ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), eU P u ≤ (triplePts P).card * (P.card - 1) := by classical have h1 : ∀ u, eU P u ≤ ∑ c ∈ triplePts P, mU P c u := by intro u have := eU_le P u have hdisj : ((triplePts P : Finset ℂ) : Set ℂ).PairwiseDisjoint (row P) := (row_disjoint P).subset (coe_subset.mpr (filter_subset _ _)) have hcnt : cnt ((triplePts P).biUnion (row P)) u = ∑ c ∈ triplePts P, mU P c u := by unfold cnt rw [filter_biUnion, card_biUnion] · refine sum_congr rfl (fun c _ => ?_) rw [← cnt_row_eq] rfl · intro a ha b hb hab exact Finset.disjoint_filter_filter (hdisj ha hb hab) omega calc ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), eU P u ≤ ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), ∑ c ∈ triplePts P, mU P c u := sum_le_sum (fun u _ => h1 u) _ = ∑ c ∈ triplePts P, ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), mU P c u := sum_comm _ = ∑ _c ∈ triplePts P, (P.card - 1) := sum_congr rfl (fun c hc => sum_mU P (mem_filter.mp hc).1) _ = (triplePts P).card * (P.card - 1) := by rw [sum_const, smul_eq_mul] /-- Cauchy–Schwarz over the rows of `Z`. -/ theorem pe_rows_le (P Z : Finset ℂ) (hZ : Z ⊆ P) : pe (Z.biUnion (row P)) (Z.biUnion (row P)) ≤ Z.card * ∑ a ∈ Z, pe (row P a) (row P a) := by have hdisj : ((Z : Finset ℂ) : Set ℂ).PairwiseDisjoint (row P) := (row_disjoint P).subset (coe_subset.mpr hZ) have hL : ∀ T, pe (Z.biUnion (row P)) T = ∑ a ∈ Z, pe (row P a) T := by intro T unfold pe rw [sum_biUnion hdisj] have h1 : ∀ a ∈ Z, pe (row P a) (Z.biUnion (row P)) = ∑ a' ∈ Z, pe (row P a) (row P a') := by intro a _ rw [pe_comm, hL] exact sum_congr rfl (fun a' _ => pe_comm _ _) have h2 : 2 * pe (Z.biUnion (row P)) (Z.biUnion (row P)) ≤ 2 * Z.card * ∑ a ∈ Z, pe (row P a) (row P a) := by rw [hL, sum_congr rfl h1, mul_sum] calc ∑ a ∈ Z, 2 * ∑ a' ∈ Z, pe (row P a) (row P a') = ∑ a ∈ Z, ∑ a' ∈ Z, 2 * pe (row P a) (row P a') := by refine sum_congr rfl (fun a _ => ?_) rw [mul_sum] _ ≤ ∑ a ∈ Z, ∑ a' ∈ Z, (pe (row P a) (row P a) + pe (row P a') (row P a')) := sum_le_sum (fun a _ => sum_le_sum (fun a' _ => two_pe_le _ _)) _ = 2 * Z.card * ∑ a ∈ Z, pe (row P a) (row P a) := sum_sum_add_eq Z (fun a => pe (row P a) (row P a)) have h3 : 2 * pe (Z.biUnion (row P)) (Z.biUnion (row P)) ≤ 2 * (Z.card * ∑ a ∈ Z, pe (row P a) (row P a)) := by rw [← mul_assoc] exact h2 omega /-- **Prop. 9.1 (a), second half** (ordered form): `Σ_u E(u)² ≤ |Z|(|Z|(n − 1) + 2n(n − 1))`, i.e. `4 Σ_u e_u² ≤ (ν² + 2ν) n³` when `|Z| ≤ νn`. -/ theorem p91a_sq {P : Finset ℂ} (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) : ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), eU P u * eU P u ≤ (triplePts P).card * ((triplePts P).card * (P.card - 1) + 2 * (P.card * P.card - P.card)) := by classical have hZ : triplePts P ⊆ P := filter_subset _ _ have h1 : ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), eU P u * eU P u ≤ pe ((triplePts P).biUnion (row P)) ((triplePts P).biUnion (row P)) := by calc _ ≤ ∑ u ∈ P.offDiag.image (fun x => dist x.1 x.2), cnt ((triplePts P).biUnion (row P)) u * cnt ((triplePts P).biUnion (row P)) u := sum_le_sum (fun u _ => Nat.mul_le_mul (eU_le P u) (eU_le P u)) _ ≤ _ := pe_ge_sum_sq _ _ have h2 := pe_rows_le P (triplePts P) hZ have h3 : ∑ a ∈ triplePts P, pe (row P a) (row P a) ≤ ∑ a ∈ triplePts P, ((P.card - 1) + (P.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card) := sum_le_sum (fun a ha => pe_row_self_le P a (hZ ha)) rw [sum_add_distrib, sum_const, smul_eq_mul] at h3 have h4 : ∑ a ∈ triplePts P, (P.offDiag.filter (fun p => a ≠ p.1 ∧ a ≠ p.2 ∧ dist a p.1 = dist a p.2)).card ≤ 2 * (P.card * P.card - P.card) := le_trans (sum_le_sum_of_subset_of_nonneg hZ (fun _ _ _ => Nat.zero_le _)) (sum_T_le hP) calc _ ≤ pe ((triplePts P).biUnion (row P)) ((triplePts P).biUnion (row P)) := h1 _ ≤ (triplePts P).card * ∑ a ∈ triplePts P, pe (row P a) (row P a) := h2 _ ≤ (triplePts P).card * ((triplePts P).card * (P.card - 1) + 2 * (P.card * P.card - P.card)) := Nat.mul_le_mul le_rfl (by omega) end Erdos94ThmA /-! ### INVERSE Prop. 9.1 (c): if `S ≥ (1/2 − δ)n³` and few vertices see a distance three times, then at least `(1/2 − ν/2 − η − 1/n)n` distances have `f(u) ≥ (1 − η)n`, `η = (δ + 1.01√ν)^{1/2}` -/ namespace Erdos94ThmA open Finset /-- ℓ² triangle inequality for `F = (F − E) + E`. -/ theorem l2_triangle (D : Finset ℝ) (F E : ℝ → ℝ) : ∑ u ∈ D, F u ^ 2 ≤ (Real.sqrt (∑ u ∈ D, (F u - E u) ^ 2) + Real.sqrt (∑ u ∈ D, E u ^ 2)) ^ 2 := by have hCS := Real.sum_mul_le_sqrt_mul_sqrt D (fun u => F u - E u) E have hexp : ∑ u ∈ D, F u ^ 2 = ∑ u ∈ D, (F u - E u) ^ 2 + 2 * ∑ u ∈ D, (F u - E u) * E u + ∑ u ∈ D, E u ^ 2 := by rw [mul_sum, ← sum_add_distrib, ← sum_add_distrib] refine sum_congr rfl (fun u _ => ?_) ring have hA20 : 0 ≤ ∑ u ∈ D, (F u - E u) ^ 2 := sum_nonneg (fun _ _ => sq_nonneg _) have hE20 : 0 ≤ ∑ u ∈ D, E u ^ 2 := sum_nonneg (fun _ _ => sq_nonneg _) have hsA := Real.sq_sqrt hA20 have hsE := Real.sq_sqrt hE20 rw [hexp, add_sq, hsA, hsE] linarith /-- The square-root arithmetic of Prop. 9.1 (c): `Σ b² ≥ (1/2 − δ − 1.01√ν) n³` in ordered units. -/ theorem p91c_sqrt {A2 E2 F2 n ν δ s : ℝ} (hn : 0 < n) (hν0 : 0 ≤ ν) (hν : ν ≤ 1 / 1000) (hs0 : 0 ≤ s) (hs2 : s ^ 2 = ν) (hδ0 : 0 ≤ δ) (hδs : δ + 1.01 * s < 1 / 4) (hA20 : 0 ≤ A2) (hE20 : 0 ≤ E2) (hF2le : F2 ≤ (Real.sqrt A2 + Real.sqrt E2) ^ 2) (hEsq : E2 ≤ (2 * ν + ν ^ 2) * n ^ 3) (hFsq : (2 - 4 * δ) * n ^ 3 ≤ F2) : (2 - 4 * (δ + 1.01 * s)) * n ^ 3 ≤ A2 := by have hn3 : 0 < n ^ 3 := by positivity have hab : Real.sqrt F2 ≤ Real.sqrt A2 + Real.sqrt E2 := by have := Real.sqrt_le_sqrt hF2le rwa [Real.sqrt_sq (by positivity)] at this have hX : Real.sqrt ((2 - 4 * δ) * n ^ 3) ≤ Real.sqrt F2 := Real.sqrt_le_sqrt hFsq have hb : Real.sqrt E2 ≤ Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) := Real.sqrt_le_sqrt hEsq have hcmp : 2 * ν + ν ^ 2 ≤ 2 - 4 * δ := by nlinarith have hX0B0 : Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) ≤ Real.sqrt ((2 - 4 * δ) * n ^ 3) := Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_right hcmp hn3.le) have hdiff : 0 ≤ Real.sqrt ((2 - 4 * δ) * n ^ 3) - Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) := by linarith have hA : Real.sqrt ((2 - 4 * δ) * n ^ 3) - Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) ≤ Real.sqrt A2 := by linarith have hA2low : (Real.sqrt ((2 - 4 * δ) * n ^ 3) - Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3)) ^ 2 ≤ A2 := by have := pow_le_pow_left₀ hdiff hA 2 rwa [Real.sq_sqrt hA20] at this have h24 : 0 ≤ 2 - 4 * δ := by linarith have hXsq : Real.sqrt ((2 - 4 * δ) * n ^ 3) ^ 2 = (2 - 4 * δ) * n ^ 3 := Real.sq_sqrt (mul_nonneg h24 hn3.le) have hprod : Real.sqrt ((2 - 4 * δ) * n ^ 3) * Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) ≤ 2.02 * s * n ^ 3 := by rw [← Real.sqrt_mul (mul_nonneg h24 hn3.le)] have h1 : (2 - 4 * δ) * n ^ 3 * ((2 * ν + ν ^ 2) * n ^ 3) ≤ (2.02 * s * n ^ 3) ^ 2 := by have e : (2.02 * s * n ^ 3) ^ 2 = 4.0804 * ν * (n ^ 3) ^ 2 := by rw [← hs2]; ring rw [e] have h2 : (2 - 4 * δ) * (2 * ν + ν ^ 2) ≤ 4.0804 * ν := by nlinarith have h3 : (2 - 4 * δ) * n ^ 3 * ((2 * ν + ν ^ 2) * n ^ 3) = (2 - 4 * δ) * (2 * ν + ν ^ 2) * (n ^ 3) ^ 2 := by ring rw [h3] exact mul_le_mul_of_nonneg_right h2 (sq_nonneg _) have := Real.sqrt_le_sqrt h1 rwa [Real.sqrt_sq (by positivity)] at this have hY0 : 0 ≤ Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) ^ 2 := sq_nonneg _ have hexp : (Real.sqrt ((2 - 4 * δ) * n ^ 3) - Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3)) ^ 2 = Real.sqrt ((2 - 4 * δ) * n ^ 3) ^ 2 + Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) ^ 2 - 2 * (Real.sqrt ((2 - 4 * δ) * n ^ 3) * Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3)) := by ring rw [hexp, hXsq] at hA2low linarith /-- Markov over the classes: the counting half of Prop. 9.1 (c). -/ theorem p91c_count (D : Finset ℝ) (F E : ℝ → ℝ) {n ν η : ℝ} (hn : 1 ≤ n) (hη0 : 0 < η) (hE0 : ∀ u ∈ D, 0 ≤ E u) (hB0 : ∀ u ∈ D, E u ≤ F u) (hB2 : ∀ u ∈ D, F u - E u ≤ 2 * n) (hFsum : ∑ u ∈ D, F u = n * (n - 1)) (hEsum : ∑ u ∈ D, E u ≤ ν * n * n) (hA : (2 - 4 * η ^ 2) * n ^ 3 ≤ ∑ u ∈ D, (F u - E u) ^ 2) : (1 / 2 - ν / 2 - η - 1 / n) * n ≤ ((D.filter (fun u => 2 * (1 - η) * n ≤ F u)).card : ℝ) := by classical have hnpos : 0 < n := by linarith have hBsum : ∑ u ∈ D, (F u - E u) ≤ n * (n - 1) := by rw [sum_sub_distrib, hFsum] have : 0 ≤ ∑ u ∈ D, E u := sum_nonneg hE0 linarith have hBsum' : n * (n - 1) - ν * n * n ≤ ∑ u ∈ D, (F u - E u) := by rw [sum_sub_distrib, hFsum] linarith have hQ : ∑ u ∈ D, (F u - E u) * (2 * n - (F u - E u)) ≤ 4 * η ^ 2 * n ^ 3 := by have e : ∑ u ∈ D, (F u - E u) * (2 * n - (F u - E u)) = 2 * n * ∑ u ∈ D, (F u - E u) - ∑ u ∈ D, (F u - E u) ^ 2 := by rw [mul_sum, ← sum_sub_distrib] refine sum_congr rfl (fun u _ => ?_) ring rw [e] have h1 := mul_le_mul_of_nonneg_left hBsum (by linarith : (0 : ℝ) ≤ 2 * n) have h2 : 2 * n * (n * (n - 1)) ≤ 2 * n ^ 3 := by nlinarith linarith obtain ⟨L, hL⟩ : ∃ L, L = D.filter (fun u => F u - E u < 2 * (1 - η) * n) := ⟨_, rfl⟩ obtain ⟨H, hH⟩ : ∃ H, H = D.filter (fun u => ¬ (F u - E u < 2 * (1 - η) * n)) := ⟨_, rfl⟩ have hLsum : (∑ u ∈ L, (F u - E u)) * (2 * η * n) ≤ 4 * η ^ 2 * n ^ 3 := by have h1 : ∀ u ∈ L, (F u - E u) * (2 * η * n) ≤ (F u - E u) * (2 * n - (F u - E u)) := by intro u hu rw [hL, mem_filter] at hu have hB := hB0 u hu.1 exact mul_le_mul_of_nonneg_left (by linarith [hu.2]) (by linarith) have h2 : ∑ u ∈ L, (F u - E u) * (2 * n - (F u - E u)) ≤ ∑ u ∈ D, (F u - E u) * (2 * n - (F u - E u)) := by apply sum_le_sum_of_subset_of_nonneg (by rw [hL]; exact filter_subset _ _) intro u hu _ have hB := hB0 u hu have hB2' := hB2 u hu exact mul_nonneg (by linarith) (by linarith) rw [sum_mul] linarith [sum_le_sum h1] have hLsum' : ∑ u ∈ L, (F u - E u) ≤ 2 * η * n ^ 2 := by have hpos : 0 < 2 * η * n := by positivity have e : 4 * η ^ 2 * n ^ 3 = (2 * η * n ^ 2) * (2 * η * n) := by ring rw [e] at hLsum exact le_of_mul_le_mul_right hLsum hpos have hsplit : ∑ u ∈ D, (F u - E u) = ∑ u ∈ L, (F u - E u) + ∑ u ∈ H, (F u - E u) := by rw [hL, hH, sum_filter_add_sum_filter_not] have hHsum : ∑ u ∈ H, (F u - E u) ≤ (H.card : ℝ) * (2 * n) := by have : ∑ u ∈ H, (F u - E u) ≤ ∑ _u ∈ H, (2 * n) := sum_le_sum (fun u hu => hB2 u (by rw [hH] at hu; exact (mem_filter.mp hu).1)) rw [sum_const, nsmul_eq_mul] at this exact this have hHsub : H ⊆ D.filter (fun u => 2 * (1 - η) * n ≤ F u) := by intro u hu rw [hH, mem_filter] at hu rw [mem_filter] have := hE0 u hu.1 exact ⟨hu.1, by linarith [not_lt.mp hu.2]⟩ have hHc : (H.card : ℝ) ≤ ((D.filter (fun u => 2 * (1 - η) * n ≤ F u)).card : ℝ) := by exact_mod_cast card_le_card hHsub have hfin : n * (n - 1) - ν * n * n - 2 * η * n ^ 2 ≤ (H.card : ℝ) * (2 * n) := by linarith have e : (1 / 2 - ν / 2 - η - 1 / n) * n * (2 * n) = n * (n - 1) - ν * n * n - 2 * η * n ^ 2 - n := by field_simp ring have hgoal : (1 / 2 - ν / 2 - η - 1 / n) * n * (2 * n) ≤ (H.card : ℝ) * (2 * n) := by rw [e] linarith have := le_of_mul_le_mul_right hgoal (by positivity : (0 : ℝ) < 2 * n) linarith /-- The real-number core of Prop. 9.1 (c), ordered units: `F = 2f`, `E = 2e`, `F − E = 2b`. -/ theorem p91c_core (D : Finset ℝ) (F E : ℝ → ℝ) {n ν δ : ℝ} (hn : 1 ≤ n) (hν0 : 0 ≤ ν) (hν : ν ≤ 1 / 1000) (hδ0 : 0 < δ) (hE0 : ∀ u ∈ D, 0 ≤ E u) (hB0 : ∀ u ∈ D, E u ≤ F u) (hB2 : ∀ u ∈ D, F u - E u ≤ 2 * n) (hFsum : ∑ u ∈ D, F u = n * (n - 1)) (hEsum : ∑ u ∈ D, E u ≤ ν * n * n) (hEsq : ∑ u ∈ D, E u ^ 2 ≤ (2 * ν + ν ^ 2) * n ^ 3) (hFsq : (2 - 4 * δ) * n ^ 3 ≤ ∑ u ∈ D, F u ^ 2) : (1 / 2 - ν / 2 - Real.sqrt (δ + 1.01 * Real.sqrt ν) - 1 / n) * n ≤ ((D.filter (fun u => 2 * (1 - Real.sqrt (δ + 1.01 * Real.sqrt ν)) * n ≤ F u)).card : ℝ) := by obtain ⟨s, hsdef⟩ : ∃ s, s = Real.sqrt ν := ⟨_, rfl⟩ obtain ⟨η, hηdef⟩ : ∃ η, η = Real.sqrt (δ + 1.01 * s) := ⟨_, rfl⟩ rw [← hsdef, ← hηdef] have hs0 : 0 ≤ s := by rw [hsdef]; exact Real.sqrt_nonneg _ have hs2 : s ^ 2 = ν := by rw [hsdef]; exact Real.sq_sqrt hν0 have hη2 : η ^ 2 = δ + 1.01 * s := by rw [hηdef]; exact Real.sq_sqrt (by positivity) have hηpos : 0 < η := by rw [hηdef] exact Real.sqrt_pos.mpr (by positivity) have hnpos : 0 < n := by linarith have hcard0 : (0 : ℝ) ≤ ((D.filter (fun u => 2 * (1 - η) * n ≤ F u)).card : ℝ) := Nat.cast_nonneg _ by_cases hηbig : 1 / 2 ≤ η · have h1 : 0 < 1 / n := by positivity have : (1 / 2 - ν / 2 - η - 1 / n) * n ≤ 0 := by apply mul_nonpos_of_nonpos_of_nonneg _ hnpos.le linarith linarith have hηlt : η < 1 / 2 := not_le.mp hηbig have hδs : δ + 1.01 * s < 1 / 4 := by nlinarith have hA := p91c_sqrt hnpos hν0 hν hs0 hs2 hδ0.le hδs (sum_nonneg (fun _ _ => sq_nonneg _)) (sum_nonneg (fun _ _ => sq_nonneg _)) (l2_triangle D F E) hEsq hFsq rw [← hη2] at hA exact p91c_count D F E hn hηpos hE0 hB0 hB2 hFsum hEsum hA theorem cnt_eq_sum_mU (P : Finset ℂ) (u : ℝ) : cnt P.offDiag u = ∑ c ∈ P, mU P c u := by classical unfold cnt rw [offDiag_eq_biUnion_row, filter_biUnion, card_biUnion] · refine sum_congr rfl (fun c _ => ?_) rw [← cnt_row_eq] rfl · intro a ha b hb hab exact Finset.disjoint_filter_filter (row_disjoint P ha hb hab) open Classical in /-- **Proposition 9.1 (c)** (INVERSE §9) for a convex-independent `P ⊂ ℂ`: if at most `νn` vertices see some distance three times (`ν ≤ 10⁻³`), `δ > 0` and `S(P) ≥ (1/2 − δ)n³`, then with `η = (δ + 1.01√ν)^{1/2}` at least `(1/2 − ν/2 − η − 1/n)n` distances have `f(u) ≥ (1 − η)n`. -/ theorem p91c {P : Finset ℂ} (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) (hn : 1 ≤ P.card) {ν δ : ℝ} (hν0 : 0 ≤ ν) (hν : ν ≤ 1 / 1000) (hδ0 : 0 < δ) (hZ : ((triplePts P).card : ℝ) ≤ ν * P.card) (hS : (1 / 2 - δ) * (P.card : ℝ) ^ 3 ≤ ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2) : (1 / 2 - ν / 2 - Real.sqrt (δ + 1.01 * Real.sqrt ν) - 1 / P.card) * P.card ≤ (((distanceSet P).filter (fun u => (1 - Real.sqrt (δ + 1.01 * Real.sqrt ν)) * P.card ≤ distanceMultiplicity P u)).card : ℝ) := by have hnR : (1 : ℝ) ≤ P.card := by exact_mod_cast hn have hD : distanceSet P = P.offDiag.image (fun x => dist x.1 x.2) := rfl have hE0 : ∀ u ∈ distanceSet P, (0 : ℝ) ≤ (eU P u : ℝ) := fun _ _ => Nat.cast_nonneg _ have hsubZ : (triplePts P).biUnion (row P) ⊆ P.offDiag := by intro x hx rw [mem_biUnion] at hx obtain ⟨c, hc, hx⟩ := hx unfold row at hx rw [mem_image] at hx obtain ⟨b, hb, rfl⟩ := hx rw [mem_erase] at hb exact mem_offDiag.mpr ⟨(mem_filter.mp hc).1, hb.2, fun h => hb.1 h.symm⟩ have hB0 : ∀ u ∈ distanceSet P, (eU P u : ℝ) ≤ (cnt P.offDiag u : ℝ) := fun u _ => by exact_mod_cast le_trans (eU_le P u) (cnt_mono hsubZ u) have hB2 : ∀ u ∈ distanceSet P, (cnt P.offDiag u : ℝ) - eU P u ≤ 2 * P.card := fun u _ => by have h : cnt P.offDiag u ≤ eU P u + 2 * P.card := by rw [cnt_eq_sum_mU] unfold eU calc ∑ c ∈ P, mU P c u ≤ ∑ c ∈ P, ((mU P c u - 2) + 2) := sum_le_sum (fun c _ => by omega) _ = ∑ c ∈ P, (mU P c u - 2) + 2 * P.card := by rw [sum_add_distrib, sum_const, smul_eq_mul, mul_comm] have hR : (cnt P.offDiag u : ℝ) ≤ eU P u + 2 * P.card := by exact_mod_cast h linarith have hFsum : ∑ u ∈ distanceSet P, (cnt P.offDiag u : ℝ) = P.card * (P.card - 1) := by have h := sum_cnt_eq P.offDiag (distanceSet P) have hall : P.offDiag.filter (fun y => dist y.1 y.2 ∈ distanceSet P) = P.offDiag := filter_true_of_mem (fun x hx => by rw [hD]; exact mem_image_of_mem _ hx) rw [hall, offDiag_card] at h have h' : ((∑ u ∈ distanceSet P, cnt P.offDiag u : ℕ) : ℝ) = ((P.card * P.card - P.card : ℕ) : ℝ) := by rw [h] rw [Nat.cast_sub (Nat.le_mul_self _)] at h' push_cast at h' rw [h'] ring have hEsum : ∑ u ∈ distanceSet P, (eU P u : ℝ) ≤ ν * P.card * P.card := by have h := p91a_sum P rw [← hD] at h have hR : ∑ u ∈ distanceSet P, (eU P u : ℝ) ≤ ((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) := by exact_mod_cast h have h1 : ((P.card - 1 : ℕ) : ℝ) ≤ P.card := by have : P.card - 1 ≤ P.card := Nat.sub_le _ _ exact_mod_cast this have h2 := mul_le_mul hZ h1 (Nat.cast_nonneg _) (by positivity) linarith have hEsq : ∑ u ∈ distanceSet P, (eU P u : ℝ) ^ 2 ≤ (2 * ν + ν ^ 2) * (P.card : ℝ) ^ 3 := by have h := p91a_sq hP rw [← hD] at h have hR : ∑ u ∈ distanceSet P, (eU P u : ℝ) * (eU P u : ℝ) ≤ ((triplePts P).card : ℝ) * (((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) + 2 * ((P.card * P.card - P.card : ℕ) : ℝ)) := by exact_mod_cast h have h1 : ((P.card - 1 : ℕ) : ℝ) ≤ P.card := by have : P.card - 1 ≤ P.card := Nat.sub_le _ _ exact_mod_cast this have h1' : ((P.card * P.card - P.card : ℕ) : ℝ) ≤ (P.card : ℝ) * P.card := by have : P.card * P.card - P.card ≤ P.card * P.card := Nat.sub_le _ _ exact_mod_cast this have hZ0 : (0 : ℝ) ≤ (triplePts P).card := Nat.cast_nonneg _ have hn0 : (0 : ℝ) ≤ P.card := by linarith have h3 : ((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) ≤ ν * P.card * P.card := mul_le_mul hZ h1 (Nat.cast_nonneg _) (by positivity) have h4 : ((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) + 2 * ((P.card * P.card - P.card : ℕ) : ℝ) ≤ ν * P.card * P.card + 2 * ((P.card : ℝ) * P.card) := by linarith have h5 := mul_le_mul hZ h4 (by positivity) (by positivity) simp only [sq] at hR ⊢ nlinarith have hFsq : (2 - 4 * δ) * (P.card : ℝ) ^ 3 ≤ ∑ u ∈ distanceSet P, (cnt P.offDiag u : ℝ) ^ 2 := by have h1 := Erdos94Infra.sum_sq_mult_eq P have h2 : (Erdos94Infra.pairEnergy P : ℝ) = (pe P.offDiag P.offDiag : ℝ) := rfl have h3 := pe_eq_sum_fiber P.offDiag P.offDiag (distanceSet P) (fun x hx => by rw [hD]; exact mem_image_of_mem _ hx) have h3R : (pe P.offDiag P.offDiag : ℝ) = ∑ u ∈ distanceSet P, (cnt P.offDiag u : ℝ) ^ 2 := by rw [h3] push_cast simp only [sq] linarith have hcore := p91c_core (distanceSet P) (fun u => (cnt P.offDiag u : ℝ)) (fun u => (eU P u : ℝ)) hnR hν0 hν hδ0 hE0 hB0 hB2 hFsum hEsum hEsq hFsq have hfilt : (distanceSet P).filter (fun u => 2 * (1 - Real.sqrt (δ + 1.01 * Real.sqrt ν)) * P.card ≤ (cnt P.offDiag u : ℝ)) = (distanceSet P).filter (fun u => (1 - Real.sqrt (δ + 1.01 * Real.sqrt ν)) * P.card ≤ distanceMultiplicity P u) := by refine filter_congr (fun u _ => ?_) rw [cnt_offDiag_eq_two_mult] constructor <;> intro h <;> linarith rw [hfilt] at hcore exact hcore /-- `(√(2n³) + √((2ν + ν²) n³))² = 2 (1 + √(ν + ν²/2))² n³`. -/ theorem p91b_alg {n ν : ℝ} (hn : 0 ≤ n) (hν0 : 0 ≤ ν) : (Real.sqrt (2 * n ^ 3) + Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3)) ^ 2 = 2 * (1 + Real.sqrt (ν + ν ^ 2 / 2)) ^ 2 * n ^ 3 := by have hn3 : 0 ≤ n ^ 3 := by positivity have e1 : Real.sqrt ((2 * ν + ν ^ 2) * n ^ 3) = Real.sqrt 2 * Real.sqrt (ν + ν ^ 2 / 2) * Real.sqrt (n ^ 3) := by rw [show (2 * ν + ν ^ 2) * n ^ 3 = 2 * (ν + ν ^ 2 / 2) * n ^ 3 by ring, Real.sqrt_mul (by positivity), Real.sqrt_mul (by norm_num)] have e2 : Real.sqrt (2 * n ^ 3) = Real.sqrt 2 * Real.sqrt (n ^ 3) := Real.sqrt_mul (by norm_num) _ rw [e1, e2] have h2 : Real.sqrt 2 ^ 2 = 2 := Real.sq_sqrt (by norm_num) have h3 : Real.sqrt (n ^ 3) ^ 2 = n ^ 3 := Real.sq_sqrt hn3 have : (Real.sqrt 2 * Real.sqrt (n ^ 3) + Real.sqrt 2 * Real.sqrt (ν + ν ^ 2 / 2) * Real.sqrt (n ^ 3)) ^ 2 = Real.sqrt 2 ^ 2 * (1 + Real.sqrt (ν + ν ^ 2 / 2)) ^ 2 * Real.sqrt (n ^ 3) ^ 2 := by ring rw [this, h2, h3] open Classical in /-- **Proposition 9.1 (b)** (INVERSE §9) for a convex-independent `P ⊂ ℂ`: if at most `νn` vertices see some distance three times, then `S(P) ≤ ½ (1 + √(ν + ν²/2))² n³` (no error term needed). -/ theorem p91b {P : Finset ℂ} (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) (hn : 1 ≤ P.card) {ν : ℝ} (hν0 : 0 ≤ ν) (hZ : ((triplePts P).card : ℝ) ≤ ν * P.card) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ 1 / 2 * (1 + Real.sqrt (ν + ν ^ 2 / 2)) ^ 2 * (P.card : ℝ) ^ 3 := by have hnR : (1 : ℝ) ≤ P.card := by exact_mod_cast hn have hD : distanceSet P = P.offDiag.image (fun x => dist x.1 x.2) := rfl have hE0 : ∀ u ∈ distanceSet P, (0 : ℝ) ≤ (eU P u : ℝ) := fun _ _ => Nat.cast_nonneg _ have hsubZ : (triplePts P).biUnion (row P) ⊆ P.offDiag := by intro x hx rw [mem_biUnion] at hx obtain ⟨c, hc, hx⟩ := hx unfold row at hx rw [mem_image] at hx obtain ⟨b, hb, rfl⟩ := hx rw [mem_erase] at hb exact mem_offDiag.mpr ⟨(mem_filter.mp hc).1, hb.2, fun h => hb.1 h.symm⟩ have hB0 : ∀ u ∈ distanceSet P, (eU P u : ℝ) ≤ (cnt P.offDiag u : ℝ) := fun u _ => by exact_mod_cast le_trans (eU_le P u) (cnt_mono hsubZ u) have hB2 : ∀ u ∈ distanceSet P, (cnt P.offDiag u : ℝ) - eU P u ≤ 2 * P.card := fun u _ => by have h : cnt P.offDiag u ≤ eU P u + 2 * P.card := by rw [cnt_eq_sum_mU] unfold eU calc ∑ c ∈ P, mU P c u ≤ ∑ c ∈ P, ((mU P c u - 2) + 2) := sum_le_sum (fun c _ => by omega) _ = ∑ c ∈ P, (mU P c u - 2) + 2 * P.card := by rw [sum_add_distrib, sum_const, smul_eq_mul, mul_comm] have hR : (cnt P.offDiag u : ℝ) ≤ eU P u + 2 * P.card := by exact_mod_cast h linarith have hFsum : ∑ u ∈ distanceSet P, (cnt P.offDiag u : ℝ) = P.card * (P.card - 1) := by have h := sum_cnt_eq P.offDiag (distanceSet P) have hall : P.offDiag.filter (fun y => dist y.1 y.2 ∈ distanceSet P) = P.offDiag := filter_true_of_mem (fun x hx => by rw [hD]; exact mem_image_of_mem _ hx) rw [hall, offDiag_card] at h have h' : ((∑ u ∈ distanceSet P, cnt P.offDiag u : ℕ) : ℝ) = ((P.card * P.card - P.card : ℕ) : ℝ) := by rw [h] rw [Nat.cast_sub (Nat.le_mul_self _)] at h' push_cast at h' rw [h'] ring have hEsum : ∑ u ∈ distanceSet P, (eU P u : ℝ) ≤ ν * P.card * P.card := by have h := p91a_sum P rw [← hD] at h have hR : ∑ u ∈ distanceSet P, (eU P u : ℝ) ≤ ((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) := by exact_mod_cast h have h1 : ((P.card - 1 : ℕ) : ℝ) ≤ P.card := by have : P.card - 1 ≤ P.card := Nat.sub_le _ _ exact_mod_cast this have h2 := mul_le_mul hZ h1 (Nat.cast_nonneg _) (by positivity) linarith have hEsq : ∑ u ∈ distanceSet P, (eU P u : ℝ) ^ 2 ≤ (2 * ν + ν ^ 2) * (P.card : ℝ) ^ 3 := by have h := p91a_sq hP rw [← hD] at h have hR : ∑ u ∈ distanceSet P, (eU P u : ℝ) * (eU P u : ℝ) ≤ ((triplePts P).card : ℝ) * (((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) + 2 * ((P.card * P.card - P.card : ℕ) : ℝ)) := by exact_mod_cast h have h1 : ((P.card - 1 : ℕ) : ℝ) ≤ P.card := by have : P.card - 1 ≤ P.card := Nat.sub_le _ _ exact_mod_cast this have h1' : ((P.card * P.card - P.card : ℕ) : ℝ) ≤ (P.card : ℝ) * P.card := by have : P.card * P.card - P.card ≤ P.card * P.card := Nat.sub_le _ _ exact_mod_cast this have hZ0 : (0 : ℝ) ≤ (triplePts P).card := Nat.cast_nonneg _ have hn0 : (0 : ℝ) ≤ P.card := by linarith have h3 : ((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) ≤ ν * P.card * P.card := mul_le_mul hZ h1 (Nat.cast_nonneg _) (by positivity) have h4 : ((triplePts P).card : ℝ) * ((P.card - 1 : ℕ) : ℝ) + 2 * ((P.card * P.card - P.card : ℕ) : ℝ) ≤ ν * P.card * P.card + 2 * ((P.card : ℝ) * P.card) := by linarith have h5 := mul_le_mul hZ h4 (by positivity) (by positivity) simp only [sq] at hR ⊢ nlinarith have hS : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 = (∑ u ∈ distanceSet P, (cnt P.offDiag u : ℝ) ^ 2) / 4 := by rw [sum_div] refine sum_congr rfl (fun u _ => ?_) rw [cnt_offDiag_eq_two_mult] ring have hn0 : (0 : ℝ) ≤ P.card := by linarith have htri := l2_triangle (distanceSet P) (fun u => (cnt P.offDiag u : ℝ)) (fun u => (eU P u : ℝ)) have hA2 : ∑ u ∈ distanceSet P, ((cnt P.offDiag u : ℝ) - eU P u) ^ 2 ≤ 2 * (P.card : ℝ) ^ 3 := by have h1 : ∀ u ∈ distanceSet P, ((cnt P.offDiag u : ℝ) - eU P u) ^ 2 ≤ 2 * P.card * ((cnt P.offDiag u : ℝ) - eU P u) := by intro u hu have a := hB0 u hu have b := hB2 u hu rw [sq] exact mul_le_mul_of_nonneg_right b (by linarith) have h2 := sum_le_sum h1 rw [← mul_sum] at h2 have h3 : ∑ u ∈ distanceSet P, ((cnt P.offDiag u : ℝ) - eU P u) ≤ P.card * (P.card - 1) := by rw [sum_sub_distrib, hFsum] have : (0 : ℝ) ≤ ∑ u ∈ distanceSet P, (eU P u : ℝ) := sum_nonneg (fun _ _ => Nat.cast_nonneg _) linarith have h4 := mul_le_mul_of_nonneg_left h3 (by linarith : (0 : ℝ) ≤ 2 * P.card) nlinarith have hsA : Real.sqrt (∑ u ∈ distanceSet P, ((cnt P.offDiag u : ℝ) - eU P u) ^ 2) ≤ Real.sqrt (2 * (P.card : ℝ) ^ 3) := Real.sqrt_le_sqrt hA2 have hsE : Real.sqrt (∑ u ∈ distanceSet P, (eU P u : ℝ) ^ 2) ≤ Real.sqrt ((2 * ν + ν ^ 2) * (P.card : ℝ) ^ 3) := Real.sqrt_le_sqrt hEsq have hsum := add_le_add hsA hsE have hsq := pow_le_pow_left₀ (by positivity) hsum 2 rw [p91b_alg hn0 hν0] at hsq rw [hS] have := le_trans htri hsq linarith end Erdos94ThmA /-! ### INVERSE Theorem 9.2 modulo Theorem 6.11: Prop. 9.1 (c) + [a big circle] + Prop. 8.1 + Prop. C -/ namespace Erdos94ThmA open Finset open Classical in /-- **Theorem 9.2, conditional on Theorem 6.11's conclusion** (in `ℂ`). Let `P` be convex independent with `n ≥ 10¹¹`, at most `νn` vertices seeing some distance three times (`ν ≤ 10⁻²²`), and a circle `C(O, ρ)` containing all but at most `10⁻⁴n` points of `P` (this is what INVERSE's Theorem 6.11 supplies). Then `S(P) ≤ R(n)`. -/ theorem thm92_mod611_C (P : Finset ℂ) (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) (hn : 100000000000 ≤ P.card) {ν : ℝ} (hν0 : 0 ≤ ν) (hν : ν ≤ 1 / 10 ^ 22) (hZ : ((triplePts P).card : ℝ) ≤ ν * P.card) (O : ℂ) {ρ : ℝ} (hρ : 0 < ρ) (hcirc : ((P.filter (fun z => ‖z - O‖ ≠ ρ)).card : ℝ) ≤ 1 / 10000 * P.card) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue P.card := by have hnR : (100000000000 : ℝ) ≤ P.card := by exact_mod_cast hn have hnpos : (0 : ℝ) < P.card := by linarith have hS4 : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 = (pe P.offDiag P.offDiag : ℝ) / 4 := by rw [Erdos94Infra.sum_sq_mult_eq] rfl by_contra hcon have hS : Erdos94Infra.ngonValue P.card < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 := not_le.mp hcon have hRn := ngonValue_ge P.card -- δ = 1/n have hδ0 : (0 : ℝ) < 1 / P.card := by positivity have hSδ : (1 / 2 - 1 / (P.card : ℝ)) * (P.card : ℝ) ^ 3 ≤ ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 := by have e : (1 / 2 - 1 / (P.card : ℝ)) * (P.card : ℝ) ^ 3 = (P.card : ℝ) ^ 3 / 2 - (P.card : ℝ) ^ 2 := by field_simp rw [e] nlinarith have h91 := p91c hP (by omega) hν0 (by linarith [show (1 : ℝ) / 10 ^ 22 ≤ 1 / 1000 by norm_num]) hδ0 hZ hSδ -- bounds on η = √(1/n + 1.01√ν) have hsν : Real.sqrt ν ≤ 1 / 10 ^ 11 := by have := Real.sqrt_le_sqrt (show ν ≤ (1 / 10 ^ 11) ^ 2 by norm_num; linarith) rwa [Real.sqrt_sq (by norm_num)] at this have hinv : 1 / (P.card : ℝ) ≤ 1 / 100000000000 := one_div_le_one_div_of_le (by norm_num) hnR have hη : Real.sqrt (1 / (P.card : ℝ) + 1.01 * Real.sqrt ν) ≤ 45 / 10000000 := by have h1 : 1 / (P.card : ℝ) + 1.01 * Real.sqrt ν ≤ (45 / 10000000) ^ 2 := by have : (1 : ℝ) / 10 ^ 11 = 1 / 100000000000 := by norm_num nlinarith [Real.sqrt_nonneg ν] have := Real.sqrt_le_sqrt h1 rwa [Real.sqrt_sq (by norm_num)] at this have hη0 : 0 ≤ Real.sqrt (1 / (P.card : ℝ) + 1.01 * Real.sqrt ν) := Real.sqrt_nonneg _ -- ε := 9·10⁻⁶ works for Prop. 8.1 obtain ⟨U, hU⟩ : ∃ U, U = (distanceSet P).filter (fun u => (1 - Real.sqrt (1 / (P.card : ℝ) + 1.01 * Real.sqrt ν)) * P.card ≤ distanceMultiplicity P u) := ⟨_, rfl⟩ rw [← hU] at h91 have hUc : (1 / 2 - 9 / 1000000) * (P.card : ℝ) ≤ U.card := by have : (1 / 2 - 9 / 1000000) * (P.card : ℝ) ≤ (1 / 2 - ν / 2 - Real.sqrt (1 / (P.card : ℝ) + 1.01 * Real.sqrt ν) - 1 / P.card) * P.card := by apply mul_le_mul_of_nonneg_right _ hnpos.le have hν2 : ν / 2 ≤ 1 / 10000000 := by have : (1 : ℝ) / 10 ^ 22 ≤ 2 / 10000000 := by norm_num linarith linarith linarith have hUf : ∀ u ∈ U, (1 - 9 / 1000000) * (P.card : ℝ) ≤ distanceMultiplicity P u := by intro u hu rw [hU, mem_filter] at hu have : (1 - 9 / 1000000) * (P.card : ℝ) ≤ (1 - Real.sqrt (1 / (P.card : ℝ) + 1.01 * Real.sqrt ν)) * P.card := mul_le_mul_of_nonneg_right (by linarith) hnpos.le linarith [hu.2] have h81 := prop81_C P (by omega) (by norm_num : (0 : ℝ) ≤ 9 / 1000000) (by norm_num) (le_refl (1 / 10000 : ℝ)) U hUc hUf O hρ hcirc have hC := propC_C P hP (by omega) O hρ (by linarith) linarith end Erdos94ThmA /-! ### (F1) Cyclically labelled polygons: orientation, left turns, edges, turning; INVERSE Lemma 11.2 -/ namespace Erdos94ThmA open Finset /-- The cross product `z × w = Im(z̄ w) = z.re w.im − z.im w.re`. -/ def cr (z w : ℂ) : ℝ := ((starRingEnd ℂ) z * w).im theorem cr_eq (z w : ℂ) : cr z w = z.re * w.im - z.im * w.re := by unfold cr simp only [Complex.mul_im, Complex.conj_re, Complex.conj_im] ring /-- Edge `e_x = v_{x+1} − v_x` of a cyclically labelled polygon. -/ def edge {n : ℕ} (v : ZMod n → ℂ) (x : ZMod n) : ℂ := v (x + 1) - v x /-- `v` turns left at every vertex: `e_x × e_{x+1} > 0`. -/ def LeftTurns {n : ℕ} (v : ZMod n → ℂ) : Prop := ∀ x : ZMod n, 0 < cr (edge v x) (edge v (x + 1)) /-- Exterior angle at `v_{x+1}` (the turn from `e_x` to `e_{x+1}`). -/ noncomputable def extAng {n : ℕ} (v : ZMod n → ℂ) (x : ZMod n) : ℝ := Complex.arg (edge v (x + 1) / edge v x) /-- `τ(x, x+p)`: total turning of `∂P` from `e_x` to `e_{x+p}` (exterior angles at `v_{x+1}, …, v_{x+p}`). -/ noncomputable def turning {n : ℕ} (v : ZMod n → ℂ) (x : ZMod n) (p : ℕ) : ℝ := ∑ i ∈ range p, extAng v (x + i) theorem edge_ne_zero {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) : edge v x ≠ 0 := by intro h have := hv x rw [h, cr_eq] at this simp at this theorem extAng_nonneg {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) : 0 ≤ extAng v x := by unfold extAng rw [Complex.arg_nonneg_iff] have h0 := edge_ne_zero hv x have h1 := hv x rw [cr_eq] at h1 rw [Complex.div_im] have hn : 0 < Complex.normSq (edge v x) := Complex.normSq_pos.mpr h0 have : (edge v (x + 1)).im * (edge v x).re / Complex.normSq (edge v x) - (edge v (x + 1)).re * (edge v x).im / Complex.normSq (edge v x) = ((edge v x).re * (edge v (x + 1)).im - (edge v x).im * (edge v (x + 1)).re) / Complex.normSq (edge v x) := by ring rw [this] exact (div_pos h1 hn).le theorem turning_succ {n : ℕ} (v : ZMod n → ℂ) (x : ZMod n) (p : ℕ) : turning v x (p + 1) = turning v x p + extAng v (x + p) := by unfold turning rw [sum_range_succ] theorem turning_nonneg {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) (p : ℕ) : 0 ≤ turning v x p := sum_nonneg (fun i _ => extAng_nonneg hv _) /-- The edge `e_{x+p}` is `e_x` rotated by `τ(x, x+p)` and scaled by a positive factor. -/ theorem edge_rot {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) (p : ℕ) : ∃ r : ℝ, 0 < r ∧ edge v (x + p) = edge v x * ((r : ℂ) * Complex.exp ((turning v x p : ℝ) * Complex.I)) := by induction p with | zero => exact ⟨1, one_pos, by simp [turning]⟩ | succ p ih => obtain ⟨r, hr, he⟩ := ih obtain ⟨q, hq⟩ : ∃ q, q = edge v (x + p + 1) / edge v (x + p) := ⟨_, rfl⟩ have hq0 : q ≠ 0 := by rw [hq] exact div_ne_zero (edge_ne_zero hv _) (edge_ne_zero hv _) have hqpol : q = (‖q‖ : ℂ) * Complex.exp (Complex.arg q * Complex.I) := (Complex.norm_mul_exp_arg_mul_I q).symm refine ⟨r * ‖q‖, mul_pos hr (norm_pos_iff.mpr hq0), ?_⟩ have e1 : x + ((p + 1 : ℕ) : ZMod n) = x + p + 1 := by push_cast; ring have e2 : edge v (x + p + 1) = edge v (x + p) * q := by rw [hq] field_simp [edge_ne_zero hv (x + p)] have e3 : extAng v (x + p) = Complex.arg q := by rw [hq] rfl rw [e1, e2, turning_succ, e3] conv_lhs => rw [he, hqpol] push_cast rw [add_mul, Complex.exp_add] ring theorem sub_eq_sum_edges {n : ℕ} (v : ZMod n → ℂ) (x : ZMod n) (p : ℕ) : v (x + p) - v x = ∑ i ∈ range p, edge v (x + i) := by induction p with | zero => simp | succ p ih => rw [sum_range_succ, ← ih] unfold edge have : x + ((p + 1 : ℕ) : ZMod n) = x + p + 1 := by push_cast; ring rw [this] ring theorem turning_split {n : ℕ} (v : ZMod n → ℂ) (x : ZMod n) (i m : ℕ) : turning v x (i + m) = turning v x i + turning v (x + i) m := by unfold turning rw [sum_range_add] congr 1 refine sum_congr rfl (fun j _ => ?_) congr 1 push_cast ring /-- **INVERSE Lemma 11.2 (quarter-turn monotonicity).** If the total turning `τ(x, x+p)` is less than `π/2`, then `|v_x v_{x+p+1}| > |v_x v_{x+p}|`. (Only left turns are used.) -/ theorem quarter_turn {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) (p : ℕ) (hτ : turning v x p < Real.pi / 2) : dist (v x) (v (x + p)) < dist (v x) (v (x + (p + 1 : ℕ))) := by set e := edge v (x + p) with he have he0 : e ≠ 0 := edge_ne_zero hv _ -- each earlier edge makes an acute angle with `e` have hacute : ∀ i ∈ range p, 0 < (edge v (x + i) * (starRingEnd ℂ) e).re := by intro i hi have hip : i ≤ p := (mem_range.mp hi).le obtain ⟨r, hr, hrot⟩ := edge_rot hv (x + i) (p - i) have e1 : x + (i : ZMod n) + ((p - i : ℕ) : ZMod n) = x + p := by rw [Nat.cast_sub hip] ring rw [e1] at hrot have hτi : turning v (x + i) (p - i) ≤ turning v x p := by have := turning_split v x i (p - i) rw [Nat.add_sub_cancel' hip] at this linarith [turning_nonneg hv x i] have hτ0 := turning_nonneg hv (x + i) (p - i) have hcos : 0 < Real.cos (turning v (x + i) (p - i)) := Real.cos_pos_of_mem_Ioo ⟨by linarith [Real.pi_pos], by linarith⟩ rw [he, hrot] set a := edge v (x + i) have ha0 : a ≠ 0 := edge_ne_zero hv _ have hconj : (starRingEnd ℂ) (a * ((r : ℂ) * Complex.exp ((turning v (x + i) (p - i) : ℝ) * Complex.I))) = (starRingEnd ℂ) a * ((r : ℂ) * Complex.exp (-(turning v (x + i) (p - i) : ℝ) * Complex.I)) := by rw [map_mul, map_mul, Complex.conj_ofReal, ← Complex.exp_conj] congr 2 simp [Complex.conj_ofReal] rw [hconj] have : a * ((starRingEnd ℂ) a * ((r : ℂ) * Complex.exp (-(turning v (x + i) (p - i) : ℝ) * Complex.I))) = ((Complex.normSq a * r : ℝ) : ℂ) * Complex.exp ((-(turning v (x + i) (p - i)) : ℝ) * Complex.I) := by rw [← mul_assoc, Complex.mul_conj] push_cast ring rw [this, Complex.re_ofReal_mul, Complex.exp_ofReal_mul_I_re, Real.cos_neg] exact mul_pos (mul_pos (Complex.normSq_pos.mpr ha0) hr) hcos have hS : 0 ≤ ((v (x + p) - v x) * (starRingEnd ℂ) e).re := by rw [sub_eq_sum_edges, sum_mul, Complex.re_sum] exact sum_nonneg (fun i hi => (hacute i hi).le) have hnext : v (x + (p + 1 : ℕ)) - v x = (v (x + p) - v x) + e := by rw [he] unfold edge have : x + ((p + 1 : ℕ) : ZMod n) = x + p + 1 := by push_cast; ring rw [this] ring rw [dist_comm, dist_eq_norm, dist_comm (v x), dist_eq_norm] have hsq : ‖v (x + p) - v x‖ ^ 2 < ‖v (x + (p + 1 : ℕ)) - v x‖ ^ 2 := by rw [hnext, Complex.sq_norm, Complex.sq_norm, Complex.normSq_add] have := Complex.normSq_pos.mpr he0 linarith exact lt_of_pow_lt_pow_left₀ 2 (norm_nonneg _) hsq end Erdos94ThmA /-! ### (F2) Every convex-independent finite set in `ℂ` is a counterclockwise convex polygon `v : ZMod n → ℂ` (vertices sorted by `arg` around the lowest point); counterclockwise polygons turn left at every vertex -/ namespace Erdos94ThmA open Finset /-- `v` lists a strictly convex polygon counterclockwise: every three vertices with increasing labels (in `0, …, n − 1`) form a positively oriented triangle. -/ def CCWPoly {n : ℕ} (v : ZMod n → ℂ) : Prop := ∀ i j k : ZMod n, i.val < j.val → j.val < k.val → 0 < cr (v j - v i) (v k - v i) theorem cr_cyc (A B C : ℂ) : cr (B - A) (C - A) = cr (C - B) (A - B) := by simp only [cr_eq, Complex.sub_re, Complex.sub_im] ring theorem cr_pos_of_arg {z w : ℂ} (hz : z ≠ 0) (hw : w ≠ 0) (h1 : Complex.arg z < Complex.arg w) (h2 : Complex.arg w - Complex.arg z < Real.pi) : 0 < cr z w := by have hzr : z.re = ‖z‖ * Real.cos (Complex.arg z) := by rw [Complex.cos_arg hz]; field_simp [norm_ne_zero_iff.mpr hz] have hzi : z.im = ‖z‖ * Real.sin (Complex.arg z) := by rw [Complex.sin_arg]; field_simp [norm_ne_zero_iff.mpr hz] have hwr : w.re = ‖w‖ * Real.cos (Complex.arg w) := by rw [Complex.cos_arg hw]; field_simp [norm_ne_zero_iff.mpr hw] have hwi : w.im = ‖w‖ * Real.sin (Complex.arg w) := by rw [Complex.sin_arg]; field_simp [norm_ne_zero_iff.mpr hw] have hs : 0 < Real.sin (Complex.arg w - Complex.arg z) := Real.sin_pos_of_pos_of_lt_pi (by linarith) h2 rw [Real.sin_sub] at hs rw [cr_eq, hzr, hzi, hwr, hwi] have := mul_pos (norm_pos_iff.mpr hz) (norm_pos_iff.mpr hw) nlinarith /-- Cramer's rule in the plane: `(a × c) b = (b × c) a + (a × b) c`. -/ theorem cramer (a b c : ℂ) : (cr a c : ℂ) * b = (cr b c : ℂ) * a + (cr a b : ℂ) * c := by apply Complex.ext <;> simp [cr_eq, Complex.mul_re, Complex.mul_im] <;> ring theorem mem_hull_three {S : Set ℂ} {p q r x : ℂ} (hp : p ∈ S) (hq : q ∈ S) (hr : r ∈ S) {α β γ : ℝ} (hα : 0 ≤ α) (hβ : 0 ≤ β) (hγ : 0 ≤ γ) (hs : α + β + γ = 1) (hx : x = (α : ℂ) * p + (β : ℂ) * q + (γ : ℂ) * r) : x ∈ convexHull ℝ S := by have hconv := convex_convexHull ℝ S have hp' := subset_convexHull ℝ S hp have hq' := subset_convexHull ℝ S hq have hr' := subset_convexHull ℝ S hr by_cases hbg : β + γ = 0 · have hb : β = 0 := by linarith have hg : γ = 0 := by linarith have ha : α = 1 := by linarith rw [hx, hb, hg, ha] simpa using hp' · have hbg0 : 0 < β + γ := lt_of_le_of_ne (by linarith) (Ne.symm hbg) have hy : (β / (β + γ)) • q + (γ / (β + γ)) • r ∈ convexHull ℝ S := hconv hq' hr' (div_nonneg hβ hbg0.le) (div_nonneg hγ hbg0.le) (by field_simp) have hxy := hconv hp' hy hα hbg0.le (by linarith) convert hxy using 1 rw [hx] simp only [Complex.real_smul, smul_add] have hbgC : (β : ℂ) + γ ≠ 0 := by exact_mod_cast hbg push_cast field_simp ring /-- Three distinct points with equal direction from `p₀` are collinear. -/ theorem collinear_of_arg_eq {p₀ z w : ℂ} (hz : z ≠ p₀) (hw : w ≠ p₀) (h : Complex.arg (z - p₀) = Complex.arg (w - p₀)) : Collinear ℝ ({p₀, w, z} : Set ℂ) := by have hz0 : z - p₀ ≠ 0 := sub_ne_zero.mpr hz have hw0 : w - p₀ ≠ 0 := sub_ne_zero.mpr hw have hzp := Complex.norm_mul_exp_arg_mul_I (z - p₀) have hwp := Complex.norm_mul_exp_arg_mul_I (w - p₀) have hwn : (‖w - p₀‖ : ℂ) ≠ 0 := by exact_mod_cast norm_ne_zero_iff.mpr hw0 have hE : Complex.exp ((Complex.arg (w - p₀) : ℝ) * Complex.I) = (w - p₀) / (‖w - p₀‖ : ℂ) := by rw [eq_div_iff hwn, mul_comm] exact hwp have key : z - p₀ = ((‖z - p₀‖ / ‖w - p₀‖ : ℝ) : ℂ) * (w - p₀) := by calc z - p₀ = (‖z - p₀‖ : ℂ) * Complex.exp ((Complex.arg (z - p₀) : ℝ) * Complex.I) := hzp.symm _ = (‖z - p₀‖ : ℂ) * Complex.exp ((Complex.arg (w - p₀) : ℝ) * Complex.I) := by rw [h] _ = (‖z - p₀‖ : ℂ) * ((w - p₀) / (‖w - p₀‖ : ℂ)) := by rw [hE] _ = ((‖z - p₀‖ / ‖w - p₀‖ : ℝ) : ℂ) * (w - p₀) := by push_cast field_simp rw [collinear_iff_of_mem (Set.mem_insert p₀ _)] refine ⟨w - p₀, fun p hp => ?_⟩ simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hp rcases hp with rfl | rfl | rfl · exact ⟨0, by simp⟩ · exact ⟨1, by simp⟩ · refine ⟨‖p - p₀‖ / ‖w - p₀‖, ?_⟩ rw [vadd_eq_add, Complex.real_smul, ← key] ring /-- **Counterclockwise labelling.** A convex-independent `P ⊂ ℂ` with `n = |P| ≥ 3` points is the vertex set of a counterclockwise strictly convex polygon `v : ZMod n → ℂ`. -/ theorem exists_ccw_labelling (P : Finset ℂ) (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) (h3 : 3 ≤ P.card) : ∃ v : ZMod P.card → ℂ, Function.Injective v ∧ (∀ k, v k ∈ P) ∧ CCWPoly v := by classical have hne : P.Nonempty := by rw [← card_pos]; omega have hNZ : NeZero P.card := ⟨by omega⟩ -- the lowest (then leftmost) point obtain ⟨m₀, hm₀P, hm₀⟩ := P.exists_min_image (fun z => z.im) hne obtain ⟨p₀, hp₀1, hp₀⟩ := (P.filter (fun z => z.im = m₀.im)).exists_min_image (fun z => z.re) ⟨m₀, mem_filter.mpr ⟨hm₀P, rfl⟩⟩ have hp₀P : p₀ ∈ P := (mem_filter.mp hp₀1).1 have hp₀im : p₀.im = m₀.im := (mem_filter.mp hp₀1).2 have harg : ∀ z ∈ P, z ≠ p₀ → 0 ≤ Complex.arg (z - p₀) ∧ Complex.arg (z - p₀) < Real.pi := by intro z hz hzp have him : 0 ≤ (z - p₀).im := by rw [Complex.sub_im, hp₀im] linarith [hm₀ z hz] refine ⟨Complex.arg_nonneg_iff.mpr him, Complex.arg_lt_pi_iff.mpr ?_⟩ by_cases h0 : (z - p₀).im = 0 · left have hz1 : z ∈ P.filter (fun z => z.im = m₀.im) := by rw [mem_filter] refine ⟨hz, ?_⟩ rw [Complex.sub_im, hp₀im] at h0 linarith have := hp₀ z hz1 rw [Complex.sub_re] linarith · right exact h0 -- the other points, sorted by direction from p₀ obtain ⟨Q, hQ⟩ : ∃ Q, Q = P.erase p₀ := ⟨_, rfl⟩ have hQP : ∀ z ∈ Q, z ∈ P ∧ z ≠ p₀ := fun z hz => by rw [hQ, mem_erase] at hz exact ⟨hz.2, hz.1⟩ have hQc : Q.card = P.card - 1 := by rw [hQ, card_erase_of_mem hp₀P] have hinj : Set.InjOn (fun z => Complex.arg (z - p₀)) (Q : Set ℂ) := by intro z hz w hw h by_contra hzw have hz' := hQP z hz have hw' := hQP w hw exact convexIndepC_not_collinear hP (mem_coe.mpr hp₀P) (mem_coe.mpr hw'.1) (mem_coe.mpr hz'.1) (Ne.symm hw'.2) (Ne.symm hz'.2) (fun e => hzw e.symm) (collinear_of_arg_eq hz'.2 hw'.2 h) obtain ⟨A, hA⟩ : ∃ A, A = Q.image (fun z => Complex.arg (z - p₀)) := ⟨_, rfl⟩ have hAc : A.card = P.card - 1 := by rw [hA, card_image_of_injOn hinj, hQc] obtain ⟨e, he⟩ : ∃ e, e = A.orderEmbOfFin hAc := ⟨_, rfl⟩ have heA : ∀ i, e i ∈ A := fun i => by rw [he]; exact A.orderEmbOfFin_mem hAc i let q : Fin (P.card - 1) → ℂ := fun i => Function.invFunOn (fun z => Complex.arg (z - p₀)) (Q : Set ℂ) (e i) have hq : ∀ i, q i ∈ Q ∧ Complex.arg (q i - p₀) = e i := by intro i have hex : ∃ a ∈ (Q : Set ℂ), Complex.arg (a - p₀) = e i := by have := heA i rw [hA, mem_image] at this obtain ⟨a, ha, h⟩ := this exact ⟨a, mem_coe.mpr ha, h⟩ exact ⟨mem_coe.mp (Function.invFunOn_mem hex), Function.invFunOn_eq hex⟩ have hemono : StrictMono e := by rw [he]; exact (A.orderEmbOfFin hAc).strictMono -- the labelling let v : ZMod P.card → ℂ := fun k => if h : k.val = 0 then p₀ else q ⟨k.val - 1, by have := ZMod.val_lt k; omega⟩ have hv0 : ∀ k : ZMod P.card, k.val = 0 → v k = p₀ := fun k h => by simp only [v]; rw [dif_pos h] have hv1 : ∀ k : ZMod P.card, ∀ h : k.val ≠ 0, v k = q ⟨k.val - 1, by have := ZMod.val_lt k; omega⟩ := fun k h => by simp only [v]; rw [dif_neg h] have hvP : ∀ k, v k ∈ P := by intro k by_cases h : k.val = 0 · rw [hv0 k h]; exact hp₀P · rw [hv1 k h]; exact (hQP _ (hq _).1).1 have hargv : ∀ k : ZMod P.card, ∀ h : k.val ≠ 0, Complex.arg (v k - p₀) = e ⟨k.val - 1, by have := ZMod.val_lt k; omega⟩ := fun k h => by rw [hv1 k h]; exact (hq _).2 have hvne : ∀ k : ZMod P.card, k.val ≠ 0 → v k ≠ p₀ := fun k h => by rw [hv1 k h]; exact (hQP _ (hq _).1).2 have hvinj : Function.Injective v := by intro k k' hkk apply ZMod.val_injective by_cases h : k.val = 0 · by_cases h' : k'.val = 0 · rw [h, h'] · exact absurd (hkk.symm.trans (hv0 k h)) (hvne k' h') · by_cases h' : k'.val = 0 · exact absurd (hkk.trans (hv0 k' h')) (hvne k h) · have e1 := hargv k h have e2 := hargv k' h' rw [hkk] at e1 have := hemono.injective (e1.symm.trans e2) have := congrArg Fin.val this simp only at this omega refine ⟨v, hvinj, hvP, ?_⟩ intro i j k hij hjk have hj0 : j.val ≠ 0 := by omega have hk0 : k.val ≠ 0 := by omega have hjk' : Complex.arg (v j - p₀) < Complex.arg (v k - p₀) := by rw [hargv j hj0, hargv k hk0] apply hemono show j.val - 1 < k.val - 1 omega have hjP := harg (v j) (hvP j) (hvne j hj0) have hkP := harg (v k) (hvP k) (hvne k hk0) have hj0' : v j - p₀ ≠ 0 := sub_ne_zero.mpr (hvne j hj0) have hk0' : v k - p₀ ≠ 0 := sub_ne_zero.mpr (hvne k hk0) by_cases hi : i.val = 0 · rw [hv0 i hi] exact cr_pos_of_arg hj0' hk0' hjk' (by linarith [hjP.1, hkP.2]) · have hiP := harg (v i) (hvP i) (hvne i hi) have hi0' : v i - p₀ ≠ 0 := sub_ne_zero.mpr (hvne i hi) have hij' : Complex.arg (v i - p₀) < Complex.arg (v j - p₀) := by rw [hargv i hi, hargv j hj0] apply hemono show i.val - 1 < j.val - 1 omega have hab := cr_pos_of_arg hi0' hj0' hij' (by linarith [hiP.1, hjP.2]) have hbc := cr_pos_of_arg hj0' hk0' hjk' (by linarith [hjP.1, hkP.2]) have hac := cr_pos_of_arg hi0' hk0' (lt_trans hij' hjk') (by linarith [hiP.1, hkP.2]) by_contra hcon have hle : cr (v j - v i) (v k - v i) ≤ 0 := not_lt.mp hcon have hcr : cr (v j - v i) (v k - v i) = cr (v j - p₀) (v k - p₀) + cr (v i - p₀) (v j - p₀) - cr (v i - p₀) (v k - p₀) := by simp only [cr_eq, Complex.sub_re, Complex.sub_im] ring have hne_ij : v i ≠ v j := fun h => by have := hvinj h rw [this] at hij exact lt_irrefl _ hij have hne_kj : v k ≠ v j := fun h => by have := hvinj h rw [this] at hjk exact lt_irrefl _ hjk have hcram := cramer (v i - p₀) (v j - p₀) (v k - p₀) apply hP (v j) (hvP j) apply mem_hull_three (p := p₀) (q := v i) (r := v k) (α := -cr (v j - v i) (v k - v i) / cr (v i - p₀) (v k - p₀)) (β := cr (v j - p₀) (v k - p₀) / cr (v i - p₀) (v k - p₀)) (γ := cr (v i - p₀) (v j - p₀) / cr (v i - p₀) (v k - p₀)) · exact ⟨mem_coe.mpr hp₀P, fun h => hvne j hj0 (Set.mem_singleton_iff.mp h).symm⟩ · exact ⟨mem_coe.mpr (hvP i), fun h => hne_ij (Set.mem_singleton_iff.mp h)⟩ · exact ⟨mem_coe.mpr (hvP k), fun h => hne_kj (Set.mem_singleton_iff.mp h)⟩ · exact div_nonneg (by linarith) hac.le · exact div_nonneg hbc.le hac.le · exact div_nonneg hab.le hac.le · rw [hcr] field_simp ring · have hacC : (cr (v i - p₀) (v k - p₀) : ℂ) ≠ 0 := by exact_mod_cast hac.ne' rw [hcr] push_cast field_simp linear_combination hcram end Erdos94ThmA namespace Erdos94ThmA open Finset theorem val_add_cases {n : ℕ} [NeZero n] (a d : ZMod n) : ((a + d).val = a.val + d.val ∧ a.val + d.val < n) ∨ ((a + d).val + n = a.val + d.val ∧ n ≤ a.val + d.val) := by have ha := ZMod.val_lt a have hd := ZMod.val_lt d rw [ZMod.val_add] by_cases h : a.val + d.val < n · left exact ⟨Nat.mod_eq_of_lt h, h⟩ · right have h' : n ≤ a.val + d.val := not_lt.mp h rw [Nat.mod_eq_sub_mod h', Nat.mod_eq_of_lt (by omega)] exact ⟨by omega, h'⟩ /-- Any three vertices met in counterclockwise cyclic order from the first form a positive triangle. -/ theorem ccw_cyclic {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : CCWPoly v) {a b c : ZMod n} (hab : 0 < (b - a).val) (hbc : (b - a).val < (c - a).val) : 0 < cr (v b - v a) (v c - v a) := by have hb : b = a + (b - a) := by ring have hc : c = a + (c - a) := by ring have hcn := ZMod.val_lt (c - a) have hbv := val_add_cases a (b - a) have hcv := val_add_cases a (c - a) rw [← hb] at hbv rw [← hc] at hcv rcases hbv with ⟨hb1, hb2⟩ | ⟨hb1, hb2⟩ <;> rcases hcv with ⟨hc1, hc2⟩ | ⟨hc1, hc2⟩ · exact hv a b c (by omega) (by omega) · have := hv c a b (by omega) (by omega) rw [cr_cyc (v a) (v b) (v c), cr_cyc (v b) (v c) (v a)] exact this · omega · have := hv b c a (by omega) (by omega) rw [cr_cyc (v a) (v b) (v c)] exact this /-- A counterclockwise polygon with `n ≥ 3` vertices turns left at every vertex. -/ theorem ccw_leftTurns {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) : LeftTurns v := by intro x have h1 : ((x + 1) - x).val = 1 := by rw [add_sub_cancel_left, show (1 : ZMod n) = ((1 : ℕ) : ZMod n) by simp, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] have h2 : ((x + 2) - x).val = 2 := by rw [add_sub_cancel_left, show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by simp, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] have := ccw_cyclic hv (a := x) (b := x + 1) (c := x + 2) (by omega) (by omega) unfold edge have e : x + 1 + 1 = x + 2 := by ring rw [e] have : cr (v (x + 1) - v x) (v (x + 2) - v (x + 1)) = cr (v (x + 1) - v x) (v (x + 2) - v x) := by simp only [cr_eq, Complex.sub_re, Complex.sub_im] ring rw [this] exact ‹0 < cr (v (x + 1) - v x) (v (x + 2) - v x)› end Erdos94ThmA /-! ### (F3) Cyclic orders on `ZMod n`: INVERSE Lemmas 2.1 and 2.2 -/ namespace Erdos94ThmA open Finset /-- `cyc a b c`: going counterclockwise from `a` one meets `b` strictly before `c`. -/ def cyc {n : ℕ} (a b c : ZMod n) : Prop := 0 < (b - a).val ∧ (b - a).val < (c - a).val theorem val_one_of_three {n : ℕ} [NeZero n] (hn : 3 ≤ n) : (1 : ZMod n).val = 1 := by rw [show (1 : ZMod n) = ((1 : ℕ) : ZMod n) by simp, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] theorem cyc_succ {n : ℕ} [NeZero n] (hn : 3 ≤ n) {x z : ZMod n} (hzx : z ≠ x) (hz1 : z ≠ x + 1) : cyc x (x + 1) z := by have h1 : ((x + 1) - x).val = 1 := by rw [add_sub_cancel_left]; exact val_one_of_three hn refine ⟨by rw [h1]; omega, ?_⟩ rw [h1] by_contra hcon have hle : (z - x).val ≤ 1 := not_lt.mp hcon rcases Nat.le_one_iff_eq_zero_or_eq_one.mp hle with h | h · apply hzx have : z - x = 0 := (ZMod.val_eq_zero (z - x)).mp h exact sub_eq_zero.mp this · apply hz1 have : z - x = 1 := ZMod.val_injective n (h.trans (val_one_of_three hn).symm) rw [← this] ring /-- A value `1` step after `T x` can only be the image of a point that is not cyclically after `x + 1`. -/ theorem cyc_no_gap {n : ℕ} [NeZero n] (hn : 3 ≤ n) {Tx Tx1 Tz : ZMod n} (hz : Tz = Tx + 1) (h : cyc Tx Tx1 Tz) : False := by have h1 : (Tz - Tx).val = 1 := by rw [hz, add_sub_cancel_left]; exact val_one_of_three hn have h2 := h.2 have h0 := h.1 rw [h1] at h2 omega /-- **INVERSE Lemma 2.1.** A bijection of `ZMod n` (`n ≥ 3`) preserving the cyclic order is a rotation. -/ theorem cyc_bij_rot {n : ℕ} [NeZero n] (hn : 3 ≤ n) (T : ZMod n → ZMod n) (hT : Function.Injective T) (hcyc : ∀ a b c, cyc a b c → cyc (T a) (T b) (T c)) : ∀ x, T x = T 0 + x := by have hsurj : Function.Surjective T := Finite.injective_iff_surjective.mp hT have hone : (1 : ZMod n) ≠ 0 := by intro h have := congrArg ZMod.val h rw [val_one_of_three hn, ZMod.val_zero] at this omega have hstep : ∀ x, T (x + 1) = T x + 1 := by intro x by_contra h obtain ⟨z, hz⟩ := hsurj (T x + 1) have hzx : z ≠ x := fun e => by rw [e] at hz exact hone (by linear_combination -hz) have hz1 : z ≠ x + 1 := fun e => h (by rw [← e, hz]) exact cyc_no_gap hn hz (hcyc _ _ _ (cyc_succ hn hzx hz1)) have hnat : ∀ k : ℕ, T (k : ZMod n) = T 0 + k := by intro k induction k with | zero => simp | succ k ih => push_cast rw [hstep, ih] ring intro x have := hnat x.val rwa [ZMod.natCast_zmod_val] at this open Classical in /-- **INVERSE Lemma 2.2 (count).** If `T` is injective on `A ⊂ ZMod n` and preserves the cyclic order there, then `#{x ∈ A : x + 1 ∈ A, T(x + 1) = T(x) + 1} ≥ n − 3|V ∖ A|`. -/ theorem cyc_consecutive {n : ℕ} [NeZero n] (hn : 3 ≤ n) (A : Finset (ZMod n)) (T : ZMod n → ZMod n) (hT : Set.InjOn T A) (hcyc : ∀ a ∈ A, ∀ b ∈ A, ∀ c ∈ A, cyc a b c → cyc (T a) (T b) (T c)) : n ≤ (A.filter (fun x => x + 1 ∈ A ∧ T (x + 1) = T x + 1)).card + 3 * (n - A.card) := by have hcardU : (univ : Finset (ZMod n)).card = n := ZMod.card n have hAle : A.card ≤ n := le_trans (card_le_univ A) hcardU.le -- the three kinds of bad positions have hcov : (univ : Finset (ZMod n)) ⊆ A.filter (fun x => x + 1 ∈ A ∧ T (x + 1) = T x + 1) ∪ univ.filter (fun x => x ∉ A) ∪ A.filter (fun x => x + 1 ∉ A) ∪ A.filter (fun x => x + 1 ∈ A ∧ T (x + 1) ≠ T x + 1) := by intro x _ simp only [mem_union, mem_filter, mem_univ, true_and] by_cases hx : x ∈ A · by_cases hx1 : x + 1 ∈ A · by_cases h : T (x + 1) = T x + 1 · exact Or.inl (Or.inl (Or.inl ⟨hx, hx1, h⟩)) · exact Or.inr ⟨hx, hx1, h⟩ · exact Or.inl (Or.inr ⟨hx, hx1⟩) · exact Or.inl (Or.inl (Or.inr hx)) have h1 : (univ.filter (fun x => x ∉ A)).card = n - A.card := by have e : univ.filter (fun x => x ∉ A) = Aᶜ := by ext x simp rw [e, card_compl, ZMod.card] have h2 : (A.filter (fun x => x + 1 ∉ A)).card ≤ n - A.card := by have : (A.filter (fun x => x + 1 ∉ A)).card ≤ (univ.filter (fun x : ZMod n => x ∉ A)).card := by apply card_le_card_of_injOn (fun x => x + 1) · intro x hx have hx' := mem_filter.mp hx exact mem_filter.mpr ⟨mem_univ _, hx'.2⟩ · intro x _ y _ h simpa using h rw [h1] at this exact this have h3 : (A.filter (fun x => x + 1 ∈ A ∧ T (x + 1) ≠ T x + 1)).card ≤ n - A.card := by have : (A.filter (fun x => x + 1 ∈ A ∧ T (x + 1) ≠ T x + 1)).card ≤ (univ.filter (fun y : ZMod n => y ∉ A.image T)).card := by apply card_le_card_of_injOn (fun x => T x + 1) · intro x hx have hx' := mem_filter.mp hx refine mem_filter.mpr ⟨mem_univ _, fun hmem => ?_⟩ rw [mem_image] at hmem obtain ⟨z, hzA, hz0⟩ := hmem have hz : T z = T x + 1 := hz0 have hone : (1 : ZMod n) ≠ 0 := by intro h have := congrArg ZMod.val h rw [val_one_of_three hn, ZMod.val_zero] at this omega have hzx : z ≠ x := fun e => by rw [e] at hz exact hone (by linear_combination -hz) have hz1 : z ≠ x + 1 := fun e => hx'.2.2 (by rw [← e, hz]) exact cyc_no_gap hn hz (hcyc _ hx'.1 _ hx'.2.1 _ hzA (cyc_succ hn hzx hz1)) · intro x hx y hy h have h' : T x = T y := by simpa using h exact hT (mem_filter.mp hx).1 (mem_filter.mp hy).1 h' have hB : (univ.filter (fun y : ZMod n => y ∉ A.image T)).card = n - A.card := by have e : univ.filter (fun y : ZMod n => y ∉ A.image T) = (A.image T)ᶜ := by ext y simp rw [e, card_compl, ZMod.card, card_image_of_injOn hT] rw [hB] at this exact this have := le_trans (card_le_card hcov) (le_trans (card_union_le _ _) (add_le_add (le_trans (card_union_le _ _) (add_le_add (card_union_le _ _) le_rfl)) le_rfl)) rw [hcardU] at this omega end Erdos94ThmA /-! ### (F4) INVERSE Theorem 3.1 (rigidity of almost-isometries) and Lemma 11.3 -/ namespace Erdos94ThmA open Finset /-- A point is determined by its distances to the vertices of a non-degenerate triangle. -/ theorem eq_of_dist3 {a b c z w : ℂ} (hcr : cr (b - a) (c - a) ≠ 0) (ha : ‖z - a‖ = ‖w - a‖) (hb : ‖z - b‖ = ‖w - b‖) (hc : ‖z - c‖ = ‖w - c‖) : z = w := by have sq : ∀ p : ℂ, ‖z - p‖ = ‖w - p‖ → (z.re - p.re) ^ 2 + (z.im - p.im) ^ 2 = (w.re - p.re) ^ 2 + (w.im - p.im) ^ 2 := by intro p h have h2 : ‖z - p‖ ^ 2 = ‖w - p‖ ^ 2 := by rw [h] rw [Complex.sq_norm, Complex.sq_norm, Complex.normSq_apply, Complex.normSq_apply] at h2 simp only [Complex.sub_re, Complex.sub_im] at h2 linear_combination h2 have ea := sq a ha have eb := sq b hb have ec := sq c hc have h1 : (b.re - a.re) * (z.re - w.re) + (b.im - a.im) * (z.im - w.im) = 0 := by linear_combination (eb - ea) / (-2) have h2 : (c.re - a.re) * (z.re - w.re) + (c.im - a.im) * (z.im - w.im) = 0 := by linear_combination (ec - ea) / (-2) rw [cr_eq] at hcr simp only [Complex.sub_re, Complex.sub_im] at hcr have hre : ((b.re - a.re) * (c.im - a.im) - (b.im - a.im) * (c.re - a.re)) * (z.re - w.re) = 0 := by linear_combination (c.im - a.im) * h1 - (b.im - a.im) * h2 have him : ((b.re - a.re) * (c.im - a.im) - (b.im - a.im) * (c.re - a.re)) * (z.im - w.im) = 0 := by linear_combination (b.re - a.re) * h2 - (c.re - a.re) * h1 rcases mul_eq_zero.mp hre with h | h · exact absurd h hcr rcases mul_eq_zero.mp him with h' | h' · exact absurd h' hcr exact Complex.ext (by linarith) (by linarith) theorem im_div_eq_cr (z w : ℂ) : (z / w).im = cr w z / Complex.normSq w := by rw [Complex.div_im, cr_eq] ring /-- **SSS, direct form.** Two positively oriented triangles with equal sides differ by a rotation: `c' − a' = ω (c − a)` with `ω = (b' − a')/(b − a)`. -/ theorem sss_direct {a b c a' b' c' : ℂ} (hab : a ≠ b) (h1 : 0 < cr (b - a) (c - a)) (h1' : 0 < cr (b' - a') (c' - a')) (hb : ‖b' - a'‖ = ‖b - a‖) (hc : ‖c' - a'‖ = ‖c - a‖) (hbc : ‖c' - b'‖ = ‖c - b‖) : c' - a' = (b' - a') / (b - a) * (c - a) := by have hp : b - a ≠ 0 := sub_ne_zero.mpr (Ne.symm hab) have hpn : 0 < ‖b - a‖ := norm_pos_iff.mpr hp have hp' : b' - a' ≠ 0 := by intro h rw [h, norm_zero] at hb linarith obtain ⟨u, hu⟩ : ∃ u, u = (c - a) / (b - a) := ⟨_, rfl⟩ obtain ⟨u', hu'⟩ : ∃ u, u = (c' - a') / (b' - a') := ⟨_, rfl⟩ have hn1 : ‖u‖ = ‖u'‖ := by rw [hu, hu', norm_div, norm_div, hb, hc] have hm1 : u - 1 = (c - b) / (b - a) := by rw [hu]; field_simp; ring have hm1' : u' - 1 = (c' - b') / (b' - a') := by rw [hu']; field_simp; ring have hn2 : ‖u - 1‖ = ‖u' - 1‖ := by rw [hm1, hm1', norm_div, norm_div, hb, hbc] have him : 0 < u.im := by rw [hu, im_div_eq_cr] exact div_pos h1 (Complex.normSq_pos.mpr hp) have him' : 0 < u'.im := by rw [hu', im_div_eq_cr] exact div_pos h1' (Complex.normSq_pos.mpr hp') have e1 : u.re ^ 2 + u.im ^ 2 = u'.re ^ 2 + u'.im ^ 2 := by have h2 : ‖u‖ ^ 2 = ‖u'‖ ^ 2 := by rw [hn1] rw [Complex.sq_norm, Complex.sq_norm, Complex.normSq_apply, Complex.normSq_apply] at h2 linear_combination h2 have e2 : (u.re - 1) ^ 2 + u.im ^ 2 = (u'.re - 1) ^ 2 + u'.im ^ 2 := by have h2 : ‖u - 1‖ ^ 2 = ‖u' - 1‖ ^ 2 := by rw [hn2] rw [Complex.sq_norm, Complex.sq_norm, Complex.normSq_apply, Complex.normSq_apply] at h2 simp only [Complex.sub_re, Complex.sub_im, Complex.one_re, Complex.one_im] at h2 linear_combination h2 have hre : u.re = u'.re := by linarith have hsq : u.im ^ 2 = u'.im ^ 2 := by rw [hre] at e1; linarith have himeq : u.im = u'.im := by have := (sq_eq_sq₀ him.le him'.le).mp hsq exact this have huu : u = u' := Complex.ext hre himeq have : c' - a' = u' * (b' - a') := by rw [hu']; field_simp rw [this, ← huu, hu] field_simp /-- Markov: few vertices have many bad partners. -/ theorem markov_card {α : Type*} (s : Finset α) (d : α → ℕ) {T c : ℝ} (hc : 0 < c) (hsum : (∑ x ∈ s, d x : ℝ) ≤ T) : ((s.filter (fun x => c < d x)).card : ℝ) * c ≤ T := by classical have h1 : ∑ x ∈ s.filter (fun x => c < d x), c ≤ ∑ x ∈ s.filter (fun x => c < d x), (d x : ℝ) := sum_le_sum (fun x hx => (mem_filter.mp hx).2.le) have h2 : ∑ x ∈ s.filter (fun x => c < d x), (d x : ℝ) ≤ ∑ x ∈ s, (d x : ℝ) := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun _ _ _ => Nat.cast_nonneg _) rw [sum_const, nsmul_eq_mul] at h1 linarith theorem cyc_or {n : ℕ} [NeZero n] {a b c : ZMod n} (hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) : cyc a b c ∨ cyc a c b := by have h1 : (b - a).val ≠ 0 := fun h => hab (sub_eq_zero.mp ((ZMod.val_eq_zero _).mp h)).symm have h2 : (c - a).val ≠ 0 := fun h => hac (sub_eq_zero.mp ((ZMod.val_eq_zero _).mp h)).symm have h3 : (b - a).val ≠ (c - a).val := fun h => hbc (by have := ZMod.val_injective n h linear_combination this) unfold cyc omega open Classical in /-- **INVERSE Theorem 3.1 (rigidity of almost-isometries)**, for a counterclockwise polygon `v` with `n ≥ 7` vertices and a bijection `π` of the labels preserving the cyclic order: if at most `βn²` unordered pairs (`2βn²` ordered pairs) change length under `π` (`0 < β ≤ 1/100`), then there is a direct isometry `g(z) = ωz + t` (`|ω| = 1`) with `π(v) = g(v)` for all but `6√β n` vertices; `g` is not a nontrivial translation (given the translation lemma for the vertex set) and is not the identity when `π` has no fixed point. -/ theorem rigidity31 {n : ℕ} [NeZero n] (hn : 7 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (π : ZMod n → ZMod n) (hcyc : ∀ a b c, cyc a b c → cyc (π a) (π b) (π c)) {β : ℝ} (hβ0 : 0 < β) (hβ : β ≤ 1 / 100) (hB : ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => dist (v (π p.1)) (v (π p.2)) ≠ dist (v p.1) (v p.2))).card : ℝ) ≤ 2 * β * n ^ 2) (hT : ∀ t : ℂ, t ≠ 0 → (univ.filter (fun x : ZMod n => ∃ y, v y = v x + t)).card ≤ 2) : ∃ ω t : ℂ, ‖ω‖ = 1 ∧ ((univ.filter (fun x => v (π x) ≠ ω * v x + t)).card : ℝ) ≤ 6 * Real.sqrt β * n ∧ (ω = 1 → t = 0) ∧ ((∀ x, π x ≠ x) → ω ≠ 1) := by have hnR : (7 : ℝ) ≤ n := by exact_mod_cast hn have hcardU : ((univ : Finset (ZMod n)).card : ℝ) = n := by rw [card_univ, ZMod.card] obtain ⟨s, hs⟩ : ∃ s, s = Real.sqrt β := ⟨_, rfl⟩ have hs0 : 0 < s := by rw [hs]; exact Real.sqrt_pos.mpr hβ0 have hs2 : s ^ 2 = β := by rw [hs]; exact Real.sq_sqrt hβ0.le have hs1 : s ≤ 1 / 10 := by rw [hs] have := Real.sqrt_le_sqrt hβ rwa [show (1 : ℝ) / 100 = (1 / 10) ^ 2 by norm_num, Real.sqrt_sq (by norm_num)] at this rw [← hs] -- degrees in the "bad pair" graph obtain ⟨N, hN⟩ : ∃ N : ZMod n → Finset (ZMod n), N = fun x => univ.filter (fun y => dist (v (π x)) (v (π y)) ≠ dist (v x) (v y)) := ⟨_, rfl⟩ have hNx : ∀ x y, y ∈ N x ↔ dist (v (π x)) (v (π y)) ≠ dist (v x) (v y) := by intro x y rw [hN] simp have hsum : (∑ x, ((N x).card : ℝ)) ≤ 2 * s ^ 2 * n ^ 2 := by have e : ∑ x, (N x).card = (((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => dist (v (π p.1)) (v (π p.2)) ≠ dist (v p.1) (v p.2))).card := by rw [card_filter, sum_product] refine sum_congr rfl (fun x _ => ?_) rw [hN] simp only rw [card_filter] have e' : (∑ x, ((N x).card : ℝ)) = (((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => dist (v (π p.1)) (v (π p.2)) ≠ dist (v p.1) (v p.2))).card : ℕ) : ℝ) := by rw [← e] push_cast rfl rw [e', hs2] exact hB obtain ⟨W, hW⟩ : ∃ W, W = univ.filter (fun x => ((N x).card : ℝ) ≤ 2 * s * n) := ⟨_, rfl⟩ have hWbad : ((univ.filter (fun x => 2 * s * n < ((N x).card : ℝ))).card : ℝ) ≤ s * n := by have h := markov_card univ (fun x => (N x).card) (c := 2 * s * n) (by positivity) hsum have hpos : 0 < 2 * s * n := by positivity have : ((univ.filter (fun x => 2 * s * n < ((N x).card : ℝ))).card : ℝ) * (2 * s * n) ≤ (s * n) * (2 * s * n) := by nlinarith exact le_of_mul_le_mul_right this hpos have hWcard : (n : ℝ) - s * n ≤ W.card := by have h := card_filter_add_card_filter_not (s := (univ : Finset (ZMod n))) (fun x => ((N x).card : ℝ) ≤ 2 * s * n) have h' : ((univ.filter (fun x => ((N x).card : ℝ) ≤ 2 * s * n)).card : ℝ) + (univ.filter (fun x => ¬ (((N x).card : ℝ) ≤ 2 * s * n))).card = ((univ : Finset (ZMod n)).card : ℝ) := by exact_mod_cast h rw [hcardU] at h' have h2 : univ.filter (fun x => ¬ (((N x).card : ℝ) ≤ 2 * s * n)) = univ.filter (fun x => 2 * s * n < ((N x).card : ℝ)) := filter_congr (fun x _ => not_le) rw [h2] at h' rw [hW] linarith have hsn : s * n ≤ n / 10 := by nlinarith have hWd : ∀ x ∈ W, ((N x).card : ℝ) ≤ 2 * s * n := fun x hx => by rw [hW] at hx exact (mem_filter.mp hx).2 -- choose a, b, c in W, pairwise good have hW0 : W.Nonempty := by rw [← card_pos] have : (0 : ℝ) < W.card := by nlinarith exact_mod_cast this obtain ⟨a, haW⟩ := hW0 have hb_ex : (W \ ({a} ∪ N a)).Nonempty := by rw [← card_pos] have h1 := le_card_sdiff ({a} ∪ N a) W have h2 : ({a} ∪ N a).card ≤ 1 + (N a).card := by have := card_union_le {a} (N a) rwa [card_singleton] at this have hda := hWd a haW have : (1 + (N a).card : ℕ) < W.card := by have h4 : ((1 + (N a).card : ℕ) : ℝ) < W.card := by push_cast; linarith exact_mod_cast h4 omega obtain ⟨b, hb⟩ := hb_ex rw [mem_sdiff, mem_union, mem_singleton, not_or] at hb obtain ⟨hbW, hba, hbN⟩ := hb have hc_ex : (W \ ({a, b} ∪ N a ∪ N b)).Nonempty := by rw [← card_pos] have h1 := le_card_sdiff ({a, b} ∪ N a ∪ N b) W have h2 : ({a, b} ∪ N a ∪ N b).card ≤ 2 + (N a).card + (N b).card := by have e1 := card_union_le ({a, b} ∪ N a) (N b) have e2 := card_union_le ({a, b} : Finset (ZMod n)) (N a) have e3 : ({a, b} : Finset (ZMod n)).card ≤ 2 := card_le_two omega have hda := hWd a haW have hdb := hWd b hbW have : (2 + (N a).card + (N b).card : ℕ) < W.card := by have h4 : ((2 + (N a).card + (N b).card : ℕ) : ℝ) < W.card := by push_cast; linarith exact_mod_cast h4 omega obtain ⟨c, hc⟩ := hc_ex rw [mem_sdiff, mem_union, mem_union, mem_insert, mem_singleton, not_or, not_or, not_or] at hc obtain ⟨hcW, ⟨⟨hca, hcb⟩, hcNa⟩, hcNb⟩ := hc -- orient the triple have hgood : ∀ x y, y ∉ N x → ‖v (π y) - v (π x)‖ = ‖v y - v x‖ := by intro x y h rw [hNx] at h push_neg at h rw [← dist_eq_norm, ← dist_eq_norm, dist_comm, h, dist_comm] have hsymm : ∀ x y, y ∉ N x → x ∉ N y := by intro x y h h' rw [hNx] at h h' exact h' (by rw [dist_comm, dist_comm (v y)]; push_neg at h; exact h) obtain ⟨b₁, c₁, hb₁W, hc₁W, hab₁, hb₁c₁, hac₁, hcyc₁⟩ : ∃ b₁ c₁, b₁ ∈ W ∧ c₁ ∈ W ∧ b₁ ∉ N a ∧ c₁ ∉ N b₁ ∧ c₁ ∉ N a ∧ cyc a b₁ c₁ := by rcases cyc_or (Ne.symm hba) (Ne.symm hca) (Ne.symm hcb) with h | h · exact ⟨b, c, hbW, hcW, hbN, hcNb, hcNa, h⟩ · exact ⟨c, b, hcW, hbW, hcNa, hsymm b c hcNb, hbN, h⟩ have ho := ccw_cyclic hv hcyc₁.1 hcyc₁.2 have ho' := ccw_cyclic hv (hcyc _ _ _ hcyc₁).1 (hcyc _ _ _ hcyc₁).2 have hab₁' : v a ≠ v b₁ := fun h => by have := hvi h rw [this] at hcyc₁ have h0 := hcyc₁.1 rw [sub_self, ZMod.val_zero] at h0 exact lt_irrefl _ h0 obtain ⟨ω, hω⟩ : ∃ ω, ω = (v (π b₁) - v (π a)) / (v b₁ - v a) := ⟨_, rfl⟩ have hωn : ‖ω‖ = 1 := by rw [hω, norm_div, hgood a b₁ hab₁] exact div_self (norm_ne_zero_iff.mpr (sub_ne_zero.mpr (Ne.symm hab₁'))) have hkey := sss_direct hab₁' ho ho' (hgood a b₁ hab₁) (hgood a c₁ hac₁) (hgood b₁ c₁ hb₁c₁) rw [← hω] at hkey obtain ⟨t, ht⟩ : ∃ t, t = v (π a) - ω * v a := ⟨_, rfl⟩ have hga : ω * v a + t = v (π a) := by rw [ht]; ring have hgb : ω * v b₁ + t = v (π b₁) := by rw [ht, hω] field_simp [sub_ne_zero.mpr (Ne.symm hab₁')] ring have hgc : ω * v c₁ + t = v (π c₁) := by rw [ht] linear_combination -hkey have hiso : ∀ z w : ℂ, ‖(ω * z + t) - (ω * w + t)‖ = ‖z - w‖ := by intro z w rw [show (ω * z + t) - (ω * w + t) = ω * (z - w) by ring, norm_mul, hωn, one_mul] have hagree : ∀ x, x ∉ N a → x ∉ N b₁ → x ∉ N c₁ → v (π x) = ω * v x + t := by intro x hxa hxb hxc apply eq_of_dist3 (a := v (π a)) (b := v (π b₁)) (c := v (π c₁)) (ne_of_gt ho') · rw [hgood a x hxa, ← hga, hiso] · rw [hgood b₁ x hxb, ← hgb, hiso] · rw [hgood c₁ x hxc, ← hgc, hiso] have hbadsub : univ.filter (fun x => v (π x) ≠ ω * v x + t) ⊆ N a ∪ N b₁ ∪ N c₁ := by intro x hx rw [mem_filter] at hx rw [mem_union, mem_union] by_contra hcon push_neg at hcon exact hx.2 (hagree x hcon.1.1 hcon.1.2 hcon.2) have hbadc : ((univ.filter (fun x => v (π x) ≠ ω * v x + t)).card : ℝ) ≤ 6 * s * n := by have e1 := card_union_le (N a ∪ N b₁) (N c₁) have e2 := card_union_le (N a) (N b₁) have h1 : (univ.filter (fun x => v (π x) ≠ ω * v x + t)).card ≤ (N a).card + (N b₁).card + (N c₁).card := le_trans (card_le_card hbadsub) (by omega) have h1R : ((univ.filter (fun x => v (π x) ≠ ω * v x + t)).card : ℝ) ≤ (N a).card + (N b₁).card + (N c₁).card := by exact_mod_cast h1 linarith [hWd a haW, hWd b₁ hb₁W, hWd c₁ hc₁W] -- the agreement set has at least three points have hgood3 : 2 < (univ.filter (fun x => v (π x) = ω * v x + t)).card := by have h := card_filter_add_card_filter_not (s := (univ : Finset (ZMod n))) (fun x => v (π x) = ω * v x + t) have h' : ((univ.filter (fun x => v (π x) = ω * v x + t)).card : ℝ) + (univ.filter (fun x => ¬ (v (π x) = ω * v x + t))).card = ((univ : Finset (ZMod n)).card : ℝ) := by exact_mod_cast h rw [hcardU] at h' have h3 : (2 : ℝ) < (univ.filter (fun x => v (π x) = ω * v x + t)).card := by nlinarith exact_mod_cast h3 have htr : ω = 1 → t = 0 := by intro h1 by_contra ht0 have hsub : univ.filter (fun x => v (π x) = ω * v x + t) ⊆ univ.filter (fun x : ZMod n => ∃ y, v y = v x + t) := by intro x hx rw [mem_filter] at hx ⊢ refine ⟨mem_univ _, π x, ?_⟩ rw [hx.2, h1, one_mul] have := le_trans (card_le_card hsub) (hT t ht0) omega refine ⟨ω, t, hωn, hbadc, htr, fun hfix h1 => ?_⟩ have ht0 := htr h1 obtain ⟨x, hx⟩ : (univ.filter (fun x => v (π x) = ω * v x + t)).Nonempty := by rw [← card_pos] omega rw [mem_filter, h1, ht0, one_mul, add_zero] at hx exact hfix x (hvi hx.2) end Erdos94ThmA /-! ### (F5) INVERSE Lemma 11.3: Theorem 3.1 inside a window -/ namespace Erdos94ThmA open Finset open Classical in /-- **INVERSE Lemma 11.3 (local almost-isometry ⇒ local rotation)**: Theorem 3.1 inside a window `W` of `≥ 7` labels, for any `π` preserving the cyclic order on `W`: if at most `βn²` unordered pairs (`2βn²` ordered pairs) change length under `π` (`0 < β ≤ 1/100`), then there is a direct isometry `g(z) = ωz + t` (`|ω| = 1`) with `π(v) = g(v)` for all but `6√β n` vertices; `g` is not a nontrivial translation (given the translation lemma for the vertex set) and is not the identity when `π` has no fixed point. -/ theorem rigidityW {n : ℕ} [NeZero n] (W₀ : Finset (ZMod n)) (hn : 7 ≤ W₀.card) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (π : ZMod n → ZMod n) (hcyc : ∀ a ∈ W₀, ∀ b ∈ W₀, ∀ c ∈ W₀, cyc a b c → cyc (π a) (π b) (π c)) {β : ℝ} (hβ0 : 0 < β) (hβ : β ≤ 1 / 100) (hB : (((W₀ ×ˢ W₀).filter (fun p => dist (v (π p.1)) (v (π p.2)) ≠ dist (v p.1) (v p.2))).card : ℝ) ≤ 2 * β * (W₀.card : ℝ) ^ 2) (hT : ∀ t : ℂ, t ≠ 0 → (W₀.filter (fun x : ZMod n => ∃ y, v y = v x + t)).card ≤ 2) : ∃ ω t : ℂ, ‖ω‖ = 1 ∧ ((W₀.filter (fun x => v (π x) ≠ ω * v x + t)).card : ℝ) ≤ 6 * Real.sqrt β * W₀.card ∧ (ω = 1 → t = 0) ∧ ((∀ x ∈ W₀, π x ≠ x) → ω ≠ 1) := by have hnR : (7 : ℝ) ≤ W₀.card := by exact_mod_cast hn obtain ⟨s, hs⟩ : ∃ s, s = Real.sqrt β := ⟨_, rfl⟩ have hs0 : 0 < s := by rw [hs]; exact Real.sqrt_pos.mpr hβ0 have hs2 : s ^ 2 = β := by rw [hs]; exact Real.sq_sqrt hβ0.le have hs1 : s ≤ 1 / 10 := by rw [hs] have := Real.sqrt_le_sqrt hβ rwa [show (1 : ℝ) / 100 = (1 / 10) ^ 2 by norm_num, Real.sqrt_sq (by norm_num)] at this rw [← hs] -- degrees in the "bad pair" graph obtain ⟨N, hN⟩ : ∃ N : ZMod n → Finset (ZMod n), N = fun x => W₀.filter (fun y => dist (v (π x)) (v (π y)) ≠ dist (v x) (v y)) := ⟨_, rfl⟩ have hNx : ∀ x y, y ∈ N x ↔ y ∈ W₀ ∧ dist (v (π x)) (v (π y)) ≠ dist (v x) (v y) := by intro x y rw [hN] simp have hsum : (∑ x ∈ W₀, ((N x).card : ℝ)) ≤ 2 * s ^ 2 * (W₀.card : ℝ) ^ 2 := by have e : ∑ x ∈ W₀, (N x).card = ((W₀ ×ˢ W₀).filter (fun p => dist (v (π p.1)) (v (π p.2)) ≠ dist (v p.1) (v p.2))).card := by rw [card_filter, sum_product] refine sum_congr rfl (fun x _ => ?_) rw [hN] simp only rw [card_filter] have e' : (∑ x ∈ W₀, ((N x).card : ℝ)) = (((((W₀ ×ˢ W₀)).filter (fun p => dist (v (π p.1)) (v (π p.2)) ≠ dist (v p.1) (v p.2))).card : ℕ) : ℝ) := by rw [← e] push_cast rfl rw [e', hs2] exact hB obtain ⟨W, hW⟩ : ∃ W, W = W₀.filter (fun x => ((N x).card : ℝ) ≤ 2 * s * W₀.card) := ⟨_, rfl⟩ have hWbad : ((W₀.filter (fun x => 2 * s * W₀.card < ((N x).card : ℝ))).card : ℝ) ≤ s * W₀.card := by have h := markov_card W₀ (fun x => (N x).card) (c := 2 * s * W₀.card) (by positivity) hsum have hpos : 0 < 2 * s * (W₀.card : ℝ) := by positivity have : ((W₀.filter (fun x => 2 * s * W₀.card < ((N x).card : ℝ))).card : ℝ) * (2 * s * W₀.card) ≤ (s * W₀.card) * (2 * s * W₀.card) := by nlinarith exact le_of_mul_le_mul_right this hpos have hWcard : (W₀.card : ℝ) - s * W₀.card ≤ W.card := by have h := card_filter_add_card_filter_not (s := W₀) (fun x => ((N x).card : ℝ) ≤ 2 * s * W₀.card) have h' : ((W₀.filter (fun x => ((N x).card : ℝ) ≤ 2 * s * W₀.card)).card : ℝ) + (W₀.filter (fun x => ¬ (((N x).card : ℝ) ≤ 2 * s * W₀.card))).card = (W₀.card : ℝ) := by exact_mod_cast h have h2 : W₀.filter (fun x => ¬ (((N x).card : ℝ) ≤ 2 * s * W₀.card)) = W₀.filter (fun x => 2 * s * W₀.card < ((N x).card : ℝ)) := filter_congr (fun x _ => not_le) rw [h2] at h' rw [hW] linarith have hsn : s * W₀.card ≤ (W₀.card : ℝ) / 10 := by nlinarith have hWd : ∀ x ∈ W, ((N x).card : ℝ) ≤ 2 * s * W₀.card := fun x hx => by rw [hW] at hx exact (mem_filter.mp hx).2 -- choose a, b, c in W, pairwise good have hW0 : W.Nonempty := by rw [← card_pos] have : (0 : ℝ) < W.card := by nlinarith exact_mod_cast this obtain ⟨a, haW⟩ := hW0 have hb_ex : (W \ ({a} ∪ N a)).Nonempty := by rw [← card_pos] have h1 := le_card_sdiff ({a} ∪ N a) W have h2 : ({a} ∪ N a).card ≤ 1 + (N a).card := by have := card_union_le {a} (N a) rwa [card_singleton] at this have hda := hWd a haW have : (1 + (N a).card : ℕ) < W.card := by have h4 : ((1 + (N a).card : ℕ) : ℝ) < W.card := by push_cast; linarith exact_mod_cast h4 omega obtain ⟨b, hb⟩ := hb_ex rw [mem_sdiff, mem_union, mem_singleton, not_or] at hb obtain ⟨hbW, hba, hbN⟩ := hb have hc_ex : (W \ ({a, b} ∪ N a ∪ N b)).Nonempty := by rw [← card_pos] have h1 := le_card_sdiff ({a, b} ∪ N a ∪ N b) W have h2 : ({a, b} ∪ N a ∪ N b).card ≤ 2 + (N a).card + (N b).card := by have e1 := card_union_le ({a, b} ∪ N a) (N b) have e2 := card_union_le ({a, b} : Finset (ZMod n)) (N a) have e3 : ({a, b} : Finset (ZMod n)).card ≤ 2 := card_le_two omega have hda := hWd a haW have hdb := hWd b hbW have : (2 + (N a).card + (N b).card : ℕ) < W.card := by have h4 : ((2 + (N a).card + (N b).card : ℕ) : ℝ) < W.card := by push_cast; linarith exact_mod_cast h4 omega obtain ⟨c, hc⟩ := hc_ex rw [mem_sdiff, mem_union, mem_union, mem_insert, mem_singleton, not_or, not_or, not_or] at hc obtain ⟨hcW, ⟨⟨hca, hcb⟩, hcNa⟩, hcNb⟩ := hc -- orient the triple have hWW : W ⊆ W₀ := by rw [hW]; exact filter_subset _ _ have hgood : ∀ x y, y ∈ W₀ → y ∉ N x → ‖v (π y) - v (π x)‖ = ‖v y - v x‖ := by intro x y hy h rw [hNx] at h have h : ¬ (dist (v (π x)) (v (π y)) ≠ dist (v x) (v y)) := fun h' => h ⟨hy, h'⟩ push_neg at h rw [← dist_eq_norm, ← dist_eq_norm, dist_comm, h, dist_comm] have hsymm : ∀ x y, x ∈ W₀ → y ∈ W₀ → y ∉ N x → x ∉ N y := by intro x y hx hy h h' rw [hNx] at h h' exact h ⟨hy, by rw [dist_comm, dist_comm (v x)]; exact h'.2⟩ obtain ⟨b₁, c₁, hb₁W, hc₁W, hab₁, hb₁c₁, hac₁, hcyc₁⟩ : ∃ b₁ c₁, b₁ ∈ W ∧ c₁ ∈ W ∧ b₁ ∉ N a ∧ c₁ ∉ N b₁ ∧ c₁ ∉ N a ∧ cyc a b₁ c₁ := by rcases cyc_or (Ne.symm hba) (Ne.symm hca) (Ne.symm hcb) with h | h · exact ⟨b, c, hbW, hcW, hbN, hcNb, hcNa, h⟩ · exact ⟨c, b, hcW, hbW, hcNa, hsymm b c (hWW hbW) (hWW hcW) hcNb, hbN, h⟩ have ho := ccw_cyclic hv hcyc₁.1 hcyc₁.2 have hcycπ := hcyc a (hWW haW) b₁ (hWW hb₁W) c₁ (hWW hc₁W) hcyc₁ have ho' := ccw_cyclic hv hcycπ.1 hcycπ.2 have hab₁' : v a ≠ v b₁ := fun h => by have := hvi h rw [this] at hcyc₁ have h0 := hcyc₁.1 rw [sub_self, ZMod.val_zero] at h0 exact lt_irrefl _ h0 obtain ⟨ω, hω⟩ : ∃ ω, ω = (v (π b₁) - v (π a)) / (v b₁ - v a) := ⟨_, rfl⟩ have hωn : ‖ω‖ = 1 := by rw [hω, norm_div, hgood a b₁ (hWW hb₁W) hab₁] exact div_self (norm_ne_zero_iff.mpr (sub_ne_zero.mpr (Ne.symm hab₁'))) have hkey := sss_direct hab₁' ho ho' (hgood a b₁ (hWW hb₁W) hab₁) (hgood a c₁ (hWW hc₁W) hac₁) (hgood b₁ c₁ (hWW hc₁W) hb₁c₁) rw [← hω] at hkey obtain ⟨t, ht⟩ : ∃ t, t = v (π a) - ω * v a := ⟨_, rfl⟩ have hga : ω * v a + t = v (π a) := by rw [ht]; ring have hgb : ω * v b₁ + t = v (π b₁) := by rw [ht, hω] field_simp [sub_ne_zero.mpr (Ne.symm hab₁')] ring have hgc : ω * v c₁ + t = v (π c₁) := by rw [ht] linear_combination -hkey have hiso : ∀ z w : ℂ, ‖(ω * z + t) - (ω * w + t)‖ = ‖z - w‖ := by intro z w rw [show (ω * z + t) - (ω * w + t) = ω * (z - w) by ring, norm_mul, hωn, one_mul] have hagree : ∀ x ∈ W₀, x ∉ N a → x ∉ N b₁ → x ∉ N c₁ → v (π x) = ω * v x + t := by intro x hxW hxa hxb hxc apply eq_of_dist3 (a := v (π a)) (b := v (π b₁)) (c := v (π c₁)) (ne_of_gt ho') · rw [hgood a x hxW hxa, ← hga, hiso] · rw [hgood b₁ x hxW hxb, ← hgb, hiso] · rw [hgood c₁ x hxW hxc, ← hgc, hiso] have hbadsub : W₀.filter (fun x => v (π x) ≠ ω * v x + t) ⊆ N a ∪ N b₁ ∪ N c₁ := by intro x hx rw [mem_filter] at hx rw [mem_union, mem_union] by_contra hcon push_neg at hcon exact hx.2 (hagree x hx.1 hcon.1.1 hcon.1.2 hcon.2) have hbadc : ((W₀.filter (fun x => v (π x) ≠ ω * v x + t)).card : ℝ) ≤ 6 * s * W₀.card := by have e1 := card_union_le (N a ∪ N b₁) (N c₁) have e2 := card_union_le (N a) (N b₁) have h1 : (W₀.filter (fun x => v (π x) ≠ ω * v x + t)).card ≤ (N a).card + (N b₁).card + (N c₁).card := le_trans (card_le_card hbadsub) (by omega) have h1R : ((W₀.filter (fun x => v (π x) ≠ ω * v x + t)).card : ℝ) ≤ (N a).card + (N b₁).card + (N c₁).card := by exact_mod_cast h1 linarith [hWd a haW, hWd b₁ hb₁W, hWd c₁ hc₁W] -- the agreement set has at least three points have hgood3 : 2 < (W₀.filter (fun x => v (π x) = ω * v x + t)).card := by have h := card_filter_add_card_filter_not (s := W₀) (fun x => v (π x) = ω * v x + t) have h' : ((W₀.filter (fun x => v (π x) = ω * v x + t)).card : ℝ) + (W₀.filter (fun x => ¬ (v (π x) = ω * v x + t))).card = (W₀.card : ℝ) := by exact_mod_cast h have h3 : (2 : ℝ) < (W₀.filter (fun x => v (π x) = ω * v x + t)).card := by nlinarith exact_mod_cast h3 have htr : ω = 1 → t = 0 := by intro h1 by_contra ht0 have hsub : W₀.filter (fun x => v (π x) = ω * v x + t) ⊆ W₀.filter (fun x : ZMod n => ∃ y, v y = v x + t) := by intro x hx rw [mem_filter] at hx ⊢ refine ⟨hx.1, π x, ?_⟩ rw [hx.2, h1, one_mul] have := le_trans (card_le_card hsub) (hT t ht0) omega refine ⟨ω, t, hωn, hbadc, htr, fun hfix h1 => ?_⟩ have ht0 := htr h1 obtain ⟨x, hx⟩ : (W₀.filter (fun x => v (π x) = ω * v x + t)).Nonempty := by rw [← card_pos] omega rw [mem_filter, h1, ht0, one_mul, add_zero] at hx exact hfix x hx.1 (hvi hx.2) /-- Two direct isometries that agree at two distinct points are equal (the second half of Lemma 11.3). -/ theorem direct_iso_unique {ω t ω' t' p q : ℂ} (hpq : p ≠ q) (hp : ω * p + t = ω' * p + t') (hq : ω * q + t = ω' * q + t') : ω = ω' ∧ t = t' := by have h1 : (ω - ω') * (p - q) = 0 := by linear_combination hp - hq have hω : ω = ω' := by rcases mul_eq_zero.mp h1 with h | h · exact sub_eq_zero.mp h · exact absurd (sub_eq_zero.mp h) hpq refine ⟨hω, ?_⟩ rw [hω] at hp linear_combination hp end Erdos94ThmA /-! ### (F6) INVERSE §11.8: quarter-turn ranges `F(x)`, `B(x)` and facts (i)–(iii); total turning `≥ 2π`; the hypothesis (H₀) -/ namespace Erdos94ThmA open Finset /-- Offsets add along the cycle: `(b − a) + (c − b) = (c − a)` or `= (c − a) + n`. -/ theorem off_add {n : ℕ} [NeZero n] (a b c : ZMod n) : (b - a).val + (c - b).val = (c - a).val ∨ (b - a).val + (c - b).val = (c - a).val + n := by have h := val_add_cases (b - a) (c - b) rw [show b - a + (c - b) = c - a by ring] at h omega /-- If `b` comes no later than `c` (seen from `a`), the offsets add exactly. -/ theorem off_add_of_le {n : ℕ} [NeZero n] {a b c : ZMod n} (h : (b - a).val ≤ (c - a).val) : (b - a).val + (c - b).val = (c - a).val := by have h1 := off_add a b c have h2 := ZMod.val_lt (c - b) omega theorem off_cast {n : ℕ} [NeZero n] (a : ZMod n) {j : ℕ} (hj : j < n) : ((a + j) - a).val = j := by rw [add_sub_cancel_left, ZMod.val_cast_of_lt hj] theorem add_off {n : ℕ} [NeZero n] (a b : ZMod n) : a + ((b - a).val : ZMod n) = b := by rw [ZMod.natCast_zmod_val] ring theorem off_eq_zero {n : ℕ} [NeZero n] {a b : ZMod n} : (b - a).val = 0 ↔ b = a := by rw [ZMod.val_eq_zero, sub_eq_zero] /-- Going around: `(b − a) + (a − b) = n` for `a ≠ b`. -/ theorem off_swap {n : ℕ} [NeZero n] {a b : ZMod n} (h : a ≠ b) : (b - a).val + (a - b).val = n := by have h1 := off_add a b a rw [sub_self, ZMod.val_zero] at h1 have h2 : (b - a).val ≠ 0 := fun h' => h (off_eq_zero.mp h').symm omega theorem turning_mono {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) {p p' : ℕ} (h : p ≤ p') : turning v x p ≤ turning v x p' := by obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le h rw [turning_split] linarith [turning_nonneg hv (x + p) m] theorem extAng_im_pos {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) : 0 < (edge v (x + 1) / edge v x).im := by have h0 := edge_ne_zero hv x have h1 := hv x rw [cr_eq] at h1 rw [Complex.div_im] have hn : 0 < Complex.normSq (edge v x) := Complex.normSq_pos.mpr h0 have : (edge v (x + 1)).im * (edge v x).re / Complex.normSq (edge v x) - (edge v (x + 1)).re * (edge v x).im / Complex.normSq (edge v x) = ((edge v x).re * (edge v (x + 1)).im - (edge v x).im * (edge v (x + 1)).re) / Complex.normSq (edge v x) := by ring rw [this] exact div_pos h1 hn theorem extAng_pos {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) : 0 < extAng v x := by have h0 := extAng_nonneg hv x have h1 := extAng_im_pos hv x rcases h0.lt_or_eq with h | h · exact h · exfalso have h2 : Complex.arg (edge v (x + 1) / edge v x) = 0 := h.symm rw [Complex.arg_eq_zero_iff] at h2 linarith [h2.2] /-- **Total turning of a left-turning closed polygon is at least `2π`** (the edge directions return to the start: `∏ e_{x+1}/e_x = 1`, so the sum of the exterior angles is a positive multiple of `2π`). -/ theorem turning_total_ge {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) : 2 * Real.pi ≤ ∑ x : ZMod n, extAng v x := by have hq0 : ∀ x, edge v (x + 1) / edge v x ≠ 0 := fun x => div_ne_zero (edge_ne_zero hv _) (edge_ne_zero hv _) have hprod : ∏ x : ZMod n, edge v (x + 1) / edge v x = 1 := by rw [prod_div_distrib] have : ∏ x : ZMod n, edge v (x + 1) = ∏ x : ZMod n, edge v x := Fintype.prod_equiv (Equiv.addRight 1) _ _ (fun x => rfl) rw [this, div_self] exact prod_ne_zero_iff.mpr (fun x _ => edge_ne_zero hv x) have hpol : ∏ x : ZMod n, edge v (x + 1) / edge v x = ((∏ x : ZMod n, ‖edge v (x + 1) / edge v x‖ : ℝ) : ℂ) * Complex.exp (((∑ x : ZMod n, extAng v x : ℝ) : ℂ) * Complex.I) := by rw [Complex.ofReal_prod, Complex.ofReal_sum, sum_mul, Complex.exp_sum, ← prod_mul_distrib] refine prod_congr rfl (fun x _ => ?_) exact (Complex.norm_mul_exp_arg_mul_I _).symm have hR : 0 < ∏ x : ZMod n, ‖edge v (x + 1) / edge v x‖ := prod_pos (fun x _ => norm_pos_iff.mpr (hq0 x)) rw [hpol] at hprod have hnorm := congrArg norm hprod rw [norm_mul, Complex.norm_exp_ofReal_mul_I, mul_one, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hR, norm_one] at hnorm rw [hnorm, Complex.ofReal_one, one_mul, Complex.exp_eq_one_iff] at hprod obtain ⟨k, hk⟩ := hprod have hS : (∑ x : ZMod n, extAng v x) = k * (2 * Real.pi) := by have h := congrArg Complex.im hk simp only [Complex.mul_im, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im, Complex.intCast_re, Complex.intCast_im, Complex.mul_re, Complex.re_ofNat, Complex.im_ofNat] at h linarith have hpos : 0 < ∑ x : ZMod n, extAng v x := sum_pos (fun x _ => extAng_pos hv x) univ_nonempty have hk1 : (0 : ℝ) < k := by by_contra hc push_neg at hc nlinarith [Real.pi_pos] have hk2 : (1 : ℤ) ≤ k := by have : (0 : ℤ) < k := by exact_mod_cast hk1 omega have hk3 : (1 : ℝ) ≤ k := by exact_mod_cast hk2 rw [hS] nlinarith [Real.pi_pos] /-- `τ(y, y+n)` is the sum of all exterior angles. -/ theorem turning_full {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (y : ZMod n) : turning v y n = ∑ x : ZMod n, extAng v x := by unfold turning refine sum_nbij' (fun i => y + (i : ZMod n)) (fun x => (x - y).val) ?_ ?_ ?_ ?_ ?_ · intro i _ exact mem_univ _ · intro x _ exact mem_range.mpr (ZMod.val_lt _) · intro i hi exact off_cast y (mem_range.mp hi) · intro x _ exact add_off y x · intro i _ rfl /-- Backward form of Lemma 11.2: if the open arc from `a` to `a + p + 1` turns by `< π/2` (exterior angles at `v_{a+1}, …, v_{a+p}`), then `|v_{a+p+1} v_{a+1}| < |v_{a+p+1} v_a|`. -/ theorem quarter_turn_back {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (a : ZMod n) (p : ℕ) (hτ : turning v a p < Real.pi / 2) : dist (v (a + 1 + p)) (v (a + 1)) < dist (v (a + 1 + p)) (v a) := by have he0 : edge v a ≠ 0 := edge_ne_zero hv _ have hacute : ∀ i ∈ range p, 0 < (edge v (a + 1 + i) * (starRingEnd ℂ) (edge v a)).re := by intro i hi have hip : i + 1 ≤ p := mem_range.mp hi obtain ⟨r, hr, hrot⟩ := edge_rot hv a (i + 1) have e1 : a + ((i + 1 : ℕ) : ZMod n) = a + 1 + i := by push_cast; ring rw [e1] at hrot have hτi : turning v a (i + 1) ≤ turning v a p := turning_mono hv a hip have hτ0 := turning_nonneg hv a (i + 1) have hcos : 0 < Real.cos (turning v a (i + 1)) := Real.cos_pos_of_mem_Ioo ⟨by linarith [Real.pi_pos], by linarith⟩ rw [hrot] have hmul : edge v a * ((r : ℂ) * Complex.exp ((turning v a (i + 1) : ℝ) * Complex.I)) * (starRingEnd ℂ) (edge v a) = ((Complex.normSq (edge v a) * r : ℝ) : ℂ) * Complex.exp ((turning v a (i + 1) : ℝ) * Complex.I) := by rw [mul_comm (edge v a), mul_assoc, Complex.mul_conj] push_cast ring rw [hmul, Complex.re_ofReal_mul, Complex.exp_ofReal_mul_I_re] exact mul_pos (mul_pos (Complex.normSq_pos.mpr he0) hr) hcos have hS : 0 ≤ ((v (a + 1 + p) - v (a + 1)) * (starRingEnd ℂ) (edge v a)).re := by rw [sub_eq_sum_edges, sum_mul, Complex.re_sum] exact sum_nonneg (fun i hi => (hacute i hi).le) have hprev : v (a + 1 + p) - v a = (v (a + 1 + p) - v (a + 1)) + edge v a := by unfold edge ring rw [dist_eq_norm, dist_eq_norm] have hsq : ‖v (a + 1 + p) - v (a + 1)‖ ^ 2 < ‖v (a + 1 + p) - v a‖ ^ 2 := by rw [hprev, Complex.sq_norm, Complex.sq_norm, Complex.normSq_add] have := Complex.normSq_pos.mpr he0 linarith exact lt_of_pow_lt_pow_left₀ 2 (norm_nonneg _) hsq /-- Along an arc from `a` turning by `< π/2` before `a + m`, the profile of `a` is strictly increasing. -/ theorem arc_fwd {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (a : ZMod n) {m : ℕ} (hτ : turning v a (m - 1) < Real.pi / 2) {j j' : ℕ} (hjj : j < j') (hj' : j' ≤ m) : dist (v a) (v (a + j)) < dist (v a) (v (a + j')) := by induction j' with | zero => omega | succ k ih => have hstep : dist (v a) (v (a + k)) < dist (v a) (v (a + (k + 1 : ℕ))) := quarter_turn hv a k (lt_of_le_of_lt (turning_mono hv a (by omega)) hτ) by_cases h : j < k · exact (ih h (by omega)).trans hstep · have : j = k := by omega rw [this] exact hstep /-- Along the same arc, the profile of the end vertex `a + m` is strictly decreasing towards it. -/ theorem arc_back {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (a : ZMod n) {m : ℕ} (hτ : turning v a (m - 1) < Real.pi / 2) {i i' : ℕ} (hii : i < i') (hi' : i' ≤ m) : dist (v (a + m)) (v (a + i')) < dist (v (a + m)) (v (a + i)) := by have hstep : ∀ k, k + 1 ≤ m → dist (v (a + m)) (v (a + (k + 1 : ℕ))) < dist (v (a + m)) (v (a + k)) := by intro k hk obtain ⟨r, hr⟩ : ∃ r, m = k + 1 + r := ⟨m - (k + 1), by omega⟩ have hsplit := turning_split v a k r rw [show m - 1 = k + r by omega] at hτ have hτk : turning v (a + k) r < Real.pi / 2 := by linarith [turning_nonneg hv a k] have h := quarter_turn_back hv (a + k) r hτk have e1 : a + (k : ZMod n) + 1 + (r : ZMod n) = a + (m : ZMod n) := by rw [hr] push_cast ring have e2 : a + (k : ZMod n) + 1 = a + ((k + 1 : ℕ) : ZMod n) := by push_cast; ring rw [e1, e2] at h exact h induction i' with | zero => omega | succ k ih => by_cases h : i < k · exact (hstep k hi').trans (ih h (by omega)) · have : i = k := by omega rw [this] exact hstep k hi' /-- **Fact (iii) of INVERSE §11.8** (offset form): if the arc from `a` to `a + m` turns by `< π/2` before its end, every chord `(a+i, a+j)` with `0 ≤ i < j ≤ m`, `(i, j) ≠ (0, m)`, is strictly shorter than `|v_a v_{a+m}|`. -/ theorem arc_nest {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (a : ZMod n) {m : ℕ} (hτ : turning v a (m - 1) < Real.pi / 2) {i j : ℕ} (hij : i < j) (hj : j ≤ m) (hne : 0 < i ∨ j < m) : dist (v (a + i)) (v (a + j)) < dist (v a) (v (a + m)) := by have hτj : turning v a (j - 1) < Real.pi / 2 := lt_of_le_of_lt (turning_mono hv a (by omega)) hτ have h1s : 0 < i → dist (v (a + i)) (v (a + j)) < dist (v a) (v (a + j)) := by intro h have := arc_back hv a hτj h (le_of_lt hij) rw [Nat.cast_zero, add_zero, dist_comm (v (a + j)), dist_comm (v (a + j))] at this exact this have h1 : dist (v (a + i)) (v (a + j)) ≤ dist (v a) (v (a + j)) := by rcases Nat.eq_zero_or_pos i with h | h · rw [h, Nat.cast_zero, add_zero] · exact (h1s h).le have h2 : dist (v a) (v (a + j)) ≤ dist (v a) (v (a + m)) := by rcases hj.lt_or_eq with h | h · exact (arc_fwd hv a hτ h le_rfl).le · rw [h] rcases hne with h | h · exact lt_of_lt_of_le (h1s h) h2 · exact lt_of_le_of_lt h1 (arc_fwd hv a hτ h le_rfl) /-- `q_x` (INVERSE §11.8): the largest `p < n` with `τ(x, x+p) < π/2`. -/ noncomputable def qF {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x : ZMod n) : ℕ := ((range n).filter (fun p => turning v x p < Real.pi / 2)).max' ⟨0, mem_filter.mpr ⟨mem_range.mpr (NeZero.pos n), by rw [turning, sum_range_zero]; positivity⟩⟩ /-- `y ∈ F(x) = {x+1, …, x+q_x+1}` (the forward quarter-turn range). -/ def inF {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x y : ZMod n) : Prop := 0 < (y - x).val ∧ (y - x).val ≤ qF v x + 1 /-- `q′_x`: the largest `p < n` such that the exterior angles at `v_{x−p}, …, v_{x−1}` sum to `< π/2`. -/ noncomputable def qB {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x : ZMod n) : ℕ := ((range n).filter (fun p : ℕ => turning v (x - 1 - (p : ZMod n)) p < Real.pi / 2)).max' ⟨0, mem_filter.mpr ⟨mem_range.mpr (NeZero.pos n), by rw [turning, sum_range_zero]; positivity⟩⟩ /-- `y ∈ B(x) = {x−1, …, x−q′_x−1}` (the backward quarter-turn range). -/ def inB {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x y : ZMod n) : Prop := 0 < (x - y).val ∧ (x - y).val ≤ qB v x + 1 theorem qF_mem {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x : ZMod n) : qF v x < n ∧ turning v x (qF v x) < Real.pi / 2 := by unfold qF have h := mem_filter.mp (max'_mem ((range n).filter (fun p => turning v x p < Real.pi / 2)) ⟨0, mem_filter.mpr ⟨mem_range.mpr (NeZero.pos n), by rw [turning, sum_range_zero]; positivity⟩⟩) exact ⟨mem_range.mp h.1, h.2⟩ theorem le_qF {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x : ZMod n) {p : ℕ} (hp : p < n) (hτ : turning v x p < Real.pi / 2) : p ≤ qF v x := by unfold qF exact le_max' _ p (mem_filter.mpr ⟨mem_range.mpr hp, hτ⟩) theorem qB_mem {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x : ZMod n) : qB v x < n ∧ turning v (x - 1 - (qB v x : ZMod n)) (qB v x) < Real.pi / 2 := by unfold qB have h := mem_filter.mp (max'_mem ((range n).filter (fun p : ℕ => turning v (x - 1 - (p : ZMod n)) p < Real.pi / 2)) ⟨0, mem_filter.mpr ⟨mem_range.mpr (NeZero.pos n), by rw [turning, sum_range_zero]; positivity⟩⟩) exact ⟨mem_range.mp h.1, h.2⟩ theorem le_qB {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x : ZMod n) {p : ℕ} (hp : p < n) (hτ : turning v (x - 1 - (p : ZMod n)) p < Real.pi / 2) : p ≤ qB v x := by unfold qB exact le_max' _ p (mem_filter.mpr ⟨mem_range.mpr hp, hτ⟩) theorem turning_back_mono {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) {p p' : ℕ} (h : p ≤ p') : turning v (x - 1 - (p : ZMod n)) p ≤ turning v (x - 1 - (p' : ZMod n)) p' := by obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le h have hs := turning_split v (x - 1 - ((p + m : ℕ) : ZMod n)) m p have e : x - 1 - ((p + m : ℕ) : ZMod n) + (m : ZMod n) = x - 1 - (p : ZMod n) := by push_cast; ring rw [e, show m + p = p + m by ring] at hs rw [hs] linarith [turning_nonneg hv (x - 1 - ((p + m : ℕ) : ZMod n)) m] /-- `y ∈ F(x)` iff the open arc from `x` to `y` turns by `< π/2`. -/ theorem inF_iff {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (x y : ZMod n) : inF v x y ↔ 0 < (y - x).val ∧ turning v x ((y - x).val - 1) < Real.pi / 2 := by constructor · rintro ⟨h1, h2⟩ exact ⟨h1, lt_of_le_of_lt (turning_mono hv x (by omega)) (qF_mem v x).2⟩ · rintro ⟨h1, h2⟩ have hl := ZMod.val_lt (y - x) exact ⟨h1, by have := le_qF v x (by omega) h2; omega⟩ /-- `y ∈ B(x)` iff the open arc from `y` to `x` turns by `< π/2`. -/ theorem inB_iff {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (x y : ZMod n) : inB v x y ↔ 0 < (x - y).val ∧ turning v y ((x - y).val - 1) < Real.pi / 2 := by have hcast : 0 < (x - y).val → x - 1 - (((x - y).val - 1 : ℕ) : ZMod n) = y := by intro h rw [Nat.cast_sub (show 1 ≤ (x - y).val by omega), ZMod.natCast_zmod_val] push_cast ring constructor · rintro ⟨h1, h2⟩ refine ⟨h1, ?_⟩ have hm := turning_back_mono hv x (show (x - y).val - 1 ≤ qB v x by omega) rw [hcast h1] at hm exact lt_of_le_of_lt hm (qB_mem v x).2 · rintro ⟨h1, h2⟩ have hl := ZMod.val_lt (x - y) refine ⟨h1, ?_⟩ have := le_qB v x (p := (x - y).val - 1) (by omega) (by rw [hcast h1]; exact h2) omega /-- **Fact (i)**: `y ∈ B(x) ⟺ x ∈ F(y)` (both say the open arc from `y` to `x` turns by `< π/2`). -/ theorem inB_iff_inF {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (x y : ZMod n) : inB v x y ↔ inF v y x := by rw [inB_iff hv, inF_iff hv] /-- `F(x)` never wraps around to `x`: `q_x + 2 ≤ n` (from Lemma 11.2: `|v_x v_x| = 0`). -/ theorem qF_le {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) : qF v x + 2 ≤ n := by have hn0 := NeZero.pos n by_contra h have hq := qF_mem v x have he : qF v x + 1 = n := by omega have h1 := quarter_turn hv x (qF v x) hq.2 rw [show ((qF v x + 1 : ℕ) : ZMod n) = 0 by rw [he, ZMod.natCast_self], add_zero, dist_self] at h1 exact absurd h1 (not_lt.mpr dist_nonneg) /-- The arc condition for a member of `F(x)`, in offset form. -/ theorem inF_arc {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {x y : ZMod n} (h : inF v x y) : turning v x ((y - x).val - 1) < Real.pi / 2 := ((inF_iff hv x y).mp h).2 /-- **Fact (ii), forward**: the profile of `x` is strictly increasing on `F(x)`. -/ theorem F_strict {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {x y y' : ZMod n} (hy' : inF v x y') (hlt : (y - x).val < (y' - x).val) : dist (v x) (v y) < dist (v x) (v y') := by have h := arc_fwd hv x (inF_arc hv hy') hlt le_rfl rwa [add_off, add_off] at h /-- **Fact (ii), backward**: the profile of `x` is strictly increasing on `B(x)` read away from `x` (stated through fact (i): `y, y' ∈ B(x)` means `x ∈ F(y)`, `x ∈ F(y')`). -/ theorem B_strict {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {x y y' : ZMod n} (hy' : inF v y' x) (hlt : (x - y).val < (x - y').val) : dist (v x) (v y) < dist (v x) (v y') := by have hτ := inF_arc hv hy' have hle : (x - y).val ≤ (x - y').val := hlt.le have h := arc_back hv y' hτ (i := 0) (i' := (x - y').val - (x - y).val) (by omega) (by omega) have e1 : y' + (((x - y').val - (x - y).val : ℕ) : ZMod n) = y := by rw [Nat.cast_sub hle, ZMod.natCast_zmod_val, ZMod.natCast_zmod_val] ring rwa [add_off, e1, Nat.cast_zero, add_zero] at h /-- (H₀) of INVERSE §11.8 (`ext(v_x) + ext(v_{x+1}) < 3π/2` for all `x`) implies that no `F(y)` contains `y − 1` (the form in which (H₀) is used). -/ theorem H0_noWrap {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ x : ZMod n, extAng v x + extAng v (x + 1) < 3 * Real.pi / 2) (y : ZMod n) : ¬ inF v y (y - 1) := by rw [inF_iff hv] rintro ⟨_, h2⟩ have hv1 : (y - 1 - y).val = n - 1 := by have hne : y ≠ y - 1 := by intro h have h1 : (1 : ZMod n) = 0 := by linear_combination h have := congrArg ZMod.val h1 rw [val_one_of_three hn, ZMod.val_zero] at this omega have h2 := off_swap hne rw [show y - (y - 1) = 1 by ring, val_one_of_three hn] at h2 omega rw [hv1, show n - 1 - 1 = n - 2 by omega] at h2 have htot := turning_total_ge hv rw [← turning_full v y] at htot have hs := turning_split v y (n - 2) 2 rw [show n - 2 + 2 = n by omega] at hs have e2 : turning v (y + ((n - 2 : ℕ) : ZMod n)) 2 = extAng v (y - 2) + extAng v (y - 2 + 1) := by have e : y + ((n - 2 : ℕ) : ZMod n) = y - 2 := by rw [Nat.cast_sub (show 2 ≤ n by omega), ZMod.natCast_self] push_cast ring rw [e] simp only [turning, sum_range_succ, sum_range_zero, Nat.cast_zero, Nat.cast_one, add_zero, zero_add] have := hH0 (y - 2) linarith end Erdos94ThmA /-! ### (F7) INVERSE Lemma 11.5: the short-chord matchings `T_u` — injective, offsets never drop, image-free and pairwise disjoint gaps, at most `2(n − |A_u|)` chords not mapped onto `T`-chords -/ namespace Erdos94ThmA open Finset theorem val_neg_one_of_three {n : ℕ} [NeZero n] (hn : 3 ≤ n) : ((-1 : ZMod n)).val = n - 1 := by have hne : (0 : ZMod n) ≠ -1 := by intro h have h1 : (1 : ZMod n) = 0 := by linear_combination h have := congrArg ZMod.val h1 rw [val_one_of_three hn, ZMod.val_zero] at this omega have h2 := off_swap hne rw [show (-1 : ZMod n) - 0 = -1 by ring, show (0 : ZMod n) - -1 = 1 by ring, val_one_of_three hn] at h2 omega theorem succ_ne_self {n : ℕ} [NeZero n] (hn : 3 ≤ n) (x : ZMod n) : x + 1 ≠ x := by intro h have h' : (1 : ZMod n) = 0 := by linear_combination h have := congrArg ZMod.val h' rw [val_one_of_three hn, ZMod.val_zero] at this omega open Classical in /-- `A_u` (INVERSE Lemma 11.5): the vertices `x` with a `u`-partner in `F(x)`. -/ noncomputable def Au {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u : ℝ) : Finset (ZMod n) := univ.filter (fun x => ∃ y, inF v x y ∧ dist (v x) (v y) = u) open Classical in /-- The partner map `T_u : A_u → V`: `T_u(x)` is the `u`-partner of `x` in `F(x)` (junk value `x` off `A_u`). -/ noncomputable def Tu {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u : ℝ) (x : ZMod n) : ZMod n := if h : ∃ y, inF v x y ∧ dist (v x) (v y) = u then h.choose else x theorem mem_Au {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {u : ℝ} {x : ZMod n} : x ∈ Au v u ↔ ∃ y, inF v x y ∧ dist (v x) (v y) = u := by unfold Au simp theorem Tu_spec {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {u : ℝ} {x : ZMod n} (hx : x ∈ Au v u) : inF v x (Tu v u x) ∧ dist (v x) (v (Tu v u x)) = u := by have h := mem_Au.mp hx unfold Tu rw [dif_pos h] exact h.choose_spec /-- The `u`-partner in `F(x)` is unique (fact (ii)), so `T_u` is well defined. -/ theorem Tu_unique {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u : ℝ} {x y : ZMod n} (hy : inF v x y) (hd : dist (v x) (v y) = u) : Tu v u x = y := by have hx : x ∈ Au v u := mem_Au.mpr ⟨y, hy, hd⟩ obtain ⟨h1, h2⟩ := Tu_spec hx by_contra hne rcases lt_trichotomy (Tu v u x - x).val (y - x).val with h | h | h · have := F_strict hv hy h linarith · exact hne (by have := ZMod.val_injective n h; linear_combination this) · have := F_strict hv h1 h linarith /-- **Lemma 11.5: `T_u` is injective** (two preimages of `y` would lie in `B(y)` at equal distance from `y`). -/ theorem Tu_injOn {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (u : ℝ) : Set.InjOn (Tu v u) (Au v u) := by intro x hx x' hx' hxx have h1 := Tu_spec (mem_coe.mp hx) have h2 := Tu_spec (mem_coe.mp hx') rw [hxx] at h1 rw [dist_comm] at h1 h2 by_contra hne rcases lt_trichotomy (Tu v u x' - x).val (Tu v u x' - x').val with h | h | h · have := B_strict hv h2.1 h linarith [h1.2, h2.2] · apply hne have := ZMod.val_injective n h linear_combination -this · have := B_strict hv h1.1 h linarith [h1.2, h2.2] /-- **Lemma 11.5: offsets never drop.** For `x, x + 1 ∈ A_u`, `k(x) ≤ k(x+1)` (`k(x) := T(x) − x`), with equality iff the shift maps `{x, T x}` onto the `u`-chord `{x+1, T(x+1)}`. -/ theorem Tu_off_mono {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) {u : ℝ} {x : ZMod n} (hx : x ∈ Au v u) (hx1 : x + 1 ∈ Au v u) : (Tu v u x - x).val ≤ (Tu v u (x + 1) - (x + 1)).val ∧ ((Tu v u x - x).val = (Tu v u (x + 1) - (x + 1)).val ↔ Tu v u (x + 1) = Tu v u x + 1) := by obtain ⟨hF, hd⟩ := Tu_spec hx obtain ⟨hF1, hd1⟩ := Tu_spec hx1 obtain ⟨k, hk⟩ : ∃ k, k = (Tu v u x - x).val := ⟨_, rfl⟩ obtain ⟨k1, hk1⟩ : ∃ k1, k1 = (Tu v u (x + 1) - (x + 1)).val := ⟨_, rfl⟩ rw [← hk, ← hk1] have hk1pos : 0 < k1 := by rw [hk1]; exact hF1.1 have hkn : k < n := by rw [hk]; exact ZMod.val_lt _ have hk1n : k1 < n := by rw [hk1]; exact ZMod.val_lt _ have hTx : Tu v u x = x + k := by rw [hk, add_off] have hTx1 : Tu v u (x + 1) = x + 1 + k1 := by rw [hk1, add_off] have hτ : turning v x (k - 1) < Real.pi / 2 := by rw [hk]; exact inF_arc hv hF have hlt : k < 1 + k1 := by by_contra hge push_neg at hge rcases hge.lt_or_eq with h | h · have := arc_nest hv x hτ (i := 1) (j := 1 + k1) (by omega) h.le (Or.inl one_pos) have e1 : x + ((1 : ℕ) : ZMod n) = x + 1 := by push_cast; ring have e2 : x + ((1 + k1 : ℕ) : ZMod n) = Tu v u (x + 1) := by rw [hTx1]; push_cast; ring rw [e1, e2, ← hTx] at this linarith · have : Tu v u (x + 1) = Tu v u x := by rw [hTx1, hTx, ← h]; push_cast; ring exact succ_ne_self hn x (Tu_injOn hv u (mem_coe.mpr hx1) (mem_coe.mpr hx) this) refine ⟨by omega, ⟨fun h => ?_, fun h => ?_⟩⟩ · rw [hTx1, hTx, ← h] ring · rw [hTx1, hTx] at h have h2 : ((k1 : ℕ) : ZMod n) = (k : ZMod n) := by linear_combination h have := congrArg ZMod.val h2 rw [ZMod.val_cast_of_lt hk1n, ZMod.val_cast_of_lt hkn] at this omega /-- Offsets of `T(x+1)` seen from `x` and from `T x`, when `x ∉ F(x+1)` ((H₀) at `x + 1`). -/ theorem Tu_succ_off {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) {u : ℝ} {x : ZMod n} (hx : x ∈ Au v u) (hx1 : x + 1 ∈ Au v u) (hH : ¬ inF v (x + 1) x) : (Tu v u (x + 1) - x).val = 1 + (Tu v u (x + 1) - (x + 1)).val ∧ (Tu v u (x + 1) - Tu v u x).val = 1 + (Tu v u (x + 1) - (x + 1)).val - (Tu v u x - x).val ∧ 1 + (Tu v u (x + 1) - (x + 1)).val < n := by obtain ⟨hF, _⟩ := Tu_spec hx obtain ⟨hF1, _⟩ := Tu_spec hx1 have hmono := (Tu_off_mono hn hv hx hx1).1 obtain ⟨k, hk⟩ : ∃ k, k = (Tu v u x - x).val := ⟨_, rfl⟩ obtain ⟨k1, hk1⟩ : ∃ k1, k1 = (Tu v u (x + 1) - (x + 1)).val := ⟨_, rfl⟩ rw [← hk, ← hk1] at hmono ⊢ have hq : k1 ≤ qF v (x + 1) + 1 := by rw [hk1]; exact hF1.2 have hval : (x - (x + 1)).val = n - 1 := by rw [show x - (x + 1) = -1 by ring] exact val_neg_one_of_three hn have hlt : 1 + k1 < n := by by_contra hc apply hH unfold inF rw [hval] constructor <;> omega have hTx : Tu v u x = x + k := by rw [hk, add_off] have hTx1 : Tu v u (x + 1) = x + 1 + k1 := by rw [hk1, add_off] refine ⟨?_, ?_, hlt⟩ · rw [hTx1, show x + 1 + (k1 : ZMod n) - x = ((1 + k1 : ℕ) : ZMod n) by push_cast; ring, ZMod.val_cast_of_lt hlt] · rw [hTx1, hTx, show x + 1 + (k1 : ZMod n) - (x + k) = ((1 + k1 - k : ℕ) : ZMod n) by rw [Nat.cast_sub (show k ≤ 1 + k1 by omega)]; push_cast; ring, ZMod.val_cast_of_lt (by omega)] /-- **Lemma 11.5: gaps are image-free.** If `x, x+1 ∈ A_u` and `x ∉ F(x+1)` ((H₀) at `x + 1`), no vertex strictly between `T x` and `T(x+1)` (counterclockwise) is an image of `T_u`. -/ theorem Tu_gap {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) {u : ℝ} {x : ZMod n} (hx : x ∈ Au v u) (hx1 : x + 1 ∈ Au v u) (hH : ¬ inF v (x + 1) x) {z : ZMod n} (hz : cyc (Tu v u x) z (Tu v u (x + 1))) {w : ZMod n} (hw : w ∈ Au v u) : Tu v u w ≠ z := by intro hwz obtain ⟨hF, hd⟩ := Tu_spec hx obtain ⟨hF1, hd1⟩ := Tu_spec hx1 obtain ⟨hFw, hdw⟩ := Tu_spec hw rw [hwz] at hFw hdw obtain ⟨_, hKk, hKn⟩ := Tu_succ_off hn hv hx hx1 hH have hmono := (Tu_off_mono hn hv hx hx1).1 obtain ⟨k, hk⟩ : ∃ k, k = (Tu v u x - x).val := ⟨_, rfl⟩ obtain ⟨k1, hk1⟩ : ∃ k1, k1 = (Tu v u (x + 1) - (x + 1)).val := ⟨_, rfl⟩ rw [← hk, ← hk1] at hKk hmono rw [← hk1] at hKn have hkpos : 0 < k := by rw [hk]; exact hF.1 have hk1pos : 0 < k1 := by rw [hk1]; exact hF1.1 have hz1 := hz.1 have hz2 := hz.2 rw [hKk] at hz2 obtain ⟨m, hm⟩ : ∃ m, m = (z - x).val := ⟨_, rfl⟩ have hmn : m < n := by rw [hm]; exact ZMod.val_lt _ have hmk : k + (z - Tu v u x).val = m := by rcases off_add x (Tu v u x) z with h | h · rw [← hk, ← hm] at h exact h · rw [← hk, ← hm] at h omega obtain ⟨j, hj⟩ : ∃ j, j = (z - w).val := ⟨_, rfl⟩ obtain ⟨pw, hpw⟩ : ∃ pw, pw = (w - x).val := ⟨_, rfl⟩ have hjpos : 0 < j := by rw [hj]; exact hFw.1 have hτw : turning v w (j - 1) < Real.pi / 2 := by rw [hj]; exact inF_arc hv hFw have hjn : j < n := by rw [hj]; exact ZMod.val_lt _ have hpwn : pw < n := by rw [hpw]; exact ZMod.val_lt _ have hw' : w = x + pw := by rw [hpw, add_off] have hz' : z = x + m := by rw [hm, add_off] have hTx : Tu v u x = x + k := by rw [hk, add_off] have hTx1 : Tu v u (x + 1) = x + 1 + k1 := by rw [hk1, add_off] rcases off_add x w z with h | h · -- `w` lies in `[x, z)` rw [← hpw, ← hj, ← hm] at h rcases Nat.lt_or_ge pw 2 with hp | hp · rcases Nat.lt_or_ge pw 1 with hp' | hp' · -- `w = x` have hpw0 : pw = 0 := by omega have hwx : w = x := by rw [hw', hpw0, Nat.cast_zero, add_zero] rw [hwx] at hwz rw [← hwz, sub_self, ZMod.val_zero] at hz1 exact lt_irrefl 0 hz1 · -- `w = x + 1` have hpw1 : pw = 1 := by omega have hwx : w = x + 1 := by rw [hw', hpw1, Nat.cast_one] rw [hwx] at hwz rw [← hwz, hKk] at hz2 exact lt_irrefl _ hz2 · -- `{w, z}` is strictly nested in `{x+1, T(x+1)}` have hτ1 : turning v (x + 1) (k1 - 1) < Real.pi / 2 := by rw [hk1]; exact inF_arc hv hF1 have hn1 := arc_nest hv (x + 1) hτ1 (i := pw - 1) (j := m - 1) (by omega) (by omega) (Or.inl (by omega)) have e1 : x + 1 + ((pw - 1 : ℕ) : ZMod n) = w := by rw [hw', Nat.cast_sub (show 1 ≤ pw by omega)] push_cast ring have e2 : x + 1 + ((m - 1 : ℕ) : ZMod n) = z := by rw [hz', Nat.cast_sub (show 1 ≤ m by omega)] push_cast ring rw [e1, e2, ← hTx1] at hn1 linarith · -- `w` lies in `(z, x)`: `{x, T x}` is strictly nested in `{w, z}` rw [← hpw, ← hj, ← hm] at h have hwx : w ≠ x := by intro h' rw [h', sub_self, ZMod.val_zero] at hpw omega have hsw := off_swap hwx.symm obtain ⟨e, he⟩ : ∃ e, e = (x - w).val := ⟨_, rfl⟩ rw [← hpw, ← he] at hsw have hn1 := arc_nest hv w hτw (i := e) (j := e + k) (by omega) (by omega) (Or.inl (by omega)) have e1 : w + (e : ZMod n) = x := by rw [he, add_off] have e2 : w + ((e + k : ℕ) : ZMod n) = Tu v u x := by rw [Nat.cast_add, ← add_assoc, e1, hTx] have e3 : w + (j : ZMod n) = z := by rw [hj, add_off] rw [e1, e2, e3] at hn1 linarith /-- If `a` is closer than `a'` to `z` from behind and `z` lies strictly between `a'` and `b'`, then so does `a`. -/ theorem cyc_of_back {n : ℕ} [NeZero n] {a a' z b' : ZMod n} (h0 : 0 < (z - a).val) (h : (z - a).val < (z - a').val) (hz : cyc a' z b') : cyc a' a b' := by have h1 := off_add a' a z have h2 := ZMod.val_lt (a - a') have h3 := hz.2 refine ⟨?_, ?_⟩ <;> omega /-- **Lemma 11.5: the gaps are pairwise disjoint** (under (H₀) in the form "no `F(y)` contains `y − 1`"). -/ theorem Tu_gaps_disjoint {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) {u : ℝ} {x x' : ZMod n} (hx : x ∈ Au v u) (hx1 : x + 1 ∈ Au v u) (hx' : x' ∈ Au v u) (hx'1 : x' + 1 ∈ Au v u) (hne : x ≠ x') (z : ZMod n) : ¬ (cyc (Tu v u x) z (Tu v u (x + 1)) ∧ cyc (Tu v u x') z (Tu v u (x' + 1))) := by rintro ⟨h1, h2⟩ have hH : ∀ y : ZMod n, ¬ inF v (y + 1) y := fun y => by have := hH0 (y + 1) rwa [add_sub_cancel_right] at this have hTne : Tu v u x ≠ Tu v u x' := fun h => hne (Tu_injOn hv u (mem_coe.mpr hx) (mem_coe.mpr hx') h) rcases lt_trichotomy (z - Tu v u x).val (z - Tu v u x').val with h | h | h · exact Tu_gap hn hv hx' hx'1 (hH x') (cyc_of_back h1.1 h h2) hx rfl · apply hTne have := ZMod.val_injective n h linear_combination -this · exact Tu_gap hn hv hx hx1 (hH x) (cyc_of_back h2.1 h h1) hx' rfl /-- **Lemma 11.5, the count.** Under (H₀) in the form "no `F(y)` contains `y − 1`", at most `2(n − |A_u|)` vertices `x ∈ A_u` fail "`x + 1 ∈ A_u` and `T(x+1) = T(x) + 1`"; i.e. at most `2(n − |A_u|)` chords `{x, T x}` are not mapped by the shift onto `T`-chords. -/ theorem lemma115_count {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (u : ℝ) : ((Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).card ≤ 2 * (n - (Au v u).card) := by classical have hcardU : (univ : Finset (ZMod n)).card = n := ZMod.card n have hH : ∀ y : ZMod n, ¬ inF v (y + 1) y := fun y => by have := hH0 (y + 1) rwa [add_sub_cancel_right] at this have hA1 := card_sdiff_add_card_eq_card (subset_univ (Au v u)) have h1 : ((Au v u).filter (fun x => x + 1 ∉ Au v u)).card ≤ n - (Au v u).card := by have : ((Au v u).filter (fun x => x + 1 ∉ Au v u)).card ≤ (univ \ Au v u).card := by refine card_le_card_of_injOn (fun x => x + 1) (fun x hx => ?_) (fun x _ y _ h => ?_) · have hx' := mem_filter.mp hx rw [coe_sdiff, coe_univ, Set.mem_diff] exact ⟨Set.mem_univ _, hx'.2⟩ · simpa using h omega have h2 : ((Au v u).filter (fun x => x + 1 ∈ Au v u ∧ Tu v u (x + 1) ≠ Tu v u x + 1)).card ≤ n - (Au v u).card := by have himg : ((Au v u).image (Tu v u)).card = (Au v u).card := card_image_of_injOn (Tu_injOn hv u) have hB1 := card_sdiff_add_card_eq_card (subset_univ ((Au v u).image (Tu v u))) have : ((Au v u).filter (fun x => x + 1 ∈ Au v u ∧ Tu v u (x + 1) ≠ Tu v u x + 1)).card ≤ (univ \ (Au v u).image (Tu v u)).card := by refine card_le_card_of_injOn (fun x => Tu v u x + 1) (fun x hx => ?_) (fun x hx y hy h => ?_) · obtain ⟨hxA, hx1A, hne⟩ := mem_filter.mp hx have hmono := Tu_off_mono hn hv hxA hx1A have hlt : (Tu v u x - x).val < (Tu v u (x + 1) - (x + 1)).val := by rcases hmono.1.lt_or_eq with h | h · exact h · exact absurd (hmono.2.mp h) hne obtain ⟨_, hKk, _⟩ := Tu_succ_off hn hv hxA hx1A (hH x) have hcyc : cyc (Tu v u x) (Tu v u x + 1) (Tu v u (x + 1)) := by refine ⟨?_, ?_⟩ · rw [add_sub_cancel_left, val_one_of_three hn] norm_num · rw [add_sub_cancel_left, val_one_of_three hn, hKk] omega rw [coe_sdiff, coe_univ, Set.mem_diff, coe_image] refine ⟨Set.mem_univ _, ?_⟩ rintro ⟨w, hw, hwz⟩ exact Tu_gap hn hv hxA hx1A (hH x) hcyc (mem_coe.mp hw) hwz · have hx' := (mem_filter.mp hx).1 have hy' := (mem_filter.mp hy).1 have h' : Tu v u x = Tu v u y := by simpa using h exact Tu_injOn hv u (mem_coe.mpr hx') (mem_coe.mpr hy') h' omega calc ((Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).card ≤ ((Au v u).filter (fun x => x + 1 ∉ Au v u) ∪ (Au v u).filter (fun x => x + 1 ∈ Au v u ∧ Tu v u (x + 1) ≠ Tu v u x + 1)).card := by apply card_le_card intro x hx rw [mem_filter] at hx rw [mem_union, mem_filter, mem_filter] by_cases h : x + 1 ∈ Au v u · exact Or.inr ⟨hx.1, h, fun h' => hx.2 ⟨h, h'⟩⟩ · exact Or.inl ⟨hx.1, h⟩ _ ≤ _ := card_union_le _ _ _ ≤ 2 * (n - (Au v u).card) := by omega /-- **INVERSE Lemma 11.5** (assembled). `P` counterclockwise (`CCWPoly v`, `n ≥ 3`) with (H₀) in the form "no `F(y)` contains `y − 1`" (see `H0_noWrap` for the paper's (H₀) ⇒ this). Fix a distance `u`; `A_u = {x : x has a u-partner in F(x)}`, `T(x)` that partner (unique), `k(x) = T(x) − x`. Then `T` is injective; for `x, x+1 ∈ A_u`, `k(x+1) ≥ k(x)` with equality iff the shift maps `{x, T x}` onto `{x+1, T(x+1)}`; every vertex strictly between `T(x)` and `T(x+1)` is outside `T(A_u)`; these gaps are pairwise disjoint; and at most `2(n − |A_u|)` chords `{x, T x}` are not mapped by the shift onto `T`-chords. -/ theorem lemma115 {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (u : ℝ) : (∀ x ∈ Au v u, inF v x (Tu v u x) ∧ dist (v x) (v (Tu v u x)) = u) ∧ (∀ x y, inF v x y → dist (v x) (v y) = u → Tu v u x = y) ∧ Set.InjOn (Tu v u) (Au v u) ∧ (∀ x ∈ Au v u, x + 1 ∈ Au v u → (Tu v u x - x).val ≤ (Tu v u (x + 1) - (x + 1)).val ∧ ((Tu v u x - x).val = (Tu v u (x + 1) - (x + 1)).val ↔ Tu v u (x + 1) = Tu v u x + 1)) ∧ (∀ x ∈ Au v u, x + 1 ∈ Au v u → ∀ z, cyc (Tu v u x) z (Tu v u (x + 1)) → ∀ w ∈ Au v u, Tu v u w ≠ z) ∧ (∀ x ∈ Au v u, x + 1 ∈ Au v u → ∀ x' ∈ Au v u, x' + 1 ∈ Au v u → x ≠ x' → ∀ z, ¬ (cyc (Tu v u x) z (Tu v u (x + 1)) ∧ cyc (Tu v u x') z (Tu v u (x' + 1)))) ∧ ((Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).card ≤ 2 * (n - (Au v u).card) := by have hl := ccw_leftTurns hn hv have hH : ∀ y : ZMod n, ¬ inF v (y + 1) y := fun y => by have := hH0 (y + 1) rwa [add_sub_cancel_right] at this refine ⟨fun x hx => Tu_spec hx, fun x y hy hd => Tu_unique hl hy hd, Tu_injOn hl u, fun x hx hx1 => Tu_off_mono hn hl hx hx1, fun x hx hx1 z hz w hw => Tu_gap hn hl hx hx1 (hH x) hz hw, fun x hx hx1 x' hx' hx'1 hne z => Tu_gaps_disjoint hn hl hH0 hx hx1 hx' hx'1 hne z, lemma115_count hn hl hH0 u⟩ /-- Lemma 11.5 under the paper's (H₀): `ext(v_x) + ext(v_{x+1}) < 3π/2` for every `x`. -/ theorem lemma115_H0 {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hH0 : ∀ x : ZMod n, extAng v x + extAng v (x + 1) < 3 * Real.pi / 2) (u : ℝ) : Set.InjOn (Tu v u) (Au v u) ∧ ((Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).card ≤ 2 * (n - (Au v u).card) := by have hl := ccw_leftTurns hn hv have hW := H0_noWrap hn hl hH0 exact ⟨Tu_injOn hl u, lemma115_count hn hl hW u⟩ end Erdos94ThmA /-! ### (F8) INVERSE Lemma 11.6 (middle-chord coherence) and Corollary 11.7 (below the thin scale) -/ namespace Erdos94ThmA open Finset /-- A chord `{x, y}` is SHORT if `y ∈ F(x) ∪ B(x)` (INVERSE §11.8); otherwise (and `x ≠ y`) it is a MIDDLE chord, `y ∈ Mid(x) = V ∖ ({x} ∪ F(x) ∪ B(x))`. -/ def isShort {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x y : ZMod n) : Prop := inF v x y ∨ inB v x y /-- SHORT is symmetric (fact (i)). -/ theorem isShort_symm {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {x y : ZMod n} : isShort v x y ↔ isShort v y x := by unfold isShort rw [inB_iff_inF hv, inB_iff_inF hv] tauto open Classical in /-- Ordered `u`-chords `(x, y)`: `x ≠ y` and `|v_x v_y| = u` (`2f(u)` of them). -/ noncomputable def chO {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u : ℝ) : Finset (ZMod n × ZMod n) := (univ ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) = u) open Classical in /-- Ordered MIDDLE `u`-chords (`2t_u` of them). -/ noncomputable def midO {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u : ℝ) : Finset (ZMod n × ZMod n) := (chO v u).filter (fun p => ¬ isShort v p.1 p.2) open Classical in /-- Ordered `u`-chords that the index shift `x ↦ x + 1` does not map onto `u`-chords. -/ noncomputable def chgO {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u : ℝ) : Finset (ZMod n × ZMod n) := (chO v u).filter (fun p => dist (v (p.1 + 1)) (v (p.2 + 1)) ≠ u) theorem mem_chO {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {u : ℝ} {p : ZMod n × ZMod n} : p ∈ chO v u ↔ p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) = u := by unfold chO simp /-- **INVERSE Lemma 11.6** (ordered form). Under (H₀) (as "no `F(y)` contains `y − 1`"), for every distance `u` the index shift maps all but `2(n − f(u)) + 3t_u` of the `u`-chords onto `u`-chords; with ordered counts (`#chO = 2f(u)`, `#midO = 2t_u`, `#chgO = 2·#changed`): `#chgO + 2·#chO ≤ 4n + 3·#midO`. -/ theorem lemma116 {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (u : ℝ) : (chgO v u).card + 2 * (chO v u).card ≤ 4 * n + 3 * (midO v u).card := by classical have hAle : (Au v u).card ≤ n := by have h := card_le_univ (Au v u) rwa [ZMod.card] at h have hbad := lemma115_count hn hv hH0 u -- every short `u`-chord is a `T`-chord have hshort : (chO v u).filter (fun p => isShort v p.1 p.2) ⊆ (Au v u).image (fun x => (x, Tu v u x)) ∪ (Au v u).image (fun x => (Tu v u x, x)) := by intro p hp obtain ⟨hp1, hs⟩ := mem_filter.mp hp obtain ⟨_, hd⟩ := mem_chO.mp hp1 rw [mem_union, mem_image, mem_image] rcases hs with h | h · left exact ⟨p.1, mem_Au.mpr ⟨p.2, h, hd⟩, by rw [Tu_unique hv h hd]⟩ · right rw [inB_iff_inF hv] at h have hd' : dist (v p.2) (v p.1) = u := by rw [dist_comm]; exact hd exact ⟨p.2, mem_Au.mpr ⟨p.1, h, hd'⟩, by rw [Tu_unique hv h hd']⟩ have hshort_card : ((chO v u).filter (fun p => isShort v p.1 p.2)).card ≤ 2 * (Au v u).card := by calc _ ≤ ((Au v u).image (fun x => (x, Tu v u x)) ∪ (Au v u).image (fun x => (Tu v u x, x))).card := card_le_card hshort _ ≤ ((Au v u).image (fun x => (x, Tu v u x))).card + ((Au v u).image (fun x => (Tu v u x, x))).card := card_union_le _ _ _ ≤ (Au v u).card + (Au v u).card := add_le_add card_image_le card_image_le _ = 2 * (Au v u).card := by ring -- a changed short chord comes from a bad `x` have hchg : (chgO v u).filter (fun p => isShort v p.1 p.2) ⊆ ((Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x)) := by intro p hp obtain ⟨hp1, hs⟩ := mem_filter.mp hp unfold chgO at hp1 obtain ⟨hp2, hch⟩ := mem_filter.mp hp1 obtain ⟨_, hd⟩ := mem_chO.mp hp2 rw [mem_union, mem_image, mem_image] rcases hs with h | h · left have hT := Tu_unique hv h hd refine ⟨p.1, mem_filter.mpr ⟨mem_Au.mpr ⟨p.2, h, hd⟩, ?_⟩, by rw [hT]⟩ rintro ⟨h1, h2⟩ apply hch have := (Tu_spec h1).2 rw [h2, hT] at this exact this · right rw [inB_iff_inF hv] at h have hd' : dist (v p.2) (v p.1) = u := by rw [dist_comm]; exact hd have hT := Tu_unique hv h hd' refine ⟨p.2, mem_filter.mpr ⟨mem_Au.mpr ⟨p.1, h, hd'⟩, ?_⟩, by rw [hT]⟩ rintro ⟨h1, h2⟩ apply hch have := (Tu_spec h1).2 rw [h2, hT, dist_comm] at this exact this have hchg_card : ((chgO v u).filter (fun p => isShort v p.1 p.2)).card ≤ 2 * ((Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).card := by refine (card_le_card hchg).trans ((card_union_le _ _).trans ?_) have := add_le_add (card_image_le (s := (Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (f := fun x => (x, Tu v u x))) (card_image_le (s := (Au v u).filter (fun x => ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (f := fun x => (Tu v u x, x))) omega have hmid : (chgO v u).filter (fun p => ¬ isShort v p.1 p.2) ⊆ midO v u := by intro p hp obtain ⟨hp1, hs⟩ := mem_filter.mp hp unfold chgO at hp1 exact mem_filter.mpr ⟨(mem_filter.mp hp1).1, hs⟩ have hs1 := card_filter_add_card_filter_not (s := chO v u) (fun p => isShort v p.1 p.2) have hs2 := card_filter_add_card_filter_not (s := chgO v u) (fun p => isShort v p.1 p.2) have hm1 : ((chO v u).filter (fun p => ¬ isShort v p.1 p.2)).card = (midO v u).card := rfl have hm2 := card_le_card hmid omega open Classical in /-- `B(u₀)`: the THIN vertices at scale `u₀`, `m(x) := min{|v_x v_y| : y ∈ Mid(x)} < u₀`, i.e. some middle chord at `x` is shorter than `u₀`. -/ noncomputable def thinB {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u₀ : ℝ) : Finset (ZMod n) := univ.filter (fun x => ∃ y, x ≠ y ∧ ¬ isShort v x y ∧ dist (v x) (v y) < u₀) open Classical in /-- Middle chords below `u₀` join two thin vertices. -/ theorem midO_sub_thin {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u u₀ : ℝ} (hu : u < u₀) : midO v u ⊆ (thinB v u₀).offDiag := by intro p hp unfold midO at hp obtain ⟨hp1, hs⟩ := mem_filter.mp hp obtain ⟨hne, hd⟩ := mem_chO.mp hp1 rw [mem_offDiag] refine ⟨?_, ?_, hne⟩ · unfold thinB rw [mem_filter] exact ⟨mem_univ _, p.2, hne, hs, by rw [hd]; exact hu⟩ · unfold thinB rw [mem_filter] refine ⟨mem_univ _, p.1, fun h => hne h.symm, fun h => hs ((isShort_symm hv).mp h), ?_⟩ rw [dist_comm, hd] exact hu /-- **INVERSE Corollary 11.7** (ordered form). Under (H₀), for every finite set `U` of distances below `u₀`: `Σ_{u∈U} (#chgO u + 2·#chO u) ≤ 4n|U| + 3·|B(u₀)|(|B(u₀)| − 1)`, i.e. (unordered) `#{U-chords changed by the shift} ≤ 2Σ_{u∈U}(n − f(u)) + 3·C(|B(u₀)|, 2)`. -/ theorem cor117 {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (U : Finset ℝ) {u₀ : ℝ} (hU : ∀ u ∈ U, u < u₀) : ∑ u ∈ U, ((chgO v u).card + 2 * (chO v u).card) ≤ 4 * n * U.card + 3 * ((thinB v u₀).card * (thinB v u₀).card - (thinB v u₀).card) := by classical have h1 : ∑ u ∈ U, ((chgO v u).card + 2 * (chO v u).card) ≤ ∑ u ∈ U, (4 * n + 3 * (midO v u).card) := sum_le_sum (fun u _ => lemma116 hn hv hH0 u) have h2 : ∑ u ∈ U, (4 * n + 3 * (midO v u).card) = 4 * n * U.card + 3 * ∑ u ∈ U, (midO v u).card := by rw [sum_add_distrib, sum_const, smul_eq_mul, ← mul_sum] ring have hdisj : (U : Set ℝ).PairwiseDisjoint (midO v) := by intro u _ u' _ huu' refine disjoint_left.mpr (fun p hp hp' => huu' ?_) unfold midO at hp hp' rw [← (mem_chO.mp (mem_filter.mp hp).1).2, (mem_chO.mp (mem_filter.mp hp').1).2] have h3 : ∑ u ∈ U, (midO v u).card ≤ ((thinB v u₀).offDiag).card := by rw [← card_biUnion hdisj] apply card_le_card intro p hp obtain ⟨u, hu, hp'⟩ := mem_biUnion.mp hp exact midO_sub_thin hv (hU u hu) hp' rw [offDiag_card] at h3 omega end Erdos94ThmA /-! ### (F9) INVERSE §0 coherent classes and Lemma 2.3 (coherent near-full classes ⇒ the shift is an almost-isometry) -/ namespace Erdos94ThmA open Finset /-- **Coherent class** (INVERSE §0): the distance `u` is coherent with defect `≤ δn` via `(A, T)` if `|V ∖ A| ≤ δn`, `T` is injective on `A` and preserves the cyclic order of `A` (`cyc a b c → cyc (T a) (T b) (T c)` for `a, b, c ∈ A`), `|v_x v_{T x}| = u` for `x ∈ A`, and the chords `{x, T x}` (`x ∈ A`) are proper (`T x ≠ x`) and pairwise distinct (no `x ≠ x'` in `A` with `T x = x'` and `T x' = x`). -/ def Coherent {n : ℕ} (v : ZMod n → ℂ) (u δ : ℝ) (A : Finset (ZMod n)) (T : ZMod n → ZMod n) : Prop := ((n : ℝ) - A.card ≤ δ * n) ∧ Set.InjOn T A ∧ (∀ a ∈ A, ∀ b ∈ A, ∀ c ∈ A, cyc a b c → cyc (T a) (T b) (T c)) ∧ (∀ x ∈ A, dist (v x) (v (T x)) = u) ∧ (∀ x ∈ A, T x ≠ x) ∧ (∀ x ∈ A, ∀ x' ∈ A, x ≠ x' → ¬ (T x = x' ∧ T x' = x)) open Classical in /-- The ordered chords `(x, T x)`, `(T x, x)` with `x, x + 1 ∈ A`, `T(x+1) = T x + 1` keep their length under the shift; there are exactly `2·#{such x}` of them. -/ theorem coh_pres {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {u δ : ℝ} {A : Finset (ZMod n)} {T : ZMod n → ZMod n} (h : Coherent v u δ A T) : let G := A.filter (fun x => x + 1 ∈ A ∧ T (x + 1) = T x + 1) (G.image (fun x => (x, T x)) ∪ G.image (fun x => (T x, x))).card = 2 * G.card ∧ G.image (fun x => (x, T x)) ∪ G.image (fun x => (T x, x)) ⊆ ((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) = dist (v p.1) (v p.2) ∧ dist (v p.1) (v p.2) = u) := by intro G obtain ⟨_, _, _, hd, hfix, h2⟩ := h refine ⟨?_, ?_⟩ · have hdisj : Disjoint (G.image (fun x => (x, T x))) (G.image (fun x => (T x, x))) := by rw [disjoint_left] intro p hp hp' obtain ⟨x, hx, rfl⟩ := mem_image.mp hp obtain ⟨x', hx', he⟩ := mem_image.mp hp' have hxA := (mem_filter.mp hx).1 have hx'A := (mem_filter.mp hx').1 simp only [Prod.mk.injEq] at he by_cases hxx : x = x' · subst hxx exact hfix x hxA he.1 · exact h2 x hxA x' hx'A hxx ⟨he.2.symm, he.1⟩ rw [card_union_of_disjoint hdisj, card_image_of_injective _ (fun a b hab => by simpa using congrArg Prod.fst hab), card_image_of_injective _ (fun a b hab => by simpa using congrArg Prod.snd hab)] ring · intro p hp rw [mem_filter] refine ⟨mem_product.mpr ⟨mem_univ _, mem_univ _⟩, ?_⟩ rcases mem_union.mp hp with hp | hp · obtain ⟨x, hx, rfl⟩ := mem_image.mp hp obtain ⟨hxA, hx1, hTx⟩ := mem_filter.mp hx refine ⟨fun h' => hfix x hxA h'.symm, ?_, hd x hxA⟩ rw [← hTx, hd x hxA, hd (x + 1) hx1] · obtain ⟨x, hx, rfl⟩ := mem_image.mp hp obtain ⟨hxA, hx1, hTx⟩ := mem_filter.mp hx refine ⟨fun h' => hfix x hxA h', ?_, by rw [dist_comm]; exact hd x hxA⟩ rw [← hTx, dist_comm, hd (x + 1) hx1, dist_comm, hd x hxA] open Classical in /-- **INVERSE Lemma 2.3** (ordered pairs). Let `U` be a set of `≥ (1/2 − ε)n` distances, each coherent with defect `≤ δn` (`0 ≤ ε, δ`). Then at most `2(ε + 2δ)n² + n` ordered pairs `(a, b)`, `a ≠ b`, have `|v_{a+1} v_{b+1}| ≠ |v_a v_b|` (i.e. the unordered set `B` of the paper has `|B| ≤ (ε + 2δ)n² + n/2`). -/ theorem lemma23 {n : ℕ} [NeZero n] (hn : 3 ≤ n) (v : ZMod n → ℂ) (U : Finset ℝ) (A : ℝ → Finset (ZMod n)) (T : ℝ → ZMod n → ZMod n) {ε δ : ℝ} (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (hU : (1 / 2 - ε) * n ≤ U.card) (hcoh : ∀ u ∈ U, Coherent v u δ (A u) (T u)) : ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) ≠ dist (v p.1) (v p.2))).card : ℝ) ≤ 2 * (ε + 2 * δ) * n ^ 2 + n := by have hnR : (3 : ℝ) ≤ n := by exact_mod_cast hn -- changed + preserved = all ordered pairs with distinct entries have hsplit := card_filter_add_card_filter_not (s := ((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2)) (fun p => dist (v (p.1 + 1)) (v (p.2 + 1)) = dist (v p.1) (v p.2)) rw [filter_filter, filter_filter] at hsplit have hoff : (((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2)).card = n * n - n := by have : ((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2) = (univ : Finset (ZMod n)).offDiag := by ext p simp [mem_offDiag] rw [this, offDiag_card, card_univ, ZMod.card] -- the preserved pairs contain the disjoint union of the families `S u` obtain ⟨G, hG⟩ : ∃ G : ℝ → Finset (ZMod n), G = fun u => (A u).filter (fun x => x + 1 ∈ A u ∧ T u (x + 1) = T u x + 1) := ⟨_, rfl⟩ obtain ⟨S, hS⟩ : ∃ S : ℝ → Finset (ZMod n × ZMod n), S = fun u => (G u).image (fun x => (x, T u x)) ∪ (G u).image (fun x => (T u x, x)) := ⟨_, rfl⟩ have hSu : ∀ u ∈ U, (S u).card = 2 * (G u).card ∧ S u ⊆ ((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) = dist (v p.1) (v p.2) ∧ dist (v p.1) (v p.2) = u) := by intro u hu rw [hS, hG] exact coh_pres (hcoh u hu) have hdisj : (U : Set ℝ).PairwiseDisjoint S := by intro u hu u' hu' huu' refine disjoint_left.mpr (fun p hp hp' => huu' ?_) have h1 := (mem_filter.mp ((hSu u hu).2 hp)).2.2.2 have h2 := (mem_filter.mp ((hSu u' hu').2 hp')).2.2.2 rw [← h1, h2] have hpres : ∑ u ∈ U, 2 * (G u).card ≤ (((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) = dist (v p.1) (v p.2))).card := by rw [← sum_congr rfl (fun u hu => (hSu u hu).1), ← card_biUnion hdisj] apply card_le_card intro p hp obtain ⟨u, hu, hp'⟩ := mem_biUnion.mp hp have := mem_filter.mp ((hSu u hu).2 hp') exact mem_filter.mpr ⟨this.1, this.2.1, this.2.2.1⟩ -- Lemma 2.2 for each class have hGu : ∀ u ∈ U, (n : ℝ) - 3 * (δ * n) ≤ (G u).card := by intro u hu obtain ⟨hdef, hinj, hcyc, _, _, _⟩ := hcoh u hu have h22 := cyc_consecutive hn (A u) (T u) hinj hcyc have hAle : (A u).card ≤ n := by have := card_le_univ (A u) rwa [ZMod.card] at this rw [hG] have : ((n - (A u).card : ℕ) : ℝ) = n - (A u).card := by rw [Nat.cast_sub hAle] have h22' : (n : ℝ) ≤ ((A u).filter (fun x => x + 1 ∈ A u ∧ T u (x + 1) = T u x + 1)).card + 3 * ((n - (A u).card : ℕ) : ℝ) := by exact_mod_cast h22 rw [this] at h22' linarith have hsum : (U.card : ℝ) * ((n : ℝ) - 3 * (δ * n)) ≤ ∑ u ∈ U, ((G u).card : ℝ) := by have := sum_le_sum hGu rwa [sum_const, nsmul_eq_mul] at this have hpresR : 2 * ∑ u ∈ U, ((G u).card : ℝ) ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) = dist (v p.1) (v p.2))).card : ℝ) := by rw [mul_sum] exact_mod_cast hpres have hsplitR : ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) ≠ dist (v p.1) (v p.2))).card : ℝ) + ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) = dist (v p.1) (v p.2))).card : ℝ) = (n : ℝ) * n - n := by have hle : n ≤ n * n := Nat.le_mul_self n have := hsplit rw [hoff] at this have hc : ((n * n - n : ℕ) : ℝ) = (n : ℝ) * n - n := by rw [Nat.cast_sub hle, Nat.cast_mul] rw [← hc] exact_mod_cast (by rw [add_comm]; exact this) -- arithmetic have hP0 : (0 : ℝ) ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) = dist (v p.1) (v p.2))).card : ℝ) := Nat.cast_nonneg _ have hn2 : (0 : ℝ) ≤ (n : ℝ) ^ 2 := sq_nonneg _ have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg _ have hG0 : (0 : ℝ) ≤ ∑ u ∈ U, ((G u).card : ℝ) := sum_nonneg (fun u _ => Nat.cast_nonneg _) by_cases hδ3 : 1 ≤ 3 * δ · linarith [mul_nonneg (show (0:ℝ) ≤ 4 * δ - 1 by linarith) hn2, mul_nonneg hε hn2] · by_cases hε2 : 1 / 2 ≤ ε · linarith [mul_nonneg (show (0:ℝ) ≤ 2 * ε - 1 by linarith) hn2, mul_nonneg hδ hn2] · push_neg at hδ3 hε2 have hpos : 0 ≤ (n : ℝ) - 3 * (δ * n) := by nlinarith have h1 : (1 / 2 - ε) * n * ((n : ℝ) - 3 * (δ * n)) ≤ (U.card : ℝ) * ((n : ℝ) - 3 * (δ * n)) := mul_le_mul_of_nonneg_right hU hpos linarith [mul_nonneg hδ hn2, mul_nonneg (mul_nonneg hε hδ) hn2] end Erdos94ThmA /-! ### (F10) INVERSE Theorem 11.9′, part 1: changed pairs inside a window, the defect `def′` of §11.16(a), and the global budgets -/ namespace Erdos94ThmA open Finset open Classical in /-- Ordered pairs of `W` with distinct entries whose length the index shift changes. -/ noncomputable def chgW {n : ℕ} (v : ZMod n → ℂ) (W : Finset (ZMod n)) : Finset (ZMod n × ZMod n) := (W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v (p.1 + 1)) (v (p.2 + 1)) ≠ dist (v p.1) (v p.2)) open Classical in /-- The defect `def′(y)` of §11.16(a): the number of classes `u ∈ U` for which `y` is not in the domain `A_u` of `T_u`, plus the number for which `y` is not in its image `T_u(A_u)`. -/ noncomputable def defc {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) (y : ZMod n) : ℕ := (U.filter (fun u => y ∉ Au v u)).card + (U.filter (fun u => y ∉ (Au v u).image (Tu v u))).card /-- Every short `u`-chord is a `T`-chord: `#chO ≤ 2|A_u| + #midO` (from the proof of Lemma 11.6). -/ theorem chO_le_Au {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (u : ℝ) : (chO v u).card ≤ 2 * (Au v u).card + (midO v u).card := by classical have hshort : (chO v u).filter (fun p => isShort v p.1 p.2) ⊆ (Au v u).image (fun x => (x, Tu v u x)) ∪ (Au v u).image (fun x => (Tu v u x, x)) := by intro p hp obtain ⟨hp1, hs⟩ := mem_filter.mp hp obtain ⟨_, hd⟩ := mem_chO.mp hp1 rw [mem_union, mem_image, mem_image] rcases hs with h | h · left exact ⟨p.1, mem_Au.mpr ⟨p.2, h, hd⟩, by rw [Tu_unique hv h hd]⟩ · right rw [inB_iff_inF hv] at h have hd' : dist (v p.2) (v p.1) = u := by rw [dist_comm]; exact hd exact ⟨p.2, mem_Au.mpr ⟨p.1, h, hd'⟩, by rw [Tu_unique hv h hd']⟩ have h1 := card_le_card hshort have h2 := card_union_le ((Au v u).image (fun x => (x, Tu v u x))) ((Au v u).image (fun x => (Tu v u x, x))) have h3 : ((Au v u).image (fun x => (x, Tu v u x))).card ≤ (Au v u).card := card_image_le have h4 : ((Au v u).image (fun x => (Tu v u x, x))).card ≤ (Au v u).card := card_image_le have hs1 := card_filter_add_card_filter_not (s := chO v u) (fun p => isShort v p.1 p.2) have hm1 : ((chO v u).filter (fun p => ¬ isShort v p.1 p.2)).card = (midO v u).card := rfl omega open Classical in /-- Inside a window `W` (with `x + 1 ∈ W⁺` for `x ∈ W`), the bad `x ∈ A_u` whose chord `{x, T x}` lies in `W` number at most `#{y ∈ W⁺ : y ∉ A_u} + #{y ∈ W⁺ : y ∉ T_u(A_u)}`: the witness is `x + 1` (non-domain) or the first gap vertex `T x + 1` (non-image, Lemma 11.5). -/ theorem bad_in_window {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (u : ℝ) (W Wp : Finset (ZMod n)) (hWp : ∀ x ∈ W, x + 1 ∈ Wp) : ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).card ≤ (Wp.filter (fun y => y ∉ Au v u)).card + (Wp.filter (fun y => y ∉ (Au v u).image (Tu v u))).card := by have hH : ∀ y : ZMod n, ¬ inF v (y + 1) y := fun y => by have := hH0 (y + 1) rwa [add_sub_cancel_right] at this have h1 : (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).filter (fun x => x + 1 ∉ Au v u)).card ≤ (Wp.filter (fun y => y ∉ Au v u)).card := by refine card_le_card_of_injOn (fun x => x + 1) (fun x hx => ?_) (fun x _ y _ h => ?_) · obtain ⟨hxB, hx1⟩ := mem_filter.mp hx obtain ⟨_, hxW, _, _⟩ := mem_filter.mp hxB exact mem_filter.mpr ⟨hWp x hxW, hx1⟩ · simpa using h have h2 : (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).filter (fun x => ¬ x + 1 ∉ Au v u)).card ≤ (Wp.filter (fun y => y ∉ (Au v u).image (Tu v u))).card := by refine card_le_card_of_injOn (fun x => Tu v u x + 1) (fun x hx => ?_) (fun x hx y hy h => ?_) · obtain ⟨hxB, hx1⟩ := mem_filter.mp hx obtain ⟨hxA, _, hTW, hbad⟩ := mem_filter.mp hxB have hx1A : x + 1 ∈ Au v u := not_not.mp hx1 have hne : Tu v u (x + 1) ≠ Tu v u x + 1 := fun h' => hbad ⟨hx1A, h'⟩ have hmono := Tu_off_mono hn hv hxA hx1A have hlt : (Tu v u x - x).val < (Tu v u (x + 1) - (x + 1)).val := by rcases hmono.1.lt_or_eq with h | h · exact h · exact absurd (hmono.2.mp h) hne obtain ⟨_, hKk, _⟩ := Tu_succ_off hn hv hxA hx1A (hH x) have hcyc : cyc (Tu v u x) (Tu v u x + 1) (Tu v u (x + 1)) := by refine ⟨?_, ?_⟩ · rw [add_sub_cancel_left, val_one_of_three hn] norm_num · rw [add_sub_cancel_left, val_one_of_three hn, hKk] omega refine mem_filter.mpr ⟨hWp _ hTW, ?_⟩ rw [mem_image] rintro ⟨w, hw, hwz⟩ exact Tu_gap hn hv hxA hx1A (hH x) hcyc hw hwz · have hx' := (mem_filter.mp (mem_filter.mp hx).1).1 have hy' := (mem_filter.mp (mem_filter.mp hy).1).1 have h' : Tu v u x = Tu v u y := by simpa using h exact Tu_injOn hv u (mem_coe.mpr hx') (mem_coe.mpr hy') h' have hs := card_filter_add_card_filter_not (s := (Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (fun x => x + 1 ∉ Au v u) omega open Classical in /-- Double counting the defects over a vertex set. -/ theorem sum_defc {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) (S : Finset (ZMod n)) : ∑ y ∈ S, defc v U y = ∑ u ∈ U, ((S.filter (fun y => y ∉ Au v u)).card + (S.filter (fun y => y ∉ (Au v u).image (Tu v u))).card) := by unfold defc rw [sum_add_distrib, sum_add_distrib] congr 1 · simp only [card_filter] exact sum_comm · simp only [card_filter] exact sum_comm open Classical in /-- **The window decomposition** (proof of Theorem 11.9′ with the §11.16(a) matching bound). If all pairs of `W` are shorter than `u₀` and `x + 1 ∈ W⁺` for `x ∈ W`, then the changed ordered pairs of `W` number at most (pairs of `W` outside the classes `U`) + (ordered pairs of thin vertices of `W`) + `2Σ_{y ∈ W⁺} def′(y)`, the defect taken over the classes of `U` below `u₀`. -/ theorem chgW_le {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (U : Finset ℝ) {u₀ : ℝ} (W Wp : Finset (ZMod n)) (hWp : ∀ x ∈ W, x + 1 ∈ Wp) (hspan : ∀ a ∈ W, ∀ b ∈ W, dist (v a) (v b) < u₀) : (chgW v W).card ≤ ((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card + ((W ∩ thinB v u₀).offDiag).card + 2 * ∑ y ∈ Wp, defc v (U.filter (fun u => u < u₀)) y := by -- the bad sets per class have hsub : chgW v W ⊆ ((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)) ∪ (W ∩ thinB v u₀).offDiag ∪ (U.filter (fun u => u < u₀)).biUnion (fun u => ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))) := by intro p hp unfold chgW at hp obtain ⟨hpW, hne, hch⟩ := mem_filter.mp hp obtain ⟨h1W, h2W⟩ := mem_product.mp hpW by_cases hU : dist (v p.1) (v p.2) ∈ U · have hu0 := hspan _ h1W _ h2W by_cases hs : isShort v p.1 p.2 · refine mem_union_right _ (mem_biUnion.mpr ⟨dist (v p.1) (v p.2), mem_filter.mpr ⟨hU, hu0⟩, ?_⟩) rw [mem_union, mem_image, mem_image] rcases hs with h | h · left have hT := Tu_unique hv h rfl refine ⟨p.1, mem_filter.mpr ⟨mem_Au.mpr ⟨p.2, h, rfl⟩, h1W, by rw [hT]; exact h2W, ?_⟩, by rw [hT]⟩ rintro ⟨h1, h2⟩ apply hch have := (Tu_spec h1).2 rw [h2, hT] at this exact this · right rw [inB_iff_inF hv] at h have hd' : dist (v p.2) (v p.1) = dist (v p.1) (v p.2) := dist_comm _ _ have hT := Tu_unique hv h hd' refine ⟨p.2, mem_filter.mpr ⟨mem_Au.mpr ⟨p.1, h, hd'⟩, h2W, by rw [hT]; exact h1W, ?_⟩, by rw [hT]⟩ rintro ⟨h1, h2⟩ apply hch have := (Tu_spec h1).2 rw [h2, hT, dist_comm] at this exact this · refine mem_union_left _ (mem_union_right _ ?_) have hmid : p ∈ midO v (dist (v p.1) (v p.2)) := by unfold midO exact mem_filter.mpr ⟨mem_chO.mpr ⟨hne, rfl⟩, hs⟩ have := midO_sub_thin hv hu0 hmid rw [mem_offDiag] at this ⊢ exact ⟨mem_inter.mpr ⟨h1W, this.1⟩, mem_inter.mpr ⟨h2W, this.2.1⟩, hne⟩ · exact mem_union_left _ (mem_union_left _ (mem_filter.mpr ⟨hpW, hne, hU⟩)) have hcard := card_le_card hsub have hu1 := card_union_le (((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)) ∪ (W ∩ thinB v u₀).offDiag) ((U.filter (fun u => u < u₀)).biUnion (fun u => ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x)))) have hu2 := card_union_le ((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)) (W ∩ thinB v u₀).offDiag have hb := card_biUnion_le (s := U.filter (fun u => u < u₀)) (t := fun u => ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))) have hper : ∀ u ∈ U.filter (fun u => u < u₀), (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))).card ≤ 2 * ((Wp.filter (fun y => y ∉ Au v u)).card + (Wp.filter (fun y => y ∉ (Au v u).image (Tu v u))).card) := by intro u _ have hbw := bad_in_window hn hv hH0 u W Wp hWp have := card_union_le (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x))) (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))) have h1 := card_image_le (s := (Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (f := fun x => (x, Tu v u x)) have h2 := card_image_le (s := (Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (f := fun x => (Tu v u x, x)) omega have hsum := sum_le_sum hper rw [← mul_sum, ← sum_defc] at hsum omega open Classical in /-- The global defect budget (§11.16(a)): `Σ_y def′(y) + Σ_{u ∈ U, u < u₀} #chO u ≤ 2n·|U_{ u < u₀)) y + ∑ u ∈ U.filter (fun u => u < u₀), (chO v u).card ≤ 2 * n * (U.filter (fun u => u < u₀)).card + ((thinB v u₀).card * (thinB v u₀).card - (thinB v u₀).card) := by have hcardU : (univ : Finset (ZMod n)).card = n := ZMod.card n rw [sum_defc] have hper : ∀ u ∈ U.filter (fun u => u < u₀), ((univ.filter (fun y => y ∉ Au v u)).card + (univ.filter (fun y => y ∉ (Au v u).image (Tu v u))).card) + (chO v u).card ≤ 2 * n + (midO v u).card := by intro u _ have h1 := card_filter_add_card_filter_not (s := (univ : Finset (ZMod n))) (fun y => y ∈ Au v u) have h2 := card_filter_add_card_filter_not (s := (univ : Finset (ZMod n))) (fun y => y ∈ (Au v u).image (Tu v u)) have e1 : (univ.filter (fun y => y ∈ Au v u)).card = (Au v u).card := by rw [filter_mem_eq_inter, univ_inter] have e2 : (univ.filter (fun y => y ∈ (Au v u).image (Tu v u))).card = (Au v u).card := by rw [filter_mem_eq_inter, univ_inter, card_image_of_injOn (Tu_injOn hv u)] have h3 := chO_le_Au hv u omega have hs := sum_le_sum hper simp only [sum_add_distrib, sum_const, smul_eq_mul] at hs ⊢ have hdisj : ((U.filter (fun u => u < u₀)) : Set ℝ).PairwiseDisjoint (midO v) := by intro u _ u' _ huu' refine disjoint_left.mpr (fun p hp hp' => huu' ?_) unfold midO at hp hp' rw [← (mem_chO.mp (mem_filter.mp hp).1).2, (mem_chO.mp (mem_filter.mp hp').1).2] have h3 : ∑ u ∈ U.filter (fun u => u < u₀), (midO v u).card ≤ ((thinB v u₀).offDiag).card := by rw [← card_biUnion hdisj] apply card_le_card intro p hp obtain ⟨u, hu, hp'⟩ := mem_biUnion.mp hp exact midO_sub_thin hv (mem_filter.mp hu).2 hp' rw [offDiag_card] at h3 have : (U.filter (fun u => u < u₀)).card * (2 * n) = 2 * n * (U.filter (fun u => u < u₀)).card := by ring omega open Classical in /-- Ordered pairs outside the classes `U` and the `U`-chords partition the off-diagonal pairs. -/ theorem ptot_eq {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) : (((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card + ∑ u ∈ U, (chO v u).card = n * n - n := by have hoff : (((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2)).card = n * n - n := by have : ((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2) = (univ : Finset (ZMod n)).offDiag := by ext p simp [mem_offDiag] rw [this, offDiag_card, card_univ, ZMod.card] have hdisj : (U : Set ℝ).PairwiseDisjoint (chO v) := by intro u _ u' _ huu' refine disjoint_left.mpr (fun p hp hp' => huu' ?_) rw [← (mem_chO.mp hp).2, (mem_chO.mp hp').2] have hU : ∑ u ∈ U, (chO v u).card = (((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∈ U)).card := by rw [← card_biUnion hdisj] congr 1 ext p simp only [mem_biUnion, mem_chO, mem_filter, mem_product, mem_univ, true_and] constructor · rintro ⟨u, hu, hne, hd⟩ exact ⟨hne, hd ▸ hu⟩ · rintro ⟨hne, hd⟩ exact ⟨_, hd, hne, rfl⟩ have hs := card_filter_add_card_filter_not (s := ((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2)) (fun p => dist (v p.1) (v p.2) ∈ U) rw [filter_filter, filter_filter, hoff] at hs rw [hU] omega end Erdos94ThmA /-! ### (F11) INVERSE Theorem 11.9′, part 2: window counting, one rotation per good window, gluing; the theorem for an arbitrary family of windows -/ namespace Erdos94ThmA open Finset open Classical in /-- Double counting over a family of windows in which every vertex lies in at most `M` windows (pairs version). -/ theorem sum_mult_le {n : ℕ} {α : Type*} (K M : ℕ) (Wf : ℕ → Finset (ZMod n)) (S : Finset α) (g : α → ZMod n) (hM : ∀ y : ZMod n, ((range K).filter (fun k => y ∈ Wf k)).card ≤ M) : ∑ k ∈ range K, (S.filter (fun p => g p ∈ Wf k)).card ≤ M * S.card := by calc ∑ k ∈ range K, (S.filter (fun p => g p ∈ Wf k)).card = ∑ k ∈ range K, ∑ p ∈ S, if g p ∈ Wf k then 1 else 0 := by refine sum_congr rfl (fun k _ => ?_) rw [card_filter] _ = ∑ p ∈ S, ∑ k ∈ range K, if g p ∈ Wf k then 1 else 0 := sum_comm _ = ∑ p ∈ S, ((range K).filter (fun k => g p ∈ Wf k)).card := by refine sum_congr rfl (fun p _ => ?_) rw [card_filter] _ ≤ ∑ p ∈ S, M := sum_le_sum (fun p _ => hM (g p)) _ = M * S.card := by rw [sum_const, smul_eq_mul, mul_comm] open Classical in /-- Double counting over a family of windows (vertex-weighted version). -/ theorem sum_mult_le' {n : ℕ} [NeZero n] (K M : ℕ) (Wf : ℕ → Finset (ZMod n)) (f : ZMod n → ℕ) (hM : ∀ y : ZMod n, ((range K).filter (fun k => y ∈ Wf k)).card ≤ M) : ∑ k ∈ range K, ∑ y ∈ Wf k, f y ≤ M * ∑ y, f y := by calc ∑ k ∈ range K, ∑ y ∈ Wf k, f y = ∑ k ∈ range K, ∑ y, if y ∈ Wf k then f y else 0 := by refine sum_congr rfl (fun k _ => ?_) rw [← sum_filter] congr 1 ext y simp _ = ∑ y, ∑ k ∈ range K, if y ∈ Wf k then f y else 0 := sum_comm _ = ∑ y, ((range K).filter (fun k => y ∈ Wf k)).card * f y := by refine sum_congr rfl (fun y _ => ?_) rw [← sum_filter, sum_const, smul_eq_mul] _ ≤ ∑ y, M * f y := sum_le_sum (fun y _ => Nat.mul_le_mul_right _ (hM y)) _ = M * ∑ y, f y := by rw [mul_sum] /-- **Lemma 11.3 applied to a good window**: if at most `2β|W|²` ordered pairs of `W` change length under the shift, the shift agrees on all but `6√β|W|` vertices of `W` with one rotation `z ↦ ωz + t`, `|ω| = 1`, `ω ≠ 1`. -/ theorem good_window_rot {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (hT : ∀ t : ℂ, t ≠ 0 → ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) (W : Finset (ZMod n)) (hW7 : 7 ≤ W.card) {β : ℝ} (hβ0 : 0 < β) (hβ : β ≤ 1 / 100) (hgood : ((chgW v W).card : ℝ) ≤ 2 * β * (W.card : ℝ) ^ 2) : ∃ ω t : ℂ, ‖ω‖ = 1 ∧ ω ≠ 1 ∧ ((W.filter (fun x => v (x + 1) ≠ ω * v x + t)).card : ℝ) ≤ 6 * Real.sqrt β * W.card := by classical have hcyc : ∀ a ∈ W, ∀ b ∈ W, ∀ c ∈ W, cyc a b c → cyc (a + 1) (b + 1) (c + 1) := by intro a _ b _ c _ h unfold cyc at h ⊢ rw [show b + 1 - (a + 1) = b - a by ring, show c + 1 - (a + 1) = c - a by ring] exact h have hB : (((W ×ˢ W).filter (fun p => dist (v (p.1 + 1)) (v (p.2 + 1)) ≠ dist (v p.1) (v p.2))).card : ℝ) ≤ 2 * β * (W.card : ℝ) ^ 2 := by refine le_trans ?_ hgood exact_mod_cast card_le_card (fun p hp => by obtain ⟨hpW, hd⟩ := mem_filter.mp hp unfold chgW refine mem_filter.mpr ⟨hpW, fun h => hd ?_, hd⟩ rw [h, dist_self, dist_self]) have hTW : ∀ t : ℂ, t ≠ 0 → (W.filter (fun x : ZMod n => ∃ y, v y = v x + t)).card ≤ 2 := fun t ht => le_trans (card_le_card (filter_subset_filter _ (subset_univ W))) (hT t ht) obtain ⟨ω, t, h1, h2, _, h4⟩ := rigidityW W hW7 hv hvi (fun x => x + 1) hcyc hβ0 hβ hB hTW exact ⟨ω, t, h1, h4 (fun x _ => succ_ne_self hn x), h2⟩ open Classical in /-- **Gluing** (Lemma 11.3, second half): two windows whose exceptional sets are smaller than their overlap minus two carry the same rotation. -/ theorem glue_rot {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hvi : Function.Injective v) {W W' : Finset (ZMod n)} {ω t ω' t' : ℂ} {e e' : ℝ} (h1 : ((W.filter (fun x => v (x + 1) ≠ ω * v x + t)).card : ℝ) ≤ e) (h2 : ((W'.filter (fun x => v (x + 1) ≠ ω' * v x + t')).card : ℝ) ≤ e') (hov : e + e' + 2 ≤ ((W ∩ W').card : ℝ)) : ω = ω' ∧ t = t' := by have hsub : (W ∩ W') ⊆ (W ∩ W').filter (fun x => v (x + 1) = ω * v x + t ∧ v (x + 1) = ω' * v x + t') ∪ (W.filter (fun x => v (x + 1) ≠ ω * v x + t) ∪ W'.filter (fun x => v (x + 1) ≠ ω' * v x + t')) := by intro x hx obtain ⟨hxW, hxW'⟩ := mem_inter.mp hx by_cases ha : v (x + 1) = ω * v x + t · by_cases hb : v (x + 1) = ω' * v x + t' · exact mem_union_left _ (mem_filter.mpr ⟨hx, ha, hb⟩) · exact mem_union_right _ (mem_union_right _ (mem_filter.mpr ⟨hxW', hb⟩)) · exact mem_union_right _ (mem_union_left _ (mem_filter.mpr ⟨hxW, ha⟩)) have hc := card_le_card hsub have hc2 := card_union_le ((W ∩ W').filter (fun x => v (x + 1) = ω * v x + t ∧ v (x + 1) = ω' * v x + t')) (W.filter (fun x => v (x + 1) ≠ ω * v x + t) ∪ W'.filter (fun x => v (x + 1) ≠ ω' * v x + t')) have hc3 := card_union_le (W.filter (fun x => v (x + 1) ≠ ω * v x + t)) (W'.filter (fun x => v (x + 1) ≠ ω' * v x + t')) have hN : (W ∩ W').card ≤ ((W ∩ W').filter (fun x => v (x + 1) = ω * v x + t ∧ v (x + 1) = ω' * v x + t')).card + (W.filter (fun x => v (x + 1) ≠ ω * v x + t)).card + (W'.filter (fun x => v (x + 1) ≠ ω' * v x + t')).card := by omega have hNR : ((W ∩ W').card : ℝ) ≤ (((W ∩ W').filter (fun x => v (x + 1) = ω * v x + t ∧ v (x + 1) = ω' * v x + t')).card : ℝ) + ((W.filter (fun x => v (x + 1) ≠ ω * v x + t)).card : ℝ) + ((W'.filter (fun x => v (x + 1) ≠ ω' * v x + t')).card : ℝ) := by exact_mod_cast hN have hS : 1 < ((W ∩ W').filter (fun x => v (x + 1) = ω * v x + t ∧ v (x + 1) = ω' * v x + t')).card := by have : (1 : ℝ) < (((W ∩ W').filter (fun x => v (x + 1) = ω * v x + t ∧ v (x + 1) = ω' * v x + t')).card : ℝ) := by linarith exact_mod_cast this obtain ⟨x, hx, y, hy, hxy⟩ := one_lt_card.mp hS have hx' := (mem_filter.mp hx).2 have hy' := (mem_filter.mp hy).2 exact direct_iso_unique (fun h => hxy (hvi h)) (hx'.1.symm.trans hx'.2) (hy'.1.symm.trans hy'.2) /-- The arithmetic of Theorem 11.9′ (window count with thresholds `1.09βw²`, `0.01βw²`, `0.9βw²`). -/ theorem thm119_arith {n : ℝ} {w ε β lam Bc Uc xP xD : ℝ} (hn : 0 < n) (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hβ0 : 0 < β) (hlam0 : 0 < lam) (hlam : lam * n ≤ w) (hxP0 : 0 ≤ xP) (hxD0 : 0 ≤ xD) (hUc0 : 0 ≤ Uc) (hP : xP * (109 / 100 * β * w ^ 2) ≤ 6 * (3 * ε * n ^ 2)) (hD : xD * (9 / 10 * β * w ^ 2) ≤ 12 * (2 * ε * n * Uc + Bc ^ 2)) (hU : Uc * (2 * (1 - ε) * n) ≤ n ^ 2) : xP + xD ≤ (37 * ε + 24 * (Bc / n) ^ 2) / (β * lam ^ 2) := by have hw2 : lam ^ 2 * n ^ 2 ≤ w ^ 2 := by have h0 : 0 ≤ lam * n := by positivity have := pow_le_pow_left₀ h0 hlam 2 nlinarith have hU' : 2 * ε * n * Uc ≤ 100 / 99 * ε * n ^ 2 := by have h1 : 0 < 2 * (1 - ε) * n := by nlinarith have h2 : Uc ≤ n ^ 2 / (2 * (1 - ε) * n) := by rw [le_div_iff₀ h1]; linarith have h3 : n ^ 2 / (2 * (1 - ε) * n) ≤ 50 / 99 * n := by rw [div_le_iff₀ h1] nlinarith have h4 := mul_le_mul_of_nonneg_left (h2.trans h3) (by positivity : (0:ℝ) ≤ 2 * ε * n) nlinarith have hb : 0 < β * lam ^ 2 := by positivity rw [le_div_iff₀ hb] have hn2 : 0 < n ^ 2 := by positivity -- xP·βλ²n² ≤ xP·βw² and xD·βλ²n² ≤ xD·βw² have hP' : xP * (109 / 100 * β * (lam ^ 2 * n ^ 2)) ≤ 18 * ε * n ^ 2 := by have : xP * (109 / 100 * β * (lam ^ 2 * n ^ 2)) ≤ xP * (109 / 100 * β * w ^ 2) := by apply mul_le_mul_of_nonneg_left _ hxP0 nlinarith linarith have hD' : xD * (9 / 10 * β * (lam ^ 2 * n ^ 2)) ≤ 12 * (100 / 99 * ε * n ^ 2 + Bc ^ 2) := by have : xD * (9 / 10 * β * (lam ^ 2 * n ^ 2)) ≤ xD * (9 / 10 * β * w ^ 2) := by apply mul_le_mul_of_nonneg_left _ hxD0 nlinarith linarith have hBn : (Bc / n) ^ 2 * n ^ 2 = Bc ^ 2 := by field_simp -- divide by n² have hP'' : xP * (β * lam ^ 2) * n ^ 2 ≤ 18 * 100 / 109 * ε * n ^ 2 := by nlinarith have hD'' : xD * (β * lam ^ 2) * n ^ 2 ≤ (12 * 10 / 9) * (100 / 99 * ε * n ^ 2 + (Bc / n) ^ 2 * n ^ 2) := by rw [hBn] nlinarith have hP3 : xP * (β * lam ^ 2) ≤ 18 * 100 / 109 * ε := by by_contra hc push_neg at hc nlinarith have hD3 : xD * (β * lam ^ 2) ≤ (12 * 10 / 9) * (100 / 99 * ε + (Bc / n) ^ 2) := by by_contra hc push_neg at hc nlinarith have hν : 0 ≤ (Bc / n) ^ 2 := sq_nonneg _ nlinarith open Classical in /-- A window with more than `2βw²` changed pairs is bad for one of the three reasons. -/ theorem thm119_split (K : ℕ) (chg Pk Mk Dk : ℕ → ℕ) {β w : ℝ} (hdec : ∀ k < K, chg k ≤ Pk k + Mk k + Dk k) : (((range K).filter (fun k => 2 * β * w ^ 2 < (chg k : ℝ))).card : ℝ) ≤ (((range K).filter (fun k => 109 / 100 * β * w ^ 2 < (Pk k : ℝ))).card : ℝ) + (((range K).filter (fun k => 1 / 100 * β * w ^ 2 < (Mk k : ℝ))).card : ℝ) + (((range K).filter (fun k => 9 / 10 * β * w ^ 2 < (Dk k : ℝ))).card : ℝ) := by have hsub : (range K).filter (fun k => 2 * β * w ^ 2 < (chg k : ℝ)) ⊆ ((range K).filter (fun k => 109 / 100 * β * w ^ 2 < (Pk k : ℝ)) ∪ (range K).filter (fun k => 1 / 100 * β * w ^ 2 < (Mk k : ℝ))) ∪ (range K).filter (fun k => 9 / 10 * β * w ^ 2 < (Dk k : ℝ)) := by intro k hk obtain ⟨hkK, hk2⟩ := mem_filter.mp hk have hdR : (chg k : ℝ) ≤ (Pk k : ℝ) + (Mk k : ℝ) + (Dk k : ℝ) := by exact_mod_cast hdec k (mem_range.mp hkK) by_contra hc simp only [mem_union, mem_filter, not_or, not_and, not_lt] at hc have h1 := hc.1.1 hkK have h2 := hc.1.2 hkK have h3 := hc.2 hkK linarith have hcard := card_le_card hsub have hcu1 := card_union_le ((range K).filter (fun k => 109 / 100 * β * w ^ 2 < (Pk k : ℝ)) ∪ (range K).filter (fun k => 1 / 100 * β * w ^ 2 < (Mk k : ℝ))) ((range K).filter (fun k => 9 / 10 * β * w ^ 2 < (Dk k : ℝ))) have hcu2 := card_union_le ((range K).filter (fun k => 109 / 100 * β * w ^ 2 < (Pk k : ℝ))) ((range K).filter (fun k => 1 / 100 * β * w ^ 2 < (Mk k : ℝ))) exact_mod_cast (hcard.trans (hcu1.trans (by omega))) open Classical in /-- The pairs outside the classes `U`: at most `3εn²` ordered pairs in all. -/ theorem thm119_Ptot {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) : ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) ≤ 3 * ε * n ^ 2 ∧ ∑ u ∈ U, ((chO v u).card : ℝ) ≤ (n : ℝ) ^ 2 := by have hpt := ptot_eq v U have hle : n ≤ n * n := Nat.le_mul_self n have hptR : ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) + ∑ u ∈ U, ((chO v u).card : ℝ) = (n : ℝ) * n - n := by have hc : ((n * n - n : ℕ) : ℝ) = (n : ℝ) * n - n := by rw [Nat.cast_sub hle, Nat.cast_mul] rw [← hc, ← hpt] push_cast ring have hchU : (U.card : ℝ) * (2 * (1 - ε) * n) ≤ ∑ u ∈ U, ((chO v u).card : ℝ) := by have := sum_le_sum hU2 rwa [sum_const, nsmul_eq_mul] at this have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg _ have h2e : 0 ≤ 2 * (1 - ε) * (n : ℝ) := by nlinarith have hU1' := mul_le_mul_of_nonneg_right hU1 h2e have hP0 : (0 : ℝ) ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := Nat.cast_nonneg _ constructor · nlinarith · nlinarith open Classical in /-- Σ over the windows of the pairs of `W_k` outside the classes `U` is at most `18εn²`. -/ theorem thm119_Psum {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (K : ℕ) (Wf Wpf : ℕ → Finset (ZMod n)) (hWsub : ∀ k < K, Wf k ⊆ Wpf k) (hM : ∀ y : ZMod n, ((range K).filter (fun k => y ∈ Wpf k)).card ≤ 6) : ∑ k ∈ range K, ((((Wf k ×ˢ Wf k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℕ) : ℝ) ≤ 6 * (3 * ε * n ^ 2) := by have hPk' : ∀ k ∈ range K, ((Wf k ×ˢ Wf k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).filter (fun p => p.1 ∈ Wpf k)).card := by intro k hk apply card_le_card intro p hp obtain ⟨hpW, hp2⟩ := mem_filter.mp hp obtain ⟨h1, _⟩ := mem_product.mp hpW exact mem_filter.mpr ⟨mem_filter.mpr ⟨mem_product.mpr ⟨mem_univ _, mem_univ _⟩, hp2⟩, hWsub k (mem_range.mp hk) h1⟩ have hPsum := (sum_le_sum hPk').trans (sum_mult_le K 6 Wpf _ Prod.fst hM) have hR : ((∑ k ∈ range K, ((Wf k ×ˢ Wf k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℕ) : ℝ) ≤ 6 * ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := by exact_mod_cast hPsum push_cast at hR have := (thm119_Ptot v U hε0 hε1 hU1 hU2).1 linarith open Classical in /-- Σ over the windows of `2Σ_{y ∈ W_k⁺} def′(y)` is at most `12(2εn|U_{ y ∈ Wpf k)).card ≤ 6) : ∑ k ∈ range K, (((2 * ∑ y ∈ Wpf k, defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) ≤ 12 * (2 * ε * n * ((U.filter (fun u => u < u₀)).card : ℝ) + ((thinB v u₀).card : ℝ) ^ 2) := by have hDsum : ∑ k ∈ range K, 2 * ∑ y ∈ Wpf k, defc v (U.filter (fun u => u < u₀)) y ≤ 12 * ∑ y, defc v (U.filter (fun u => u < u₀)) y := by rw [← mul_sum] have := sum_mult_le' K 6 Wpf (defc v (U.filter (fun u => u < u₀))) hM omega have hdt := defc_total hv U u₀ have hchU' : ∑ u ∈ U.filter (fun u => u < u₀), (2 * (1 - ε) * (n : ℝ)) ≤ ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) := sum_le_sum (fun u hu => hU2 u (mem_filter.mp hu).1) rw [sum_const, nsmul_eq_mul] at hchU' have h1 : ((∑ y, defc v (U.filter (fun u => u < u₀)) y + ∑ u ∈ U.filter (fun u => u < u₀), (chO v u).card : ℕ) : ℝ) ≤ ((2 * n * (U.filter (fun u => u < u₀)).card + (thinB v u₀).card * (thinB v u₀).card : ℕ) : ℝ) := by exact_mod_cast hdt.trans (by omega) push_cast at h1 have h2 : ((∑ k ∈ range K, 2 * ∑ y ∈ Wpf k, defc v (U.filter (fun u => u < u₀)) y : ℕ) : ℝ) ≤ 12 * ((∑ y, defc v (U.filter (fun u => u < u₀)) y : ℕ) : ℝ) := by exact_mod_cast hDsum push_cast at h2 ⊢ nlinarith /-- A window with more than `βw²/100` ordered thin pairs has more than `βλ²n/16` thin vertices. -/ theorem thm119_Msub {n w β lam m c : ℝ} (hβ0 : 0 < β) (hβ : β ≤ 1 / 10000) (hlam0 : 0 < lam) (hlam : lam * n ≤ w) (hlam1 : lam ≤ 1) (hn : 0 ≤ n) (hc0 : 0 ≤ c) (hm : m ≤ c ^ 2) (hbig : 1 / 100 * β * w ^ 2 < m) : β * lam ^ 2 * n / 16 < c := by by_contra hc push_neg at hc have hsq : c ^ 2 ≤ (β * lam ^ 2 * n / 16) ^ 2 := pow_le_pow_left₀ hc0 hc 2 have hw2 : lam ^ 2 * n ^ 2 ≤ w ^ 2 := by have h0 : 0 ≤ lam * n := by positivity have := pow_le_pow_left₀ h0 hlam 2 nlinarith have h1 : β * lam ^ 2 ≤ 1 / 10000 := by nlinarith have h2 : 0 ≤ lam ^ 2 * n ^ 2 := by positivity have h3 : β * (β * lam ^ 2) * (lam ^ 2 * n ^ 2) ≤ β * (1 / 10000) * w ^ 2 := by apply mul_le_mul (mul_le_mul_of_nonneg_left h1 hβ0.le) hw2 h2 positivity have e : (β * lam ^ 2 * n / 16) ^ 2 = β * (β * lam ^ 2) * (lam ^ 2 * n ^ 2) / 256 := by ring nlinarith open Classical in /-- **The bad-window count of Theorem 11.9′** for an arbitrary family of windows `W_k ⊆ W_k⁺` (`k < K`) in which every vertex lies in at most `6` sets `W_k⁺`: the windows with more than `2βw²` changed ordered pairs number at most `N_B + (37ε + 24ν²)/(βλ²)`, `N_B := #{k : |W_k⁺ ∩ B(u₀)| > βλ²n/16}`, `ν := |B(u₀)|/n`. -/ theorem thm119_count {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (u₀ : ℝ) (K w : ℕ) (Wf Wpf : ℕ → Finset (ZMod n)) (hWsub : ∀ k < K, Wf k ⊆ Wpf k) (hWp : ∀ k < K, ∀ x ∈ Wf k, x + 1 ∈ Wpf k) (hspan : ∀ k < K, ∀ a ∈ Wf k, ∀ b ∈ Wf k, dist (v a) (v b) < u₀) (hM : ∀ y : ZMod n, ((range K).filter (fun k => y ∈ Wpf k)).card ≤ 6) {β lam : ℝ} (hβ0 : 0 < β) (hβ : β ≤ 1 / 10000) (hlam0 : 0 < lam) (hlam : lam * n ≤ w) (hlam1 : lam ≤ 1) : (((range K).filter (fun k => 2 * β * (w : ℝ) ^ 2 < (chgW v (Wf k)).card)).card : ℝ) ≤ ((range K).filter (fun k => β * lam ^ 2 * n / 16 < ((Wpf k ∩ thinB v u₀).card : ℝ))).card + (37 * ε + 24 * (((thinB v u₀).card : ℝ) / n) ^ 2) / (β * lam ^ 2) := by have hnR : (3 : ℝ) ≤ n := by exact_mod_cast hn have hw0 : (0 : ℝ) < w := by nlinarith have hsplit := thm119_split K (fun k => (chgW v (Wf k)).card) (fun k => ((Wf k ×ˢ Wf k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card) (fun k => ((Wf k ∩ thinB v u₀).offDiag).card) (fun k => 2 * ∑ y ∈ Wpf k, defc v (U.filter (fun u => u < u₀)) y) (β := β) (w := (w : ℝ)) (fun k hk => chgW_le hn hv hH0 U (Wf k) (Wpf k) (hWp k hk) (hspan k hk)) have hBP := markov_card (range K) (fun k => ((Wf k ×ˢ Wf k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card) (c := 109 / 100 * β * (w : ℝ) ^ 2) (by positivity) (thm119_Psum v U hε0 hε1 hU1 hU2 K Wf Wpf hWsub hM) have hBD := markov_card (range K) (fun k => 2 * ∑ y ∈ Wpf k, defc v (U.filter (fun u => u < u₀)) y) (c := 9 / 10 * β * (w : ℝ) ^ 2) (by positivity) (thm119_Dsum hv U hU2 u₀ K Wpf hM) have hBM : (range K).filter (fun k => 1 / 100 * β * (w : ℝ) ^ 2 < (((Wf k ∩ thinB v u₀).offDiag).card : ℝ)) ⊆ (range K).filter (fun k => β * lam ^ 2 * n / 16 < ((Wpf k ∩ thinB v u₀).card : ℝ)) := by intro k hk obtain ⟨hkK, hk2⟩ := mem_filter.mp hk refine mem_filter.mpr ⟨hkK, ?_⟩ have hm1 : ((Wf k ∩ thinB v u₀).offDiag).card ≤ (Wpf k ∩ thinB v u₀).card * (Wpf k ∩ thinB v u₀).card := by have hm2 : (Wf k ∩ thinB v u₀).card ≤ (Wpf k ∩ thinB v u₀).card := card_le_card (inter_subset_inter_right (hWsub k (mem_range.mp hkK))) rw [offDiag_card] exact (Nat.sub_le _ _).trans (Nat.mul_le_mul hm2 hm2) have hm3 : (((Wf k ∩ thinB v u₀).offDiag).card : ℝ) ≤ ((Wpf k ∩ thinB v u₀).card : ℝ) ^ 2 := by rw [sq] exact_mod_cast hm1 exact thm119_Msub hβ0 hβ hlam0 hlam hlam1 (Nat.cast_nonneg _) (Nat.cast_nonneg _) hm3 hk2 have hNB : (((range K).filter (fun k => 1 / 100 * β * (w : ℝ) ^ 2 < (((Wf k ∩ thinB v u₀).offDiag).card : ℝ))).card : ℝ) ≤ (((range K).filter (fun k => β * lam ^ 2 * n / 16 < ((Wpf k ∩ thinB v u₀).card : ℝ))).card : ℝ) := by exact_mod_cast card_le_card hBM have hUc : ((U.filter (fun u => u < u₀)).card : ℝ) * (2 * (1 - ε) * n) ≤ (n : ℝ) ^ 2 := by have h1 : ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) ≤ ∑ u ∈ U, ((chO v u).card : ℝ) := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun _ _ _ => Nat.cast_nonneg _) have h2 : ∑ u ∈ U.filter (fun u => u < u₀), (2 * (1 - ε) * (n : ℝ)) ≤ ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) := sum_le_sum (fun u hu => hU2 u (mem_filter.mp hu).1) rw [sum_const, nsmul_eq_mul] at h2 have := (thm119_Ptot v U hε0 hε1 hU1 hU2).2 linarith have harith := thm119_arith (n := (n : ℝ)) (w := (w : ℝ)) (by positivity) hε0 hε1 hβ0 hlam0 hlam (Nat.cast_nonneg _) (Nat.cast_nonneg _) (Nat.cast_nonneg ((U.filter (fun u => u < u₀)).card)) hBP hBD hUc linarith open Classical in /-- **INVERSE Theorem 11.9′ (localised one-rotation theorem) with the §11.16(a) correction, for an arbitrary family of windows.** `P` counterclockwise (`CCWPoly`, `n ≥ 3`), injective labelling, the translation lemma (T), (H₀) (as "no `F(y)` contains `y − 1`"); `U` a set of `≥ (1/2 − ε)n` distances with `f(u) ≥ (1 − ε)n` (`#chO = 2f`), `0 ≤ ε ≤ 1/100`; windows `W_k ⊆ W_k⁺` (`k < K`) of `w ≥ 7` vertices with `x + 1 ∈ W_k⁺` for `x ∈ W_k`, all pairs inside `W_k` shorter than `u₀`, every vertex in at most `6` sets `W_k⁺`; `0 < β ≤ 10⁻⁴`, `0 < λ ≤ 1`, `λn ≤ w`. A window is GOOD if at most `2βw²` ordered pairs of it change length under the shift (`βw²` unordered). Then (1) the bad windows number at most `N_B + (37ε + 24ν²)/(βλ²)` with `N_B = #{k : |W_k⁺ ∩ B(u₀)| > βλ²n/16}`, `ν = |B(u₀)|/n`; (2) on every good window the shift agrees with a rotation `R k` (`z ↦ ωz + t`, `|ω| = 1`, `ω ≠ 1`) off at most `6√β w` vertices; (3) two good windows overlapping in `≥ 12√β w + 2` vertices have the same rotation. -/ theorem thm119g {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (hT : ∀ t : ℂ, t ≠ 0 → ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (u₀ : ℝ) (K w : ℕ) (Wf Wpf : ℕ → Finset (ZMod n)) (hw7 : 7 ≤ w) (hcard : ∀ k < K, (Wf k).card = w) (hWsub : ∀ k < K, Wf k ⊆ Wpf k) (hWp : ∀ k < K, ∀ x ∈ Wf k, x + 1 ∈ Wpf k) (hspan : ∀ k < K, ∀ a ∈ Wf k, ∀ b ∈ Wf k, dist (v a) (v b) < u₀) (hM : ∀ y : ZMod n, ((range K).filter (fun k => y ∈ Wpf k)).card ≤ 6) {β lam : ℝ} (hβ0 : 0 < β) (hβ : β ≤ 1 / 10000) (hlam0 : 0 < lam) (hlam : lam * n ≤ w) (hlam1 : lam ≤ 1) : (((range K).filter (fun k => 2 * β * (w : ℝ) ^ 2 < (chgW v (Wf k)).card)).card : ℝ) ≤ ((range K).filter (fun k => β * lam ^ 2 * n / 16 < ((Wpf k ∩ thinB v u₀).card : ℝ))).card + (37 * ε + 24 * (((thinB v u₀).card : ℝ) / n) ^ 2) / (β * lam ^ 2) ∧ ∃ R : ℕ → ℂ × ℂ, (∀ k < K, ((chgW v (Wf k)).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 → ‖(R k).1‖ = 1 ∧ (R k).1 ≠ 1 ∧ (((Wf k).filter (fun x => v (x + 1) ≠ (R k).1 * v x + (R k).2)).card : ℝ) ≤ 6 * Real.sqrt β * w) ∧ (∀ k < K, ∀ k' < K, ((chgW v (Wf k)).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 → ((chgW v (Wf k')).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 → 12 * Real.sqrt β * w + 2 ≤ ((Wf k ∩ Wf k').card : ℝ) → R k = R k') := by refine ⟨thm119_count hn (ccw_leftTurns hn hv) hH0 U hε0 hε1 hU1 hU2 u₀ K w Wf Wpf hWsub hWp hspan hM hβ0 hβ hlam0 hlam hlam1, ?_⟩ have hβ' : β ≤ 1 / 100 := by linarith have hex : ∀ k, ∃ r : ℂ × ℂ, k < K → ((chgW v (Wf k)).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 → ‖r.1‖ = 1 ∧ r.1 ≠ 1 ∧ (((Wf k).filter (fun x => v (x + 1) ≠ r.1 * v x + r.2)).card : ℝ) ≤ 6 * Real.sqrt β * w := by intro k by_cases h : k < K ∧ ((chgW v (Wf k)).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 · have hc := hcard k h.1 obtain ⟨ω, t, h1, h2, h3⟩ := good_window_rot hn hv hvi hT (Wf k) (by rw [hc]; exact hw7) hβ0 hβ' (by rw [hc]; exact h.2) rw [hc] at h3 exact ⟨(ω, t), fun _ _ => ⟨h1, h2, h3⟩⟩ · exact ⟨(1, 0), fun hk hg => absurd ⟨hk, hg⟩ h⟩ choose R hR using hex refine ⟨R, fun k hk hg => hR k hk hg, fun k hk k' hk' hg hg' hov => ?_⟩ obtain ⟨_, _, h1⟩ := hR k hk hg obtain ⟨_, _, h2⟩ := hR k' hk' hg' have := glue_rot hvi h1 h2 (by linarith) exact Prod.ext this.1 this.2 end Erdos94ThmA /-! ### (F12) INVERSE Theorem 11.9′ for the windows of Theorem 11.9: `W_k = [k⌈w/2⌉, k⌈w/2⌉ + w)`, `k < K = ⌈n/⌈w/2⌉⌉` -/ namespace Erdos94ThmA open Finset /-- The window `W_k = {k⌈w/2⌉ + i : i < w}` of Theorem 11.9 (`⌈w/2⌉ = (w + 1)/2`). -/ def winK {n : ℕ} (w k : ℕ) : Finset (ZMod n) := (range w).image (fun i => ((k * ((w + 1) / 2) + i : ℕ) : ZMod n)) /-- `W_k⁺ = W_k ∪ {k⌈w/2⌉ + w}` (the window plus the next vertex). -/ def winKp {n : ℕ} (w k : ℕ) : Finset (ZMod n) := (range (w + 1)).image (fun i => ((k * ((w + 1) / 2) + i : ℕ) : ZMod n)) /-- The number of windows, `K = ⌈n/⌈w/2⌉⌉`. -/ def nWin (n w : ℕ) : ℕ := (n + (w + 1) / 2 - 1) / ((w + 1) / 2) theorem winK_sub {n : ℕ} (w k : ℕ) : (winK w k : Finset (ZMod n)) ⊆ winKp w k := image_subset_image (range_mono (Nat.le_succ w)) theorem winK_succ {n : ℕ} {w k : ℕ} {x : ZMod n} (hx : x ∈ (winK w k : Finset (ZMod n))) : x + 1 ∈ (winKp w k : Finset (ZMod n)) := by obtain ⟨i, hi, rfl⟩ := mem_image.mp hx refine mem_image.mpr ⟨i + 1, mem_range.mpr (by have := mem_range.mp hi; omega), ?_⟩ push_cast ring theorem winK_mem {n : ℕ} {w k : ℕ} {x : ZMod n} (hx : x ∈ (winK w k : Finset (ZMod n))) : ∃ i < w, x = ((k * ((w + 1) / 2) : ℕ) : ZMod n) + i := by obtain ⟨i, hi, rfl⟩ := mem_image.mp hx exact ⟨i, mem_range.mp hi, by push_cast; ring⟩ theorem cast_add_inj {n : ℕ} [NeZero n] (a : ℕ) {i j : ℕ} (hi : i < n) (hj : j < n) (h : ((a + i : ℕ) : ZMod n) = ((a + j : ℕ) : ZMod n)) : i = j := by push_cast at h have h1 := add_left_cancel h have h2 := congrArg ZMod.val h1 rwa [ZMod.val_cast_of_lt hi, ZMod.val_cast_of_lt hj] at h2 theorem winK_card {n : ℕ} [NeZero n] {w : ℕ} (hwn : w ≤ n) (k : ℕ) : (winK w k : Finset (ZMod n)).card = w := by unfold winK rw [card_image_of_injOn, card_range] intro i hi j hj hij have hij' : ((k * ((w + 1) / 2) + i : ℕ) : ZMod n) = ((k * ((w + 1) / 2) + j : ℕ) : ZMod n) := hij exact cast_add_inj _ (by have := mem_range.mp hi; omega) (by have := mem_range.mp hj; omega) hij' theorem nWin_spec {n w : ℕ} (hw : 1 ≤ w) : nWin n w * ((w + 1) / 2) + 1 ≤ n + (w + 1) / 2 ∧ n ≤ nWin n w * ((w + 1) / 2) := by obtain ⟨s, hs⟩ : ∃ s, s = (w + 1) / 2 := ⟨_, rfl⟩ have hs1 : 1 ≤ s := by omega unfold nWin rw [← hs] obtain ⟨q, hq⟩ : ∃ q, q = (n + s - 1) / s := ⟨_, rfl⟩ obtain ⟨r, hr⟩ : ∃ r, r = (n + s - 1) % s := ⟨_, rfl⟩ have h1 := Nat.div_add_mod (n + s - 1) s have h2 := Nat.mod_lt (n + s - 1) (show 0 < s by omega) rw [← hq, ← hr] at h1 rw [← hr] at h2 rw [← hq] rw [mul_comm] at h1 constructor <;> omega theorem nWin_mul {n w : ℕ} (hw : 1 ≤ w) {k : ℕ} (hk : k < nWin n w) : k * ((w + 1) / 2) + 1 ≤ n := by have h1 := (nWin_spec (n := n) hw).1 have h2 : (k + 1) * ((w + 1) / 2) ≤ nWin n w * ((w + 1) / 2) := Nat.mul_le_mul_right _ hk rw [add_mul, one_mul] at h2 omega theorem card_le_three {S : Finset ℕ} (h : ∀ a ∈ S, ∀ b ∈ S, a ≤ b + 2) : S.card ≤ 3 := by rcases S.eq_empty_or_nonempty with hS | hS · simp [hS] · have hsub : S ⊆ Icc (S.min' hS) (S.min' hS + 2) := by intro a ha exact mem_Icc.mpr ⟨min'_le S a ha, h a ha _ (min'_mem S hS)⟩ have := card_le_card hsub rw [Nat.card_Icc] at this omega /-- Every vertex lies in at most `6` of the sets `W_k⁺`. -/ theorem winKp_mult {n : ℕ} [NeZero n] {w : ℕ} (hw : 1 ≤ w) (hwn : w < n) (y : ZMod n) : ((range (nWin n w)).filter (fun k => y ∈ (winKp w k : Finset (ZMod n)))).card ≤ 6 := by classical obtain ⟨s, hs⟩ : ∃ s, s = (w + 1) / 2 := ⟨_, rfl⟩ have hs1 : 1 ≤ s := by omega have hs2 : w ≤ 2 * s := by omega have hsub : (range (nWin n w)).filter (fun k => y ∈ (winKp w k : Finset (ZMod n))) ⊆ (range (nWin n w)).filter (fun k => k * s ≤ y.val ∧ y.val ≤ k * s + w) ∪ (range (nWin n w)).filter (fun k => k * s ≤ y.val + n ∧ y.val + n ≤ k * s + w) := by intro k hk obtain ⟨hkK, hky⟩ := mem_filter.mp hk unfold winKp at hky obtain ⟨i, hi, hiy⟩ := mem_image.mp hky have hi' : i ≤ w := Nat.lt_succ_iff.mp (mem_range.mp hi) have hks := nWin_mul hw (mem_range.mp hkK) rw [← hs] at hks hiy have hval := congrArg ZMod.val hiy rw [ZMod.val_natCast] at hval have hyv := ZMod.val_lt y rcases Nat.lt_or_ge (k * s + i) n with h | h · rw [Nat.mod_eq_of_lt h] at hval exact mem_union_left _ (mem_filter.mpr ⟨hkK, by omega, by omega⟩) · rw [Nat.mod_eq_sub_mod h, Nat.mod_eq_of_lt (by omega)] at hval exact mem_union_right _ (mem_filter.mpr ⟨hkK, by omega, by omega⟩) have h3 : ∀ c : ℕ, ((range (nWin n w)).filter (fun k => k * s ≤ c ∧ c ≤ k * s + w)).card ≤ 3 := by intro c apply card_le_three intro a ha b hb obtain ⟨_, ha1, ha2⟩ := mem_filter.mp ha obtain ⟨_, hb1, hb2⟩ := mem_filter.mp hb by_contra hab push_neg at hab have : (b + 3) * s ≤ a * s := Nat.mul_le_mul_right _ (by omega) rw [add_mul] at this omega have hc := card_le_card hsub have hu := card_union_le ((range (nWin n w)).filter (fun k => k * s ≤ y.val ∧ y.val ≤ k * s + w)) ((range (nWin n w)).filter (fun k => k * s ≤ y.val + n ∧ y.val + n ≤ k * s + w)) have h4 := h3 y.val have h5 := h3 (y.val + n) omega /-- Cyclically consecutive windows overlap in at least `⌊w/2⌋ = w − ⌈w/2⌉` vertices. -/ theorem winK_overlap {n : ℕ} [NeZero n] {w : ℕ} (hw : 1 ≤ w) (hwn : w ≤ n) {k : ℕ} (hk : k < nWin n w) : w - (w + 1) / 2 ≤ ((winK w k : Finset (ZMod n)) ∩ winK w ((k + 1) % nWin n w)).card := by classical have hspec := nWin_spec (n := n) hw have hks := nWin_mul hw hk obtain ⟨s, hs⟩ : ∃ s, s = (w + 1) / 2 := ⟨_, rfl⟩ have hs1 : 1 ≤ s := by omega have hsw : s ≤ w := by omega rw [← hs] at hspec hks ⊢ rcases Nat.lt_or_ge (k + 1) (nWin n w) with h | h · rw [Nat.mod_eq_of_lt h] have hsub : (Ico s w).image (fun j => ((k * s + j : ℕ) : ZMod n)) ⊆ (winK w k : Finset (ZMod n)) ∩ winK w (k + 1) := by intro x hx obtain ⟨j, hj, rfl⟩ := mem_image.mp hx obtain ⟨hj1, hj2⟩ := mem_Ico.mp hj refine mem_inter.mpr ⟨?_, ?_⟩ · unfold winK rw [← hs] exact mem_image.mpr ⟨j, mem_range.mpr hj2, rfl⟩ · unfold winK rw [← hs] refine mem_image.mpr ⟨j - s, mem_range.mpr (by omega), ?_⟩ congr 1 rw [add_mul, one_mul] omega have hcard : ((Ico s w).image (fun j => ((k * s + j : ℕ) : ZMod n))).card = w - s := by rw [card_image_of_injOn, Nat.card_Ico] intro i hi j hj hij have hij' : ((k * s + i : ℕ) : ZMod n) = ((k * s + j : ℕ) : ZMod n) := hij exact cast_add_inj _ (by have := (mem_Ico.mp hi).2; omega) (by have := (mem_Ico.mp hj).2; omega) hij' have := card_le_card hsub omega · have hkK : k + 1 = nWin n w := by omega rw [hkK, Nat.mod_self] have hns : n ≤ k * s + s := by have := hspec.2 rw [← hkK, add_mul, one_mul] at this exact this have hsub : (Ico (n - k * s) w).image (fun j => ((k * s + j : ℕ) : ZMod n)) ⊆ (winK w k : Finset (ZMod n)) ∩ winK w 0 := by intro x hx obtain ⟨j, hj, rfl⟩ := mem_image.mp hx obtain ⟨hj1, hj2⟩ := mem_Ico.mp hj refine mem_inter.mpr ⟨?_, ?_⟩ · unfold winK rw [← hs] exact mem_image.mpr ⟨j, mem_range.mpr hj2, rfl⟩ · unfold winK refine mem_image.mpr ⟨k * s + j - n, mem_range.mpr (by omega), ?_⟩ simp only [zero_mul, zero_add] rw [Nat.cast_sub (by omega), ZMod.natCast_self, sub_zero] have hcard : ((Ico (n - k * s) w).image (fun j => ((k * s + j : ℕ) : ZMod n))).card = w - (n - k * s) := by rw [card_image_of_injOn, Nat.card_Ico] intro i hi j hj hij have hij' : ((k * s + i : ℕ) : ZMod n) = ((k * s + j : ℕ) : ZMod n) := hij exact cast_add_inj _ (by have := (mem_Ico.mp hi).2; omega) (by have := (mem_Ico.mp hj).2; omega) hij' have := card_le_card hsub omega open Classical in /-- **INVERSE Theorem 11.9′** (localised: thin vertices and bad windows only cut the boundary into stretches), with the §11.16(a) correction (`24ν²`), for the windows `W_k = [k⌈w/2⌉, k⌈w/2⌉ + w)`, `k < K = ⌈n/⌈w/2⌉⌉`, of Theorem 11.9. Hypotheses: `CCWPoly v` (`n ≥ 3`), `v` injective, (T), (H₀) (as "no `F(y)` contains `y − 1`"); `w = ⌈λn⌉ ≥ 10³`, `w < n`; every `w` consecutive vertices span `< u₀`; `U` a set of `≥ (1/2 − ε)n` distances with `f(u) ≥ (1 − ε)n` (`#chO = 2f`), `0 ≤ ε ≤ 1/100`; `0 < β ≤ 10⁻⁴`. GOOD window: at most `2βw²` ordered (`βw²` unordered) changed pairs. Conclusions: (1) all windows but at most `N_B + (37ε + 24ν²)/(βλ²)` are good (`N_B = #{k : |W_k⁺ ∩ B(u₀)| > βλ²n/16}`, `ν = |B(u₀)|/n`); (2) on every good window the shift agrees with a rotation `R k` (`|ω| = 1`, `ω ≠ 1`) off at most `6√β w` vertices; (3) cyclically consecutive good windows have the same rotation — so the boundary splits into at most (#bad windows + 1) arcs of consecutive good windows, each carrying one rotation. -/ theorem thm119' {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (hT : ∀ t : ℂ, t ≠ 0 → ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) {lam : ℝ} (hlam0 : 0 < lam) {w : ℕ} (hw : w = ⌈lam * n⌉₊) (hw3 : 1000 ≤ w) (hwn : w < n) {u₀ : ℝ} (hspan : ∀ x : ZMod n, ∀ i j : ℕ, i < w → j < w → dist (v (x + i)) (v (x + j)) < u₀) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) {β : ℝ} (hβ0 : 0 < β) (hβ : β ≤ 1 / 10000) : (((range (nWin n w)).filter (fun k => 2 * β * (w : ℝ) ^ 2 < (chgW v (winK w k)).card)).card : ℝ) ≤ ((range (nWin n w)).filter (fun k => β * lam ^ 2 * n / 16 < (((winKp w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ))).card + (37 * ε + 24 * (((thinB v u₀).card : ℝ) / n) ^ 2) / (β * lam ^ 2) ∧ ∃ R : ℕ → ℂ × ℂ, (∀ k < nWin n w, ((chgW v (winK w k)).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 → ‖(R k).1‖ = 1 ∧ (R k).1 ≠ 1 ∧ ((((winK w k : Finset (ZMod n))).filter (fun x => v (x + 1) ≠ (R k).1 * v x + (R k).2)).card : ℝ) ≤ 6 * Real.sqrt β * w) ∧ (∀ k < nWin n w, ((chgW v (winK w k)).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 → ((chgW v (winK w ((k + 1) % nWin n w))).card : ℝ) ≤ 2 * β * (w : ℝ) ^ 2 → R k = R ((k + 1) % nWin n w)) := by have hw1 : 1 ≤ w := by omega have hlam : lam * n ≤ w := by rw [hw]; exact Nat.le_ceil _ have hnR3 : (3 : ℝ) ≤ n := by exact_mod_cast hn have hnR : (0 : ℝ) < n := by linarith have hlam1 : lam ≤ 1 := by have : (w : ℝ) < n := by exact_mod_cast hwn by_contra hc push_neg at hc nlinarith have hspanW : ∀ k < nWin n w, ∀ a ∈ (winK w k : Finset (ZMod n)), ∀ b ∈ (winK w k : Finset (ZMod n)), dist (v a) (v b) < u₀ := by intro k _ a ha b hb obtain ⟨i, hi, rfl⟩ := winK_mem ha obtain ⟨j, hj, rfl⟩ := winK_mem hb exact hspan _ i j hi hj obtain ⟨h1, R, h2, h3⟩ := thm119g hn hv hvi hT hH0 U hε0 hε1 hU1 hU2 u₀ (nWin n w) w (fun k => (winK w k : Finset (ZMod n))) (fun k => (winKp w k : Finset (ZMod n))) (by omega) (fun k _ => winK_card hwn.le k) (fun k _ => winK_sub w k) (fun k _ x hx => winK_succ hx) hspanW (winKp_mult hw1 hwn) hβ0 hβ hlam0 hlam hlam1 refine ⟨h1, R, h2, fun k hk hg hg' => ?_⟩ have hK0 : 0 < nWin n w := by omega refine h3 k hk ((k + 1) % nWin n w) (Nat.mod_lt _ hK0) hg hg' ?_ have hov := winK_overlap (n := n) hw1 hwn.le hk have hovR : ((w : ℝ) - 1) / 2 ≤ (((winK w k : Finset (ZMod n)) ∩ winK w ((k + 1) % nWin n w)).card : ℝ) := by have h' : w ≤ 2 * (((winK w k : Finset (ZMod n)) ∩ winK w ((k + 1) % nWin n w)).card) + 1 := by omega have h'' : (w : ℝ) ≤ 2 * ((((winK w k : Finset (ZMod n)) ∩ winK w ((k + 1) % nWin n w)).card : ℕ) : ℝ) + 1 := by exact_mod_cast h' linarith have hsq : Real.sqrt β ≤ 1 / 100 := by have := Real.sqrt_le_sqrt hβ rwa [show (1 : ℝ) / 10000 = (1 / 100) ^ 2 by norm_num, Real.sqrt_sq (by norm_num)] at this have hwR : (1000 : ℝ) ≤ w := by exact_mod_cast hw3 nlinarith [Real.sqrt_nonneg β] end Erdos94ThmA /-! ### (F13) INVERSE Lemma 11.17 (block rigidity), via the equal-step case of GLIDE Lemma 10.1 -/ namespace Erdos94ThmA open Finset /-- `|a e^{iφ} − b e^{iψ}|² = a² + b² − 2ab cos(ψ − φ)`. -/ theorem norm_polar_sub_sq (a b φ ψ : ℝ) : ‖(a : ℂ) * Complex.exp (φ * Complex.I) - (b : ℂ) * Complex.exp (ψ * Complex.I)‖ ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b * Real.cos (ψ - φ) := by rw [Complex.sq_norm, Complex.normSq_apply] simp only [Complex.sub_re, Complex.sub_im, Complex.mul_re, Complex.mul_im, Complex.ofReal_re, Complex.ofReal_im, Complex.exp_ofReal_mul_I_re, Complex.exp_ofReal_mul_I_im, zero_mul, sub_zero, add_zero] rw [Real.cos_sub] linear_combination a ^ 2 * Real.sin_sq_add_cos_sq φ + b ^ 2 * Real.sin_sq_add_cos_sq ψ /-- `|a − e^{iθ} b|² = |a|² + |b|² − 2|a||b| cos(arg b + θ − arg a)`. -/ theorem norm_sub_rot_sq (a b : ℂ) (θ : ℝ) : ‖a - Complex.exp (θ * Complex.I) * b‖ ^ 2 = ‖a‖ ^ 2 + ‖b‖ ^ 2 - 2 * ‖a‖ * ‖b‖ * Real.cos (Complex.arg b + θ - Complex.arg a) := by have key : a - Complex.exp (θ * Complex.I) * b = (‖a‖ : ℂ) * Complex.exp (Complex.arg a * Complex.I) - (‖b‖ : ℂ) * Complex.exp ((Complex.arg b + θ : ℝ) * Complex.I) := by conv_lhs => rw [← Complex.norm_mul_exp_arg_mul_I a, ← Complex.norm_mul_exp_arg_mul_I b] push_cast rw [add_mul, Complex.exp_add] ring rw [key, norm_polar_sub_sq] /-- `b|a| = e^{i(arg b − arg a)} a |b|`. -/ theorem polar_rot (a b : ℂ) : b * ‖a‖ = Complex.exp (((Complex.arg b - Complex.arg a : ℝ)) * Complex.I) * a * ‖b‖ := by have ha := Complex.norm_mul_exp_arg_mul_I a have hb := Complex.norm_mul_exp_arg_mul_I b have he : Complex.exp (((Complex.arg b - Complex.arg a : ℝ)) * Complex.I) * Complex.exp (Complex.arg a * Complex.I) = Complex.exp (Complex.arg b * Complex.I) := by rw [← Complex.exp_add] congr 1 push_cast ring calc b * ‖a‖ = ((‖b‖ : ℂ) * Complex.exp (Complex.arg b * Complex.I)) * ‖a‖ := by rw [hb] _ = (Complex.exp (((Complex.arg b - Complex.arg a : ℝ)) * Complex.I) * Complex.exp (Complex.arg a * Complex.I)) * ‖b‖ * ‖a‖ := by rw [he]; ring _ = Complex.exp (((Complex.arg b - Complex.arg a : ℝ)) * Complex.I) * ((‖a‖ : ℂ) * Complex.exp (Complex.arg a * Complex.I)) * ‖b‖ := by ring _ = Complex.exp (((Complex.arg b - Complex.arg a : ℝ)) * Complex.I) * a * ‖b‖ := by rw [ha] /-- The equal-step two-step system forces a degree-1 trigonometric equation in `s` (GLIDE Lemma 10.1, `v = (α, α)`): `E(s) = −2BD sin²α cos s + 2BD sin α (1 − cos α) sin s + B² sin²α + 2D²(1 − cos α) − B'² sin²α = 0`, `D = A − A'`. -/ theorem twostep_zero {A B A' B' α s s' : ℝ} (h1 : A - B * Real.cos s = A' - B' * Real.cos s') (h2 : A - B * Real.cos (s + α) = A' - B' * Real.cos (s' + α)) : 0 * Real.cos s ^ 2 + 0 * Real.cos s * Real.sin s + (-2 * B * (A - A') * Real.sin α ^ 2) * Real.cos s + (2 * B * (A - A') * Real.sin α * (1 - Real.cos α)) * Real.sin s + (B ^ 2 * Real.sin α ^ 2 + 2 * (A - A') ^ 2 * (1 - Real.cos α) - B' ^ 2 * Real.sin α ^ 2) = 0 := by have hP : B' * Real.cos s' = B * Real.cos s - (A - A') := by linarith have hQ : B' * (Real.cos s' * Real.cos α - Real.sin s' * Real.sin α) = B * (Real.cos s * Real.cos α - Real.sin s * Real.sin α) - (A - A') := by rw [← Real.cos_add, ← Real.cos_add] linarith have hS : B' * Real.sin s' * Real.sin α = B * Real.sin s * Real.sin α + (A - A') * (1 - Real.cos α) := by linear_combination Real.cos α * hP - hQ linear_combination (-(Real.sin α ^ 2) * (B * Real.cos s - (A - A') + B' * Real.cos s')) * hP + (-(B * Real.sin s * Real.sin α + (A - A') * (1 - Real.cos α) + B' * Real.sin s' * Real.sin α)) * hS + (B' ^ 2 * Real.sin α ^ 2) * Real.sin_sq_add_cos_sq s' + (-(B ^ 2 * Real.sin α ^ 2)) * Real.sin_sq_add_cos_sq s + (-((A - A') ^ 2)) * Real.sin_sq_add_cos_sq α /-- **GLIDE Lemma 10.1, equal steps `(α, α)`.** If `(A, B) ≠ (A', B')`, `B, B' > 0` and `sin α ≠ 0`, the system `A − B cos s = A' − B' cos s'`, `A − B cos(s + α) = A' − B' cos(s' + α)` has solutions for at most `4` values `s ∈ [0, 2π)`. -/ theorem twostep_le_four {A B A' B' α : ℝ} (hB : 0 < B) (hB' : 0 < B') (hne : A ≠ A' ∨ B ≠ B') (hsa : Real.sin α ≠ 0) (T : Finset ℝ) (hT : ∀ s ∈ T, 0 ≤ s ∧ s < 2 * Real.pi) (hsol : ∀ s ∈ T, ∃ s' : ℝ, A - B * Real.cos s = A' - B' * Real.cos s' ∧ A - B * Real.cos (s + α) = A' - B' * Real.cos (s' + α)) : T.card ≤ 4 := by by_cases hD : A = A' · have hBB : B ≠ B' := hne.resolve_left (not_not.mpr hD) have hT0 : T = ∅ := by rw [eq_empty_iff_forall_notMem] intro s hs obtain ⟨s', h1, h2⟩ := hsol s hs have h3 := twostep_zero h1 h2 rw [hD, sub_self] at h3 have h4 : B ^ 2 * Real.sin α ^ 2 = B' ^ 2 * Real.sin α ^ 2 := by linarith have h5 : B ^ 2 = B' ^ 2 := mul_right_cancel₀ (pow_ne_zero 2 hsa) h4 exact hBB ((pow_left_inj₀ hB.le hB'.le two_ne_zero).mp h5) rw [hT0, card_empty] norm_num · have hca : Real.cos α ≠ 1 := by intro h have := Real.sin_sq_add_cos_sq α rw [h] at this exact hsa (pow_eq_zero_iff two_ne_zero |>.mp (by linarith)) have hH : 2 * B * (A - A') * Real.sin α * (1 - Real.cos α) ≠ 0 := by refine mul_ne_zero (mul_ne_zero (mul_ne_zero (mul_ne_zero two_ne_zero hB.ne') (sub_ne_zero.mpr hD)) hsa) ?_ exact sub_ne_zero.mpr (Ne.symm hca) exact trig_zeros_le_four (Or.inr hH) T hT (fun s hs => by obtain ⟨s', h1, h2⟩ := hsol s hs exact twostep_zero h1 h2) theorem cos_toIcoMod (z c : ℝ) : Real.cos (toIcoMod Real.two_pi_pos 0 z + c) = Real.cos (z + c) := by have h := toIcoMod_add_toIcoDiv_zsmul Real.two_pi_pos 0 z rw [zsmul_eq_mul] at h have e : toIcoMod Real.two_pi_pos 0 z + c = (z + c) - (toIcoDiv Real.two_pi_pos 0 z : ℝ) * (2 * Real.pi) := by linarith rw [e, Real.cos_sub_int_mul_two_pi] /-- **INVERSE Lemma 11.17 (block rigidity).** Let `g(z) = O + e^{iα}(z − O)` be the rotation about `O` by `α`, `0 < 6α < 2π`. If `m ≥ 6` consecutive classes `u_0 < u_1 < … < u_{m−1}` are realised from `x` at `y, g(y), …, g^{m−1}(y)` and from `x'` at `y', g(y'), …, g^{m−1}(y')`, in the same order, then `{|Ox|, |Oy|} = {|Ox'|, |Oy'|}` and the angle from `x` to `y` about `O` equals the angle from `x'` to `y'` (one `t` with `(y − O)|x − O| = e^{it}(x − O)|y − O|` and `(y' − O)|x' − O| = e^{it}(x' − O)|y' − O|`). -/ theorem lemma1117 {O x x' y y' : ℂ} {α : ℝ} (hα0 : 0 < α) (hα : 6 * α < 2 * Real.pi) {m : ℕ} (hm : 6 ≤ m) (u : ℕ → ℝ) (hu : ∀ k, k + 1 < m → u k < u (k + 1)) (hx : ∀ k < m, dist x (O + Complex.exp (((k : ℝ) * α : ℝ) * Complex.I) * (y - O)) = u k) (hx' : ∀ k < m, dist x' (O + Complex.exp (((k : ℝ) * α : ℝ) * Complex.I) * (y' - O)) = u k) : ((‖x - O‖ = ‖x' - O‖ ∧ ‖y - O‖ = ‖y' - O‖) ∨ (‖x - O‖ = ‖y' - O‖ ∧ ‖y - O‖ = ‖x' - O‖)) ∧ ∃ t : ℝ, (y - O) * ‖x - O‖ = Complex.exp (t * Complex.I) * (x - O) * ‖y - O‖ ∧ (y' - O) * ‖x' - O‖ = Complex.exp (t * Complex.I) * (x' - O) * ‖y' - O‖ := by -- the squared distances have hsq : ∀ (p q : ℂ), (∀ k < m, dist p (O + Complex.exp (((k : ℝ) * α : ℝ) * Complex.I) * (q - O)) = u k) → ∀ k < m, u k ^ 2 = (‖p - O‖ ^ 2 + ‖q - O‖ ^ 2) - (2 * ‖p - O‖ * ‖q - O‖) * Real.cos ((Complex.arg (q - O) - Complex.arg (p - O)) + k * α) := by intro p q hpq k hk rw [← hpq k hk, dist_eq_norm, show p - (O + Complex.exp (((k : ℝ) * α : ℝ) * Complex.I) * (q - O)) = (p - O) - Complex.exp (((k : ℝ) * α : ℝ) * Complex.I) * (q - O) by ring, norm_sub_rot_sq] rw [show Complex.arg (q - O) + ↑k * α - Complex.arg (p - O) = Complex.arg (q - O) - Complex.arg (p - O) + ↑k * α by ring] have h1 := hsq x y hx have h2 := hsq x' y' hx' have hu0 : ∀ k < m, 0 ≤ u k := fun k hk => by rw [← hx k hk]; exact dist_nonneg -- positivity of the radii products have hpos : ∀ (p q : ℂ), (∀ k < m, u k ^ 2 = (‖p - O‖ ^ 2 + ‖q - O‖ ^ 2) - (2 * ‖p - O‖ * ‖q - O‖) * Real.cos ((Complex.arg (q - O) - Complex.arg (p - O)) + k * α)) → 0 < 2 * ‖p - O‖ * ‖q - O‖ := by intro p q hpq by_contra hc have h0 : 2 * ‖p - O‖ * ‖q - O‖ = 0 := by have := mul_nonneg (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) (norm_nonneg (p - O))) (norm_nonneg (q - O)) linarith have e0 := hpq 0 (by omega) have e1 := hpq 1 (by omega) rw [h0, zero_mul, sub_zero] at e0 e1 have : u 0 ^ 2 = u 1 ^ 2 := by rw [e0, e1] have h01 := hu 0 (by omega) have := (pow_left_inj₀ (hu0 0 (by omega)) (hu0 1 (by omega)) two_ne_zero).mp this linarith have hB := hpos x y h1 have hB' := hpos x' y' h2 have hsa : Real.sin α ≠ 0 := (Real.sin_pos_of_pos_of_lt_pi hα0 (by linarith [Real.pi_pos])).ne' obtain ⟨t, ht⟩ : ∃ t, t = Complex.arg (y - O) - Complex.arg (x - O) := ⟨_, rfl⟩ obtain ⟨t', ht'⟩ : ∃ t', t' = Complex.arg (y' - O) - Complex.arg (x' - O) := ⟨_, rfl⟩ rw [← ht] at h1 rw [← ht'] at h2 -- (A, B) = (A', B') have hAB : ‖x - O‖ ^ 2 + ‖y - O‖ ^ 2 = ‖x' - O‖ ^ 2 + ‖y' - O‖ ^ 2 ∧ 2 * ‖x - O‖ * ‖y - O‖ = 2 * ‖x' - O‖ * ‖y' - O‖ := by by_contra hc have hne : (‖x - O‖ ^ 2 + ‖y - O‖ ^ 2 ≠ ‖x' - O‖ ^ 2 + ‖y' - O‖ ^ 2) ∨ (2 * ‖x - O‖ * ‖y - O‖ ≠ 2 * ‖x' - O‖ * ‖y' - O‖) := by by_contra hc' push_neg at hc' exact hc hc' have hinj : Set.InjOn (fun k : ℕ => toIcoMod Real.two_pi_pos 0 (t + k * α)) (range 5) := by intro j hj k hk hjk obtain ⟨N, hN⟩ := (toIcoMod_eq_toIcoMod Real.two_pi_pos).mp hjk rw [zsmul_eq_mul] at hN have hjR : (j : ℝ) < 5 := by exact_mod_cast mem_range.mp hj have hkR : (k : ℝ) < 5 := by exact_mod_cast mem_range.mp hk have hj0 : (0 : ℝ) ≤ j := Nat.cast_nonneg _ have hk0 : (0 : ℝ) ≤ k := Nat.cast_nonneg _ have hlt : ((k : ℝ) - j) * α < 2 * Real.pi := by have := mul_lt_mul_of_pos_right (show (k : ℝ) - j < 5 by linarith) hα0 linarith have hgt : -(2 * Real.pi) < ((k : ℝ) - j) * α := by have := mul_lt_mul_of_pos_right (show (j : ℝ) - k < 5 by linarith) hα0 linarith have hN1 : (N : ℝ) < 1 := by by_contra hc2 push_neg at hc2 nlinarith [Real.pi_pos] have hN2 : (-1 : ℝ) < N := by by_contra hc2 push_neg at hc2 nlinarith [Real.pi_pos] have hN0 : N = 0 := by have a1 : N < 1 := by exact_mod_cast hN1 have a2 : -1 < N := by exact_mod_cast hN2 omega rw [hN0, Int.cast_zero, zero_mul] at hN have hz : ((k : ℝ) - j) * α = 0 := by linarith rcases mul_eq_zero.mp hz with h | h · have : (k : ℝ) = j := by linarith exact_mod_cast this.symm · exact absurd h hα0.ne' have hcard : ((range 5).image (fun k : ℕ => toIcoMod Real.two_pi_pos 0 (t + k * α))).card = 5 := by rw [card_image_of_injOn hinj, card_range] have hle := twostep_le_four (A := ‖x - O‖ ^ 2 + ‖y - O‖ ^ 2) (B := 2 * ‖x - O‖ * ‖y - O‖) (A' := ‖x' - O‖ ^ 2 + ‖y' - O‖ ^ 2) (B' := 2 * ‖x' - O‖ * ‖y' - O‖) (α := α) hB hB' hne hsa ((range 5).image (fun k : ℕ => toIcoMod Real.two_pi_pos 0 (t + k * α))) (fun s hs => by obtain ⟨k, _, rfl⟩ := mem_image.mp hs have := toIcoMod_mem_Ico Real.two_pi_pos 0 (t + k * α) rw [zero_add] at this exact ⟨this.1, this.2⟩) (fun s hs => by obtain ⟨k, hk, rfl⟩ := mem_image.mp hs have hk5 := mem_range.mp hk refine ⟨t' + k * α, ?_, ?_⟩ · have e1 := h1 k (by omega) have e2 := h2 k (by omega) have c1 := cos_toIcoMod (t + k * α) 0 rw [add_zero, add_zero] at c1 rw [c1] linarith · have e1 := h1 (k + 1) (by omega) have e2 := h2 (k + 1) (by omega) rw [cos_toIcoMod] push_cast at e1 e2 rw [show t + (↑k + 1) * α = t + ↑k * α + α by ring] at e1 rw [show t' + (↑k + 1) * α = t' + ↑k * α + α by ring] at e2 linarith) rw [hcard] at hle omega obtain ⟨hA, hBB⟩ := hAB refine ⟨?_, ?_⟩ · -- the radius pairs agree have hs1 : (‖x - O‖ + ‖y - O‖) ^ 2 = (‖x' - O‖ + ‖y' - O‖) ^ 2 := by linear_combination hA + hBB have hs2 : ‖x - O‖ + ‖y - O‖ = ‖x' - O‖ + ‖y' - O‖ := (pow_left_inj₀ (by positivity) (by positivity) two_ne_zero).mp hs1 have hz : (‖x - O‖ - ‖x' - O‖) * (‖x - O‖ - ‖y' - O‖) = 0 := by linear_combination ‖x - O‖ * hs2 - (1 / 2 : ℝ) * hBB rcases mul_eq_zero.mp hz with h | h · left exact ⟨by linarith, by linarith⟩ · right exact ⟨by linarith, by linarith⟩ · -- the angles agree: cos t = cos t', sin t = sin t' have e0 := h1 0 (by omega) have f0 := h2 0 (by omega) have e1 := h1 1 (by omega) have f1 := h2 1 (by omega) push_cast at e0 f0 e1 f1 simp only [zero_mul, add_zero, one_mul] at e0 f0 e1 f1 have hc : Real.cos t = Real.cos t' := by have : 2 * ‖x - O‖ * ‖y - O‖ * Real.cos t = 2 * ‖x - O‖ * ‖y - O‖ * Real.cos t' := by rw [hBB] at e0 ⊢ linarith exact mul_left_cancel₀ hB.ne' this have hc1 : Real.cos (t + α) = Real.cos (t' + α) := by have : 2 * ‖x - O‖ * ‖y - O‖ * Real.cos (t + α) = 2 * ‖x - O‖ * ‖y - O‖ * Real.cos (t' + α) := by rw [hBB] at e1 ⊢ linarith exact mul_left_cancel₀ hB.ne' this have hs : Real.sin t = Real.sin t' := by rw [Real.cos_add, Real.cos_add, hc] at hc1 have : Real.sin t * Real.sin α = Real.sin t' * Real.sin α := by linarith exact mul_right_cancel₀ hsa this have hexp : Complex.exp (t * Complex.I) = Complex.exp (t' * Complex.I) := by apply Complex.ext · rw [Complex.exp_ofReal_mul_I_re, Complex.exp_ofReal_mul_I_re, hc] · rw [Complex.exp_ofReal_mul_I_im, Complex.exp_ofReal_mul_I_im, hs] refine ⟨t, ?_, ?_⟩ · rw [ht] exact polar_rot (x - O) (y - O) · rw [hexp, ht'] exact polar_rot (x' - O) (y' - O) end Erdos94ThmA /-! ### (F14) INVERSE Theorem 11.15, part 1: the short range `F_{u₀}(x)`, class positions, and the budgets `Σ def ≤ εnK + |B|²/2`, `Σ nf ≤ 3εn²`, `Σ β ≤ |X|n` -/ namespace Erdos94ThmA open Finset open Classical in /-- `F_{u₀}(x)` (proof of Theorem 11.15), as offsets: `j < n` with `x + j ∈ F(x)` and `|v_x v_{x+j}| < u₀`. -/ noncomputable def Fu0 {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u₀ : ℝ) (x : ZMod n) : Finset ℕ := (range n).filter (fun j : ℕ => inF v x (x + (j : ZMod n)) ∧ dist (v x) (v (x + (j : ZMod n))) < u₀) open Classical in /-- `def(x)`: the classes of `U_s` without a partner in `F(x)`. -/ noncomputable def dfc {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (Us : Finset ℝ) (x : ZMod n) : ℕ := (Us.filter (fun u => x ∉ Au v u)).card open Classical in /-- `nf(x)`: the "extra" positions of `F_{u₀}(x)`, whose distance is not a class of `U`. -/ noncomputable def nfc {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) (u₀ : ℝ) (x : ZMod n) : ℕ := ((Fu0 v u₀ x).filter (fun j : ℕ => dist (v x) (v (x + (j : ZMod n))) ∉ U)).card open Classical in /-- `β(x)`: the positions of `F_{u₀}(x)` at vertices of the exceptional set `X` (run boundaries in the range). -/ noncomputable def bdc {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (X : Finset (ZMod n)) (u₀ : ℝ) (x : ZMod n) : ℕ := ((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∈ X)).card open Classical in /-- `F_{u₀}(x)` is an initial segment of the offsets. -/ theorem Fu0_initial {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u₀ : ℝ} {x : ZMod n} {j j' : ℕ} (hj : j ∈ Fu0 v u₀ x) (h1 : 1 ≤ j') (h2 : j' ≤ j) : j' ∈ Fu0 v u₀ x := by unfold Fu0 at hj ⊢ obtain ⟨hjn, hF, hd⟩ := mem_filter.mp hj have hjn' := mem_range.mp hjn have hoff : ((x + (j : ZMod n)) - x).val = j := off_cast x hjn' have hoff' : ((x + (j' : ZMod n)) - x).val = j' := off_cast x (by omega) have hF' : inF v x (x + j') := by unfold inF at hF ⊢ rw [hoff] at hF rw [hoff'] exact ⟨by omega, by omega⟩ refine mem_filter.mpr ⟨mem_range.mpr (by omega), hF', ?_⟩ rcases h2.lt_or_eq with h | h · have := F_strict hv hF (show ((x + (j' : ZMod n)) - x).val < ((x + (j : ZMod n)) - x).val by rw [hoff, hoff']; exact h) linarith · rw [h]; exact hd open Classical in /-- For a class `u < u₀` with `x ∈ A_u`, the partner `T_u x` sits at a position of `F_{u₀}(x)`. -/ theorem pos_mem_Fu0 {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {u u₀ : ℝ} (hu : u < u₀) {x : ZMod n} (hx : x ∈ Au v u) : (Tu v u x - x).val ∈ Fu0 v u₀ x := by obtain ⟨hF, hd⟩ := Tu_spec hx unfold Fu0 refine mem_filter.mpr ⟨mem_range.mpr (ZMod.val_lt _), ?_, ?_⟩ · rw [add_off] exact hF · rw [add_off, hd] exact hu /-- Positions of classes increase with the class. -/ theorem pos_strict {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u u' : ℝ} (huu : u < u') {x : ZMod n} (hx : x ∈ Au v u) (hx' : x ∈ Au v u') : (Tu v u x - x).val < (Tu v u' x - x).val := by obtain ⟨hF, hd⟩ := Tu_spec hx obtain ⟨hF', hd'⟩ := Tu_spec hx' by_contra hc push_neg at hc rcases hc.lt_or_eq with h | h · have := F_strict hv hF h linarith · have : Tu v u' x = Tu v u x := by have := ZMod.val_injective n h linear_combination this rw [this] at hd' linarith open Classical in /-- **The partition of `F_{u₀}(x)`**: its positions carry the non-deficient classes of `U_s = U ∩ (−∞, u₀)` (one each) and the `nf(x)` extra positions, so `|F_{u₀}(x)| = (|U_s| − def(x)) + nf(x)`. -/ theorem Fu0_card {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (x : ZMod n) : (Fu0 v u₀ x).card = ((U.filter (fun u => u < u₀)).card - dfc v (U.filter (fun u => u < u₀)) x) + nfc v U u₀ x := by have hs := card_filter_add_card_filter_not (s := Fu0 v u₀ x) (fun j : ℕ => dist (v x) (v (x + (j : ZMod n))) ∈ U) have hcls : ((Fu0 v u₀ x).filter (fun j : ℕ => dist (v x) (v (x + (j : ZMod n))) ∈ U)).card = ((U.filter (fun u => u < u₀)).filter (fun u => x ∈ Au v u)).card := by refine card_bij (fun (j : ℕ) _ => dist (v x) (v (x + (j : ZMod n)))) ?_ ?_ ?_ · intro j hj obtain ⟨hjF, hjU⟩ := mem_filter.mp hj unfold Fu0 at hjF obtain ⟨_, hF, hd⟩ := mem_filter.mp hjF exact mem_filter.mpr ⟨mem_filter.mpr ⟨hjU, hd⟩, mem_Au.mpr ⟨_, hF, rfl⟩⟩ · intro j hj j' hj' hjj obtain ⟨hjF, _⟩ := mem_filter.mp hj obtain ⟨hjF', _⟩ := mem_filter.mp hj' unfold Fu0 at hjF hjF' obtain ⟨hjn, hF, _⟩ := mem_filter.mp hjF obtain ⟨hjn', hF', _⟩ := mem_filter.mp hjF' have e1 : ((x + (j : ZMod n)) - x).val = j := off_cast x (mem_range.mp hjn) have e2 : ((x + (j' : ZMod n)) - x).val = j' := off_cast x (mem_range.mp hjn') by_contra hne rcases lt_or_gt_of_ne hne with h | h · have := F_strict hv hF' (show ((x + (j : ZMod n)) - x).val < ((x + (j' : ZMod n)) - x).val by rw [e1, e2]; exact h) linarith · have := F_strict hv hF (show ((x + (j' : ZMod n)) - x).val < ((x + (j : ZMod n)) - x).val by rw [e1, e2]; exact h) linarith · intro u hu obtain ⟨hu1, hxA⟩ := mem_filter.mp hu obtain ⟨huU, hu0⟩ := mem_filter.mp hu1 refine ⟨(Tu v u x - x).val, mem_filter.mpr ⟨pos_mem_Fu0 hu0 hxA, ?_⟩, ?_⟩ · rw [add_off, (Tu_spec hxA).2] exact huU · rw [add_off, (Tu_spec hxA).2] have hd := card_filter_add_card_filter_not (s := U.filter (fun u => u < u₀)) (fun u => x ∈ Au v u) unfold dfc nfc omega open Classical in /-- **Budget `Σ def`**: `Σ_x def(x) = Σ_{u ∈ U_s} (n − |A_u|)`, and `2Σ_x def(x) + Σ_{U_s} #chO ≤ 2n|U_s| + |B|(|B| − 1)` (i.e. `Σ def ≤ εnK + |B|²/2` when `f ≥ (1 − ε)n`). -/ theorem dfc_total {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) : 2 * ∑ x, dfc v (U.filter (fun u => u < u₀)) x + ∑ u ∈ U.filter (fun u => u < u₀), (chO v u).card ≤ 2 * n * (U.filter (fun u => u < u₀)).card + ((thinB v u₀).card * (thinB v u₀).card - (thinB v u₀).card) := by have h1 : ∑ x, defc v (U.filter (fun u => u < u₀)) x = 2 * ∑ x, dfc v (U.filter (fun u => u < u₀)) x := by rw [sum_defc] have h2 : ∑ x, dfc v (U.filter (fun u => u < u₀)) x = ∑ u ∈ U.filter (fun u => u < u₀), (univ.filter (fun y => y ∉ Au v u)).card := by unfold dfc simp only [card_filter] exact sum_comm rw [h2, mul_sum] refine sum_congr rfl (fun u _ => ?_) have e1 := card_filter_add_card_filter_not (s := (univ : Finset (ZMod n))) (fun y => y ∈ Au v u) have e2 := card_filter_add_card_filter_not (s := (univ : Finset (ZMod n))) (fun y => y ∈ (Au v u).image (Tu v u)) have f1 : (univ.filter (fun y => y ∈ Au v u)).card = (Au v u).card := by rw [filter_mem_eq_inter, univ_inter] have f2 : (univ.filter (fun y => y ∈ (Au v u).image (Tu v u))).card = (Au v u).card := by rw [filter_mem_eq_inter, univ_inter, card_image_of_injOn (Tu_injOn hv u)] omega have := defc_total hv U u₀ omega open Classical in /-- **Budget `Σ nf`**: the extra positions number at most the ordered pairs outside the classes `U`. -/ theorem nfc_total {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) (u₀ : ℝ) : ∑ x, nfc v U u₀ x ≤ (((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card := by have hsig : ∑ x, nfc v U u₀ x = (univ.sigma (fun x => (Fu0 v u₀ x).filter (fun j : ℕ => dist (v x) (v (x + (j : ZMod n))) ∉ U))).card := by rw [card_sigma] rfl rw [hsig] refine card_le_card_of_injOn (fun p => (p.1, p.1 + (p.2 : ZMod n))) (fun p hp => ?_) (fun p hp q hq hpq => ?_) · obtain ⟨_, hp2⟩ := mem_sigma.mp hp obtain ⟨hpF, hpU⟩ := mem_filter.mp hp2 unfold Fu0 at hpF obtain ⟨hjn, hF, _⟩ := mem_filter.mp hpF refine mem_filter.mpr ⟨mem_product.mpr ⟨mem_univ _, mem_univ _⟩, ?_, hpU⟩ intro h have h' : p.1 = p.1 + (p.2 : ZMod n) := h have := hF.1 rw [← h', sub_self, ZMod.val_zero] at this exact lt_irrefl 0 this · obtain ⟨_, hp2⟩ := mem_sigma.mp hp obtain ⟨_, hq2⟩ := mem_sigma.mp hq have hpn := mem_range.mp (mem_filter.mp (mem_filter.mp hp2).1).1 have hqn := mem_range.mp (mem_filter.mp (mem_filter.mp hq2).1).1 simp only [Prod.mk.injEq] at hpq obtain ⟨h1, h2⟩ := hpq have h3 : (p.2 : ZMod n) = (q.2 : ZMod n) := by rw [h1] at h2; exact add_left_cancel h2 have h4 := congrArg ZMod.val h3 rw [ZMod.val_cast_of_lt hpn, ZMod.val_cast_of_lt hqn] at h4 exact Sigma.ext h1 (heq_of_eq h4) open Classical in /-- **Budget `Σ β`**: `Σ_x β(x) ≤ n|X|`. -/ theorem bdc_total {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (X : Finset (ZMod n)) (u₀ : ℝ) : ∑ x, bdc v X u₀ x ≤ n * X.card := by have hx : ∀ x : ZMod n, bdc v X u₀ x ≤ X.card := by intro x unfold bdc refine card_le_card_of_injOn (fun j => x + (j : ZMod n)) (fun j hj => (mem_filter.mp hj).2) (fun j hj j' hj' h => ?_) have hjn := mem_range.mp (mem_filter.mp (mem_filter.mp hj).1).1 have hjn' := mem_range.mp (mem_filter.mp (mem_filter.mp hj').1).1 have h3 : (j : ZMod n) = (j' : ZMod n) := add_left_cancel h have h4 := congrArg ZMod.val h3 rwa [ZMod.val_cast_of_lt hjn, ZMod.val_cast_of_lt hjn'] at h4 calc ∑ x, bdc v X u₀ x ≤ ∑ _x : ZMod n, X.card := sum_le_sum (fun x _ => hx x) _ = n * X.card := by rw [sum_const, card_univ, ZMod.card, smul_eq_mul] end Erdos94ThmA /-! ### (F15) INVERSE Theorem 11.15, part 2a: the classes of `U_s` in increasing order, breaks, clean blocks of six consecutive classes, and the count of clean starts -/ namespace Erdos94ThmA open Finset /-- The `i`-th smallest element of `S` (`0` for `i ≥ |S|`). -/ noncomputable def usort (S : Finset ℝ) (i : ℕ) : ℝ := if h : i < S.card then S.orderEmbOfFin rfl ⟨i, h⟩ else 0 theorem usort_mem {S : Finset ℝ} {i : ℕ} (h : i < S.card) : usort S i ∈ S := by unfold usort rw [dif_pos h] exact orderEmbOfFin_mem S rfl _ theorem usort_lt {S : Finset ℝ} {i j : ℕ} (hij : i < j) (hj : j < S.card) : usort S i < usort S j := by unfold usort rw [dif_pos (hij.trans hj), dif_pos hj] exact (S.orderEmbOfFin rfl).strictMono (Fin.mk_lt_mk.mpr hij) theorem usort_surj {S : Finset ℝ} {u : ℝ} (hu : u ∈ S) : ∃ i < S.card, usort S i = u := by have : u ∈ Set.range (S.orderEmbOfFin rfl) := by rw [range_orderEmbOfFin] exact hu obtain ⟨⟨i, hi⟩, hiu⟩ := this refine ⟨i, hi, ?_⟩ unfold usort rw [dif_pos hi] exact hiu /-- No element of `S` lies strictly between two consecutive sorted elements. -/ theorem usort_gap {S : Finset ℝ} {i : ℕ} (hi : i + 1 < S.card) {u : ℝ} (hu : u ∈ S) (h1 : usort S i < u) (h2 : u < usort S (i + 1)) : False := by obtain ⟨j, hj, rfl⟩ := usort_surj hu rcases lt_trichotomy j i with h | h | h · have := usort_lt h (by omega : i < S.card) linarith · rw [h] at h1 linarith · rcases lt_trichotomy j (i + 1) with h' | h' | h' · omega · rw [h'] at h2 linarith · have := usort_lt h' hj linarith open Classical in /-- The deficient class indices of `x`. -/ noncomputable def defI {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (S : Finset ℝ) (x : ZMod n) : Finset ℕ := (range S.card).filter (fun i => x ∉ Au v (usort S i)) open Classical in /-- The extra-position breaks of `x`: consecutive non-deficient classes at non-consecutive positions. -/ noncomputable def brkI {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (S : Finset ℝ) (x : ZMod n) : Finset ℕ := (range S.card).filter (fun i => i + 1 < S.card ∧ x ∈ Au v (usort S i) ∧ x ∈ Au v (usort S (i + 1)) ∧ (Tu v (usort S (i + 1)) x - x).val ≠ (Tu v (usort S i) x - x).val + 1) open Classical in /-- The run breaks of `x`: non-deficient classes realised at a vertex of `X`. -/ noncomputable def runI {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (S : Finset ℝ) (X : Finset (ZMod n)) (x : ZMod n) : Finset ℕ := (range S.card).filter (fun i => x ∈ Au v (usort S i) ∧ Tu v (usort S i) x ∈ X) open Classical in theorem defI_card {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (S : Finset ℝ) (x : ZMod n) : (defI v S x).card = dfc v S x := by unfold defI dfc refine card_bij (fun i _ => usort S i) (fun i hi => ?_) (fun i hi j hj hij => ?_) (fun u hu => ?_) · obtain ⟨hi1, hi2⟩ := mem_filter.mp hi exact mem_filter.mpr ⟨usort_mem (mem_range.mp hi1), hi2⟩ · have hi1 := mem_range.mp (mem_filter.mp hi).1 have hj1 := mem_range.mp (mem_filter.mp hj).1 by_contra hne rcases lt_or_gt_of_ne hne with h | h · have := usort_lt h hj1 linarith · have := usort_lt h hi1 linarith · obtain ⟨hu1, hu2⟩ := mem_filter.mp hu obtain ⟨i, hi, rfl⟩ := usort_surj hu1 exact ⟨i, mem_filter.mpr ⟨mem_range.mpr hi, hu2⟩, rfl⟩ open Classical in /-- Breaks are paid by extra positions: `#breaks(x) ≤ nf(x)`. -/ theorem brkI_card {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (x : ZMod n) : (brkI v (U.filter (fun u => u < u₀)) x).card ≤ nfc v U u₀ x := by unfold brkI nfc refine card_le_card_of_injOn (fun i => (Tu v (usort (U.filter (fun u => u < u₀)) i) x - x).val + 1) (fun i hi => ?_) (fun i hi j hj hij => ?_) · obtain ⟨hiK, hi1, hxi, hxi1, hne⟩ := mem_filter.mp hi have hus0 := usort_mem (mem_range.mp hiK) have hus1 := usort_mem hi1 have hlt := pos_strict hv (usort_lt (by omega : i < i + 1) hi1) hxi hxi1 have hmem1 := pos_mem_Fu0 (mem_filter.mp hus1).2 hxi1 have hmem := Fu0_initial hv hmem1 (by omega : 1 ≤ (Tu v (usort (U.filter (fun u => u < u₀)) i) x - x).val + 1) (by omega) refine mem_filter.mpr ⟨hmem, ?_⟩ intro hU -- the distance at the extra position lies strictly between two consecutive classes obtain ⟨hF, hd⟩ := Tu_spec hxi obtain ⟨hF1, hd1⟩ := Tu_spec hxi1 unfold Fu0 at hmem obtain ⟨hjn, hFj, hdj⟩ := mem_filter.mp hmem have e0 := off_cast x (mem_range.mp hjn) have hlo : dist (v x) (v (Tu v (usort (U.filter (fun u => u < u₀)) i) x)) < dist (v x) (v (x + (((Tu v (usort (U.filter (fun u => u < u₀)) i) x - x).val + 1 : ℕ) : ZMod n))) := F_strict hv hFj (by rw [e0]; omega) have hhi : dist (v x) (v (x + (((Tu v (usort (U.filter (fun u => u < u₀)) i) x - x).val + 1 : ℕ) : ZMod n))) < dist (v x) (v (Tu v (usort (U.filter (fun u => u < u₀)) (i + 1)) x)) := F_strict hv hF1 (by rw [e0]; omega) rw [hd] at hlo rw [hd1] at hhi exact usort_gap hi1 (mem_filter.mpr ⟨hU, hdj⟩) hlo hhi · have hi' := mem_filter.mp hi have hj' := mem_filter.mp hj have hij' : (Tu v (usort (U.filter (fun u => u < u₀)) i) x - x).val = (Tu v (usort (U.filter (fun u => u < u₀)) j) x - x).val := by simp only at hij omega by_contra hne rcases lt_or_gt_of_ne hne with h | h · have := pos_strict hv (usort_lt h (mem_range.mp hj'.1)) hi'.2.2.1 hj'.2.2.1 omega · have := pos_strict hv (usort_lt h (mem_range.mp hi'.1)) hj'.2.2.1 hi'.2.2.1 omega open Classical in /-- Run breaks are paid by the boundaries in the range: `#runbreaks(x) ≤ β(x)`. -/ theorem runI_card {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) (x : ZMod n) : (runI v (U.filter (fun u => u < u₀)) X x).card ≤ bdc v X u₀ x := by unfold runI bdc refine card_le_card_of_injOn (fun i => (Tu v (usort (U.filter (fun u => u < u₀)) i) x - x).val) (fun i hi => ?_) (fun i hi j hj hij => ?_) · obtain ⟨hiK, hxi, hX⟩ := mem_filter.mp hi have hus0 := usort_mem (mem_range.mp hiK) refine mem_filter.mpr ⟨pos_mem_Fu0 (mem_filter.mp hus0).2 hxi, ?_⟩ simp only rw [add_off] exact hX · have hi' := mem_filter.mp hi have hj' := mem_filter.mp hj have hij' : (Tu v (usort (U.filter (fun u => u < u₀)) i) x - x).val = (Tu v (usort (U.filter (fun u => u < u₀)) j) x - x).val := hij by_contra hne rcases lt_or_gt_of_ne hne with h | h · have := pos_strict hv (usort_lt h (mem_range.mp hj'.1)) hi'.2.1 hj'.2.1 omega · have := pos_strict hv (usort_lt h (mem_range.mp hi'.1)) hj'.2.1 hi'.2.1 omega /-- A clean block of six consecutive classes `a, …, a+5` for `x`: all non-deficient, at consecutive positions, the first five realised outside `X`. -/ def cleanAt {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (S : Finset ℝ) (X : Finset (ZMod n)) (x : ZMod n) (a : ℕ) : Prop := (∀ k ≤ 5, x ∈ Au v (usort S (a + k))) ∧ (∀ k < 5, (Tu v (usort S (a + k + 1)) x - x).val = (Tu v (usort S (a + k)) x - x).val + 1) ∧ (∀ k < 5, Tu v (usort S (a + k)) x ∉ X) open Classical in /-- Starts that are not clean for `x` lie within distance `5` of a deficient class or within `4` of a break. -/ theorem not_clean_sub {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (S : Finset ℝ) (X : Finset (ZMod n)) (x : ZMod n) : (range (S.card - 5)).filter (fun a => ¬ cleanAt v S X x a) ⊆ (defI v S x).biUnion (fun d => Icc (d - 5) d) ∪ (brkI v S x ∪ runI v S X x).biUnion (fun e => Icc (e - 4) e) := by intro a ha obtain ⟨haK, hnc⟩ := mem_filter.mp ha have haK' := mem_range.mp haK by_cases hD : ∃ k ≤ 5, x ∉ Au v (usort S (a + k)) · obtain ⟨k, hk, hxk⟩ := hD refine mem_union_left _ (mem_biUnion.mpr ⟨a + k, mem_filter.mpr ⟨mem_range.mpr (by omega), hxk⟩, ?_⟩) exact mem_Icc.mpr ⟨by omega, by omega⟩ · push_neg at hD by_cases hB : ∃ k < 5, (Tu v (usort S (a + k + 1)) x - x).val ≠ (Tu v (usort S (a + k)) x - x).val + 1 · obtain ⟨k, hk, hne⟩ := hB have h1 : x ∈ Au v (usort S (a + k + 1)) := by have := hD (k + 1) (by omega) rwa [show a + (k + 1) = a + k + 1 by ring] at this refine mem_union_right _ (mem_biUnion.mpr ⟨a + k, mem_union_left _ (mem_filter.mpr ⟨mem_range.mpr (by omega), by omega, hD k (by omega), h1, hne⟩), ?_⟩) exact mem_Icc.mpr ⟨by omega, by omega⟩ · push_neg at hB have hR : ∃ k < 5, Tu v (usort S (a + k)) x ∈ X := by by_contra hR push_neg at hR exact hnc ⟨hD, hB, hR⟩ obtain ⟨k, hk, hX⟩ := hR refine mem_union_right _ (mem_biUnion.mpr ⟨a + k, mem_union_right _ (mem_filter.mpr ⟨mem_range.mpr (by omega), hD k (by omega), hX⟩), ?_⟩) exact mem_Icc.mpr ⟨by omega, by omega⟩ open Classical in /-- **Count of clean starts for a pair** `(x, x')`: at least `|U_s| − 5 − 6(def x + def x') − 5(nf x + nf x' + β x + β x')` starts `a < |U_s| − 5` are clean for both. -/ theorem clean_count {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) (x x' : ZMod n) : (U.filter (fun u => u < u₀)).card - 5 ≤ ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X x' a)).card + (6 * (dfc v (U.filter (fun u => u < u₀)) x + dfc v (U.filter (fun u => u < u₀)) x') + 5 * (nfc v U u₀ x + nfc v U u₀ x' + bdc v X u₀ x + bdc v X u₀ x')) := by have hbad : ∀ y : ZMod n, ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X y a)).card ≤ 6 * dfc v (U.filter (fun u => u < u₀)) y + 5 * (nfc v U u₀ y + bdc v X u₀ y) := by intro y have h1 := card_le_card (not_clean_sub v (U.filter (fun u => u < u₀)) X y) have h2 := card_union_le ((defI v (U.filter (fun u => u < u₀)) y).biUnion (fun d => Icc (d - 5) d)) ((brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) X y).biUnion (fun e => Icc (e - 4) e)) have h3 : ((defI v (U.filter (fun u => u < u₀)) y).biUnion (fun d => Icc (d - 5) d)).card ≤ 6 * dfc v (U.filter (fun u => u < u₀)) y := by refine card_biUnion_le.trans ?_ rw [← defI_card] calc ∑ d ∈ defI v (U.filter (fun u => u < u₀)) y, (Icc (d - 5) d).card ≤ ∑ d ∈ defI v (U.filter (fun u => u < u₀)) y, 6 := sum_le_sum (fun d _ => by rw [Nat.card_Icc]; omega) _ = 6 * (defI v (U.filter (fun u => u < u₀)) y).card := by rw [sum_const, smul_eq_mul, mul_comm] have h4 : ((brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) X y).biUnion (fun e => Icc (e - 4) e)).card ≤ 5 * (nfc v U u₀ y + bdc v X u₀ y) := by refine card_biUnion_le.trans ?_ calc ∑ e ∈ brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) X y, (Icc (e - 4) e).card ≤ ∑ e ∈ brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) X y, 5 := sum_le_sum (fun e _ => by rw [Nat.card_Icc]; omega) _ = 5 * (brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) X y).card := by rw [sum_const, smul_eq_mul, mul_comm] _ ≤ 5 * (nfc v U u₀ y + bdc v X u₀ y) := by have := card_union_le (brkI v (U.filter (fun u => u < u₀)) y) (runI v (U.filter (fun u => u < u₀)) X y) have := brkI_card hv U u₀ y have := runI_card hv U u₀ X y omega omega have hsplit := card_filter_add_card_filter_not (s := range ((U.filter (fun u => u < u₀)).card - 5)) (fun a => cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X x' a) have hsub : (range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ (cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X x' a)) ⊆ (range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X x a) ∪ (range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X x' a) := by intro a ha obtain ⟨haK, hnc⟩ := mem_filter.mp ha by_cases h : cleanAt v (U.filter (fun u => u < u₀)) X x a · exact mem_union_right _ (mem_filter.mpr ⟨haK, fun h' => hnc ⟨h, h'⟩⟩) · exact mem_union_left _ (mem_filter.mpr ⟨haK, h⟩) have hc := card_le_card hsub have hu := card_union_le ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X x a)) ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X x' a)) have hb1 := hbad x have hb2 := hbad x' rw [card_range] at hsplit omega end Erdos94ThmA /-! ### (F16) INVERSE Theorem 11.15, part 2b: clean blocks are arcs of one rotation; Lemma 11.17 puts them on the partner's radius; positions on a radius; ranges shift inside `F_{u₀}` -/ namespace Erdos94ThmA open Finset open Classical in /-- The exceptional set of the rotation `g z = O + ω(z − O)`: the `z` with `v_{z+1} ≠ g(v_z)`. -/ noncomputable def excX {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (O ω : ℂ) : Finset (ZMod n) := univ.filter (fun z => v (z + 1) ≠ O + ω * (v z - O)) /-- Along a clean block the realising vertices are consecutive points of one `g`-orbit. -/ theorem block_rot {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {S : Finset ℝ} {O ω : ℂ} {x : ZMod n} {a : ℕ} (hc : cleanAt v S (excX v O ω) x a) : ∀ k ≤ 5, v (Tu v (usort S (a + k)) x) - O = ω ^ k * (v (Tu v (usort S a) x) - O) := by intro k hk induction k with | zero => simp | succ k ih => have ih' := ih (by omega) have hpos := hc.2.1 k (by omega) have hT : Tu v (usort S (a + (k + 1))) x = Tu v (usort S (a + k)) x + 1 := by have e1 := add_off x (Tu v (usort S (a + (k + 1))) x) have e2 := add_off x (Tu v (usort S (a + k)) x) rw [show a + (k + 1) = a + k + 1 by ring] at e1 ⊢ rw [hpos] at e1 rw [← e1] conv_rhs => rw [← e2] push_cast ring have hX := hc.2.2 k (by omega) unfold excX at hX rw [mem_filter] at hX push_neg at hX have hX' := hX (mem_univ _) rw [hT, hX', pow_succ] rw [show O + ω * (v (Tu v (usort S (a + k)) x) - O) - O = ω * (v (Tu v (usort S (a + k)) x) - O) by ring, ih'] ring open Classical in /-- **Lemma 11.17 on a clean block**: if `x, x'` are both clean at `a` (`a + 5 < |S|`), `ω = e^{iα}` with `0 < α`, `6α < 2π`, and `|Ox| ≠ |Ox'|`, then `x`'s realisation of the class `u_a` lies on the circle of radius `|Ox'|`. -/ theorem block_radius {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {S : Finset ℝ} {O : ℂ} {α : ℝ} (hα0 : 0 < α) (hα : 6 * α < 2 * Real.pi) {x x' : ZMod n} {a : ℕ} (haK : a + 5 < S.card) (hc : cleanAt v S (excX v O (Complex.exp (α * Complex.I))) x a) (hc' : cleanAt v S (excX v O (Complex.exp (α * Complex.I))) x' a) (hne : ‖v x - O‖ ≠ ‖v x' - O‖) : ‖v (Tu v (usort S a) x) - O‖ = ‖v x' - O‖ := by have hexp : ∀ k : ℕ, Complex.exp (((k : ℝ) * α : ℝ) * Complex.I) = Complex.exp (α * Complex.I) ^ k := by intro k rw [← Complex.exp_nat_mul] congr 1 push_cast ring have hreal : ∀ y : ZMod n, cleanAt v S (excX v O (Complex.exp (α * Complex.I))) y a → ∀ k : ℕ, k < 6 → dist (v y) (O + Complex.exp (((k : ℝ) * α : ℝ) * Complex.I) * (v (Tu v (usort S a) y) - O)) = usort S (a + k) := by intro y hy k hk have h1 := block_rot hy k (by omega) rw [hexp, ← h1, add_sub_cancel] exact (Tu_spec (hy.1 k (by omega))).2 have hu : ∀ k, k + 1 < 6 → usort S (a + k) < usort S (a + (k + 1)) := fun k hk => usort_lt (by omega) (by omega) obtain ⟨hrad, _⟩ := lemma1117 hα0 hα (le_refl 6) (fun k => usort S (a + k)) hu (hreal x hc) (hreal x' hc') rcases hrad with h | h · exact absurd h.1 hne · exact h.2 open Classical in /-- Clean starts give distinct positions of `F_{u₀}(x)` on the partner's radius. -/ theorem pos_on_radius {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) {O : ℂ} {α : ℝ} (hα0 : 0 < α) (hα : 6 * α < 2 * Real.pi) {x x' : ZMod n} (hne : ‖v x - O‖ ≠ ‖v x' - O‖) : ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O (Complex.exp (α * Complex.I))) x a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O (Complex.exp (α * Complex.I))) x' a)).card ≤ ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x' - O‖)).card := by refine card_le_card_of_injOn (fun a => (Tu v (usort (U.filter (fun u => u < u₀)) a) x - x).val) (fun a ha => ?_) (fun a ha b hb hab => ?_) · obtain ⟨haK, hc, hc'⟩ := mem_filter.mp ha have haK' := mem_range.mp haK have hus := usort_mem (show a < (U.filter (fun u => u < u₀)).card by omega) refine mem_filter.mpr ⟨pos_mem_Fu0 (mem_filter.mp hus).2 (by have := hc.1 0 (by omega); simpa using this), ?_⟩ simp only rw [add_off] exact block_radius hα0 hα (by omega) hc hc' hne · have ha' := mem_filter.mp ha have hb' := mem_filter.mp hb have haK := mem_range.mp ha'.1 have hbK := mem_range.mp hb'.1 have hxa : x ∈ Au v (usort (U.filter (fun u => u < u₀)) a) := by have := ha'.2.1.1 0 (by omega); simpa using this have hxb : x ∈ Au v (usort (U.filter (fun u => u < u₀)) b) := by have := hb'.2.1.1 0 (by omega); simpa using this have hab' : (Tu v (usort (U.filter (fun u => u < u₀)) a) x - x).val = (Tu v (usort (U.filter (fun u => u < u₀)) b) x - x).val := hab by_contra hne' rcases lt_or_gt_of_ne hne' with h | h · have := pos_strict hv (usort_lt h (by omega)) hxa hxb omega · have := pos_strict hv (usort_lt h (by omega)) hxb hxa omega open Classical in /-- Ranges shift: for `0 < j₀ < j` in `F_{u₀}(x)`, `j − j₀ ∈ F_{u₀}(x + j₀)` (sub-arc turning and fact (iii)). -/ theorem Fu0_shift {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u₀ : ℝ} {x : ZMod n} {j₀ j : ℕ} (h0 : 0 < j₀) (hlt : j₀ < j) (hj : j ∈ Fu0 v u₀ x) : j - j₀ ∈ Fu0 v u₀ (x + (j₀ : ZMod n)) ∧ x + (j₀ : ZMod n) + ((j - j₀ : ℕ) : ZMod n) = x + (j : ZMod n) := by have he : x + (j₀ : ZMod n) + ((j - j₀ : ℕ) : ZMod n) = x + (j : ZMod n) := by rw [Nat.cast_sub hlt.le] ring refine ⟨?_, he⟩ unfold Fu0 at hj ⊢ obtain ⟨hjn, hF, hd⟩ := mem_filter.mp hj have hjn' := mem_range.mp hjn have hoff : ((x + (j : ZMod n)) - x).val = j := off_cast x hjn' have hτ := inF_arc hv hF rw [hoff] at hτ refine mem_filter.mpr ⟨mem_range.mpr (by omega), ?_, ?_⟩ · rw [inF_iff hv] have hoff2 : ((x + (j₀ : ZMod n) + ((j - j₀ : ℕ) : ZMod n)) - (x + (j₀ : ZMod n))).val = j - j₀ := off_cast _ (by omega) rw [hoff2] refine ⟨by omega, ?_⟩ have hs := turning_split v x j₀ (j - j₀ - 1) rw [show j₀ + (j - j₀ - 1) = j - 1 by omega] at hs linarith [turning_nonneg hv x j₀] · rw [he] have := arc_nest hv x hτ (i := j₀) (j := j) hlt le_rfl (Or.inl h0) linarith end Erdos94ThmA /-! ### (F17) INVERSE Theorem 11.15 (one rotation + near-full short classes ⇒ one circle) -/ namespace Erdos94ThmA open Finset open Classical in /-- The good vertices `G` of the proof of Theorem 11.15: `def ≤ K/480`, `nf ≤ K/480`, `β ≤ K/240`, `K = |U_s|`. -/ noncomputable def goodG {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) : Finset (ZMod n) := univ.filter (fun x => (dfc v (U.filter (fun u => u < u₀)) x : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) / 480 ∧ (nfc v U u₀ x : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) / 480 ∧ (bdc v X u₀ x : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) / 240) open Classical in /-- Two good vertices have at least `(73/80)K − 5` common clean starts. -/ theorem clean_G {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) {x x' : ZMod n} (hx : x ∈ goodG v U u₀ X) (hx' : x' ∈ goodG v U u₀ X) (hK : 5 ≤ (U.filter (fun u => u < u₀)).card) : (73 / 80 : ℝ) * (U.filter (fun u => u < u₀)).card - 5 ≤ (((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X x' a)).card : ℝ) := by have hc := clean_count hv U u₀ X x x' have hcR : (((U.filter (fun u => u < u₀)).card - 5 : ℕ) : ℝ) ≤ (((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X x' a)).card : ℝ) + (6 * ((dfc v (U.filter (fun u => u < u₀)) x : ℝ) + dfc v (U.filter (fun u => u < u₀)) x') + 5 * ((nfc v U u₀ x : ℝ) + nfc v U u₀ x' + bdc v X u₀ x + bdc v X u₀ x')) := by exact_mod_cast hc rw [Nat.cast_sub hK] at hcR obtain ⟨_, h1, h2, h3⟩ := mem_filter.mp hx obtain ⟨_, h1', h2', h3'⟩ := mem_filter.mp hx' push_cast at hcR linarith /-- `F_{u₀}(x)` has at most `K + K/480` positions at a good vertex. -/ theorem Fu0_card_G {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) {x : ZMod n} (hx : x ∈ goodG v U u₀ X) : ((Fu0 v u₀ x).card : ℝ) ≤ (U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 := by have h := Fu0_card hv U u₀ x have h' : (Fu0 v u₀ x).card ≤ (U.filter (fun u => u < u₀)).card + nfc v U u₀ x := by omega have h'' : ((Fu0 v u₀ x).card : ℝ) ≤ (U.filter (fun u => u < u₀)).card + (nfc v U u₀ x : ℝ) := by exact_mod_cast h' have := (mem_filter.mp hx).2.2.1 linarith open Classical in /-- **Step (3) of Theorem 11.15, local form**: if `x` and `x₂` are good and fewer than `0.4K` positions of `F_{u₀}(x)` are at non-good vertices, then `|Ox| = |Ox₂|` (the FIRST good vertex of `F_{u₀}(x)` on the radius of `x₂` replaces the half-range argument; only non-good vertices inside `x`'s own range enter, so this also serves an averaged step (3)). -/ theorem one_radius_loc {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) {O : ℂ} {α : ℝ} (hα0 : 0 < α) (hα : 6 * α < 2 * Real.pi) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {x x₂ : ZMod n} (hloc : (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card) (hx : x ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))) (hx₂ : x₂ ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))) : ‖v x - O‖ = ‖v x₂ - O‖ := by by_contra hne have hK5 : 5 ≤ (U.filter (fun u => u < u₀)).card := by omega have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 -- (1) many positions of `x` on the radius of `x₂` have hT2 : (73 / 80 : ℝ) * (U.filter (fun u => u < u₀)).card - 5 ≤ (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card : ℝ) := by have h1 := clean_G hv U u₀ (excX v O (Complex.exp (α * Complex.I))) hx hx₂ hK5 have h2 := pos_on_radius hv U u₀ hα0 hα hne have h2R : (((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O (Complex.exp (α * Complex.I))) x a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O (Complex.exp (α * Complex.I))) x₂ a)).card : ℝ) ≤ (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card : ℝ) := by exact_mod_cast h2 linarith -- (2) the positions on that radius at non-good vertices are few have hbadG : (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℝ) ≤ (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℝ) := by have : ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card ≤ ((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card := by apply card_le_card intro j hj obtain ⟨hjF, _, hjG⟩ := mem_filter.mp hj exact mem_filter.mpr ⟨hjF, hjG⟩ exact_mod_cast this -- (3) a good vertex on the radius of `x₂`, the first one have hsplitG := card_filter_add_card_filter_not (s := (Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)) (fun j : ℕ => x + (j : ZMod n) ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))) rw [filter_filter, filter_filter] at hsplitG have hne' : ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).Nonempty := by rw [← card_pos] have : (0 : ℝ) < (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℝ) := by have hs : ((((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℕ) : ℝ) + (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℝ) = (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card : ℝ) := by exact_mod_cast hsplitG linarith exact_mod_cast this obtain ⟨j₀, hj₀⟩ : ∃ j₀, j₀ = ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).min' hne' := ⟨_, rfl⟩ have hj₀mem := min'_mem _ hne' rw [← hj₀] at hj₀mem obtain ⟨hj₀F, hj₀r, hj₀G⟩ := mem_filter.mp hj₀mem have hj₀min : ∀ j ∈ (Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))), j₀ ≤ j := by intro j hj rw [hj₀] exact min'_le _ _ hj have hj₀pos : 0 < j₀ := by unfold Fu0 at hj₀F obtain ⟨hjn, hF, _⟩ := mem_filter.mp hj₀F have := hF.1 rw [off_cast x (mem_range.mp hjn)] at this exact this -- (4) from `y = x + j₀` (good, on the radius of `x₂`), many positions on the radius of `x` have hney : ‖v (x + (j₀ : ZMod n)) - O‖ ≠ ‖v x - O‖ := by rw [hj₀r] exact fun h => hne h.symm have hT1y : (73 / 80 : ℝ) * (U.filter (fun u => u < u₀)).card - 5 ≤ (((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x - O‖)).card : ℝ) := by have h1 := clean_G hv U u₀ (excX v O (Complex.exp (α * Complex.I))) hj₀G hx hK5 have h2 := pos_on_radius hv U u₀ hα0 hα hney have h2R : (((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O (Complex.exp (α * Complex.I))) (x + (j₀ : ZMod n)) a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O (Complex.exp (α * Complex.I))) x a)).card : ℝ) ≤ (((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x - O‖)).card : ℝ) := by exact_mod_cast h2 linarith -- (5) so few positions of `y` lie on the radius of `x₂` have hdisj : (((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x - O‖)).card : ℝ) + (((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card : ℝ) ≤ ((Fu0 v u₀ (x + (j₀ : ZMod n))).card : ℝ) := by have hd : Disjoint ((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x - O‖)) ((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)) := by rw [disjoint_left] intro j hj hj' exact hne ((mem_filter.mp hj).2.symm.trans (mem_filter.mp hj').2) have := card_union_of_disjoint hd have h2 : (((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x - O‖)) ∪ ((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x₂ - O‖))).card ≤ (Fu0 v u₀ (x + (j₀ : ZMod n))).card := card_le_card (union_subset (filter_subset _ _) (filter_subset _ _)) rw [this] at h2 exact_mod_cast h2 have hJy := Fu0_card_G hv U u₀ (excX v O (Complex.exp (α * Complex.I))) hj₀G -- (6) the positions of `x` beyond `j₀` on the radius of `x₂` shift into `y`'s range have hR : (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ j₀ < j)).card : ℝ) ≤ (((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card : ℝ) := by have : ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ j₀ < j)).card ≤ ((Fu0 v u₀ (x + (j₀ : ZMod n))).filter (fun j : ℕ => ‖v (x + (j₀ : ZMod n) + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card := by refine card_le_card_of_injOn (fun j => j - j₀) (fun j hj => ?_) (fun j hj j' hj' h => ?_) · obtain ⟨hjF, hjr, hjlt⟩ := mem_filter.mp hj obtain ⟨hs1, hs2⟩ := Fu0_shift hv hj₀pos hjlt hjF refine mem_filter.mpr ⟨hs1, ?_⟩ simp only rw [hs2] exact hjr · have h1 := (mem_filter.mp hj).2.2 have h2 := (mem_filter.mp hj').2.2 have h' : j - j₀ = j' - j₀ := h omega exact_mod_cast this -- (7) the positions of `x` on the radius of `x₂` up to `j₀` have hlow : (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card : ℝ) ≤ (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℝ) + 1 + (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ j₀ < j)).card : ℝ) := by have hsub : (Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖) ⊆ ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))) ∪ {j₀} ∪ (Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ j₀ < j) := by intro j hj obtain ⟨hjF, hjr⟩ := mem_filter.mp hj rcases lt_trichotomy j j₀ with h | h | h · refine mem_union_left _ (mem_union_left _ (mem_filter.mpr ⟨hjF, hjr, fun hG => ?_⟩)) have := hj₀min j (mem_filter.mpr ⟨hjF, hjr, hG⟩) omega · rw [h] exact mem_union_left _ (mem_union_right _ (mem_singleton_self _)) · exact mem_union_right _ (mem_filter.mpr ⟨hjF, hjr, h⟩) have h1 := card_le_card hsub have h2 := card_union_le (((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))) ∪ {j₀}) ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ j₀ < j)) have h3 := card_union_le ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))) {j₀} rw [card_singleton] at h3 have h4 : ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖)).card ≤ ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card + 1 + ((Fu0 v u₀ x).filter (fun j : ℕ => ‖v (x + (j : ZMod n)) - O‖ = ‖v x₂ - O‖ ∧ j₀ < j)).card := by omega exact_mod_cast h4 -- (8) contradiction linarith open Classical in /-- The positions of `F_{u₀}(x)` at non-good vertices are at most the non-good vertices. -/ theorem nongood_le_compl {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u₀ : ℝ) (G : Finset (ZMod n)) (x : ZMod n) : ((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card ≤ (univ \ G).card := by refine card_le_card_of_injOn (fun j : ℕ => x + (j : ZMod n)) (fun j hj => ?_) (fun j hj j' hj' h => ?_) · exact mem_sdiff.mpr ⟨mem_univ _, (mem_filter.mp hj).2⟩ · have hjn := mem_range.mp (mem_filter.mp (mem_filter.mp hj).1).1 have hjn' := mem_range.mp (mem_filter.mp (mem_filter.mp hj').1).1 have h3 : (j : ZMod n) = (j' : ZMod n) := add_left_cancel h have h4 := congrArg ZMod.val h3 rwa [ZMod.val_cast_of_lt hjn, ZMod.val_cast_of_lt hjn'] at h4 open Classical in /-- **All good vertices lie on one circle about `O`** when fewer than `0.4K` vertices are not good. -/ theorem one_radius {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) {O : ℂ} {α : ℝ} (hα0 : 0 < α) (hα : 6 * α < 2 * Real.pi) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) (hcompl : ((univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card) {x x₂ : ZMod n} (hx : x ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))) (hx₂ : x₂ ∈ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))) : ‖v x - O‖ = ‖v x₂ - O‖ := by have h := nongood_le_compl v u₀ (goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))) x have hR : (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))))).card : ℝ) ≤ ((univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))).card : ℝ) := by exact_mod_cast h exact one_radius_loc hv U u₀ hα0 hα hK30 (lt_of_le_of_lt hR hcompl) hx hx₂ open Classical in /-- **INVERSE Theorem 11.15 (one rotation + near-full short classes ⇒ one circle).** `P` counterclockwise (`CCWPoly v`, `n ≥ 3`); `U` a set of `≥ (1/2 − ε)n` distances with `f ≥ (1 − ε)n` (`0 ≤ ε ≤ 1/100`); `u₀`; `|B(u₀)| ≤ νn`; `K := |{u ∈ U : u < u₀}| ≥ κn` (`κ > 0`) and `K ≥ 30`; the index shift agrees with the rotation `g(z) = O + e^{iα}(z − O)`, `0 < α`, `6α < 2π`, off a set `X` with `|X| ≤ ξn`. Put `b₀ := ν + 480ε + (1440ε + 240ν² + 240ξ)/κ`. If `b₀ < 0.4κ`, then all but `b₀n` vertices lie on one circle about `O`. (Deviations: `|U| ≥ (1/2 − ε)n` is explicit; `6α < 2π` is a hypothesis (FIX 2 derives it from `ξ < 1/6`); `K ≥ 30` replaces `K > 850`; (H₀) is not needed.) -/ theorem thm1115 {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) {u₀ ν κ ξ : ℝ} (hB : ((thinB v u₀).card : ℝ) ≤ ν * n) (hκ : 0 < κ) (hK : κ * n ≤ (U.filter (fun u => u < u₀)).card) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O : ℂ} {α : ℝ} (hα0 : 0 < α) (hα : 6 * α < 2 * Real.pi) (hX : ((excX v O (Complex.exp (α * Complex.I))).card : ℝ) ≤ ξ * n) (hb : ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ < 2 / 5 * κ) : ∃ ρ : ℝ, (((univ : Finset (ZMod n)).filter (fun x => ‖v x - O‖ ≠ ρ)).card : ℝ) ≤ (ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n := by have hl := ccw_leftTurns hn hv have hnR : (3 : ℝ) ≤ n := by exact_mod_cast hn have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 have hν0 : 0 ≤ ν := by have : (0 : ℝ) ≤ ((thinB v u₀).card : ℝ) := Nat.cast_nonneg _ nlinarith have hξ0 : 0 ≤ ξ := by have : (0 : ℝ) ≤ ((excX v O (Complex.exp (α * Complex.I))).card : ℝ) := Nat.cast_nonneg _ nlinarith -- budgets have hdfc : (∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) ≤ ε * n * (U.filter (fun u => u < u₀)).card + ((thinB v u₀).card : ℝ) ^ 2 / 2 := by have h1 := dfc_total hl U u₀ have h1R : 2 * (∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) + ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) ≤ 2 * n * ((U.filter (fun u => u < u₀)).card : ℝ) + ((thinB v u₀).card : ℝ) * (thinB v u₀).card := by have hBB : ((thinB v u₀).card * (thinB v u₀).card - (thinB v u₀).card : ℕ) ≤ (thinB v u₀).card * (thinB v u₀).card := Nat.sub_le _ _ have := h1.trans (Nat.add_le_add_left hBB _) exact_mod_cast this have h2 : ∑ u ∈ U.filter (fun u => u < u₀), (2 * (1 - ε) * (n : ℝ)) ≤ ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) := sum_le_sum (fun u hu => hU2 u (mem_filter.mp hu).1) rw [sum_const, nsmul_eq_mul] at h2 nlinarith have hnfc : (∑ x, (nfc v U u₀ x : ℝ)) ≤ 3 * ε * n ^ 2 := by have h1 := nfc_total v U u₀ have h1R : (∑ x, (nfc v U u₀ x : ℝ)) ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := by exact_mod_cast h1 linarith [(thm119_Ptot v U hε0 hε1 hU1 hU2).1] have hbdc : (∑ x, (bdc v (excX v O (Complex.exp (α * Complex.I))) u₀ x : ℝ)) ≤ ξ * n * n := by have h1 := bdc_total v (excX v O (Complex.exp (α * Complex.I))) u₀ have h1R : (∑ x, (bdc v (excX v O (Complex.exp (α * Complex.I))) u₀ x : ℝ)) ≤ (n : ℝ) * (excX v O (Complex.exp (α * Complex.I))).card := by exact_mod_cast h1 have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg _ nlinarith -- Markov: the complement of `G` have hKpos : (0 : ℝ) < (U.filter (fun u => u < u₀)).card := by linarith have m1 := markov_card univ (dfc v (U.filter (fun u => u < u₀))) (c := ((U.filter (fun u => u < u₀)).card : ℝ) / 480) (by positivity) hdfc have m2 := markov_card univ (nfc v U u₀) (c := ((U.filter (fun u => u < u₀)).card : ℝ) / 480) (by positivity) hnfc have m3 := markov_card univ (bdc v (excX v O (Complex.exp (α * Complex.I))) u₀) (c := ((U.filter (fun u => u < u₀)).card : ℝ) / 240) (by positivity) hbdc have hsub : univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))) ⊆ (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x) ∪ univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)) ∪ univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 240 < bdc v (excX v O (Complex.exp (α * Complex.I))) u₀ x) := by intro x hx have hxG : x ∉ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))) := (mem_sdiff.mp hx).2 unfold goodG at hxG rw [mem_filter] at hxG simp only [mem_union, mem_filter, mem_univ, true_and] by_contra hc push_neg at hc exact hxG ⟨mem_univ _, hc.1.1, hc.1.2, hc.2⟩ have hcard := card_le_card hsub have hcu1 := card_union_le (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x) ∪ univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)) (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 240 < bdc v (excX v O (Complex.exp (α * Complex.I))) u₀ x)) have hcu2 := card_union_le (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)) (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)) have hcompR : ((univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))).card : ℝ) ≤ ((univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) + ((univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) + ((univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 240 < bdc v (excX v O (Complex.exp (α * Complex.I))) u₀ x)).card : ℝ) := by exact_mod_cast hcard.trans (hcu1.trans (by omega)) -- the complement is at most `b₀n` have hcomp : ((univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))).card : ℝ) ≤ (ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n := by have hn0 : (0 : ℝ) < n := by linarith have hK0 : (0 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := hKpos.le have hc1 := mul_le_mul_of_nonneg_right hcompR hK0 have hB0 : (0 : ℝ) ≤ ((thinB v u₀).card : ℝ) := Nat.cast_nonneg _ have hB2 : ((thinB v u₀).card : ℝ) ^ 2 ≤ (ν * n) ^ 2 := pow_le_pow_left₀ hB0 hB 2 have hQ0 : 0 ≤ 1440 * ε + 240 * ν ^ 2 + 240 * ξ := by positivity have hQ : (1440 * ε + 240 * ν ^ 2 + 240 * ξ) * (n : ℝ) ^ 2 ≤ (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ * n * (U.filter (fun u => u < u₀)).card := by have h1 : (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ * n * (κ * n) = (1440 * ε + 240 * ν ^ 2 + 240 * ξ) * (n : ℝ) ^ 2 := by field_simp rw [← h1] apply mul_le_mul_of_nonneg_left hK positivity have hcK : ((univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))).card : ℝ) * (U.filter (fun u => u < u₀)).card ≤ ((ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n) * (U.filter (fun u => u < u₀)).card := by have hνK : 0 ≤ ν * n * (U.filter (fun u => u < u₀)).card := by positivity nlinarith exact le_of_mul_le_mul_right hcK hKpos have hb0n : (ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n < 2 / 5 * (U.filter (fun u => u < u₀)).card := by have hn0 : (0 : ℝ) < n := by linarith have := mul_lt_mul_of_pos_right hb hn0 linarith have hcompl : ((univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card := lt_of_le_of_lt hcomp hb0n -- conclusion by_cases hG : (goodG v U u₀ (excX v O (Complex.exp (α * Complex.I)))).Nonempty · obtain ⟨x₀, hx₀⟩ := hG refine ⟨‖v x₀ - O‖, le_trans ?_ hcomp⟩ have : (univ : Finset (ZMod n)).filter (fun x => ‖v x - O‖ ≠ ‖v x₀ - O‖) ⊆ univ \ goodG v U u₀ (excX v O (Complex.exp (α * Complex.I))) := by intro x hx refine mem_sdiff.mpr ⟨mem_univ _, fun hxG => (mem_filter.mp hx).2 ?_⟩ exact one_radius hl U u₀ hα0 hα hK30 hcompl hxG hx₀ exact_mod_cast card_le_card this · refine ⟨0, le_trans ?_ hcomp⟩ rw [not_nonempty_iff_eq_empty] at hG rw [hG, sdiff_empty] exact_mod_cast card_le_card (filter_subset _ _) end Erdos94ThmA /-! ### GLIDE Lemma 11.9 (E1), part 1: relative angles about a centre -/ namespace Erdos94ThmA open Finset /-- Relative angle of `w` seen from `z` about the centre `O`, normalised to `[0, 2π)`: `arg (w − O) − arg (z − O)` reduced mod `2π`. -/ noncomputable def rang (O z w : ℂ) : ℝ := toIcoMod Real.two_pi_pos 0 (Complex.arg (w - O) - Complex.arg (z - O)) theorem rang_mem (O z w : ℂ) : 0 ≤ rang O z w ∧ rang O z w < 2 * Real.pi := by have h := toIcoMod_mem_Ico Real.two_pi_pos 0 (Complex.arg (w - O) - Complex.arg (z - O)) rw [Set.mem_Ico, zero_add] at h exact h theorem rang_self (O z : ℂ) : rang O z z = 0 := by simp [rang] theorem rang_spec (O z w : ℂ) : ∃ m : ℤ, Complex.arg (w - O) - Complex.arg (z - O) = rang O z w + m * (2 * Real.pi) := by refine ⟨toIcoDiv Real.two_pi_pos 0 (Complex.arg (w - O) - Complex.arg (z - O)), ?_⟩ have h := toIcoMod_add_toIcoDiv_zsmul Real.two_pi_pos 0 (Complex.arg (w - O) - Complex.arg (z - O)) rw [zsmul_eq_mul] at h simp only [rang] linarith /-- If `t ≡ c (mod 2π)` and `c ∈ [0, 2π)` then `toIcoMod t = c`. -/ theorem toIcoMod_eq_of {t c : ℝ} (m : ℤ) (hc0 : 0 ≤ c) (hc1 : c < 2 * Real.pi) (h : t = c + m * (2 * Real.pi)) : toIcoMod Real.two_pi_pos 0 t = c := by rw [toIcoMod_eq_iff] refine ⟨⟨hc0, by rw [zero_add]; exact hc1⟩, m, ?_⟩ rw [zsmul_eq_mul] exact h /-- Frame change: `rang O z₁ w ≡ rang O z₁ z₂ + rang O z₂ w (mod 2π)`. -/ theorem rang_add (O z₁ z₂ w : ℂ) : toIcoMod Real.two_pi_pos 0 (rang O z₁ z₂ + rang O z₂ w) = rang O z₁ w := by obtain ⟨m₁, h₁⟩ := rang_spec O z₁ z₂ obtain ⟨m₂, h₂⟩ := rang_spec O z₂ w obtain ⟨m₃, h₃⟩ := rang_spec O z₁ w have hm := rang_mem O z₁ w refine toIcoMod_eq_of (m₃ - m₁ - m₂) hm.1 hm.2 ?_ push_cast linarith /-- An integer multiple of `2π` strictly inside `(−2π, 2π)` is `0`. -/ theorem int_mul_two_pi_eq_zero {m : ℤ} (h1 : (m : ℝ) * (2 * Real.pi) < 2 * Real.pi) (h2 : -(2 * Real.pi) < (m : ℝ) * (2 * Real.pi)) : m = 0 := by have hpi := Real.pi_pos have hm1 : (m : ℝ) < 1 := by nlinarith have hm2 : -1 < (m : ℝ) := by nlinarith have : m < 1 := by exact_mod_cast hm1 have : -1 < m := by exact_mod_cast hm2 omega /-- On a circle about `O`, the relative angle seen from any `z` determines the point. -/ theorem rang_inj {O z w w' : ℂ} {r : ℝ} (hw : ‖w - O‖ = r) (hw' : ‖w' - O‖ = r) (h : rang O z w = rang O z w') : w = w' := by obtain ⟨m, hm⟩ := rang_spec O z w obtain ⟨m', hm'⟩ := rang_spec O z w' have h1 := Complex.neg_pi_lt_arg (w - O) have h2 := Complex.arg_le_pi (w - O) have h3 := Complex.neg_pi_lt_arg (w' - O) have h4 := Complex.arg_le_pi (w' - O) have hd : Complex.arg (w - O) - Complex.arg (w' - O) = ((m - m' : ℤ) : ℝ) * (2 * Real.pi) := by push_cast linarith have hk : m - m' = 0 := int_mul_two_pi_eq_zero (by linarith) (by linarith) rw [hk] at hd have harg : Complex.arg (w - O) = Complex.arg (w' - O) := by simp at hd linarith have e := Complex.ext_norm_arg (hw.trans hw'.symm) harg linear_combination e /-- `rang O z w = 0` on the circle only for the point on the ray from `O` through `z`; in particular `rang O b c = 0 ⇒ c = b` for `b, c` on one circle. -/ theorem rang_eq_zero_iff {O b c : ℂ} {r : ℝ} (hb : ‖b - O‖ = r) (hc : ‖c - O‖ = r) : rang O b c = 0 ↔ c = b := by constructor · intro h exact rang_inj hc hb (h.trans (rang_self O b).symm) · rintro rfl exact rang_self O c /-- Law of cosines in relative-angle form: for `w` on the circle `|w − O| = r`, `|zw|² = |zO|² + r² − 2|zO| r cos(rang O z w)`. -/ theorem dist_rang_sq (O z w : ℂ) {r : ℝ} (hw : ‖w - O‖ = r) : dist z w ^ 2 = ‖z - O‖ ^ 2 + r ^ 2 - 2 * ‖z - O‖ * r * Real.cos (rang O z w) := by have key : z - w = ((‖z - O‖ : ℝ) : ℂ) * Complex.exp (Complex.arg (z - O) * Complex.I) - ((r : ℝ) : ℂ) * Complex.exp (Complex.arg (w - O) * Complex.I) := by rw [← hw, Complex.norm_mul_exp_arg_mul_I, Complex.norm_mul_exp_arg_mul_I] ring rw [dist_eq_norm, key, norm_polar_sub_sq] obtain ⟨m, hm⟩ := rang_spec O z w rw [hm, Real.cos_add_int_mul_two_pi] theorem cos_lt_cos_of_pi_le {x y : ℝ} (hx : Real.pi ≤ x) (hy : y ≤ 2 * Real.pi) (hxy : x < y) : Real.cos x < Real.cos y := by have e1 : Real.cos x = Real.cos (2 * Real.pi - x) := by rw [Real.cos_sub, Real.cos_two_pi, Real.sin_two_pi] ring have e2 : Real.cos y = Real.cos (2 * Real.pi - y) := by rw [Real.cos_sub, Real.cos_two_pi, Real.sin_two_pi] ring rw [e1, e2] exact Real.cos_lt_cos_of_nonneg_of_le_pi (by linarith) (by linarith) (by linarith) /-- The two open half-circles seen from a point: `side true = (0, π)`, `side false = (π, 2π)`. -/ def side (s : Bool) (t : ℝ) : Prop := if s then 0 < t ∧ t < Real.pi else Real.pi < t ∧ t < 2 * Real.pi /-- The sign attached to a half-circle (`+1` on `(0, π)`, `−1` on `(π, 2π)`). -/ def sgnB (s : Bool) : ℝ := if s then 1 else -1 theorem sgnB_ne (s : Bool) : sgnB s ≠ 0 := by cases s <;> simp [sgnB] /-- On one half-circle seen from `z ≠ O`, distance from `z` is strictly increasing in `sgnB s · rang`. -/ theorem dist_lt_of_side {O z w w' : ℂ} {r : ℝ} (hz : z ≠ O) (hr : 0 < r) (hw : ‖w - O‖ = r) (hw' : ‖w' - O‖ = r) {s : Bool} (h1 : side s (rang O z w)) (h2 : side s (rang O z w')) (hlt : sgnB s * rang O z w < sgnB s * rang O z w') : dist z w < dist z w' := by have hd : 0 < ‖z - O‖ := norm_pos_iff.mpr (sub_ne_zero.mpr hz) have e1 := dist_rang_sq O z w hw have e2 := dist_rang_sq O z w' hw' have hcos : Real.cos (rang O z w') < Real.cos (rang O z w) := by cases s · simp only [side, sgnB] at h1 h2 hlt simp only [Bool.false_eq_true, ↓reduceIte] at h1 h2 hlt exact cos_lt_cos_of_pi_le h2.1.le h1.2.le (by linarith) · simp only [side, sgnB, ↓reduceIte] at h1 h2 hlt exact Real.cos_lt_cos_of_nonneg_of_le_pi h1.1.le h2.2.le (by linarith) have hsq : dist z w ^ 2 < dist z w' ^ 2 := by rw [e1, e2] have := mul_pos hd hr nlinarith exact lt_of_pow_lt_pow_left₀ 2 dist_nonneg hsq /-- Consequently `|zw| < |zw'| ⟺ sgnB s · rang O z w < sgnB s · rang O z w'` on one half-circle. -/ theorem side_lt_iff {O z w w' : ℂ} {r : ℝ} (hz : z ≠ O) (hr : 0 < r) (hw : ‖w - O‖ = r) (hw' : ‖w' - O‖ = r) {s : Bool} (h1 : side s (rang O z w)) (h2 : side s (rang O z w')) : sgnB s * rang O z w < sgnB s * rang O z w' ↔ dist z w < dist z w' := by constructor · exact dist_lt_of_side hz hr hw hw' h1 h2 · intro hlt rcases lt_trichotomy (sgnB s * rang O z w) (sgnB s * rang O z w') with h | h | h · exact h · have : rang O z w = rang O z w' := mul_left_cancel₀ (sgnB_ne s) h rw [rang_inj hw hw' this] at hlt exact absurd hlt (lt_irrefl _) · exact absurd (dist_lt_of_side hz hr hw' hw h2 h1 h) (not_lt.mpr hlt.le) /-- On one half-circle the relative angle is determined by the distance. -/ theorem side_eq_of_dist {O z w w' : ℂ} {r : ℝ} (hz : z ≠ O) (hr : 0 < r) (hw : ‖w - O‖ = r) (hw' : ‖w' - O‖ = r) {s : Bool} (h1 : side s (rang O z w)) (h2 : side s (rang O z w')) (hd : dist z w = dist z w') : w = w' := by rcases lt_trichotomy (sgnB s * rang O z w) (sgnB s * rang O z w') with h | h | h · exact absurd hd (ne_of_lt (dist_lt_of_side hz hr hw hw' h1 h2 h)) · exact rang_inj hw hw' (mul_left_cancel₀ (sgnB_ne s) h) · exact absurd hd (ne_of_gt (dist_lt_of_side hz hr hw' hw h2 h1 h)) /-- Every relative angle off the axis lies on one of the two half-circles. -/ theorem side_cases (t : ℝ) (h0 : 0 ≤ t) (h1 : t < 2 * Real.pi) (ha : t ≠ 0) (hb : t ≠ Real.pi) : side true t ∨ side false t := by simp only [side, Bool.false_eq_true, ↓reduceIte] rcases lt_or_gt_of_ne hb with h | h · exact Or.inl ⟨lt_of_le_of_ne h0 (Ne.symm ha), h⟩ · exact Or.inr ⟨h, h1⟩ theorem side_unique {s s' : Bool} {t : ℝ} (h : side s t) (h' : side s' t) : s = s' := by cases s <;> cases s' <;> simp_all [side] <;> linarith /-- **Betweenness transfer.** If `rang O z b < rang O z c` and `w` lies on the open ccw arc from `b` to `c` (as seen from `b`), then `w` lies strictly between `b` and `c` as seen from `z`. -/ theorem rang_between {O z b c w : ℂ} (hbc : rang O z b < rang O z c) (hw0 : 0 < rang O b w) (hw1 : rang O b w < rang O b c) : rang O z b < rang O z w ∧ rang O z w < rang O z c := by have hb := rang_mem O z b have hc := rang_mem O z c have hbc' := rang_mem O b c -- first: rang O b c = rang O z c − rang O z b have e1 : rang O b c = rang O z c - rang O z b := by have h := rang_add O z b c rw [toIcoMod_eq_iff] at h obtain ⟨_, m, hm⟩ := h rw [zsmul_eq_mul] at hm have hm0 : m = 0 := by apply int_mul_two_pi_eq_zero <;> linarith rw [hm0] at hm simp at hm linarith have h := rang_add O z b w have hwz : toIcoMod Real.two_pi_pos 0 (rang O z b + rang O b w) = rang O z b + rang O b w := toIcoMod_eq_of 0 (by linarith) (by linarith) (by simp) rw [hwz] at h constructor <;> linarith end Erdos94ThmA /-! ### GLIDE Lemma 11.9 (E1), part 2: the step count of a monotone chain (Lemma 11.1 / 11.9(6), abstract) -/ namespace Erdos94ThmA open Finset open Classical in /-- Ordered pairs `(p, q)` of a chain with `x p < x q` whose open `x`-gap and open `y`-gap contain fewer than `G` reference values each. -/ noncomputable def smallSteps {ι : Type*} (Ch : Finset ι) (x y : ι → ℝ) (Xs Ys : Finset ℝ) (G : ℕ) : Finset (ι × ι) := (Ch ×ˢ Ch).filter (fun pq => x pq.1 < x pq.2 ∧ (Xs.filter (fun t => x pq.1 < t ∧ t < x pq.2)).card < G ∧ (Ys.filter (fun t => y pq.1 < t ∧ t < y pq.2)).card < G) open Classical in /-- **Chain step count.** A chain `Ch` on which `x` is injective and `y` is strictly increasing in `x`, with `x`-values in `Xs` and `y`-values in `Ys`: `(G + 1)|Ch| ≤ (G + 1)(1 + #small steps) + |Xs| + |Ys|`. (Consecutive chain points whose `x`-gap or `y`-gap holds `≥ G` reference values number `≤ (|Xs| + |Ys|)/(G + 1)`, since the half-open gaps are disjoint; every other consecutive pair is a small step.) -/ theorem chain_count {ι : Type*} [DecidableEq ι] (Ch : Finset ι) (x y : ι → ℝ) (Xs Ys : Finset ℝ) (hx : ∀ p ∈ Ch, x p ∈ Xs) (hy : ∀ p ∈ Ch, y p ∈ Ys) (hmono : ∀ p ∈ Ch, ∀ q ∈ Ch, x p < x q → y p < y q) (hinj : ∀ p ∈ Ch, ∀ q ∈ Ch, x p = x q → p = q) (G : ℕ) : (G + 1) * Ch.card ≤ (G + 1) * (1 + (smallSteps Ch x y Xs Ys G).card) + Xs.card + Ys.card := by -- successor in the x-order let U : ι → Finset ι := fun p => Ch.filter (fun q => x p < x q) obtain ⟨Ch', hCh'⟩ : ∃ C, C = Ch.filter (fun p => (U p).Nonempty) := ⟨_, rfl⟩ let nx : ι → ι := fun p => if h : (U p).Nonempty then Classical.choose (exists_min_image (U p) x h) else p have hnx : ∀ p ∈ Ch', nx p ∈ Ch ∧ x p < x (nx p) ∧ ∀ r ∈ Ch, x p < x r → x (nx p) ≤ x r := by intro p hp rw [hCh', mem_filter] at hp have hne := hp.2 have e : nx p = Classical.choose (exists_min_image (U p) x hne) := by simp only [nx] rw [dif_pos hne] have hs := Classical.choose_spec (exists_min_image (U p) x hne) rw [← e] at hs obtain ⟨hmem, hmin⟩ := hs have hmem' := mem_filter.mp hmem exact ⟨hmem'.1, hmem'.2, fun r hr hpr => hmin r (mem_filter.mpr ⟨hr, hpr⟩)⟩ have hsub : Ch' ⊆ Ch := by rw [hCh'] exact filter_subset _ _ -- at most one point has no successor have hcard1 : Ch.card ≤ Ch'.card + 1 := by have hle : (Ch.filter (fun p => ¬ (U p).Nonempty)).card ≤ 1 := by apply card_le_one.mpr intro a ha b hb rw [mem_filter] at ha hb rcases lt_trichotomy (x a) (x b) with h | h | h · exact absurd ⟨b, mem_filter.mpr ⟨hb.1, h⟩⟩ ha.2 · exact hinj a ha.1 b hb.1 h · exact absurd ⟨a, mem_filter.mpr ⟨ha.1, h⟩⟩ hb.2 have := card_filter_add_card_filter_not (s := Ch) (fun p => (U p).Nonempty) rw [← hCh'] at this omega -- the gap sets let gX : ι → Finset ℝ := fun p => Xs.filter (fun t => x p < t ∧ t ≤ x (nx p)) let gY : ι → Finset ℝ := fun p => Ys.filter (fun t => y p < t ∧ t ≤ y (nx p)) let sX : ι → ℕ := fun p => (Xs.filter (fun t => x p < t ∧ t < x (nx p))).card let sY : ι → ℕ := fun p => (Ys.filter (fun t => y p < t ∧ t < y (nx p))).card have hgX : ∀ p ∈ Ch', (gX p).card = sX p + 1 := by intro p hp have h := hnx p hp have e : gX p = insert (x (nx p)) (Xs.filter (fun t => x p < t ∧ t < x (nx p))) := by ext t simp only [gX, mem_filter, mem_insert] constructor · rintro ⟨ht, h1, h2⟩ rcases lt_or_eq_of_le h2 with h3 | h3 · exact Or.inr ⟨ht, h1, h3⟩ · exact Or.inl h3 · rintro (rfl | ⟨ht, h1, h2⟩) · exact ⟨hx _ h.1, h.2.1, le_refl _⟩ · exact ⟨ht, h1, h2.le⟩ rw [e, card_insert_of_notMem] simp have hgY : ∀ p ∈ Ch', (gY p).card = sY p + 1 := by intro p hp have h := hnx p hp have hyl : y p < y (nx p) := hmono p (hsub hp) (nx p) h.1 h.2.1 have e : gY p = insert (y (nx p)) (Ys.filter (fun t => y p < t ∧ t < y (nx p))) := by ext t simp only [gY, mem_filter, mem_insert] constructor · rintro ⟨ht, h1, h2⟩ rcases lt_or_eq_of_le h2 with h3 | h3 · exact Or.inr ⟨ht, h1, h3⟩ · exact Or.inl h3 · rintro (rfl | ⟨ht, h1, h2⟩) · exact ⟨hy _ h.1, hyl, le_refl _⟩ · exact ⟨ht, h1, h2.le⟩ rw [e, card_insert_of_notMem] simp -- order facts: for distinct p, p' ∈ Ch' with x p < x p', the successor of p is at or before p' have hord : ∀ p ∈ Ch', ∀ p' ∈ Ch', x p < x p' → x (nx p) ≤ x p' ∧ y (nx p) ≤ y p' := by intro p hp p' hp' hlt have h := hnx p hp have h1 := h.2.2 p' (hsub hp') hlt refine ⟨h1, ?_⟩ rcases lt_or_eq_of_le h1 with h2 | h2 · exact (hmono _ h.1 p' (hsub hp') h2).le · rw [hinj _ h.1 p' (hsub hp') h2] have hdisjX : (Ch' : Set ι).PairwiseDisjoint gX := by intro p hp p' hp' hpp rw [Function.onFun, disjoint_left] intro t ht ht' simp only [gX, mem_filter] at ht ht' rcases lt_trichotomy (x p) (x p') with h | h | h · have := (hord p hp p' hp' h).1 linarith [ht.2.2, ht'.2.1] · exact hpp (hinj p (hsub hp) p' (hsub hp') h) · have := (hord p' hp' p hp h).1 linarith [ht'.2.2, ht.2.1] have hdisjY : (Ch' : Set ι).PairwiseDisjoint gY := by intro p hp p' hp' hpp rw [Function.onFun, disjoint_left] intro t ht ht' simp only [gY, mem_filter] at ht ht' rcases lt_trichotomy (x p) (x p') with h | h | h · have := (hord p hp p' hp' h).2 linarith [ht.2.2, ht'.2.1] · exact hpp (hinj p (hsub hp) p' (hsub hp') h) · have := (hord p' hp' p hp h).2 linarith [ht'.2.2, ht.2.1] have hsumX : ∑ p ∈ Ch', (gX p).card ≤ Xs.card := by rw [← card_biUnion hdisjX] apply card_le_card intro t ht rw [mem_biUnion] at ht obtain ⟨p, _, ht⟩ := ht exact (mem_filter.mp ht).1 have hsumY : ∑ p ∈ Ch', (gY p).card ≤ Ys.card := by rw [← card_biUnion hdisjY] apply card_le_card intro t ht rw [mem_biUnion] at ht obtain ⟨p, _, ht⟩ := ht exact (mem_filter.mp ht).1 -- big steps obtain ⟨BX, hBX⟩ : ∃ S, S = Ch'.filter (fun p => G ≤ sX p) := ⟨_, rfl⟩ obtain ⟨BY, hBY⟩ : ∃ S, S = Ch'.filter (fun p => G ≤ sY p) := ⟨_, rfl⟩ obtain ⟨R, hR⟩ : ∃ S, S = Ch'.filter (fun p => sX p < G ∧ sY p < G) := ⟨_, rfl⟩ have hBXc : (G + 1) * BX.card ≤ Xs.card := by calc (G + 1) * BX.card = ∑ _p ∈ BX, (G + 1) := by rw [sum_const, smul_eq_mul, mul_comm] _ ≤ ∑ p ∈ BX, (gX p).card := by apply sum_le_sum intro p hp rw [hBX, mem_filter] at hp rw [hgX p hp.1] omega _ ≤ ∑ p ∈ Ch', (gX p).card := by apply sum_le_sum_of_subset rw [hBX] exact filter_subset _ _ _ ≤ Xs.card := hsumX have hBYc : (G + 1) * BY.card ≤ Ys.card := by calc (G + 1) * BY.card = ∑ _p ∈ BY, (G + 1) := by rw [sum_const, smul_eq_mul, mul_comm] _ ≤ ∑ p ∈ BY, (gY p).card := by apply sum_le_sum intro p hp rw [hBY, mem_filter] at hp rw [hgY p hp.1] omega _ ≤ ∑ p ∈ Ch', (gY p).card := by apply sum_le_sum_of_subset rw [hBY] exact filter_subset _ _ _ ≤ Ys.card := hsumY have hRc : R.card ≤ (smallSteps Ch x y Xs Ys G).card := by apply card_le_card_of_injOn (fun p => (p, nx p)) · intro p hp rw [mem_coe, hR, mem_filter] at hp have h := hnx p hp.1 rw [mem_coe, smallSteps, mem_filter, mem_product] exact ⟨⟨hsub hp.1, h.1⟩, h.2.1, hp.2.1, hp.2.2⟩ · intro p _ p' _ h exact (Prod.mk.inj h).1 have hcov : Ch'.card ≤ BX.card + BY.card + R.card := by have hs : Ch' ⊆ BX ∪ BY ∪ R := by intro p hp rw [mem_union, mem_union, hBX, hBY, hR, mem_filter, mem_filter, mem_filter] by_cases h1 : G ≤ sX p · exact Or.inl (Or.inl ⟨hp, h1⟩) · by_cases h2 : G ≤ sY p · exact Or.inl (Or.inr ⟨hp, h2⟩) · exact Or.inr ⟨hp, by omega, by omega⟩ calc Ch'.card ≤ (BX ∪ BY ∪ R).card := card_le_card hs _ ≤ (BX ∪ BY).card + R.card := card_union_le _ _ _ ≤ BX.card + BY.card + R.card := by have := card_union_le BX BY omega calc (G + 1) * Ch.card ≤ (G + 1) * (Ch'.card + 1) := Nat.mul_le_mul_left _ hcard1 _ ≤ (G + 1) * (BX.card + BY.card + R.card + 1) := Nat.mul_le_mul_left _ (by omega) _ = (G + 1) * BX.card + (G + 1) * BY.card + (G + 1) * (1 + R.card) := by ring _ ≤ Xs.card + Ys.card + (G + 1) * (1 + (smallSteps Ch x y Xs Ys G).card) := by have := Nat.mul_le_mul_left (G + 1) (Nat.add_le_add_left hRc 1) omega _ = (G + 1) * (1 + (smallSteps Ch x y Xs Ys G).card) + Xs.card + Ys.card := by ring end Erdos94ThmA /-! ### GLIDE Lemma 11.9 (E1), part 3: index-close pairs on a circle (intrinsic closeness) -/ namespace Erdos94ThmA open Finset open Classical in /-- `ccwPairs O B G`: ordered pairs `(b, c)` of distinct points of `B` with fewer than `G` points of `B` on the open counterclockwise arc from `b` to `c` (about the centre `O`). -/ noncomputable def ccwPairs (O : ℂ) (B : Finset ℂ) (G : ℕ) : Finset (ℂ × ℂ) := (B ×ˢ B).filter (fun bc => bc.1 ≠ bc.2 ∧ (B.filter (fun w => 0 < rang O bc.1 w ∧ rang O bc.1 w < rang O bc.1 bc.2)).card < G) open Classical in theorem arc_card_lt {O b c₁ c₂ : ℂ} {r : ℝ} {B : Finset ℂ} (hb : ‖b - O‖ = r) (hc₁ : ‖c₁ - O‖ = r) (hc₁B : c₁ ∈ B) (hne : c₁ ≠ b) (hlt : rang O b c₁ < rang O b c₂) : (B.filter (fun w => 0 < rang O b w ∧ rang O b w < rang O b c₁)).card < (B.filter (fun w => 0 < rang O b w ∧ rang O b w < rang O b c₂)).card := by apply card_lt_card rw [ssubset_iff_of_subset] · refine ⟨c₁, ?_, ?_⟩ · rw [mem_filter] refine ⟨hc₁B, ?_, hlt⟩ rcases lt_or_eq_of_le (rang_mem O b c₁).1 with h | h · exact h · exact absurd ((rang_eq_zero_iff hb hc₁).mp h.symm) hne · rw [mem_filter] exact fun h => lt_irrefl _ h.2.2 · intro w hw rw [mem_filter] at hw ⊢ exact ⟨hw.1, hw.2.1, lt_trans hw.2.2 hlt⟩ open Classical in /-- Each point has fewer than `G + 1` ccw-close successors, so `|ccwPairs| ≤ G |B|`. -/ theorem ccwPairs_card {O : ℂ} {r : ℝ} {B : Finset ℂ} (hB : ∀ b ∈ B, ‖b - O‖ = r) (G : ℕ) : (ccwPairs O B G).card ≤ G * B.card := by have hfib : (ccwPairs O B G).card = ∑ b ∈ B, ((ccwPairs O B G).filter (fun bc => bc.1 = b)).card := by apply card_eq_sum_card_fiberwise intro bc hbc rw [mem_coe, ccwPairs, mem_filter, mem_product] at hbc exact mem_coe.mpr hbc.1.1 rw [hfib, mul_comm] calc ∑ b ∈ B, ((ccwPairs O B G).filter (fun bc => bc.1 = b)).card ≤ ∑ _b ∈ B, G := by apply sum_le_sum intro b hb let k : ℂ × ℂ → ℕ := fun bc => (B.filter (fun w => 0 < rang O b w ∧ rang O b w < rang O b bc.2)).card calc ((ccwPairs O B G).filter (fun bc => bc.1 = b)).card ≤ (range G).card := by apply card_le_card_of_injOn k · intro bc hbc rw [mem_coe, mem_filter, ccwPairs, mem_filter] at hbc rw [mem_coe, mem_range] have h := hbc.1.2.2 rw [hbc.2] at h exact h · intro bc hbc bc' hbc' hk rw [mem_coe, mem_filter, ccwPairs, mem_filter, mem_product] at hbc hbc' have hc : ‖bc.2 - O‖ = r := hB _ hbc.1.1.2 have hc' : ‖bc'.2 - O‖ = r := hB _ hbc'.1.1.2 have hb' : ‖b - O‖ = r := hB _ hb have hne : bc.2 ≠ b := fun h => hbc.1.2.1 (hbc.2.trans h.symm) have hne' : bc'.2 ≠ b := fun h => hbc'.1.2.1 (hbc'.2.trans h.symm) have h2 : bc.2 = bc'.2 := by rcases lt_trichotomy (rang O b bc.2) (rang O b bc'.2) with h | h | h · exact absurd hk (ne_of_lt (arc_card_lt hb' hc hbc.1.1.2 hne h)) · exact rang_inj hc hc' h · exact absurd hk (ne_of_gt (arc_card_lt hb' hc' hbc'.1.1.2 hne' h)) exact Prod.ext (hbc.2.trans hbc'.2.symm) h2 _ = G := card_range G _ = B.card * G := by rw [sum_const, smul_eq_mul] open Classical in /-- Close pairs of points of `B × B`: both coordinates ccw-close in one of the two directions. -/ noncomputable def closeQuads (O : ℂ) (B : Finset ℂ) (G : ℕ) : Finset ((ℂ × ℂ) × (ℂ × ℂ)) := ((B ×ˢ B) ×ˢ (B ×ˢ B)).filter (fun pq => ((pq.1.1, pq.2.1) ∈ ccwPairs O B G ∨ (pq.2.1, pq.1.1) ∈ ccwPairs O B G) ∧ ((pq.1.2, pq.2.2) ∈ ccwPairs O B G ∨ (pq.2.2, pq.1.2) ∈ ccwPairs O B G)) theorem closeQuads_card {O : ℂ} {r : ℝ} {B : Finset ℂ} (hB : ∀ b ∈ B, ‖b - O‖ = r) (G : ℕ) : (closeQuads O B G).card ≤ 4 * (G * B.card) ^ 2 := by classical obtain ⟨PP, hPP⟩ : ∃ S : Finset (ℂ × ℂ), S = ccwPairs O B G ∪ (ccwPairs O B G).image Prod.swap := ⟨_, rfl⟩ have hPPc : PP.card ≤ 2 * (G * B.card) := by rw [hPP] have h1 := card_union_le (ccwPairs O B G) ((ccwPairs O B G).image Prod.swap) have h2 := card_image_le (s := ccwPairs O B G) (f := Prod.swap) have h3 := ccwPairs_card hB G omega have hsub : closeQuads O B G ⊆ (PP ×ˢ PP).image (fun xy : (ℂ × ℂ) × (ℂ × ℂ) => ((xy.1.1, xy.2.1), (xy.1.2, xy.2.2))) := by intro pq hpq rw [closeQuads, mem_filter] at hpq rw [mem_image] refine ⟨((pq.1.1, pq.2.1), (pq.1.2, pq.2.2)), ?_, rfl⟩ rw [mem_product, hPP, mem_union, mem_union, mem_image, mem_image] refine ⟨?_, ?_⟩ · rcases hpq.2.1 with h | h · exact Or.inl h · exact Or.inr ⟨_, h, rfl⟩ · rcases hpq.2.2 with h | h · exact Or.inl h · exact Or.inr ⟨_, h, rfl⟩ calc (closeQuads O B G).card ≤ ((PP ×ˢ PP).image (fun xy : (ℂ × ℂ) × (ℂ × ℂ) => ((xy.1.1, xy.2.1), (xy.1.2, xy.2.2)))).card := card_le_card hsub _ ≤ (PP ×ˢ PP).card := card_image_le _ = PP.card * PP.card := card_product _ _ _ ≤ (2 * (G * B.card)) * (2 * (G * B.card)) := Nat.mul_le_mul hPPc hPPc _ = 4 * (G * B.card) ^ 2 := by ring open Classical in /-- **Small gap ⇒ intrinsically close.** For `b, c ∈ B` on the half-circle `s` seen from `z`, ordered by `sgnB s · rang`, a gap holding fewer than `G` values of `sgnB s · rang O z (B)` makes `(b, c)` or `(c, b)` ccw-close. -/ theorem gap_close {O z b c : ℂ} {r : ℝ} {B : Finset ℂ} (hB : ∀ w ∈ B, ‖w - O‖ = r) (hbB : b ∈ B) (hcB : c ∈ B) (s : Bool) (G : ℕ) (hlt : sgnB s * rang O z b < sgnB s * rang O z c) (hgap : ((B.image (fun w => sgnB s * rang O z w)).filter (fun t => sgnB s * rang O z b < t ∧ t < sgnB s * rang O z c)).card < G) : (b, c) ∈ ccwPairs O B G ∨ (c, b) ∈ ccwPairs O B G := by have hinj : Set.InjOn (fun w => sgnB s * rang O z w) (B : Set ℂ) := by intro w hw w' hw' h exact rang_inj (hB w (mem_coe.mp hw)) (hB w' (mem_coe.mp hw')) (mul_left_cancel₀ (sgnB_ne s) h) cases s · -- sgnB false = -1: the order is reversed, so (c, b) is ccw-close right simp only [sgnB, Bool.false_eq_true, ↓reduceIte] at hlt hgap have hcb : rang O z c < rang O z b := by linarith rw [ccwPairs, mem_filter, mem_product] refine ⟨⟨hcB, hbB⟩, fun h => by have h' : c = b := h rw [h'] at hcb exact lt_irrefl _ hcb, ?_⟩ refine lt_of_le_of_lt ?_ hgap apply card_le_card_of_injOn (fun w => -1 * rang O z w) · intro w hw rw [mem_coe, mem_filter] at hw obtain ⟨h1, h2⟩ := rang_between hcb hw.2.1 hw.2.2 rw [mem_coe, mem_filter, mem_image] exact ⟨⟨w, hw.1, rfl⟩, by linarith, by linarith⟩ · intro w hw w' hw' h exact hinj (mem_coe.mpr (mem_filter.mp (mem_coe.mp hw)).1) (mem_coe.mpr (mem_filter.mp (mem_coe.mp hw')).1) (by simp only [sgnB]; simpa using h) · left simp only [sgnB, ↓reduceIte, one_mul] at hlt hgap rw [ccwPairs, mem_filter, mem_product] refine ⟨⟨hbB, hcB⟩, fun h => by have h' : b = c := h rw [h'] at hlt exact lt_irrefl _ hlt, ?_⟩ refine lt_of_le_of_lt ?_ hgap apply card_le_card_of_injOn (fun w => rang O z w) · intro w hw rw [mem_coe, mem_filter] at hw obtain ⟨h1, h2⟩ := rang_between hlt hw.2.1 hw.2.2 rw [mem_coe, mem_filter, mem_image] exact ⟨⟨w, hw.1, by simp⟩, h1, h2⟩ · intro w hw w' hw' h exact rang_inj (hB w (mem_filter.mp (mem_coe.mp hw)).1) (hB w' (mem_filter.mp (mem_coe.mp hw')).1) h end Erdos94ThmA /-! ### GLIDE Lemma 11.9 (E1), part 4: the dual property (Lemma 11.9(5)) -/ namespace Erdos94ThmA open Finset Polynomial /-- A degree-`≤ 2` trigonometric form with some nonzero coefficient gives a nonzero `trigPoly`. -/ theorem trigPoly_ne_zero' {A B F H K₀ : ℝ} (h : A ≠ 0 ∨ B ≠ 0 ∨ F ≠ 0 ∨ H ≠ 0 ∨ K₀ ≠ 0) : trigPoly A B F H K₀ ≠ 0 := by intro hQ have h4 := trigPoly_coeff4 A B F H K₀ have h3 := trigPoly_coeff3 A B F H K₀ have h2 : (trigPoly A B F H K₀).coeff 2 = 2 * (A : ℂ) + 4 * K₀ := by simp only [trigPoly, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X, coeff_C] norm_num rw [hQ, coeff_zero] at h4 h3 h2 have h4r := congrArg Complex.re h4 have h4i := congrArg Complex.im h4 have h3r := congrArg Complex.re h3 have h3i := congrArg Complex.im h3 have h2r := congrArg Complex.re h2 simp at h4r h4i h3r h3i h2r have hA : A = 0 := by linarith have hK : K₀ = 0 := by linarith rcases h with h | h | h | h | h · exact h hA · exact h h4i · exact h (by linarith) · exact h h3i · exact h hK /-- **(TC′)** A nonzero form `A cos²t + B cos t sin t + F cos t + H sin t + K₀` has at most four zeros in `[0, 2π)`. -/ theorem trig_zeros_le_four' {A B F H K₀ : ℝ} (hne : A ≠ 0 ∨ B ≠ 0 ∨ F ≠ 0 ∨ H ≠ 0 ∨ K₀ ≠ 0) (T : Finset ℝ) (hT : ∀ t ∈ T, 0 ≤ t ∧ t < 2 * Real.pi) (hzero : ∀ t ∈ T, A * Real.cos t ^ 2 + B * Real.cos t * Real.sin t + F * Real.cos t + H * Real.sin t + K₀ = 0) : T.card ≤ 4 := by classical have hQ0 := trigPoly_ne_zero' hne have hroot : ∀ t ∈ T, Complex.exp (t * Complex.I) ∈ (trigPoly A B F H K₀).roots.toFinset := by intro t ht rw [Multiset.mem_toFinset, mem_roots hQ0, IsRoot.def, trigPoly_eval, hzero t ht] simp have hinj : Set.InjOn (fun t : ℝ => Complex.exp (t * Complex.I)) (T : Set ℝ) := Set.InjOn.mono (fun t ht => Set.mem_Ico.mpr (hT t (mem_coe.mp ht))) exp_injOn_Ico calc T.card = (T.image (fun t : ℝ => Complex.exp (t * Complex.I))).card := (card_image_of_injOn hinj).symm _ ≤ (trigPoly A B F H K₀).roots.toFinset.card := card_le_card (fun z hz => by rw [mem_image] at hz obtain ⟨t, ht, rfl⟩ := hz exact hroot t ht) _ ≤ Multiset.card (trigPoly A B F H K₀).roots := Multiset.toFinset_card_le _ _ ≤ (trigPoly A B F H K₀).natDegree := card_roots' _ _ ≤ 4 := trigPoly_natDegree_le A B F H K₀ /-- Eliminating `w` from the two linear conditions (independent case) gives a degree-2 trigonometric equation in the angle of `u` (GLIDE Lemma 11.9(5)(i)). -/ theorem dual_alg_poly {p₁ q₁ p₂ q₂ al₁ be₁ al₂ be₂ k₁ k₂ r C S w₁ w₂ a₁ b₁ c₁ a₂ b₂ c₂ D : ℝ} (hD : D = p₁ * q₂ - q₁ * p₂) (ha₁ : a₁ = r * (al₁ * q₂ - al₂ * q₁)) (hb₁ : b₁ = r * (be₁ * q₂ - be₂ * q₁)) (hc₁ : c₁ = k₁ * q₂ - k₂ * q₁) (ha₂ : a₂ = r * (p₁ * al₂ - p₂ * al₁)) (hb₂ : b₂ = r * (p₁ * be₂ - p₂ * be₁)) (hc₂ : c₂ = p₁ * k₂ - p₂ * k₁) (e1 : p₁ * w₁ + q₁ * w₂ = r * (al₁ * C + be₁ * S) + k₁) (e2 : p₂ * w₁ + q₂ * w₂ = r * (al₂ * C + be₂ * S) + k₂) (hw : w₁ ^ 2 + w₂ ^ 2 = r ^ 2) (hC : C ^ 2 + S ^ 2 = 1) : (a₁ ^ 2 + a₂ ^ 2 - b₁ ^ 2 - b₂ ^ 2) * C ^ 2 + (2 * (a₁ * b₁ + a₂ * b₂)) * C * S + (2 * (a₁ * c₁ + a₂ * c₂)) * C + (2 * (b₁ * c₁ + b₂ * c₂)) * S + (b₁ ^ 2 + b₂ ^ 2 + c₁ ^ 2 + c₂ ^ 2 - D ^ 2 * r ^ 2) = 0 := by have hU : D * w₁ = a₁ * C + b₁ * S + c₁ := by rw [hD, ha₁, hb₁, hc₁] linear_combination q₂ * e1 - q₁ * e2 have hV : D * w₂ = a₂ * C + b₂ * S + c₂ := by rw [hD, ha₂, hb₂, hc₂] linear_combination p₁ * e2 - p₂ * e1 linear_combination (-(a₁ * C + b₁ * S + c₁ + D * w₁)) * hU + (-(a₂ * C + b₂ * S + c₂ + D * w₂)) * hV + D ^ 2 * hw - (b₁ ^ 2 + b₂ ^ 2) * hC /-- If the eliminated form vanishes identically then `k₁ = 0` (GLIDE Lemma 11.9(5)(i): then `M` is orthogonal, `v₀ = 0`, every match is explained). -/ theorem dual_alg_nonzero {p₁ q₁ p₂ q₂ al₁ be₁ al₂ be₂ k₁ k₂ r a₁ b₁ c₁ a₂ b₂ c₂ D : ℝ} (hD : D = p₁ * q₂ - q₁ * p₂) (ha₁ : a₁ = r * (al₁ * q₂ - al₂ * q₁)) (hb₁ : b₁ = r * (be₁ * q₂ - be₂ * q₁)) (hc₁ : c₁ = k₁ * q₂ - k₂ * q₁) (ha₂ : a₂ = r * (p₁ * al₂ - p₂ * al₁)) (hb₂ : b₂ = r * (p₁ * be₂ - p₂ * be₁)) (hc₂ : c₂ = p₁ * k₂ - p₂ * k₁) (hD0 : D ≠ 0) (hr : r ≠ 0) (hf : al₁ ≠ 0 ∨ be₁ ≠ 0) (h1 : a₁ ^ 2 + a₂ ^ 2 - b₁ ^ 2 - b₂ ^ 2 = 0) (h2 : 2 * (a₁ * b₁ + a₂ * b₂) = 0) (h3 : 2 * (a₁ * c₁ + a₂ * c₂) = 0) (h4 : 2 * (b₁ * c₁ + b₂ * c₂) = 0) : k₁ = 0 := by have eA : r * al₁ * D = p₁ * a₁ + q₁ * a₂ := by rw [hD, ha₁, ha₂]; ring have eB : r * be₁ * D = p₁ * b₁ + q₁ * b₂ := by rw [hD, hb₁, hb₂]; ring have eK : k₁ * D = p₁ * c₁ + q₁ * c₂ := by rw [hD, hc₁, hc₂]; ring by_cases hl : a₁ ^ 2 + a₂ ^ 2 = 0 · exfalso have ha1 : a₁ = 0 := by nlinarith [sq_nonneg a₁, sq_nonneg a₂] have ha2 : a₂ = 0 := by nlinarith [sq_nonneg a₁, sq_nonneg a₂] have hb : b₁ ^ 2 + b₂ ^ 2 = 0 := by linarith have hb1 : b₁ = 0 := by nlinarith [sq_nonneg b₁, sq_nonneg b₂] have hb2 : b₂ = 0 := by nlinarith [sq_nonneg b₁, sq_nonneg b₂] rw [ha1, ha2] at eA rw [hb1, hb2] at eB have hrD : r * D ≠ 0 := mul_ne_zero hr hD0 rcases hf with h | h · exact h (by have : al₁ * (r * D) = 0 := by linarith rcases mul_eq_zero.mp this with h' | h' · exact h' · exact absurd h' hrD) · exact h (by have : be₁ * (r * D) = 0 := by linarith rcases mul_eq_zero.mp this with h' | h' · exact h' · exact absurd h' hrD) · have hdet : (a₁ * b₂ - a₂ * b₁) ^ 2 = (a₁ ^ 2 + a₂ ^ 2) ^ 2 := by linear_combination (-(a₁ ^ 2 + a₂ ^ 2)) * h1 - ((a₁ * b₁ + a₂ * b₂) / 2) * h2 have hdet0 : a₁ * b₂ - a₂ * b₁ ≠ 0 := by intro h0 rw [h0] at hdet exact hl (pow_eq_zero_iff two_ne_zero |>.mp (by linarith)) have hc1 : c₁ * (a₁ * b₂ - a₂ * b₁) = 0 := by linear_combination (b₂ / 2) * h3 - (a₂ / 2) * h4 have hc2 : c₂ * (a₁ * b₂ - a₂ * b₁) = 0 := by linear_combination (a₁ / 2) * h4 - (b₁ / 2) * h3 have hc10 : c₁ = 0 := (mul_eq_zero.mp hc1).resolve_right hdet0 have hc20 : c₂ = 0 := (mul_eq_zero.mp hc2).resolve_right hdet0 rw [hc10, hc20] at eK have : k₁ * D = 0 := by linarith exact (mul_eq_zero.mp this).resolve_right hD0 /-- `‖z‖² = re² + im²` and `dist x y² = (Δre)² + (Δim)²`. -/ theorem norm_sq_re_im (z : ℂ) : ‖z‖ ^ 2 = z.re ^ 2 + z.im ^ 2 := by rw [Complex.sq_norm, Complex.normSq_apply] ring theorem dist_sq_re_im (x y : ℂ) : dist x y ^ 2 = (x.re - y.re) ^ 2 + (x.im - y.im) ^ 2 := by rw [Complex.dist_eq, norm_sq_re_im, Complex.sub_re, Complex.sub_im] /-- For `a, a'` on the circle `|· − O| = r`: `|ab| = |a'b'|` is the linear condition `⟨a' − O, b' − O⟩ = ⟨a − O, b − O⟩ + (|b' − O|² − |b − O|²)/2`. -/ theorem ip_of_dist_eq {O a a' b b' : ℂ} {r : ℝ} (ha : ‖a - O‖ = r) (ha' : ‖a' - O‖ = r) (h : dist a b = dist a' b') : (b' - O).re * (a' - O).re + (b' - O).im * (a' - O).im = (b - O).re * (a - O).re + (b - O).im * (a - O).im + (((b' - O).re ^ 2 + (b' - O).im ^ 2) - ((b - O).re ^ 2 + (b - O).im ^ 2)) / 2 := by have E1 : dist a b ^ 2 = dist a' b' ^ 2 := by rw [h] rw [dist_sq_re_im, dist_sq_re_im] at E1 have E2 : ‖a - O‖ ^ 2 = r ^ 2 := by rw [ha] have E3 : ‖a' - O‖ ^ 2 = r ^ 2 := by rw [ha'] rw [norm_sq_re_im] at E2 E3 simp only [Complex.sub_re, Complex.sub_im] at E1 E2 E3 ⊢ linear_combination (1 / 2) * E1 - (1 / 2) * E2 + (1 / 2) * E3 /-- A line meets a circle in at most two points: `#{a ∈ A : ⟨a − O, g⟩ = K} ≤ 2` for `g ≠ 0`. -/ theorem line_circle_le_two {O : ℂ} {r : ℝ} {A : Finset ℂ} (hA : ∀ a ∈ A, ‖a - O‖ = r) {g : ℂ} (hg : g ≠ 0) (K : ℝ) : (A.filter (fun a => g.re * (a - O).re + g.im * (a - O).im = K)).card ≤ 2 := by classical have hx : O + g ≠ O := fun h => hg (by linear_combination h) have hsub : A.filter (fun a => g.re * (a - O).re + g.im * (a - O).im = K) ⊆ A.filter (fun a => dist (O + g) a = Real.sqrt (‖g‖ ^ 2 - 2 * K + r ^ 2)) := by intro a ha rw [mem_filter] at ha ⊢ refine ⟨ha.1, ?_⟩ have hr := hA a ha.1 have hsq : dist (O + g) a ^ 2 = ‖g‖ ^ 2 - 2 * K + r ^ 2 := by rw [dist_sq_re_im, norm_sq_re_im, ← ha.2, ← hr, norm_sq_re_im] simp only [Complex.add_re, Complex.add_im, Complex.sub_re, Complex.sub_im] ring rw [← hsq, Real.sqrt_sq dist_nonneg] exact le_trans (card_le_card hsub) (card_circle_dist_le_two hA hx _) /-- Cosine and sine of the angle of `a` about `O` (measured from the direction `1`). -/ theorem cos_sin_rang_one {O a : ℂ} {r : ℝ} (hr : 0 < r) (ha : ‖a - O‖ = r) : Real.cos (rang O (O + 1) a) = (a - O).re / r ∧ Real.sin (rang O (O + 1) a) = (a - O).im / r := by obtain ⟨m, hm⟩ := rang_spec O (O + 1) a have h1 : O + 1 - O = 1 := by ring rw [h1, Complex.arg_one, sub_zero] at hm have hne : a - O ≠ 0 := by intro h0 rw [h0, norm_zero] at ha linarith have e : rang O (O + 1) a = Complex.arg (a - O) - m * (2 * Real.pi) := by linarith rw [e, Real.cos_sub_int_mul_two_pi, Real.sin_sub_int_mul_two_pi, Complex.cos_arg hne, Complex.sin_arg, ha] exact ⟨rfl, rfl⟩ /-- **GLIDE Lemma 11.9(5), the dual property.** Let `A` lie on the circle `|· − O| = r` (`r > 0`), and let `(b, b'), (c, c')` be distinct pairs of points `≠ O` with `|Ob| ≠ |Ob'|` (a NON-explained match; by SSS, a match `|ab| = |a'b'|` with `a, a'` on the circle is explained iff `|Ob| = |Ob'|`). Then at most four pairs `(a, a') ∈ A²` satisfy both `|ab| = |a'b'|` and `|ac| = |a'c'|`. -/ theorem dual_le_four {O : ℂ} {r : ℝ} (hr : 0 < r) {A : Finset ℂ} (hA : ∀ a ∈ A, ‖a - O‖ = r) {b b' c c' : ℂ} (hb : b ≠ O) (hc' : c' ≠ O) (hb' : b' ≠ O) (hne : (b, b') ≠ (c, c')) (hbe : ‖b - O‖ ≠ ‖b' - O‖) : ((A ×ˢ A).filter (fun aa => dist aa.1 b = dist aa.2 b' ∧ dist aa.1 c = dist aa.2 c')).card ≤ 4 := by classical obtain ⟨Sol, hSol⟩ : ∃ X, X = (A ×ˢ A).filter (fun aa => dist aa.1 b = dist aa.2 b' ∧ dist aa.1 c = dist aa.2 c') := ⟨_, rfl⟩ rw [← hSol] -- coordinates obtain ⟨p₁, hp₁⟩ : ∃ x, x = (b' - O).re := ⟨_, rfl⟩ obtain ⟨q₁, hq₁⟩ : ∃ x, x = (b' - O).im := ⟨_, rfl⟩ obtain ⟨p₂, hp₂⟩ : ∃ x, x = (c' - O).re := ⟨_, rfl⟩ obtain ⟨q₂, hq₂⟩ : ∃ x, x = (c' - O).im := ⟨_, rfl⟩ obtain ⟨al₁, hal₁⟩ : ∃ x, x = (b - O).re := ⟨_, rfl⟩ obtain ⟨be₁, hbe₁⟩ : ∃ x, x = (b - O).im := ⟨_, rfl⟩ obtain ⟨al₂, hal₂⟩ : ∃ x, x = (c - O).re := ⟨_, rfl⟩ obtain ⟨be₂, hbe₂⟩ : ∃ x, x = (c - O).im := ⟨_, rfl⟩ obtain ⟨k₁, hk₁⟩ : ∃ x, x = ((p₁ ^ 2 + q₁ ^ 2) - (al₁ ^ 2 + be₁ ^ 2)) / 2 := ⟨_, rfl⟩ obtain ⟨k₂, hk₂⟩ : ∃ x, x = ((p₂ ^ 2 + q₂ ^ 2) - (al₂ ^ 2 + be₂ ^ 2)) / 2 := ⟨_, rfl⟩ -- the two linear conditions for a solution have hlin : ∀ aa ∈ Sol, p₁ * (aa.2 - O).re + q₁ * (aa.2 - O).im = al₁ * (aa.1 - O).re + be₁ * (aa.1 - O).im + k₁ ∧ p₂ * (aa.2 - O).re + q₂ * (aa.2 - O).im = al₂ * (aa.1 - O).re + be₂ * (aa.1 - O).im + k₂ := by intro aa haa rw [hSol, mem_filter, mem_product] at haa have h1 := ip_of_dist_eq (hA _ haa.1.1) (hA _ haa.1.2) haa.2.1 have h2 := ip_of_dist_eq (hA _ haa.1.1) (hA _ haa.1.2) haa.2.2 rw [← hp₁, ← hq₁, ← hal₁, ← hbe₁] at h1 rw [← hp₂, ← hq₂, ← hal₂, ← hbe₂] at h2 constructor · rw [hk₁]; linarith · rw [hk₂]; linarith have hk₁0 : k₁ ≠ 0 := by intro h0 apply hbe have h2 : ‖b - O‖ ^ 2 = ‖b' - O‖ ^ 2 := by rw [norm_sq_re_im, norm_sq_re_im, ← hp₁, ← hq₁, ← hal₁, ← hbe₁] linarith exact (pow_left_inj₀ (norm_nonneg _) (norm_nonneg _) two_ne_zero).mp h2 have hf : al₁ ≠ 0 ∨ be₁ ≠ 0 := by by_contra h push Not at h apply hb have : b - O = 0 := Complex.ext (by rw [Complex.zero_re, ← hal₁, h.1]) (by rw [Complex.zero_im, ← hbe₁, h.2]) linear_combination this have he₁ : p₁ ≠ 0 ∨ q₁ ≠ 0 := by by_contra h push Not at h apply hb' have : b' - O = 0 := Complex.ext (by rw [Complex.zero_re, ← hp₁, h.1]) (by rw [Complex.zero_im, ← hq₁, h.2]) linear_combination this have hrA : ∀ a ∈ A, (a - O).re ^ 2 + (a - O).im ^ 2 = r ^ 2 := by intro a ha rw [← norm_sq_re_im, hA a ha] by_cases hD : p₁ * q₂ - q₁ * p₂ = 0 · -- dependent case: e₂ = μ e₁ obtain ⟨μ, hμ⟩ : ∃ x, x = (p₁ * p₂ + q₁ * q₂) / (p₁ ^ 2 + q₁ ^ 2) := ⟨_, rfl⟩ have hpq : p₁ ^ 2 + q₁ ^ 2 ≠ 0 := by rcases he₁ with h | h · have := sq_pos_of_ne_zero h nlinarith [sq_nonneg q₁] · have := sq_pos_of_ne_zero h nlinarith [sq_nonneg p₁] have hp2 : p₂ = μ * p₁ := by rw [hμ, div_mul_eq_mul_div, eq_div_iff hpq] linear_combination (-q₁) * hD have hq2 : q₂ = μ * q₁ := by rw [hμ, div_mul_eq_mul_div, eq_div_iff hpq] linear_combination p₁ * hD -- for a solution, the a-coordinate satisfies a linear condition have hlinA : ∀ aa ∈ Sol, (al₂ - μ * al₁) * (aa.1 - O).re + (be₂ - μ * be₁) * (aa.1 - O).im = μ * k₁ - k₂ := by intro aa haa obtain ⟨h1, h2⟩ := hlin aa haa rw [hp2, hq2] at h2 linear_combination μ * h1 - h2 by_cases hg : al₂ - μ * al₁ = 0 ∧ be₂ - μ * be₁ = 0 · -- identical case: no solution at all rcases Sol.eq_empty_or_nonempty with h0 | ⟨aa, haa⟩ · rw [h0, card_empty] norm_num · exfalso have hk : μ * k₁ - k₂ = 0 := by have := hlinA aa haa rw [hg.1, hg.2] at this linarith have hal2 : al₂ = μ * al₁ := by linarith [hg.1] have hbe2 : be₂ = μ * be₁ := by linarith [hg.2] have hk2 : k₂ = μ ^ 2 * k₁ := by rw [hk₂, hk₁, hp2, hq2, hal2, hbe2] ring have hμk : μ * (μ - 1) * k₁ = 0 := by linear_combination -hk2 - hk have hμ0 : μ ≠ 0 := by intro h0 apply hc' have : c' - O = 0 := Complex.ext (by rw [Complex.zero_re, ← hp₂, hp2, h0, zero_mul]) (by rw [Complex.zero_im, ← hq₂, hq2, h0, zero_mul]) linear_combination this have hμ1 : μ ≠ 1 := by intro h1 apply hne have e1 : c' - O = b' - O := Complex.ext (by rw [← hp₂, ← hp₁, hp2, h1, one_mul]) (by rw [← hq₂, ← hq₁, hq2, h1, one_mul]) have e2 : c - O = b - O := Complex.ext (by rw [← hal₂, ← hal₁, hal2, h1, one_mul]) (by rw [← hbe₂, ← hbe₁, hbe2, h1, one_mul]) have e1' : c' = b' := by linear_combination e1 have e2' : c = b := by linear_combination e2 rw [e1', e2'] have := mul_ne_zero (mul_ne_zero hμ0 (sub_ne_zero.mpr hμ1)) hk₁0 exact this hμk · -- the a-coordinates lie on a line: ≤ 2 of them, each with ≤ 2 partners have hgne : (⟨al₂ - μ * al₁, be₂ - μ * be₁⟩ : ℂ) ≠ 0 := by intro h0 apply hg exact ⟨by simpa using congrArg Complex.re h0, by simpa using congrArg Complex.im h0⟩ obtain ⟨L, hL⟩ : ∃ X, X = A.filter (fun a => (⟨al₂ - μ * al₁, be₂ - μ * be₁⟩ : ℂ).re * (a - O).re + (⟨al₂ - μ * al₁, be₂ - μ * be₁⟩ : ℂ).im * (a - O).im = μ * k₁ - k₂) := ⟨_, rfl⟩ have hLc : L.card ≤ 2 := by rw [hL] exact line_circle_le_two hA hgne _ have he₁ne : (⟨p₁, q₁⟩ : ℂ) ≠ 0 := by intro h0 rcases he₁ with h | h · exact h (by simpa using congrArg Complex.re h0) · exact h (by simpa using congrArg Complex.im h0) have hfib : Sol.card = ∑ a ∈ L, (Sol.filter (fun aa => aa.1 = a)).card := by apply card_eq_sum_card_fiberwise intro aa haa have haa' := mem_coe.mp haa have h := hlinA aa haa' rw [hSol, mem_filter, mem_product] at haa' rw [mem_coe, hL, mem_filter] exact ⟨haa'.1.1, by simpa using h⟩ rw [hfib] calc ∑ a ∈ L, (Sol.filter (fun aa => aa.1 = a)).card ≤ ∑ _a ∈ L, 2 := by apply sum_le_sum intro a _ calc (Sol.filter (fun aa => aa.1 = a)).card ≤ (A.filter (fun a' => (⟨p₁, q₁⟩ : ℂ).re * (a' - O).re + (⟨p₁, q₁⟩ : ℂ).im * (a' - O).im = al₁ * (a - O).re + be₁ * (a - O).im + k₁)).card := by apply card_le_card_of_injOn Prod.snd · intro aa haa have haa' := mem_coe.mp haa rw [mem_filter] at haa' have h := (hlin aa haa'.1).1 rw [haa'.2] at h have hm := haa'.1 rw [hSol, mem_filter, mem_product] at hm rw [mem_coe, mem_filter] exact ⟨hm.1.2, by simpa using h⟩ · intro aa haa aa' haa' h have e1 := (mem_filter.mp (mem_coe.mp haa)).2 have e2 := (mem_filter.mp (mem_coe.mp haa')).2 exact Prod.ext (e1.trans e2.symm) h _ ≤ 2 := line_circle_le_two hA he₁ne _ _ = L.card * 2 := by rw [sum_const, smul_eq_mul] _ ≤ 2 * 2 := Nat.mul_le_mul_right 2 hLc _ = 4 := by norm_num · -- independent case: w is determined by u, and the angle of u solves a nonzero trigonometric form obtain ⟨D, hD'⟩ : ∃ x, x = p₁ * q₂ - q₁ * p₂ := ⟨_, rfl⟩ rw [← hD'] at hD obtain ⟨a₁, ha₁⟩ : ∃ x, x = r * (al₁ * q₂ - al₂ * q₁) := ⟨_, rfl⟩ obtain ⟨b₁, hb₁⟩ : ∃ x, x = r * (be₁ * q₂ - be₂ * q₁) := ⟨_, rfl⟩ obtain ⟨c₁, hc₁⟩ : ∃ x, x = k₁ * q₂ - k₂ * q₁ := ⟨_, rfl⟩ obtain ⟨a₂, ha₂⟩ : ∃ x, x = r * (p₁ * al₂ - p₂ * al₁) := ⟨_, rfl⟩ obtain ⟨b₂, hb₂⟩ : ∃ x, x = r * (p₁ * be₂ - p₂ * be₁) := ⟨_, rfl⟩ obtain ⟨c₂, hc₂⟩ : ∃ x, x = p₁ * k₂ - p₂ * k₁ := ⟨_, rfl⟩ have hcoef : (a₁ ^ 2 + a₂ ^ 2 - b₁ ^ 2 - b₂ ^ 2) ≠ 0 ∨ (2 * (a₁ * b₁ + a₂ * b₂)) ≠ 0 ∨ (2 * (a₁ * c₁ + a₂ * c₂)) ≠ 0 ∨ (2 * (b₁ * c₁ + b₂ * c₂)) ≠ 0 ∨ (b₁ ^ 2 + b₂ ^ 2 + c₁ ^ 2 + c₂ ^ 2 - D ^ 2 * r ^ 2) ≠ 0 := by by_contra h push Not at h exact hk₁0 (dual_alg_nonzero hD' ha₁ hb₁ hc₁ ha₂ hb₂ hc₂ hD hr.ne' hf h.1 h.2.1 h.2.2.1 h.2.2.2.1) -- injectivity of aa ↦ angle of aa.1 on Sol have hinj : Set.InjOn (fun aa : ℂ × ℂ => rang O (O + 1) aa.1) (Sol : Set (ℂ × ℂ)) := by intro aa haa aa' haa' h have hm := mem_coe.mp haa have hm' := mem_coe.mp haa' have hl := hlin aa hm have hl' := hlin aa' hm' rw [hSol, mem_filter, mem_product] at hm hm' have h1 : aa.1 = aa'.1 := rang_inj (hA _ hm.1.1) (hA _ hm'.1.1) h rw [h1] at hl have ex : D * (aa.2 - O).re = D * (aa'.2 - O).re := by rw [hD'] linear_combination q₂ * hl.1 - q₁ * hl.2 - (q₂ * hl'.1 - q₁ * hl'.2) have ey : D * (aa.2 - O).im = D * (aa'.2 - O).im := by rw [hD'] linear_combination p₁ * hl.2 - p₂ * hl.1 - (p₁ * hl'.2 - p₂ * hl'.1) have ex' := mul_left_cancel₀ hD ex have ey' := mul_left_cancel₀ hD ey have h2 : aa.2 - O = aa'.2 - O := Complex.ext ex' ey' exact Prod.ext h1 (by linear_combination h2) rw [← card_image_of_injOn hinj] apply trig_zeros_le_four' hcoef · intro t ht rw [mem_image] at ht obtain ⟨aa, _, rfl⟩ := ht exact rang_mem _ _ _ · intro t ht rw [mem_image] at ht obtain ⟨aa, haa, rfl⟩ := ht have hl := hlin aa haa have hm := haa rw [hSol, mem_filter, mem_product] at hm obtain ⟨hcos, hsin⟩ := cos_sin_rang_one hr (hA _ hm.1.1) rw [hcos, hsin] have hre : (aa.1 - O).re = r * ((aa.1 - O).re / r) := by field_simp have him : (aa.1 - O).im = r * ((aa.1 - O).im / r) := by field_simp have hC : ((aa.1 - O).re / r) ^ 2 + ((aa.1 - O).im / r) ^ 2 = 1 := by have := hrA _ hm.1.1 field_simp linarith refine dual_alg_poly hD' ha₁ hb₁ hc₁ ha₂ hb₂ hc₂ (w₁ := (aa.2 - O).re) (w₂ := (aa.2 - O).im) ?_ ?_ (hrA _ hm.1.2) hC · rw [hl.1] nth_rewrite 1 [hre] nth_rewrite 1 [him] ring · rw [hl.2] nth_rewrite 1 [hre] nth_rewrite 1 [him] ring end Erdos94ThmA /-! ### GLIDE Lemma 11.9 (E1), part 5: chains of non-explained matches on one curve `Γ_{a,a'}` -/ namespace Erdos94ThmA open Finset open Classical in /-- Non-explained matches of the curve `(a, a')`: `(b, b') ∈ B²` with `|ab| = |a'b'|` and `|O₁b| ≠ |O₁b'|`. -/ noncomputable def nexM (O₁ : ℂ) (B : Finset ℂ) (a a' : ℂ) : Finset (ℂ × ℂ) := (B ×ˢ B).filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ ≠ ‖p.2 - O₁‖) open Classical in /-- The quadrant chain `(s, s')`: non-explained matches with `b` on the half-circle `s` seen from `a` and `b'` on the half-circle `s'` seen from `a'` (angles about `O₂`). -/ noncomputable def chainM (O₁ O₂ : ℂ) (B : Finset ℂ) (a a' : ℂ) (s s' : Bool) : Finset (ℂ × ℂ) := (nexM O₁ B a a').filter (fun p => side s (rang O₂ a p.1) ∧ side s' (rang O₂ a' p.2)) open Classical in /-- **One quadrant chain** (GLIDE Lemma 11.9(4)+(6)): `(G + 1)|Ch| ≤ (G + 1)(1 + #close steps) + 2|B|`. -/ theorem chain_bound {O₁ O₂ a a' : ℂ} {r₂ : ℝ} (hr₂ : 0 < r₂) {B : Finset ℂ} (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) (ha : a ≠ O₂) (ha' : a' ≠ O₂) (s s' : Bool) (G : ℕ) : (G + 1) * (chainM O₁ O₂ B a a' s s').card ≤ (G + 1) * (1 + ((closeQuads O₂ B G).filter (fun pq => pq.1 ∈ chainM O₁ O₂ B a a' s s' ∧ pq.2 ∈ chainM O₁ O₂ B a a' s s' ∧ pq.1 ≠ pq.2)).card) + 2 * B.card := by obtain ⟨Ch, hCh⟩ : ∃ X, X = chainM O₁ O₂ B a a' s s' := ⟨_, rfl⟩ rw [← hCh] have hmem : ∀ p ∈ Ch, p.1 ∈ B ∧ p.2 ∈ B ∧ dist a p.1 = dist a' p.2 ∧ side s (rang O₂ a p.1) ∧ side s' (rang O₂ a' p.2) := by intro p hp rw [hCh, chainM, mem_filter, nexM, mem_filter, mem_product] at hp exact ⟨hp.1.1.1, hp.1.1.2, hp.1.2.1, hp.2.1, hp.2.2⟩ let x : ℂ × ℂ → ℝ := fun p => sgnB s * rang O₂ a p.1 let y : ℂ × ℂ → ℝ := fun p => sgnB s' * rang O₂ a' p.2 have hmono : ∀ p ∈ Ch, ∀ q ∈ Ch, x p < x q → y p < y q := by intro p hp q hq hlt obtain ⟨hp1, hp2, hpd, hps, hps'⟩ := hmem p hp obtain ⟨hq1, hq2, hqd, hqs, hqs'⟩ := hmem q hq have h1 := (side_lt_iff ha hr₂ (hB _ hp1) (hB _ hq1) hps hqs).mp hlt rw [hpd, hqd] at h1 exact (side_lt_iff ha' hr₂ (hB _ hp2) (hB _ hq2) hps' hqs').mpr h1 have hinj : ∀ p ∈ Ch, ∀ q ∈ Ch, x p = x q → p = q := by intro p hp q hq h obtain ⟨hp1, hp2, hpd, hps, hps'⟩ := hmem p hp obtain ⟨hq1, hq2, hqd, hqs, hqs'⟩ := hmem q hq have e1 : p.1 = q.1 := rang_inj (hB _ hp1) (hB _ hq1) (mul_left_cancel₀ (sgnB_ne s) h) have hd : dist a' p.2 = dist a' q.2 := by rw [← hpd, ← hqd, e1] have e2 : p.2 = q.2 := side_eq_of_dist ha' hr₂ (hB _ hp2) (hB _ hq2) hps' hqs' hd exact Prod.ext e1 e2 have hcc := chain_count Ch x y (B.image (fun w => sgnB s * rang O₂ a w)) (B.image (fun w => sgnB s' * rang O₂ a' w)) (fun p hp => mem_image.mpr ⟨p.1, (hmem p hp).1, rfl⟩) (fun p hp => mem_image.mpr ⟨p.2, (hmem p hp).2.1, rfl⟩) hmono hinj G have hX : (B.image (fun w => sgnB s * rang O₂ a w)).card ≤ B.card := card_image_le have hY : (B.image (fun w => sgnB s' * rang O₂ a' w)).card ≤ B.card := card_image_le have hss : (smallSteps Ch x y (B.image (fun w => sgnB s * rang O₂ a w)) (B.image (fun w => sgnB s' * rang O₂ a' w)) G).card ≤ ((closeQuads O₂ B G).filter (fun pq => pq.1 ∈ Ch ∧ pq.2 ∈ Ch ∧ pq.1 ≠ pq.2)).card := by apply card_le_card intro pq hpq rw [smallSteps, mem_filter, mem_product] at hpq obtain ⟨⟨hp, hq⟩, hlt, hgx, hgy⟩ := hpq obtain ⟨hp1, hp2, hpd, hps, hps'⟩ := hmem pq.1 hp obtain ⟨hq1, hq2, hqd, hqs, hqs'⟩ := hmem pq.2 hq have hylt : y pq.1 < y pq.2 := hmono _ hp _ hq hlt rw [mem_filter, closeQuads, mem_filter, mem_product, mem_product, mem_product] refine ⟨⟨⟨⟨hp1, hp2⟩, hq1, hq2⟩, gap_close hB hp1 hq1 s G hlt hgx, gap_close hB hp2 hq2 s' G hylt hgy⟩, hp, hq, fun h => ?_⟩ rw [h] at hlt exact lt_irrefl _ hlt calc (G + 1) * Ch.card ≤ (G + 1) * (1 + (smallSteps Ch x y (B.image (fun w => sgnB s * rang O₂ a w)) (B.image (fun w => sgnB s' * rang O₂ a' w)) G).card) + (B.image (fun w => sgnB s * rang O₂ a w)).card + (B.image (fun w => sgnB s' * rang O₂ a' w)).card := hcc _ ≤ (G + 1) * (1 + ((closeQuads O₂ B G).filter (fun pq => pq.1 ∈ Ch ∧ pq.2 ∈ Ch ∧ pq.1 ≠ pq.2)).card) + 2 * B.card := by have := Nat.mul_le_mul_left (G + 1) (Nat.add_le_add_left hss 1) omega open Classical in /-- Matches on an axis line: at most two `b` with `rang O₂ a b ∈ {0, π}`. -/ theorem axis_card_le_two {O₂ z : ℂ} {r₂ : ℝ} {B : Finset ℂ} (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) : (B.filter (fun b => rang O₂ z b = 0 ∨ rang O₂ z b = Real.pi)).card ≤ 2 := by calc (B.filter (fun b => rang O₂ z b = 0 ∨ rang O₂ z b = Real.pi)).card ≤ ({0, Real.pi} : Finset ℝ).card := by apply card_le_card_of_injOn (fun b => rang O₂ z b) · intro b hb rw [mem_coe, mem_filter] at hb rw [mem_coe, mem_insert, mem_singleton] exact hb.2 · intro b hb b' hb' h exact rang_inj (hB _ (mem_filter.mp (mem_coe.mp hb)).1) (hB _ (mem_filter.mp (mem_coe.mp hb')).1) h _ ≤ 2 := card_le_two open Classical in /-- **One curve** (GLIDE Lemma 11.9(4)+(6)): for `a, a' ≠ O₂`, the non-explained matches satisfy `(G + 1)·N_ne(a, a') ≤ (G + 1)(12 + #close pairs of matches) + 8|B|` (four quadrant chains, ≤ 8 axis matches). -/ theorem curve_bound {O₁ O₂ a a' : ℂ} {r₂ : ℝ} (hr₂ : 0 < r₂) {B : Finset ℂ} (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) (ha : a ≠ O₂) (ha' : a' ≠ O₂) (G : ℕ) : (G + 1) * (nexM O₁ B a a').card ≤ (G + 1) * (12 + ((closeQuads O₂ B G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B a a' ∧ pq.2 ∈ nexM O₁ B a a')).card) + 8 * B.card := by obtain ⟨N, hN⟩ : ∃ X, X = nexM O₁ B a a' := ⟨_, rfl⟩ rw [← hN] let C : Bool × Bool → Finset (ℂ × ℂ) := fun ss => chainM O₁ O₂ B a a' ss.1 ss.2 let F : Bool × Bool → Finset ((ℂ × ℂ) × (ℂ × ℂ)) := fun ss => (closeQuads O₂ B G).filter (fun pq => pq.1 ∈ C ss ∧ pq.2 ∈ C ss ∧ pq.1 ≠ pq.2) obtain ⟨ax₁, hax₁⟩ : ∃ X, X = N.filter (fun p => rang O₂ a p.1 = 0 ∨ rang O₂ a p.1 = Real.pi) := ⟨_, rfl⟩ obtain ⟨ax₂, hax₂⟩ : ∃ X, X = N.filter (fun p => rang O₂ a' p.2 = 0 ∨ rang O₂ a' p.2 = Real.pi) := ⟨_, rfl⟩ have hNmem : ∀ p ∈ N, p.1 ∈ B ∧ p.2 ∈ B ∧ dist a p.1 = dist a' p.2 := by intro p hp rw [hN, nexM, mem_filter, mem_product] at hp exact ⟨hp.1.1, hp.1.2, hp.2.1⟩ -- covering have hcov : N ⊆ (univ : Finset (Bool × Bool)).biUnion C ∪ ax₁ ∪ ax₂ := by intro p hp by_cases h1 : rang O₂ a p.1 = 0 ∨ rang O₂ a p.1 = Real.pi · exact mem_union_left _ (mem_union_right _ (by rw [hax₁, mem_filter]; exact ⟨hp, h1⟩)) · by_cases h2 : rang O₂ a' p.2 = 0 ∨ rang O₂ a' p.2 = Real.pi · exact mem_union_right _ (by rw [hax₂, mem_filter]; exact ⟨hp, h2⟩) · push Not at h1 h2 have hm1 := rang_mem O₂ a p.1 have hm2 := rang_mem O₂ a' p.2 obtain ⟨s, hs⟩ : ∃ s, side s (rang O₂ a p.1) := by rcases side_cases _ hm1.1 hm1.2 h1.1 h1.2 with h | h · exact ⟨true, h⟩ · exact ⟨false, h⟩ obtain ⟨s', hs'⟩ : ∃ s', side s' (rang O₂ a' p.2) := by rcases side_cases _ hm2.1 hm2.2 h2.1 h2.2 with h | h · exact ⟨true, h⟩ · exact ⟨false, h⟩ refine mem_union_left _ (mem_union_left _ (mem_biUnion.mpr ⟨(s, s'), mem_univ _, ?_⟩)) simp only [C, chainM, mem_filter] rw [← hN] exact ⟨hp, hs, hs'⟩ -- axis bounds have hax₁c : ax₁.card ≤ 4 := by have hsub : ax₁ ⊆ (B.filter (fun b => rang O₂ a b = 0 ∨ rang O₂ a b = Real.pi)).biUnion (fun b => (B.filter (fun b' => dist a' b' = dist a b)).image (fun b' => (b, b'))) := by intro p hp rw [hax₁, mem_filter] at hp obtain ⟨hp1, hp2, hpd⟩ := hNmem p hp.1 rw [mem_biUnion] refine ⟨p.1, mem_filter.mpr ⟨hp1, hp.2⟩, mem_image.mpr ⟨p.2, mem_filter.mpr ⟨hp2, hpd.symm⟩, rfl⟩⟩ calc ax₁.card ≤ _ := card_le_card hsub _ ≤ ∑ b ∈ B.filter (fun b => rang O₂ a b = 0 ∨ rang O₂ a b = Real.pi), ((B.filter (fun b' => dist a' b' = dist a b)).image (fun b' => (b, b'))).card := card_biUnion_le _ ≤ ∑ _b ∈ B.filter (fun b => rang O₂ a b = 0 ∨ rang O₂ a b = Real.pi), 2 := by apply sum_le_sum intro b _ exact le_trans card_image_le (card_circle_dist_le_two hB ha' _) _ ≤ 2 * 2 := by rw [sum_const, smul_eq_mul] exact Nat.mul_le_mul_right 2 (axis_card_le_two hB) _ = 4 := by norm_num have hax₂c : ax₂.card ≤ 4 := by have hsub : ax₂ ⊆ (B.filter (fun b => rang O₂ a' b = 0 ∨ rang O₂ a' b = Real.pi)).biUnion (fun b' => (B.filter (fun b => dist a b = dist a' b')).image (fun b => (b, b'))) := by intro p hp rw [hax₂, mem_filter] at hp obtain ⟨hp1, hp2, hpd⟩ := hNmem p hp.1 rw [mem_biUnion] exact ⟨p.2, mem_filter.mpr ⟨hp2, hp.2⟩, mem_image.mpr ⟨p.1, mem_filter.mpr ⟨hp1, hpd⟩, rfl⟩⟩ calc ax₂.card ≤ _ := card_le_card hsub _ ≤ ∑ b' ∈ B.filter (fun b => rang O₂ a' b = 0 ∨ rang O₂ a' b = Real.pi), ((B.filter (fun b => dist a b = dist a' b')).image (fun b => (b, b'))).card := card_biUnion_le _ ≤ ∑ _b ∈ B.filter (fun b => rang O₂ a' b = 0 ∨ rang O₂ a' b = Real.pi), 2 := by apply sum_le_sum intro b _ exact le_trans card_image_le (card_circle_dist_le_two hB ha _) _ ≤ 2 * 2 := by rw [sum_const, smul_eq_mul] exact Nat.mul_le_mul_right 2 (axis_card_le_two hB) _ = 4 := by norm_num -- chains have hch : ∀ ss : Bool × Bool, (G + 1) * (C ss).card ≤ (G + 1) * (1 + (F ss).card) + 2 * B.card := fun ss => chain_bound hr₂ hB ha ha' ss.1 ss.2 G have hFdisj : ((univ : Finset (Bool × Bool)) : Set (Bool × Bool)).PairwiseDisjoint F := by intro ss _ tt _ hst rw [Function.onFun, disjoint_left] intro pq h1 h2 simp only [F, C, mem_filter, chainM] at h1 h2 apply hst exact Prod.ext (side_unique h1.2.1.2.1 h2.2.1.2.1) (side_unique h1.2.1.2.2 h2.2.1.2.2) have hFsub : (univ : Finset (Bool × Bool)).biUnion F ⊆ (closeQuads O₂ B G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ N ∧ pq.2 ∈ N) := by intro pq hpq rw [mem_biUnion] at hpq obtain ⟨ss, _, hpq⟩ := hpq simp only [F, C, mem_filter, chainM] at hpq rw [mem_filter, hN] exact ⟨hpq.1, hpq.2.2.2, hpq.2.1.1, hpq.2.2.1.1⟩ have hsumF : ∑ ss ∈ (univ : Finset (Bool × Bool)), (F ss).card ≤ ((closeQuads O₂ B G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ N ∧ pq.2 ∈ N)).card := by rw [← card_biUnion hFdisj] exact card_le_card hFsub have hsumC : (G + 1) * ∑ ss ∈ (univ : Finset (Bool × Bool)), (C ss).card ≤ (G + 1) * (4 + ∑ ss ∈ (univ : Finset (Bool × Bool)), (F ss).card) + 8 * B.card := by rw [mul_sum] calc ∑ ss ∈ (univ : Finset (Bool × Bool)), (G + 1) * (C ss).card ≤ ∑ ss ∈ (univ : Finset (Bool × Bool)), ((G + 1) * (1 + (F ss).card) + 2 * B.card) := sum_le_sum (fun ss _ => hch ss) _ = (G + 1) * (4 + ∑ ss ∈ (univ : Finset (Bool × Bool)), (F ss).card) + 8 * B.card := by rw [sum_add_distrib, ← mul_sum, sum_add_distrib, sum_const, sum_const] simp only [card_univ, Fintype.card_prod, Fintype.card_bool, smul_eq_mul] ring have hNc : N.card ≤ ∑ ss ∈ (univ : Finset (Bool × Bool)), (C ss).card + 8 := by calc N.card ≤ ((univ : Finset (Bool × Bool)).biUnion C ∪ ax₁ ∪ ax₂).card := card_le_card hcov _ ≤ ((univ : Finset (Bool × Bool)).biUnion C ∪ ax₁).card + ax₂.card := card_union_le _ _ _ ≤ ((univ : Finset (Bool × Bool)).biUnion C).card + ax₁.card + ax₂.card := by have := card_union_le ((univ : Finset (Bool × Bool)).biUnion C) ax₁ omega _ ≤ ∑ ss ∈ (univ : Finset (Bool × Bool)), (C ss).card + 8 := by have := card_biUnion_le (s := (univ : Finset (Bool × Bool))) (t := C) omega calc (G + 1) * N.card ≤ (G + 1) * (∑ ss ∈ (univ : Finset (Bool × Bool)), (C ss).card + 8) := Nat.mul_le_mul_left _ hNc _ = (G + 1) * ∑ ss ∈ (univ : Finset (Bool × Bool)), (C ss).card + (G + 1) * 8 := by ring _ ≤ (G + 1) * (4 + ∑ ss ∈ (univ : Finset (Bool × Bool)), (F ss).card) + 8 * B.card + (G + 1) * 8 := by omega _ ≤ (G + 1) * (12 + ((closeQuads O₂ B G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ N ∧ pq.2 ∈ N)).card) + 8 * B.card := by have := Nat.mul_le_mul_left (G + 1) hsumF nlinarith end Erdos94ThmA /-! ### GLIDE Lemma 11.9 (E1), part 6: assembly — cross energy of two non-concentric circles -/ namespace Erdos94ThmA open Finset open Classical in /-- `pe(A × B, A × B) = Σ_{a, a'} #{(b, b') : |ab| = |a'b'|}`. -/ theorem pe_prod_eq (A B : Finset ℂ) : pe (A ×ˢ B) (A ×ˢ B) = ∑ a ∈ A, ∑ a' ∈ A, ((B ×ˢ B).filter (fun p => dist a p.1 = dist a' p.2)).card := by unfold pe rw [sum_product] refine sum_congr rfl (fun a _ => ?_) have h1 : ∀ b ∈ B, (∑ y ∈ A ×ˢ B, if dist (a, b).1 (a, b).2 = dist y.1 y.2 then 1 else 0) = ∑ a' ∈ A, ∑ b' ∈ B, (if dist a b = dist a' b' then 1 else 0) := fun b _ => by rw [sum_product] rw [sum_congr rfl h1, sum_comm] refine sum_congr rfl (fun a' _ => ?_) rw [card_filter, sum_product] open Classical in /-- On `A × B` with `B` on a circle about `O₂`, every distance class has at most `2|A| + |B|` pairs. -/ theorem cnt_prod_le {O₂ : ℂ} {r₂ : ℝ} {A B : Finset ℂ} (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) (u : ℝ) : cnt (A ×ˢ B) u ≤ 2 * A.card + B.card := by unfold cnt have hsub : (A ×ˢ B).filter (fun y => dist y.1 y.2 = u) ⊆ ({O₂} ×ˢ B) ∪ (A.erase O₂).biUnion (fun a => (B.filter (fun b => dist a b = u)).image (fun b => (a, b))) := by intro y hy rw [mem_filter, mem_product] at hy by_cases h : y.1 = O₂ · exact mem_union_left _ (mem_product.mpr ⟨mem_singleton.mpr h, hy.1.2⟩) · refine mem_union_right _ (mem_biUnion.mpr ⟨y.1, mem_erase.mpr ⟨h, hy.1.1⟩, mem_image.mpr ⟨y.2, mem_filter.mpr ⟨hy.1.2, hy.2⟩, rfl⟩⟩) calc ((A ×ˢ B).filter (fun y => dist y.1 y.2 = u)).card ≤ _ := card_le_card hsub _ ≤ ({O₂} ×ˢ B).card + ((A.erase O₂).biUnion (fun a => (B.filter (fun b => dist a b = u)).image (fun b => (a, b)))).card := card_union_le _ _ _ ≤ B.card + 2 * A.card := by refine Nat.add_le_add (by rw [card_product, card_singleton, one_mul]) ?_ calc ((A.erase O₂).biUnion (fun a => (B.filter (fun b => dist a b = u)).image (fun b => (a, b)))).card ≤ ∑ a ∈ A.erase O₂, ((B.filter (fun b => dist a b = u)).image (fun b => (a, b))).card := card_biUnion_le _ ≤ ∑ _a ∈ A.erase O₂, 2 := by apply sum_le_sum intro a ha exact le_trans card_image_le (card_circle_dist_le_two hB (ne_of_mem_erase ha) u) _ = (A.erase O₂).card * 2 := by rw [sum_const, smul_eq_mul] _ ≤ 2 * A.card := by have := card_erase_le (s := A) (a := O₂) omega _ = 2 * A.card + B.card := by ring open Classical in /-- **Lemma 11.9 step (0): removing the centres.** Quadruples using `a = O₂` or `b = O₁` cost at most `2(|A| + |B|)(2|A| + |B|)`. -/ theorem pe_centres_le {O₁ O₂ : ℂ} {r₂ : ℝ} {A B : Finset ℂ} (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) : pe (A ×ˢ B) (A ×ˢ B) ≤ pe ((A.erase O₂) ×ˢ (B.erase O₁)) ((A.erase O₂) ×ˢ (B.erase O₁)) + 2 * ((A.card + B.card) * (2 * A.card + B.card)) := by obtain ⟨X, hX⟩ : ∃ S, S = (A.erase O₂) ×ˢ (B.erase O₁) := ⟨_, rfl⟩ obtain ⟨E, hE⟩ : ∃ S, S = (A ×ˢ B).filter (fun x => x.1 = O₂ ∨ x.2 = O₁) := ⟨_, rfl⟩ rw [← hX] have hXsub : X ⊆ A ×ˢ B := by rw [hX] exact product_subset_product (erase_subset _ _) (erase_subset _ _) have hEsub : E ⊆ A ×ˢ B := by rw [hE] exact filter_subset _ _ have hcov : A ×ˢ B ⊆ X ∪ E := by intro x hx by_cases h : x.1 = O₂ ∨ x.2 = O₁ · exact mem_union_right _ (by rw [hE, mem_filter]; exact ⟨hx, h⟩) · push Not at h rw [mem_product] at hx exact mem_union_left _ (by rw [hX, mem_product] exact ⟨mem_erase.mpr ⟨h.1, hx.1⟩, mem_erase.mpr ⟨h.2, hx.2⟩⟩) have hEc : E.card ≤ A.card + B.card := by have hs : E ⊆ ({O₂} ×ˢ B) ∪ (A ×ˢ {O₁}) := by intro x hx rw [hE, mem_filter, mem_product] at hx rcases hx.2 with h | h · exact mem_union_left _ (mem_product.mpr ⟨mem_singleton.mpr h, hx.1.2⟩) · exact mem_union_right _ (mem_product.mpr ⟨hx.1.1, mem_singleton.mpr h⟩) calc E.card ≤ (({O₂} ×ˢ B) ∪ (A ×ˢ {O₁})).card := card_le_card hs _ ≤ ({O₂} ×ˢ B).card + (A ×ˢ {O₁}).card := card_union_le _ _ _ = A.card + B.card := by rw [card_product, card_product, card_singleton, card_singleton]; ring have hcntS : ∀ x ∈ E, cnt (X ∪ E) (dist x.1 x.2) ≤ 2 * A.card + B.card := by intro x _ calc cnt (X ∪ E) (dist x.1 x.2) ≤ cnt (A ×ˢ B) (dist x.1 x.2) := by unfold cnt exact card_le_card (filter_subset_filter _ (union_subset hXsub hEsub)) _ ≤ 2 * A.card + B.card := cnt_prod_le hB _ have hpeE : pe E (X ∪ E) ≤ E.card * (2 * A.card + B.card) := pe_le_of_cnt_le _ _ _ hcntS calc pe (A ×ˢ B) (A ×ˢ B) ≤ pe (X ∪ E) (X ∪ E) := le_trans (pe_mono_left hcov _) (pe_mono_right _ hcov) _ ≤ pe X (X ∪ E) + pe E (X ∪ E) := pe_union_left_le _ _ _ _ ≤ (pe X X + pe X E) + pe E (X ∪ E) := Nat.add_le_add_right (pe_union_right_le _ _ _) _ _ ≤ pe X X + 2 * pe E (X ∪ E) := by have : pe X E ≤ pe E (X ∪ E) := by rw [pe_comm] exact pe_mono_right _ subset_union_left omega _ ≤ pe X X + 2 * ((A.card + B.card) * (2 * A.card + B.card)) := by have := Nat.mul_le_mul_right (2 * A.card + B.card) hEc omega open Classical in /-- **Lemma 11.9 step (3): explained quadruples.** With `|ab| = |a'b'|` and `a, a'` on the circle about `O₁`, the match is explained iff `|O₁b| = |O₁b'|` (SSS); there are at most `4|A||B|` such quadruples. -/ theorem explained_le {O₁ O₂ : ℂ} (hO : O₁ ≠ O₂) {r₁ r₂ : ℝ} {A B : Finset ℂ} (hA : ∀ a ∈ A, ‖a - O₁‖ = r₁) (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) : ∑ a ∈ A.erase O₂, ∑ a' ∈ A.erase O₂, ((B.erase O₁ ×ˢ B.erase O₁).filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card ≤ 4 * A.card * B.card := by obtain ⟨A', hA'⟩ : ∃ S, S = A.erase O₂ := ⟨_, rfl⟩ obtain ⟨B', hB'⟩ : ∃ S, S = B.erase O₁ := ⟨_, rfl⟩ rw [← hA', ← hB'] have hA'c : A'.card ≤ A.card := by rw [hA']; exact card_erase_le have hB'c : B'.card ≤ B.card := by rw [hB']; exact card_erase_le have hB'O : ∀ b ∈ B', b ≠ O₁ := fun b hb => by rw [hB'] at hb; exact ne_of_mem_erase hb have hA'A : ∀ a ∈ A', a ∈ A := fun a ha => by rw [hA'] at ha; exact mem_of_mem_erase ha have hB'B : ∀ b ∈ B', b ∈ B := fun b hb => by rw [hB'] at hb; exact mem_of_mem_erase hb have hswap : ∀ a ∈ A', ∑ a' ∈ A', ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card = ∑ p ∈ B' ×ˢ B', (A'.filter (fun a' => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card := by intro a _ simp_rw [card_filter] exact sum_comm rw [sum_congr rfl hswap] -- each (a, p) contributes at most 2 if |O₁ p.1| = |O₁ p.2|, else 0 have hterm : ∀ a ∈ A', ∀ p ∈ B' ×ˢ B', (A'.filter (fun a' => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card ≤ if ‖p.1 - O₁‖ = ‖p.2 - O₁‖ then 2 else 0 := by intro a _ p hp rw [mem_product] at hp split_ifs with h · calc (A'.filter (fun a' => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card ≤ (A.filter (fun a' => dist p.2 a' = dist a p.1)).card := by apply card_le_card intro a' ha' rw [mem_filter] at ha' ⊢ exact ⟨hA'A _ ha'.1, by rw [dist_comm]; exact ha'.2.1.symm⟩ _ ≤ 2 := card_circle_dist_le_two hA (hB'O _ hp.2) _ · rw [Nat.le_zero, card_eq_zero, filter_eq_empty_iff] intro a' _ h' exact h h'.2 have hpairs : ((B' ×ˢ B').filter (fun p => ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card ≤ 2 * B.card := by have hfib : ((B' ×ˢ B').filter (fun p => ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card = ∑ b ∈ B', (((B' ×ˢ B').filter (fun p => ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).filter (fun p => p.1 = b)).card := by apply card_eq_sum_card_fiberwise intro p hp rw [mem_coe, mem_filter, mem_product] at hp exact mem_coe.mpr hp.1.1 rw [hfib] calc ∑ b ∈ B', (((B' ×ˢ B').filter (fun p => ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).filter (fun p => p.1 = b)).card ≤ ∑ _b ∈ B', 2 := by apply sum_le_sum intro b _ calc (((B' ×ˢ B').filter (fun p => ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).filter (fun p => p.1 = b)).card ≤ (B.filter (fun b' => dist O₁ b' = ‖b - O₁‖)).card := by apply card_le_card_of_injOn Prod.snd · intro p hp rw [mem_coe, mem_filter, mem_filter, mem_product] at hp rw [mem_coe, mem_filter, dist_comm, dist_eq_norm, ← hp.2, hp.1.2] exact ⟨hB'B _ hp.1.1.2, rfl⟩ · intro p hp p' hp' h have e1 := (mem_filter.mp (mem_coe.mp hp)).2 have e2 := (mem_filter.mp (mem_coe.mp hp')).2 exact Prod.ext (e1.trans e2.symm) h _ ≤ 2 := card_circle_dist_le_two hB hO _ _ = B'.card * 2 := by rw [sum_const, smul_eq_mul] _ ≤ 2 * B.card := by omega calc ∑ a ∈ A', ∑ p ∈ B' ×ˢ B', (A'.filter (fun a' => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card ≤ ∑ _a ∈ A', ∑ p ∈ B' ×ˢ B', (if ‖p.1 - O₁‖ = ‖p.2 - O₁‖ then 2 else 0) := sum_le_sum (fun a ha => sum_le_sum (fun p hp => hterm a ha p hp)) _ = A'.card * (2 * ((B' ×ˢ B').filter (fun p => ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card) := by rw [sum_const, smul_eq_mul, ← sum_filter, sum_const, smul_eq_mul, mul_comm _ 2] _ ≤ A.card * (2 * (2 * B.card)) := Nat.mul_le_mul hA'c (Nat.mul_le_mul_left 2 hpairs) _ = 4 * A.card * B.card := by ring /-- Swapping a double sum of filter cardinalities. -/ theorem sum_card_filter_swap {α β : Type*} (S : Finset α) (Q : Finset β) (P : α → α → β → Prop) [∀ a a' q, Decidable (P a a' q)] : ∑ a ∈ S, ∑ a' ∈ S, (Q.filter (fun q => P a a' q)).card = ∑ q ∈ Q, ((S ×ˢ S).filter (fun aa => P aa.1 aa.2 q)).card := by have h1 : ∀ a ∈ S, ∑ a' ∈ S, (Q.filter (fun q => P a a' q)).card = ∑ q ∈ Q, (S.filter (fun a' => P a a' q)).card := by intro a _ simp only [card_filter] exact sum_comm rw [sum_congr rfl h1, sum_comm] refine sum_congr rfl (fun q _ => ?_) simp only [card_filter, sum_product] open Classical in /-- **Lemma 11.9 step (6), the double count over curves:** a close pair of distinct points of `B²` that are both non-explained matches lies on at most 4 curves (the dual property), so `Σ_{a,a'} #(close pairs of matches of (a, a')) ≤ 4 |closeQuads|`. -/ theorem dual_sum_le {O₁ O₂ : ℂ} {r₁ : ℝ} (hr₁ : 0 < r₁) {A B : Finset ℂ} (hA : ∀ a ∈ A, ‖a - O₁‖ = r₁) (G : ℕ) : ∑ a ∈ A.erase O₂, ∑ a' ∈ A.erase O₂, ((closeQuads O₂ (B.erase O₁) G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ (B.erase O₁) a a' ∧ pq.2 ∈ nexM O₁ (B.erase O₁) a a')).card ≤ 4 * (closeQuads O₂ (B.erase O₁) G).card := by obtain ⟨A', hA'⟩ : ∃ S, S = A.erase O₂ := ⟨_, rfl⟩ obtain ⟨B', hB'⟩ : ∃ S, S = B.erase O₁ := ⟨_, rfl⟩ rw [← hA', ← hB'] obtain ⟨Q, hQ⟩ : ∃ S, S = closeQuads O₂ B' G := ⟨_, rfl⟩ rw [← hQ] have hA'A : ∀ a ∈ A', a ∈ A := fun a ha => by rw [hA'] at ha; exact mem_of_mem_erase ha have hB'O : ∀ b ∈ B', b ≠ O₁ := fun b hb => by rw [hB'] at hb; exact ne_of_mem_erase hb have hswap : ∑ a ∈ A', ∑ a' ∈ A', (Q.filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' a a' ∧ pq.2 ∈ nexM O₁ B' a a')).card = ∑ pq ∈ Q, ((A' ×ˢ A').filter (fun aa => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' aa.1 aa.2 ∧ pq.2 ∈ nexM O₁ B' aa.1 aa.2)).card := sum_card_filter_swap A' Q (fun a a' pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' a a' ∧ pq.2 ∈ nexM O₁ B' a a') rw [hswap] calc ∑ pq ∈ Q, ((A' ×ˢ A').filter (fun aa => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' aa.1 aa.2 ∧ pq.2 ∈ nexM O₁ B' aa.1 aa.2)).card ≤ ∑ _pq ∈ Q, 4 := by apply sum_le_sum intro pq hpq rw [hQ, closeQuads, mem_filter, mem_product, mem_product, mem_product] at hpq obtain ⟨⟨⟨hb, hb'⟩, hc, hc'⟩, _⟩ := hpq by_cases hne : pq.1 ≠ pq.2 ∧ ‖pq.1.1 - O₁‖ ≠ ‖pq.1.2 - O₁‖ · calc ((A' ×ˢ A').filter (fun aa => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' aa.1 aa.2 ∧ pq.2 ∈ nexM O₁ B' aa.1 aa.2)).card ≤ ((A ×ˢ A).filter (fun aa => dist aa.1 pq.1.1 = dist aa.2 pq.1.2 ∧ dist aa.1 pq.2.1 = dist aa.2 pq.2.2)).card := by apply card_le_card intro aa haa rw [mem_filter, mem_product] at haa ⊢ obtain ⟨⟨h1, h2⟩, _, hm1, hm2⟩ := haa rw [nexM, mem_filter] at hm1 hm2 exact ⟨⟨hA'A _ h1, hA'A _ h2⟩, hm1.2.1, hm2.2.1⟩ _ ≤ 4 := by have hpq : (pq.1.1, pq.1.2) ≠ (pq.2.1, pq.2.2) := by intro h exact hne.1 (Prod.ext (congrArg Prod.fst h) (congrArg Prod.snd h)) exact dual_le_four hr₁ hA (hB'O _ hb) (hB'O _ hc') (hB'O _ hb') hpq hne.2 · rw [not_and_or, not_not, not_not] at hne rw [Nat.le_succ_iff] left rw [Nat.le_iff_lt_or_eq] left apply Nat.lt_of_le_of_lt (m := 0) _ (by norm_num) rw [Nat.le_zero, card_eq_zero, filter_eq_empty_iff] intro aa _ h rcases hne with h' | h' · exact h.1 h' · have hm := h.2.1 rw [nexM, mem_filter] at hm exact hm.2.2 h' _ = 4 * Q.card := by rw [sum_const, smul_eq_mul, mul_comm] open Classical in /-- **GLIDE Lemma 11.9 (E1), counting form.** `C₁ = C(O₁, r₁)`, `C₂ = C(O₂, r₂)`, `O₁ ≠ O₂`, `r₁, r₂ > 0`, `A ⊂ C₁`, `B ⊂ C₂` arbitrary finite sets, `G ∈ ℕ`. Then `(G + 1)·S_AB ≤ (G + 1)(12|A|² + 16G²|B|² + 4|A||B| + 2(|A| + |B|)(2|A| + |B|)) + 8|A|²|B|`, with `S_AB = #{(a, b, a', b') ∈ (A × B)² : |ab| = |a'b'|}` (`pe (A ×ˢ B) (A ×ˢ B)`). -/ theorem lemma119_nat {O₁ O₂ : ℂ} (hO : O₁ ≠ O₂) {r₁ r₂ : ℝ} (hr₁ : 0 < r₁) (hr₂ : 0 < r₂) {A B : Finset ℂ} (hA : ∀ a ∈ A, ‖a - O₁‖ = r₁) (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) (G : ℕ) : (G + 1) * pe (A ×ˢ B) (A ×ˢ B) ≤ (G + 1) * (12 * A.card ^ 2 + 16 * (G * B.card) ^ 2 + 4 * A.card * B.card + 2 * ((A.card + B.card) * (2 * A.card + B.card))) + 8 * A.card ^ 2 * B.card := by obtain ⟨A', hA'⟩ : ∃ S, S = A.erase O₂ := ⟨_, rfl⟩ obtain ⟨B', hB'⟩ : ∃ S, S = B.erase O₁ := ⟨_, rfl⟩ have hA'c : A'.card ≤ A.card := by rw [hA']; exact card_erase_le have hB'c : B'.card ≤ B.card := by rw [hB']; exact card_erase_le have hB'B : ∀ b ∈ B', ‖b - O₂‖ = r₂ := fun b hb => by rw [hB'] at hb; exact hB b (mem_of_mem_erase hb) have hA'O : ∀ a ∈ A', a ≠ O₂ := fun a ha => by rw [hA'] at ha; exact ne_of_mem_erase ha have h0 := pe_centres_le (O₁ := O₁) (O₂ := O₂) (A := A) hB rw [← hA', ← hB'] at h0 have hsplit : ∀ a ∈ A', ∀ a' ∈ A', ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2)).card = (nexM O₁ B' a a').card + ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card := by intro a _ a' _ rw [nexM, ← card_filter_add_card_filter_not (s := (B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2)) (fun p => ‖p.1 - O₁‖ = ‖p.2 - O₁‖), filter_filter, filter_filter, add_comm] have hpe : pe (A' ×ˢ B') (A' ×ˢ B') = ∑ a ∈ A', ∑ a' ∈ A', ((nexM O₁ B' a a').card + ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card) := by rw [pe_prod_eq] exact sum_congr rfl (fun a ha => sum_congr rfl (fun a' ha' => hsplit a ha a' ha')) have hex := explained_le (A := A) (B := B) hO hA hB rw [← hA', ← hB'] at hex have hdual := dual_sum_le (O₂ := O₂) (B := B) hr₁ hA G rw [← hA', ← hB'] at hdual have hcq := closeQuads_card hB'B G have hcurve : ∀ a ∈ A', ∀ a' ∈ A', (G + 1) * (nexM O₁ B' a a').card ≤ (G + 1) * (12 + ((closeQuads O₂ B' G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' a a' ∧ pq.2 ∈ nexM O₁ B' a a')).card) + 8 * B'.card := fun a ha a' ha' => curve_bound hr₂ hB'B (hA'O a ha) (hA'O a' ha') G -- sum the curve bounds have hsum : (G + 1) * pe (A' ×ˢ B') (A' ×ˢ B') ≤ (G + 1) * (12 * A'.card ^ 2 + ∑ a ∈ A', ∑ a' ∈ A', ((closeQuads O₂ B' G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' a a' ∧ pq.2 ∈ nexM O₁ B' a a')).card) + 8 * B'.card * A'.card ^ 2 + (G + 1) * ∑ a ∈ A', ∑ a' ∈ A', ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card := by rw [hpe, mul_sum] calc ∑ a ∈ A', (G + 1) * ∑ a' ∈ A', ((nexM O₁ B' a a').card + ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card) = ∑ a ∈ A', ∑ a' ∈ A', ((G + 1) * (nexM O₁ B' a a').card + (G + 1) * ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card) := by refine sum_congr rfl (fun a _ => ?_) rw [mul_sum] exact sum_congr rfl (fun a' _ => by ring) _ ≤ ∑ a ∈ A', ∑ a' ∈ A', (((G + 1) * (12 + ((closeQuads O₂ B' G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' a a' ∧ pq.2 ∈ nexM O₁ B' a a')).card) + 8 * B'.card) + (G + 1) * ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card) := sum_le_sum (fun a ha => sum_le_sum (fun a' ha' => Nat.add_le_add_right (hcurve a ha a' ha') _)) _ = (G + 1) * (12 * A'.card ^ 2 + ∑ a ∈ A', ∑ a' ∈ A', ((closeQuads O₂ B' G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' a a' ∧ pq.2 ∈ nexM O₁ B' a a')).card) + 8 * B'.card * A'.card ^ 2 + (G + 1) * ∑ a ∈ A', ∑ a' ∈ A', ((B' ×ˢ B').filter (fun p => dist a p.1 = dist a' p.2 ∧ ‖p.1 - O₁‖ = ‖p.2 - O₁‖)).card := by simp only [sum_add_distrib, mul_add, mul_sum, sum_const, smul_eq_mul] ring -- combine have hfin : (G + 1) * pe (A' ×ˢ B') (A' ×ˢ B') ≤ (G + 1) * (12 * A.card ^ 2 + 16 * (G * B.card) ^ 2 + 4 * A.card * B.card) + 8 * A.card ^ 2 * B.card := by have e1 : A'.card ^ 2 ≤ A.card ^ 2 := Nat.pow_le_pow_left hA'c 2 have e2 : (G * B'.card) ^ 2 ≤ (G * B.card) ^ 2 := Nat.pow_le_pow_left (Nat.mul_le_mul_left G hB'c) 2 have e3 : 8 * B'.card * A'.card ^ 2 ≤ 8 * A.card ^ 2 * B.card := by have := Nat.mul_le_mul (Nat.mul_le_mul_left 8 hB'c) e1 nlinarith have e4 : ∑ a ∈ A', ∑ a' ∈ A', ((closeQuads O₂ B' G).filter (fun pq => pq.1 ≠ pq.2 ∧ pq.1 ∈ nexM O₁ B' a a' ∧ pq.2 ∈ nexM O₁ B' a a')).card ≤ 16 * (G * B.card) ^ 2 := by calc _ ≤ 4 * (closeQuads O₂ B' G).card := hdual _ ≤ 4 * (4 * (G * B'.card) ^ 2) := Nat.mul_le_mul_left 4 hcq _ ≤ 16 * (G * B.card) ^ 2 := by nlinarith have e5 := Nat.mul_le_mul_left (G + 1) hex have e6 := Nat.mul_le_mul_left (G + 1) (Nat.add_le_add (Nat.mul_le_mul_left 12 e1) e4) nlinarith calc (G + 1) * pe (A ×ˢ B) (A ×ˢ B) ≤ (G + 1) * (pe (A' ×ˢ B') (A' ×ˢ B') + 2 * ((A.card + B.card) * (2 * A.card + B.card))) := Nat.mul_le_mul_left _ h0 _ ≤ (G + 1) * (12 * A.card ^ 2 + 16 * (G * B.card) ^ 2 + 4 * A.card * B.card + 2 * ((A.card + B.card) * (2 * A.card + B.card))) + 8 * A.card ^ 2 * B.card := by nlinarith /-- **GLIDE Lemma 11.9 (cross energy of two non-concentric circles), the paper's bound.** `C₁ = C(O₁, r₁)`, `C₂ = C(O₂, r₂)`, `O₁ ≠ O₂` (radii positive, arbitrary otherwise; the circles may intersect), `A ⊂ C₁`, `B ⊂ C₂` ARBITRARY finite sets. Then for every integer `G ≥ 1` `S_AB ≤ 16|A||B| + 6(|A| + |B|)² + |A|²(12 + 8|B|/G) + 4|B|²(2G + 1)²`, where `S_AB = pe (A ×ˢ B) (A ×ˢ B) = #{(a, b, a', b') : |ab| = |a'b'|}` (this counts also `|ab| = 0`, so it bounds the paper's `S_AB`, which requires `|ab| > 0`). -/ theorem lemma119 {O₁ O₂ : ℂ} (hO : O₁ ≠ O₂) {r₁ r₂ : ℝ} (hr₁ : 0 < r₁) (hr₂ : 0 < r₂) {A B : Finset ℂ} (hA : ∀ a ∈ A, ‖a - O₁‖ = r₁) (hB : ∀ b ∈ B, ‖b - O₂‖ = r₂) (G : ℕ) (hG : 1 ≤ G) : (pe (A ×ˢ B) (A ×ˢ B) : ℝ) ≤ 16 * A.card * B.card + 6 * (A.card + B.card) ^ 2 + A.card ^ 2 * (12 + 8 * B.card / G) + 4 * B.card ^ 2 * (2 * G + 1) ^ 2 := by have h := lemma119_nat hO hr₁ hr₂ hA hB G obtain ⟨a, ha⟩ : ∃ x : ℝ, x = A.card := ⟨_, rfl⟩ obtain ⟨b, hb⟩ : ∃ x : ℝ, x = B.card := ⟨_, rfl⟩ obtain ⟨g, hg⟩ : ∃ x : ℝ, x = G := ⟨_, rfl⟩ obtain ⟨P, hP⟩ : ∃ x : ℝ, x = pe (A ×ˢ B) (A ×ˢ B) := ⟨_, rfl⟩ have hR : (g + 1) * P ≤ (g + 1) * (12 * a ^ 2 + 16 * (g * b) ^ 2 + 4 * a * b + 2 * ((a + b) * (2 * a + b))) + 8 * a ^ 2 * b := by rw [ha, hb, hg, hP] exact_mod_cast h rw [← ha, ← hb, ← hg, ← hP] have hg1 : (1 : ℝ) ≤ g := by rw [hg]; exact_mod_cast hG have ha0 : 0 ≤ a := by rw [ha]; positivity have hb0 : 0 ≤ b := by rw [hb]; positivity have h1 : P ≤ 12 * a ^ 2 + 16 * (g * b) ^ 2 + 4 * a * b + 2 * ((a + b) * (2 * a + b)) + 8 * a ^ 2 * b / (g + 1) := by rw [← sub_nonneg] have e : 12 * a ^ 2 + 16 * (g * b) ^ 2 + 4 * a * b + 2 * ((a + b) * (2 * a + b)) + 8 * a ^ 2 * b / (g + 1) - P = ((g + 1) * (12 * a ^ 2 + 16 * (g * b) ^ 2 + 4 * a * b + 2 * ((a + b) * (2 * a + b))) + 8 * a ^ 2 * b - (g + 1) * P) / (g + 1) := by field_simp rw [e] apply div_nonneg <;> linarith have h2 : 8 * a ^ 2 * b / (g + 1) ≤ a ^ 2 * (8 * b / g) := by rw [mul_div_assoc', show a ^ 2 * (8 * b) = 8 * a ^ 2 * b by ring] exact div_le_div_of_nonneg_left (by positivity) (by linarith) (by linarith) have hX : 16 * (g * b) ^ 2 + 4 * a * b + 2 * ((a + b) * (2 * a + b)) ≤ 16 * a * b + 6 * (a + b) ^ 2 + 4 * b ^ 2 * (2 * g + 1) ^ 2 := by nlinarith [mul_nonneg ha0 hb0, mul_nonneg (sq_nonneg b) (by linarith : (0 : ℝ) ≤ 4 * g + 1), mul_nonneg ha0 ha0, mul_nonneg hb0 hb0] have e3 : a ^ 2 * (12 + 8 * b / g) = 12 * a ^ 2 + a ^ 2 * (8 * b / g) := by ring rw [e3] linarith end Erdos94ThmA /-! ### GLIDE Corollary 11.10 (cross energies of a circle family with distinct centres) -/ namespace Erdos94ThmA open Finset /-- **GLIDE Corollary 11.10, explicit form.** Points `Q_i` on circles `C(c_i, ρ_i)` (`ρ_i > 0`) with pairwise distinct centres, `|Q_i| ≤ N`: for `i ≠ j` and every integer `G ≥ 1` the cross energy satisfies `S_ij = pe(Q_i × Q_j) ≤ 52N² + 8N³/G + 4(2G + 1)²N²`. -/ theorem cor1110 {k : ℕ} (c : Fin k → ℂ) (hc : Function.Injective c) (ρ : Fin k → ℝ) (hρ : ∀ i, 0 < ρ i) (Q : Fin k → Finset ℂ) (hQ : ∀ i, ∀ q ∈ Q i, ‖q - c i‖ = ρ i) {N : ℝ} (hQN : ∀ i, ((Q i).card : ℝ) ≤ N) {i j : Fin k} (hij : i ≠ j) (G : ℕ) (hG : 1 ≤ G) : (pe (Q i ×ˢ Q j) (Q i ×ˢ Q j) : ℝ) ≤ 52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2 := by have hne : c i ≠ c j := fun h => hij (hc h) have h := lemma119 hne (hρ i) (hρ j) (hQ i) (hQ j) G hG have hG0 : (0 : ℝ) < G := by exact_mod_cast hG obtain ⟨a, ha⟩ : ∃ x : ℝ, x = (Q i).card := ⟨_, rfl⟩ obtain ⟨b, hb⟩ : ∃ x : ℝ, x = (Q j).card := ⟨_, rfl⟩ rw [← ha, ← hb] at h have haN : a ≤ N := by rw [ha]; exact hQN _ have hbN : b ≤ N := by rw [hb]; exact hQN _ have ha0 : 0 ≤ a := by rw [ha]; positivity have hb0 : 0 ≤ b := by rw [hb]; positivity have h1 : a * b ≤ N ^ 2 := by nlinarith have h2 : (a + b) ^ 2 ≤ 4 * N ^ 2 := by nlinarith have h3 : a ^ 2 ≤ N ^ 2 := by nlinarith have h4 : a ^ 2 * b ≤ N ^ 3 := by have := mul_le_mul h3 hbN hb0 (sq_nonneg N) nlinarith have h5 : 8 * (a ^ 2 * b) / G ≤ 8 * N ^ 3 / G := div_le_div_of_nonneg_right (by linarith) hG0.le have h6 : b ^ 2 * (2 * G + 1) ^ 2 ≤ N ^ 2 * (2 * G + 1) ^ 2 := mul_le_mul_of_nonneg_right (by nlinarith) (sq_nonneg _) have e : a ^ 2 * (12 + 8 * b / G) = 12 * a ^ 2 + 8 * (a ^ 2 * b) / G := by field_simp rw [e] at h nlinarith /-- **GLIDE Corollary 11.10, `O(N^{8/3})` form.** In the setting of `cor1110`, if `N ≥ 1` then every cross energy satisfies `S_ij ≤ 160·N^{8/3}` (take `G = ⌈N^{1/3}⌉`). -/ theorem cor1110' {k : ℕ} (c : Fin k → ℂ) (hc : Function.Injective c) (ρ : Fin k → ℝ) (hρ : ∀ i, 0 < ρ i) (Q : Fin k → Finset ℂ) (hQ : ∀ i, ∀ q ∈ Q i, ‖q - c i‖ = ρ i) {N : ℝ} (hN1 : 1 ≤ N) (hQN : ∀ i, ((Q i).card : ℝ) ≤ N) {i j : Fin k} (hij : i ≠ j) : (pe (Q i ×ˢ Q j) (Q i ×ˢ Q j) : ℝ) ≤ 160 * N ^ ((8 : ℝ) / 3) := by have hN0 : 0 < N := by linarith obtain ⟨t, ht⟩ : ∃ x : ℝ, x = N ^ ((1 : ℝ) / 3) := ⟨_, rfl⟩ have ht1 : 1 ≤ t := by rw [ht]; exact Real.one_le_rpow hN1 (by norm_num) have ht3 : t ^ 3 = N := by rw [ht, ← Real.rpow_natCast, ← Real.rpow_mul hN0.le] norm_num have ht8 : N ^ ((8 : ℝ) / 3) = t ^ 8 := by rw [ht, ← Real.rpow_natCast, ← Real.rpow_mul hN0.le] norm_num rw [ht8] obtain ⟨G, hG⟩ : ∃ g : ℕ, g = ⌈t⌉₊ := ⟨_, rfl⟩ have hGt : t ≤ G := by rw [hG]; exact Nat.le_ceil t have hGt' : (G : ℝ) < t + 1 := by rw [hG]; exact Nat.ceil_lt_add_one (by linarith) have hG1 : 1 ≤ G := by have : (1 : ℝ) ≤ G := le_trans ht1 hGt exact_mod_cast this have h := cor1110 c hc ρ hρ Q hQ hQN hij G hG1 have hG0 : (0 : ℝ) < G := by linarith have e1 : 8 * N ^ 3 / G ≤ 8 * t ^ 8 := by rw [div_le_iff₀ hG0, ← ht3] have : t ^ 9 ≤ t ^ 8 * G := by have := mul_le_mul_of_nonneg_left hGt (by positivity : (0 : ℝ) ≤ t ^ 8) nlinarith nlinarith have e2 : 4 * (2 * (G : ℝ) + 1) ^ 2 * N ^ 2 ≤ 100 * t ^ 8 := by have hb : 2 * (G : ℝ) + 1 ≤ 5 * t := by linarith have hb0 : 0 ≤ 2 * (G : ℝ) + 1 := by positivity have hsq : (2 * (G : ℝ) + 1) ^ 2 ≤ 25 * t ^ 2 := by nlinarith rw [← ht3] have : (2 * (G : ℝ) + 1) ^ 2 * (t ^ 3) ^ 2 ≤ 25 * t ^ 2 * (t ^ 3) ^ 2 := mul_le_mul_of_nonneg_right hsq (sq_nonneg _) nlinarith have e3 : 52 * N ^ 2 ≤ 52 * t ^ 8 := by rw [← ht3] have : t ^ 6 ≤ t ^ 8 := pow_le_pow_right₀ ht1 (by norm_num) nlinarith linarith end Erdos94ThmA /-! ### GLIDE Theorem 9.5 (energy accounting for boundedly many circles with distinct centres) -/ namespace Erdos94ThmA open Finset /-- `(x + y)² ≤ (1 + λ)x² + (1 + 1/λ)y²` for `λ > 0`. -/ theorem sq_add_le_lam {x y l : ℝ} (hl : 0 < l) : (x + y) ^ 2 ≤ (1 + l) * x ^ 2 + (1 + 1 / l) * y ^ 2 := by have h : 0 ≤ (l * x - y) ^ 2 / l := div_nonneg (sq_nonneg _) hl.le have e : (1 + l) * x ^ 2 + (1 + 1 / l) * y ^ 2 - (x + y) ^ 2 = (l * x - y) ^ 2 / l := by field_simp ring linarith theorem pe_eq_sum_sq (S : Finset (ℂ × ℂ)) (V : Finset ℝ) (hV : ∀ x ∈ S, dist x.1 x.2 ∈ V) : (pe S S : ℝ) = ∑ u ∈ V, (cnt S u : ℝ) ^ 2 := by rw [pe_eq_sum_fiber S S V hV] push_cast exact sum_congr rfl (fun u _ => by ring) /-- `pe(S ∪ T) ≤ (1 + λ) pe(S) + (1 + 1/λ) pe(T)`. -/ theorem pe_union_le_lam (S T : Finset (ℂ × ℂ)) {l : ℝ} (hl : 0 < l) : (pe (S ∪ T) (S ∪ T) : ℝ) ≤ (1 + l) * pe S S + (1 + 1 / l) * pe T T := by classical obtain ⟨V, hV⟩ : ∃ V : Finset ℝ, V = (S ∪ T).image (fun x => dist x.1 x.2) := ⟨_, rfl⟩ have hSV : ∀ x ∈ S, dist x.1 x.2 ∈ V := fun x hx => by rw [hV]; exact mem_image_of_mem _ (mem_union_left _ hx) have hTV : ∀ x ∈ T, dist x.1 x.2 ∈ V := fun x hx => by rw [hV]; exact mem_image_of_mem _ (mem_union_right _ hx) have hUV : ∀ x ∈ S ∪ T, dist x.1 x.2 ∈ V := fun x hx => by rw [hV]; exact mem_image_of_mem _ hx rw [pe_eq_sum_sq _ V hUV, pe_eq_sum_sq _ V hSV, pe_eq_sum_sq _ V hTV, mul_sum, mul_sum, ← sum_add_distrib] apply sum_le_sum intro u _ have h1 : (cnt (S ∪ T) u : ℝ) ≤ cnt S u + cnt T u := by exact_mod_cast cnt_union_le S T u have h0 : (0 : ℝ) ≤ cnt (S ∪ T) u := by positivity calc (cnt (S ∪ T) u : ℝ) ^ 2 ≤ ((cnt S u : ℝ) + cnt T u) ^ 2 := pow_le_pow_left₀ h0 h1 2 _ ≤ (1 + l) * (cnt S u : ℝ) ^ 2 + (1 + 1 / l) * (cnt T u : ℝ) ^ 2 := sq_add_le_lam hl /-- Cauchy–Schwarz over a family: `pe(⋃_t X_t) ≤ |T| Σ_t pe(X_t)`. -/ theorem pe_biUnion_le {ι : Type*} [DecidableEq ι] (T : Finset ι) (X : ι → Finset (ℂ × ℂ)) : (pe (T.biUnion X) (T.biUnion X) : ℝ) ≤ T.card * ∑ t ∈ T, (pe (X t) (X t) : ℝ) := by classical obtain ⟨V, hV⟩ : ∃ V : Finset ℝ, V = (T.biUnion X).image (fun x => dist x.1 x.2) := ⟨_, rfl⟩ have hUV : ∀ x ∈ T.biUnion X, dist x.1 x.2 ∈ V := fun x hx => by rw [hV]; exact mem_image_of_mem _ hx have hXV : ∀ t ∈ T, ∀ x ∈ X t, dist x.1 x.2 ∈ V := fun t ht x hx => hUV x (mem_biUnion.mpr ⟨t, ht, hx⟩) rw [pe_eq_sum_sq _ V hUV] rw [sum_congr rfl (fun t ht => pe_eq_sum_sq (X t) V (hXV t ht)), sum_comm, mul_sum] apply sum_le_sum intro u _ have hc : (cnt (T.biUnion X) u : ℝ) ≤ ∑ t ∈ T, (cnt (X t) u : ℝ) := by have : cnt (T.biUnion X) u ≤ ∑ t ∈ T, cnt (X t) u := by unfold cnt rw [filter_biUnion] exact card_biUnion_le exact_mod_cast this have h0 : (0 : ℝ) ≤ cnt (T.biUnion X) u := by positivity calc (cnt (T.biUnion X) u : ℝ) ^ 2 ≤ (∑ t ∈ T, (cnt (X t) u : ℝ)) ^ 2 := pow_le_pow_left₀ h0 hc 2 _ ≤ T.card * ∑ t ∈ T, (cnt (X t) u : ℝ) ^ 2 := sq_sum_le_card_mul_sum_sq /-- On a circle every point has at most two partners at a given distance: `cnt(Q°, u) ≤ 2|Q|`. -/ theorem cnt_offDiag_circle_le' {Q : Finset ℂ} {O : ℂ} {ρ : ℝ} (hρ : 0 < ρ) (hQ : ∀ q ∈ Q, ‖q - O‖ = ρ) (u : ℝ) : cnt Q.offDiag u ≤ 2 * Q.card := by classical unfold cnt have hsub : Q.offDiag.filter (fun y => dist y.1 y.2 = u) ⊆ Q.biUnion (fun x => (Q.filter (fun z => dist x z = u)).image (fun z => (x, z))) := by intro y hy rw [mem_filter, mem_offDiag] at hy exact mem_biUnion.mpr ⟨y.1, hy.1.1, mem_image.mpr ⟨y.2, mem_filter.mpr ⟨hy.1.2.1, hy.2⟩, rfl⟩⟩ calc (Q.offDiag.filter (fun y => dist y.1 y.2 = u)).card ≤ _ := card_le_card hsub _ ≤ ∑ x ∈ Q, ((Q.filter (fun z => dist x z = u)).image (fun z => (x, z))).card := card_biUnion_le _ ≤ ∑ _x ∈ Q, 2 := by apply sum_le_sum intro x hx have hxO : x ≠ O := by intro h have := hQ x hx rw [h, sub_self, norm_zero] at this linarith exact le_trans card_image_le (card_circle_dist_le_two hQ hxO u) _ = 2 * Q.card := by rw [sum_const, smul_eq_mul, mul_comm] open Classical in /-- **GLIDE Theorem 9.5, energy accounting (direct form).** Let `Q_i` (`i < k`) lie on circles `C(c_i, ρ_i)` with pairwise distinct centres and positive radii, `|Q_i| ≤ M`, `Σ|Q_i| ≤ N`, and `U = ⋃ Q_i`. Then for every `λ > 0` and integer `G ≥ 1` `4 S(U) = pe(U°, U°) ≤ (1 + λ)·2MN² + (1 + 1/λ)·k⁴·(52N² + 8N³/G + 4(2G + 1)²N²)`. (Same-circle classes have at most `2|Q_i|` ordered pairs from each circle, so the same-circle energy is `≤ 2MN²`; cross energies are `O(N^{8/3})` by Lemma 11.9.) Consequently `S(U) ≤ M N²/2 + o(N³)`: the paper's deficit `½ Σ_{i (Q i).offDiag) := ⟨_, rfl⟩ obtain ⟨T, hT⟩ : ∃ S : Finset (Fin k × Fin k), S = (univ : Finset (Fin k)).offDiag := ⟨_, rfl⟩ obtain ⟨X, hX⟩ : ∃ S : Finset (ℂ × ℂ), S = T.biUnion (fun ij => Q ij.1 ×ˢ Q ij.2) := ⟨_, rfl⟩ obtain ⟨bd, hbd⟩ : ∃ x : ℝ, x = 52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2 := ⟨_, rfl⟩ rw [← hbd] have hcard0 : ∀ i, (0 : ℝ) ≤ (Q i).card := fun i => by positivity have hQN : ∀ i, ((Q i).card : ℝ) ≤ N := by intro i calc ((Q i).card : ℝ) ≤ ∑ j, ((Q j).card : ℝ) := single_le_sum (fun j _ => hcard0 j) (mem_univ i) _ ≤ N := hN have hN0 : 0 ≤ N := le_trans (sum_nonneg (fun j _ => hcard0 j)) hN have hG0 : (0 : ℝ) < G := by exact_mod_cast hG have hbd0 : 0 ≤ bd := by rw [hbd]; positivity have hcov : (univ.biUnion Q).offDiag ⊆ D ∪ X := by intro p hp rw [mem_offDiag] at hp obtain ⟨h1, h2, h12⟩ := hp rw [mem_biUnion] at h1 h2 obtain ⟨i, _, hi⟩ := h1 obtain ⟨j, _, hj⟩ := h2 by_cases hij : i = j · rw [← hij] at hj exact mem_union_left _ (by rw [hD, mem_biUnion]; exact ⟨i, mem_univ _, mem_offDiag.mpr ⟨hi, hj, h12⟩⟩) · exact mem_union_right _ (by rw [hX, mem_biUnion] exact ⟨(i, j), by rw [hT]; exact mem_offDiag.mpr ⟨mem_univ _, mem_univ _, hij⟩, mem_product.mpr ⟨hi, hj⟩⟩) -- same-circle part have hcntD : ∀ u, (cnt D u : ℝ) ≤ 2 * N := by intro u have h1 : cnt D u ≤ ∑ i, cnt (Q i).offDiag u := by unfold cnt rw [hD, filter_biUnion] exact card_biUnion_le have h2 : ∀ i, cnt (Q i).offDiag u ≤ 2 * (Q i).card := fun i => cnt_offDiag_circle_le' (hρ i) (hQ i) u have h3 : (cnt D u : ℝ) ≤ ∑ i, (2 * ((Q i).card : ℝ)) := by have : cnt D u ≤ ∑ i, 2 * (Q i).card := le_trans h1 (sum_le_sum (fun i _ => h2 i)) exact_mod_cast this rw [← mul_sum] at h3 linarith have hDc : (D.card : ℝ) ≤ M * N := by have h1 : D.card ≤ ∑ i, (Q i).offDiag.card := by rw [hD]; exact card_biUnion_le have h2 : (D.card : ℝ) ≤ ∑ i, ((Q i).card : ℝ) * (Q i).card := by have : D.card ≤ ∑ i, (Q i).card * (Q i).card := by refine le_trans h1 (sum_le_sum (fun i _ => ?_)) rw [offDiag_card] exact Nat.sub_le _ _ exact_mod_cast this have h3 : ∑ i, ((Q i).card : ℝ) * (Q i).card ≤ ∑ i, M * (Q i).card := sum_le_sum (fun i _ => mul_le_mul_of_nonneg_right (hM i) (hcard0 i)) rw [← mul_sum] at h3 have h4 : M * ∑ i, ((Q i).card : ℝ) ≤ M * N := mul_le_mul_of_nonneg_left hN hM0 linarith have hpeD : (pe D D : ℝ) ≤ 2 * M * N ^ 2 := by rw [pe_eq_sum_cnt] push_cast calc ∑ x ∈ D, (cnt D (dist x.1 x.2) : ℝ) ≤ ∑ _x ∈ D, 2 * N := sum_le_sum (fun x _ => hcntD _) _ = D.card * (2 * N) := by rw [sum_const, nsmul_eq_mul] _ ≤ (M * N) * (2 * N) := mul_le_mul_of_nonneg_right hDc (by linarith) _ = 2 * M * N ^ 2 := by ring -- cross part have hterm : ∀ ij ∈ T, (pe (Q ij.1 ×ˢ Q ij.2) (Q ij.1 ×ˢ Q ij.2) : ℝ) ≤ bd := by intro ij hij rw [hT, mem_offDiag] at hij have hne : c ij.1 ≠ c ij.2 := fun h => hij.2.2 (hc h) have h := lemma119 hne (hρ ij.1) (hρ ij.2) (hQ ij.1) (hQ ij.2) G hG obtain ⟨a, ha⟩ : ∃ x : ℝ, x = (Q ij.1).card := ⟨_, rfl⟩ obtain ⟨b, hb⟩ : ∃ x : ℝ, x = (Q ij.2).card := ⟨_, rfl⟩ rw [← ha, ← hb] at h have haN : a ≤ N := by rw [ha]; exact hQN _ have hbN : b ≤ N := by rw [hb]; exact hQN _ have ha0 : 0 ≤ a := by rw [ha]; exact hcard0 _ have hb0 : 0 ≤ b := by rw [hb]; exact hcard0 _ have h1 : a * b ≤ N ^ 2 := by nlinarith have h2 : (a + b) ^ 2 ≤ 4 * N ^ 2 := by nlinarith have h3 : a ^ 2 ≤ N ^ 2 := by nlinarith have h4 : a ^ 2 * b ≤ N ^ 3 := by have := mul_le_mul h3 hbN hb0 (sq_nonneg N) nlinarith have h5 : 8 * (a ^ 2 * b) / G ≤ 8 * N ^ 3 / G := div_le_div_of_nonneg_right (by linarith) hG0.le have h6 : b ^ 2 * (2 * G + 1) ^ 2 ≤ N ^ 2 * (2 * G + 1) ^ 2 := mul_le_mul_of_nonneg_right (by nlinarith) (sq_nonneg _) have e : a ^ 2 * (12 + 8 * b / G) = 12 * a ^ 2 + 8 * (a ^ 2 * b) / G := by field_simp rw [e] at h rw [hbd] nlinarith have hTc : (T.card : ℝ) ≤ (k : ℝ) ^ 2 := by rw [hT, offDiag_card, card_univ, Fintype.card_fin] have : k * k - k ≤ k ^ 2 := by rw [sq]; exact Nat.sub_le _ _ exact_mod_cast this have hpeX : (pe X X : ℝ) ≤ (k : ℝ) ^ 4 * bd := by rw [hX] have h1 := pe_biUnion_le T (fun ij => Q ij.1 ×ˢ Q ij.2) have hsum : ∑ ij ∈ T, (pe (Q ij.1 ×ˢ Q ij.2) (Q ij.1 ×ˢ Q ij.2) : ℝ) ≤ T.card * bd := by calc ∑ ij ∈ T, (pe (Q ij.1 ×ˢ Q ij.2) (Q ij.1 ×ˢ Q ij.2) : ℝ) ≤ ∑ _ij ∈ T, bd := sum_le_sum hterm _ = T.card * bd := by rw [sum_const, nsmul_eq_mul] have hT0 : (0 : ℝ) ≤ T.card := by positivity calc (pe (T.biUnion (fun ij => Q ij.1 ×ˢ Q ij.2)) (T.biUnion (fun ij => Q ij.1 ×ˢ Q ij.2)) : ℝ) ≤ T.card * ∑ ij ∈ T, (pe (Q ij.1 ×ˢ Q ij.2) (Q ij.1 ×ˢ Q ij.2) : ℝ) := h1 _ ≤ T.card * (T.card * bd) := mul_le_mul_of_nonneg_left hsum hT0 _ ≤ (k : ℝ) ^ 2 * ((k : ℝ) ^ 2 * bd) := by have := mul_le_mul_of_nonneg_right hTc hbd0 have h2 : (T.card : ℝ) * (T.card * bd) ≤ (k : ℝ) ^ 2 * (T.card * bd) := mul_le_mul_of_nonneg_right hTc (mul_nonneg hT0 hbd0) have h3 : (k : ℝ) ^ 2 * (T.card * bd) ≤ (k : ℝ) ^ 2 * ((k : ℝ) ^ 2 * bd) := mul_le_mul_of_nonneg_left this (by positivity) linarith _ = (k : ℝ) ^ 4 * bd := by ring have hmono : (pe (univ.biUnion Q).offDiag (univ.biUnion Q).offDiag : ℝ) ≤ pe (D ∪ X) (D ∪ X) := by exact_mod_cast le_trans (pe_mono_left hcov _) (pe_mono_right _ hcov) have hl1 : 0 ≤ 1 + 1 / l := by positivity calc (pe (univ.biUnion Q).offDiag (univ.biUnion Q).offDiag : ℝ) ≤ pe (D ∪ X) (D ∪ X) := hmono _ ≤ (1 + l) * pe D D + (1 + 1 / l) * pe X X := pe_union_le_lam D X hl _ ≤ (1 + l) * (2 * M * N ^ 2) + (1 + 1 / l) * ((k : ℝ) ^ 4 * bd) := by have := mul_le_mul_of_nonneg_left hpeD (by linarith : (0 : ℝ) ≤ 1 + l) have := mul_le_mul_of_nonneg_left hpeX hl1 linarith _ = (1 + l) * (2 * M * N ^ 2) + (1 + 1 / l) * (k : ℝ) ^ 4 * bd := by ring end Erdos94ThmA /-! ### GLIDE Corollary 9.6 (near a family of circles with distinct centres ⇒ `S ≤ R`) -/ namespace Erdos94ThmA open Finset open Classical in /-- The points of `P` assigned to circle `i`: on `C(c_i, ρ_i)` and on no circle of smaller index. -/ noncomputable def famQ (P : Finset ℂ) {k : ℕ} (c : Fin k → ℂ) (ρ : Fin k → ℝ) (i : Fin k) : Finset ℂ := P.filter (fun z => ‖z - c i‖ = ρ i ∧ ∀ j : Fin k, j < i → ‖z - c j‖ ≠ ρ j) theorem famQ_on (P : Finset ℂ) {k : ℕ} (c : Fin k → ℂ) (ρ : Fin k → ℝ) (i : Fin k) : ∀ q ∈ famQ P c ρ i, ‖q - c i‖ = ρ i := by intro q hq rw [famQ, mem_filter] at hq exact hq.2.1 theorem famQ_sub (P : Finset ℂ) {k : ℕ} (c : Fin k → ℂ) (ρ : Fin k → ℝ) (i : Fin k) : famQ P c ρ i ⊆ P.filter (fun z => ‖z - c i‖ = ρ i) := by intro q hq rw [famQ, mem_filter] at hq exact mem_filter.mpr ⟨hq.1, hq.2.1⟩ theorem famQ_disj (P : Finset ℂ) {k : ℕ} (c : Fin k → ℂ) (ρ : Fin k → ℝ) : ((univ : Finset (Fin k)) : Set (Fin k)).PairwiseDisjoint (famQ P c ρ) := by intro i _ j _ hij rw [Function.onFun, disjoint_left] intro z hi hj rw [famQ, mem_filter] at hi hj rcases lt_or_gt_of_ne hij with h | h · exact hj.2.2 i h hi.2.1 · exact hi.2.2 j h hj.2.1 theorem famQ_sum (P : Finset ℂ) {k : ℕ} (c : Fin k → ℂ) (ρ : Fin k → ℝ) : ∑ i, (famQ P c ρ i).card ≤ P.card := by rw [← card_biUnion (famQ_disj P c ρ)] apply card_le_card intro z hz rw [mem_biUnion] at hz obtain ⟨i, _, hz⟩ := hz rw [famQ, mem_filter] at hz exact hz.1 open Classical in /-- A point of `P` on some circle of the family lies in some `famQ`. -/ theorem mem_famQ_of (P : Finset ℂ) {k : ℕ} (c : Fin k → ℂ) (ρ : Fin k → ℝ) {z : ℂ} (hz : z ∈ P) (h : ∃ i, ‖z - c i‖ = ρ i) : z ∈ univ.biUnion (famQ P c ρ) := by have hS : (univ.filter (fun i : Fin k => ‖z - c i‖ = ρ i)).Nonempty := by obtain ⟨i, hi⟩ := h exact ⟨i, mem_filter.mpr ⟨mem_univ _, hi⟩⟩ obtain ⟨i, hi⟩ : ∃ i, i = (univ.filter (fun i : Fin k => ‖z - c i‖ = ρ i)).min' hS := ⟨_, rfl⟩ have hmem : i ∈ univ.filter (fun i : Fin k => ‖z - c i‖ = ρ i) := by rw [hi]; exact min'_mem _ _ rw [mem_biUnion] refine ⟨i, mem_univ _, ?_⟩ rw [famQ, mem_filter] refine ⟨hz, (mem_filter.mp hmem).2, fun j hj hjz => ?_⟩ have : i ≤ j := by rw [hi] exact min'_le (univ.filter (fun i : Fin k => ‖z - c i‖ = ρ i)) j (mem_filter.mpr ⟨mem_univ j, hjz⟩) exact absurd hj (not_lt.mpr this) open Classical in /-- From a point `y` a circle family is seen at distance `u` at most `2` times per circle not centred at `y`: `#{(y, z) ∈ Y × ⋃Q_i : |yz| = u} ≤ 2k|Y| + Σ|Q_i|`. -/ theorem fam_cnt_le {k : ℕ} (c : Fin k → ℂ) (ρ : Fin k → ℝ) (Q : Fin k → Finset ℂ) (hQ : ∀ i, ∀ q ∈ Q i, ‖q - c i‖ = ρ i) (Y : Finset ℂ) (u : ℝ) : cnt (Y ×ˢ univ.biUnion Q) u ≤ 2 * k * Y.card + ∑ i, (Q i).card := by unfold cnt have hsub : (Y ×ˢ univ.biUnion Q).filter (fun p => dist p.1 p.2 = u) ⊆ Y.biUnion (fun y => univ.biUnion (fun i => ((Q i).filter (fun z => dist y z = u)).image (fun z => (y, z)))) := by intro p hp rw [mem_filter, mem_product, mem_biUnion] at hp obtain ⟨⟨hy, i, _, hz⟩, hd⟩ := hp rw [mem_biUnion] refine ⟨p.1, hy, mem_biUnion.mpr ⟨i, mem_univ _, mem_image.mpr ⟨p.2, mem_filter.mpr ⟨hz, hd⟩, rfl⟩⟩⟩ have hterm : ∀ y, ∀ i, ((Q i).filter (fun z => dist y z = u)).card ≤ 2 + (if y = c i then (Q i).card else 0) := by intro y i by_cases h : y = c i · rw [ite_eq_left_iff.mpr (fun h' => absurd h h')] exact le_trans (card_filter_le _ _) (Nat.le_add_left _ _) · rw [ite_eq_right_iff.mpr (fun h' => absurd h' h), add_zero] exact card_circle_dist_le_two (hQ i) h u calc ((Y ×ˢ univ.biUnion Q).filter (fun p => dist p.1 p.2 = u)).card ≤ _ := card_le_card hsub _ ≤ ∑ y ∈ Y, (univ.biUnion (fun i => ((Q i).filter (fun z => dist y z = u)).image (fun z => (y, z)))).card := card_biUnion_le _ ≤ ∑ y ∈ Y, ∑ i, (2 + (if y = c i then (Q i).card else 0)) := by apply sum_le_sum intro y _ calc (univ.biUnion (fun i => ((Q i).filter (fun z => dist y z = u)).image (fun z => (y, z)))).card ≤ ∑ i, (((Q i).filter (fun z => dist y z = u)).image (fun z => (y, z))).card := card_biUnion_le _ ≤ ∑ i, (2 + (if y = c i then (Q i).card else 0)) := sum_le_sum (fun i _ => le_trans card_image_le (hterm y i)) _ = ∑ y ∈ Y, (2 * k + ∑ i, (if y = c i then (Q i).card else 0)) := by refine sum_congr rfl (fun y _ => ?_) rw [sum_add_distrib, sum_const, card_univ, Fintype.card_fin, smul_eq_mul] ring _ = 2 * k * Y.card + ∑ y ∈ Y, ∑ i, (if y = c i then (Q i).card else 0) := by rw [sum_add_distrib, sum_const, smul_eq_mul] ring _ = 2 * k * Y.card + ∑ i, ∑ y ∈ Y, (if y = c i then (Q i).card else 0) := by rw [sum_comm] _ ≤ 2 * k * Y.card + ∑ i, (Q i).card := by apply Nat.add_le_add_left apply sum_le_sum intro i _ rw [sum_ite_eq'] split_ifs <;> simp theorem cor96_t1 {n : ℝ} (hn : 0 ≤ n) : (1 + 1 / 100000) * (2 * (n - n / 50000) * n ^ 2) ≤ (2 - 2 / 100000) * n ^ 3 := by have hn3 : 0 ≤ n ^ 3 := by positivity have e : (1 + 1 / 100000) * (2 * (n - n / 50000) * n ^ 2) = (2 - 2 / 100000 - 4 / 10 ^ 10) * n ^ 3 := by ring rw [e] nlinarith theorem cor96_t2 {n kk G : ℝ} (hn : 0 ≤ n) (hk0 : 0 ≤ kk) (hG : G = 2 * 10 ^ 11 * kk ^ 4 + 1) : (1 + 1 / (1 / 100000)) * kk ^ 4 * (8 * n ^ 3 / G) ≤ n ^ 3 / 200000 := by have e1 : (1 + 1 / (1 / 100000) : ℝ) = 100001 := by norm_num rw [e1] have hk40 : 0 ≤ kk ^ 4 := by positivity have hG0 : 0 < G := by rw [hG]; positivity have hn3 : 0 ≤ n ^ 3 := by positivity have hkey : 800008 * kk ^ 4 * 200000 ≤ G := by rw [hG]; linarith rw [show (100001 : ℝ) * kk ^ 4 * (8 * n ^ 3 / G) = 800008 * kk ^ 4 * n ^ 3 / G by ring, div_le_div_iff₀ hG0 (by norm_num)] have := mul_le_mul_of_nonneg_right hkey hn3 linarith theorem cor96_t3a {kk G K4 : ℝ} (hk0 : 0 ≤ kk) (hG : G = 2 * 10 ^ 11 * kk ^ 4 + 1) (hK4 : 1 ≤ K4) (hk4 : kk ^ 4 ≤ K4) : 52 + 4 * (2 * G + 1) ^ 2 ≤ 2 * 10 ^ 24 * K4 ^ 2 := by have h1 : 2 * G + 1 ≤ 5 * 10 ^ 11 * K4 := by rw [hG]; linarith have h0 : 0 ≤ 2 * G + 1 := by rw [hG]; positivity have h2 : (2 * G + 1) ^ 2 ≤ (5 * 10 ^ 11 * K4) ^ 2 := pow_le_pow_left₀ h0 h1 2 have h3 : (1 : ℝ) ≤ K4 ^ 2 := one_le_pow₀ hK4 have e : (5 * 10 ^ 11 * K4) ^ 2 = 25 * 10 ^ 22 * K4 ^ 2 := by ring rw [e] at h2 linarith theorem cor96_t3 {n kk G K4 : ℝ} (hk0 : 0 ≤ kk) (hG : G = 2 * 10 ^ 11 * kk ^ 4 + 1) (hK4 : 1 ≤ K4) (hk4 : kk ^ 4 ≤ K4) (hn : 10 ^ 40 * K4 ^ 3 ≤ n) : (1 + 1 / (1 / 100000)) * kk ^ 4 * (52 * n ^ 2 + 4 * (2 * G + 1) ^ 2 * n ^ 2) ≤ n ^ 3 / 1000000 := by have e1 : (1 + 1 / (1 / 100000) : ℝ) = 100001 := by norm_num rw [e1] have hA := cor96_t3a hk0 hG hK4 hk4 have hA0 : 0 ≤ 52 + 4 * (2 * G + 1) ^ 2 := by positivity have hk40 : 0 ≤ kk ^ 4 := by positivity have hB : kk ^ 4 * (52 + 4 * (2 * G + 1) ^ 2) ≤ K4 * (2 * 10 ^ 24 * K4 ^ 2) := mul_le_mul hk4 hA hA0 (by positivity) have e2 : K4 * (2 * 10 ^ 24 * K4 ^ 2) = 2 * 10 ^ 24 * K4 ^ 3 := by ring rw [e2] at hB have hC : 100001 * kk ^ 4 * (52 + 4 * (2 * G + 1) ^ 2) ≤ n / 1000000 := by have : 100001 * (kk ^ 4 * (52 + 4 * (2 * G + 1) ^ 2)) ≤ 100001 * (2 * 10 ^ 24 * K4 ^ 3) := mul_le_mul_of_nonneg_left hB (by norm_num) have hK3 : 0 ≤ K4 ^ 3 := by positivity rw [le_div_iff₀ (by norm_num : (0 : ℝ) < 1000000)] nlinarith have hn2 : 0 ≤ n ^ 2 := sq_nonneg n have e3 : 100001 * kk ^ 4 * (52 * n ^ 2 + 4 * (2 * G + 1) ^ 2 * n ^ 2) = (100001 * kk ^ 4 * (52 + 4 * (2 * G + 1) ^ 2)) * n ^ 2 := by ring rw [e3] have := mul_le_mul_of_nonneg_right hC hn2 have e4 : n / 1000000 * n ^ 2 = n ^ 3 / 1000000 := by ring linarith theorem cor96_t4 {n e kk : ℝ} (hk0 : 0 ≤ kk) (he : e ≤ n / (200000 * (28 * kk + 20))) : (28 * kk + 20) * e * n ^ 2 ≤ n ^ 3 / 200000 := by have h28 : 0 < 28 * kk + 20 := by linarith have h1 : (28 * kk + 20) * e ≤ n / 200000 := by have h2 : (28 * kk + 20) * e ≤ (28 * kk + 20) * (n / (200000 * (28 * kk + 20))) := mul_le_mul_of_nonneg_left he h28.le have e2 : (28 * kk + 20) * (n / (200000 * (28 * kk + 20))) = n / 200000 := by field_simp linarith have := mul_le_mul_of_nonneg_right h1 (sq_nonneg n) have e3 : n / 200000 * n ^ 2 = n ^ 3 / 200000 := by ring linarith theorem cor96_t5 {n : ℝ} (hn : 3000000 ≤ n) : 3 * n ^ 2 ≤ n ^ 3 / 1000000 := by have h1 : 3 ≤ n / 1000000 := by rw [le_div_iff₀ (by norm_num)]; linarith have := mul_le_mul_of_nonneg_right h1 (sq_nonneg n) have e : n / 1000000 * n ^ 2 = n ^ 3 / 1000000 := by ring linarith /-- The arithmetic of Corollary 9.6 (case "no circle carries all but `n/50000` points"). -/ theorem cor96_arith {n e kk G pU X1 X2 X3 X4 : ℝ} (hk0 : 0 ≤ kk) (hn : (10 : ℝ) ^ 40 * (kk + 1) ^ 12 ≤ n) (he0 : 0 ≤ e) (he : e ≤ n / (200000 * (28 * kk + 20))) (hG : G = 2 * 10 ^ 11 * kk ^ 4 + 1) (hU : pU ≤ (1 + 1 / 100000) * (2 * (n - n / 50000) * n ^ 2) + (1 + 1 / (1 / 100000)) * kk ^ 4 * (52 * n ^ 2 + 8 * n ^ 3 / G + 4 * (2 * G + 1) ^ 2 * n ^ 2)) (hE : 4 * X1 + 2 * X2 + 8 * X3 + 2 * X4 ≤ (28 * kk + 20) * e * n ^ 2) : pU + 4 * X1 + 2 * X2 + 8 * X3 + 2 * X4 ≤ 2 * n ^ 3 - 3 * n ^ 2 := by have hK1 : (1 : ℝ) ≤ kk + 1 := by linarith have hK4 : (1 : ℝ) ≤ (kk + 1) ^ 4 := one_le_pow₀ hK1 have hk4 : kk ^ 4 ≤ (kk + 1) ^ 4 := pow_le_pow_left₀ hk0 (by linarith) 4 have hn' : 10 ^ 40 * ((kk + 1) ^ 4) ^ 3 ≤ n := by have e : ((kk + 1) ^ 4) ^ 3 = (kk + 1) ^ 12 := by ring rw [e] exact hn have hK12 : (1 : ℝ) ≤ ((kk + 1) ^ 4) ^ 3 := one_le_pow₀ hK4 have hn1 : (3000000 : ℝ) ≤ n := by nlinarith have hn0 : 0 ≤ n := by linarith have t1 := cor96_t1 hn0 have t2 := cor96_t2 hn0 hk0 hG have t3 := cor96_t3 hk0 hG hK4 hk4 hn' have t4 := cor96_t4 (e := e) hk0 he have t5 := cor96_t5 hn1 have hsplit : (1 + 1 / (1 / 100000)) * kk ^ 4 * (52 * n ^ 2 + 8 * n ^ 3 / G + 4 * (2 * G + 1) ^ 2 * n ^ 2) = (1 + 1 / (1 / 100000)) * kk ^ 4 * (8 * n ^ 3 / G) + (1 + 1 / (1 / 100000)) * kk ^ 4 * (52 * n ^ 2 + 4 * (2 * G + 1) ^ 2 * n ^ 2) := by ring rw [hsplit] at hU have hn3 : 0 ≤ n ^ 3 := by positivity linarith /-- The outlier terms of Corollary 9.6: `4X₁ + 2X₂ + 8X₃ + 2X₄ ≤ (28k + 20)|E| n²`. -/ theorem cor96_Eterms {n e uu kk X1 X2 X3 X4 : ℝ} (he0 : 0 ≤ e) (heN : e ≤ n) (hu0 : 0 ≤ uu) (huN : uu ≤ n) (hk0 : 0 ≤ kk) (h1 : X1 ≤ e * uu * (2 * kk * n + n)) (h2 : X2 ≤ e * e * (2 * kk * n + n)) (h3 : X3 ≤ e * uu * (2 * kk * e + n)) (h4 : X4 ≤ 3 * e * (e * e)) : 4 * X1 + 2 * X2 + 8 * X3 + 2 * X4 ≤ (28 * kk + 20) * e * n ^ 2 := by have hn0 : 0 ≤ n := le_trans he0 heN have h0 : 0 ≤ 2 * kk * n + n := by positivity have a1 : e * uu * (2 * kk * n + n) ≤ e * n * (2 * kk * n + n) := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left huN he0) h0 have a2 : e * e * (2 * kk * n + n) ≤ e * n * (2 * kk * n + n) := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left heN he0) h0 have a3 : e * uu * (2 * kk * e + n) ≤ e * n * (2 * kk * n + n) := by have hke : 2 * kk * e ≤ 2 * kk * n := mul_le_mul_of_nonneg_left heN (by positivity) exact mul_le_mul (mul_le_mul_of_nonneg_left huN he0) (by linarith) (by positivity) (by positivity) have a4 : 3 * e * (e * e) ≤ 3 * e * (n * n) := mul_le_mul_of_nonneg_left (mul_le_mul heN heN he0 hn0) (by positivity) have e1 : e * n * (2 * kk * n + n) = 2 * kk * e * n ^ 2 + e * n ^ 2 := by ring have e2 : 3 * e * (n * n) = 3 * e * n ^ 2 := by ring have e3 : (28 * kk + 20) * e * n ^ 2 = 28 * kk * e * n ^ 2 + 20 * e * n ^ 2 := by ring linarith open Classical in /-- **GLIDE Corollary 9.6 (near a circle family) in ℂ.** Let `P` be convex independent, `|P| = n`, and let `C(c_i, ρ_i)` (`i < k`) be circles with pairwise distinct centres and positive radii such that all but `n/(200000(28k + 20))` points of `P` lie on their union. If `n ≥ 10⁴⁰(k + 1)¹²` then `pairEnergy(P) = pe(P°, P°) ≤ 4R(n)`, i.e. `S(P) ≤ R(n)`. (Either one circle carries all but `n/50000` points — Prop. C — or every circle misses `> n/50000` points and the direct accounting of Theorem 9.5 gives `S(P) ≤ (1 − 2·10⁻⁵)n³/2 + O(kκn³) + O(k⁴ n^{8/3})`.) -/ theorem cor96_C (P : Finset ℂ) (hP : ∀ z ∈ P, z ∉ convexHull ℝ ((P : Set ℂ) \ {z})) {k : ℕ} (c : Fin k → ℂ) (hc : Function.Injective c) (ρ : Fin k → ℝ) (hρ : ∀ i, 0 < ρ i) (hn : (10 : ℝ) ^ 40 * ((k : ℝ) + 1) ^ 12 ≤ P.card) (hE : ((P.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i)).card : ℝ) ≤ P.card / (200000 * (28 * k + 20))) : (pe P.offDiag P.offDiag : ℝ) ≤ 4 * Erdos94Infra.ngonValue P.card := by have hK1 : (1 : ℝ) ≤ (k : ℝ) + 1 := by have : (0 : ℝ) ≤ k := Nat.cast_nonneg k; linarith have hn1 : (10 : ℝ) ^ 40 ≤ P.card := by have : (1 : ℝ) ≤ ((k : ℝ) + 1) ^ 12 := one_le_pow₀ hK1 have h2 : (10 : ℝ) ^ 40 * 1 ≤ 10 ^ 40 * ((k : ℝ) + 1) ^ 12 := mul_le_mul_of_nonneg_left this (by norm_num) linarith by_cases hA : ∃ i, ((P.filter (fun z => ‖z - c i‖ ≠ ρ i)).card : ℝ) ≤ P.card / 50000 · obtain ⟨i, hi⟩ := hA have hn' : 161000 ≤ P.card := by have : (161000 : ℝ) ≤ P.card := by linarith exact_mod_cast this exact propC_C P hP hn' (c i) (hρ i) hi · push Not at hA obtain ⟨Q, hQdef⟩ : ∃ Q, Q = famQ P c ρ := ⟨_, rfl⟩ obtain ⟨U, hUdef⟩ : ∃ U, U = univ.biUnion Q := ⟨_, rfl⟩ obtain ⟨E, hEdef⟩ : ∃ E, E = P \ U := ⟨_, rfl⟩ have hQ : ∀ i, ∀ q ∈ Q i, ‖q - c i‖ = ρ i := by rw [hQdef]; exact famQ_on P c ρ have hUP : U ⊆ P := by intro z hz rw [hUdef, mem_biUnion] at hz obtain ⟨i, _, hz⟩ := hz rw [hQdef, famQ, mem_filter] at hz exact hz.1 have hUE : Disjoint U E := by rw [hEdef]; exact disjoint_sdiff have hUEP : U ∪ E = P := by rw [hEdef]; exact union_sdiff_of_subset hUP have hEP : E ⊆ P := by rw [hEdef]; exact sdiff_subset have hEfil : E ⊆ P.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i) := by intro z hz rw [hEdef, mem_sdiff] at hz rw [mem_filter] refine ⟨hz.1, fun i hi => hz.2 ?_⟩ rw [hUdef, hQdef] exact mem_famQ_of P c ρ hz.1 ⟨i, hi⟩ have hEc : (E.card : ℝ) ≤ P.card / (200000 * (28 * k + 20)) := le_trans (by exact_mod_cast card_le_card hEfil) hE have hEconv : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a}) := fun a ha h => hP a (hEP ha) (convexHull_mono (Set.sdiff_subset_sdiff_left (coe_subset.mpr hEP)) h) -- the circle bound have hM : ∀ i, ((Q i).card : ℝ) ≤ P.card - P.card / 50000 := by intro i have h1 : (Q i).card ≤ (P.filter (fun z => ‖z - c i‖ = ρ i)).card := by rw [hQdef]; exact card_le_card (famQ_sub P c ρ i) have h2 := card_filter_add_card_filter_not (s := P) (fun z => ‖z - c i‖ = ρ i) have h3 := hA i have h4 : ((P.filter (fun z => ‖z - c i‖ = ρ i)).card : ℝ) + (P.filter (fun z => ¬ ‖z - c i‖ = ρ i)).card = P.card := by exact_mod_cast h2 have h5 : ((Q i).card : ℝ) ≤ (P.filter (fun z => ‖z - c i‖ = ρ i)).card := by exact_mod_cast h1 simp only [ne_eq] at h3 linarith have hNs : ∑ i, (Q i).card ≤ P.card := by rw [hQdef]; exact famQ_sum P c ρ have hN : ∑ i, ((Q i).card : ℝ) ≤ P.card := by exact_mod_cast hNs have hM0 : (0 : ℝ) ≤ P.card - P.card / 50000 := by have : (0 : ℝ) ≤ P.card := Nat.cast_nonneg _ linarith obtain ⟨G, hG⟩ : ∃ g : ℕ, g = 2 * 10 ^ 11 * k ^ 4 + 1 := ⟨_, rfl⟩ have hG1 : 1 ≤ G := by rw [hG]; omega have hGR : (G : ℝ) = 2 * 10 ^ 11 * (k : ℝ) ^ 4 + 1 := by rw [hG]; push_cast; ring have h95 := thm95 c hc ρ hρ Q hQ hM0 hM hN (l := 1 / 100000) (by norm_num) G hG1 rw [← hUdef] at h95 -- decomposition have hdec := pe_decomp U E hUE rw [hUEP] at hdec have hdecR : (pe P.offDiag P.offDiag : ℝ) ≤ pe U.offDiag U.offDiag + 4 * pe (E ×ˢ U) U.offDiag + 2 * pe E.offDiag U.offDiag + 8 * pe (E ×ˢ U) (E ×ˢ U) + 2 * pe E.offDiag E.offDiag := by exact_mod_cast hdec -- E-term bounds have hUc : U.card ≤ P.card := card_le_card hUP have hEn : E.card ≤ P.card := card_le_card hEP have hcntU : ∀ u, cnt U.offDiag u ≤ 2 * k * P.card + P.card := by intro u have h1 : cnt U.offDiag u ≤ cnt (U ×ˢ U) u := by unfold cnt exact card_le_card (filter_subset_filter _ (fun p hp => by rw [mem_offDiag] at hp exact mem_product.mpr ⟨hp.1, hp.2.1⟩)) have h2 := fam_cnt_le c ρ Q hQ U u rw [← hUdef] at h2 have h3 : 2 * k * U.card ≤ 2 * k * P.card := Nat.mul_le_mul_left _ hUc omega have hcntEU : ∀ u, cnt (E ×ˢ U) u ≤ 2 * k * E.card + P.card := by intro u have h2 := fam_cnt_le c ρ Q hQ E u rw [← hUdef] at h2 omega have hX1 : pe (E ×ˢ U) U.offDiag ≤ (E ×ˢ U).card * (2 * k * P.card + P.card) := pe_le_of_cnt_le _ _ _ (fun x _ => hcntU _) have hX2 : pe E.offDiag U.offDiag ≤ E.offDiag.card * (2 * k * P.card + P.card) := pe_le_of_cnt_le _ _ _ (fun x _ => hcntU _) have hX3 : pe (E ×ˢ U) (E ×ˢ U) ≤ (E ×ˢ U).card * (2 * k * E.card + P.card) := pe_le_of_cnt_le _ _ _ (fun x _ => hcntEU _) have hX4 := pe_offDiag_le hEconv obtain ⟨n, hnn⟩ : ∃ x : ℝ, x = P.card := ⟨_, rfl⟩ obtain ⟨e, hee⟩ : ∃ x : ℝ, x = E.card := ⟨_, rfl⟩ obtain ⟨uu, huu⟩ : ∃ x : ℝ, x = U.card := ⟨_, rfl⟩ have hEUc : ((E ×ˢ U).card : ℝ) = e * uu := by rw [card_product, hee, huu]; push_cast; ring have hEoc : (E.offDiag.card : ℝ) ≤ e * e := by rw [hee] have : E.offDiag.card ≤ E.card * E.card := by rw [offDiag_card]; exact Nat.sub_le _ _ exact_mod_cast this have hX1R : (pe (E ×ˢ U) U.offDiag : ℝ) ≤ e * uu * (2 * k * n + n) := by rw [← hEUc, hnn]; exact_mod_cast hX1 have hX2R : (pe E.offDiag U.offDiag : ℝ) ≤ e * e * (2 * k * n + n) := by have h : (pe E.offDiag U.offDiag : ℝ) ≤ E.offDiag.card * (2 * k * n + n) := by rw [hnn]; exact_mod_cast hX2 have h0 : (0 : ℝ) ≤ 2 * k * n + n := by rw [hnn]; positivity have := mul_le_mul_of_nonneg_right hEoc h0 linarith have hX3R : (pe (E ×ˢ U) (E ×ˢ U) : ℝ) ≤ e * uu * (2 * k * e + n) := by rw [← hEUc, hnn, hee]; exact_mod_cast hX3 have hX4R : (pe E.offDiag E.offDiag : ℝ) ≤ 3 * e * (e * e) := by have h : (pe E.offDiag E.offDiag : ℝ) ≤ 3 * E.card * ((E.card * E.card - E.card : ℕ) : ℝ) := by exact_mod_cast hX4 have h' : ((E.card * E.card - E.card : ℕ) : ℝ) ≤ e * e := by rw [hee] have : E.card * E.card - E.card ≤ E.card * E.card := Nat.sub_le _ _ exact_mod_cast this rw [← hee] at h have he0 : 0 ≤ e := by rw [hee]; positivity have := mul_le_mul_of_nonneg_left h' (by positivity : (0 : ℝ) ≤ 3 * e) linarith have he0 : 0 ≤ e := by rw [hee]; positivity have heN : e ≤ n := by rw [hee, hnn]; exact_mod_cast hEn have huN : uu ≤ n := by rw [huu, hnn]; exact_mod_cast hUc have hu0 : 0 ≤ uu := by rw [huu]; positivity have hk0 : (0 : ℝ) ≤ k := Nat.cast_nonneg k have hEterms : 4 * (pe (E ×ˢ U) U.offDiag : ℝ) + 2 * pe E.offDiag U.offDiag + 8 * pe (E ×ˢ U) (E ×ˢ U) + 2 * pe E.offDiag E.offDiag ≤ (28 * k + 20) * e * n ^ 2 := cor96_Eterms he0 heN hu0 huN hk0 hX1R hX2R hX3R hX4R have hfinal := cor96_arith (pU := (pe U.offDiag U.offDiag : ℝ)) hk0 (by rw [hnn]; exact hn) he0 (by rw [hee, hnn]; exact hEc) hGR (by rw [hnn]; exact h95) hEterms have hR := ngonValue_ge P.card rw [← hnn] at hR linarith /-- **GLIDE Corollary 9.6, `S`-form.** Same hypotheses: `Σ_u f(u)² ≤ R(n)`. -/ theorem cor96_S (P : Finset ℂ) (hP : ∀ z ∈ P, z ∉ convexHull ℝ ((P : Set ℂ) \ {z})) {k : ℕ} (c : Fin k → ℂ) (hc : Function.Injective c) (ρ : Fin k → ℝ) (hρ : ∀ i, 0 < ρ i) (hn : (10 : ℝ) ^ 40 * ((k : ℝ) + 1) ^ 12 ≤ P.card) (hE : ((P.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i)).card : ℝ) ≤ P.card / (200000 * (28 * k + 20))) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue P.card := by have hS4 : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 = (pe P.offDiag P.offDiag : ℝ) / 4 := by rw [Erdos94Infra.sum_sq_mult_eq] rfl rw [hS4] have := cor96_C P hP c hc ρ hρ hn hE linarith end Erdos94ThmA /-! ### Top-level assembly (lead's proof map, LEAN_PLAN.md): the master outline with its open links as hypotheses -/ namespace Erdos94ThmA open Finset /-- The `(NF_ε)` conclusion of link 1: at least `(1/2 − ε)n` distances have multiplicity `f(u) ≥ (1 − ε)n`. -/ def NFconcl (ε : ℝ) (P : Finset (EuclideanSpace ℝ (Fin 2))) : Prop := ∃ U : Finset ℝ, (1 / 2 - ε) * P.card ≤ U.card ∧ ∀ u ∈ U, (1 - ε) * P.card ≤ distanceMultiplicity P u /-- Near-concyclic: some circle `C(O, ρ)`, `ρ > 0`, contains all but `θ n` points of `P`. -/ def NearConcyclic (θ : ℝ) (P : Finset (EuclideanSpace ℝ (Fin 2))) : Prop := ∃ O : EuclideanSpace ℝ (Fin 2), ∃ ρ : ℝ, 0 < ρ ∧ ((P.filter (fun p => dist p O ≠ ρ)).card : ℝ) ≤ θ * P.card /-- `width(P) ≥ ζ₀·diam(P)`: in every direction `(cos t, sin t)` the projection of `P` has extent `≥ ζ₀·diam(P)`. -/ def Fat (ζ₀ : ℝ) (P : Finset (EuclideanSpace ℝ (Fin 2))) : Prop := ∀ t : ℝ, ∃ p ∈ P, ∃ q ∈ P, ζ₀ * Metric.diam (P : Set (EuclideanSpace ℝ (Fin 2))) ≤ (p 0 - q 0) * Real.cos t + (p 1 - q 1) * Real.sin t /-- The over-full excess `D⁺(P) = Σ_u f(u)·(f(u) − n)⁺` (GLIDE §11.11(a); `n = |P|`, `f` = `distanceMultiplicity`). -/ noncomputable def Dplus (P : Finset (EuclideanSpace ℝ (Fin 2))) : ℝ := ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - P.card) 0 /-- **Link 1** (INVERSE §11.19; (BIG) + (NF_ε), proved from (XE^rich) by `link1_of_XE` via GLIDE §11.11(a) and GLIDE-2 §14.0(a)): a convex `n`-gon (`n ≥ n₁`) with `S(P) > R(n)` has near-full classes and small over-full excess `D⁺ ≤ ε²n³` (the latter is an input of the needle case, AUDIT2 §119). -/ def Link1 (ε : ℝ) (n₁ : ℕ) : Prop := ∀ n ≥ n₁, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → Erdos94Infra.ngonValue n < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 → NFconcl ε P ∧ Dplus P ≤ ε ^ 2 * (n : ℝ) ^ 3 /-- **Links 2–6, wide case** (INVERSE Theorem 11.24′, AUDITED CORRECT AUDIT2 §104; its inputs Cor. 9.6 = `cor96_C` and Lemma 11.9 = `lemma119` are formal): fat + near-full classes ⇒ near-concyclic, for counterexamples (`S > R(n)`; a free weakening of Thm 11.24′, since `main_of_links` uses the wide case only by contradiction). -/ def WideThm (ζ₀ θ ε : ℝ) (n₃ : ℕ) : Prop := ∀ n ≥ n₃, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → Erdos94Infra.ngonValue n < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 → Fat ζ₀ P → NFconcl ε P → NearConcyclic θ P /-- **The needle case** (`hNeedle`; OPEN, INVERSE-3 §11.22, Thm 11.41): a thin convex `n`-gon that is a counterexample (`S > R(n)`) cannot have near-full classes together with small over-full excess `D⁺ ≤ ε²n³` (the hypothesis set of Thm 11.41, AUDIT2 §119; the counterexample hypothesis is a free weakening, since `main_of_links` argues by contradiction). -/ def NeedleThm (ζ₀ ε : ℝ) (n₂ : ℕ) : Prop := ∀ n ≥ n₂, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → Erdos94Infra.ngonValue n < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 → ¬ Fat ζ₀ P → NFconcl ε P → Dplus P ≤ ε ^ 2 * (n : ℝ) ^ 3 → False /-- **Master outline, final assembly (link 7 + case split).** With fixed `ζ₀`, `ε ≤ 9·10⁻⁶`, `θ = 10⁻⁴`: links 1, 2–6 (wide case) and the needle case give `S(P) ≤ R(n)` for all `n ≥ max(n₁, n₂, n₃, 2·10⁶)` (link 7 = `endgame81C`, Prop. 8.1 + Prop. C). The task's `target` is then `Erdos94Infra.target_of_large_class N (fun n hn P h1 h2 _ => …)`. -/ theorem main_of_links {ζ₀ ε : ℝ} {n₁ n₂ n₃ : ℕ} (hε0 : 0 ≤ ε) (hε : ε ≤ 9 / 1000000) (h1 : Link1 ε n₁) (hW : WideThm ζ₀ (1 / 10000) ε n₃) (hN : NeedleThm ζ₀ ε n₂) : ∃ N : ℕ, ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := by refine ⟨max n₁ (max n₂ (max n₃ 2000000)), fun n hn P hcard hconv => ?_⟩ have hn1 : n₁ ≤ n := le_trans (le_max_left _ _) hn have hn2 : n₂ ≤ n := le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) hn have hn3 : n₃ ≤ n := le_trans (le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) (le_max_right _ _)) hn have hn4 : 2000000 ≤ n := le_trans (le_trans (le_trans (le_max_right _ _) (le_max_right _ _)) (le_max_right _ _)) hn by_contra hlt push Not at hlt obtain ⟨⟨U, hU, hf⟩, hD⟩ := h1 n hn1 P hcard hconv hlt by_cases hfat : Fat ζ₀ P · obtain ⟨O, ρ, hρ, hk⟩ := hW n hn3 P hcard hconv hlt hfat ⟨U, hU, hf⟩ have h := endgame81C hconv (by rw [hcard]; exact hn4) hε0 hε U hU hf hρ hk rw [hcard] at h exact absurd h (not_le.mpr hlt) · exact hN n hn2 P hcard hconv hlt hfat ⟨U, hU, hf⟩ hD /-- **Master outline with its quantifiers** (constant chain ζ₀ → ε → n₀ of INVERSE Thm 11.24′(d)): if link 1 holds for every `ε > 0`, the wide case for every `ζ₀ > 0` and all small `ε`, and the needle case for one `ζ₀ > 0` and all small `ε`, then `S(P) ≤ R(n)` for all large `n`. -/ theorem main_of_hyps (hL1 : ∀ ε > 0, ∃ n₁, Link1 ε n₁) (hW : ∀ ζ₀ > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm ζ₀ (1 / 10000) ε n₃) (hN : ∃ ζ₀ > 0, ∃ ε₁ > 0, ∀ ε, 0 < ε → ε ≤ ε₁ → ∃ n₂, NeedleThm ζ₀ ε n₂) : ∃ N : ℕ, ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := by obtain ⟨ζ₀, hζ, ε₁, hε₁, hN'⟩ := hN obtain ⟨ε₀, hε₀, hW'⟩ := hW ζ₀ hζ obtain ⟨ε, hε⟩ : ∃ x : ℝ, x = min (min ε₀ ε₁) (9 / 1000000) := ⟨_, rfl⟩ have hεpos : 0 < ε := by rw [hε]; exact lt_min (lt_min hε₀ hε₁) (by norm_num) have hε9 : ε ≤ 9 / 1000000 := by rw [hε]; exact min_le_right _ _ have hεε₀ : ε ≤ ε₀ := by rw [hε]; exact le_trans (min_le_left _ _) (min_le_left _ _) have hεε₁ : ε ≤ ε₁ := by rw [hε]; exact le_trans (min_le_left _ _) (min_le_right _ _) obtain ⟨n₁, h1⟩ := hL1 ε hεpos obtain ⟨n₃, h3⟩ := hW' ε hεpos hεε₀ obtain ⟨n₂, h2⟩ := hN' ε hεpos hεε₁ exact main_of_links hεpos.le hε9 h1 h3 h2 end Erdos94ThmA /-! ### INVERSE §11.21(b) step (0): the rotation angle of a run inside a quarter-turn range lies in `(0, π/8)` (replaces FIX 2 of AUDIT2 §56: `0 < α`, `6α < 2π` are derived, not assumed) -/ namespace Erdos94ThmA open Finset /-- Two consecutive rotated edges: `e_{z+1} = ω e_z` when `v_{z+1} = g(v_z)` and `v_{z+2} = g(v_{z+1})`. -/ theorem edge_rot_of {n : ℕ} {v : ZMod n → ℂ} {O ω : ℂ} {z : ZMod n} (h0 : v (z + 1) = O + ω * (v z - O)) (h1 : v (z + 1 + 1) = O + ω * (v (z + 1) - O)) : edge v (z + 1) = ω * edge v z := by unfold edge linear_combination h1 - h0 /-- **Rotation angle of a run.** If `v_{z+k+1} = O + ω(v_{z+k} − O)` for `k < 5` (five consecutive edges of one rotation orbit) and the exterior angles at `v_{z+1}, …, v_{z+4}` sum to `< π/2`, then `0 < arg ω < π/8` (each of the four exterior angles equals `arg ω`, and they are positive because the polygon turns left). -/ theorem rot_small {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) {O ω : ℂ} {z : ZMod n} (hrot : ∀ k : ℕ, k < 5 → v (z + k + 1) = O + ω * (v (z + k) - O)) (hturn : turning v z 4 < Real.pi / 2) : 0 < Complex.arg ω ∧ Complex.arg ω < Real.pi / 8 := by have hext : ∀ k : ℕ, k < 4 → extAng v (z + k) = Complex.arg ω := by intro k hk have h0 := hrot k (by omega) have h1 := hrot (k + 1) (by omega) have e : (z + ((k + 1 : ℕ) : ZMod n)) = z + k + 1 := by push_cast; ring rw [e] at h1 have he := edge_rot_of h0 h1 unfold extAng rw [he, mul_div_assoc, div_self (edge_ne_zero hv _), mul_one] have hsum : turning v z 4 = 4 * Complex.arg ω := by unfold turning rw [sum_congr rfl (fun k hk => hext k (mem_range.mp hk))] simp only [sum_const, card_range, nsmul_eq_mul] norm_num have hpos := extAng_pos hv z have e0 : extAng v z = extAng v (z + ((0 : ℕ) : ZMod n)) := by simp rw [e0, hext 0 (by norm_num)] at hpos exact ⟨hpos, by linarith⟩ /-- **A clean block fixes the rotation angle.** If `x` has a clean block (six consecutive classes realised at six consecutive vertices of `F(x)`, the first five off `X = excX v O ω`), then `0 < arg ω < π/8`; so `6 arg ω < 2π`. -/ theorem clean_rot_small {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {S : Finset ℝ} {O ω : ℂ} {x : ZMod n} {a : ℕ} (hc : cleanAt v S (excX v O ω) x a) : 0 < Complex.arg ω ∧ Complex.arg ω < Real.pi / 8 := by obtain ⟨hA, hcons, hX⟩ := hc let t : ℕ → ZMod n := fun k => Tu v (usort S (a + k)) x have hF : ∀ k ≤ 5, inF v x (t k) := fun k hk => (Tu_spec (hA k hk)).1 obtain ⟨j, hj⟩ : ∃ j, j = (t 0 - x).val := ⟨_, rfl⟩ have hval : ∀ k ≤ 5, (t k - x).val = j + k := by intro k hk induction k with | zero => simp [hj] | succ k ih => have h1 := hcons k (by omega) have h2 := ih (by omega) simp only [t] at h1 h2 ⊢ rw [show a + (k + 1) = a + k + 1 by ring, h1, h2] ring have ht : ∀ k ≤ 5, t k = x + ((j + k : ℕ) : ZMod n) := by intro k hk have h := hval k hk have e : t k - x = ((j + k : ℕ) : ZMod n) := by rw [← h, ZMod.natCast_zmod_val] linear_combination e -- the run starts at z := x + j have hrot : ∀ k : ℕ, k < 5 → v (x + (j : ZMod n) + k + 1) = O + ω * (v (x + (j : ZMod n) + k) - O) := by intro k hk have hk' := hX k hk rw [excX, mem_filter] at hk' push Not at hk' have e := ht k hk.le have e' : x + (j : ZMod n) + k = t k := by rw [e]; push_cast; ring rw [e'] exact hk' (mem_univ _) -- the turning from `v_{z+1}` to `v_{z+4}` is part of `F(x)`'s quarter turn have hF0 := hF 0 (by norm_num) have hF5 := hF 5 (le_refl _) unfold inF at hF0 hF5 rw [hval 0 (by norm_num)] at hF0 rw [hval 5 (le_refl _)] at hF5 have hturn : turning v (x + (j : ZMod n)) 4 < Real.pi / 2 := by have h1 := turning_split v x j 4 have h2 := turning_nonneg hv x j have h3 := turning_mono hv x (show j + 4 ≤ qF v x by omega) have h4 := (qF_mem v x).2 linarith exact rot_small hv hrot hturn /-- The rotation `z ↦ O + ω(z − O)` with `‖ω‖ = 1` is `z ↦ O + e^{i arg ω}(z − O)`. -/ theorem exp_arg_of_norm_one {ω : ℂ} (h : ‖ω‖ = 1) : Complex.exp (Complex.arg ω * Complex.I) = ω := by have := Complex.norm_mul_exp_arg_mul_I ω rw [h] at this simpa using this end Erdos94ThmA /-! ### INVERSE Theorem 11.15 with FIX 2 discharged (`thm1115'`): the rotation is given as `ω`, `‖ω‖ = 1`; `0 < arg ω < π/8` is derived from a clean block of a good vertex (INVERSE §11.21(b) step (0)) -/ namespace Erdos94ThmA open Finset /-- The Markov budget of Theorem 11.15 for an arbitrary exceptional set `X`, `|X| ≤ ξn`: `|V ∖ G| ≤ (ν + 480ε + (1440ε + 240ν² + 240ξ)/κ) n`. (Extracted from the proof of `thm1115`.) -/ theorem goodG_compl_le {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) {u₀ ν κ ξ : ℝ} (hB : ((thinB v u₀).card : ℝ) ≤ ν * n) (hκ : 0 < κ) (hK : κ * n ≤ (U.filter (fun u => u < u₀)).card) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) (X : Finset (ZMod n)) (hX : (X.card : ℝ) ≤ ξ * n) : ((univ \ goodG v U u₀ X).card : ℝ) ≤ (ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n := by have hl := ccw_leftTurns hn hv have hnR : (3 : ℝ) ≤ n := by exact_mod_cast hn have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 have hν0 : 0 ≤ ν := by have : (0 : ℝ) ≤ ((thinB v u₀).card : ℝ) := Nat.cast_nonneg _ nlinarith have hξ0 : 0 ≤ ξ := by have : (0 : ℝ) ≤ ((X).card : ℝ) := Nat.cast_nonneg _ nlinarith -- budgets have hdfc : (∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) ≤ ε * n * (U.filter (fun u => u < u₀)).card + ((thinB v u₀).card : ℝ) ^ 2 / 2 := by have h1 := dfc_total hl U u₀ have h1R : 2 * (∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) + ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) ≤ 2 * n * ((U.filter (fun u => u < u₀)).card : ℝ) + ((thinB v u₀).card : ℝ) * (thinB v u₀).card := by have hBB : ((thinB v u₀).card * (thinB v u₀).card - (thinB v u₀).card : ℕ) ≤ (thinB v u₀).card * (thinB v u₀).card := Nat.sub_le _ _ have := h1.trans (Nat.add_le_add_left hBB _) exact_mod_cast this have h2 : ∑ u ∈ U.filter (fun u => u < u₀), (2 * (1 - ε) * (n : ℝ)) ≤ ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) := sum_le_sum (fun u hu => hU2 u (mem_filter.mp hu).1) rw [sum_const, nsmul_eq_mul] at h2 nlinarith have hnfc : (∑ x, (nfc v U u₀ x : ℝ)) ≤ 3 * ε * n ^ 2 := by have h1 := nfc_total v U u₀ have h1R : (∑ x, (nfc v U u₀ x : ℝ)) ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := by exact_mod_cast h1 linarith [(thm119_Ptot v U hε0 hε1 hU1 hU2).1] have hbdc : (∑ x, (bdc v (X) u₀ x : ℝ)) ≤ ξ * n * n := by have h1 := bdc_total v (X) u₀ have h1R : (∑ x, (bdc v (X) u₀ x : ℝ)) ≤ (n : ℝ) * (X).card := by exact_mod_cast h1 have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg _ nlinarith -- Markov: the complement of `G` have hKpos : (0 : ℝ) < (U.filter (fun u => u < u₀)).card := by linarith have m1 := markov_card univ (dfc v (U.filter (fun u => u < u₀))) (c := ((U.filter (fun u => u < u₀)).card : ℝ) / 480) (by positivity) hdfc have m2 := markov_card univ (nfc v U u₀) (c := ((U.filter (fun u => u < u₀)).card : ℝ) / 480) (by positivity) hnfc have m3 := markov_card univ (bdc v (X) u₀) (c := ((U.filter (fun u => u < u₀)).card : ℝ) / 240) (by positivity) hbdc have hsub : univ \ goodG v U u₀ (X) ⊆ (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x) ∪ univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)) ∪ univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 240 < bdc v (X) u₀ x) := by intro x hx have hxG : x ∉ goodG v U u₀ (X) := (mem_sdiff.mp hx).2 unfold goodG at hxG rw [mem_filter] at hxG simp only [mem_union, mem_filter, mem_univ, true_and] by_contra hc push_neg at hc exact hxG ⟨mem_univ _, hc.1.1, hc.1.2, hc.2⟩ have hcard := card_le_card hsub have hcu1 := card_union_le (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x) ∪ univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)) (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 240 < bdc v (X) u₀ x)) have hcu2 := card_union_le (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)) (univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)) have hcompR : ((univ \ goodG v U u₀ (X)).card : ℝ) ≤ ((univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) + ((univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) + ((univ.filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 240 < bdc v (X) u₀ x)).card : ℝ) := by exact_mod_cast hcard.trans (hcu1.trans (by omega)) -- the complement is at most `b₀n` have hcomp : ((univ \ goodG v U u₀ (X)).card : ℝ) ≤ (ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n := by have hn0 : (0 : ℝ) < n := by linarith have hK0 : (0 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := hKpos.le have hc1 := mul_le_mul_of_nonneg_right hcompR hK0 have hB0 : (0 : ℝ) ≤ ((thinB v u₀).card : ℝ) := Nat.cast_nonneg _ have hB2 : ((thinB v u₀).card : ℝ) ^ 2 ≤ (ν * n) ^ 2 := pow_le_pow_left₀ hB0 hB 2 have hQ0 : 0 ≤ 1440 * ε + 240 * ν ^ 2 + 240 * ξ := by positivity have hQ : (1440 * ε + 240 * ν ^ 2 + 240 * ξ) * (n : ℝ) ^ 2 ≤ (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ * n * (U.filter (fun u => u < u₀)).card := by have h1 : (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ * n * (κ * n) = (1440 * ε + 240 * ν ^ 2 + 240 * ξ) * (n : ℝ) ^ 2 := by field_simp rw [← h1] apply mul_le_mul_of_nonneg_left hK positivity have hcK : ((univ \ goodG v U u₀ (X)).card : ℝ) * (U.filter (fun u => u < u₀)).card ≤ ((ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n) * (U.filter (fun u => u < u₀)).card := by have hνK : 0 ≤ ν * n * (U.filter (fun u => u < u₀)).card := by positivity nlinarith exact le_of_mul_le_mul_right hcK hKpos exact hcomp open Classical in /-- **INVERSE Theorem 11.15, FIX 2 discharged.** As `thm1115`, but the rotation is `g(z) = O + ω(z − O)` with `‖ω‖ = 1` and NO hypothesis on its angle: `0 < arg ω < π/8` (so `6 arg ω < 2π`) follows from one clean block of a good vertex (`clean_rot_small`: four exterior angles equal `arg ω` inside a quarter turn). -/ theorem thm1115' {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) {u₀ ν κ ξ : ℝ} (hB : ((thinB v u₀).card : ℝ) ≤ ν * n) (hκ : 0 < κ) (hK : κ * n ≤ (U.filter (fun u => u < u₀)).card) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O ω : ℂ} (hω : ‖ω‖ = 1) (hX : ((excX v O ω).card : ℝ) ≤ ξ * n) (hb : ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ < 2 / 5 * κ) : ∃ ρ : ℝ, (((univ : Finset (ZMod n)).filter (fun x => ‖v x - O‖ ≠ ρ)).card : ℝ) ≤ (ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n := by have hl := ccw_leftTurns hn hv by_cases hG : (goodG v U u₀ (excX v O ω)).Nonempty · obtain ⟨x₀, hx₀⟩ := hG have hc := clean_G hl U u₀ (excX v O ω) hx₀ hx₀ (by omega) have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 have hne : ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x₀ a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x₀ a)).Nonempty := by rw [← card_pos] have : (0 : ℝ) < ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x₀ a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x₀ a)).card := by linarith exact_mod_cast this obtain ⟨a, ha⟩ := hne obtain ⟨hα0, hα8⟩ := clean_rot_small hl (mem_filter.mp ha).2.1 have hexp := exp_arg_of_norm_one hω rw [← hexp] at hX exact thm1115 hn hv U hε0 hε1 hU1 hU2 hB hκ hK hK30 hα0 (by linarith [Real.pi_pos]) hX hb · refine ⟨0, le_trans ?_ (goodG_compl_le hn hv U hε0 hε1 hU1 hU2 hB hκ hK hK30 (excX v O ω) hX)⟩ rw [not_nonempty_iff_eq_empty] at hG rw [hG, sdiff_empty] exact_mod_cast card_le_card (filter_subset _ _) end Erdos94ThmA /-! ### INVERSE Theorem 11.15′ for one global rotation (`S = V`): no hypothesis `b₀ < 0.4κ` (INVERSE §11.21(b), the averaged step (3); LEMMA_QUEUE LEAN2-NOTE-3) -/ namespace Erdos94ThmA open Finset open Classical in /-- Positions in `F_{u₀}(x)` are at most `|F_{u₀}(x)|` (it is the initial segment `{1, …, |F_{u₀}(x)|}`). -/ theorem Fu0_le_card {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u₀ : ℝ} {x : ZMod n} {j : ℕ} (hj : j ∈ Fu0 v u₀ x) : 1 ≤ j ∧ j ≤ (Fu0 v u₀ x).card := by have h1 : 1 ≤ j := by unfold Fu0 at hj obtain ⟨hjn, hF, _⟩ := mem_filter.mp hj have hoff : ((x + (j : ZMod n)) - x).val = j := off_cast x (mem_range.mp hjn) unfold inF at hF rw [hoff] at hF exact hF.1 refine ⟨h1, ?_⟩ have hsub : Icc 1 j ⊆ Fu0 v u₀ x := by intro j' hj' rw [mem_Icc] at hj' exact Fu0_initial hv hj hj'.1 hj'.2 have := card_le_card hsub rw [Nat.card_Icc] at this omega open Classical in /-- **Averaging (INVERSE Lemma 11.28 / §11.21(b)).** The positions of `F_{u₀}(x)`, `x ∈ G`, at non-good vertices number at most `|V ∖ G|·(K + K/480)` in total (each non-good `z` is at offset `j ≤ K + K/480` from at most one `x` per `j`). -/ theorem sum_nongood_le {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) : (∑ x ∈ goodG v U u₀ X, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ X)).card : ℝ)) ≤ ((univ \ goodG v U u₀ X).card : ℝ) * ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) := by obtain ⟨G, hG⟩ : ∃ S, S = goodG v U u₀ X := ⟨_, rfl⟩ rw [← hG] obtain ⟨M, hM⟩ : ∃ m : ℕ, m = ⌊((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480⌋₊ := ⟨_, rfl⟩ have hMle : (M : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 := by rw [hM] exact Nat.floor_le (by positivity) -- the pairs (x, j) have hcard : (G.sigma (fun x => (Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G))).card ≤ ((univ \ G) ×ˢ Icc 1 M).card := by apply card_le_card_of_injOn (fun p => (p.1 + (p.2 : ZMod n), p.2)) · intro p hp rw [mem_coe, mem_sigma] at hp obtain ⟨hx, hj⟩ := hp rw [mem_filter] at hj have hxG : p.1 ∈ goodG v U u₀ X := by rw [← hG]; exact hx obtain ⟨h1, h2⟩ := Fu0_le_card hv hj.1 have h3 := Fu0_card_G hv U u₀ X hxG have h4 : (p.2 : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 := le_trans (by exact_mod_cast h2) h3 have h5 : p.2 ≤ M := by rw [hM] exact Nat.le_floor h4 rw [mem_coe, mem_product, mem_sdiff, mem_Icc] exact ⟨⟨mem_univ _, hj.2⟩, h1, h5⟩ · intro p hp p' hp' h have h2 : p.2 = p'.2 := (Prod.mk.inj h).2 have h1 : p.1 + (p.2 : ZMod n) = p'.1 + (p'.2 : ZMod n) := (Prod.mk.inj h).1 rw [h2] at h1 have h1' : p.1 = p'.1 := add_right_cancel h1 exact Sigma.ext h1' (heq_of_eq h2) rw [card_sigma, card_product, Nat.card_Icc] at hcard have hcR : (∑ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ)) ≤ ((univ \ G).card : ℝ) * M := by have : ∑ x ∈ G, ((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card ≤ (univ \ G).card * M := by have := hcard simpa using this exact_mod_cast this have h0 : (0 : ℝ) ≤ ((univ \ G).card : ℝ) := Nat.cast_nonneg _ have := mul_le_mul_of_nonneg_left hMle h0 linarith open Classical in /-- **INVERSE Theorem 11.15′(iii) for one global rotation.** For ANY `U`, `u₀` with `K = |U ∩ (−∞, u₀)| ≥ 30` and any rotation `z ↦ O + ω(z − O)`, `‖ω‖ = 1` (exceptional set `X = excX v O ω`, good set `G = goodG v U u₀ X`), all but `3.51·|V ∖ G|` vertices lie on one circle about `O`. No `b₀ < 0.4κ`, no `ε`, no `(H₀)`: either some good `x` has fewer than `0.4K` non-good positions in `F_{u₀}(x)` — then `one_radius_loc` puts all of `G` on `x`'s circle — or every good vertex has `≥ 0.4K` of them, and averaging gives `|G| ≤ 2.506|V ∖ G|`. -/ theorem thm1115av {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O ω : ℂ} (hω : ‖ω‖ = 1) : ∃ ρ : ℝ, (((univ : Finset (ZMod n)).filter (fun x => ‖v x - O‖ ≠ ρ)).card : ℝ) ≤ (7 / 2 + 1 / 100) * ((univ \ goodG v U u₀ (excX v O ω)).card : ℝ) := by obtain ⟨G, hG⟩ : ∃ S, S = goodG v U u₀ (excX v O ω) := ⟨_, rfl⟩ rw [← hG] have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 have hcompl0 : (0 : ℝ) ≤ ((univ \ G).card : ℝ) := Nat.cast_nonneg _ by_cases hA : ∃ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card · obtain ⟨x, hxG, hloc⟩ := hA have hxG' : x ∈ goodG v U u₀ (excX v O ω) := by rw [← hG]; exact hxG -- a clean block of `x` fixes the angle have hc := clean_G hv U u₀ (excX v O ω) hxG' hxG' (by omega) have hne : ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a)).Nonempty := by rw [← card_pos] have : (0 : ℝ) < ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a)).card := by linarith exact_mod_cast this obtain ⟨a, ha⟩ := hne obtain ⟨hα0, hα8⟩ := clean_rot_small hv (mem_filter.mp ha).2.1 have hexp := exp_arg_of_norm_one hω have hG' : G = goodG v U u₀ (excX v O (Complex.exp (Complex.arg ω * Complex.I))) := by rw [hG, hexp] have hα6 : 6 * Complex.arg ω < 2 * Real.pi := by linarith [Real.pi_pos] refine ⟨‖v x - O‖, ?_⟩ have hsub : (univ : Finset (ZMod n)).filter (fun z => ‖v z - O‖ ≠ ‖v x - O‖) ⊆ univ \ G := by intro z hz refine mem_sdiff.mpr ⟨mem_univ _, fun hzG => (mem_filter.mp hz).2 ?_⟩ rw [hG'] at hzG hxG hloc exact (one_radius_loc hv U u₀ hα0 hα6 hK30 hloc hxG hzG).symm have h1 : (((univ : Finset (ZMod n)).filter (fun z => ‖v z - O‖ ≠ ‖v x - O‖)).card : ℝ) ≤ ((univ \ G).card : ℝ) := by exact_mod_cast card_le_card hsub linarith · push Not at hA refine ⟨0, ?_⟩ have hsum := sum_nongood_le hv U u₀ (excX v O ω) rw [← hG] at hsum have hlow : ((G.card : ℝ)) * (2 / 5 * (U.filter (fun u => u < u₀)).card) ≤ ∑ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) := by rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum (fun x hx => hA x hx) -- |G| · 0.4K ≤ |V∖G| · (1 + 1/480) K ⇒ |G| ≤ 2.506 |V∖G| have hKpos : (0 : ℝ) < (U.filter (fun u => u < u₀)).card := by linarith have hGc : (G.card : ℝ) ≤ (2405 / 960) * ((univ \ G).card : ℝ) := by have h := le_trans hlow hsum have e : ((univ \ G).card : ℝ) * ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) = (2 / 5 * (U.filter (fun u => u < u₀)).card) * ((2405 / 960) * ((univ \ G).card : ℝ)) := by ring rw [e] at h have h2 : 0 < 2 / 5 * ((U.filter (fun u => u < u₀)).card : ℝ) := by positivity rw [mul_comm] at h exact le_of_mul_le_mul_left h h2 have htot : ((univ : Finset (ZMod n)).card : ℝ) = G.card + ((univ \ G).card : ℝ) := by have := card_sdiff_add_card_eq_card (subset_univ G) push_cast [← this] ring have h1 : (((univ : Finset (ZMod n)).filter (fun z => ‖v z - O‖ ≠ 0)).card : ℝ) ≤ ((univ : Finset (ZMod n)).card : ℝ) := by exact_mod_cast card_filter_le _ _ linarith /-- **INVERSE Theorem 11.15′ for one global rotation, with the budgets** (repair of master-outline link 3): the hypotheses of Theorem 11.15 WITHOUT `b₀ < 0.4κ` and without any hypothesis on the rotation angle (`‖ω‖ = 1` only) give all but `3.51·b₀·n` vertices on one circle about `O`, `b₀ = ν + 480ε + (1440ε + 240ν² + 240ξ)/κ`. -/ theorem thm1115'' {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) {u₀ ν κ ξ : ℝ} (hB : ((thinB v u₀).card : ℝ) ≤ ν * n) (hκ : 0 < κ) (hK : κ * n ≤ (U.filter (fun u => u < u₀)).card) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O ω : ℂ} (hω : ‖ω‖ = 1) (hX : ((excX v O ω).card : ℝ) ≤ ξ * n) : ∃ ρ : ℝ, (((univ : Finset (ZMod n)).filter (fun x => ‖v x - O‖ ≠ ρ)).card : ℝ) ≤ (7 / 2 + 1 / 100) * ((ν + 480 * ε + (1440 * ε + 240 * ν ^ 2 + 240 * ξ) / κ) * n) := by obtain ⟨ρ, hρ⟩ := thm1115av (ccw_leftTurns hn hv) U u₀ hK30 hω refine ⟨ρ, le_trans hρ ?_⟩ have := goodG_compl_le hn hv U hε0 hε1 hU1 hU2 hB hκ hK hK30 (excX v O ω) hX exact mul_le_mul_of_nonneg_left this (by norm_num) end Erdos94ThmA /-! ### The open input of link 1 as a Lean `Prop`: (XE^rich_0) (GLIDE-2 §14.0(a)) -/ namespace Erdos94ThmA open Finset /-- A quarter-turn arc of a labelled polygon `v`: consecutive labels `a, a+1, …, a+m` (`m < n`) whose interior exterior angles (at `v_{a+1}, …, v_{a+m−1}`) sum to `< π/2`. On such an arc every vertex sees each distance at most twice inside the arc (Lemma 11.2 forward and backward; GLIDE Remark 13.3). -/ def QTArc {n : ℕ} (v : ZMod n → ℂ) (A : Finset (ZMod n)) : Prop := ∃ a : ZMod n, ∃ m : ℕ, m < n ∧ A = (range (m + 1)).image (fun i : ℕ => a + (i : ZMod n)) ∧ turning v a (m - 1) < Real.pi / 2 open Classical in /-- `m_u(x) = #{y ≠ x : |v_x v_y| = u}`. -/ noncomputable def mUv {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (x : ZMod n) (u : ℝ) : ℕ := (univ.filter (fun y => y ≠ x ∧ dist (v x) (v y) = u)).card open Classical in /-- GLIDE-2 §14.0(a): `R_ij(u) = #{(x, t) ∈ A_i × A_j : |xt| = u, m_u(x) ≥ 3}` and `S^rich_ij = Σ_u R_ij(u)²`. -/ noncomputable def Srich {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (Ai Aj : Finset (ZMod n)) : ℕ := ∑ u ∈ (Ai ×ˢ Aj).image (fun p => dist (v p.1) (v p.2)), ((Ai ×ˢ Aj).filter (fun p => dist (v p.1) (v p.2) = u ∧ 3 ≤ mUv v p.1 u)).card ^ 2 /-- **(XE^rich_0)** — the OPEN input of master-outline link 1 (GLIDE-2 §14.0(a)(ii)), in its weakest form: for every `ε > 0` and all large `n`, every strictly convex labelled `n`-gon that is a COUNTEREXAMPLE (`S > R(n)` for its vertex set `univ.image v`) admits a partition into `s ≤ 5` quarter-turn arcs whose rich cross energies satisfy `S^rich_ij ≤ ε n³` (`i ≠ j`). (A quarter-turn partition with `s ≤ 5` always exists: GLIDE Lemma 12.5 with AUDIT2 §87; it is included here so that the hypothesis is as weak as possible; the counterexample hypothesis is a free weakening, since link 1 is used only for counterexamples.) -/ def XErich : Prop := ∀ ε > 0, ∃ n₁ : ℕ, ∀ n ≥ n₁, ∀ hn : NeZero n, ∀ v : ZMod n → ℂ, 3 ≤ n → CCWPoly v → Function.Injective v → Erdos94Infra.ngonValue n < ∑ u ∈ distanceSet ((@Finset.univ (ZMod n) (@ZMod.fintype n hn)).image v), (distanceMultiplicity ((@Finset.univ (ZMod n) (@ZMod.fintype n hn)).image v) u : ℝ) ^ 2 → ∃ s : ℕ, s ≤ 5 ∧ ∃ A : Fin s → Finset (ZMod n), (∀ x, ∃ i, x ∈ A i) ∧ (∀ i j, i ≠ j → Disjoint (A i) (A j)) ∧ (∀ i, QTArc v (A i)) ∧ ∀ i j, i ≠ j → (@Srich n hn v (A i) (A j) : ℝ) ≤ ε * (n : ℝ) ^ 3 /-- **The master outline from its open inputs** (lead's `MAIN_of_hXE_hNeedle`, LEAN_PLAN "top-level proof map"), with the two audited-but-not-yet-formal steps as explicit hypotheses: * `hL1`: (XE^rich_0) ⇒ link 1 for every `ε` (GLIDE §11.11(a) + GLIDE-2 §14.0(a), [A]); * `hW`: INVERSE Theorem 11.24′ (AUDITED CORRECT AUDIT2 §104; inputs `cor96_C`, `lemma119`, `thm1115''`, `thm119g` formal); and the two OPEN inputs `hXE` (= `XErich`) and `hNeedle` (the needle case). Conclusion: `S(P) ≤ R(n)` for all large `n`, which gives the task's `target` by `Erdos94Infra.target_of_large_class`. -/ theorem main_of_XE_needle (hL1 : XErich → ∀ ε > 0, ∃ n₁, Link1 ε n₁) (hW : ∀ ζ₀ > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm ζ₀ (1 / 10000) ε n₃) (hXE : XErich) (hNeedle : ∃ ζ₀ > 0, ∃ ε₁ > 0, ∀ ε, 0 < ε → ε ≤ ε₁ → ∃ n₂, NeedleThm ζ₀ ε n₂) : ∃ N : ℕ, ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := main_of_hyps (hL1 hXE) hW hNeedle end Erdos94ThmA /-! ### GLIDE Corollary 9.6, general form (the input of INVERSE Theorem 11.24′ step 5) -/ namespace Erdos94ThmA open Finset open Classical in /-- **GLIDE Cor. 9.6, general form.** `P ⊂ ℂ` convex independent, `k` circles `C(c_i, ρ_i)` with pairwise distinct centres and positive radii, each containing at most `M` points of `P`; `E` = points of `P` on no circle. For every `λ > 0` and integer `G ≥ 1`: `pe(P°, P°) ≤ (1 + λ)·2Mn² + (1 + 1/λ)k⁴(52n² + 8n³/G + 4(2G + 1)²n²) + (28k + 20)|E| n²`. So `S(P) ≤ Mn²/2 + O(k|E|n²) + o_k(n³)`: if `S(P) ≥ (1/2 − δ)n³` then some circle carries `≥ (1 − 2δ − o(1))n` points. -/ theorem cor96_gen (P : Finset ℂ) (hP : ∀ z ∈ P, z ∉ convexHull ℝ ((P : Set ℂ) \ {z})) {k : ℕ} (c : Fin k → ℂ) (hc : Function.Injective c) (ρ : Fin k → ℝ) (hρ : ∀ i, 0 < ρ i) {M : ℝ} (hM0 : 0 ≤ M) (hM : ∀ i, ((P.filter (fun z => ‖z - c i‖ = ρ i)).card : ℝ) ≤ M) {l : ℝ} (hl : 0 < l) (G : ℕ) (hG1 : 1 ≤ G) : (pe P.offDiag P.offDiag : ℝ) ≤ (1 + l) * (2 * M * (P.card : ℝ) ^ 2) + (1 + 1 / l) * (k : ℝ) ^ 4 * (52 * (P.card : ℝ) ^ 2 + 8 * (P.card : ℝ) ^ 3 / G + 4 * (2 * G + 1) ^ 2 * (P.card : ℝ) ^ 2) + (28 * k + 20) * ((P.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i)).card : ℝ) * (P.card : ℝ) ^ 2 := by obtain ⟨Q, hQdef⟩ : ∃ Q, Q = famQ P c ρ := ⟨_, rfl⟩ obtain ⟨U, hUdef⟩ : ∃ U, U = univ.biUnion Q := ⟨_, rfl⟩ obtain ⟨E, hEdef⟩ : ∃ E, E = P \ U := ⟨_, rfl⟩ have hQ : ∀ i, ∀ q ∈ Q i, ‖q - c i‖ = ρ i := by rw [hQdef]; exact famQ_on P c ρ have hUP : U ⊆ P := by intro z hz rw [hUdef, mem_biUnion] at hz obtain ⟨i, _, hz⟩ := hz rw [hQdef, famQ, mem_filter] at hz exact hz.1 have hUE : Disjoint U E := by rw [hEdef]; exact disjoint_sdiff have hUEP : U ∪ E = P := by rw [hEdef]; exact union_sdiff_of_subset hUP have hEP : E ⊆ P := by rw [hEdef]; exact sdiff_subset have hEfil : E ⊆ P.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i) := by intro z hz rw [hEdef, mem_sdiff] at hz rw [mem_filter] refine ⟨hz.1, fun i hi => hz.2 ?_⟩ rw [hUdef, hQdef] exact mem_famQ_of P c ρ hz.1 ⟨i, hi⟩ have hEconv : ∀ a ∈ E, a ∉ convexHull ℝ ((E : Set ℂ) \ {a}) := fun a ha h => hP a (hEP ha) (convexHull_mono (Set.sdiff_subset_sdiff_left (coe_subset.mpr hEP)) h) -- the circle bound have hMQ : ∀ i, ((Q i).card : ℝ) ≤ M := by intro i have h1 : (Q i).card ≤ (P.filter (fun z => ‖z - c i‖ = ρ i)).card := by rw [hQdef]; exact card_le_card (famQ_sub P c ρ i) have h5 : ((Q i).card : ℝ) ≤ (P.filter (fun z => ‖z - c i‖ = ρ i)).card := by exact_mod_cast h1 linarith [hM i] have hNs : ∑ i, (Q i).card ≤ P.card := by rw [hQdef]; exact famQ_sum P c ρ have hN : ∑ i, ((Q i).card : ℝ) ≤ P.card := by exact_mod_cast hNs have h95 := thm95 c hc ρ hρ Q hQ hM0 hMQ hN hl G hG1 rw [← hUdef] at h95 -- decomposition have hdec := pe_decomp U E hUE rw [hUEP] at hdec have hdecR : (pe P.offDiag P.offDiag : ℝ) ≤ pe U.offDiag U.offDiag + 4 * pe (E ×ˢ U) U.offDiag + 2 * pe E.offDiag U.offDiag + 8 * pe (E ×ˢ U) (E ×ˢ U) + 2 * pe E.offDiag E.offDiag := by exact_mod_cast hdec -- E-term bounds have hUc : U.card ≤ P.card := card_le_card hUP have hEn : E.card ≤ P.card := card_le_card hEP have hcntU : ∀ u, cnt U.offDiag u ≤ 2 * k * P.card + P.card := by intro u have h1 : cnt U.offDiag u ≤ cnt (U ×ˢ U) u := by unfold cnt exact card_le_card (filter_subset_filter _ (fun p hp => by rw [mem_offDiag] at hp exact mem_product.mpr ⟨hp.1, hp.2.1⟩)) have h2 := fam_cnt_le c ρ Q hQ U u rw [← hUdef] at h2 have h3 : 2 * k * U.card ≤ 2 * k * P.card := Nat.mul_le_mul_left _ hUc omega have hcntEU : ∀ u, cnt (E ×ˢ U) u ≤ 2 * k * E.card + P.card := by intro u have h2 := fam_cnt_le c ρ Q hQ E u rw [← hUdef] at h2 omega have hX1 : pe (E ×ˢ U) U.offDiag ≤ (E ×ˢ U).card * (2 * k * P.card + P.card) := pe_le_of_cnt_le _ _ _ (fun x _ => hcntU _) have hX2 : pe E.offDiag U.offDiag ≤ E.offDiag.card * (2 * k * P.card + P.card) := pe_le_of_cnt_le _ _ _ (fun x _ => hcntU _) have hX3 : pe (E ×ˢ U) (E ×ˢ U) ≤ (E ×ˢ U).card * (2 * k * E.card + P.card) := pe_le_of_cnt_le _ _ _ (fun x _ => hcntEU _) have hX4 := pe_offDiag_le hEconv obtain ⟨n, hnn⟩ : ∃ x : ℝ, x = P.card := ⟨_, rfl⟩ obtain ⟨e, hee⟩ : ∃ x : ℝ, x = E.card := ⟨_, rfl⟩ obtain ⟨uu, huu⟩ : ∃ x : ℝ, x = U.card := ⟨_, rfl⟩ have hEUc : ((E ×ˢ U).card : ℝ) = e * uu := by rw [card_product, hee, huu]; push_cast; ring have hEoc : (E.offDiag.card : ℝ) ≤ e * e := by rw [hee] have : E.offDiag.card ≤ E.card * E.card := by rw [offDiag_card]; exact Nat.sub_le _ _ exact_mod_cast this have hX1R : (pe (E ×ˢ U) U.offDiag : ℝ) ≤ e * uu * (2 * k * n + n) := by rw [← hEUc, hnn]; exact_mod_cast hX1 have hX2R : (pe E.offDiag U.offDiag : ℝ) ≤ e * e * (2 * k * n + n) := by have h : (pe E.offDiag U.offDiag : ℝ) ≤ E.offDiag.card * (2 * k * n + n) := by rw [hnn]; exact_mod_cast hX2 have h0 : (0 : ℝ) ≤ 2 * k * n + n := by rw [hnn]; positivity have := mul_le_mul_of_nonneg_right hEoc h0 linarith have hX3R : (pe (E ×ˢ U) (E ×ˢ U) : ℝ) ≤ e * uu * (2 * k * e + n) := by rw [← hEUc, hnn, hee]; exact_mod_cast hX3 have hX4R : (pe E.offDiag E.offDiag : ℝ) ≤ 3 * e * (e * e) := by have h : (pe E.offDiag E.offDiag : ℝ) ≤ 3 * E.card * ((E.card * E.card - E.card : ℕ) : ℝ) := by exact_mod_cast hX4 have h' : ((E.card * E.card - E.card : ℕ) : ℝ) ≤ e * e := by rw [hee] have : E.card * E.card - E.card ≤ E.card * E.card := Nat.sub_le _ _ exact_mod_cast this rw [← hee] at h have he0 : 0 ≤ e := by rw [hee]; positivity have := mul_le_mul_of_nonneg_left h' (by positivity : (0 : ℝ) ≤ 3 * e) linarith have he0 : 0 ≤ e := by rw [hee]; positivity have heN : e ≤ n := by rw [hee, hnn]; exact_mod_cast hEn have huN : uu ≤ n := by rw [huu, hnn]; exact_mod_cast hUc have hu0 : 0 ≤ uu := by rw [huu]; positivity have hk0 : (0 : ℝ) ≤ k := Nat.cast_nonneg k have hEterms : 4 * (pe (E ×ˢ U) U.offDiag : ℝ) + 2 * pe E.offDiag U.offDiag + 8 * pe (E ×ˢ U) (E ×ˢ U) + 2 * pe E.offDiag E.offDiag ≤ (28 * k + 20) * e * n ^ 2 := cor96_Eterms he0 heN hu0 huN hk0 hX1R hX2R hX3R hX4R have hEterms : 4 * (pe (E ×ˢ U) U.offDiag : ℝ) + 2 * pe E.offDiag U.offDiag + 8 * pe (E ×ˢ U) (E ×ˢ U) + 2 * pe E.offDiag E.offDiag ≤ (28 * k + 20) * e * n ^ 2 := cor96_Eterms he0 heN hu0 huN hk0 hX1R hX2R hX3R hX4R have hEf : e ≤ ((P.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i)).card : ℝ) := by rw [hee]; exact_mod_cast card_le_card hEfil have h28 : (0 : ℝ) ≤ (28 * k + 20) * n ^ 2 := by positivity have := mul_le_mul_of_nonneg_left hEf h28 rw [← hnn] at h95 ⊢ linarith end Erdos94ThmA /-! ### Toward `link1_of_XE`, step (b): inside a quarter-turn arc a vertex sees each distance at most twice (GLIDE Remark 13.3; Lemma 11.2 forward and backward) -/ namespace Erdos94ThmA open Finset /-- Forward along a quarter-turn arc from `a + i`: at most one vertex `a + j`, `i < j ≤ m`, at a given distance. -/ theorem qt_fwd_le_one {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) {a : ZMod n} {m i : ℕ} (hτ : turning v a (m - 1) < Real.pi / 2) (him : i ≤ m) (u : ℝ) : ((Ioc i m).filter (fun j : ℕ => dist (v (a + (i : ZMod n))) (v (a + (j : ZMod n))) = u)).card ≤ 1 := by apply card_le_one.mpr intro j₁ h₁ j₂ h₂ rw [mem_filter, mem_Ioc] at h₁ h₂ -- the sub-arc from `a + i` turns less than the whole arc have hτ' : turning v (a + (i : ZMod n)) (m - i - 1) < Real.pi / 2 := by have hs := turning_split v a i (m - i - 1) have h0 := turning_nonneg hv a i have hmono := turning_mono hv a (show i + (m - i - 1) ≤ m - 1 by omega) linarith have key : ∀ k₁ k₂ : ℕ, i < k₁ → k₁ < k₂ → k₂ ≤ m → dist (v (a + (i : ZMod n))) (v (a + (k₁ : ZMod n))) < dist (v (a + (i : ZMod n))) (v (a + (k₂ : ZMod n))) := by intro k₁ k₂ hk₁ hk₁₂ hk₂ have hτ'' : turning v (a + (i : ZMod n)) (m - i - 1) < Real.pi / 2 := hτ' have h := arc_fwd hv (a + (i : ZMod n)) (m := m - i) hτ'' (j := k₁ - i) (j' := k₂ - i) (by omega) (by omega) have e1 : a + (i : ZMod n) + ((k₁ - i : ℕ) : ZMod n) = a + k₁ := by rw [Nat.cast_sub hk₁.le]; ring have e2 : a + (i : ZMod n) + ((k₂ - i : ℕ) : ZMod n) = a + k₂ := by rw [Nat.cast_sub (by omega : i ≤ k₂)]; ring rw [e1, e2] at h exact h rcases lt_trichotomy j₁ j₂ with h | h | h · exact absurd (h₁.2.trans h₂.2.symm) (ne_of_lt (key j₁ j₂ h₁.1.1 h h₂.1.2)) · exact h · exact absurd (h₂.2.trans h₁.2.symm) (ne_of_lt (key j₂ j₁ h₂.1.1 h h₁.1.2)) /-- Backward along a quarter-turn arc to `a + i`: at most one vertex `a + j`, `j < i`, at a given distance. -/ theorem qt_back_le_one {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) {a : ZMod n} {m i : ℕ} (hτ : turning v a (m - 1) < Real.pi / 2) (him : i ≤ m) (u : ℝ) : ((range i).filter (fun j : ℕ => dist (v (a + (i : ZMod n))) (v (a + (j : ZMod n))) = u)).card ≤ 1 := by apply card_le_one.mpr intro j₁ h₁ j₂ h₂ rw [mem_filter, mem_range] at h₁ h₂ have hτ' : turning v a (i - 1) < Real.pi / 2 := lt_of_le_of_lt (turning_mono hv a (show i - 1 ≤ m - 1 by omega)) hτ rcases lt_trichotomy j₁ j₂ with h | h | h · exact absurd (h₂.2.trans h₁.2.symm) (ne_of_lt (arc_back hv a hτ' h h₂.1.le)) · exact h · exact absurd (h₁.2.trans h₂.2.symm) (ne_of_lt (arc_back hv a hτ' h h₁.1.le)) open Classical in /-- **GLIDE Remark 13.3.** Inside a quarter-turn arc `A` every vertex `x ∈ A` sees each distance at most twice. -/ theorem qtarc_le_two {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {A : Finset (ZMod n)} (hA : QTArc v A) {x : ZMod n} (hx : x ∈ A) (u : ℝ) : (A.filter (fun y => y ≠ x ∧ dist (v x) (v y) = u)).card ≤ 2 := by obtain ⟨a, m, hm, rfl, hτ⟩ := hA rw [mem_image] at hx obtain ⟨i, hi, rfl⟩ := hx rw [mem_range] at hi have hsub : ((range (m + 1)).image (fun i : ℕ => a + (i : ZMod n))).filter (fun y => y ≠ a + (i : ZMod n) ∧ dist (v (a + (i : ZMod n))) (v y) = u) ⊆ ((Ioc i m).filter (fun j : ℕ => dist (v (a + (i : ZMod n))) (v (a + (j : ZMod n))) = u)).image (fun j : ℕ => a + (j : ZMod n)) ∪ ((range i).filter (fun j : ℕ => dist (v (a + (i : ZMod n))) (v (a + (j : ZMod n))) = u)).image (fun j : ℕ => a + (j : ZMod n)) := by intro y hy rw [mem_filter, mem_image] at hy obtain ⟨⟨j, hj, rfl⟩, hne, hd⟩ := hy rw [mem_range] at hj rcases lt_trichotomy i j with h | h | h · exact mem_union_left _ (mem_image.mpr ⟨j, mem_filter.mpr ⟨mem_Ioc.mpr ⟨h, by omega⟩, hd⟩, rfl⟩) · exact absurd (by rw [h]) hne · exact mem_union_right _ (mem_image.mpr ⟨j, mem_filter.mpr ⟨mem_range.mpr h, hd⟩, rfl⟩) calc _ ≤ _ := card_le_card hsub _ ≤ _ := card_union_le _ _ _ ≤ 1 + 1 := Nat.add_le_add (le_trans card_image_le (qt_fwd_le_one hv hτ (by omega) u)) (le_trans card_image_le (qt_back_le_one hv hτ (by omega) u)) end Erdos94ThmA /-! ### Toward `link1_of_XE`, step (c): GLIDE-2 §14.0(a), `D⁺ ≤ εn³/2 + 400ε⁻²·max_{i≠j} S^rich_ij` (ordered units) -/ namespace Erdos94ThmA open Finset open Classical in /-- `R_ij(u)` of GLIDE-2 §14.0(a). -/ noncomputable def Rrich {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (Ai Aj : Finset (ZMod n)) (u : ℝ) : ℕ := ((Ai ×ˢ Aj).filter (fun p => dist (v p.1) (v p.2) = u ∧ 3 ≤ mUv v p.1 u)).card open Classical in /-- **GLIDE Remark 13.3, counting form.** For a partition of the vertices into quarter-turn arcs `A_i`: `2f(u) = |chO u| ≤ 2n + Σ_{i≠j} R_ij(u)` (a vertex seeing `u` at most twice contributes `≤ 2`; a richer vertex has at most two `u`-partners in its own arc, the others are counted by `R`). -/ theorem chO_le_rich {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {s : ℕ} (A : Fin s → Finset (ZMod n)) (hcov : ∀ x, ∃ i, x ∈ A i) (hdisj : ∀ i j, i ≠ j → Disjoint (A i) (A j)) (hqt : ∀ i, QTArc v (A i)) (u : ℝ) : (chO v u).card ≤ 2 * n + ∑ ij ∈ (univ : Finset (Fin s)).offDiag, Rrich v (A ij.1) (A ij.2) u := by -- split the ordered chords obtain ⟨L, hL⟩ : ∃ S : Finset (ZMod n × ZMod n), S = (chO v u).filter (fun p => mUv v p.1 u ≤ 2 ∨ ∃ i, p.1 ∈ A i ∧ p.2 ∈ A i) := ⟨_, rfl⟩ obtain ⟨Rs, hRs⟩ : ∃ S : Finset (ZMod n × ZMod n), S = (univ : Finset (Fin s)).offDiag.biUnion (fun ij => (A ij.1 ×ˢ A ij.2).filter (fun p => dist (v p.1) (v p.2) = u ∧ 3 ≤ mUv v p.1 u)) := ⟨_, rfl⟩ have hcovC : chO v u ⊆ L ∪ Rs := by intro p hp by_cases h : mUv v p.1 u ≤ 2 ∨ ∃ i, p.1 ∈ A i ∧ p.2 ∈ A i · exact mem_union_left _ (by rw [hL, mem_filter]; exact ⟨hp, h⟩) · push Not at h obtain ⟨h3, hno⟩ := h obtain ⟨i, hi⟩ := hcov p.1 obtain ⟨j, hj⟩ := hcov p.2 have hij : i ≠ j := fun e => hno i hi (e ▸ hj) have hd : dist (v p.1) (v p.2) = u := by unfold chO at hp exact (mem_filter.mp hp).2.2 refine mem_union_right _ ?_ rw [hRs, mem_biUnion] exact ⟨(i, j), mem_offDiag.mpr ⟨mem_univ _, mem_univ _, hij⟩, mem_filter.mpr ⟨mem_product.mpr ⟨hi, hj⟩, hd, by omega⟩⟩ -- the low/own part: at most two chords per first vertex have hLc : L.card ≤ 2 * n := by have hfib : L.card = ∑ x : ZMod n, (L.filter (fun p => p.1 = x)).card := by apply card_eq_sum_card_fiberwise intro p _ exact mem_coe.mpr (mem_univ _) rw [hfib] calc ∑ x : ZMod n, (L.filter (fun p => p.1 = x)).card ≤ ∑ _x : ZMod n, 2 := by apply sum_le_sum intro x _ by_cases hm : mUv v x u ≤ 2 · calc (L.filter (fun p => p.1 = x)).card ≤ (univ.filter (fun y => y ≠ x ∧ dist (v x) (v y) = u)).card := by apply card_le_card_of_injOn Prod.snd · intro p hp rw [mem_coe, mem_filter, hL, mem_filter] at hp obtain ⟨⟨hpc, _⟩, hpx⟩ := hp unfold chO at hpc rw [mem_filter] at hpc rw [mem_coe, mem_filter] refine ⟨mem_univ _, ?_, ?_⟩ · rw [← hpx]; exact fun e => hpc.2.1 e.symm · rw [← hpx]; exact hpc.2.2 · intro p hp p' hp' h have e1 := (mem_filter.mp (mem_coe.mp hp)).2 have e2 := (mem_filter.mp (mem_coe.mp hp')).2 exact Prod.ext (e1.trans e2.symm) h _ = mUv v x u := rfl _ ≤ 2 := hm · push Not at hm obtain ⟨i, hi⟩ := hcov x calc (L.filter (fun p => p.1 = x)).card ≤ ((A i).filter (fun y => y ≠ x ∧ dist (v x) (v y) = u)).card := by apply card_le_card_of_injOn Prod.snd · intro p hp rw [mem_coe, mem_filter, hL, mem_filter] at hp obtain ⟨⟨hpc, hown⟩, hpx⟩ := hp unfold chO at hpc rw [mem_filter] at hpc rw [hpx] at hown hpc rcases hown with hlow | ⟨i', hi'x, hi'y⟩ · omega · have hii : i' = i := by by_contra hne exact disjoint_left.mp (hdisj i' i hne) hi'x hi rw [hii] at hi'y rw [mem_coe, mem_filter] exact ⟨hi'y, fun e => hpc.2.1 e.symm, hpc.2.2⟩ · intro p hp p' hp' h have e1 := (mem_filter.mp (mem_coe.mp hp)).2 have e2 := (mem_filter.mp (mem_coe.mp hp')).2 exact Prod.ext (e1.trans e2.symm) h _ ≤ 2 := qtarc_le_two hv (hqt i) hi u _ = 2 * n := by rw [sum_const, card_univ, ZMod.card, smul_eq_mul, mul_comm] have hRc : Rs.card ≤ ∑ ij ∈ (univ : Finset (Fin s)).offDiag, Rrich v (A ij.1) (A ij.2) u := by rw [hRs] exact card_biUnion_le calc (chO v u).card ≤ (L ∪ Rs).card := card_le_card hcovC _ ≤ L.card + Rs.card := card_union_le _ _ _ ≤ 2 * n + ∑ ij ∈ (univ : Finset (Fin s)).offDiag, Rrich v (A ij.1) (A ij.2) u := Nat.add_le_add hLc hRc open Classical in /-- `S^rich_ij = Σ_u R_ij(u)²` over any set of distances containing those of `A_i × A_j`. -/ theorem Srich_eq_sum {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (Ai Aj : Finset (ZMod n)) (D : Finset ℝ) (hD : ∀ p ∈ Ai ×ˢ Aj, dist (v p.1) (v p.2) ∈ D) : (Srich v Ai Aj : ℝ) = ∑ u ∈ D, (Rrich v Ai Aj u : ℝ) ^ 2 := by unfold Srich push_cast apply sum_subset · intro u hu rw [mem_image] at hu obtain ⟨p, hp, rfl⟩ := hu exact hD p hp · intro u _ hu have h0 : Rrich v Ai Aj u = 0 := by unfold Rrich rw [card_eq_zero, filter_eq_empty_iff] intro p hp h exact hu (mem_image.mpr ⟨p, hp, h.1⟩) unfold Rrich at h0 rw [h0] simp /-- The per-distance arithmetic of GLIDE-2 §14.0(a). -/ theorem dplus_per_arith {c R n ε Q : ℝ} (hc0 : 0 ≤ c) (hR0 : 0 ≤ R) (hn0 : 0 ≤ n) (hε0 : 0 < ε) (hc1 : c ≤ 2 * n + R) (hCS : R ^ 2 ≤ Q) : c * max (c - 2 * n) 0 ≤ ((1 + ε) / ε) ^ 2 * Q + 2 * ε * n * c := by have hK : 0 ≤ ((1 + ε) / ε) ^ 2 := sq_nonneg _ have hQ0 : 0 ≤ Q := le_trans (sq_nonneg R) hCS by_cases hbig : 2 * (1 + ε) * n ≤ c · have h2 : c * ε ≤ (1 + ε) * R := by nlinarith have h3 : c ≤ (1 + ε) / ε * R := by rw [div_mul_eq_mul_div, le_div_iff₀ hε0] linarith have h4 : c ^ 2 ≤ ((1 + ε) / ε * R) ^ 2 := pow_le_pow_left₀ hc0 h3 2 have h5 : c * max (c - 2 * n) 0 ≤ c ^ 2 := by have h : max (c - 2 * n) 0 ≤ c := max_le (by linarith) hc0 have := mul_le_mul_of_nonneg_left h hc0 nlinarith have h6 : ((1 + ε) / ε * R) ^ 2 = ((1 + ε) / ε) ^ 2 * R ^ 2 := by ring have h7 : ((1 + ε) / ε) ^ 2 * R ^ 2 ≤ ((1 + ε) / ε) ^ 2 * Q := mul_le_mul_of_nonneg_left hCS hK have h8 : 0 ≤ 2 * ε * n * c := by positivity linarith · push Not at hbig have h1 : max (c - 2 * n) 0 ≤ 2 * ε * n := max_le (by linarith) (by positivity) have h2 := mul_le_mul_of_nonneg_left h1 hc0 have h3 : 0 ≤ ((1 + ε) / ε) ^ 2 * Q := mul_nonneg hK hQ0 have e : c * (2 * ε * n) = 2 * ε * n * c := by ring linarith open Classical in /-- **GLIDE-2 §14.0(a) (ordered units).** For a partition of the vertices of a left-turning labelled polygon into `s ≤ 5` quarter-turn arcs with all rich cross energies `S^rich_ij ≤ M` (`i ≠ j`), and every `0 < ε ≤ 1`: `Σ_u c(u)·(c(u) − 2n)⁺ ≤ 1600 M/ε² + 2εn·Σ_u c(u)`, where `c(u) = |chO u| = 2f(u)`; i.e. `D⁺ ≤ 400M/ε² + εn·N`. -/ theorem dplus_le {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {s : ℕ} (hs : s ≤ 5) (A : Fin s → Finset (ZMod n)) (hcov : ∀ x, ∃ i, x ∈ A i) (hdisj : ∀ i j, i ≠ j → Disjoint (A i) (A j)) (hqt : ∀ i, QTArc v (A i)) {M : ℝ} (hM0 : 0 ≤ M) (hM : ∀ i j, i ≠ j → (Srich v (A i) (A j) : ℝ) ≤ M) {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε ≤ 1) (D : Finset ℝ) (hD : ∀ p : ZMod n × ZMod n, dist (v p.1) (v p.2) ∈ D) : ∑ u ∈ D, ((chO v u).card : ℝ) * max (((chO v u).card : ℝ) - 2 * n) 0 ≤ 1600 / ε ^ 2 * M + 2 * ε * n * ∑ u ∈ D, ((chO v u).card : ℝ) := by obtain ⟨T, hT⟩ : ∃ X : Finset (Fin s × Fin s), X = (univ : Finset (Fin s)).offDiag := ⟨_, rfl⟩ have hTc : (T.card : ℝ) ≤ 20 := by rw [hT, offDiag_card, card_univ, Fintype.card_fin] have h1 : s * s - s ≤ 20 := by interval_cases s <;> norm_num exact_mod_cast h1 have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg n have hper : ∀ u ∈ D, ((chO v u).card : ℝ) * max (((chO v u).card : ℝ) - 2 * n) 0 ≤ ((1 + ε) / ε) ^ 2 * (20 * ∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) + 2 * ε * n * (chO v u).card := by intro u _ have hc1 : ((chO v u).card : ℝ) ≤ 2 * n + ∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ) := by have h := chO_le_rich hv A hcov hdisj hqt u rw [← hT] at h exact_mod_cast h have hCS : (∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ)) ^ 2 ≤ 20 * ∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by have h := sq_sum_le_card_mul_sum_sq (s := T) (f := fun ij => (Rrich v (A ij.1) (A ij.2) u : ℝ)) have h0 : 0 ≤ ∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by positivity exact le_trans h (mul_le_mul_of_nonneg_right hTc h0) exact dplus_per_arith (by positivity) (by positivity) hn0 hε0 hc1 hCS have hsumR : ∑ u ∈ D, ∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 ≤ 20 * M := by rw [sum_comm] have h : ∀ ij ∈ T, ∑ u ∈ D, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 ≤ M := by intro ij hij rw [← Srich_eq_sum v (A ij.1) (A ij.2) D (fun p _ => hD p)] rw [hT, mem_offDiag] at hij exact hM ij.1 ij.2 hij.2.2 calc ∑ ij ∈ T, ∑ u ∈ D, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 ≤ ∑ _ij ∈ T, M := sum_le_sum h _ = T.card * M := by rw [sum_const, nsmul_eq_mul] _ ≤ 20 * M := mul_le_mul_of_nonneg_right hTc hM0 have hK4 : ((1 + ε) / ε) ^ 2 ≤ 4 / ε ^ 2 := by rw [div_pow, div_le_div_iff_of_pos_right (by positivity)] nlinarith calc ∑ u ∈ D, ((chO v u).card : ℝ) * max (((chO v u).card : ℝ) - 2 * n) 0 ≤ ∑ u ∈ D, (((1 + ε) / ε) ^ 2 * (20 * ∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) + 2 * ε * n * (chO v u).card) := sum_le_sum hper _ = ((1 + ε) / ε) ^ 2 * 20 * ∑ u ∈ D, ∑ ij ∈ T, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 + 2 * ε * n * ∑ u ∈ D, ((chO v u).card : ℝ) := by rw [sum_add_distrib, ← mul_sum, ← mul_sum, ← mul_sum] ring _ ≤ ((1 + ε) / ε) ^ 2 * 20 * (20 * M) + 2 * ε * n * ∑ u ∈ D, ((chO v u).card : ℝ) := by have := mul_le_mul_of_nonneg_left hsumR (by positivity : (0 : ℝ) ≤ ((1 + ε) / ε) ^ 2 * 20) linarith _ ≤ 1600 / ε ^ 2 * M + 2 * ε * n * ∑ u ∈ D, ((chO v u).card : ℝ) := by have h := mul_le_mul_of_nonneg_right hK4 (by positivity : (0 : ℝ) ≤ 400 * M) have e1 : ((1 + ε) / ε) ^ 2 * 20 * (20 * M) = ((1 + ε) / ε) ^ 2 * (400 * M) := by ring have e2 : 4 / ε ^ 2 * (400 * M) = 1600 / ε ^ 2 * M := by ring linarith end Erdos94ThmA /-! ### Link 1 from (XE^rich_0): `link1_of_XE` (GLIDE §11.11(a) + GLIDE-2 §14.0(a); steps (a) and (d)) -/ namespace Erdos94ThmA open Finset /-- No pair of distinct points is at distance `0`: `f(0) = 0`. -/ theorem mult_zero_eq (P : Finset (EuclideanSpace ℝ (Fin 2))) : distanceMultiplicity P 0 = 0 := by have h := Erdos94Infra.mult_cast P 0 have h0 : (P.offDiag.filter (fun x => dist x.1 x.2 = 0)).card = 0 := by rw [card_eq_zero, filter_eq_empty_iff] intro p hp hd rw [mem_offDiag] at hp exact hp.2.2 (dist_eq_zero.mp hd) rw [h0] at h simpa using h theorem max_two_mul (x : ℝ) : max (2 * x) 0 = 2 * max x 0 := by rcases le_total x 0 with h | h · rw [max_eq_right h, max_eq_right (by linarith)] ring · rw [max_eq_left h, max_eq_left (by linarith)] /-- **Link 1, step (a): plane → `ℂ` → counterclockwise labelling.** A convex-independent `P ⊂ ℝ²` with `n ≥ 3` points is the vertex set of a counterclockwise strictly convex polygon `v : ZMod n → ℂ` (through the isometry `ℝ² ≅ ℂ`); its ordered `u`-chords number `2f_P(u)`, and its distances between distinct labels are distances of `P`. -/ theorem plane_ccw_labelling {n : ℕ} [NeZero n] (h3 : 3 ≤ n) (P : Finset (EuclideanSpace ℝ (Fin 2))) (hcard : P.card = n) (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) : ∃ v : ZMod n → ℂ, Function.Injective v ∧ CCWPoly v ∧ (∀ u, ((chO v u).card : ℝ) = 2 * (distanceMultiplicity P u : ℝ)) ∧ (∀ p : ZMod n × ZMod n, p.1 ≠ p.2 → dist (v p.1) (v p.2) ∈ distanceSet P) ∧ ∑ u ∈ distanceSet (univ.image v), (distanceMultiplicity (univ.image v) u : ℝ) ^ 2 = ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 := by obtain ⟨Q, hQ⟩ : ∃ Q : Finset ℂ, Q = P.image Complex.orthonormalBasisOneI.repr.symm := ⟨_, rfl⟩ have hQc : Q.card = n := by rw [hQ, card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective, hcard] have hQi : ∀ z ∈ Q, z ∉ convexHull ℝ ((Q : Set ℂ) \ {z}) := by intro z hz rw [hQ] at hz ⊢ exact convexIndep_image_C hP hz obtain ⟨w, hwinj, hwmem, hwccw⟩ := exists_ccw_labelling Q hQi (by rw [hQc]; exact h3) subst hQc have himg : univ.image w = Q := by apply eq_of_subset_of_card_le · intro z hz rw [mem_image] at hz obtain ⟨k, _, rfl⟩ := hz exact hwmem k · rw [card_image_of_injective _ hwinj, card_univ, ZMod.card] have hsurj : ∀ z ∈ Q, ∃ k, w k = z := by intro z hz rw [← himg, mem_image] at hz obtain ⟨k, _, hk⟩ := hz exact ⟨k, hk⟩ have hch : ∀ u, (chO w u).card = (Q.offDiag.filter (fun x => dist x.1 x.2 = u)).card := by intro u apply card_bij (fun p _ => (w p.1, w p.2)) · intro p hp rw [mem_chO] at hp rw [mem_filter, mem_offDiag] exact ⟨⟨hwmem p.1, hwmem p.2, fun h => hp.1 (hwinj h)⟩, hp.2⟩ · intro p₁ _ p₂ _ h simp only [Prod.mk.injEq] at h exact Prod.ext (hwinj h.1) (hwinj h.2) · intro b hb rw [mem_filter, mem_offDiag] at hb obtain ⟨⟨hb1, hb2, hb12⟩, hbd⟩ := hb obtain ⟨k₁, hk₁⟩ := hsurj b.1 hb1 obtain ⟨k₂, hk₂⟩ := hsurj b.2 hb2 refine ⟨(k₁, k₂), ?_, ?_⟩ · rw [mem_chO] refine ⟨fun h => hb12 (by rw [← hk₁, ← hk₂]; exact congrArg w h), ?_⟩ show dist (w k₁) (w k₂) = u rw [hk₁, hk₂] exact hbd · show (w k₁, w k₂) = b rw [hk₁, hk₂] refine ⟨w, hwinj, hwccw, fun u => ?_, fun p hp => ?_, ?_⟩ · rw [hch u] have h1 := Erdos94Infra.mult_cast Q u have h2 : distanceMultiplicity Q u = distanceMultiplicity P u := by rw [hQ] exact mult_image_C P u rw [h2] at h1 linarith · have h1 : w p.1 ∈ P.image Complex.orthonormalBasisOneI.repr.symm := by rw [← hQ]; exact hwmem p.1 have h2 : w p.2 ∈ P.image Complex.orthonormalBasisOneI.repr.symm := by rw [← hQ]; exact hwmem p.2 obtain ⟨a, ha, hav⟩ := mem_image.mp h1 obtain ⟨b, hb, hbv⟩ := mem_image.mp h2 have hab : a ≠ b := by intro h apply hp apply hwinj rw [← hav, ← hbv, h] unfold distanceSet rw [mem_image] refine ⟨(a, b), mem_offDiag.mpr ⟨ha, hb, hab⟩, ?_⟩ show dist a b = dist (w p.1) (w p.2) rw [← hav, ← hbv, Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] · rw [himg, hQ, Erdos94Infra.sum_sq_mult_eq, Erdos94Infra.sum_sq_mult_eq, pairEnergy_image_C] open Classical in /-- **(XE^rich_0) ⇒ (BIG)** (link 1, steps (a)–(c): GLIDE-2 §14.0(a) with `ε′ = δ` and `S^rich_ij ≤ δ³n³/800`): for every `0 < δ ≤ 1` and all large `n`, every convex `n`-gon with `S(P) > R(n)` has `D⁺ ≤ δ n³`. -/ theorem dplus_small_of_XE (hXE : XErich) {δ : ℝ} (hδ0 : 0 < δ) (hδ1 : δ ≤ 1) : ∃ n₁ : ℕ, ∀ n ≥ n₁, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → Erdos94Infra.ngonValue n < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 → Dplus P ≤ δ * (n : ℝ) ^ 3 := by obtain ⟨n₀, hn₀⟩ := hXE (δ ^ 3 / 800) (by positivity) refine ⟨max n₀ 3, fun n hn P hcard hP hSR => ?_⟩ have h3 : 3 ≤ n := le_trans (le_max_right _ _) hn have hn0 : n₀ ≤ n := le_trans (le_max_left _ _) hn haveI : NeZero n := ⟨by omega⟩ obtain ⟨v, hinj, hccw, hch, hdist, hSv⟩ := plane_ccw_labelling h3 P hcard hP have hv : LeftTurns v := ccw_leftTurns h3 hccw obtain ⟨s, hs, A, hcov, hdisj, hqt, hS⟩ := hn₀ n hn0 inferInstance v h3 hccw hinj (by rw [hSv]; exact hSR) obtain ⟨D, hD⟩ : ∃ D : Finset ℝ, D = insert 0 (distanceSet P) := ⟨_, rfl⟩ have hDall : ∀ p : ZMod n × ZMod n, dist (v p.1) (v p.2) ∈ D := by intro p rw [hD, mem_insert] by_cases hp : p.1 = p.2 · left rw [hp, dist_self] · right exact hdist p hp have hM0 : (0 : ℝ) ≤ δ ^ 3 / 800 * (n : ℝ) ^ 3 := by positivity have key := dplus_le hv hs A hcov hdisj hqt hM0 (fun i j hij => hS i j hij) hδ0 hδ1 D hDall have hsub : distanceSet P ⊆ D := by rw [hD] exact subset_insert _ _ have hper : ∀ u, ((chO v u).card : ℝ) * max (((chO v u).card : ℝ) - 2 * n) 0 = 4 * ((distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - P.card) 0) := by intro u rw [hch u, hcard, show 2 * (distanceMultiplicity P u : ℝ) - 2 * n = 2 * ((distanceMultiplicity P u : ℝ) - n) by ring, max_two_mul] ring have e1 : ∑ u ∈ D, ((chO v u).card : ℝ) * max (((chO v u).card : ℝ) - 2 * n) 0 = 4 * Dplus P := by rw [sum_congr rfl (fun u _ => hper u), ← mul_sum] congr 1 unfold Dplus symm apply sum_subset hsub intro u huD hu rw [hD, mem_insert] at huD rcases huD with h | h · rw [h, mult_zero_eq] simp · exact absurd h hu have e2 : ∑ u ∈ D, ((chO v u).card : ℝ) = 2 * ((n.choose 2 : ℕ) : ℝ) := by rw [sum_congr rfl (fun u _ => hch u), ← mul_sum] congr 1 rw [← sum_subset hsub (fun u huD hu => ?_)] · rw [← hcard] exact_mod_cast sum_distanceMultiplicity P · rw [hD, mem_insert] at huD rcases huD with h | h · rw [h, mult_zero_eq] simp · exact absurd h hu rw [e1, e2] at key have hC : ((n.choose 2 : ℕ) : ℝ) = (n : ℝ) * (n - 1) / 2 := Nat.cast_choose_two ℝ n have h1 : 1600 / δ ^ 2 * (δ ^ 3 / 800 * (n : ℝ) ^ 3) = 2 * δ * (n : ℝ) ^ 3 := by field_simp ring have h2 : 2 * δ * n * (2 * ((n.choose 2 : ℕ) : ℝ)) ≤ 2 * δ * (n : ℝ) ^ 3 := by rw [hC] have h0 : (0 : ℝ) ≤ 2 * δ * n := by positivity have h4 : 2 * ((n : ℝ) * (n - 1) / 2) ≤ (n : ℝ) ^ 2 := by nlinarith have := mul_le_mul_of_nonneg_left h4 h0 nlinarith linarith theorem link1_per_low {x n e : ℝ} (hx : 0 ≤ x) (hn : 0 ≤ n) (he0 : 0 ≤ e) : (if ¬ ((1 - e) * n ≤ x) then e * n * x else 0) ≤ x * (n - x) + x * max (x - n) 0 := by have hm : 0 ≤ max (x - n) 0 := le_max_right _ _ by_cases h : (1 - e) * n ≤ x · rw [if_neg (not_not.mpr h)] rcases le_total x n with hxn | hxn · have h1 : 0 ≤ x * (n - x) := mul_nonneg hx (by linarith) have h2 : 0 ≤ x * max (x - n) 0 := mul_nonneg hx hm linarith · rw [max_eq_left (by linarith)] have : x * (n - x) + x * (x - n) = 0 := by ring linarith · rw [if_pos h] have h' : x < (1 - e) * n := not_le.mp h have hen : 0 ≤ e * n := mul_nonneg he0 hn have hxn : x - n ≤ 0 := by linarith rw [max_eq_right hxn, mul_zero, add_zero] have : 0 ≤ x * ((1 - e) * n - x) := mul_nonneg hx (by linarith) linarith theorem link1_per_high {x n : ℝ} (hx : 0 ≤ x) (hn : 0 ≤ n) : n * x ≤ n ^ 2 + x * max (x - n) 0 := by rcases le_total x n with h | h · have h1 : n * x ≤ n * n := mul_le_mul_of_nonneg_left h hn have h2 : 0 ≤ x * max (x - n) 0 := mul_nonneg hx (le_max_right _ _) nlinarith · rw [max_eq_left (by linarith)] nlinarith [sq_nonneg (x - n)] /-- The arithmetic of GLIDE §11.11(a): `S > R ≥ nN − n²/4` and `D⁺ ≤ e²n³` force `≥ (1/2 − 2e)n` classes with `f ≥ (1 − e)n` once `e²n ≥ 1`. (`L` = pairs in low classes, `Uc` = number of near-full classes.) -/ theorem link1_arith {n N S R Dp L Uc e : ℝ} (hn : 0 < n) (he : 0 < e) (he2 : e ≤ 1 / 2) (hN : N = n * (n - 1) / 2) (hR : n ^ 2 * (n - 1) / 2 - n ^ 2 / 4 ≤ R) (hSR : R < S) (h2 : e * n * L ≤ n * N - S + Dp) (h3 : n * (N - L) ≤ Uc * n ^ 2 + Dp) (hD : Dp ≤ e ^ 2 * n ^ 3) (hne : 1 ≤ e ^ 2 * n) : (1 / 2 - 2 * e) * n ≤ Uc := by have hnN : n * N = n ^ 2 * (n - 1) / 2 := by rw [hN]; ring have hA : e * n * L < n ^ 2 / 4 + Dp := by linarith have hB : e * (n * (N - L)) ≤ e * (Uc * n ^ 2 + Dp) := mul_le_mul_of_nonneg_left h3 he.le have heN : e * (n * N) = e * (n ^ 2 * (n - 1) / 2) := by rw [hnN] have hD' : (1 + e) * Dp ≤ (1 + e) * (e ^ 2 * n ^ 3) := mul_le_mul_of_nonneg_left hD (by linarith) have hF1 : (1 : ℝ) * (1 / 2) ≤ e ^ 2 * n * (1 - e) := mul_le_mul hne (by linarith) (by norm_num) (by positivity) have hF2 : n ^ 2 * (1 * (1 / 2)) ≤ n ^ 2 * (e ^ 2 * n * (1 - e)) := mul_le_mul_of_nonneg_left hF1 (by positivity) have hF3 : e * n ^ 2 ≤ 1 / 2 * n ^ 2 := mul_le_mul_of_nonneg_right he2 (by positivity) have hE : e * n ^ 2 * ((1 / 2 - 2 * e) * n) ≤ e * n ^ 2 * Uc := by linarith exact le_of_mul_le_mul_left hE (by positivity) open Classical in /-- **Link 1, step (d): GLIDE §11.11(a), (BIG) ⇒ (NF)** for a counterexample. If `S(P) > R(n)`, `D⁺ ≤ e²n³`, `0 < e ≤ 1/2` and `e²n ≥ 1`, then at least `(1/2 − 2e)n` distances have `f(u) ≥ (1 − e)n`. -/ theorem nf_of_dplus {P : Finset (EuclideanSpace ℝ (Fin 2))} {e : ℝ} (he0 : 0 < e) (he2 : e ≤ 1 / 2) (hne : 1 ≤ e ^ 2 * P.card) (hD : Dplus P ≤ e ^ 2 * (P.card : ℝ) ^ 3) (hSR : Erdos94Infra.ngonValue P.card < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2) : ∃ U : Finset ℝ, (1 / 2 - 2 * e) * P.card ≤ U.card ∧ ∀ u ∈ U, (1 - e) * P.card ≤ distanceMultiplicity P u := by have hn0 : (0 : ℝ) ≤ P.card := Nat.cast_nonneg _ have hnpos : (0 : ℝ) < P.card := by by_contra h have h0 : (P.card : ℝ) = 0 := le_antisymm (not_lt.mp h) hn0 rw [h0, mul_zero] at hne linarith refine ⟨(distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ)), ?_, fun u hu => (mem_filter.mp hu).2⟩ have hN : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) = (P.card : ℝ) * (P.card - 1) / 2 := by rw [← Nat.cast_choose_two ℝ P.card] exact_mod_cast sum_distanceMultiplicity P have hlow : e * P.card * ∑ u ∈ (distanceSet P).filter (fun u => ¬ ((1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ))), (distanceMultiplicity P u : ℝ) ≤ ∑ u ∈ distanceSet P, ((distanceMultiplicity P u : ℝ) * (P.card - distanceMultiplicity P u) + (distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - P.card) 0) := by rw [mul_sum, sum_filter] apply sum_le_sum intro u _ exact link1_per_low (Nat.cast_nonneg _) hn0 he0.le have hid : ∑ u ∈ distanceSet P, ((distanceMultiplicity P u : ℝ) * (P.card - distanceMultiplicity P u) + (distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - P.card) 0) = (P.card : ℝ) * ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) - ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 + Dplus P := by unfold Dplus rw [sum_add_distrib, mul_sum, ← sum_sub_distrib] congr 1 apply sum_congr rfl intro u _ ring have hsplit := sum_filter_add_sum_filter_not (distanceSet P) (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ)) (fun u => (distanceMultiplicity P u : ℝ)) have hhigh : (P.card : ℝ) * ∑ u ∈ (distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ)), (distanceMultiplicity P u : ℝ) ≤ ((distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ))).card * (P.card : ℝ) ^ 2 + Dplus P := by rw [mul_sum] have h1 : ∑ u ∈ (distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ)), (P.card : ℝ) * (distanceMultiplicity P u : ℝ) ≤ ∑ u ∈ (distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ)), ((P.card : ℝ) ^ 2 + (distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - P.card) 0) := sum_le_sum (fun u _ => link1_per_high (Nat.cast_nonneg _) hn0) have h2 : ∑ u ∈ (distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ)), (distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - P.card) 0 ≤ Dplus P := by unfold Dplus apply sum_le_sum_of_subset_of_nonneg (filter_subset _ _) intro u _ _ exact mul_nonneg (Nat.cast_nonneg _) (le_max_right _ _) rw [sum_add_distrib, sum_const, nsmul_eq_mul] at h1 linarith have hUs : ∑ u ∈ (distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ)), (distanceMultiplicity P u : ℝ) = ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) - ∑ u ∈ (distanceSet P).filter (fun u => ¬ ((1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ))), (distanceMultiplicity P u : ℝ) := by linarith have h3 : (P.card : ℝ) * (∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) - ∑ u ∈ (distanceSet P).filter (fun u => ¬ ((1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ))), (distanceMultiplicity P u : ℝ)) ≤ ((distanceSet P).filter (fun u => (1 - e) * P.card ≤ (distanceMultiplicity P u : ℝ))).card * (P.card : ℝ) ^ 2 + Dplus P := by rw [← hUs] exact hhigh exact link1_arith hnpos he0 he2 hN (ngonValue_ge P.card) hSR (by linarith) h3 hD hne /-- **Link 1 from (XE^rich_0)** (the lead's hL1; GLIDE §11.11(a) + GLIDE-2 §14.0(a)): for every `ε > 0` and all large `n`, a convex `n`-gon with `S(P) > R(n)` has (NF_ε) and `D⁺ ≤ ε²n³`. Constants: `e := min(ε, 1)/2`, (BIG) with `δ = e²` from `dplus_small_of_XE` (i.e. (XE^rich_0) at `e⁶/800`), and `n ≥ 1/e²`. -/ theorem link1_of_XE (hXE : XErich) : ∀ ε > 0, ∃ n₁, Link1 ε n₁ := by intro ε hε obtain ⟨e, he⟩ : ∃ e : ℝ, e = min ε 1 / 2 := ⟨_, rfl⟩ have hm0 : 0 < min ε 1 := lt_min hε one_pos have he0 : 0 < e := by rw [he]; linarith have he2 : e ≤ 1 / 2 := by rw [he]; linarith [min_le_right ε 1] have heε : 2 * e ≤ ε := by rw [he]; linarith [min_le_left ε 1] obtain ⟨nB, hB⟩ := dplus_small_of_XE hXE (δ := e ^ 2) (by positivity) (by nlinarith) obtain ⟨nC, hC⟩ := exists_nat_ge (1 / e ^ 2) refine ⟨max nB nC, fun n hn P hcard hP hSR => ?_⟩ have hnB : nB ≤ n := le_trans (le_max_left _ _) hn have hnC : nC ≤ n := le_trans (le_max_right _ _) hn have hD := hB n hnB P hcard hP hSR have hnR : (nC : ℝ) ≤ n := by exact_mod_cast hnC have h1n : 1 ≤ e ^ 2 * P.card := by rw [hcard] have h := le_trans hC hnR rw [div_le_iff₀ (by positivity)] at h linarith have hD' : Dplus P ≤ e ^ 2 * (P.card : ℝ) ^ 3 := by rw [hcard]; exact hD obtain ⟨U, hU, hf⟩ := nf_of_dplus he0 he2 h1n hD' (by rw [hcard]; exact hSR) refine ⟨⟨U, ?_, fun u hu => ?_⟩, ?_⟩ · have : (1 / 2 - ε) * (P.card : ℝ) ≤ (1 / 2 - 2 * e) * P.card := mul_le_mul_of_nonneg_right (by linarith) (Nat.cast_nonneg _) linarith · have : (1 - ε) * (P.card : ℝ) ≤ (1 - e) * P.card := mul_le_mul_of_nonneg_right (by linarith) (Nat.cast_nonneg _) linarith [hf u hu] · have h2 : e ^ 2 ≤ ε ^ 2 := by nlinarith calc Dplus P ≤ e ^ 2 * (n : ℝ) ^ 3 := hD _ ≤ ε ^ 2 * (n : ℝ) ^ 3 := mul_le_mul_of_nonneg_right h2 (by positivity) /-- **The master outline with link 1 discharged** (`hL1` of `main_of_XE_needle` is now `link1_of_XE`): from the wide case `hW` (INVERSE Thm 11.24′), (XE^rich_0) and the needle case, `S(P) ≤ R(n)` for all large `n`. -/ theorem main_of_W_XE_needle (hW : ∀ ζ₀ > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm ζ₀ (1 / 10000) ε n₃) (hXE : XErich) (hNeedle : ∃ ζ₀ > 0, ∃ ε₁ > 0, ∀ ε, 0 < ε → ε ≤ ε₁ → ∃ n₂, NeedleThm ζ₀ ε n₂) : ∃ N : ℕ, ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := main_of_XE_needle link1_of_XE hW hXE hNeedle end Erdos94ThmA /-! ### The total turning of a counterclockwise polygon is exactly `2π` (fan decomposition about `v₀`) -/ namespace Erdos94ThmA open Finset /-- `arg (a / b) = arg a − arg b` whenever the difference lies in `(−π, π]`. -/ theorem arg_div_of_mem {a b : ℂ} (ha : a ≠ 0) (hb : b ≠ 0) (h : Complex.arg a - Complex.arg b ∈ Set.Ioc (-Real.pi) Real.pi) : Complex.arg (a / b) = Complex.arg a - Complex.arg b := by have h1 : ((Complex.arg (a / b) : ℝ) : Real.Angle) = ((Complex.arg a - Complex.arg b : ℝ) : Real.Angle) := by rw [Complex.arg_div_coe_angle ha hb, Real.Angle.coe_sub] have h2 := congrArg Real.Angle.toReal h1 rwa [Complex.arg_coe_angle_toReal_eq_arg, Real.Angle.toReal_coe_eq_self_iff_mem_Ioc.mpr h] at h2 /-- A complex number in the open upper half plane has argument in `(0, π)`. -/ theorem arg_pos_lt_pi {z : ℂ} (h : 0 < z.im) : 0 < Complex.arg z ∧ Complex.arg z < Real.pi := by refine ⟨?_, Complex.arg_lt_pi_iff.mpr (Or.inr h.ne')⟩ rcases (Complex.arg_nonneg_iff.mpr h.le).lt_or_eq with h1 | h1 · exact h1 · exfalso have := Complex.arg_eq_zero_iff.mp h1.symm linarith [this.2] /-- `Im (a / b) > 0` iff `b × a > 0`. -/ theorem im_div_pos_of_cr {a b : ℂ} (hb : b ≠ 0) (h : 0 < cr b a) : 0 < (a / b).im := by rw [cr_eq] at h rw [Complex.div_im] have hn : 0 < Complex.normSq b := Complex.normSq_pos.mpr hb have e : a.im * b.re / Complex.normSq b - a.re * b.im / Complex.normSq b = (b.re * a.im - b.im * a.re) / Complex.normSq b := by ring rw [e] exact div_pos h hn /-- Exterior angles of a left-turning polygon are `< π`. -/ theorem extAng_lt_pi {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) : extAng v x < Real.pi := by unfold extAng exact (arg_pos_lt_pi (im_div_pos_of_cr (edge_ne_zero hv x) (hv x))).2 theorem cr_sub_self_right (a b : ℂ) : cr a (b - a) = cr a b := by simp only [cr_eq, Complex.sub_re, Complex.sub_im] ring /-- **The total turning of a counterclockwise strictly convex polygon is `2π`.** Proof by the fan about `v₀`: the exterior angle at `v_j` (`1 ≤ j ≤ n − 1`) is `A_j − B_j` with `A_j = arg((v₀ − v_j)/e_{j−1}) ∈ (0, π]`, `B_j = arg((v₀ − v_j)/e_j) ∈ [0, π)`; `A_{j+1} − B_j = φ_{j+1} − φ_j` with `φ_j = arg((v_j − v₀)/(v₁ − v₀)) ∈ [0, π)`; `A_1 = π`, `B_{n−1} = 0`; and the exterior angle at `v₀` is `π − φ_{n−1}`. -/ theorem turning_total_eq {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) : ∑ x : ZMod n, extAng v x = 2 * Real.pi := by have hL := ccw_leftTurns hn hv obtain ⟨V, hV⟩ : ∃ V : ℕ → ℂ, V = fun j : ℕ => v (j : ZMod n) := ⟨_, rfl⟩ have hval : ∀ j : ℕ, j < n → ((j : ZMod n)).val = j := fun j hj => by rw [ZMod.val_natCast, Nat.mod_eq_of_lt hj] have hcc : ∀ a b c : ℕ, a < b → b < c → c < n → 0 < cr (V b - V a) (V c - V a) := by intro a b c hab hbc hc rw [hV] exact hv _ _ _ (by rw [hval a (by omega), hval b (by omega)]; exact hab) (by rw [hval b (by omega), hval c hc]; exact hbc) have hVn : V n = V 0 := by rw [hV]; simp have hVn1 : V (n + 1) = V 1 := by rw [hV]; simp have hedge : ∀ j : ℕ, edge v (j : ZMod n) = V (j + 1) - V j := by intro j rw [hV] unfold edge push_cast rfl have hext : ∀ j : ℕ, extAng v (j : ZMod n) = Complex.arg ((V (j + 1 + 1) - V (j + 1)) / (V (j + 1) - V j)) := by intro j unfold extAng rw [show (j : ZMod n) + 1 = ((j + 1 : ℕ) : ZMod n) by push_cast; rfl, hedge, hedge] have he0 : ∀ j : ℕ, V (j + 1) - V j ≠ 0 := by intro j rw [← hedge] exact edge_ne_zero hL _ -- `φ_j` have hV10 : V 1 - V 0 ≠ 0 := he0 0 have hφpos : ∀ j : ℕ, 2 ≤ j → j < n → 0 < Complex.arg ((V j - V 0) / (V 1 - V 0)) ∧ Complex.arg ((V j - V 0) / (V 1 - V 0)) < Real.pi := fun j hj hjn => arg_pos_lt_pi (im_div_pos_of_cr hV10 (hcc 0 1 j (by norm_num) (by omega) hjn)) have hφ1 : Complex.arg ((V 1 - V 0) / (V 1 - V 0)) = 0 := by rw [div_self hV10, Complex.arg_one] have hr0 : ∀ j : ℕ, 1 ≤ j → j < n → V 0 - V j ≠ 0 := by intro j hj1 hjn rcases Nat.lt_or_ge j 2 with h | h · have : j = 1 := by omega rw [this] intro h' apply hV10 linear_combination -h' · intro h' have := (hφpos j h hjn).1 rw [show V j - V 0 = 0 by linear_combination -h', zero_div, Complex.arg_zero] at this exact lt_irrefl _ this -- the two angles at `v_{i+1}` have hA : ∀ i : ℕ, 1 ≤ i → i + 2 ≤ n → 0 < Complex.arg ((V 0 - V (i + 1)) / (V (i + 1) - V i)) ∧ Complex.arg ((V 0 - V (i + 1)) / (V (i + 1) - V i)) < Real.pi := by intro i hi hin refine arg_pos_lt_pi (im_div_pos_of_cr (he0 i) ?_) have h := hcc 0 i (i + 1) (by omega) (by omega) (by omega) rw [cr_cyc] at h have e : V 0 - V (i + 1) = (V 0 - V i) - (V (i + 1) - V i) := by ring rw [e, show cr (V (i + 1) - V i) ((V 0 - V i) - (V (i + 1) - V i)) = cr (V (i + 1) - V i) (V 0 - V i) by simp only [cr_eq, Complex.sub_re, Complex.sub_im]; ring] exact h have hB : ∀ i : ℕ, i + 3 ≤ n → 0 < Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) ∧ Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) < Real.pi := by intro i hin refine arg_pos_lt_pi (im_div_pos_of_cr (he0 (i + 1)) ?_) have h := hcc 0 (i + 1) (i + 1 + 1) (by omega) (by omega) (by omega) rw [cr_cyc] at h exact h have hA0 : Complex.arg ((V 0 - V (0 + 1)) / (V (0 + 1) - V 0)) = Real.pi := by rw [show V 0 - V (0 + 1) = -(V (0 + 1) - V 0) by ring, neg_div, div_self (he0 0), Complex.arg_neg_one] have hBl : Complex.arg ((V 0 - V (n - 2 + 1)) / (V (n - 2 + 1 + 1) - V (n - 2 + 1))) = 0 := by rw [show n - 2 + 1 + 1 = n by omega, hVn, div_self (hr0 (n - 2 + 1) (by omega) (by omega)), Complex.arg_one] -- the exterior angle at `v_{i+1}` is `A − B` have hsplit : ∀ i : ℕ, i + 2 ≤ n → extAng v (i : ZMod n) = Complex.arg ((V 0 - V (i + 1)) / (V (i + 1) - V i)) - Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) := by intro i hin rw [hext i] have hr := hr0 (i + 1) (by omega) (by omega) have hq : (V (i + 1 + 1) - V (i + 1)) / (V (i + 1) - V i) = ((V 0 - V (i + 1)) / (V (i + 1) - V i)) / ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) := by field_simp [he0 i, he0 (i + 1), hr] rw [hq] have hAm : 0 < Complex.arg ((V 0 - V (i + 1)) / (V (i + 1) - V i)) ∧ Complex.arg ((V 0 - V (i + 1)) / (V (i + 1) - V i)) ≤ Real.pi := by rcases Nat.eq_zero_or_pos i with h0 | h0 · subst h0 rw [hA0] exact ⟨Real.pi_pos, le_rfl⟩ · exact ⟨(hA i h0 hin).1, (hA i h0 hin).2.le⟩ have hBm : 0 ≤ Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) ∧ Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) < Real.pi := by rcases Nat.lt_or_ge (i + 2) n with h1 | h1 · exact ⟨(hB i (by omega)).1.le, (hB i (by omega)).2⟩ · have hi : i = n - 2 := by omega subst hi rw [hBl] exact ⟨le_rfl, Real.pi_pos⟩ exact arg_div_of_mem (div_ne_zero hr (he0 i)) (div_ne_zero hr (he0 (i + 1))) ⟨by linarith [hAm.1, hBm.2], by linarith [hAm.2, hBm.1]⟩ -- telescoping: `A_{i+2} − B_{i+1} = φ_{i+2} − φ_{i+1}` have htel : ∀ i : ℕ, i + 3 ≤ n → Complex.arg ((V 0 - V (i + 1 + 1)) / (V (i + 1 + 1) - V (i + 1))) - Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) = Complex.arg ((V (i + 1 + 1) - V 0) / (V 1 - V 0)) - Complex.arg ((V (i + 1) - V 0) / (V 1 - V 0)) := by intro i hin have hr1 := hr0 (i + 1) (by omega) (by omega) have hr2 := hr0 (i + 1 + 1) (by omega) (by omega) have hAi := hA (i + 1) (by omega) (by omega) have hBi := hB i hin have e1 := arg_div_of_mem (div_ne_zero hr2 (he0 (i + 1))) (div_ne_zero hr1 (he0 (i + 1))) ⟨by linarith [hAi.1, hBi.2], by linarith [hAi.2, hBi.1]⟩ have hq1 : ((V 0 - V (i + 1 + 1)) / (V (i + 1 + 1) - V (i + 1))) / ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) = ((V (i + 1 + 1) - V 0) / (V 1 - V 0)) / ((V (i + 1) - V 0) / (V 1 - V 0)) := by have hr1' : V (i + 1) - V 0 ≠ 0 := fun h => hr1 (by linear_combination -h) field_simp [he0 (i + 1), hr1, hr1', hV10] ring rw [hq1] at e1 rw [← e1] have hp2 := hφpos (i + 1 + 1) (by omega) (by omega) have hp1 : 0 ≤ Complex.arg ((V (i + 1) - V 0) / (V 1 - V 0)) ∧ Complex.arg ((V (i + 1) - V 0) / (V 1 - V 0)) < Real.pi := by rcases Nat.eq_zero_or_pos i with h0 | h0 · subst h0 rw [show (0 : ℕ) + 1 = 1 by norm_num, hφ1] exact ⟨le_rfl, Real.pi_pos⟩ · exact ⟨(hφpos (i + 1) (by omega) (by omega)).1.le, (hφpos (i + 1) (by omega) (by omega)).2⟩ have hr1' : V (i + 1) - V 0 ≠ 0 := fun h => hr1 (by linear_combination -h) have hr2' : V (i + 1 + 1) - V 0 ≠ 0 := fun h => hr2 (by linear_combination -h) exact arg_div_of_mem (div_ne_zero hr2' hV10) (div_ne_zero hr1' hV10) ⟨by linarith [hp2.1, hp1.2], by linarith [hp2.2, hp1.1]⟩ -- the exterior angle at `v₀` have hlast : extAng v ((n - 1 : ℕ) : ZMod n) = Real.pi - Complex.arg ((V (n - 1) - V 0) / (V 1 - V 0)) := by rw [hext (n - 1), show n - 1 + 1 + 1 = n + 1 by omega, show n - 1 + 1 = n by omega, hVn1, hVn] obtain ⟨z, hz⟩ : ∃ z, z = (V (n - 1) - V 0) / (V 1 - V 0) := ⟨_, rfl⟩ have hzp := hφpos (n - 1) (by omega) (by omega) rw [← hz] at hzp ⊢ have hz0 : z ≠ 0 := by intro h rw [h, Complex.arg_zero] at hzp exact lt_irrefl _ hzp.1 have hzim : 0 < z.im := by by_contra hc push_neg at hc rcases hc.lt_or_eq with h | h · have := Complex.arg_neg_iff.mpr h linarith [hzp.1] · have : Complex.arg z = 0 ∨ Complex.arg z = Real.pi := by rcases le_or_gt 0 z.re with hr | hr · left exact Complex.arg_eq_zero_iff.mpr ⟨hr, h⟩ · right exact Complex.arg_eq_pi_iff.mpr ⟨hr, h⟩ rcases this with h' | h' · linarith [hzp.1] · linarith [hzp.2] have hq : (V 1 - V 0) / (V 0 - V (n - 1)) = -(z⁻¹) := by have hr1 : V (n - 1) - V 0 ≠ 0 := fun h => (hr0 (n - 1) (by omega) (by omega)) (by linear_combination -h) rw [hz] field_simp [hV10, hr1] have h2 : V 0 - V (n - 1) = -(V (n - 1) - V 0) := by ring rw [h2] field_simp rw [hq] have himinv : (z⁻¹).im < 0 := by rw [Complex.inv_im] have : 0 < Complex.normSq z := Complex.normSq_pos.mpr hz0 exact div_neg_of_neg_of_pos (by linarith) this rw [Complex.arg_neg_eq_arg_add_pi_of_im_neg himinv, Complex.arg_inv, if_neg (ne_of_lt hzp.2)] ring -- assemble have hfull : ∑ x : ZMod n, extAng v x = ∑ i ∈ range n, extAng v (i : ZMod n) := by rw [← turning_full v 0] unfold turning refine sum_congr rfl (fun i _ => ?_) rw [zero_add] have hrange : range n = range (n - 1 + 1) := by rw [Nat.sub_add_cancel (by omega : 1 ≤ n)] have hsum : ∑ i ∈ range (n - 1), extAng v (i : ZMod n) = ∑ i ∈ range (n - 1), (Complex.arg ((V 0 - V (i + 1)) / (V (i + 1) - V i)) - Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1)))) := sum_congr rfl (fun i hi => hsplit i (by have := mem_range.mp hi; omega)) rw [hfull, hrange, sum_range_succ, hlast, hsum, sum_sub_distrib] obtain ⟨m, hm⟩ : ∃ m, m = n - 2 := ⟨_, rfl⟩ have hn1 : n - 1 = m + 1 := by omega rw [hn1, sum_range_succ' (fun i => Complex.arg ((V 0 - V (i + 1)) / (V (i + 1) - V i))), sum_range_succ (fun i => Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))))] have htel' : ∑ i ∈ range m, Complex.arg ((V 0 - V (i + 1 + 1)) / (V (i + 1 + 1) - V (i + 1))) - ∑ i ∈ range m, Complex.arg ((V 0 - V (i + 1)) / (V (i + 1 + 1) - V (i + 1))) = Complex.arg ((V (m + 1) - V 0) / (V 1 - V 0)) - Complex.arg ((V 1 - V 0) / (V 1 - V 0)) := by rw [← sum_sub_distrib] rw [sum_congr rfl (fun i hi => htel i (by have := mem_range.mp hi; omega))] exact sum_range_sub (fun i => Complex.arg ((V (i + 1) - V 0) / (V 1 - V 0))) m have hBl' : Complex.arg ((V 0 - V (m + 1)) / (V (m + 1 + 1) - V (m + 1))) = 0 := by rw [hm]; exact hBl rw [hφ1] at htel' linarith [htel', hBl', hA0] end Erdos94ThmA /-! ### INVERSE Theorem 11.15′ per stretch (§11.21(b)(iii)–(iv)): a set `G` of good vertices whose ranges lie in `S` -/ namespace Erdos94ThmA open Finset open Classical in /-- Averaging inside a stretch: for `G ⊆ goodG` whose ranges `F_{u₀}(x)` lie in `S`, the range positions outside `G` number at most `|S ∖ G|·(K + K/480)`. -/ theorem sum_nongood_le_S {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) (S G : Finset (ZMod n)) (hGg : G ⊆ goodG v U u₀ X) (hGS : ∀ x ∈ G, ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S) : (∑ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ)) ≤ ((S \ G).card : ℝ) * ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) := by obtain ⟨M, hM⟩ : ∃ m : ℕ, m = ⌊((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480⌋₊ := ⟨_, rfl⟩ have hMle : (M : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 := by rw [hM] exact Nat.floor_le (by positivity) have hcard : (G.sigma (fun x => (Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G))).card ≤ ((S \ G) ×ˢ Icc 1 M).card := by apply card_le_card_of_injOn (fun p => (p.1 + (p.2 : ZMod n), p.2)) · intro p hp rw [mem_coe, mem_sigma] at hp obtain ⟨hx, hj⟩ := hp rw [mem_filter] at hj have hxG : p.1 ∈ goodG v U u₀ X := hGg hx obtain ⟨h1, h2⟩ := Fu0_le_card hv hj.1 have h3 := Fu0_card_G hv U u₀ X hxG have h4 : (p.2 : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 := le_trans (by exact_mod_cast h2) h3 have h5 : p.2 ≤ M := by rw [hM] exact Nat.le_floor h4 rw [mem_coe, mem_product, mem_sdiff, mem_Icc] exact ⟨⟨hGS p.1 hx p.2 hj.1, hj.2⟩, h1, h5⟩ · intro p hp p' hp' h have h2 : p.2 = p'.2 := (Prod.mk.inj h).2 have h1 : p.1 + (p.2 : ZMod n) = p'.1 + (p'.2 : ZMod n) := (Prod.mk.inj h).1 rw [h2] at h1 have h1' : p.1 = p'.1 := add_right_cancel h1 exact Sigma.ext h1' (heq_of_eq h2) rw [card_sigma, card_product, Nat.card_Icc] at hcard have hcR : (∑ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ)) ≤ ((S \ G).card : ℝ) * M := by have : ∑ x ∈ G, ((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card ≤ (S \ G).card * M := by have := hcard simpa using this exact_mod_cast this have h0 : (0 : ℝ) ≤ ((S \ G).card : ℝ) := Nat.cast_nonneg _ have := mul_le_mul_of_nonneg_left hMle h0 linarith open Classical in /-- One good vertex with fewer than `0.4K` range positions outside `G ⊆ goodG` puts all of `G` on its circle about `O` (`one_radius_loc`, with the angle of the rotation fixed by a clean block, `clean_rot_small`). -/ theorem one_radius_G {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O ω : ℂ} (hω : ‖ω‖ = 1) (G : Finset (ZMod n)) (hGg : G ⊆ goodG v U u₀ (excX v O ω)) {x : ZMod n} (hxG : x ∈ G) (hloc : (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card) : ∀ z ∈ G, ‖v z - O‖ = ‖v x - O‖ := by have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 have hxG' : x ∈ goodG v U u₀ (excX v O ω) := hGg hxG have hc := clean_G hv U u₀ (excX v O ω) hxG' hxG' (by omega) have hne : ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a)).Nonempty := by rw [← card_pos] have : (0 : ℝ) < ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x a)).card := by linarith exact_mod_cast this obtain ⟨a, ha⟩ := hne obtain ⟨hα0, hα8⟩ := clean_rot_small hv (mem_filter.mp ha).2.1 have hexp := exp_arg_of_norm_one hω have hα6 : 6 * Complex.arg ω < 2 * Real.pi := by linarith [Real.pi_pos] have hloc' : (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ (excX v O (Complex.exp (Complex.arg ω * Complex.I))))).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card := by rw [hexp] have hsub : (Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ (excX v O ω)) ⊆ (Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G) := by intro j hj rw [mem_filter] at hj ⊢ exact ⟨hj.1, fun h => hj.2 (hGg h)⟩ have := card_le_card hsub have h' : (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ goodG v U u₀ (excX v O ω))).card : ℝ) ≤ (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) := by exact_mod_cast this linarith intro z hz have hx2 : x ∈ goodG v U u₀ (excX v O (Complex.exp (Complex.arg ω * Complex.I))) := by rw [hexp]; exact hxG' have hz2 : z ∈ goodG v U u₀ (excX v O (Complex.exp (Complex.arg ω * Complex.I))) := by rw [hexp]; exact hGg hz exact (one_radius_loc hv U u₀ hα0 hα6 hK30 hloc' hx2 hz2).symm open Classical in /-- **INVERSE Theorem 11.15′(iii), per stretch** (§11.21(b), §11.15(a)): for any rotation `z ↦ O + ω(z − O)` (`‖ω‖ = 1`), any set `S` of vertices and any `G ⊆ S ∩ goodG v U u₀ (excX v O ω)` whose ranges `F_{u₀}(x)` lie in `S`, all but `3.51·|S ∖ G|` vertices of `S` lie on one circle about `O` (`K ≥ 30`). -/ theorem thm1115S {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O ω : ℂ} (hω : ‖ω‖ = 1) (S G : Finset (ZMod n)) (hGg : G ⊆ goodG v U u₀ (excX v O ω)) (hGS0 : G ⊆ S) (hGS : ∀ x ∈ G, ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S) : ∃ ρ : ℝ, ((S.filter (fun x => ‖v x - O‖ ≠ ρ)).card : ℝ) ≤ (7 / 2 + 1 / 100) * ((S \ G).card : ℝ) := by have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 have hcompl0 : (0 : ℝ) ≤ ((S \ G).card : ℝ) := Nat.cast_nonneg _ by_cases hA : ∃ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card · obtain ⟨x, hxG, hloc⟩ := hA have hr := one_radius_G hv U u₀ hK30 hω G hGg hxG hloc refine ⟨‖v x - O‖, ?_⟩ have hsub : S.filter (fun z => ‖v z - O‖ ≠ ‖v x - O‖) ⊆ S \ G := by intro z hz obtain ⟨hzS, hzne⟩ := mem_filter.mp hz exact mem_sdiff.mpr ⟨hzS, fun hzG => hzne (hr z hzG)⟩ have h1 : ((S.filter (fun z => ‖v z - O‖ ≠ ‖v x - O‖)).card : ℝ) ≤ ((S \ G).card : ℝ) := by exact_mod_cast card_le_card hsub linarith · push Not at hA refine ⟨0, ?_⟩ have hsum := sum_nongood_le_S hv U u₀ (excX v O ω) S G hGg hGS have hlow : ((G.card : ℝ)) * (2 / 5 * (U.filter (fun u => u < u₀)).card) ≤ ∑ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) := by rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum (fun x hx => hA x hx) have hGc : (G.card : ℝ) ≤ (2405 / 960) * ((S \ G).card : ℝ) := by have h := le_trans hlow hsum have e : ((S \ G).card : ℝ) * ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) = (2 / 5 * (U.filter (fun u => u < u₀)).card) * ((2405 / 960) * ((S \ G).card : ℝ)) := by ring rw [e] at h have h2 : 0 < 2 / 5 * ((U.filter (fun u => u < u₀)).card : ℝ) := by positivity rw [mul_comm] at h exact le_of_mul_le_mul_left h h2 have htot : (S.card : ℝ) = G.card + ((S \ G).card : ℝ) := by have := card_sdiff_add_card_eq_card hGS0 push_cast [← this] ring have h1 : ((S.filter (fun z => ‖v z - O‖ ≠ 0)).card : ℝ) ≤ (S.card : ℝ) := by exact_mod_cast card_filter_le _ _ linarith open Classical in /-- **INVERSE Theorem 11.15′(iv), per stretch ("solid" stretch).** If moreover `|G| > 10·|S ∖ G|`, then some `x₀ ∈ G` has at most `(K + K/480)/10` range positions outside `G`, and all of `G` lies on the circle about `O` through `v_{x₀}`. -/ theorem thm1115S_solid {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O ω : ℂ} (hω : ‖ω‖ = 1) (S G : Finset (ZMod n)) (hGg : G ⊆ goodG v U u₀ (excX v O ω)) (hGS : ∀ x ∈ G, ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S) (hsol : 10 * (S \ G).card < G.card) : ∃ x₀ ∈ G, (((Fu0 v u₀ x₀).filter (fun j : ℕ => x₀ + (j : ZMod n) ∉ G)).card : ℝ) ≤ ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) / 10 ∧ ∀ z ∈ G, ‖v z - O‖ = ‖v x₀ - O‖ := by have hKR : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 have hsum := sum_nongood_le_S hv U u₀ (excX v O ω) S G hGg hGS have hGpos : (0 : ℝ) < G.card := by have : 0 < G.card := by omega exact_mod_cast this have hsolR : 10 * ((S \ G).card : ℝ) < G.card := by exact_mod_cast hsol by_contra hcon push Not at hcon -- every `x ∈ G` with few outside positions would put `G` on one circle, so all have many have hall : ∀ x ∈ G, ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) / 10 < (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) := by intro x hx by_contra h push Not at h have hloc : (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) < 2 / 5 * (U.filter (fun u => u < u₀)).card := by linarith obtain ⟨z, hz, hzne⟩ := hcon x hx h exact hzne (one_radius_G hv U u₀ hK30 hω G hGg hx hloc z hz) have hlow : ((G.card : ℝ)) * (((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) / 10) ≤ ∑ x ∈ G, (((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card : ℝ) := by rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum (fun x hx => (hall x hx).le) have hK0 : (0 : ℝ) < ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) := by positivity have h1 := le_trans hlow hsum have h2 : ((G.card : ℝ)) * (((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) / 10) > ((S \ G).card : ℝ) * ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) := by have := mul_lt_mul_of_pos_right hsolR hK0 nlinarith linarith end Erdos94ThmA /-! ### INVERSE Lemma 11.17′ (concentric case) / §11.15(c): solid stretches with a common centre lie on one circle -/ namespace Erdos94ThmA open Finset /-- The three-term recurrence of `Re(p·conj(ωᵐq))` for a unit `ω`. -/ theorem rec_re {p q ω : ℂ} (hω : ω * (starRingEnd ℂ) ω = 1) (m : ℕ) : (p * (starRingEnd ℂ) (ω ^ (m + 2) * q)).re + (p * (starRingEnd ℂ) (ω ^ m * q)).re = 2 * ω.re * (p * (starRingEnd ℂ) (ω ^ (m + 1) * q)).re := by have key : p * (starRingEnd ℂ) (ω ^ (m + 2) * q) + p * (starRingEnd ℂ) (ω ^ m * q) = (ω + (starRingEnd ℂ) ω) * (p * (starRingEnd ℂ) (ω ^ (m + 1) * q)) := by simp only [map_mul, map_pow] linear_combination (-(p * (starRingEnd ℂ) q * (starRingEnd ℂ) ω ^ m)) * hω rw [Complex.add_conj] at key have h := congrArg Complex.re key rw [Complex.add_re, Complex.re_ofReal_mul] at h linarith theorem unit_facts {ω : ℂ} (hω : ‖ω‖ = 1) : ω * (starRingEnd ℂ) ω = 1 ∧ ω.re ^ 2 + ω.im ^ 2 = 1 := by have h1 : Complex.normSq ω = 1 := by rw [Complex.normSq_eq_norm_sq, hω]; norm_num refine ⟨by rw [Complex.mul_conj, h1]; norm_num, ?_⟩ rw [Complex.normSq_apply] at h1 nlinarith /-- **Lemma 11.17′, concentric case (algebraic core).** If `|p| = |q| = r > 0`, `|p′| = |q′| = r′ ≥ 0`, `ω, ω′` are unit with positive imaginary part, and `|p − ωᵏq| = |p′ − ω′ᵏq′|` for `k = 0, …, 4`, then `r = r′`. (With `Y_k = Re(p·conj(ωᵏq))`: `Y′_k = Y_k + r′² − r²`, both sequences satisfy three-term recurrences with `2Re ω`, `2Re ω′`; `Re ω ≠ Re ω′` forces `Y_1 = Y_2 = 0`, impossible for `r > 0`, `Im ω > 0`; `Re ω = Re ω′ < 1` forces `r′² = r²`.) -/ theorem concentric_radius {p q p' q' ω ω' : ℂ} {r r' : ℝ} (hr0 : 0 < r) (hr' : 0 ≤ r') (hp : ‖p‖ = r) (hq : ‖q‖ = r) (hp' : ‖p'‖ = r') (hq' : ‖q'‖ = r') (hω : ‖ω‖ = 1) (hω' : ‖ω'‖ = 1) (him : 0 < ω.im) (him' : 0 < ω'.im) (h : ∀ k ≤ 4, ‖p - ω ^ k * q‖ = ‖p' - ω' ^ k * q'‖) : r = r' := by obtain ⟨hωc, hω2⟩ := unit_facts hω obtain ⟨hωc', hω2'⟩ := unit_facts hω' have hc1 : ω.re < 1 := by nlinarith have hc1' : ω'.re < 1 := by nlinarith obtain ⟨Y, hY⟩ : ∃ Y : ℕ → ℝ, Y = fun m => (p * (starRingEnd ℂ) (ω ^ m * q)).re := ⟨_, rfl⟩ obtain ⟨Y', hY'⟩ : ∃ Y : ℕ → ℝ, Y = fun m => (p' * (starRingEnd ℂ) (ω' ^ m * q')).re := ⟨_, rfl⟩ have hns : ∀ (a b c : ℂ) (s : ℝ), ‖a‖ = s → ‖c‖ = 1 → ‖b‖ = s → ∀ k : ℕ, Complex.normSq (a - c ^ k * b) = 2 * s ^ 2 - 2 * (a * (starRingEnd ℂ) (c ^ k * b)).re := by intro a b c s ha hc hb k rw [Complex.normSq_sub, Complex.normSq_mul, Complex.normSq_eq_norm_sq a, Complex.normSq_eq_norm_sq b, Complex.normSq_eq_norm_sq (c ^ k), norm_pow, hc, one_pow, ha, hb] ring have hd : ∀ k ≤ 4, Y' k = Y k + (r' ^ 2 - r ^ 2) := by intro k hk have h1 := h k hk have h2 : Complex.normSq (p - ω ^ k * q) = Complex.normSq (p' - ω' ^ k * q') := by rw [Complex.normSq_eq_norm_sq, Complex.normSq_eq_norm_sq, h1] rw [hns p q ω r hp hω hq k, hns p' q' ω' r' hp' hω' hq' k] at h2 rw [hY, hY'] simp only linarith have hrec : ∀ m, Y (m + 2) + Y m = 2 * ω.re * Y (m + 1) := by intro m rw [hY] exact rec_re hωc m have hrec' : ∀ m, Y' (m + 2) + Y' m = 2 * ω'.re * Y' (m + 1) := by intro m rw [hY'] exact rec_re hωc' m have hlin : ∀ m ≤ 2, (ω.re - ω'.re) * Y (m + 1) = (ω'.re - 1) * (r' ^ 2 - r ^ 2) := by intro m hm have h1 := hrec m have h2 := hrec' m rw [hd (m + 2) (by omega), hd m (by omega), hd (m + 1) (by omega)] at h2 nlinarith by_cases hcc : ω.re = ω'.re · have h1 := hlin 0 (by norm_num) rw [hcc, sub_self, zero_mul] at h1 have hD : r' ^ 2 - r ^ 2 = 0 := by rcases mul_eq_zero.mp h1.symm with h' | h' · exact absurd h' (by linarith) · exact h' have : r ^ 2 = r' ^ 2 := by linarith exact (sq_eq_sq₀ hr0.le hr').mp this · exfalso have hne : ω.re - ω'.re ≠ 0 := sub_ne_zero.mpr hcc have e1 := hlin 0 (by norm_num) have e2 := hlin 1 (by norm_num) have e3 := hlin 2 (by norm_num) have h12 : Y 1 = Y 2 := mul_left_cancel₀ hne (by rw [e1, e2]) have h23 : Y 2 = Y 3 := mul_left_cancel₀ hne (by rw [e2, e3]) have hr1 := hrec 1 have hY2 : Y 2 = 0 := by have : (1 - ω.re) * Y 2 = 0 := by have e : Y (1 + 2) + Y 1 = 2 * ω.re * Y (1 + 1) := hr1 norm_num at e nlinarith rcases mul_eq_zero.mp this with h' | h' · exact absurd h' (by linarith) · exact h' have hY1 : Y 1 = 0 := by rw [h12]; exact hY2 -- `w = p·conj(ωq)` has `Re w = Re(w·conj ω) = 0`, so `w = 0` obtain ⟨w, hw⟩ : ∃ w, w = p * (starRingEnd ℂ) (ω * q) := ⟨_, rfl⟩ have hw1 : w.re = 0 := by have := hY1 rw [hY] at this simp only [pow_one] at this rw [hw] exact this have hw2 : (w * (starRingEnd ℂ) ω).re = 0 := by have := hY2 rw [hY] at this simp only at this rw [hw] have e : p * (starRingEnd ℂ) (ω ^ 2 * q) = p * (starRingEnd ℂ) (ω * q) * (starRingEnd ℂ) ω := by simp only [map_mul, map_pow] ring rw [← e] exact this rw [Complex.mul_re, Complex.conj_re, Complex.conj_im, hw1] at hw2 have hwim : w.im = 0 := by have : w.im * ω.im = 0 := by linarith rcases mul_eq_zero.mp this with h' | h' · exact h' · exact absurd h' him.ne' have hw0 : w = 0 := Complex.ext hw1 hwim have hnw : ‖w‖ = r * r := by rw [hw, norm_mul, Complex.norm_conj, norm_mul, hω, one_mul, hp, hq] rw [hw0, norm_zero] at hnw nlinarith open Classical in /-- Common clean starts for two good vertices with respect to two (possibly different) exceptional sets. -/ theorem clean_count2 {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X X' : Finset (ZMod n)) (x x' : ZMod n) : (U.filter (fun u => u < u₀)).card - 5 ≤ ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X' x' a)).card + (6 * (dfc v (U.filter (fun u => u < u₀)) x + dfc v (U.filter (fun u => u < u₀)) x') + 5 * (nfc v U u₀ x + nfc v U u₀ x' + bdc v X u₀ x + bdc v X' u₀ x')) := by have hbad : ∀ (Y : Finset (ZMod n)) (y : ZMod n), ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) Y y a)).card ≤ 6 * dfc v (U.filter (fun u => u < u₀)) y + 5 * (nfc v U u₀ y + bdc v Y u₀ y) := by intro Y y have h1 := card_le_card (not_clean_sub v (U.filter (fun u => u < u₀)) Y y) have h2 := card_union_le ((defI v (U.filter (fun u => u < u₀)) y).biUnion (fun d => Icc (d - 5) d)) ((brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) Y y).biUnion (fun e => Icc (e - 4) e)) have h3 : ((defI v (U.filter (fun u => u < u₀)) y).biUnion (fun d => Icc (d - 5) d)).card ≤ 6 * dfc v (U.filter (fun u => u < u₀)) y := by refine card_biUnion_le.trans ?_ rw [← defI_card] calc ∑ d ∈ defI v (U.filter (fun u => u < u₀)) y, (Icc (d - 5) d).card ≤ ∑ d ∈ defI v (U.filter (fun u => u < u₀)) y, 6 := sum_le_sum (fun d _ => by rw [Nat.card_Icc]; omega) _ = 6 * (defI v (U.filter (fun u => u < u₀)) y).card := by rw [sum_const, smul_eq_mul, mul_comm] have h4 : ((brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) Y y).biUnion (fun e => Icc (e - 4) e)).card ≤ 5 * (nfc v U u₀ y + bdc v Y u₀ y) := by refine card_biUnion_le.trans ?_ calc ∑ e ∈ brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) Y y, (Icc (e - 4) e).card ≤ ∑ e ∈ brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) Y y, 5 := sum_le_sum (fun e _ => by rw [Nat.card_Icc]; omega) _ = 5 * (brkI v (U.filter (fun u => u < u₀)) y ∪ runI v (U.filter (fun u => u < u₀)) Y y).card := by rw [sum_const, smul_eq_mul, mul_comm] _ ≤ 5 * (nfc v U u₀ y + bdc v Y u₀ y) := by have := card_union_le (brkI v (U.filter (fun u => u < u₀)) y) (runI v (U.filter (fun u => u < u₀)) Y y) have := brkI_card hv U u₀ y have := runI_card hv U u₀ Y y omega omega have hsplit := card_filter_add_card_filter_not (s := range ((U.filter (fun u => u < u₀)).card - 5)) (fun a => cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X' x' a) have hsub : (range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ (cleanAt v (U.filter (fun u => u < u₀)) X x a ∧ cleanAt v (U.filter (fun u => u < u₀)) X' x' a)) ⊆ (range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X x a) ∪ (range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X' x' a) := by intro a ha obtain ⟨haK, hnc⟩ := mem_filter.mp ha by_cases h : cleanAt v (U.filter (fun u => u < u₀)) X x a · exact mem_union_right _ (mem_filter.mpr ⟨haK, fun h' => hnc ⟨h, h'⟩⟩) · exact mem_union_left _ (mem_filter.mpr ⟨haK, h⟩) have hc := card_le_card hsub have hu := card_union_le ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X x a)) ((range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => ¬ cleanAt v (U.filter (fun u => u < u₀)) X' x' a)) have hb1 := hbad X x have hb2 := hbad X' x' rw [card_range] at hsplit omega open Classical in /-- Common clean starts whose realiser from `x` lies outside `G` give distinct range positions of `x` outside `G`. -/ theorem clean_out_le {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (X : Finset (ZMod n)) (x : ZMod n) (G : Finset (ZMod n)) (C : Finset ℕ) (hC : ∀ a ∈ C, a + 5 < (U.filter (fun u => u < u₀)).card ∧ cleanAt v (U.filter (fun u => u < u₀)) X x a) : (C.filter (fun a => Tu v (usort (U.filter (fun u => u < u₀)) a) x ∉ G)).card ≤ ((Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∉ G)).card := by refine card_le_card_of_injOn (fun a => (Tu v (usort (U.filter (fun u => u < u₀)) a) x - x).val) (fun a ha => ?_) (fun a ha b hb hab => ?_) · obtain ⟨haC, hout⟩ := mem_filter.mp ha obtain ⟨haK, hc⟩ := hC a haC have hus := usort_mem (show a < (U.filter (fun u => u < u₀)).card by omega) have hxa : x ∈ Au v (usort (U.filter (fun u => u < u₀)) a) := by have := hc.1 0 (by omega); simpa using this refine mem_filter.mpr ⟨pos_mem_Fu0 (mem_filter.mp hus).2 hxa, ?_⟩ simp only rw [add_off] exact hout · have ha' := mem_filter.mp ha have hb' := mem_filter.mp hb obtain ⟨haK, hca⟩ := hC a ha'.1 obtain ⟨hbK, hcb⟩ := hC b hb'.1 have hxa : x ∈ Au v (usort (U.filter (fun u => u < u₀)) a) := by have := hca.1 0 (by omega); simpa using this have hxb : x ∈ Au v (usort (U.filter (fun u => u < u₀)) b) := by have := hcb.1 0 (by omega); simpa using this have hab' : (Tu v (usort (U.filter (fun u => u < u₀)) a) x - x).val = (Tu v (usort (U.filter (fun u => u < u₀)) b) x - x).val := hab by_contra hne' rcases lt_or_gt_of_ne hne' with h | h · have := pos_strict hv (usort_lt h (by omega)) hxa hxb omega · have := pos_strict hv (usort_lt h (by omega)) hxb hxa omega open Classical in /-- **§11.15(c) / Lemma 11.17′ for concentric solid stretches.** Two rotations about the SAME centre `O`, good sets `G ⊆ goodG(excX O ω)`, `G′ ⊆ goodG(excX O ω′)` each on one circle about `O` (through `v_{x₀}`, `v_{x₀′}`), whose vertices `x₀ ∈ G`, `x₀′ ∈ G′` have at most `(K + K/480)/10` range positions outside `G`, `G′`: the two circles coincide. -/ theorem concentric_solid {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {O ω ω' : ℂ} (hω : ‖ω‖ = 1) (hω' : ‖ω'‖ = 1) (G G' : Finset (ZMod n)) (hGg : G ⊆ goodG v U u₀ (excX v O ω)) (hGg' : G' ⊆ goodG v U u₀ (excX v O ω')) {x₀ x₀' : ZMod n} (hx₀ : x₀ ∈ G) (hx₀' : x₀' ∈ G') (hfew : (((Fu0 v u₀ x₀).filter (fun j : ℕ => x₀ + (j : ZMod n) ∉ G)).card : ℝ) ≤ ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) / 10) (hfew' : (((Fu0 v u₀ x₀').filter (fun j : ℕ => x₀' + (j : ZMod n) ∉ G')).card : ℝ) ≤ ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) / 10) (hrad : ∀ z ∈ G, ‖v z - O‖ = ‖v x₀ - O‖) (hrad' : ∀ z ∈ G', ‖v z - O‖ = ‖v x₀' - O‖) : ‖v x₀ - O‖ = ‖v x₀' - O‖ := by obtain ⟨Us, hUs⟩ : ∃ S, S = U.filter (fun u => u < u₀) := ⟨_, rfl⟩ have hKR : (30 : ℝ) ≤ Us.card := by rw [hUs]; exact_mod_cast hK30 obtain ⟨C, hCdef⟩ : ∃ C : Finset ℕ, C = (range ((U.filter (fun u => u < u₀)).card - 5)).filter (fun a => cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x₀ a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω') x₀' a) := ⟨_, rfl⟩ have hcc := clean_count2 hv U u₀ (excX v O ω) (excX v O ω') x₀ x₀' rw [← hCdef] at hcc have hg := mem_filter.mp (hGg hx₀) have hg' := mem_filter.mp (hGg' hx₀') have hCR : (73 / 80 : ℝ) * (U.filter (fun u => u < u₀)).card - 5 ≤ (C.card : ℝ) := by have hK5 : 5 ≤ (U.filter (fun u => u < u₀)).card := by omega have hcR : (((U.filter (fun u => u < u₀)).card - 5 : ℕ) : ℝ) ≤ (C.card : ℝ) + (6 * ((dfc v (U.filter (fun u => u < u₀)) x₀ : ℝ) + dfc v (U.filter (fun u => u < u₀)) x₀') + 5 * ((nfc v U u₀ x₀ : ℝ) + nfc v U u₀ x₀' + bdc v (excX v O ω) u₀ x₀ + bdc v (excX v O ω') u₀ x₀')) := by exact_mod_cast hcc rw [Nat.cast_sub hK5] at hcR push_cast at hcR linarith [hg.2.1, hg.2.2.1, hg.2.2.2, hg'.2.1, hg'.2.2.1, hg'.2.2.2] have hCmem : ∀ a ∈ C, a + 5 < (U.filter (fun u => u < u₀)).card ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω) x₀ a ∧ cleanAt v (U.filter (fun u => u < u₀)) (excX v O ω') x₀' a := by intro a ha rw [hCdef, mem_filter, mem_range] at ha exact ⟨by omega, ha.2.1, ha.2.2⟩ have hB1 := clean_out_le hv U u₀ (excX v O ω) x₀ G C (fun a ha => ⟨(hCmem a ha).1, (hCmem a ha).2.1⟩) have hB2 := clean_out_le hv U u₀ (excX v O ω') x₀' G' C (fun a ha => ⟨(hCmem a ha).1, (hCmem a ha).2.2⟩) -- a common clean start realised inside `G` and `G′` have hex : ∃ a ∈ C, Tu v (usort (U.filter (fun u => u < u₀)) a) x₀ ∈ G ∧ Tu v (usort (U.filter (fun u => u < u₀)) a) x₀' ∈ G' := by by_contra hcon push Not at hcon have hsub : C ⊆ C.filter (fun a => Tu v (usort (U.filter (fun u => u < u₀)) a) x₀ ∉ G) ∪ C.filter (fun a => Tu v (usort (U.filter (fun u => u < u₀)) a) x₀' ∉ G') := by intro a ha by_cases h : Tu v (usort (U.filter (fun u => u < u₀)) a) x₀ ∈ G · exact mem_union_right _ (mem_filter.mpr ⟨ha, hcon a ha h⟩) · exact mem_union_left _ (mem_filter.mpr ⟨ha, h⟩) have h1 := (card_le_card hsub).trans (card_union_le _ _) have h1R : (C.card : ℝ) ≤ ((C.filter (fun a => Tu v (usort (U.filter (fun u => u < u₀)) a) x₀ ∉ G)).card : ℝ) + ((C.filter (fun a => Tu v (usort (U.filter (fun u => u < u₀)) a) x₀' ∉ G')).card : ℝ) := by exact_mod_cast h1 have h2 : ((C.filter (fun a => Tu v (usort (U.filter (fun u => u < u₀)) a) x₀ ∉ G)).card : ℝ) ≤ (((Fu0 v u₀ x₀).filter (fun j : ℕ => x₀ + (j : ZMod n) ∉ G)).card : ℝ) := by exact_mod_cast hB1 have h3 : ((C.filter (fun a => Tu v (usort (U.filter (fun u => u < u₀)) a) x₀' ∉ G')).card : ℝ) ≤ (((Fu0 v u₀ x₀').filter (fun j : ℕ => x₀' + (j : ZMod n) ∉ G')).card : ℝ) := by exact_mod_cast hB2 have hK : (30 : ℝ) ≤ (U.filter (fun u => u < u₀)).card := by exact_mod_cast hK30 linarith obtain ⟨a, haC, hyG, hyG'⟩ := hex obtain ⟨haK, hc, hc'⟩ := hCmem a haC -- the two blocks have hb := block_rot hc have hb' := block_rot hc' have hdist : ∀ k ≤ 4, ‖(v x₀ - O) - ω ^ k * (v (Tu v (usort (U.filter (fun u => u < u₀)) a) x₀) - O)‖ = usort (U.filter (fun u => u < u₀)) (a + k) := by intro k hk have h1 := (Tu_spec (hc.1 k (by omega))).2 rw [dist_eq_norm] at h1 rw [← hb k (by omega)] have e : (v x₀ - O) - (v (Tu v (usort (U.filter (fun u => u < u₀)) (a + k)) x₀) - O) = v x₀ - v (Tu v (usort (U.filter (fun u => u < u₀)) (a + k)) x₀) := by ring rw [e] exact h1 have hdist' : ∀ k ≤ 4, ‖(v x₀' - O) - ω' ^ k * (v (Tu v (usort (U.filter (fun u => u < u₀)) a) x₀') - O)‖ = usort (U.filter (fun u => u < u₀)) (a + k) := by intro k hk have h1 := (Tu_spec (hc'.1 k (by omega))).2 rw [dist_eq_norm] at h1 rw [← hb' k (by omega)] have e : (v x₀' - O) - (v (Tu v (usort (U.filter (fun u => u < u₀)) (a + k)) x₀') - O) = v x₀' - v (Tu v (usort (U.filter (fun u => u < u₀)) (a + k)) x₀') := by ring rw [e] exact h1 -- angles: `Im ω > 0`, `Im ω′ > 0` have him : ∀ w : ℂ, ‖w‖ = 1 → 0 < Complex.arg w → Complex.arg w < Real.pi / 8 → 0 < w.im := by intro w hw h0 h8 have hs := Complex.sin_arg w rw [hw, div_one] at hs rw [← hs] exact Real.sin_pos_of_pos_of_lt_pi h0 (by linarith [Real.pi_pos]) obtain ⟨hα0, hα8⟩ := clean_rot_small hv hc obtain ⟨hα0', hα8'⟩ := clean_rot_small hv hc' -- the radius is positive have hr0 : 0 < ‖v x₀ - O‖ := by rcases (norm_nonneg (v x₀ - O)).lt_or_eq with h | h · exact h · exfalso have hy0 : ‖v (Tu v (usort (U.filter (fun u => u < u₀)) a) x₀) - O‖ = 0 := by rw [hrad _ hyG]; exact h.symm have hx0 : v x₀ - O = 0 := norm_eq_zero.mp h.symm have hq0 : v (Tu v (usort (U.filter (fun u => u < u₀)) a) x₀) - O = 0 := norm_eq_zero.mp hy0 have h0 := hdist 0 (by norm_num) have h1 := hdist 1 (by norm_num) rw [hx0, hq0] at h0 h1 simp at h0 h1 have := usort_lt (S := U.filter (fun u => u < u₀)) (show a < a + 1 by omega) (by omega) linarith exact concentric_radius hr0 (norm_nonneg _) rfl (hrad _ hyG) rfl (hrad' _ hyG') hω hω' (him ω hω hα0 hα8) (him ω' hω' hα0' hα8') (fun k hk => by rw [hdist k hk, hdist' k hk]) end Erdos94ThmA /-! ### Thin vertices lie near the corners (INVERSE §11.15(d), §11.16(c)), part 1: caps (projection) and strips (width) -/ namespace Erdos94ThmA open Finset /-- Every vertex lies (weakly) to the left of every edge line of a counterclockwise polygon. -/ theorem left_of_edge {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (a z : ZMod n) : 0 ≤ cr (edge v a) (v z - v a) := by by_cases hz : z = a · rw [hz, sub_self] simp [cr_eq] by_cases hz1 : z = a + 1 · rw [hz1] unfold edge simp only [cr_eq] nlinarith [sq_nonneg 0] · have h1 : ((a + 1) - a).val = 1 := by rw [add_sub_cancel_left, val_one_of_three hn] have h0 : (z - a).val ≠ 0 := by intro h apply hz have := (ZMod.val_eq_zero (z - a)).mp h linear_combination this have h2 : (z - a).val ≠ 1 := by intro h apply hz1 have : z - a = 1 := by apply ZMod.val_injective rw [h, val_one_of_three hn] linear_combination this have := ccw_cyclic hv (a := a) (b := a + 1) (c := z) (by rw [h1]; norm_num) (by rw [h1]; omega) unfold edge exact this.le /-- **Cap lemma (projection on the bisector).** If the open arc `x → x+p+1` turns by at most `π − η`, every vertex of the arc is within `|v_x v_{x+p+1}| / sin(η/2)` of `v_x`. -/ theorem cap_near {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (x : ZMod n) (p : ℕ) {η : ℝ} (hη0 : 0 < η) (hτ : turning v x p ≤ Real.pi - η) {i : ℕ} (hi : i ≤ p + 1) : Real.sin (η / 2) * ‖v (x + (i : ZMod n)) - v x‖ ≤ ‖v (x + ((p + 1 : ℕ) : ZMod n)) - v x‖ := by have he0 : edge v x ≠ 0 := edge_ne_zero hv x have hen : 0 < ‖edge v x‖ := norm_pos_iff.mpr he0 obtain ⟨φ, hφ⟩ : ∃ φ : ℝ, φ = turning v x p / 2 := ⟨_, rfl⟩ obtain ⟨ψ, hψ⟩ : ∃ ψ : ℂ, ψ = Complex.exp (((-φ : ℝ) : ℂ) * Complex.I) := ⟨_, rfl⟩ have hψn : ‖ψ‖ = 1 := by rw [hψ]; exact Complex.norm_exp_ofReal_mul_I _ have hτp0 : 0 ≤ turning v x p := turning_nonneg hv x p have hedge : ∀ j ≤ p, Real.sin (η / 2) * ‖edge v (x + (j : ZMod n)) / edge v x‖ ≤ (ψ * (edge v (x + (j : ZMod n)) / edge v x)).re := by intro j hj obtain ⟨r, hr, he⟩ := edge_rot hv x j have hq : edge v (x + (j : ZMod n)) / edge v x = (r : ℂ) * Complex.exp ((turning v x j : ℝ) * Complex.I) := by rw [he] field_simp rw [hq] have hn : ‖(r : ℂ) * Complex.exp ((turning v x j : ℝ) * Complex.I)‖ = r := by rw [norm_mul, Complex.norm_exp_ofReal_mul_I, mul_one, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hr] rw [hn] have hre : (ψ * ((r : ℂ) * Complex.exp ((turning v x j : ℝ) * Complex.I))).re = r * Real.cos (turning v x j - φ) := by have e : ψ * ((r : ℂ) * Complex.exp ((turning v x j : ℝ) * Complex.I)) = (r : ℂ) * Complex.exp (((turning v x j - φ : ℝ) : ℂ) * Complex.I) := by rw [hψ, mul_left_comm, ← Complex.exp_add] congr 2 push_cast ring rw [e, Complex.re_ofReal_mul, Complex.exp_ofReal_mul_I_re] rw [hre] have hτj0 : 0 ≤ turning v x j := turning_nonneg hv x j have hτjp : turning v x j ≤ turning v x p := turning_mono hv x hj have habs : |turning v x j - φ| ≤ Real.pi / 2 - η / 2 := by rw [abs_le] constructor <;> linarith have hcos : Real.sin (η / 2) ≤ Real.cos (turning v x j - φ) := by rw [← Real.cos_pi_div_two_sub, ← Real.cos_abs (turning v x j - φ)] exact Real.cos_le_cos_of_nonneg_of_le_pi (abs_nonneg _) (by linarith [Real.pi_pos]) habs have := mul_le_mul_of_nonneg_left hcos hr.le linarith have hsin0 : 0 ≤ Real.sin (η / 2) := by apply Real.sin_nonneg_of_nonneg_of_le_pi (by linarith) have : η ≤ Real.pi := by linarith linarith have hnonneg : ∀ j ≤ p, 0 ≤ (ψ * (edge v (x + (j : ZMod n)) / edge v x)).re := fun j hj => le_trans (mul_nonneg hsin0 (norm_nonneg _)) (hedge j hj) have hsum : ∀ m : ℕ, (v (x + (m : ZMod n)) - v x) / edge v x = ∑ j ∈ range m, edge v (x + (j : ZMod n)) / edge v x := by intro m rw [sub_eq_sum_edges, sum_div] -- lower bound at `i` have hlow : Real.sin (η / 2) * ‖(v (x + (i : ZMod n)) - v x) / edge v x‖ ≤ (ψ * ((v (x + (i : ZMod n)) - v x) / edge v x)).re := by rw [hsum i, mul_sum, Complex.re_sum] calc Real.sin (η / 2) * ‖∑ j ∈ range i, edge v (x + (j : ZMod n)) / edge v x‖ ≤ Real.sin (η / 2) * ∑ j ∈ range i, ‖edge v (x + (j : ZMod n)) / edge v x‖ := mul_le_mul_of_nonneg_left (norm_sum_le _ _) hsin0 _ = ∑ j ∈ range i, Real.sin (η / 2) * ‖edge v (x + (j : ZMod n)) / edge v x‖ := by rw [mul_sum] _ ≤ ∑ j ∈ range i, (ψ * (edge v (x + (j : ZMod n)) / edge v x)).re := sum_le_sum (fun j hj => hedge j (by have := mem_range.mp hj; omega)) -- monotonicity in the end point have hmono : (ψ * ((v (x + (i : ZMod n)) - v x) / edge v x)).re ≤ (ψ * ((v (x + ((p + 1 : ℕ) : ZMod n)) - v x) / edge v x)).re := by rw [hsum i, hsum (p + 1), mul_sum, mul_sum, Complex.re_sum, Complex.re_sum] exact sum_le_sum_of_subset_of_nonneg (range_mono hi) (fun j hj _ => hnonneg j (by have := mem_range.mp hj; omega)) have hup : (ψ * ((v (x + ((p + 1 : ℕ) : ZMod n)) - v x) / edge v x)).re ≤ ‖(v (x + ((p + 1 : ℕ) : ZMod n)) - v x) / edge v x‖ := by have := Complex.re_le_norm (ψ * ((v (x + ((p + 1 : ℕ) : ZMod n)) - v x) / edge v x)) rwa [norm_mul, hψn, one_mul] at this have hall := le_trans hlow (le_trans hmono hup) rw [norm_div, norm_div] at hall have h2 : Real.sin (η / 2) * ‖v (x + (i : ZMod n)) - v x‖ / ‖edge v x‖ ≤ ‖v (x + ((p + 1 : ℕ) : ZMod n)) - v x‖ / ‖edge v x‖ := by rw [mul_div_assoc] exact hall exact (div_le_div_iff_of_pos_right hen).mp h2 /-- `|e^{iθ} + 1| ≤ 2|θ − π|` when `|θ − π| ≤ 1`. -/ theorem norm_exp_add_one_le {θ : ℝ} (h : |θ - Real.pi| ≤ 1) : ‖Complex.exp (θ * Complex.I) + 1‖ ≤ 2 * |θ - Real.pi| := by have e : Complex.exp (θ * Complex.I) + 1 = -(Complex.exp (((θ - Real.pi : ℝ) : ℂ) * Complex.I) - 1) := by have : Complex.exp (((θ - Real.pi : ℝ) : ℂ) * Complex.I) = -Complex.exp (θ * Complex.I) := by rw [show (((θ - Real.pi : ℝ) : ℂ) * Complex.I) = θ * Complex.I - Real.pi * Complex.I by push_cast; ring, Complex.exp_sub, Complex.exp_pi_mul_I] field_simp rw [this] ring rw [e, norm_neg] have hn : ‖(((θ - Real.pi : ℝ) : ℂ) * Complex.I)‖ = |θ - Real.pi| := by rw [norm_mul, Complex.norm_I, mul_one, Complex.norm_real, Real.norm_eq_abs] have := Complex.norm_exp_sub_one_le (x := ((θ - Real.pi : ℝ) : ℂ) * Complex.I) (by rw [hn]; exact h) rwa [hn] at this /-- `Re(conj(i·e/|e|)·w) = (e × w)/|e|`. -/ theorem re_normal_eq {e w : ℂ} (he : e ≠ 0) : ((starRingEnd ℂ) (Complex.I * (e / (‖e‖ : ℂ))) * w).re = cr e w / ‖e‖ := by have hen : (‖e‖ : ℂ) ≠ 0 := by exact_mod_cast (norm_pos_iff.mpr he).ne' rw [cr_eq] have e1 : (starRingEnd ℂ) (Complex.I * (e / (‖e‖ : ℂ))) * w = (-Complex.I * ((starRingEnd ℂ) e * w)) * (((‖e‖)⁻¹ : ℝ) : ℂ) := by simp only [map_mul, map_div₀, Complex.conj_I, Complex.conj_ofReal] push_cast field_simp rw [e1, Complex.mul_re] simp only [Complex.ofReal_re, Complex.ofReal_im, mul_zero, sub_zero, Complex.mul_re, Complex.mul_im, Complex.neg_re, Complex.neg_im, Complex.I_re, Complex.I_im, Complex.conj_re, Complex.conj_im] field_simp ring /-- **Strip lemma.** If the open arc `x → y = x+p+1` turns by `τ` with `|τ − π| ≤ η ≤ 1`, all vertices lie in a strip of width `|v_x v_y| + 2ηD` orthogonal to the edge `e_x` (`D` ≥ every distance): the supporting lines at `x` and at `y` are nearly antiparallel. -/ theorem strip_bound {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (x : ZMod n) (p : ℕ) {η D : ℝ} (hη1 : η ≤ 1) (hτ : |turning v x p - Real.pi| ≤ η) (hD : ∀ a b : ZMod n, ‖v a - v b‖ ≤ D) (z z' : ZMod n) : ((starRingEnd ℂ) (Complex.I * (edge v x / (‖edge v x‖ : ℂ))) * (v z - v z')).re ≤ ‖v (x + ((p + 1 : ℕ) : ZMod n)) - v x‖ + 2 * η * D := by have hL := ccw_leftTurns hn hv have he0 : edge v x ≠ 0 := edge_ne_zero hL x have hen : 0 < ‖edge v x‖ := norm_pos_iff.mpr he0 obtain ⟨N, hN⟩ : ∃ N : ℂ, N = Complex.I * (edge v x / (‖edge v x‖ : ℂ)) := ⟨_, rfl⟩ rw [← hN] have hNn : ‖N‖ = 1 := by rw [hN, norm_mul, Complex.norm_I, one_mul, norm_div, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hen, div_self hen.ne'] -- the edge entering `y` obtain ⟨y, hy⟩ : ∃ y, y = x + ((p + 1 : ℕ) : ZMod n) := ⟨_, rfl⟩ rw [← hy] have hey : edge v (x + (p : ZMod n)) = v y - v (x + (p : ZMod n)) := by unfold edge rw [hy] push_cast ring_nf obtain ⟨r, hr, her⟩ := edge_rot hL x p have hep0 : edge v (x + (p : ZMod n)) ≠ 0 := edge_ne_zero hL _ obtain ⟨Nb, hNb⟩ : ∃ Nb : ℂ, Nb = Complex.I * (edge v (x + (p : ZMod n)) / (‖edge v (x + (p : ZMod n))‖ : ℂ)) := ⟨_, rfl⟩ have hNbN : Nb = N * Complex.exp ((turning v x p : ℝ) * Complex.I) := by rw [hNb, hN, her] have hn1 : ‖edge v x * ((r : ℂ) * Complex.exp ((turning v x p : ℝ) * Complex.I))‖ = ‖edge v x‖ * r := by rw [norm_mul, norm_mul, Complex.norm_exp_ofReal_mul_I, mul_one, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hr] rw [hn1] have hr0 : (r : ℂ) ≠ 0 := by exact_mod_cast hr.ne' have hen' : (‖edge v x‖ : ℂ) ≠ 0 := by exact_mod_cast hen.ne' push_cast field_simp -- the two half-planes have hA : ∀ w : ZMod n, 0 ≤ ((starRingEnd ℂ) N * (v w - v x)).re := by intro w rw [hN, re_normal_eq he0] exact div_nonneg (left_of_edge hn hv x w) hen.le have hB : ∀ w : ZMod n, 0 ≤ ((starRingEnd ℂ) Nb * (v w - v y)).re := by intro w rw [hNb, re_normal_eq hep0] have h1 := left_of_edge hn hv (x + (p : ZMod n)) w have h2 : cr (edge v (x + (p : ZMod n))) (v w - v y) = cr (edge v (x + (p : ZMod n))) (v w - v (x + (p : ZMod n))) := by have : v w - v y = (v w - v (x + (p : ZMod n))) - edge v (x + (p : ZMod n)) := by rw [hey]; ring rw [this] simp only [cr_eq, Complex.sub_re, Complex.sub_im] ring rw [h2] exact div_nonneg h1 (norm_nonneg _) -- `|N + N_b| ≤ 2η` have hsum : ‖N + Nb‖ ≤ 2 * η := by rw [hNbN, show N + N * Complex.exp ((turning v x p : ℝ) * Complex.I) = N * (Complex.exp ((turning v x p : ℝ) * Complex.I) + 1) by ring, norm_mul, hNn, one_mul] exact le_trans (norm_exp_add_one_le (le_trans hτ hη1)) (by linarith) have hη0 : 0 ≤ η := le_trans (abs_nonneg _) hτ have hz : ((starRingEnd ℂ) N * (v z - v y)).re ≤ 2 * η * D := by have h1 : ((starRingEnd ℂ) N * (v z - v y)).re = ((starRingEnd ℂ) (N + Nb) * (v z - v y)).re - ((starRingEnd ℂ) Nb * (v z - v y)).re := by rw [map_add, add_mul, Complex.add_re] ring have h2 : ((starRingEnd ℂ) (N + Nb) * (v z - v y)).re ≤ ‖N + Nb‖ * ‖v z - v y‖ := by have := Complex.re_le_norm ((starRingEnd ℂ) (N + Nb) * (v z - v y)) rwa [norm_mul, Complex.norm_conj] at this have h3 : ‖N + Nb‖ * ‖v z - v y‖ ≤ 2 * η * D := mul_le_mul hsum (hD z y) (norm_nonneg _) (by linarith) linarith [hB z] have hxy : ((starRingEnd ℂ) N * (v y - v x)).re ≤ ‖v y - v x‖ := by have := Complex.re_le_norm ((starRingEnd ℂ) N * (v y - v x)) rwa [norm_mul, Complex.norm_conj, hNn, one_mul] at this have hsplit : ((starRingEnd ℂ) N * (v z - v z')).re = ((starRingEnd ℂ) N * (v z - v y)).re + ((starRingEnd ℂ) N * (v y - v x)).re - ((starRingEnd ℂ) N * (v z' - v x)).re := by rw [← Complex.add_re, ← Complex.sub_re] congr 1 ring linarith [hA z'] /-- **No arc over a short chord turns by ≈ π in a fat polygon** (fatness = every directional extent is `≥ ζ₀D`). -/ theorem no_half_turn {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {ζ₀ D η : ℝ} (hfat : ∀ u : ℂ, ‖u‖ = 1 → ∃ z z' : ZMod n, ζ₀ * D ≤ ((starRingEnd ℂ) u * (v z - v z')).re) (hD : ∀ a b : ZMod n, ‖v a - v b‖ ≤ D) (hη1 : η ≤ 1) (x : ZMod n) (p : ℕ) (hsmall : ‖v (x + ((p + 1 : ℕ) : ZMod n)) - v x‖ + 2 * η * D < ζ₀ * D) : η < |turning v x p - Real.pi| := by by_contra h push Not at h have he0 : edge v x ≠ 0 := edge_ne_zero (ccw_leftTurns hn hv) x have hen : 0 < ‖edge v x‖ := norm_pos_iff.mpr he0 have hu : ‖Complex.I * (edge v x / (‖edge v x‖ : ℂ))‖ = 1 := by rw [norm_mul, Complex.norm_I, one_mul, norm_div, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hen, div_self hen.ne'] obtain ⟨z, z', hz⟩ := hfat _ hu have := strip_bound hn hv x p hη1 h hD z z' linarith end Erdos94ThmA /-! ### Thin vertices lie near the corners, part 2: the ≤ 4 change points of the edge direction; thin ⇒ near one -/ namespace Erdos94ThmA open Finset /-- The cumulative turning `θ(m) = τ(0, m)` from the edge `e_0` is `< 2π` for `m < n`. -/ theorem theta_lt_two_pi {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {m : ℕ} (hm : m < n) : turning v 0 m < 2 * Real.pi := by have htot := turning_total_eq hn hv rw [← turning_full v 0] at htot have hs := turning_split v 0 m (n - m) rw [show m + (n - m) = n by omega] at hs have hpos : 0 < turning v (0 + (m : ZMod n)) (n - m) := by unfold turning exact sum_pos (fun i _ => extAng_pos (ccw_leftTurns hn hv) _) (nonempty_range_iff.mpr (by omega)) linarith open Classical in /-- The change point of class `k`: the first index `i < n` with `θ(i) ≥ kπ/2` (`0` if none; `chpt v 0 = 0`). -/ noncomputable def chpt {n : ℕ} (v : ZMod n → ℂ) (k : ℕ) : ZMod n := if h : ∃ i : ℕ, i < n ∧ (k : ℝ) * (Real.pi / 2) ≤ turning v 0 i then ((Nat.find h : ℕ) : ZMod n) else 0 open Classical in /-- **Every arc turning by `≥ π/2` contains a change point.** -/ theorem cap_meets_chpt {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (s : ZMod n) (p : ℕ) (hp : p + 1 < n) (hτ : Real.pi / 2 ≤ turning v s p) : ∃ k < 4, ∃ j ≤ p + 1, s + (j : ZMod n) = chpt v k := by have hL := ccw_leftTurns hn hv obtain ⟨s₀, hs₀⟩ : ∃ s₀ : ℕ, s₀ = s.val := ⟨_, rfl⟩ have hs₀n : s₀ < n := by rw [hs₀]; exact ZMod.val_lt s have hscast : ((s₀ : ℕ) : ZMod n) = s := by rw [hs₀, ZMod.natCast_zmod_val] by_cases hwrap : n ≤ s₀ + p + 1 · refine ⟨0, by norm_num, n - s₀, by omega, ?_⟩ have hex : ∃ i : ℕ, i < n ∧ ((0 : ℕ) : ℝ) * (Real.pi / 2) ≤ turning v 0 i := ⟨0, by omega, by simp [turning]⟩ have h0 : chpt v 0 = 0 := by unfold chpt rw [dif_pos hex] have : Nat.find hex = 0 := (Nat.find_eq_zero hex).mpr ⟨by omega, by simp [turning]⟩ rw [this, Nat.cast_zero] rw [h0, ← hscast, ← Nat.cast_add, show s₀ + (n - s₀) = n by omega, ZMod.natCast_self] · push Not at hwrap have hsplit := turning_split v 0 s₀ p rw [zero_add, hscast] at hsplit have hθ0 : 0 ≤ turning v 0 s₀ := turning_nonneg hL 0 s₀ have hpi2 : 0 < Real.pi / 2 := by positivity obtain ⟨k, hk⟩ : ∃ k : ℕ, k = ⌊turning v 0 s₀ / (Real.pi / 2)⌋₊ + 1 := ⟨_, rfl⟩ have hk1 : turning v 0 s₀ < (k : ℝ) * (Real.pi / 2) := by have h := Nat.lt_floor_add_one (turning v 0 s₀ / (Real.pi / 2)) rw [div_lt_iff₀ hpi2] at h rw [hk] push_cast exact h have hk2 : (k : ℝ) * (Real.pi / 2) ≤ turning v 0 s₀ + Real.pi / 2 := by have h := Nat.floor_le (div_nonneg hθ0 hpi2.le) rw [le_div_iff₀ hpi2] at h rw [hk] push_cast linarith have hex : ∃ i : ℕ, i < n ∧ (k : ℝ) * (Real.pi / 2) ≤ turning v 0 i := ⟨s₀ + p, by omega, by linarith⟩ have hlt := theta_lt_two_pi hn hv (show s₀ + p < n by omega) have hk4 : k < 4 := by have h1 : (k : ℝ) * (Real.pi / 2) < 4 * (Real.pi / 2) := by linarith have h2 : (k : ℝ) < 4 := lt_of_mul_lt_mul_right h1 hpi2.le exact_mod_cast h2 have hspec := Nat.find_spec hex have hgt : s₀ < Nat.find hex := by by_contra hc push Not at hc have := turning_mono hL 0 hc linarith [hspec.2] refine ⟨k, hk4, Nat.find hex - s₀, ?_, ?_⟩ · have := Nat.find_min' hex ⟨show s₀ + p < n by omega, by linarith⟩ omega · unfold chpt rw [dif_pos hex, ← hscast, ← Nat.cast_add, Nat.add_sub_cancel' hgt.le] open Classical in /-- **Thin vertices are near a change point** (INVERSE §11.15(d)). In a polygon all of whose directional extents are `≥ ζ₀D` (`D` ≥ every distance), if `u₀ + 2ηD < ζ₀D` with `0 < η ≤ 1`, every thin vertex `x` at scale `u₀` satisfies `sin(η/2)·|v_x v_c| ≤ (1 + sin(η/2))u₀` for one of the ≤ 4 change points `c = chpt v k`, `k < 4`: its middle partner `y` cuts off a cap turning by `∈ [π/2, π − η]` (the side turning by ≈ π is excluded by the strip lemma, and the two sides turn by `< 2π` in all), the cap contains a change point, and the cap lemma bounds its size. -/ theorem thin_near {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {ζ₀ D η u₀ : ℝ} (hη0 : 0 < η) (hη1 : η ≤ 1) (hfat : ∀ u : ℂ, ‖u‖ = 1 → ∃ z z' : ZMod n, ζ₀ * D ≤ ((starRingEnd ℂ) u * (v z - v z')).re) (hD : ∀ a b : ZMod n, ‖v a - v b‖ ≤ D) (hsmall : u₀ + 2 * η * D < ζ₀ * D) {x : ZMod n} (hx : x ∈ thinB v u₀) : ∃ k < 4, Real.sin (η / 2) * ‖v x - v (chpt v k)‖ ≤ (1 + Real.sin (η / 2)) * u₀ := by have hL := ccw_leftTurns hn hv unfold thinB at hx obtain ⟨y, hxy, hns, hd⟩ := (mem_filter.mp hx).2 unfold isShort at hns push Not at hns obtain ⟨hnF, hnB⟩ := hns rw [inB_iff_inF hL] at hnB have hyx : 0 < (y - x).val := by rcases Nat.eq_zero_or_pos (y - x).val with h | h · exfalso apply hxy have := (ZMod.val_eq_zero (y - x)).mp h linear_combination -this · exact h have hxy' : 0 < (x - y).val := by rcases Nat.eq_zero_or_pos (x - y).val with h | h · exfalso apply hxy have := (ZMod.val_eq_zero (x - y)).mp h linear_combination this · exact h have hoff := off_swap hxy have hyn := ZMod.val_lt (y - x) have hxn := ZMod.val_lt (x - y) obtain ⟨p₁, hp₁⟩ : ∃ p, p = (y - x).val - 1 := ⟨_, rfl⟩ obtain ⟨p₂, hp₂⟩ : ∃ p, p = (x - y).val - 1 := ⟨_, rfl⟩ have hy1 : x + ((p₁ + 1 : ℕ) : ZMod n) = y := by rw [show p₁ + 1 = (y - x).val by omega, add_off] have hx1 : y + ((p₂ + 1 : ℕ) : ZMod n) = x := by rw [show p₂ + 1 = (x - y).val by omega, add_off] have hτ1 : Real.pi / 2 ≤ turning v x p₁ := by by_contra h push Not at h exact hnF ((inF_iff hL x y).mpr ⟨hyx, by rw [← hp₁]; exact h⟩) have hτ2 : Real.pi / 2 ≤ turning v y p₂ := by by_contra h push Not at h exact hnB ((inF_iff hL y x).mpr ⟨hxy', by rw [← hp₂]; exact h⟩) have htot : turning v x p₁ + turning v y p₂ < 2 * Real.pi := by have h1 := turning_total_eq hn hv rw [← turning_full v x] at h1 have h2 := turning_split v x (p₁ + 1) (p₂ + 1) rw [show p₁ + 1 + (p₂ + 1) = n by omega, h1, hy1, turning_succ, turning_succ] at h2 have e1 := extAng_pos hL (x + (p₁ : ZMod n)) have e2 := extAng_pos hL (y + (p₂ : ZMod n)) linarith have hd0 : 0 ≤ dist (v x) (v y) := dist_nonneg have hsin : 0 < Real.sin (η / 2) := Real.sin_pos_of_pos_of_lt_pi (by linarith) (by linarith [Real.two_le_pi]) have hd' : ‖v (x + ((p₁ + 1 : ℕ) : ZMod n)) - v x‖ + 2 * η * D < ζ₀ * D := by rw [hy1, ← dist_eq_norm, dist_comm] linarith have hnh := no_half_turn hn hv hfat hD hη1 x p₁ hd' rcases lt_abs.mp hnh with h | h · -- the arc `x → y` turns by more than `π + η`: the arc `y → x` is the cap have hτ2' : turning v y p₂ ≤ Real.pi - η := by linarith obtain ⟨k, hk, j, hj, hc⟩ := cap_meets_chpt hn hv y p₂ (by omega) hτ2 have hcap := cap_near hL y p₂ hη0 hτ2' hj rw [hc, hx1] at hcap refine ⟨k, hk, ?_⟩ have htri : ‖v x - v (chpt v k)‖ ≤ ‖v x - v y‖ + ‖v (chpt v k) - v y‖ := by have := norm_sub_le (v x - v y) (v (chpt v k) - v y) rwa [show v x - v y - (v (chpt v k) - v y) = v x - v (chpt v k) by ring] at this have hxyn : ‖v x - v y‖ < u₀ := by rw [← dist_eq_norm]; exact hd have h1 : Real.sin (η / 2) * ‖v x - v (chpt v k)‖ ≤ Real.sin (η / 2) * ‖v x - v y‖ + Real.sin (η / 2) * ‖v (chpt v k) - v y‖ := by rw [← mul_add] exact mul_le_mul_of_nonneg_left htri hsin.le have h2 : Real.sin (η / 2) * ‖v x - v y‖ ≤ Real.sin (η / 2) * u₀ := mul_le_mul_of_nonneg_left hxyn.le hsin.le rw [show ‖v x - v y‖ = ‖v y - v x‖ by rw [norm_sub_rev]] at hcap rw [show ‖v y - v x‖ = ‖v x - v y‖ by rw [norm_sub_rev]] at hcap nlinarith · -- the arc `x → y` is the cap have hτ1' : turning v x p₁ ≤ Real.pi - η := by linarith obtain ⟨k, hk, j, hj, hc⟩ := cap_meets_chpt hn hv x p₁ (by omega) hτ1 have hcap := cap_near hL x p₁ hη0 hτ1' hj rw [hc, hy1] at hcap refine ⟨k, hk, ?_⟩ have hxyn : ‖v y - v x‖ < u₀ := by rw [← dist_eq_norm, dist_comm]; exact hd rw [norm_sub_rev] at hcap nlinarith end Erdos94ThmA /-! ### Thin vertices lie near the corners, part 3: quadrant pieces and the crowding count (INVERSE Lemma 11.25(b)(ii)) -/ namespace Erdos94ThmA open Finset /-- The class (quadrant of the edge direction) of the index `i`: `⌊θ(i)/(π/2)⌋`, `θ(i) = τ(0, i)`. -/ noncomputable def qcls {n : ℕ} (v : ZMod n → ℂ) (i : ℕ) : ℕ := ⌊turning v 0 i / (Real.pi / 2)⌋₊ /-- The unit frame of class `k`: `conj(e_0)/|e_0| · e^{−ikπ/2}`. -/ noncomputable def qfr {n : ℕ} (v : ZMod n → ℂ) (k : ℕ) : ℂ := (starRingEnd ℂ) (edge v 0) / (‖edge v 0‖ : ℂ) * Complex.exp ((-((k : ℝ) * (Real.pi / 2)) : ℝ) * Complex.I) /-- The monotone coordinate of class `k`: `f_k(z) = Re(zψ_k) + Im(zψ_k)`. -/ noncomputable def qf {n : ℕ} (v : ZMod n → ℂ) (k : ℕ) (z : ℂ) : ℝ := (z * qfr v k).re + (z * qfr v k).im /-- The piece label of a vertex: (class, level `⌊f_k(v_x)/u₀⌋`). -/ noncomputable def plab {n : ℕ} (v : ZMod n → ℂ) (u₀ : ℝ) (x : ZMod n) : ℕ × ℤ := (qcls v x.val, ⌊qf v (qcls v x.val) (v x) / u₀⌋) theorem qfr_norm {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (k : ℕ) : ‖qfr v k‖ = 1 := by have h0 := edge_ne_zero hv (0 : ZMod n) have hn : 0 < ‖edge v 0‖ := norm_pos_iff.mpr h0 unfold qfr rw [norm_mul, Complex.norm_exp_ofReal_mul_I, mul_one, norm_div, Complex.norm_conj, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hn, div_self hn.ne'] theorem qf_sub {n : ℕ} (v : ZMod n → ℂ) (k : ℕ) (a b : ℂ) : qf v k (a - b) = qf v k a - qf v k b := by unfold qf rw [sub_mul, Complex.sub_re, Complex.sub_im] ring theorem qf_sum {n : ℕ} (v : ZMod n → ℂ) (k : ℕ) (s : Finset ℕ) (f : ℕ → ℂ) : qf v k (∑ i ∈ s, f i) = ∑ i ∈ s, qf v k (f i) := by unfold qf rw [sum_mul, Complex.re_sum, Complex.im_sum, ← sum_add_distrib] theorem qf_abs_le {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (k : ℕ) (z : ℂ) : |qf v k z| ≤ 2 * ‖z‖ := by unfold qf have h1 := Complex.abs_re_le_norm (z * qfr v k) have h2 := Complex.abs_im_le_norm (z * qfr v k) rw [norm_mul, qfr_norm hv, mul_one] at h1 h2 rw [abs_le] at h1 h2 ⊢ constructor <;> linarith [h1.1, h1.2, h2.1, h2.2] theorem qcls_spec {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) (i : ℕ) : (qcls v i : ℝ) * (Real.pi / 2) ≤ turning v 0 i ∧ turning v 0 i < ((qcls v i : ℝ) + 1) * (Real.pi / 2) := by have hpi2 : 0 < Real.pi / 2 := by positivity have h0 := turning_nonneg hv (0 : ZMod n) i unfold qcls constructor · have := Nat.floor_le (div_nonneg h0 hpi2.le) rwa [le_div_iff₀ hpi2] at this · have := Nat.lt_floor_add_one (turning v 0 i / (Real.pi / 2)) rwa [div_lt_iff₀ hpi2] at this theorem qcls_mono {n : ℕ} {v : ZMod n → ℂ} (hv : LeftTurns v) {i j : ℕ} (h : i ≤ j) : qcls v i ≤ qcls v j := by unfold qcls exact Nat.floor_mono (div_le_div_of_nonneg_right (turning_mono hv 0 h) (by positivity)) theorem qcls_lt_four {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {i : ℕ} (hi : i < n) : qcls v i < 4 := by have h := theta_lt_two_pi hn hv hi have hs := qcls_spec (ccw_leftTurns hn hv) i have hpi2 : 0 < Real.pi / 2 := by positivity have h1 : (qcls v i : ℝ) * (Real.pi / 2) < 4 * (Real.pi / 2) := by linarith [hs.1] have h2 : (qcls v i : ℝ) < 4 := lt_of_mul_lt_mul_right h1 hpi2.le exact_mod_cast h2 /-- An edge of class `k` has `|e| ≤ f_k(e)` (its direction lies in the `k`-th quadrant of the frame). -/ theorem qf_edge {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (l : ℕ) : ‖edge v (l : ZMod n)‖ ≤ qf v (qcls v l) (edge v (l : ZMod n)) := by obtain ⟨r, hr, he⟩ := edge_rot hv (0 : ZMod n) l rw [zero_add] at he have h0 := edge_ne_zero hv (0 : ZMod n) have hn0 : 0 < ‖edge v 0‖ := norm_pos_iff.mpr h0 obtain ⟨φ, hφ⟩ : ∃ φ : ℝ, φ = turning v 0 l - (qcls v l : ℝ) * (Real.pi / 2) := ⟨_, rfl⟩ have hs := qcls_spec hv l have hφ0 : 0 ≤ φ := by rw [hφ]; linarith [hs.1] have hφ1 : φ ≤ Real.pi / 2 := by rw [hφ]; linarith [hs.2] have hexp : Complex.exp ((turning v 0 l : ℝ) * Complex.I) * Complex.exp ((-((qcls v l : ℝ) * (Real.pi / 2)) : ℝ) * Complex.I) = Complex.exp (φ * Complex.I) := by rw [← Complex.exp_add] congr 1 rw [hφ] push_cast ring have hc : edge v 0 * (starRingEnd ℂ) (edge v 0) = (‖edge v 0‖ : ℂ) ^ 2 := by rw [Complex.mul_conj, Complex.normSq_eq_norm_sq] push_cast ring have hen : (‖edge v 0‖ : ℂ) ≠ 0 := by exact_mod_cast hn0.ne' have hprod : edge v (l : ZMod n) * qfr v (qcls v l) = ((‖edge v 0‖ * r : ℝ) : ℂ) * Complex.exp (φ * Complex.I) := by rw [he] unfold qfr rw [show edge v 0 * ((r : ℂ) * Complex.exp ((turning v 0 l : ℝ) * Complex.I)) * ((starRingEnd ℂ) (edge v 0) / (‖edge v 0‖ : ℂ) * Complex.exp ((-((qcls v l : ℝ) * (Real.pi / 2)) : ℝ) * Complex.I)) = (edge v 0 * (starRingEnd ℂ) (edge v 0)) / (‖edge v 0‖ : ℂ) * (r : ℂ) * (Complex.exp ((turning v 0 l : ℝ) * Complex.I) * Complex.exp ((-((qcls v l : ℝ) * (Real.pi / 2)) : ℝ) * Complex.I)) by ring, hexp, hc] push_cast field_simp have hnorm : ‖edge v (l : ZMod n)‖ = ‖edge v 0‖ * r := by rw [he, norm_mul, norm_mul, Complex.norm_exp_ofReal_mul_I, mul_one, Complex.norm_real, Real.norm_eq_abs, abs_of_pos hr] unfold qf rw [hprod, Complex.re_ofReal_mul, Complex.im_ofReal_mul, Complex.exp_ofReal_mul_I_re, Complex.exp_ofReal_mul_I_im, hnorm] have hc0 : 0 ≤ Real.cos φ := Real.cos_nonneg_of_mem_Icc ⟨by linarith [Real.pi_pos], hφ1⟩ have hs0 : 0 ≤ Real.sin φ := Real.sin_nonneg_of_nonneg_of_le_pi hφ0 (by linarith [Real.pi_pos]) have hcs := Real.sin_sq_add_cos_sq φ have hc1 := Real.cos_le_one φ have hs1 := Real.sin_le_one φ have hsum : 1 ≤ Real.cos φ + Real.sin φ := by nlinarith have hpos : 0 ≤ ‖edge v 0‖ * r := by positivity nlinarith open Classical in /-- **Pieces.** Two indices `i < j < n` with the same label (class and level) are in each other's forward range at scale `u₀`: `j ∈ F_{u₀}(i)` (the arc between them turns by `< π/2`, and `|v_i v_j| ≤ f_k(v_j) − f_k(v_i) < u₀`). -/ theorem piece_close {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {u₀ : ℝ} (hu₀ : 0 < u₀) {i j : ℕ} (hij : i < j) (hjn : j < n) (hcls : qcls v i = qcls v j) (hlev : ⌊qf v (qcls v i) (v (i : ZMod n)) / u₀⌋ = ⌊qf v (qcls v j) (v (j : ZMod n)) / u₀⌋) : ((j : ZMod n) - (i : ZMod n)).val ∈ Fu0 v u₀ (i : ZMod n) := by have hL := ccw_leftTurns hn hv obtain ⟨k, hk⟩ : ∃ k, k = qcls v i := ⟨_, rfl⟩ have hmid : ∀ l, i ≤ l → l ≤ j → qcls v l = k := fun l h1 h2 => le_antisymm (by rw [hk, hcls]; exact qcls_mono hL h2) (by rw [hk]; exact qcls_mono hL h1) have hval : ((j : ZMod n) - (i : ZMod n)).val = j - i := by rw [← Nat.cast_sub hij.le, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega)] have hcast : (i : ZMod n) + ((j - i : ℕ) : ZMod n) = (j : ZMod n) := by rw [Nat.cast_sub hij.le] ring have hdist : ‖v (j : ZMod n) - v (i : ZMod n)‖ ≤ qf v k (v (j : ZMod n)) - qf v k (v (i : ZMod n)) := by have hs := sub_eq_sum_edges v (i : ZMod n) (j - i) rw [hcast] at hs rw [← qf_sub, hs, qf_sum] calc ‖∑ m ∈ range (j - i), edge v ((i : ZMod n) + (m : ZMod n))‖ ≤ ∑ m ∈ range (j - i), ‖edge v ((i : ZMod n) + (m : ZMod n))‖ := norm_sum_le _ _ _ ≤ ∑ m ∈ range (j - i), qf v k (edge v ((i : ZMod n) + (m : ZMod n))) := by apply sum_le_sum intro m hm have hm' := mem_range.mp hm have e : (i : ZMod n) + (m : ZMod n) = ((i + m : ℕ) : ZMod n) := by push_cast; ring rw [e] have := qf_edge hL (i + m) rwa [hmid (i + m) (by omega) (by omega)] at this have hlev' : |qf v k (v (i : ZMod n)) / u₀ - qf v k (v (j : ZMod n)) / u₀| < 1 := by rw [← hcls, ← hk] at hlev exact Int.abs_sub_lt_one_of_floor_eq_floor hlev have hlt : ‖v (j : ZMod n) - v (i : ZMod n)‖ < u₀ := by rw [abs_lt] at hlev' have h1 : qf v k (v (j : ZMod n)) / u₀ - qf v k (v (i : ZMod n)) / u₀ < 1 := by linarith [hlev'.1] rw [← sub_div, div_lt_one hu₀] at h1 linarith have hF : inF v (i : ZMod n) (j : ZMod n) := by rw [inF_iff hL, hval] refine ⟨by omega, ?_⟩ have hsp := turning_split v 0 i (j - i - 1) rw [zero_add, show i + (j - i - 1) = j - 1 by omega] at hsp have hs1 := qcls_spec hL i have hs2 := qcls_spec hL (j - 1) rw [hmid (j - 1) (by omega) (by omega)] at hs2 rw [← hk] at hs1 linarith unfold Fu0 rw [mem_filter, add_off] refine ⟨mem_range.mpr (ZMod.val_lt _), hF, ?_⟩ rw [dist_eq_norm, norm_sub_rev] exact hlt open Classical in /-- **Crowding count** (INVERSE Lemma 11.25(b)(ii), abstract form): if any two distinct vertices of `Y` with the same label are in each other's range `F_{u₀}`, then `|Y|² ≤ M·(|Y| + 2Σ_{y∈Y}|F_{u₀}(y)|)`, `M` = number of labels used on `Y` (Cauchy–Schwarz over the labels; same-label ordered pairs inject, up to orientation, into the range pairs). -/ theorem crowd_count {n : ℕ} [NeZero n] {α : Type*} [DecidableEq α] (v : ZMod n → ℂ) (u₀ : ℝ) (Y : Finset (ZMod n)) (lab : ZMod n → α) (hpair : ∀ y ∈ Y, ∀ z ∈ Y, y ≠ z → lab y = lab z → (z - y).val ∈ Fu0 v u₀ y ∨ (y - z).val ∈ Fu0 v u₀ z) : (Y.card : ℝ) ^ 2 ≤ ((Y.image lab).card : ℝ) * (Y.card + 2 * ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ)) := by obtain ⟨T, hT⟩ : ∃ T, T = Y.image lab := ⟨_, rfl⟩ rw [← hT] have hmaps : ∀ y ∈ Y, lab y ∈ T := fun y hy => by rw [hT]; exact mem_image_of_mem lab hy obtain ⟨Fw, hFw⟩ : ∃ Fw : α → Finset (ZMod n × ZMod n), Fw = fun t => (Y.filter (fun y => lab y = t)).offDiag.filter (fun p => (p.2 - p.1).val ∈ Fu0 v u₀ p.1) := ⟨_, rfl⟩ -- per fibre: `m² ≤ m + 2|Fw_t|` have hfib : ∀ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ) ^ 2 ≤ (Y.filter (fun y => lab y = t)).card + 2 * ((Fw t).card : ℝ) := by intro t _ have hsub : (Y.filter (fun y => lab y = t)).offDiag ⊆ Fw t ∪ (Fw t).image Prod.swap := by intro p hp have hp' := mem_offDiag.mp hp obtain ⟨hy, hyt⟩ := mem_filter.mp hp'.1 obtain ⟨hz, hzt⟩ := mem_filter.mp hp'.2.1 have hne := hp'.2.2 rcases hpair p.1 hy p.2 hz hne (by rw [hyt, hzt]) with h | h · exact mem_union_left _ (by rw [hFw]; exact mem_filter.mpr ⟨hp, h⟩) · refine mem_union_right _ (mem_image.mpr ⟨p.swap, ?_, Prod.swap_swap p⟩) rw [hFw] refine mem_filter.mpr ⟨mem_offDiag.mpr ⟨hp'.2.1, hp'.1, fun h' => hne h'.symm⟩, h⟩ have h1 := (card_le_card hsub).trans (card_union_le _ _) have h2 : ((Fw t).image Prod.swap).card ≤ (Fw t).card := card_image_le rw [offDiag_card] at h1 have h3 : (Y.filter (fun y => lab y = t)).card * (Y.filter (fun y => lab y = t)).card ≤ (Y.filter (fun y => lab y = t)).card + 2 * (Fw t).card := by have := Nat.sub_le_iff_le_add.mp (h1.trans (Nat.add_le_add_left h2 _)) omega have h4 : (((Y.filter (fun y => lab y = t)).card * (Y.filter (fun y => lab y = t)).card : ℕ) : ℝ) ≤ (((Y.filter (fun y => lab y = t)).card + 2 * (Fw t).card : ℕ) : ℝ) := by exact_mod_cast h3 push_cast at h4 nlinarith -- the forward pairs inject into the range pairs have hinj : (T.sigma Fw).card ≤ (Y.sigma (fun y => Fu0 v u₀ y)).card := by apply card_le_card_of_injOn (fun q => (⟨q.2.1, (q.2.2 - q.2.1).val⟩ : Σ _ : ZMod n, ℕ)) · intro q hq rw [mem_coe, mem_sigma] at hq ⊢ obtain ⟨_, hq2⟩ := hq rw [hFw] at hq2 obtain ⟨hq3, hq4⟩ := mem_filter.mp hq2 exact ⟨(mem_filter.mp (mem_offDiag.mp hq3).1).1, hq4⟩ · intro q hq q' hq' h rw [mem_coe, mem_sigma] at hq hq' have h1 : q.2.1 = q'.2.1 := congrArg Sigma.fst h have h2 : (q.2.2 - q.2.1).val = (q'.2.2 - q'.2.1).val := by have := congrArg Sigma.snd h simpa using this have h3 : q.2.2 = q'.2.2 := by have e1 := add_off q.2.1 q.2.2 have e2 := add_off q'.2.1 q'.2.2 rw [h2, h1] at e1 rw [← e1, e2] have hq2 := hq.2 have hq2' := hq'.2 rw [hFw] at hq2 hq2' have ht : q.1 = q'.1 := by have a1 := (mem_filter.mp (mem_offDiag.mp (mem_filter.mp hq2).1).1).2 have a2 := (mem_filter.mp (mem_offDiag.mp (mem_filter.mp hq2').1).1).2 rw [← a1, ← a2, h1] exact Sigma.ext ht (heq_of_eq (Prod.ext h1 h3)) rw [card_sigma, card_sigma] at hinj have hinjR : (∑ t ∈ T, ((Fw t).card : ℝ)) ≤ ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ) := by exact_mod_cast hinj have hY : (Y.card : ℝ) = ∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ) := by rw [card_eq_sum_card_fiberwise hmaps] push_cast rfl have hCS : (∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ)) ^ 2 ≤ T.card * ∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ) ^ 2 := sq_sum_le_card_mul_sum_sq have hsum : ∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ) ^ 2 ≤ Y.card + 2 * ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ) := by calc ∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ) ^ 2 ≤ ∑ t ∈ T, (((Y.filter (fun y => lab y = t)).card : ℝ) + 2 * ((Fw t).card : ℝ)) := sum_le_sum hfib _ = (Y.card : ℝ) + 2 * ∑ t ∈ T, ((Fw t).card : ℝ) := by rw [sum_add_distrib, ← mul_sum, ← hY] _ ≤ Y.card + 2 * ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ) := by linarith rw [hY] have hT0 : (0 : ℝ) ≤ T.card := Nat.cast_nonneg _ calc (∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ)) ^ 2 ≤ T.card * ∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ) ^ 2 := hCS _ ≤ T.card * (Y.card + 2 * ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ)) := mul_le_mul_of_nonneg_left hsum hT0 _ = T.card * (∑ t ∈ T, ((Y.filter (fun y => lab y = t)).card : ℝ) + 2 * ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ)) := by rw [← hY] open Classical in /-- Same-label vertices (for `plab`) are in each other's ranges. -/ theorem plab_pair {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {u₀ : ℝ} (hu₀ : 0 < u₀) (y z : ZMod n) (hne : y ≠ z) (hl : plab v u₀ y = plab v u₀ z) : (z - y).val ∈ Fu0 v u₀ y ∨ (y - z).val ∈ Fu0 v u₀ z := by unfold plab at hl obtain ⟨h1, h2⟩ := Prod.mk.inj hl have hyv : ((y.val : ℕ) : ZMod n) = y := ZMod.natCast_zmod_val y have hzv : ((z.val : ℕ) : ZMod n) = z := ZMod.natCast_zmod_val z have hvne : y.val ≠ z.val := fun h => hne (ZMod.val_injective n h) rcases lt_or_gt_of_ne hvne with h | h · left have := piece_close hn hv hu₀ h (ZMod.val_lt z) h1 (by rw [hyv, hzv]; exact h2) rwa [hyv, hzv] at this · right have := piece_close hn hv hu₀ h (ZMod.val_lt y) h1.symm (by rw [hyv, hzv]; exact h2.symm) rwa [hyv, hzv] at this end Erdos94ThmA /-! ### Thin vertices lie near the corners, part 4: the thin-set bound (INVERSE §11.16(c), (S2)) and the class count (S1) -/ namespace Erdos94ThmA open Finset theorem toNat_le_real {z : ℤ} {r : ℝ} (h : (z : ℝ) ≤ r) (hr : 0 ≤ r) : (z.toNat : ℝ) ≤ r := by rcases le_or_gt 0 z with hz | hz · have h1 : ((z.toNat : ℕ) : ℤ) = z := Int.toNat_of_nonneg hz have h2 : ((z.toNat : ℕ) : ℝ) = (z : ℝ) := by exact_mod_cast h1 linarith · rw [Int.toNat_of_nonpos hz.le] simpa using hr open Classical in /-- **Label count.** If every point of `Y` is within `R` of one of `m` points `c j`, the piece labels used on `Y` number at most `4m(4R/u₀ + 2)`. -/ theorem plab_card_le {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {u₀ R : ℝ} (hu₀ : 0 < u₀) (hR : 0 ≤ R) (Y : Finset (ZMod n)) (m : ℕ) (c : ℕ → ZMod n) (hY : ∀ y ∈ Y, ∃ j < m, ‖v y - v (c j)‖ ≤ R) : ((Y.image (plab v u₀)).card : ℝ) ≤ 4 * m * (4 * R / u₀ + 2) := by have hL := ccw_leftTurns hn hv obtain ⟨Ls, hLs⟩ : ∃ Ls : Finset (ℕ × ℤ), Ls = (range 4).biUnion (fun k => (range m).biUnion (fun j => (Icc ⌊(qf v k (v (c j)) - 2 * R) / u₀⌋ ⌊(qf v k (v (c j)) + 2 * R) / u₀⌋).image (fun t => (k, t)))) := ⟨_, rfl⟩ have hsub : Y.image (plab v u₀) ⊆ Ls := by intro q hq obtain ⟨y, hy, rfl⟩ := mem_image.mp hq obtain ⟨j, hj, hyc⟩ := hY y hy have hk := qcls_lt_four hn hv (ZMod.val_lt y) rw [hLs, mem_biUnion] refine ⟨qcls v y.val, mem_range.mpr hk, ?_⟩ rw [mem_biUnion] refine ⟨j, mem_range.mpr hj, mem_image.mpr ⟨⌊qf v (qcls v y.val) (v y) / u₀⌋, ?_, rfl⟩⟩ have hq := qf_abs_le hL (qcls v y.val) (v y - v (c j)) rw [qf_sub] at hq rw [abs_le] at hq rw [mem_Icc] constructor · apply Int.floor_mono apply div_le_div_of_nonneg_right _ hu₀.le linarith [hq.1] · apply Int.floor_mono apply div_le_div_of_nonneg_right _ hu₀.le linarith [hq.2] have hcard := card_le_card hsub have hLc : (Ls.card : ℝ) ≤ 4 * m * (4 * R / u₀ + 2) := by rw [hLs] have h1 : ((range 4).biUnion (fun k => (range m).biUnion (fun j => (Icc ⌊(qf v k (v (c j)) - 2 * R) / u₀⌋ ⌊(qf v k (v (c j)) + 2 * R) / u₀⌋).image (fun t => (k, t))))).card ≤ ∑ k ∈ range 4, ∑ j ∈ range m, (Icc ⌊(qf v k (v (c j)) - 2 * R) / u₀⌋ ⌊(qf v k (v (c j)) + 2 * R) / u₀⌋).card := by refine card_biUnion_le.trans (sum_le_sum (fun k _ => card_biUnion_le.trans (sum_le_sum (fun j _ => ?_)))) exact card_image_le have h2 : ∀ k j, ((Icc ⌊(qf v k (v (c j)) - 2 * R) / u₀⌋ ⌊(qf v k (v (c j)) + 2 * R) / u₀⌋).card : ℝ) ≤ 4 * R / u₀ + 2 := by intro k j rw [Int.card_Icc] apply toNat_le_real _ (by positivity) have a1 := Int.floor_le ((qf v k (v (c j)) + 2 * R) / u₀) have a2 := Int.lt_floor_add_one ((qf v k (v (c j)) - 2 * R) / u₀) have e : (qf v k (v (c j)) + 2 * R) / u₀ - (qf v k (v (c j)) - 2 * R) / u₀ = 4 * R / u₀ := by field_simp ring push_cast linarith have h1R : (((range 4).biUnion (fun k => (range m).biUnion (fun j => (Icc ⌊(qf v k (v (c j)) - 2 * R) / u₀⌋ ⌊(qf v k (v (c j)) + 2 * R) / u₀⌋).image (fun t => (k, t))))).card : ℝ) ≤ ∑ k ∈ range 4, ∑ j ∈ range m, ((Icc ⌊(qf v k (v (c j)) - 2 * R) / u₀⌋ ⌊(qf v k (v (c j)) + 2 * R) / u₀⌋).card : ℝ) := by exact_mod_cast h1 have h3 : ∑ k ∈ range 4, ∑ j ∈ range m, ((Icc ⌊(qf v k (v (c j)) - 2 * R) / u₀⌋ ⌊(qf v k (v (c j)) + 2 * R) / u₀⌋).card : ℝ) ≤ ∑ _k ∈ range 4, ∑ _j ∈ range m, (4 * R / u₀ + 2) := sum_le_sum (fun k _ => sum_le_sum (fun j _ => h2 k j)) rw [sum_const, sum_const, card_range, card_range] at h3 simp only [nsmul_eq_mul] at h3 linarith have := (show (((Y.image (plab v u₀)).card : ℕ) : ℝ) ≤ (Ls.card : ℝ) by exact_mod_cast hcard) linarith open Classical in /-- `Σ_{y ∈ Y} |F_{u₀}(y)| ≤ |Y|·K + 3εn²` (`K` classes below `u₀`; positions outside `U` are `≤ 3εn²` in all). -/ theorem sum_Fu0_le {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (u₀ : ℝ) (Y : Finset (ZMod n)) : ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ) ≤ Y.card * (U.filter (fun u => u < u₀)).card + 3 * ε * n ^ 2 := by have h1 : ∀ y, ((Fu0 v u₀ y).card : ℝ) ≤ (U.filter (fun u => u < u₀)).card + nfc v U u₀ y := by intro y have := Fu0_card hv U u₀ y have h' : (Fu0 v u₀ y).card ≤ (U.filter (fun u => u < u₀)).card + nfc v U u₀ y := by omega exact_mod_cast h' have h2 : ∑ y ∈ Y, (nfc v U u₀ y : ℝ) ≤ ∑ y, (nfc v U u₀ y : ℝ) := sum_le_sum_of_subset_of_nonneg (subset_univ Y) (fun _ _ _ => Nat.cast_nonneg _) have h3 : ∑ y, (nfc v U u₀ y : ℝ) ≤ 3 * ε * n ^ 2 := by have a := nfc_total v U u₀ have b := (thm119_Ptot v U hε0 hε1 hU1 hU2).1 have a' : ((∑ y, nfc v U u₀ y : ℕ) : ℝ) ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := by exact_mod_cast a push_cast at a' linarith calc ∑ y ∈ Y, ((Fu0 v u₀ y).card : ℝ) ≤ ∑ y ∈ Y, (((U.filter (fun u => u < u₀)).card : ℝ) + nfc v U u₀ y) := sum_le_sum (fun y _ => h1 y) _ = Y.card * (U.filter (fun u => u < u₀)).card + ∑ y ∈ Y, (nfc v U u₀ y : ℝ) := by rw [sum_add_distrib, sum_const, nsmul_eq_mul] _ ≤ Y.card * (U.filter (fun u => u < u₀)).card + 3 * ε * n ^ 2 := by linarith open Classical in /-- **INVERSE §11.16(c) / Thm 11.9″ (S2): the thin set is small.** In a polygon with all directional extents `≥ ζ₀D`, if `u₀ + 2ηD < ζ₀D` (`0 < η ≤ 1`), then with `R = (1 + sin(η/2))u₀/sin(η/2)`, `M = 16(4R/u₀ + 2)` and `K` near-full classes below `u₀`: `|B(u₀)|² ≤ M(|B| + 2(|B|K + 3εn²))`, i.e. `|B| ≤ M(2K + 1) + √(6Mε)·n`. -/ theorem thin_card_bound {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (U : Finset ℝ) {ε ζ₀ D η u₀ : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (hη0 : 0 < η) (hη1 : η ≤ 1) (hfat : ∀ u : ℂ, ‖u‖ = 1 → ∃ z z' : ZMod n, ζ₀ * D ≤ ((starRingEnd ℂ) u * (v z - v z')).re) (hD : ∀ a b : ZMod n, ‖v a - v b‖ ≤ D) (hsmall : u₀ + 2 * η * D < ζ₀ * D) (hu₀ : 0 < u₀) : (((thinB v u₀).card : ℝ)) ^ 2 ≤ 16 * (4 * ((1 + Real.sin (η / 2)) * u₀ / Real.sin (η / 2)) / u₀ + 2) * (((thinB v u₀).card : ℝ) + 2 * (((thinB v u₀).card : ℝ) * (U.filter (fun u => u < u₀)).card + 3 * ε * n ^ 2)) := by have hL := ccw_leftTurns hn hv have hsin : 0 < Real.sin (η / 2) := Real.sin_pos_of_pos_of_lt_pi (by linarith) (by linarith [Real.two_le_pi]) have hR0 : 0 ≤ (1 + Real.sin (η / 2)) * u₀ / Real.sin (η / 2) := by positivity have hcc := crowd_count v u₀ (thinB v u₀) (plab v u₀) (fun y _ z _ hne hl => plab_pair hn hv hu₀ y z hne hl) have hM := plab_card_le hn hv hu₀ hR0 (thinB v u₀) 4 (chpt v) (fun y hy => by obtain ⟨k, hk, hb⟩ := thin_near hn hv hη0 hη1 hfat hD hsmall hy refine ⟨k, hk, ?_⟩ rw [le_div_iff₀ hsin] linarith) have hF := sum_Fu0_le hL U hε0 hε1 hU1 hU2 u₀ (thinB v u₀) push_cast at hM have hpos : (0 : ℝ) ≤ ((thinB v u₀).card : ℝ) + 2 * ∑ y ∈ thinB v u₀, ((Fu0 v u₀ y).card : ℝ) := by positivity calc (((thinB v u₀).card : ℝ)) ^ 2 ≤ (((thinB v u₀).image (plab v u₀)).card : ℝ) * (((thinB v u₀).card : ℝ) + 2 * ∑ y ∈ thinB v u₀, ((Fu0 v u₀ y).card : ℝ)) := hcc _ ≤ 16 * (4 * ((1 + Real.sin (η / 2)) * u₀ / Real.sin (η / 2)) / u₀ + 2) * (((thinB v u₀).card : ℝ) + 2 * ∑ y ∈ thinB v u₀, ((Fu0 v u₀ y).card : ℝ)) := by apply mul_le_mul_of_nonneg_right _ hpos linarith _ ≤ 16 * (4 * ((1 + Real.sin (η / 2)) * u₀ / Real.sin (η / 2)) / u₀ + 2) * (((thinB v u₀).card : ℝ) + 2 * (((thinB v u₀).card : ℝ) * (U.filter (fun u => u < u₀)).card + 3 * ε * n ^ 2)) := by apply mul_le_mul_of_nonneg_left _ (by positivity) linarith open Classical in /-- **INVERSE Thm 11.9″ (S1): many near-full classes below `u₀`.** With `D` ≥ every distance and `K′` near-full classes below `u₀ > 0`: `n² ≤ 4(4D/u₀ + 2)(n + 2(nK′ + 3εn²))` (all vertices lie in `≤ 4(4D/u₀ + 2)` pieces). -/ theorem classes_lower {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (U : Finset ℝ) {ε D u₀ : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (hD : ∀ a b : ZMod n, ‖v a - v b‖ ≤ D) (hu₀ : 0 < u₀) : (n : ℝ) ^ 2 ≤ 4 * (4 * D / u₀ + 2) * (n + 2 * (n * (U.filter (fun u => u < u₀)).card + 3 * ε * n ^ 2)) := by have hL := ccw_leftTurns hn hv have hD0 : 0 ≤ D := le_trans (norm_nonneg _) (hD 0 0) have hcc := crowd_count v u₀ (univ : Finset (ZMod n)) (plab v u₀) (fun y _ z _ hne hl => plab_pair hn hv hu₀ y z hne hl) have hM := plab_card_le hn hv hu₀ hD0 (univ : Finset (ZMod n)) 1 (fun _ => 0) (fun y _ => ⟨0, by norm_num, hD y 0⟩) have hF := sum_Fu0_le hL U hε0 hε1 hU1 hU2 u₀ (univ : Finset (ZMod n)) rw [card_univ, ZMod.card] at hcc hF push_cast at hM have hpos : (0 : ℝ) ≤ (n : ℝ) + 2 * ∑ y : ZMod n, ((Fu0 v u₀ y).card : ℝ) := by positivity calc (n : ℝ) ^ 2 ≤ (((univ : Finset (ZMod n)).image (plab v u₀)).card : ℝ) * ((n : ℝ) + 2 * ∑ y : ZMod n, ((Fu0 v u₀ y).card : ℝ)) := hcc _ ≤ 4 * (4 * D / u₀ + 2) * ((n : ℝ) + 2 * ∑ y : ZMod n, ((Fu0 v u₀ y).card : ℝ)) := by apply mul_le_mul_of_nonneg_right _ hpos linarith _ ≤ 4 * (4 * D / u₀ + 2) * (n + 2 * (n * (U.filter (fun u => u < u₀)).card + 3 * ε * n ^ 2)) := by apply mul_le_mul_of_nonneg_left _ (by positivity) linarith end Erdos94ThmA /-! ### INVERSE Thm 11.9″ (S3): anchored windows are short; the windows cover; the bad windows are few -/ namespace Erdos94ThmA open Finset open Classical in /-- `F_{u₀}(y)` is exactly the initial segment `{1, …, |F_{u₀}(y)|}`. -/ theorem Fu0_eq_Icc {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (u₀ : ℝ) (y : ZMod n) : Fu0 v u₀ y = Icc 1 (Fu0 v u₀ y).card := by symm apply eq_of_subset_of_card_le · intro j hj rw [mem_Icc] at hj have hne : (Fu0 v u₀ y).Nonempty := by rw [← card_pos] omega obtain ⟨m, hm⟩ := hne have hmax : ∃ M ∈ Fu0 v u₀ y, (Fu0 v u₀ y).card ≤ M := by refine ⟨(Fu0 v u₀ y).max' ⟨m, hm⟩, max'_mem _ _, ?_⟩ have hsub : Fu0 v u₀ y ⊆ Icc 1 ((Fu0 v u₀ y).max' ⟨m, hm⟩) := by intro i hi rw [mem_Icc] exact ⟨(Fu0_le_card hv hi).1, le_max' _ _ hi⟩ have := card_le_card hsub rwa [Nat.card_Icc, Nat.add_sub_cancel] at this obtain ⟨M, hM, hMc⟩ := hmax exact Fu0_initial hv hM hj.1 (by omega) · have hsub : Fu0 v u₀ y ⊆ Icc 1 (Fu0 v u₀ y).card := by intro i hi rw [mem_Icc] exact Fu0_le_card hv hi have := card_le_card hsub rw [Nat.card_Icc, Nat.add_sub_cancel] at this ⊢ open Classical in /-- Positions `p < q ≤ |F_{u₀}(y)|` are `< u₀` apart. -/ theorem pos_span {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u₀ : ℝ} {y : ZMod n} {p q : ℕ} (hpq : p < q) (hq : q ≤ (Fu0 v u₀ y).card) : dist (v (y + (p : ZMod n))) (v (y + (q : ZMod n))) < u₀ := by have hqm : q ∈ Fu0 v u₀ y := by rw [Fu0_eq_Icc hv u₀ y, mem_Icc] exact ⟨by omega, hq⟩ rcases Nat.eq_zero_or_pos p with h0 | h0 · rw [h0, Nat.cast_zero, add_zero] unfold Fu0 at hqm exact (mem_filter.mp hqm).2.2 · obtain ⟨h1, h2⟩ := Fu0_shift hv h0 hpq hqm unfold Fu0 at h1 have := (mem_filter.mp h1).2.2 rwa [h2] at this open Classical in /-- **Anchored windows are short.** If some `y ∈ W_{k−2}` has `|F_{u₀}(y)| ≥ 2w`, all pairs of `W_k` are `< u₀` apart. -/ theorem win_span {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {u₀ : ℝ} (hu₀ : 0 < u₀) {w k : ℕ} (hk : 2 ≤ k) {y : ZMod n} (hyW : y ∈ (winK w (k - 2) : Finset (ZMod n))) (hy : 2 * w ≤ (Fu0 v u₀ y).card) : ∀ a ∈ (winK w k : Finset (ZMod n)), ∀ b ∈ (winK w k : Finset (ZMod n)), dist (v a) (v b) < u₀ := by obtain ⟨i₀, hi₀, hy0⟩ := winK_mem hyW have hs : w ≤ 2 * ((w + 1) / 2) := by omega have hs' : 2 * ((w + 1) / 2) ≤ w + 1 := by omega have hpos : ∀ i < w, ((k * ((w + 1) / 2) : ℕ) : ZMod n) + (i : ZMod n) = y + ((2 * ((w + 1) / 2) - i₀ + i : ℕ) : ZMod n) := by intro i _ rw [hy0] have e : k * ((w + 1) / 2) = (k - 2) * ((w + 1) / 2) + 2 * ((w + 1) / 2) := by obtain ⟨k', rfl⟩ : ∃ k', k = k' + 2 := ⟨k - 2, by omega⟩ rw [show k' + 2 - 2 = k' by omega] ring rw [e, Nat.cast_add, Nat.cast_add, Nat.cast_sub (show i₀ ≤ 2 * ((w + 1) / 2) by omega)] ring intro a ha b hb obtain ⟨i, hi, rfl⟩ := winK_mem ha obtain ⟨i', hi', rfl⟩ := winK_mem hb rw [hpos i hi, hpos i' hi'] rcases lt_trichotomy i i' with h | h | h · exact pos_span hv (by omega) (by omega) · rw [h, dist_self] exact hu₀ · rw [dist_comm] exact pos_span hv (by omega) (by omega) /-- **The windows cover the polygon.** -/ theorem win_cover {n : ℕ} [NeZero n] {w : ℕ} (hw : 1 ≤ w) (z : ZMod n) : ∃ k < nWin n w, z ∈ (winK w k : Finset (ZMod n)) := by obtain ⟨s, hs⟩ : ∃ s, s = (w + 1) / 2 := ⟨_, rfl⟩ have hs1 : 1 ≤ s := by omega have hsw : s ≤ w := by omega have hspec := nWin_spec (n := n) hw rw [← hs] at hspec refine ⟨z.val / s, ?_, ?_⟩ · have h1 : z.val < nWin n w * s := lt_of_lt_of_le (ZMod.val_lt z) hspec.2 exact (Nat.div_lt_iff_lt_mul hs1).mpr h1 · unfold winK rw [mem_image] refine ⟨z.val % s, mem_range.mpr (lt_of_lt_of_le (Nat.mod_lt _ hs1) hsw), ?_⟩ rw [← hs, Nat.div_add_mod' z.val s, ZMod.natCast_zmod_val] open Classical in /-- Each vertex lies in at most `6` windows `W_k`. -/ theorem winK_mult {n : ℕ} [NeZero n] {w : ℕ} (hw : 1 ≤ w) (hwn : w < n) (y : ZMod n) : ((range (nWin n w)).filter (fun k => y ∈ (winK w k : Finset (ZMod n)))).card ≤ 6 := le_trans (card_le_card (fun k hk => mem_filter.mpr ⟨(mem_filter.mp hk).1, winK_sub w k (mem_filter.mp hk).2⟩)) (winKp_mult hw hwn y) open Classical in /-- Double counting `Σ_k |W_k ∩ S| = Σ_{y ∈ S} #{k : y ∈ W_k}`. -/ theorem sum_card_inter_swap {α : Type*} [DecidableEq α] (m : ℕ) (W : ℕ → Finset α) (S : Finset α) : ∑ k ∈ range m, (W k ∩ S).card = ∑ y ∈ S, ((range m).filter (fun k => y ∈ W k)).card := by calc ∑ k ∈ range m, (W k ∩ S).card = ∑ k ∈ range m, ∑ y ∈ S, if y ∈ W k then 1 else 0 := by refine sum_congr rfl (fun k _ => ?_) rw [inter_comm, ← filter_mem_eq_inter, card_filter] _ = ∑ y ∈ S, ∑ k ∈ range m, if y ∈ W k then 1 else 0 := sum_comm _ = ∑ y ∈ S, ((range m).filter (fun k => y ∈ W k)).card := by refine sum_congr rfl (fun y _ => ?_) rw [card_filter] open Classical in /-- **Windows without an anchor are few** (`N₁` of Thm 11.9″(S3)): if every vertex of `W_{k−2}` lies in `Z`, window `k` is unanchored; there are at most `6|Z|/w` such `k ≥ 2`. -/ theorem unanchored_le {n : ℕ} [NeZero n] {w : ℕ} (hw : 1 ≤ w) (hwn : w < n) (Z : Finset (ZMod n)) : (w : ℝ) * (((range (nWin n w)).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)).card : ℝ) ≤ 6 * Z.card := by obtain ⟨Kb, hKb⟩ : ∃ S, S = (range (nWin n w)).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z) := ⟨_, rfl⟩ rw [← hKb] have hsum : ∑ k ∈ Kb, ((winK w (k - 2) : Finset (ZMod n)) ∩ Z).card ≤ 6 * Z.card := by rw [show ∑ k ∈ Kb, ((winK w (k - 2) : Finset (ZMod n)) ∩ Z).card = ∑ z ∈ Z, (Kb.filter (fun k => z ∈ (winK w (k - 2) : Finset (ZMod n)))).card by simp only [card_eq_sum_ones, sum_filter] rw [sum_comm] refine sum_congr rfl (fun k _ => ?_) rw [← sum_filter, inter_comm, ← filter_mem_eq_inter]] calc ∑ z ∈ Z, (Kb.filter (fun k => z ∈ (winK w (k - 2) : Finset (ZMod n)))).card ≤ ∑ _z ∈ Z, 6 := by apply sum_le_sum intro z _ have hinj : (Kb.filter (fun k => z ∈ (winK w (k - 2) : Finset (ZMod n)))).card ≤ ((range (nWin n w)).filter (fun k => z ∈ (winK w k : Finset (ZMod n)))).card := by apply card_le_card_of_injOn (fun k => k - 2) · intro k hk rw [mem_coe, mem_filter] at hk rw [hKb, mem_filter, mem_range] at hk rw [mem_coe, mem_filter, mem_range] refine ⟨?_, hk.2⟩ show k - 2 < nWin n w omega · intro k hk k' hk' h rw [mem_coe, mem_filter, hKb, mem_filter] at hk hk' have h1 := hk.1.2.1 have h2 := hk'.1.2.1 simp only at h omega exact hinj.trans (winK_mult hw hwn z) _ = 6 * Z.card := by rw [sum_const, smul_eq_mul, mul_comm] have hcard : ∀ k ∈ Kb, ((winK w (k - 2) : Finset (ZMod n)) ∩ Z).card = w := by intro k hk rw [hKb, mem_filter] at hk rw [inter_eq_left.mpr hk.2.2, winK_card hwn.le] rw [sum_congr rfl hcard, sum_const, smul_eq_mul] at hsum have : Kb.card * w ≤ 6 * Z.card := hsum have hR : ((Kb.card * w : ℕ) : ℝ) ≤ ((6 * Z.card : ℕ) : ℝ) := by exact_mod_cast this push_cast at hR linarith end Erdos94ThmA /-! ### INVERSE Thm 11.9″ (S4): per-window rotations with per-window exceptions; gluing; at most `#bad + 1` rotations -/ namespace Erdos94ThmA open Finset open Classical in /-- **Runs.** If `R` agrees on consecutive good indices `k, k + 1 < m`, it takes at most `#bad + 1` values on the good indices (each value is the value at the start of a run, and run starts other than `0` follow a bad index). -/ theorem run_count {α : Type*} [DecidableEq α] (m : ℕ) (good : ℕ → Prop) (R : ℕ → α) (hglue : ∀ k, k + 1 < m → good k → good (k + 1) → R k = R (k + 1)) : (((range m).filter good).image R).card ≤ ((range m).filter (fun k => ¬ good k)).card + 1 := by obtain ⟨S, hS⟩ : ∃ S : Finset ℕ, S = (range m).filter (fun j => good j ∧ (j = 0 ∨ ¬ good (j - 1))) := ⟨_, rfl⟩ have hstart : ∀ k ∈ (range m).filter good, ∃ j ∈ S, R k = R j := by intro k hk obtain ⟨hkm, hkg⟩ := mem_filter.mp hk have hkm' := mem_range.mp hkm have hex : ∃ j, j ≤ k ∧ ∀ i, j ≤ i → i ≤ k → good i := ⟨k, le_rfl, fun i h1 h2 => by rw [show i = k by omega]; exact hkg⟩ obtain ⟨hjk, hjall⟩ := Nat.find_spec hex refine ⟨Nat.find hex, ?_, ?_⟩ · rw [hS, mem_filter, mem_range] refine ⟨by omega, hjall _ le_rfl hjk, ?_⟩ by_contra hc push Not at hc obtain ⟨hne, hg⟩ := hc have hmin := Nat.find_min hex (show Nat.find hex - 1 < Nat.find hex by omega) apply hmin refine ⟨by omega, fun i h1 h2 => ?_⟩ rcases Nat.eq_or_lt_of_le h1 with h | h · rw [← h] exact hg · exact hjall i (by omega) h2 · have key : ∀ d, Nat.find hex + d ≤ k → R (Nat.find hex + d) = R (Nat.find hex) := by intro d induction d with | zero => intro _; rfl | succ d ih => intro hd rw [← ih (by omega)] exact (hglue (Nat.find hex + d) (by omega) (hjall _ (by omega) (by omega)) (hjall _ (by omega) (by omega))).symm have := key (k - Nat.find hex) (by omega) rwa [show Nat.find hex + (k - Nat.find hex) = k by omega] at this have hsub : ((range m).filter good).image R ⊆ S.image R := by intro a ha obtain ⟨k, hk, rfl⟩ := mem_image.mp ha obtain ⟨j, hj, hRj⟩ := hstart k hk exact mem_image.mpr ⟨j, hj, hRj.symm⟩ have hS2 : S ⊆ insert 0 (((range m).filter (fun k => ¬ good k)).image (fun k => k + 1)) := by intro j hj rw [hS, mem_filter, mem_range] at hj obtain ⟨hjm, _, h0⟩ := hj rcases h0 with h | h · rw [h] exact mem_insert_self _ _ · rcases Nat.eq_zero_or_pos j with hj0 | hj0 · rw [hj0] exact mem_insert_self _ _ · refine mem_insert_of_mem (mem_image.mpr ⟨j - 1, ?_, by omega⟩) rw [mem_filter, mem_range] exact ⟨by omega, h⟩ calc (((range m).filter good).image R).card ≤ (S.image R).card := card_le_card hsub _ ≤ S.card := card_image_le _ ≤ (insert 0 (((range m).filter (fun k => ¬ good k)).image (fun k => k + 1))).card := card_le_card hS2 _ ≤ (((range m).filter (fun k => ¬ good k)).image (fun k => k + 1)).card + 1 := card_insert_le _ _ _ ≤ ((range m).filter (fun k => ¬ good k)).card + 1 := by have := card_image_le (s := (range m).filter (fun k => ¬ good k)) (f := fun k => k + 1) omega open Classical in /-- **A good window carries one rotation with per-window exceptions** (Lemma 11.3 via `good_window_rot` at the window's own changed fraction `β_W = (chg_W + 1)/(2w²)`): `#exceptions ≤ 6√((chg_W + 1)/2)`, and `≤ 6√(2β₀)·w`. -/ theorem win_rot {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (hT : ∀ t : ℂ, t ≠ 0 → ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) (W : Finset (ZMod n)) (hW7 : 7 ≤ W.card) {β₀ : ℝ} (hβ0 : 0 < β₀) (hβ₀ : β₀ ≤ 1 / 200) (hw2 : 1 ≤ 2 * β₀ * (W.card : ℝ) ^ 2) (hgood : ((chgW v W).card : ℝ) ≤ 2 * β₀ * (W.card : ℝ) ^ 2) : ∃ ω t : ℂ, ‖ω‖ = 1 ∧ ω ≠ 1 ∧ ((W.filter (fun x => v (x + 1) ≠ ω * v x + t)).card : ℝ) ≤ 6 * Real.sqrt ((((chgW v W).card : ℝ) + 1) / 2) ∧ ((W.filter (fun x => v (x + 1) ≠ ω * v x + t)).card : ℝ) ≤ 6 * Real.sqrt (2 * β₀) * W.card := by have hw0 : (0 : ℝ) < W.card := by have : 0 < W.card := by omega exact_mod_cast this obtain ⟨β, hβ⟩ : ∃ β : ℝ, β = (((chgW v W).card : ℝ) + 1) / (2 * (W.card : ℝ) ^ 2) := ⟨_, rfl⟩ have hβpos : 0 < β := by rw [hβ]; positivity have hβle : β ≤ 2 * β₀ := by rw [hβ, div_le_iff₀ (by positivity)] nlinarith obtain ⟨ω, t, h1, h2, h3⟩ := good_window_rot hn hv hvi hT W hW7 hβpos (by linarith) (by rw [hβ]; field_simp; linarith) refine ⟨ω, t, h1, h2, ?_, ?_⟩ · have e : Real.sqrt β * W.card = Real.sqrt ((((chgW v W).card : ℝ) + 1) / 2) := by rw [hβ] rw [show (((chgW v W).card : ℝ) + 1) / (2 * (W.card : ℝ) ^ 2) = ((((chgW v W).card : ℝ) + 1) / 2) / (W.card : ℝ) ^ 2 by field_simp] rw [Real.sqrt_div' _ (by positivity), Real.sqrt_sq hw0.le] field_simp calc ((W.filter (fun x => v (x + 1) ≠ ω * v x + t)).card : ℝ) ≤ 6 * Real.sqrt β * W.card := h3 _ = 6 * Real.sqrt ((((chgW v W).card : ℝ) + 1) / 2) := by rw [mul_assoc, e] · have hs : Real.sqrt β ≤ Real.sqrt (2 * β₀) := Real.sqrt_le_sqrt hβle have := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hs (by norm_num : (0 : ℝ) ≤ 6)) hw0.le linarith /-- `Σ √a_k ≤ √(m·Σ a_k)` (Cauchy–Schwarz). -/ theorem sum_sqrt_le {α : Type*} (s : Finset α) (a : α → ℝ) (ha : ∀ x ∈ s, 0 ≤ a x) : ∑ x ∈ s, Real.sqrt (a x) ≤ Real.sqrt (s.card * ∑ x ∈ s, a x) := by have h := sq_sum_le_card_mul_sum_sq (s := s) (f := fun x => Real.sqrt (a x)) have h2 : ∑ x ∈ s, Real.sqrt (a x) ^ 2 = ∑ x ∈ s, a x := sum_congr rfl (fun x hx => Real.sq_sqrt (ha x hx)) rw [h2] at h have h0 : 0 ≤ ∑ x ∈ s, Real.sqrt (a x) := sum_nonneg (fun x _ => Real.sqrt_nonneg _) calc ∑ x ∈ s, Real.sqrt (a x) = Real.sqrt ((∑ x ∈ s, Real.sqrt (a x)) ^ 2) := (Real.sqrt_sq h0).symm _ ≤ Real.sqrt (s.card * ∑ x ∈ s, a x) := Real.sqrt_le_sqrt h end Erdos94ThmA /-! ### INVERSE Thm 11.9″ (S3)–(S4) in Lean form: good windows, the bad-window count, one rotation per run -/ namespace Erdos94ThmA open Finset /-- An ANCHORED window: `k ≥ 2` and some `y ∈ W_{k−2}` has `|F_{u₀}(y)| ≥ 2w` (then `W_k` is short, `win_span`). -/ def anchW {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u₀ : ℝ) (w k : ℕ) : Prop := 2 ≤ k ∧ ∃ y ∈ (winK w (k - 2) : Finset (ZMod n)), 2 * w ≤ (Fu0 v u₀ y).card /-- A GOOD window (Thm 11.9″(S3), `β₀ = 10⁻⁴`): anchored, with at most `2β₀w²` changed ordered pairs. -/ def goodW {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (u₀ : ℝ) (w k : ℕ) : Prop := anchW v u₀ w k ∧ ((chgW v (winK w k)).card : ℝ) ≤ 2 * (1 / 10000) * (w : ℝ) ^ 2 open Classical in /-- **The bad-window count** (Thm 11.9″(S3), Markov form): with `Z` the non-anchors, `B` the thin vertices and `K` the classes below `u₀`, the windows that are not good number at most `2 + 6|Z|/w + (18εn² + 18|B|² + 24εnK)/(2·10⁻⁴w²)`. -/ theorem bad_count {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hH0 : ∀ y : ZMod n, ¬ inF v y (y - 1)) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) {u₀ : ℝ} (hu₀ : 0 < u₀) {w : ℕ} (hw : 7 ≤ w) (hwn : w < n) : (((range (nWin n w)).filter (fun k => ¬ goodW v u₀ w k)).card : ℝ) ≤ 2 + 6 * (((univ : Finset (ZMod n)).filter (fun y => (Fu0 v u₀ y).card < 2 * w)).card : ℝ) / w + (18 * ε * n ^ 2 + 18 * ((thinB v u₀).card : ℝ) ^ 2 + 24 * ε * n * (U.filter (fun u => u < u₀)).card) / (2 * (1 / 10000) * (w : ℝ) ^ 2) := by have hL := ccw_leftTurns hn hv have hw1 : 1 ≤ w := by omega have hw0 : (0 : ℝ) < w := by exact_mod_cast (show 0 < w by omega) obtain ⟨m, hm⟩ : ∃ m, m = nWin n w := ⟨_, rfl⟩ rw [← hm] obtain ⟨Z, hZ⟩ : ∃ Z : Finset (ZMod n), Z = (univ : Finset (ZMod n)).filter (fun y => (Fu0 v u₀ y).card < 2 * w) := ⟨_, rfl⟩ rw [← hZ] -- the anchored windows obtain ⟨An, hAn⟩ : ∃ A : Finset ℕ, A = (range m).filter (fun k => anchW v u₀ w k) := ⟨_, rfl⟩ have hsplit : (range m).filter (fun k => ¬ goodW v u₀ w k) ⊆ (range 2 ∪ (range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)) ∪ An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ)) := by intro k hk obtain ⟨hkm, hng⟩ := mem_filter.mp hk unfold goodW at hng by_cases h2 : 2 ≤ k · by_cases hanc : ∃ y ∈ (winK w (k - 2) : Finset (ZMod n)), 2 * w ≤ (Fu0 v u₀ y).card · have hkA : k ∈ An := by rw [hAn, mem_filter] exact ⟨hkm, h2, hanc⟩ refine mem_union_right _ (mem_filter.mpr ⟨hkA, ?_⟩) by_contra hc push Not at hc exact hng ⟨⟨h2, hanc⟩, hc⟩ · refine mem_union_left _ (mem_union_right _ (mem_filter.mpr ⟨hkm, h2, fun y hy => ?_⟩)) push Not at hanc rw [hZ, mem_filter] exact ⟨mem_univ _, hanc y hy⟩ · exact mem_union_left _ (mem_union_left _ (mem_range.mpr (by omega))) -- the Markov part have hchg : ∀ k ∈ An, (chgW v (winK w k)).card ≤ (((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card + (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card + 2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y := by intro k hk rw [hAn, mem_filter] at hk obtain ⟨_, hanc⟩ := hk obtain ⟨h2, y, hy, hyc⟩ := hanc exact chgW_le hn hL hH0 U (winK w k) (winKp w k) (fun x hx => winK_succ hx) (win_span hL hu₀ h2 hy hyc) have hM6 : ∀ y : ZMod n, ((range m).filter (fun k => y ∈ (winKp w k : Finset (ZMod n)))).card ≤ 6 := by intro y rw [hm] exact winKp_mult hw1 hwn y have hP := thm119_Psum v U hε0 hε1 hU1 hU2 m (fun k => winK w k) (fun k => winKp w k) (fun k _ => winK_sub w k) hM6 have hD := thm119_Dsum hL U hU2 u₀ m (fun k => winKp w k) hM6 have hMk : ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ 6 * ((thinB v u₀).card : ℝ) ^ 2 := by have h1 : ∀ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ) * (thinB v u₀).card := by intro k _ have a : (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card ≤ ((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card * (thinB v u₀).card := by rw [offDiag_card] exact (Nat.sub_le _ _).trans (Nat.mul_le_mul_left _ (card_le_card inter_subset_right)) exact_mod_cast a have h2 : ∑ k ∈ range m, ((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card ≤ 6 * (thinB v u₀).card := by rw [sum_card_inter_swap m (fun k => (winK w k : Finset (ZMod n))) (thinB v u₀)] calc ∑ y ∈ thinB v u₀, ((range m).filter (fun k => y ∈ (winK w k : Finset (ZMod n)))).card ≤ ∑ _y ∈ thinB v u₀, 6 := sum_le_sum (fun y _ => by rw [hm]; exact winK_mult hw1 hwn y) _ = 6 * (thinB v u₀).card := by rw [sum_const, smul_eq_mul, mul_comm] have h2R : (∑ k ∈ range m, (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ)) ≤ 6 * ((thinB v u₀).card : ℝ) := by exact_mod_cast h2 calc ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ ∑ k ∈ range m, (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ) * (thinB v u₀).card := sum_le_sum h1 _ = (∑ k ∈ range m, (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ)) * (thinB v u₀).card := by rw [sum_mul] _ ≤ 6 * ((thinB v u₀).card : ℝ) * (thinB v u₀).card := mul_le_mul_of_nonneg_right h2R (Nat.cast_nonneg _) _ = 6 * ((thinB v u₀).card : ℝ) ^ 2 := by ring have hAsub : An ⊆ range m := by intro k hk rw [hAn, mem_filter] at hk exact hk.1 have hsumA : (∑ k ∈ An, ((chgW v (winK w k)).card : ℝ)) ≤ 18 * ε * n ^ 2 + 18 * ((thinB v u₀).card : ℝ) ^ 2 + 24 * ε * n * (U.filter (fun u => u < u₀)).card := by have h1 : ∑ k ∈ An, ((chgW v (winK w k)).card : ℝ) ≤ ∑ k ∈ An, (((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) + ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) + (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ)) := by apply sum_le_sum intro k hk have := hchg k hk exact_mod_cast this rw [sum_add_distrib, sum_add_distrib] at h1 have h2a : ∑ k ∈ An, ((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) ≤ ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := sum_le_sum_of_subset_of_nonneg hAsub (fun _ _ _ => by positivity) have h2b : ∑ k ∈ An, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) := sum_le_sum_of_subset_of_nonneg hAsub (fun _ _ _ => by positivity) have h2c : ∑ k ∈ An, (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) ≤ ∑ k ∈ range m, (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) := sum_le_sum_of_subset_of_nonneg hAsub (fun _ _ _ => by positivity) have hP' : ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) ≤ 6 * (3 * ε * n ^ 2) := by have := hP simpa using this have hD' : ∑ k ∈ range m, (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) ≤ 12 * (2 * ε * n * ((U.filter (fun u => u < u₀)).card : ℝ) + ((thinB v u₀).card : ℝ) ^ 2) := hD linarith [h1, h2a, h2b, h2c, hP', hMk, hD'] have hmark := markov_card An (fun k => (chgW v (winK w k)).card) (c := 2 * (1 / 10000) * (w : ℝ) ^ 2) (by positivity) hsumA have hN1 := unanchored_le (n := n) hw1 hwn Z rw [← hm] at hN1 have hc1 := card_le_card hsplit have hc2 := card_union_le (range 2 ∪ (range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)) (An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ))) have hc3 := card_union_le (range 2) ((range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)) rw [card_range] at hc3 have hR : (((range m).filter (fun k => ¬ goodW v u₀ w k)).card : ℝ) ≤ 2 + (((range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)).card : ℝ) + ((An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ))).card : ℝ) := by have := hc1.trans (hc2.trans (Nat.add_le_add_right hc3 _)) exact_mod_cast this have hq1 : (((range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)).card : ℝ) ≤ 6 * (Z.card : ℝ) / w := by rw [le_div_iff₀ hw0] linarith have hq2 : ((An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ))).card : ℝ) ≤ (18 * ε * n ^ 2 + 18 * ((thinB v u₀).card : ℝ) ^ 2 + 24 * ε * n * (U.filter (fun u => u < u₀)).card) / (2 * (1 / 10000) * (w : ℝ) ^ 2) := by rw [le_div_iff₀ (by positivity)] exact hmark linarith open Classical in /-- **One rotation per run of good windows** (Thm 11.9″(S4)): a rotation `R k = (ω_k, t_k)` for every good window, with per-window exceptions `≤ 6√((chg_k + 1)/2)`, equal on consecutive good windows (they overlap in `≥ w − ⌈w/2⌉` vertices and each has `≤ 6√(2β₀)w` exceptions). -/ theorem win_rots {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (hT : ∀ t : ℂ, t ≠ 0 → ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) {u₀ : ℝ} {w : ℕ} (hw : 71 ≤ w) (hwn : w < n) : ∃ R : ℕ → ℂ × ℂ, (∀ k, goodW v u₀ w k → ‖(R k).1‖ = 1 ∧ (R k).1 ≠ 1 ∧ ((((winK w k : Finset (ZMod n))).filter (fun x => v (x + 1) ≠ (R k).1 * v x + (R k).2)).card : ℝ) ≤ 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2)) ∧ (∀ k, k + 1 < nWin n w → goodW v u₀ w k → goodW v u₀ w (k + 1) → R k = R (k + 1)) := by have hcard : ∀ k, (winK w k : Finset (ZMod n)).card = w := fun k => winK_card hwn.le k have hwR : (71 : ℝ) ≤ w := by exact_mod_cast hw have hex : ∀ k, ∃ r : ℂ × ℂ, goodW v u₀ w k → ‖r.1‖ = 1 ∧ r.1 ≠ 1 ∧ ((((winK w k : Finset (ZMod n))).filter (fun x => v (x + 1) ≠ r.1 * v x + r.2)).card : ℝ) ≤ 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2) ∧ ((((winK w k : Finset (ZMod n))).filter (fun x => v (x + 1) ≠ r.1 * v x + r.2)).card : ℝ) ≤ 6 * Real.sqrt (2 * (1 / 10000)) * w := by intro k by_cases hg : goodW v u₀ w k · have hg2 := hg.2 obtain ⟨ω, t, h1, h2, h3, h4⟩ := win_rot hn hv hvi hT (winK w k) (by rw [hcard]; omega) (β₀ := 1 / 10000) (by norm_num) (by norm_num) (by rw [hcard]; nlinarith) (by rw [hcard]; exact hg2) rw [hcard] at h4 exact ⟨(ω, t), fun _ => ⟨h1, h2, h3, h4⟩⟩ · exact ⟨(1, 0), fun h => absurd h hg⟩ choose R hR using hex refine ⟨R, fun k hk => ⟨(hR k hk).1, (hR k hk).2.1, (hR k hk).2.2.1⟩, fun k hk1 hg hg' => ?_⟩ have hov := winK_overlap (n := n) (show 1 ≤ w by omega) hwn.le (show k < nWin n w by omega) rw [Nat.mod_eq_of_lt hk1] at hov have hs : Real.sqrt (2 * (1 / 10000 : ℝ)) ≤ 1 / 50 := by rw [Real.sqrt_le_left (by norm_num)] norm_num have hovR : 6 * Real.sqrt (2 * (1 / 10000)) * w + 6 * Real.sqrt (2 * (1 / 10000)) * w + 2 ≤ (((winK w k : Finset (ZMod n)) ∩ winK w (k + 1)).card : ℝ) := by have h1 : ((w - (w + 1) / 2 : ℕ) : ℝ) ≤ (((winK w k : Finset (ZMod n)) ∩ winK w (k + 1)).card : ℝ) := by exact_mod_cast hov have h2 : (w : ℝ) / 2 - 1 ≤ ((w - (w + 1) / 2 : ℕ) : ℝ) := by have : (w + 1) / 2 ≤ w := by omega rw [Nat.cast_sub this] have h3 : (((w + 1) / 2 : ℕ) : ℝ) ≤ ((w : ℝ) + 1) / 2 := by rw [le_div_iff₀ (by norm_num)] have : (w + 1) / 2 * 2 ≤ w + 1 := Nat.div_mul_le_self _ _ exact_mod_cast this linarith nlinarith have hglue := glue_rot hvi (hR k hg).2.2.2 (hR (k + 1) hg').2.2.2 hovR exact Prod.ext hglue.1 hglue.2 end Erdos94ThmA /-! ### INVERSE Thm 11.24′ steps 1–4, bookkeeping lemmas: exceptions, range end effects, exits of a stretch -/ namespace Erdos94ThmA open Finset /-- The rotation `z ↦ ωz + t` (`ω ≠ 1`) is `z ↦ O + ω(z − O)` with `O = t/(1 − ω)`. -/ theorem rot_centre {ω t : ℂ} (hω : ω ≠ 1) (z : ℂ) : t / (1 - ω) + ω * (z - t / (1 - ω)) = ω * z + t := by have h : (1 : ℂ) - ω ≠ 0 := sub_ne_zero.mpr (Ne.symm hω) field_simp ring open Classical in /-- Positions of ranges inside `S` that are exceptional for a rotation all lie in `X ⊇ excX ∩ S`: the range positions of the vertices `x ∈ S` with `nf(x) ≤ K/480` and range in `S` number at most `|X|·(K + K/480)`. -/ theorem bdc_sum_le {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) (u₀ : ℝ) (Y S X : Finset (ZMod n)) (hXS : ∀ z ∈ Y, z ∈ S → z ∈ X) (Gc : Finset (ZMod n)) (hGc : ∀ x ∈ Gc, (nfc v U u₀ x : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S) : (∑ x ∈ Gc, (bdc v Y u₀ x : ℝ)) ≤ (X.card : ℝ) * ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) := by obtain ⟨M, hM⟩ : ∃ m : ℕ, m = ⌊((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480⌋₊ := ⟨_, rfl⟩ have hMle : (M : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 := by rw [hM] exact Nat.floor_le (by positivity) have hcard : (Gc.sigma (fun x => (Fu0 v u₀ x).filter (fun j : ℕ => x + (j : ZMod n) ∈ Y))).card ≤ (X ×ˢ Icc 1 M).card := by apply card_le_card_of_injOn (fun p => (p.1 + (p.2 : ZMod n), p.2)) · intro p hp rw [mem_coe, mem_sigma] at hp obtain ⟨hx, hj⟩ := hp rw [mem_filter] at hj obtain ⟨hnf, hS⟩ := hGc p.1 hx obtain ⟨h1, h2⟩ := Fu0_le_card hv hj.1 have h3 : ((Fu0 v u₀ p.1).card : ℝ) ≤ ((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 := by have := Fu0_card hv U u₀ p.1 have h' : (Fu0 v u₀ p.1).card ≤ (U.filter (fun u => u < u₀)).card + nfc v U u₀ p.1 := by omega have h'' : ((Fu0 v u₀ p.1).card : ℝ) ≤ (U.filter (fun u => u < u₀)).card + (nfc v U u₀ p.1 : ℝ) := by exact_mod_cast h' linarith have h5 : p.2 ≤ M := by rw [hM] exact Nat.le_floor (le_trans (by exact_mod_cast h2) h3) rw [mem_coe, mem_product, mem_Icc] exact ⟨hXS _ hj.2 (hS p.2 hj.1), h1, h5⟩ · intro p hp p' hp' h have h2 : p.2 = p'.2 := (Prod.mk.inj h).2 have h1 : p.1 + (p.2 : ZMod n) = p'.1 + (p'.2 : ZMod n) := (Prod.mk.inj h).1 rw [h2] at h1 exact Sigma.ext (add_right_cancel h1) (heq_of_eq h2) rw [card_sigma, card_product, Nat.card_Icc] at hcard have hc : ∑ x ∈ Gc, bdc v Y u₀ x ≤ X.card * M := by have := hcard unfold bdc simpa using this have hcR : (∑ x ∈ Gc, (bdc v Y u₀ x : ℝ)) ≤ (X.card : ℝ) * M := by exact_mod_cast hc have := mul_le_mul_of_nonneg_left hMle (Nat.cast_nonneg X.card : (0 : ℝ) ≤ X.card) linarith open Classical in /-- **Range end effects.** The vertices `x ∈ S` some of whose first `J` successors leave `S` number at most `J` times the exits of `S` (`z ∈ S` with `z + 1 ∉ S`). -/ theorem leave_le {n : ℕ} [NeZero n] (S : Finset (ZMod n)) (J : ℕ) : (S.filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S)).card ≤ J * (S.filter (fun z => z + 1 ∉ S)).card := by have hsub : S.filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S) ⊆ (S.filter (fun z => z + 1 ∉ S)).biUnion (fun z => (range J).image (fun i : ℕ => z - (i : ZMod n))) := by intro x hx obtain ⟨hxS, hex⟩ := mem_filter.mp hx have hj := Nat.find_spec hex obtain ⟨hj1, hjJ, hjS⟩ := hj rw [mem_biUnion] refine ⟨x + ((Nat.find hex - 1 : ℕ) : ZMod n), ?_, mem_image.mpr ⟨Nat.find hex - 1, mem_range.mpr (by omega), by ring⟩⟩ rw [mem_filter] constructor · rcases Nat.eq_or_lt_of_le hj1 with h | h · rw [← h, Nat.sub_self, Nat.cast_zero, add_zero] exact hxS · by_contra hc have hmin := Nat.find_min hex (show Nat.find hex - 1 < Nat.find hex by omega) exact hmin ⟨by omega, by omega, hc⟩ · have e : x + ((Nat.find hex - 1 : ℕ) : ZMod n) + 1 = x + ((Nat.find hex : ℕ) : ZMod n) := by rw [Nat.cast_sub hj1] push_cast ring rw [e] exact hjS calc (S.filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S)).card ≤ ((S.filter (fun z => z + 1 ∉ S)).biUnion (fun z => (range J).image (fun i : ℕ => z - (i : ZMod n)))).card := card_le_card hsub _ ≤ ∑ z ∈ S.filter (fun z => z + 1 ∉ S), ((range J).image (fun i : ℕ => z - (i : ZMod n))).card := card_biUnion_le _ ≤ ∑ _z ∈ S.filter (fun z => z + 1 ∉ S), J := sum_le_sum (fun z _ => card_image_le.trans (by rw [card_range])) _ = J * (S.filter (fun z => z + 1 ∉ S)).card := by rw [sum_const, smul_eq_mul, mul_comm] /-- The last vertex of a window: if `z ∈ W_k` and `z + 1 ∉ W_k` then `z = a_k + (w − 1)`. -/ theorem winK_last {n : ℕ} [NeZero n] {w k : ℕ} {z : ZMod n} (hz : z ∈ (winK w k : Finset (ZMod n))) (hz1 : z + 1 ∉ (winK w k : Finset (ZMod n))) : z = ((k * ((w + 1) / 2) : ℕ) : ZMod n) + ((w - 1 : ℕ) : ZMod n) := by obtain ⟨i, hi, rfl⟩ := winK_mem hz by_contra hne apply hz1 have hi' : i + 1 < w := by by_contra h apply hne rw [show i = w - 1 by omega] unfold winK rw [mem_image] exact ⟨i + 1, mem_range.mpr hi', by push_cast; ring⟩ /-- The vertex after the last vertex of `W_k` lies in `W_{k+1}` (`k + 1` a window index). -/ theorem winK_next {n : ℕ} [NeZero n] {w k : ℕ} (hw : 1 ≤ w) : ((k * ((w + 1) / 2) : ℕ) : ZMod n) + ((w - 1 : ℕ) : ZMod n) + 1 ∈ (winK w (k + 1) : Finset (ZMod n)) := by unfold winK rw [mem_image] refine ⟨w - (w + 1) / 2, mem_range.mpr (by omega), ?_⟩ have e1 : (k + 1) * ((w + 1) / 2) + (w - (w + 1) / 2) = k * ((w + 1) / 2) + (w - 1) + 1 := by have : (w + 1) / 2 ≤ w := by omega rw [add_mul, one_mul] omega rw [e1] push_cast ring end Erdos94ThmA /-! ### INVERSE Thm 11.24′ steps 1–4: from good windows to boundedly many circles with distinct centres -/ namespace Erdos94ThmA open Finset open Classical in /-- Windows of a sub-family: `Σ_{k ∈ I} #{x ∈ W_k : P x} ≤ 6·#{x : P x}`. -/ theorem win_sum_le {n : ℕ} [NeZero n] {w : ℕ} (hw : 1 ≤ w) (hwn : w < n) (I : Finset ℕ) (hI : I ⊆ range (nWin n w)) (P : ZMod n → Prop) : ∑ k ∈ I, ((winK w k : Finset (ZMod n)).filter P).card ≤ 6 * ((univ : Finset (ZMod n)).filter P).card := by have h1 : ∑ k ∈ I, ((winK w k : Finset (ZMod n)).filter P).card ≤ ∑ k ∈ range (nWin n w), ((winK w k : Finset (ZMod n)).filter P).card := sum_le_sum_of_subset_of_nonneg hI (fun _ _ _ => Nat.zero_le _) have h2 : ∑ k ∈ range (nWin n w), ((winK w k : Finset (ZMod n)).filter P).card = ∑ k ∈ range (nWin n w), ((winK w k : Finset (ZMod n)) ∩ (univ : Finset (ZMod n)).filter P).card := by refine sum_congr rfl (fun k _ => ?_) congr 1 ext x simp rw [h2, sum_card_inter_swap] at h1 refine h1.trans ?_ calc ∑ y ∈ (univ : Finset (ZMod n)).filter P, ((range (nWin n w)).filter (fun k => y ∈ (winK w k : Finset (ZMod n)))).card ≤ ∑ _y ∈ (univ : Finset (ZMod n)).filter P, 6 := sum_le_sum (fun y _ => winK_mult hw hwn y) _ = 6 * ((univ : Finset (ZMod n)).filter P).card := by rw [sum_const, smul_eq_mul, mul_comm] open Classical in /-- **INVERSE Theorem 11.24′, steps 1–4.** From the good windows (`goodW`, Thm 11.9″) and their rotations: there is a family `C` of circles (centre, radius) with positive radii and pairwise distinct centres, at most `#bad + 1` of them, such that the vertices on none of them number at most `11·(6·#{def > K/480} + 6·#{nf > K/480} + 241·Σ_good 6√((chg+1)/2) + (K + K/480 + 1)(#bad + 1)) + #bad·w`. (Stretches = unions of the good windows with one rotation; per stretch the good vertices with ranges inside the stretch (`thm1115S_solid`); solid stretches with a common centre share their circle (`concentric_solid`); non-solid stretches are counted whole.) -/ theorem circles_from_windows {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (hT : ∀ t : ℂ, t ≠ 0 → ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) (U : Finset ℝ) {u₀ : ℝ} (hK30 : 30 ≤ (U.filter (fun u => u < u₀)).card) {w : ℕ} (hw : 71 ≤ w) (hwn : w < n) : ∃ C : Finset (ℂ × ℝ), (∀ c ∈ C, 0 < c.2) ∧ (∀ c ∈ C, ∀ c' ∈ C, c.1 = c'.1 → c = c') ∧ C.card ≤ ((range (nWin n w)).filter (fun k => ¬ goodW v u₀ w k)).card + 1 ∧ (((univ : Finset (ZMod n)).filter (fun x => ∀ c ∈ C, ‖v x - c.1‖ ≠ c.2)).card : ℝ) ≤ 11 * (6 * (((univ : Finset (ZMod n)).filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) + 6 * (((univ : Finset (ZMod n)).filter (fun x => ((U.filter (fun u => u < u₀)).card : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) + 241 * ∑ k ∈ (range (nWin n w)).filter (fun k => goodW v u₀ w k), 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2) + (((U.filter (fun u => u < u₀)).card : ℝ) + ((U.filter (fun u => u < u₀)).card : ℝ) / 480 + 1) * (((range (nWin n w)).filter (fun k => ¬ goodW v u₀ w k)).card + 1)) + ((range (nWin n w)).filter (fun k => ¬ goodW v u₀ w k)).card * w := by have hL := ccw_leftTurns hn hv have hw1 : 1 ≤ w := by omega obtain ⟨K, hK⟩ : ∃ K : ℕ, K = (U.filter (fun u => u < u₀)).card := ⟨_, rfl⟩ rw [← hK] rw [← hK] at hK30 have hKR : (30 : ℝ) ≤ K := by exact_mod_cast hK30 obtain ⟨m, hm⟩ : ∃ m, m = nWin n w := ⟨_, rfl⟩ rw [← hm] obtain ⟨R, hR1, hR2⟩ := win_rots hn hv hvi hT (u₀ := u₀) hw hwn rw [← hm] at hR2 obtain ⟨Gd, hGd⟩ : ∃ s : Finset ℕ, s = (range m).filter (fun k => goodW v u₀ w k) := ⟨_, rfl⟩ obtain ⟨Bd, hBd⟩ : ∃ s : Finset ℕ, s = (range m).filter (fun k => ¬ goodW v u₀ w k) := ⟨_, rfl⟩ rw [← hGd, ← hBd] have hGdm : Gd ⊆ range m := by rw [hGd]; exact filter_subset _ _ have hmem_Gd : ∀ k, k ∈ Gd ↔ k < m ∧ goodW v u₀ w k := by intro k; rw [hGd, mem_filter, mem_range] obtain ⟨Rots, hRots⟩ : ∃ s : Finset (ℂ × ℂ), s = Gd.image R := ⟨_, rfl⟩ -- stretch data obtain ⟨O, hO⟩ : ∃ O : ℂ × ℂ → ℂ, O = fun r => r.2 / (1 - r.1) := ⟨_, rfl⟩ obtain ⟨Kr, hKr⟩ : ∃ Kr : ℂ × ℂ → Finset ℕ, Kr = fun r => Gd.filter (fun k => R k = r) := ⟨_, rfl⟩ obtain ⟨S, hS⟩ : ∃ S : ℂ × ℂ → Finset (ZMod n), S = fun r => (Kr r).biUnion (fun k => (winK w k : Finset (ZMod n))) := ⟨_, rfl⟩ obtain ⟨X, hX⟩ : ∃ X : ℂ × ℂ → Finset (ZMod n), X = fun r => (Kr r).biUnion (fun k => (winK w k : Finset (ZMod n)).filter (fun x => v (x + 1) ≠ r.1 * v x + r.2)) := ⟨_, rfl⟩ obtain ⟨G, hG⟩ : ∃ G : ℂ × ℂ → Finset (ZMod n), G = fun r => (S r).filter (fun x => x ∈ goodG v U u₀ (excX v (O r) r.1) ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r) := ⟨_, rfl⟩ have hmem_Kr : ∀ r k, k ∈ Kr r ↔ k ∈ Gd ∧ R k = r := by intro r k; rw [hKr, mem_filter] have hmem_S : ∀ r z, z ∈ S r ↔ ∃ k ∈ Kr r, z ∈ (winK w k : Finset (ZMod n)) := by intro r z; rw [hS, mem_biUnion] have hGS : ∀ r, G r ⊆ S r := by intro r; rw [hG]; exact filter_subset _ _ have hmem_G : ∀ r x, x ∈ G r ↔ x ∈ S r ∧ x ∈ goodG v U u₀ (excX v (O r) r.1) ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r := by intro r x; rw [hG, mem_filter] -- rotations of the stretches have hrot : ∀ r ∈ Rots, ‖r.1‖ = 1 ∧ r.1 ≠ 1 ∧ ∃ k ∈ Gd, R k = r := by intro r hr rw [hRots, mem_image] at hr obtain ⟨k, hk, rfl⟩ := hr have hg := ((hmem_Gd k).mp hk).2 exact ⟨(hR1 k hg).1, (hR1 k hg).2.1, k, hk, rfl⟩ -- exceptional vertices of a stretch lie in `X` have hexc : ∀ r ∈ Rots, ∀ z ∈ excX v (O r) r.1, z ∈ S r → z ∈ X r := by intro r hr z hz hzS obtain ⟨_, hne, _⟩ := hrot r hr obtain ⟨k, hk, hzk⟩ := (hmem_S r z).mp hzS unfold excX at hz have hz' := (mem_filter.mp hz).2 rw [hO] at hz' simp only at hz' rw [rot_centre hne] at hz' rw [hX] simp only rw [mem_biUnion] exact ⟨k, hk, mem_filter.mpr ⟨hzk, hz'⟩⟩ -- solid stretches: a vertex `x₀` and its circle have hsol : ∀ r ∈ Rots, 10 * (S r \ G r).card < (G r).card → ∃ x₀ ∈ G r, (((Fu0 v u₀ x₀).filter (fun j : ℕ => x₀ + (j : ZMod n) ∉ G r)).card : ℝ) ≤ ((U.filter (fun u => u < u₀)).card + ((U.filter (fun u => u < u₀)).card : ℝ) / 480) / 10 ∧ ∀ z ∈ G r, ‖v z - O r‖ = ‖v x₀ - O r‖ := by intro r hr hs obtain ⟨h1, _, _⟩ := hrot r hr refine thm1115S_solid hL U u₀ (by rw [← hK]; exact hK30) h1 (S r) (G r) ?_ ?_ hs · intro x hx exact ((hmem_G r x).mp hx).2.1 · intro x hx exact ((hmem_G r x).mp hx).2.2 choose! x₀ hx₀ using hsol obtain ⟨Sol, hSol⟩ : ∃ s : Finset (ℂ × ℂ), s = Rots.filter (fun r => 10 * (S r \ G r).card < (G r).card) := ⟨_, rfl⟩ have hmem_Sol : ∀ r, r ∈ Sol ↔ r ∈ Rots ∧ 10 * (S r \ G r).card < (G r).card := by intro r; rw [hSol, mem_filter] refine ⟨Sol.image (fun r => (O r, ‖v (x₀ r) - O r‖)), ?_, ?_, ?_, ?_⟩ · -- positive radii intro c hc obtain ⟨r, hr, rfl⟩ := mem_image.mp hc obtain ⟨hrR, hs⟩ := (hmem_Sol r).mp hr obtain ⟨hx0G, _, hcirc⟩ := hx₀ r hrR hs simp only rcases (norm_nonneg (v (x₀ r) - O r)).lt_or_eq with h | h · exact h · exfalso have hall : ∀ z ∈ G r, v z = O r := by intro z hz have := hcirc z hz rw [← h] at this exact sub_eq_zero.mp (norm_eq_zero.mp this) have hG1 : (G r).card ≤ 1 := by rw [card_le_one] intro a ha b hb exact hvi ((hall a ha).trans (hall b hb).symm) have hSG : (S r \ G r).card = 0 := by omega have hSr : (S r).card ≤ 1 := by have := card_sdiff_add_card_eq_card (hGS r) omega obtain ⟨_, _, k, hk, hRk⟩ := hrot r hrR have hsub : (winK w k : Finset (ZMod n)) ⊆ S r := by intro z hz exact (hmem_S r z).mpr ⟨k, (hmem_Kr r k).mpr ⟨hk, hRk⟩, hz⟩ have := card_le_card hsub rw [winK_card hwn.le] at this omega · -- distinct centres intro c hc c' hc' hcc obtain ⟨r, hr, rfl⟩ := mem_image.mp hc obtain ⟨r', hr', rfl⟩ := mem_image.mp hc' simp only at hcc ⊢ obtain ⟨hrR, hs⟩ := (hmem_Sol r).mp hr obtain ⟨hrR', hs'⟩ := (hmem_Sol r').mp hr' obtain ⟨hx0G, hfew, hcirc⟩ := hx₀ r hrR hs obtain ⟨hx0G', hfew', hcirc'⟩ := hx₀ r' hrR' hs' have hGg : G r ⊆ goodG v U u₀ (excX v (O r) r.1) := fun x hx => ((hmem_G r x).mp hx).2.1 have hGg' : G r' ⊆ goodG v U u₀ (excX v (O r) r'.1) := by intro x hx rw [hcc] exact ((hmem_G r' x).mp hx).2.1 have hcirc'' : ∀ z ∈ G r', ‖v z - O r‖ = ‖v (x₀ r') - O r‖ := by rw [hcc]; exact hcirc' have heq := concentric_solid hL U u₀ (by rw [← hK]; exact hK30) (hrot r hrR).1 (hrot r' hrR').1 (G r) (G r') hGg hGg' hx0G hx0G' hfew hfew' hcirc hcirc'' rw [Prod.mk.injEq] exact ⟨hcc, by rw [heq, hcc]⟩ · -- at most `#bad + 1` circles have h1 := run_count m (fun k => goodW v u₀ w k) R (fun k hk g1 g2 => hR2 k hk g1 g2) rw [← hGd, ← hBd, ← hRots] at h1 calc (Sol.image (fun r => (O r, ‖v (x₀ r) - O r‖))).card ≤ Sol.card := card_image_le _ ≤ Rots.card := by rw [hSol]; exact card_filter_le _ _ _ ≤ Bd.card + 1 := h1 · -- the vertices on no circle obtain ⟨J, hJ⟩ : ∃ J : ℕ, J = ⌊(K : ℝ) + (K : ℝ) / 480⌋₊ := ⟨_, rfl⟩ have hJle : (J : ℝ) ≤ (K : ℝ) + (K : ℝ) / 480 := by rw [hJ]; exact Nat.floor_le (by positivity) have hmaps : ∀ k ∈ Gd, R k ∈ Rots := fun k hk => by rw [hRots]; exact mem_image_of_mem R hk have hfib : ∀ g : ℕ → ℝ, ∑ r ∈ Rots, ∑ k ∈ Kr r, g k = ∑ k ∈ Gd, g k := by intro g rw [← sum_fiberwise_of_maps_to hmaps] refine sum_congr rfl (fun r _ => ?_) rw [hKr] -- T r: the part of the stretch `r` that may be off its circle obtain ⟨T, hT'⟩ : ∃ T : ℂ × ℂ → Finset (ZMod n), T = fun r => if 10 * (S r \ G r).card < (G r).card then S r \ G r else S r := ⟨_, rfl⟩ obtain ⟨unc, hunc⟩ : ∃ s : Finset (ZMod n), s = (univ : Finset (ZMod n)).filter (fun x => ∀ k ∈ Gd, x ∉ (winK w k : Finset (ZMod n))) := ⟨_, rfl⟩ have hEsub : (univ : Finset (ZMod n)).filter (fun x => ∀ c ∈ Sol.image (fun r => (O r, ‖v (x₀ r) - O r‖)), ‖v x - c.1‖ ≠ c.2) ⊆ unc ∪ Rots.biUnion T := by intro x hx have hx' := (mem_filter.mp hx).2 by_cases hu : ∀ k ∈ Gd, x ∉ (winK w k : Finset (ZMod n)) · exact mem_union_left _ (by rw [hunc]; exact mem_filter.mpr ⟨mem_univ _, hu⟩) · push Not at hu obtain ⟨k, hk, hxk⟩ := hu refine mem_union_right _ (mem_biUnion.mpr ⟨R k, hmaps k hk, ?_⟩) have hxS : x ∈ S (R k) := (hmem_S (R k) x).mpr ⟨k, (hmem_Kr (R k) k).mpr ⟨hk, rfl⟩, hxk⟩ rw [hT'] simp only split_ifs with hs · refine mem_sdiff.mpr ⟨hxS, fun hxG => ?_⟩ have hrR : R k ∈ Rots := hmaps k hk obtain ⟨_, _, hcirc⟩ := hx₀ (R k) hrR hs apply hx' (O (R k), ‖v (x₀ (R k)) - O (R k)‖) (mem_image.mpr ⟨R k, (hmem_Sol (R k)).mpr ⟨hrR, hs⟩, rfl⟩) exact hcirc x hxG · exact hxS -- the uncovered vertices have hunc_le : (unc.card : ℝ) ≤ Bd.card * w := by have hsub : unc ⊆ Bd.biUnion (fun k => (winK w k : Finset (ZMod n))) := by intro x hx rw [hunc, mem_filter] at hx obtain ⟨k, hk, hxk⟩ := win_cover (n := n) hw1 x rw [← hm] at hk refine mem_biUnion.mpr ⟨k, ?_, hxk⟩ rw [hBd, mem_filter, mem_range] refine ⟨hk, fun hg => hx.2 k ((hmem_Gd k).mpr ⟨hk, hg⟩) hxk⟩ have h1 := (card_le_card hsub).trans card_biUnion_le rw [sum_congr rfl (fun k _ => winK_card hwn.le k), sum_const, smul_eq_mul] at h1 exact_mod_cast h1 -- per stretch: `|T r| ≤ 11·(d + f + b + l)` have hTr : ∀ r ∈ Rots, ((T r).card : ℝ) ≤ 11 * ( (((S r).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) + (((S r).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) + ((((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)).filter (fun x => (K : ℝ) / 240 < bdc v (excX v (O r) r.1) u₀ x)).card : ℝ) + (((S r).filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S r)).card : ℝ)) := by intro r _ have hSG : S r \ G r ⊆ (((S r).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)) ∪ ((S r).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x))) ∪ ((((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)).filter (fun x => (K : ℝ) / 240 < bdc v (excX v (O r) r.1) u₀ x)) ∪ ((S r).filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S r))) := by intro x hx obtain ⟨hxS, hxG⟩ := mem_sdiff.mp hx rw [hmem_G] at hxG simp only [mem_union, mem_filter] by_cases hnf : (K : ℝ) / 480 < nfc v U u₀ x · exact Or.inl (Or.inr ⟨hxS, hnf⟩) · push Not at hnf by_cases hrange : ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r · have hng : x ∉ goodG v U u₀ (excX v (O r) r.1) := fun h => hxG ⟨hxS, h, hrange⟩ unfold goodG at hng rw [mem_filter] at hng push Not at hng have hng' := hng (mem_univ _) rw [← hK] at hng' by_cases hd : (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x · exact Or.inl (Or.inl ⟨hxS, hd⟩) · push Not at hd exact Or.inr (Or.inl ⟨⟨hxS, hnf, hrange⟩, hng' hd hnf⟩) · push Not at hrange obtain ⟨j, hj, hjS⟩ := hrange obtain ⟨h1, h2⟩ := Fu0_le_card hL hj have h3 : ((Fu0 v u₀ x).card : ℝ) ≤ (K : ℝ) + (K : ℝ) / 480 := by have := Fu0_card hL U u₀ x have h' : (Fu0 v u₀ x).card ≤ (U.filter (fun u => u < u₀)).card + nfc v U u₀ x := by omega rw [← hK] at h' have h'' : ((Fu0 v u₀ x).card : ℝ) ≤ K + (nfc v U u₀ x : ℝ) := by exact_mod_cast h' linarith have hjJ : j ≤ J := by rw [hJ] exact Nat.le_floor (le_trans (by exact_mod_cast h2) h3) exact Or.inr (Or.inr ⟨hxS, j, h1, hjJ, hjS⟩) have hc := (card_le_card hSG).trans ((card_union_le _ _).trans (Nat.add_le_add (card_union_le _ _) (card_union_le _ _))) have hcR : (((S r \ G r)).card : ℝ) ≤ (((S r).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) + (((S r).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) + ((((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)).filter (fun x => (K : ℝ) / 240 < bdc v (excX v (O r) r.1) u₀ x)).card : ℝ) + (((S r).filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S r)).card : ℝ) := by have h : (((S r \ G r)).card : ℝ) ≤ (((S r).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) + (((S r).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) + (((((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)).filter (fun x => (K : ℝ) / 240 < bdc v (excX v (O r) r.1) u₀ x)).card : ℝ) + (((S r).filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S r)).card : ℝ)) := by exact_mod_cast hc linarith have hTle : ((T r).card : ℝ) ≤ 11 * ((S r \ G r).card : ℝ) := by rw [hT'] simp only split_ifs with hs · have : (0 : ℝ) ≤ ((S r \ G r).card : ℝ) := Nat.cast_nonneg _ linarith · push Not at hs have h1 := card_sdiff_add_card_eq_card (hGS r) have h2 : (S r).card ≤ 11 * (S r \ G r).card := by omega exact_mod_cast h2 linarith -- the four sums have hD : ∑ r ∈ Rots, (((S r).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) ≤ 6 * (((univ : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) := by have h1 : ∀ r, (((S r).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) ≤ ∑ k ∈ Kr r, (((winK w k : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) := by intro r rw [hS] simp only rw [filter_biUnion] exact_mod_cast card_biUnion_le have h2 := win_sum_le hw1 hwn Gd (by rw [← hm]; exact hGdm) (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x) have h2R : ∑ k ∈ Gd, (((winK w k : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) ≤ 6 * (((univ : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) := by exact_mod_cast h2 calc _ ≤ ∑ r ∈ Rots, ∑ k ∈ Kr r, (((winK w k : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) := sum_le_sum (fun r _ => h1 r) _ = _ := hfib _ _ ≤ _ := h2R have hF : ∑ r ∈ Rots, (((S r).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) ≤ 6 * (((univ : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) := by have h1 : ∀ r, (((S r).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) ≤ ∑ k ∈ Kr r, (((winK w k : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) := by intro r rw [hS] simp only rw [filter_biUnion] exact_mod_cast card_biUnion_le have h2 := win_sum_le hw1 hwn Gd (by rw [← hm]; exact hGdm) (fun x => (K : ℝ) / 480 < nfc v U u₀ x) have h2R : ∑ k ∈ Gd, (((winK w k : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) ≤ 6 * (((univ : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) := by exact_mod_cast h2 calc _ ≤ ∑ r ∈ Rots, ∑ k ∈ Kr r, (((winK w k : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) := sum_le_sum (fun r _ => h1 r) _ = _ := hfib _ _ ≤ _ := h2R have hXsum : ∑ r ∈ Rots, ((X r).card : ℝ) ≤ ∑ k ∈ Gd, 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2) := by have h1 : ∀ r, ((X r).card : ℝ) ≤ ∑ k ∈ Kr r, 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2) := by intro r have a : (X r).card ≤ ∑ k ∈ Kr r, ((winK w k : Finset (ZMod n)).filter (fun x => v (x + 1) ≠ r.1 * v x + r.2)).card := by rw [hX] exact card_biUnion_le have aR : ((X r).card : ℝ) ≤ ∑ k ∈ Kr r, (((winK w k : Finset (ZMod n)).filter (fun x => v (x + 1) ≠ r.1 * v x + r.2)).card : ℝ) := by exact_mod_cast a refine aR.trans (sum_le_sum (fun k hk => ?_)) obtain ⟨hkG, hRk⟩ := (hmem_Kr r k).mp hk have hg := ((hmem_Gd k).mp hkG).2 have := (hR1 k hg).2.2 rw [hRk] at this exact this calc _ ≤ ∑ r ∈ Rots, ∑ k ∈ Kr r, 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2) := sum_le_sum (fun r _ => h1 r) _ = _ := hfib _ have hB : ∀ r ∈ Rots, ((((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)).filter (fun x => (K : ℝ) / 240 < bdc v (excX v (O r) r.1) u₀ x)).card : ℝ) ≤ 241 * ((X r).card : ℝ) := by intro r hr have hsum := bdc_sum_le hL U u₀ (excX v (O r) r.1) (S r) (X r) (fun z hz hzS => hexc r hr z hz hzS) ((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)) (fun x hx => by rw [← hK]; exact (mem_filter.mp hx).2) rw [← hK] at hsum have hmk := markov_card ((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)) (fun x => bdc v (excX v (O r) r.1) u₀ x) (c := (K : ℝ) / 240) (by positivity) hsum have hX0 : (0 : ℝ) ≤ ((X r).card : ℝ) := Nat.cast_nonneg _ have hK0 : (0 : ℝ) < K := by linarith have hmk' : ((((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)).filter (fun x => (K : ℝ) / 240 < bdc v (excX v (O r) r.1) u₀ x)).card : ℝ) ≤ ((X r).card : ℝ) * ((K : ℝ) + (K : ℝ) / 480) / ((K : ℝ) / 240) := by rw [le_div_iff₀ (by positivity)] exact hmk calc _ ≤ ((X r).card : ℝ) * ((K : ℝ) + (K : ℝ) / 480) / ((K : ℝ) / 240) := hmk' _ = 240.5 * ((X r).card : ℝ) := by field_simp; ring _ ≤ 241 * ((X r).card : ℝ) := by linarith have hLv : ∑ r ∈ Rots, (((S r).filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S r)).card : ℝ) ≤ ((K : ℝ) + (K : ℝ) / 480 + 1) * (Bd.card + 1) := by have hex1 : ∀ r ∈ Rots, ((S r).filter (fun z => z + 1 ∉ S r)).card ≤ ((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card := by intro r _ have hsub : (S r).filter (fun z => z + 1 ∉ S r) ⊆ ((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).image (fun k => ((k * ((w + 1) / 2) : ℕ) : ZMod n) + ((w - 1 : ℕ) : ZMod n)) := by intro z hz obtain ⟨hzS, hz1⟩ := mem_filter.mp hz obtain ⟨k, hk, hzk⟩ := (hmem_S r z).mp hzS have hz1k : z + 1 ∉ (winK w k : Finset (ZMod n)) := fun h => hz1 ((hmem_S r (z + 1)).mpr ⟨k, hk, h⟩) have hlast := winK_last hzk hz1k refine mem_image.mpr ⟨k, mem_filter.mpr ⟨hk, ?_⟩, hlast.symm⟩ obtain ⟨hkG, hRk⟩ := (hmem_Kr r k).mp hk have hkm := ((hmem_Gd k).mp hkG).1 by_contra hc push Not at hc obtain ⟨hne, hg⟩ := hc have hk1 : k + 1 < m := by omega have hRe := hR2 k hk1 ((hmem_Gd k).mp hkG).2 hg apply hz1 refine (hmem_S r (z + 1)).mpr ⟨k + 1, (hmem_Kr r (k + 1)).mpr ⟨(hmem_Gd (k + 1)).mpr ⟨hk1, hg⟩, by rw [← hRe, hRk]⟩, ?_⟩ rw [hlast] exact winK_next hw1 exact (card_le_card hsub).trans card_image_le have hsumex : ∑ r ∈ Rots, ((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card ≤ Bd.card + 1 := by have e : ∑ r ∈ Rots, ((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card = (Gd.filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card := by rw [card_eq_sum_card_fiberwise (f := R) (t := Rots) (fun k hk => hmaps k (mem_filter.mp hk).1)] refine sum_congr rfl (fun r _ => ?_) rw [hKr] simp only rw [filter_filter, filter_filter] congr 1 ext k simp only [mem_filter] tauto rw [e] have hsub : Gd.filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1)) ⊆ insert (m - 1) (Bd.image (fun k => k - 1)) := by intro k hk obtain ⟨hkG, hq⟩ := mem_filter.mp hk have hkm := ((hmem_Gd k).mp hkG).1 rcases hq with h | h · rw [show k = m - 1 by omega] exact mem_insert_self _ _ · by_cases hk1 : k + 1 < m · refine mem_insert_of_mem (mem_image.mpr ⟨k + 1, ?_, by omega⟩) rw [hBd, mem_filter, mem_range] exact ⟨hk1, h⟩ · rw [show k = m - 1 by omega] exact mem_insert_self _ _ calc _ ≤ (insert (m - 1) (Bd.image (fun k => k - 1))).card := card_le_card hsub _ ≤ (Bd.image (fun k => k - 1)).card + 1 := card_insert_le _ _ _ ≤ Bd.card + 1 := by have := card_image_le (s := Bd) (f := fun k => k - 1); omega have hl : ∀ r ∈ Rots, (((S r).filter (fun x => ∃ j : ℕ, 1 ≤ j ∧ j ≤ J ∧ x + (j : ZMod n) ∉ S r)).card : ℝ) ≤ J * (((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card : ℝ) := by intro r hr have := (leave_le (S r) J).trans (Nat.mul_le_mul_left J (hex1 r hr)) exact_mod_cast this have hsumexR : ∑ r ∈ Rots, (((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card : ℝ) ≤ Bd.card + 1 := by exact_mod_cast hsumex calc _ ≤ ∑ r ∈ Rots, (J : ℝ) * (((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card : ℝ) := sum_le_sum hl _ = (J : ℝ) * ∑ r ∈ Rots, (((Kr r).filter (fun k => k + 1 = m ∨ ¬ goodW v u₀ w (k + 1))).card : ℝ) := by rw [mul_sum] _ ≤ ((K : ℝ) + (K : ℝ) / 480 + 1) * (Bd.card + 1) := by apply mul_le_mul (by linarith) hsumexR (by positivity) (by positivity) -- assemble have hE := (card_le_card hEsub).trans ((card_union_le _ _).trans (Nat.add_le_add_left card_biUnion_le _)) have hER : (((univ : Finset (ZMod n)).filter (fun x => ∀ c ∈ Sol.image (fun r => (O r, ‖v (x₀ r) - O r‖)), ‖v x - c.1‖ ≠ c.2)).card : ℝ) ≤ (unc.card : ℝ) + ∑ r ∈ Rots, ((T r).card : ℝ) := by exact_mod_cast hE have hTs := sum_le_sum hTr rw [← mul_sum, sum_add_distrib, sum_add_distrib, sum_add_distrib] at hTs have hBs : ∑ r ∈ Rots, ((((S r).filter (fun x => (nfc v U u₀ x : ℝ) ≤ (K : ℝ) / 480 ∧ ∀ j ∈ Fu0 v u₀ x, x + (j : ZMod n) ∈ S r)).filter (fun x => (K : ℝ) / 240 < bdc v (excX v (O r) r.1) u₀ x)).card : ℝ) ≤ 241 * ∑ k ∈ Gd, 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2) := by calc _ ≤ ∑ r ∈ Rots, 241 * ((X r).card : ℝ) := sum_le_sum hB _ = 241 * ∑ r ∈ Rots, ((X r).card : ℝ) := by rw [mul_sum] _ ≤ _ := by linarith linarith end Erdos94ThmA /-! ### INVERSE Lemma 11.26: (H₀) fails at most once; Thm 11.9′/11.9″ window counts without (H₀) -/ namespace Erdos94ThmA open Finset /-- If `F(y) ∋ y − 1` then the exterior angles at `v_{y−1}, v_y` sum to `> 3π/2`. -/ theorem H0_fail_big {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) {y : ZMod n} (hy : inF v y (y - 1)) : 3 * Real.pi / 2 < extAng v (y - 2) + extAng v (y - 1) := by rw [inF_iff hv] at hy obtain ⟨_, h2⟩ := hy have hv1 : (y - 1 - y).val = n - 1 := by have hne : y ≠ y - 1 := by intro h have h1 : (1 : ZMod n) = 0 := by linear_combination h have := congrArg ZMod.val h1 rw [val_one_of_three hn, ZMod.val_zero] at this omega have h2 := off_swap hne rw [show y - (y - 1) = 1 by ring, val_one_of_three hn] at h2 omega rw [hv1, show n - 1 - 1 = n - 2 by omega] at h2 have htot := turning_total_ge hv rw [← turning_full v y] at htot have hs := turning_split v y (n - 2) 2 rw [show n - 2 + 2 = n by omega] at hs have e2 : turning v (y + ((n - 2 : ℕ) : ZMod n)) 2 = extAng v (y - 2) + extAng v (y - 2 + 1) := by have e : y + ((n - 2 : ℕ) : ZMod n) = y - 2 := by rw [Nat.cast_sub (show 2 ≤ n by omega), ZMod.natCast_self] push_cast ring rw [e] simp only [turning, sum_range_succ, sum_range_zero, Nat.cast_zero, Nat.cast_one, add_zero, zero_add] rw [show y - 2 + 1 = y - 1 by ring] at e2 linarith /-- **INVERSE Lemma 11.26 (count): (H₀) fails at most once** — `F(y) ∋ y − 1` for at most one `y`. -/ theorem H0_fail_unique {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {y y' : ZMod n} (hy : inF v y (y - 1)) (hy' : inF v y' (y' - 1)) : y = y' := by have hL := ccw_leftTurns hn hv have htot := turning_total_eq hn hv have h1 := H0_fail_big hn hL hy have h2 := H0_fail_big hn hL hy' have hpos : ∀ x, 0 < extAng v x := extAng_pos hL have hlt : ∀ x, extAng v x < Real.pi := extAng_lt_pi hL have hsub : ∀ T : Finset (ZMod n), ∑ x ∈ T, extAng v x ≤ 2 * Real.pi := by intro T rw [← htot] exact sum_le_sum_of_subset_of_nonneg (subset_univ T) (fun x _ _ => (hpos x).le) have h10 : (1 : ZMod n) ≠ 0 := fun h => by have := congrArg ZMod.val h rw [val_one_of_three hn, ZMod.val_zero] at this omega have h20 : (2 : ZMod n) ≠ 0 := fun h => by have := congrArg ZMod.val h rw [show (2 : ZMod n) = ((2 : ℕ) : ZMod n) by simp, ZMod.val_natCast, Nat.mod_eq_of_lt (by omega), ZMod.val_zero] at this omega by_contra hne have hab : y - 2 ≠ y - 1 := fun h => h10 (by linear_combination (-1 : ZMod n) * h) have hab' : y' - 2 ≠ y' - 1 := fun h => h10 (by linear_combination (-1 : ZMod n) * h) have hbb : y - 1 ≠ y' - 1 := fun h => hne (by linear_combination h) have haa : y - 2 ≠ y' - 2 := fun h => hne (by linear_combination h) by_cases hc1 : y - 1 = y' - 2 · -- `y' = y + 1`: three consecutive angles at `y − 2, y − 1, y` have e : y' - 1 = y := by linear_combination -hc1 have hd1 : y - 2 ≠ y := fun h => h20 (by linear_combination (-1 : ZMod n) * h) have hd2 : y - 1 ≠ y := fun h => h10 (by linear_combination (-1 : ZMod n) * h) have hs3 := hsub {y - 2, y - 1, y} rw [sum_insert (by simp [hab, hd1]), sum_insert (by simp [hd2]), sum_singleton] at hs3 rw [← hc1, e] at h2 linarith [hlt (y - 1)] by_cases hc2 : y - 2 = y' - 1 · have e : y - 1 = y' := by linear_combination hc2 have hd1 : y' - 2 ≠ y' := fun h => h20 (by linear_combination (-1 : ZMod n) * h) have hd2 : y' - 1 ≠ y' := fun h => h10 (by linear_combination (-1 : ZMod n) * h) have hs3 := hsub {y' - 2, y' - 1, y'} rw [sum_insert (by simp [hab', hd1]), sum_insert (by simp [hd2]), sum_singleton] at hs3 rw [hc2, e] at h1 linarith [hlt (y' - 1)] · have hs4 := hsub {y - 2, y - 1, y' - 2, y' - 1} rw [sum_insert (by simp [hab, haa, hc2]), sum_insert (by simp [hc1, hbb]), sum_insert (by simp [hab']), sum_singleton] at hs4 linarith [Real.pi_pos] /-- (H₀) holds at every vertex but possibly one. -/ theorem H0_almost {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) : ∃ y₀ : ZMod n, ∀ y : ZMod n, y ≠ y₀ → ¬ inF v y (y - 1) := by by_cases h : ∃ y₀, inF v y₀ (y₀ - 1) · obtain ⟨y₀, hy₀⟩ := h exact ⟨y₀, fun y hy hy' => hy (H0_fail_unique hn hv hy' hy₀)⟩ · push Not at h exact ⟨0, fun y _ => h y⟩ open Classical in /-- Inside a window `W` (with `x + 1 ∈ W⁺` for `x ∈ W`), the bad `x ∈ A_u` whose chord `{x, T x}` lies in `W` number at most `#{y ∈ W⁺ : y ∉ A_u} + #{y ∈ W⁺ : y ∉ T_u(A_u)}`: the witness is `x + 1` (non-domain) or the first gap vertex `T x + 1` (non-image, Lemma 11.5). -/ theorem bad_in_window' {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) {y₀ : ZMod n} (hH0 : ∀ y : ZMod n, y ≠ y₀ → ¬ inF v y (y - 1)) (u : ℝ) (W Wp : Finset (ZMod n)) (hWp : ∀ x ∈ W, x + 1 ∈ Wp) : ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).card ≤ (Wp.filter (fun y => y ∉ Au v u)).card + (Wp.filter (fun y => y ∉ (Au v u).image (Tu v u))).card + 1 := by have hH : ∀ y : ZMod n, y + 1 ≠ y₀ → ¬ inF v (y + 1) y := fun y hy => by have := hH0 (y + 1) hy rwa [add_sub_cancel_right] at this have h1 : (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).filter (fun x => x + 1 ∉ Au v u)).card ≤ (Wp.filter (fun y => y ∉ Au v u)).card := by refine card_le_card_of_injOn (fun x => x + 1) (fun x hx => ?_) (fun x _ y _ h => ?_) · obtain ⟨hxB, hx1⟩ := mem_filter.mp hx obtain ⟨_, hxW, _, _⟩ := mem_filter.mp hxB exact mem_filter.mpr ⟨hWp x hxW, hx1⟩ · simpa using h have h2 : ((((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).filter (fun x => ¬ x + 1 ∉ Au v u)).filter (fun x => x + 1 ≠ y₀)).card ≤ (Wp.filter (fun y => y ∉ (Au v u).image (Tu v u))).card := by refine card_le_card_of_injOn (fun x => Tu v u x + 1) (fun x hx => ?_) (fun x hx y hy h => ?_) · obtain ⟨hx', hxy₀⟩ := mem_filter.mp hx obtain ⟨hxB, hx1⟩ := mem_filter.mp hx' obtain ⟨hxA, _, hTW, hbad⟩ := mem_filter.mp hxB have hx1A : x + 1 ∈ Au v u := not_not.mp hx1 have hne : Tu v u (x + 1) ≠ Tu v u x + 1 := fun h' => hbad ⟨hx1A, h'⟩ have hmono := Tu_off_mono hn hv hxA hx1A have hlt : (Tu v u x - x).val < (Tu v u (x + 1) - (x + 1)).val := by rcases hmono.1.lt_or_eq with h | h · exact h · exact absurd (hmono.2.mp h) hne obtain ⟨_, hKk, _⟩ := Tu_succ_off hn hv hxA hx1A (hH x hxy₀) have hcyc : cyc (Tu v u x) (Tu v u x + 1) (Tu v u (x + 1)) := by refine ⟨?_, ?_⟩ · rw [add_sub_cancel_left, val_one_of_three hn] norm_num · rw [add_sub_cancel_left, val_one_of_three hn, hKk] omega refine mem_filter.mpr ⟨hWp _ hTW, ?_⟩ rw [mem_image] rintro ⟨w, hw, hwz⟩ exact Tu_gap hn hv hxA hx1A (hH x hxy₀) hcyc hw hwz · have hx' := (mem_filter.mp (mem_filter.mp (mem_filter.mp hx).1).1).1 have hy' := (mem_filter.mp (mem_filter.mp (mem_filter.mp hy).1).1).1 have h' : Tu v u x = Tu v u y := by simpa using h exact Tu_injOn hv u (mem_coe.mpr hx') (mem_coe.mpr hy') h' have hs := card_filter_add_card_filter_not (s := (Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (fun x => x + 1 ∉ Au v u) have hs2 := card_filter_add_card_filter_not (s := ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).filter (fun x => ¬ x + 1 ∉ Au v u)) (fun x => x + 1 ≠ y₀) have hs3 : ((((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).filter (fun x => ¬ x + 1 ∉ Au v u)).filter (fun x => ¬ x + 1 ≠ y₀)).card ≤ 1 := by rw [card_le_one] intro a ha b hb have ha' := (mem_filter.mp ha).2 have hb' := (mem_filter.mp hb).2 push Not at ha' hb' have : a + 1 = b + 1 := by rw [ha', hb'] exact add_right_cancel this omega open Classical in /-- **The window decomposition** (proof of Theorem 11.9′ with the §11.16(a) matching bound). If all pairs of `W` are shorter than `u₀` and `x + 1 ∈ W⁺` for `x ∈ W`, then the changed ordered pairs of `W` number at most (pairs of `W` outside the classes `U`) + (ordered pairs of thin vertices of `W`) + `2Σ_{y ∈ W⁺} def′(y)`, the defect taken over the classes of `U` below `u₀`. -/ theorem chgW_le' {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : LeftTurns v) {y₀ : ZMod n} (hH0 : ∀ y : ZMod n, y ≠ y₀ → ¬ inF v y (y - 1)) (U : Finset ℝ) {u₀ : ℝ} (W Wp : Finset (ZMod n)) (hWp : ∀ x ∈ W, x + 1 ∈ Wp) (hspan : ∀ a ∈ W, ∀ b ∈ W, dist (v a) (v b) < u₀) : (chgW v W).card ≤ ((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card + ((W ∩ thinB v u₀).offDiag).card + 2 * ∑ y ∈ Wp, defc v (U.filter (fun u => u < u₀)) y + 2 * (U.filter (fun u => u < u₀)).card := by -- the bad sets per class have hsub : chgW v W ⊆ ((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)) ∪ (W ∩ thinB v u₀).offDiag ∪ (U.filter (fun u => u < u₀)).biUnion (fun u => ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))) := by intro p hp unfold chgW at hp obtain ⟨hpW, hne, hch⟩ := mem_filter.mp hp obtain ⟨h1W, h2W⟩ := mem_product.mp hpW by_cases hU : dist (v p.1) (v p.2) ∈ U · have hu0 := hspan _ h1W _ h2W by_cases hs : isShort v p.1 p.2 · refine mem_union_right _ (mem_biUnion.mpr ⟨dist (v p.1) (v p.2), mem_filter.mpr ⟨hU, hu0⟩, ?_⟩) rw [mem_union, mem_image, mem_image] rcases hs with h | h · left have hT := Tu_unique hv h rfl refine ⟨p.1, mem_filter.mpr ⟨mem_Au.mpr ⟨p.2, h, rfl⟩, h1W, by rw [hT]; exact h2W, ?_⟩, by rw [hT]⟩ rintro ⟨h1, h2⟩ apply hch have := (Tu_spec h1).2 rw [h2, hT] at this exact this · right rw [inB_iff_inF hv] at h have hd' : dist (v p.2) (v p.1) = dist (v p.1) (v p.2) := dist_comm _ _ have hT := Tu_unique hv h hd' refine ⟨p.2, mem_filter.mpr ⟨mem_Au.mpr ⟨p.1, h, hd'⟩, h2W, by rw [hT]; exact h1W, ?_⟩, by rw [hT]⟩ rintro ⟨h1, h2⟩ apply hch have := (Tu_spec h1).2 rw [h2, hT, dist_comm] at this exact this · refine mem_union_left _ (mem_union_right _ ?_) have hmid : p ∈ midO v (dist (v p.1) (v p.2)) := by unfold midO exact mem_filter.mpr ⟨mem_chO.mpr ⟨hne, rfl⟩, hs⟩ have := midO_sub_thin hv hu0 hmid rw [mem_offDiag] at this ⊢ exact ⟨mem_inter.mpr ⟨h1W, this.1⟩, mem_inter.mpr ⟨h2W, this.2.1⟩, hne⟩ · exact mem_union_left _ (mem_union_left _ (mem_filter.mpr ⟨hpW, hne, hU⟩)) have hcard := card_le_card hsub have hu1 := card_union_le (((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)) ∪ (W ∩ thinB v u₀).offDiag) ((U.filter (fun u => u < u₀)).biUnion (fun u => ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x)))) have hu2 := card_union_le ((W ×ˢ W).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)) (W ∩ thinB v u₀).offDiag have hb := card_biUnion_le (s := U.filter (fun u => u < u₀)) (t := fun u => ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))) have hper : ∀ u ∈ U.filter (fun u => u < u₀), (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x)) ∪ ((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))).card ≤ 2 * ((Wp.filter (fun y => y ∉ Au v u)).card + (Wp.filter (fun y => y ∉ (Au v u).image (Tu v u))).card) + 2 := by intro u _ have hbw := bad_in_window' hn hv hH0 u W Wp hWp have := card_union_le (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (x, Tu v u x))) (((Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))).image (fun x => (Tu v u x, x))) have h1 := card_image_le (s := (Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (f := fun x => (x, Tu v u x)) have h2 := card_image_le (s := (Au v u).filter (fun x => x ∈ W ∧ Tu v u x ∈ W ∧ ¬ (x + 1 ∈ Au v u ∧ Tu v u (x + 1) = Tu v u x + 1))) (f := fun x => (Tu v u x, x)) omega have hsum := sum_le_sum hper rw [sum_add_distrib, ← mul_sum, ← sum_defc, sum_const, smul_eq_mul] at hsum omega open Classical in /-- **The bad-window count without (H₀)** (Thm 11.9″(S3) with INVERSE Lemma 11.26): (H₀) may fail at one vertex `y₀`; each class then has at most one more bad chord, i.e. `+2K` changed pairs per window: the windows that are not good number at most `2 + 6|Z|/w + (18εn² + 18|B|² + 24εnK + 2Km)/(2·10⁻⁴w²)`, and the changed pairs of the anchored windows total at most `18εn² + 18|B|² + 24εnK + 2Km` (`m` = number of windows). -/ theorem bad_count' {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {y₀ : ZMod n} (hH0 : ∀ y : ZMod n, y ≠ y₀ → ¬ inF v y (y - 1)) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) {u₀ : ℝ} (hu₀ : 0 < u₀) {w : ℕ} (hw : 7 ≤ w) (hwn : w < n) : (((range (nWin n w)).filter (fun k => ¬ goodW v u₀ w k)).card : ℝ) ≤ 2 + 6 * (((univ : Finset (ZMod n)).filter (fun y => (Fu0 v u₀ y).card < 2 * w)).card : ℝ) / w + (18 * ε * n ^ 2 + 18 * ((thinB v u₀).card : ℝ) ^ 2 + 24 * ε * n * (U.filter (fun u => u < u₀)).card + 2 * (U.filter (fun u => u < u₀)).card * (nWin n w)) / (2 * (1 / 10000) * (w : ℝ) ^ 2) ∧ ∑ k ∈ (range (nWin n w)).filter (fun k => anchW v u₀ w k), ((chgW v (winK w k)).card : ℝ) ≤ 18 * ε * n ^ 2 + 18 * ((thinB v u₀).card : ℝ) ^ 2 + 24 * ε * n * (U.filter (fun u => u < u₀)).card + 2 * (U.filter (fun u => u < u₀)).card * (nWin n w) := by have hL := ccw_leftTurns hn hv have hw1 : 1 ≤ w := by omega have hw0 : (0 : ℝ) < w := by exact_mod_cast (show 0 < w by omega) obtain ⟨m, hm⟩ : ∃ m, m = nWin n w := ⟨_, rfl⟩ rw [← hm] obtain ⟨Z, hZ⟩ : ∃ Z : Finset (ZMod n), Z = (univ : Finset (ZMod n)).filter (fun y => (Fu0 v u₀ y).card < 2 * w) := ⟨_, rfl⟩ rw [← hZ] -- the anchored windows obtain ⟨An, hAn⟩ : ∃ A : Finset ℕ, A = (range m).filter (fun k => anchW v u₀ w k) := ⟨_, rfl⟩ have hsplit : (range m).filter (fun k => ¬ goodW v u₀ w k) ⊆ (range 2 ∪ (range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)) ∪ An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ)) := by intro k hk obtain ⟨hkm, hng⟩ := mem_filter.mp hk unfold goodW at hng by_cases h2 : 2 ≤ k · by_cases hanc : ∃ y ∈ (winK w (k - 2) : Finset (ZMod n)), 2 * w ≤ (Fu0 v u₀ y).card · have hkA : k ∈ An := by rw [hAn, mem_filter] exact ⟨hkm, h2, hanc⟩ refine mem_union_right _ (mem_filter.mpr ⟨hkA, ?_⟩) by_contra hc push Not at hc exact hng ⟨⟨h2, hanc⟩, hc⟩ · refine mem_union_left _ (mem_union_right _ (mem_filter.mpr ⟨hkm, h2, fun y hy => ?_⟩)) push Not at hanc rw [hZ, mem_filter] exact ⟨mem_univ _, hanc y hy⟩ · exact mem_union_left _ (mem_union_left _ (mem_range.mpr (by omega))) -- the Markov part have hchg : ∀ k ∈ An, (chgW v (winK w k)).card ≤ (((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card + (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card + 2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y + 2 * (U.filter (fun u => u < u₀)).card := by intro k hk rw [hAn, mem_filter] at hk obtain ⟨_, hanc⟩ := hk obtain ⟨h2, y, hy, hyc⟩ := hanc exact chgW_le' hn hL hH0 U (winK w k) (winKp w k) (fun x hx => winK_succ hx) (win_span hL hu₀ h2 hy hyc) have hM6 : ∀ y : ZMod n, ((range m).filter (fun k => y ∈ (winKp w k : Finset (ZMod n)))).card ≤ 6 := by intro y rw [hm] exact winKp_mult hw1 hwn y have hP := thm119_Psum v U hε0 hε1 hU1 hU2 m (fun k => winK w k) (fun k => winKp w k) (fun k _ => winK_sub w k) hM6 have hD := thm119_Dsum hL U hU2 u₀ m (fun k => winKp w k) hM6 have hMk : ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ 6 * ((thinB v u₀).card : ℝ) ^ 2 := by have h1 : ∀ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ) * (thinB v u₀).card := by intro k _ have a : (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card ≤ ((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card * (thinB v u₀).card := by rw [offDiag_card] exact (Nat.sub_le _ _).trans (Nat.mul_le_mul_left _ (card_le_card inter_subset_right)) exact_mod_cast a have h2 : ∑ k ∈ range m, ((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card ≤ 6 * (thinB v u₀).card := by rw [sum_card_inter_swap m (fun k => (winK w k : Finset (ZMod n))) (thinB v u₀)] calc ∑ y ∈ thinB v u₀, ((range m).filter (fun k => y ∈ (winK w k : Finset (ZMod n)))).card ≤ ∑ _y ∈ thinB v u₀, 6 := sum_le_sum (fun y _ => by rw [hm]; exact winK_mult hw1 hwn y) _ = 6 * (thinB v u₀).card := by rw [sum_const, smul_eq_mul, mul_comm] have h2R : (∑ k ∈ range m, (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ)) ≤ 6 * ((thinB v u₀).card : ℝ) := by exact_mod_cast h2 calc ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ ∑ k ∈ range m, (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ) * (thinB v u₀).card := sum_le_sum h1 _ = (∑ k ∈ range m, (((winK w k : Finset (ZMod n)) ∩ thinB v u₀).card : ℝ)) * (thinB v u₀).card := by rw [sum_mul] _ ≤ 6 * ((thinB v u₀).card : ℝ) * (thinB v u₀).card := mul_le_mul_of_nonneg_right h2R (Nat.cast_nonneg _) _ = 6 * ((thinB v u₀).card : ℝ) ^ 2 := by ring have hAsub : An ⊆ range m := by intro k hk rw [hAn, mem_filter] at hk exact hk.1 have hsumA : (∑ k ∈ An, ((chgW v (winK w k)).card : ℝ)) ≤ 18 * ε * n ^ 2 + 18 * ((thinB v u₀).card : ℝ) ^ 2 + 24 * ε * n * (U.filter (fun u => u < u₀)).card + 2 * (U.filter (fun u => u < u₀)).card * m := by have h1 : ∑ k ∈ An, ((chgW v (winK w k)).card : ℝ) ≤ ∑ k ∈ An, (((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) + ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) + (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) + 2 * ((U.filter (fun u => u < u₀)).card : ℝ)) := by apply sum_le_sum intro k hk have := hchg k hk exact_mod_cast this rw [sum_add_distrib, sum_add_distrib, sum_add_distrib] at h1 have h2d : ∑ _k ∈ An, 2 * ((U.filter (fun u => u < u₀)).card : ℝ) ≤ 2 * (U.filter (fun u => u < u₀)).card * m := by rw [sum_const, nsmul_eq_mul] have : (An.card : ℝ) ≤ m := by have := card_le_card hAsub rw [card_range] at this exact_mod_cast this nlinarith [Nat.cast_nonneg (α := ℝ) (U.filter (fun u => u < u₀)).card] have h2a : ∑ k ∈ An, ((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) ≤ ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := sum_le_sum_of_subset_of_nonneg hAsub (fun _ _ _ => by positivity) have h2b : ∑ k ∈ An, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) ≤ ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ∩ thinB v u₀).offDiag).card : ℝ) := sum_le_sum_of_subset_of_nonneg hAsub (fun _ _ _ => by positivity) have h2c : ∑ k ∈ An, (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) ≤ ∑ k ∈ range m, (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) := sum_le_sum_of_subset_of_nonneg hAsub (fun _ _ _ => by positivity) have hP' : ∑ k ∈ range m, ((((winK w k : Finset (ZMod n)) ×ˢ winK w k).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) ≤ 6 * (3 * ε * n ^ 2) := by have := hP simpa using this have hD' : ∑ k ∈ range m, (((2 * ∑ y ∈ (winKp w k : Finset (ZMod n)), defc v (U.filter (fun u => u < u₀)) y) : ℕ) : ℝ) ≤ 12 * (2 * ε * n * ((U.filter (fun u => u < u₀)).card : ℝ) + ((thinB v u₀).card : ℝ) ^ 2) := hD linarith [h1, h2a, h2b, h2c, hP', hMk, hD', h2d] have hmark := markov_card An (fun k => (chgW v (winK w k)).card) (c := 2 * (1 / 10000) * (w : ℝ) ^ 2) (by positivity) hsumA have hN1 := unanchored_le (n := n) hw1 hwn Z rw [← hm] at hN1 have hc1 := card_le_card hsplit have hc2 := card_union_le (range 2 ∪ (range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)) (An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ))) have hc3 := card_union_le (range 2) ((range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)) rw [card_range] at hc3 have hR : (((range m).filter (fun k => ¬ goodW v u₀ w k)).card : ℝ) ≤ 2 + (((range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)).card : ℝ) + ((An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ))).card : ℝ) := by have := hc1.trans (hc2.trans (Nat.add_le_add_right hc3 _)) exact_mod_cast this have hq1 : (((range m).filter (fun k => 2 ≤ k ∧ (winK w (k - 2) : Finset (ZMod n)) ⊆ Z)).card : ℝ) ≤ 6 * (Z.card : ℝ) / w := by rw [le_div_iff₀ hw0] linarith have hq2 : ((An.filter (fun k => 2 * (1 / 10000) * (w : ℝ) ^ 2 < ((chgW v (winK w k)).card : ℝ))).card : ℝ) ≤ (18 * ε * n ^ 2 + 18 * ((thinB v u₀).card : ℝ) ^ 2 + 24 * ε * n * (U.filter (fun u => u < u₀)).card + 2 * (U.filter (fun u => u < u₀)).card * m) / (2 * (1 / 10000) * (w : ℝ) ^ 2) := by rw [le_div_iff₀ (by positivity)] exact hmark refine ⟨by linarith, ?_⟩ rw [← hAn] exact hsumA end Erdos94ThmA /-! ### INVERSE Thm 11.24′ step 5: boundedly many circles with few outliers + near-full energy ⇒ one circle (via `cor96_gen`) -/ namespace Erdos94ThmA open Finset /-- Arithmetic of step 5: the `cor96_gen` bound with `M = (1 − θ)n`, `λ = θ/2` and a constant `G` contradicts `pe ≥ (2 − 8ε)n³` once `32ε ≤ θ`, `4(28K₀ + 20)τ ≤ θ` and `n` is large. -/ theorem step5_arith {N θ ε τ E A pe : ℝ} {k K₀ G : ℝ} (hN : 0 < N) (hθ0 : 0 < θ) (hθ1 : θ ≤ 1) (hε : 32 * ε ≤ θ) (hτ0 : 0 ≤ τ) (hτ : 4 * (28 * K₀ + 20) * τ ≤ θ) (hk0 : 0 ≤ k) (hk : k ≤ K₀) (hE0 : 0 ≤ E) (hE : E ≤ τ * N) (hA : A = (1 + 2 / θ) * K₀ ^ 4) (hG1 : 1 ≤ G) (hGA : 32 * A / θ ≤ G) (hNA : 4 * A * (52 + 4 * (2 * G + 1) ^ 2) / θ < N) (hpe : (2 - 8 * ε) * N ^ 3 ≤ pe) (h96 : pe ≤ (1 + θ / 2) * (2 * ((1 - θ) * N) * N ^ 2) + (1 + 1 / (θ / 2)) * k ^ 4 * (52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2) + (28 * k + 20) * E * N ^ 2) : False := by have hN2 : 0 < N ^ 2 := by positivity have hN3 : 0 < N ^ 3 := by positivity have hG0 : 0 < G := by linarith have hK0 : 0 ≤ K₀ := le_trans hk0 hk have hA0 : 0 ≤ A := by rw [hA]; positivity -- term 1 have hT1 : (1 + θ / 2) * (2 * ((1 - θ) * N) * N ^ 2) ≤ (2 - θ) * N ^ 3 := by have e : (1 + θ / 2) * (2 * ((1 - θ) * N) * N ^ 2) = (2 - θ - θ ^ 2) * N ^ 3 := by ring rw [e] have : 0 ≤ θ ^ 2 * N ^ 3 := by positivity nlinarith -- term 3 have hT3 : (28 * k + 20) * E * N ^ 2 ≤ θ / 4 * N ^ 3 := by have h1 : (28 * k + 20) * E ≤ (28 * K₀ + 20) * (τ * N) := mul_le_mul (by linarith) hE hE0 (by linarith) have h2 : (28 * K₀ + 20) * (τ * N) ≤ θ / 4 * N := by have : (28 * K₀ + 20) * τ ≤ θ / 4 := by linarith calc (28 * K₀ + 20) * (τ * N) = ((28 * K₀ + 20) * τ) * N := by ring _ ≤ θ / 4 * N := mul_le_mul_of_nonneg_right this hN.le calc (28 * k + 20) * E * N ^ 2 ≤ θ / 4 * N * N ^ 2 := mul_le_mul_of_nonneg_right (le_trans h1 h2) hN2.le _ = θ / 4 * N ^ 3 := by ring -- term 2 have hk4 : k ^ 4 ≤ K₀ ^ 4 := pow_le_pow_left₀ hk0 hk 4 have hcoef : (1 + 1 / (θ / 2)) * k ^ 4 ≤ A := by rw [hA] have e : 1 + 1 / (θ / 2) = 1 + 2 / θ := by field_simp rw [e] exact mul_le_mul_of_nonneg_left hk4 (by positivity) have hbr0 : 0 ≤ 52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2 := by positivity have hT2a : (1 + 1 / (θ / 2)) * k ^ 4 * (52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2) ≤ A * (52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2) := mul_le_mul_of_nonneg_right hcoef hbr0 have hGt : A * (8 * N ^ 3 / G) ≤ θ / 4 * N ^ 3 := by have h32 : 32 * A ≤ θ * G := by have := (div_le_iff₀ hθ0).mp hGA linarith rw [show A * (8 * N ^ 3 / G) = (8 * A) * N ^ 3 / G by ring, div_le_iff₀ hG0] have : 8 * A * N ^ 3 ≤ θ / 4 * G * N ^ 3 := by apply mul_le_mul_of_nonneg_right _ hN3.le linarith linarith have hNt : A * (52 * N ^ 2 + 4 * (2 * G + 1) ^ 2 * N ^ 2) < θ / 4 * N ^ 3 := by have h1 : 4 * A * (52 + 4 * (2 * G + 1) ^ 2) < θ * N := by have := (div_lt_iff₀ hθ0).mp hNA linarith have h2 : 4 * A * (52 + 4 * (2 * G + 1) ^ 2) * N ^ 2 < θ * N * N ^ 2 := mul_lt_mul_of_pos_right h1 hN2 have e1 : A * (52 * N ^ 2 + 4 * (2 * G + 1) ^ 2 * N ^ 2) = (4 * A * (52 + 4 * (2 * G + 1) ^ 2) * N ^ 2) / 4 := by ring have e2 : θ / 4 * N ^ 3 = (θ * N * N ^ 2) / 4 := by ring rw [e1, e2] linarith have hT2 : A * (52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2) < θ / 2 * N ^ 3 := by have e : A * (52 * N ^ 2 + 8 * N ^ 3 / G + 4 * (2 * G + 1) ^ 2 * N ^ 2) = A * (8 * N ^ 3 / G) + A * (52 * N ^ 2 + 4 * (2 * G + 1) ^ 2 * N ^ 2) := by ring rw [e] linarith have h8 : (2 - θ / 4) * N ^ 3 ≤ (2 - 8 * ε) * N ^ 3 := by apply mul_le_mul_of_nonneg_right _ hN3.le linarith linarith open Classical in /-- **INVERSE Theorem 11.24′, step 5** (GLIDE Cor. 9.6 in the general form `cor96_gen`). For `0 < θ ≤ 1` and a bound `K₀` on the number of circles there is `N₀` such that: if `Q ⊂ ℂ` is convex independent with `|Q| = n ≥ N₀`, `k ≤ K₀` circles `C(c_i, ρ_i)` (pairwise distinct centres, `ρ_i > 0`) miss at most `τn` points of `Q`, `4(28K₀ + 20)τ ≤ θ`, and `pe(Q°, Q°) ≥ (2 − 8ε)n³` (i.e. `S(Q) ≥ (1/2 − 2ε)n³`) with `32ε ≤ θ`, then ONE circle carries `≥ (1 − θ)n` points. -/ theorem step5_circle {θ : ℝ} (hθ0 : 0 < θ) (hθ1 : θ ≤ 1) (K₀ : ℕ) : ∃ N₀ : ℕ, ∀ Q : Finset ℂ, (∀ z ∈ Q, z ∉ convexHull ℝ ((Q : Set ℂ) \ {z})) → N₀ ≤ Q.card → ∀ {k : ℕ}, k ≤ K₀ → ∀ c : Fin k → ℂ, Function.Injective c → ∀ ρ : Fin k → ℝ, (∀ i, 0 < ρ i) → ∀ {ε τ : ℝ}, 32 * ε ≤ θ → 0 ≤ τ → 4 * (28 * (K₀ : ℝ) + 20) * τ ≤ θ → ((Q.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i)).card : ℝ) ≤ τ * Q.card → (2 - 8 * ε) * (Q.card : ℝ) ^ 3 ≤ (pe Q.offDiag Q.offDiag : ℝ) → ∃ i, (1 - θ) * (Q.card : ℝ) ≤ ((Q.filter (fun z => ‖z - c i‖ = ρ i)).card : ℝ) := by obtain ⟨A, hA⟩ : ∃ A : ℝ, A = (1 + 2 / θ) * (K₀ : ℝ) ^ 4 := ⟨_, rfl⟩ have hA0 : 0 ≤ A := by rw [hA]; positivity obtain ⟨G, hG⟩ : ∃ G : ℕ, G = ⌈32 * A / θ⌉₊ + 1 := ⟨_, rfl⟩ have hG1 : 1 ≤ G := by omega have hGA : 32 * A / θ ≤ (G : ℝ) := by rw [hG]; push_cast; linarith [Nat.le_ceil (32 * A / θ)] refine ⟨⌈4 * A * (52 + 4 * (2 * (G : ℝ) + 1) ^ 2) / θ⌉₊ + 1, ?_⟩ intro Q hQ hN k hk c hc ρ hρ ε τ hεθ hτ hτθ hE hpe by_contra hcon push_neg at hcon have hNA : 4 * A * (52 + 4 * (2 * (G : ℝ) + 1) ^ 2) / θ < (Q.card : ℝ) := by have h1 := Nat.le_ceil (4 * A * (52 + 4 * (2 * (G : ℝ) + 1) ^ 2) / θ) have h2 : ((⌈4 * A * (52 + 4 * (2 * (G : ℝ) + 1) ^ 2) / θ⌉₊ + 1 : ℕ) : ℝ) ≤ (Q.card : ℝ) := by exact_mod_cast hN push_cast at h2 linarith have hNpos : (0 : ℝ) < Q.card := by have : (0 : ℝ) ≤ 4 * A * (52 + 4 * (2 * (G : ℝ) + 1) ^ 2) / θ := by positivity linarith have hM0 : (0 : ℝ) ≤ (1 - θ) * Q.card := mul_nonneg (by linarith) hNpos.le have hM : ∀ i, ((Q.filter (fun z => ‖z - c i‖ = ρ i)).card : ℝ) ≤ (1 - θ) * Q.card := fun i => (hcon i).le have h96 := cor96_gen Q hQ c hc ρ hρ hM0 hM (l := θ / 2) (by linarith) G hG1 have hk' : (k : ℝ) ≤ K₀ := by exact_mod_cast hk exact step5_arith hNpos hθ0 hθ1 hεθ hτ hτθ (Nat.cast_nonneg k) hk' (Nat.cast_nonneg _) hE hA (by exact_mod_cast hG1) hGA hNA hpe h96 end Erdos94ThmA /-! ### LEAN-5: `hW` from the per-polygon circle count `WideCircles` (INVERSE Thm 11.24′: transport ℝ² → ℂ, (NF) energy, step 5) -/ namespace Erdos94ThmA open Finset open Classical in /-- **The LEAN-4/LEAN-5 interface: INVERSE Theorem 11.24′, steps 1–4, per polygon, in `ℂ`.** For a fat counterclockwise strictly convex polygon `v` (injective labels, the translation property (T), every unit direction `u` sees an extent `≥ ζ₀D` where `D` bounds all distances) with `≥ (1/2 − ε)n` near-full distances (`2f(u) = #chO v u ≥ 2(1 − ε)n`), all but `τn` vertices lie on at most `k₀` circles with positive radii and pairwise distinct centres. `k₀` depends on `ζ₀` only (the paper's `k = s₀ + 1`), and is fixed BEFORE `τ`; no (H₀) and no `S > R(n)` hypothesis. -/ def WideCircles : Prop := ∀ ζ₀ : ℝ, 0 < ζ₀ → ζ₀ ≤ 1 → ∃ k₀ : ℕ, ∀ τ : ℝ, 0 < τ → ∃ ε₀ : ℝ, 0 < ε₀ ∧ ∀ ε : ℝ, 0 < ε → ε ≤ ε₀ → ∃ n₀ : ℕ, ∀ n : ℕ, n₀ ≤ n → ∀ hn : NeZero n, ∀ v : ZMod n → ℂ, CCWPoly v → Function.Injective v → (∀ t : ℂ, t ≠ 0 → ((@Finset.univ (ZMod n) (@ZMod.fintype n hn)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) → ∀ D : ℝ, (∀ a b, ‖v a - v b‖ ≤ D) → (∀ u : ℂ, ‖u‖ = 1 → ∃ z z', ζ₀ * D ≤ ((starRingEnd ℂ) u * (v z - v z')).re) → ∀ U : Finset ℝ, (1 / 2 - ε) * n ≤ U.card → (∀ u ∈ U, 2 * (1 - ε) * n ≤ (@chO n hn v u).card) → ∃ C : Finset (ℂ × ℝ), (∀ c ∈ C, 0 < c.2) ∧ (∀ c ∈ C, ∀ c' ∈ C, c.1 = c'.1 → c = c') ∧ C.card ≤ k₀ ∧ (((@Finset.univ (ZMod n) (@ZMod.fintype n hn)).filter (fun x => ∀ c ∈ C, ‖v x - c.1‖ ≠ c.2)).card : ℝ) ≤ τ * n open Classical in /-- `plane_ccw_labelling` with the vertex set recorded: the labels enumerate exactly the `ℂ`-image of `P`. -/ theorem plane_ccw_labelling2 {n : ℕ} [NeZero n] (h3 : 3 ≤ n) (P : Finset (EuclideanSpace ℝ (Fin 2))) (hcard : P.card = n) (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) : ∃ v : ZMod n → ℂ, Function.Injective v ∧ CCWPoly v ∧ univ.image v = P.image Complex.orthonormalBasisOneI.repr.symm ∧ (∀ u, ((chO v u).card : ℝ) = 2 * (distanceMultiplicity P u : ℝ)) := by obtain ⟨Q, hQ⟩ : ∃ Q : Finset ℂ, Q = P.image Complex.orthonormalBasisOneI.repr.symm := ⟨_, rfl⟩ have hQc : Q.card = n := by rw [hQ, card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective, hcard] have hQi : ∀ z ∈ Q, z ∉ convexHull ℝ ((Q : Set ℂ) \ {z}) := by intro z hz rw [hQ] at hz ⊢ exact convexIndep_image_C hP hz obtain ⟨w, hwinj, hwmem, hwccw⟩ := exists_ccw_labelling Q hQi (by rw [hQc]; exact h3) subst hQc have himg : univ.image w = Q := by apply eq_of_subset_of_card_le · intro z hz rw [mem_image] at hz obtain ⟨k, _, rfl⟩ := hz exact hwmem k · rw [card_image_of_injective _ hwinj, card_univ, ZMod.card] have hsurj : ∀ z ∈ Q, ∃ k, w k = z := by intro z hz rw [← himg, mem_image] at hz obtain ⟨k, _, hk⟩ := hz exact ⟨k, hk⟩ have hch : ∀ u, (chO w u).card = (Q.offDiag.filter (fun x => dist x.1 x.2 = u)).card := by intro u apply card_bij (fun p _ => (w p.1, w p.2)) · intro p hp rw [mem_chO] at hp rw [mem_filter, mem_offDiag] exact ⟨⟨hwmem p.1, hwmem p.2, fun h => hp.1 (hwinj h)⟩, hp.2⟩ · intro p₁ _ p₂ _ h simp only [Prod.mk.injEq] at h exact Prod.ext (hwinj h.1) (hwinj h.2) · intro b hb rw [mem_filter, mem_offDiag] at hb obtain ⟨⟨hb1, hb2, hb12⟩, hbd⟩ := hb obtain ⟨k₁, hk₁⟩ := hsurj b.1 hb1 obtain ⟨k₂, hk₂⟩ := hsurj b.2 hb2 refine ⟨(k₁, k₂), ?_, ?_⟩ · rw [mem_chO] refine ⟨fun h => hb12 (by rw [← hk₁, ← hk₂]; exact congrArg w h), ?_⟩ show dist (w k₁) (w k₂) = u rw [hk₁, hk₂] exact hbd · show (w k₁, w k₂) = b rw [hk₁, hk₂] refine ⟨w, hwinj, hwccw, by rw [himg, hQ], fun u => ?_⟩ rw [hch u] have h1 := Erdos94Infra.mult_cast Q u have h2 : distanceMultiplicity Q u = distanceMultiplicity P u := by rw [hQ] exact mult_image_C P u rw [h2] at h1 linarith open Classical in /-- (T) for the labels: a nonzero translation maps at most two labelled vertices onto vertices. -/ theorem labels_T {n : ℕ} [NeZero n] {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) {v : ZMod n → ℂ} (hvi : Function.Injective v) (himg : univ.image v = P.image Complex.orthonormalBasisOneI.repr.symm) {t : ℂ} (ht : t ≠ 0) : ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2 := by have h2 := translate_card_le_two_C hP ht rw [← himg] at h2 refine le_trans (card_le_card_of_injOn v ?_ ?_) h2 · intro x hx obtain ⟨y, hy⟩ := (mem_filter.mp hx).2 refine mem_filter.mpr ⟨mem_image_of_mem v (mem_univ x), ?_⟩ rw [← hy] exact mem_image_of_mem v (mem_univ y) · intro x _ y _ h exact hvi h /-- All label distances are at most `diam P`. -/ theorem diam_C {P : Finset (EuclideanSpace ℝ (Fin 2))} {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (himg : univ.image v = P.image Complex.orthonormalBasisOneI.repr.symm) : ∀ a b, ‖v a - v b‖ ≤ Metric.diam (P : Set (EuclideanSpace ℝ (Fin 2))) := by intro a b have ha : v a ∈ P.image Complex.orthonormalBasisOneI.repr.symm := by rw [← himg]; exact mem_image_of_mem _ (mem_univ a) have hb : v b ∈ P.image Complex.orthonormalBasisOneI.repr.symm := by rw [← himg]; exact mem_image_of_mem _ (mem_univ b) obtain ⟨p, hp, hpa⟩ := mem_image.mp ha obtain ⟨q, hq, hqb⟩ := mem_image.mp hb rw [← hpa, ← hqb, ← dist_eq_norm, Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] exact Metric.dist_le_diam_of_mem P.finite_toSet.isBounded hp hq /-- `Fat` is monotone in the width ratio. -/ theorem fat_mono {ζ ζ' : ℝ} (hle : ζ' ≤ ζ) {P : Finset (EuclideanSpace ℝ (Fin 2))} (hF : Fat ζ P) : Fat ζ' P := by intro t obtain ⟨p, hp, q, hq, h⟩ := hF t exact ⟨p, hp, q, hq, le_trans (mul_le_mul_of_nonneg_right hle Metric.diam_nonneg) h⟩ /-- Fatness in the `ℂ` form used by `WideCircles`: for every unit `u` some pair of labels has `Re(ū(v_z − v_{z'})) ≥ ζ₀·diam P` (the direction `(cos t, sin t)` with `t = arg u`). -/ theorem fat_C {ζ₀ : ℝ} {P : Finset (EuclideanSpace ℝ (Fin 2))} (hF : Fat ζ₀ P) {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (himg : univ.image v = P.image Complex.orthonormalBasisOneI.repr.symm) : ∀ u : ℂ, ‖u‖ = 1 → ∃ z z', ζ₀ * Metric.diam (P : Set (EuclideanSpace ℝ (Fin 2))) ≤ ((starRingEnd ℂ) u * (v z - v z')).re := by intro u hu have hu0 : u ≠ 0 := by intro h rw [h, norm_zero] at hu exact zero_ne_one hu obtain ⟨p, hp, q, hq, hpq⟩ := hF (Complex.arg u) have hp' : Complex.orthonormalBasisOneI.repr.symm p ∈ univ.image v := by rw [himg]; exact mem_image_of_mem _ hp have hq' : Complex.orthonormalBasisOneI.repr.symm q ∈ univ.image v := by rw [himg]; exact mem_image_of_mem _ hq obtain ⟨z, _, hz⟩ := mem_image.mp hp' obtain ⟨z', _, hz'⟩ := mem_image.mp hq' refine ⟨z, z', ?_⟩ rw [hz, hz', Complex.orthonormalBasisOneI_repr_symm_apply, Complex.orthonormalBasisOneI_repr_symm_apply] have hc : Real.cos (Complex.arg u) = u.re := by rw [Complex.cos_arg hu0, hu, div_one] have hs : Real.sin (Complex.arg u) = u.im := by rw [Complex.sin_arg, hu, div_one] rw [hc, hs] at hpq have e : ((starRingEnd ℂ) u * ((p 0 : ℂ) + (p 1 : ℂ) * Complex.I - ((q 0 : ℂ) + (q 1 : ℂ) * Complex.I))).re = (p 0 - q 0) * u.re + (p 1 - q 1) * u.im := by simp only [Complex.mul_re, Complex.conj_re, Complex.conj_im, Complex.sub_re, Complex.add_re, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im, Complex.sub_im, Complex.add_im, Complex.mul_im] ring rw [e] exact hpq /-- **(NF_ε) ⇒ `4S(P) ≥ (2 − 8ε)n³`** (`S ≥ |U|·((1 − ε)n)²`, `|U| ≥ (1/2 − ε)n`, `0 ≤ ε ≤ 1/2`). -/ theorem nf_S_lower {P : Finset (EuclideanSpace ℝ (Fin 2))} {ε : ℝ} (hε0 : 0 ≤ ε) (hε : ε ≤ 1 / 2) (hpos : 0 < P.card) (hNF : NFconcl ε P) : (2 - 8 * ε) * (P.card : ℝ) ^ 3 ≤ 4 * ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 := by obtain ⟨U, hU, hf⟩ := hNF have hN : (0 : ℝ) < P.card := by exact_mod_cast hpos have hsub : U ⊆ distanceSet P := by intro u hu have h1 := hf u hu have h2 : (0 : ℝ) < distanceMultiplicity P u := by have : (0 : ℝ) < (1 - ε) * P.card := mul_pos (by linarith) hN linarith have h3 : 0 < distanceMultiplicity P u := by exact_mod_cast h2 unfold distanceMultiplicity at h3 have h4 : (P.offDiag.filter (fun pair => dist pair.1 pair.2 = u)).Nonempty := by rw [← card_pos] by_contra h5 push_neg at h5 have h6 : (P.offDiag.filter (fun pair => dist pair.1 pair.2 = u)).card = 0 := by omega rw [h6] at h3 simp at h3 obtain ⟨x, hx⟩ := h4 rw [mem_filter] at hx unfold distanceSet exact mem_image.mpr ⟨x, hx.1, hx.2⟩ have hS1 : ∑ u ∈ U, (distanceMultiplicity P u : ℝ) ^ 2 ≤ ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 := sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => sq_nonneg _) have hS2 : ∑ _u ∈ U, ((1 - ε) * (P.card : ℝ)) ^ 2 ≤ ∑ u ∈ U, (distanceMultiplicity P u : ℝ) ^ 2 := sum_le_sum (fun u hu => pow_le_pow_left₀ (mul_nonneg (by linarith) hN.le) (hf u hu) 2) rw [sum_const, nsmul_eq_mul] at hS2 have h1 : 4 * ((1 / 2 - ε) * P.card * ((1 - ε) * P.card) ^ 2) ≤ 4 * ((U.card : ℝ) * ((1 - ε) * P.card) ^ 2) := by have := mul_le_mul_of_nonneg_right hU (sq_nonneg ((1 - ε) * (P.card : ℝ))) linarith have h2 : (2 - 8 * ε) * (P.card : ℝ) ^ 3 ≤ 4 * ((1 / 2 - ε) * P.card * ((1 - ε) * P.card) ^ 2) := by have e : 4 * ((1 / 2 - ε) * P.card * ((1 - ε) * P.card) ^ 2) = (2 - 8 * ε + ε ^ 2 * (10 - 4 * ε)) * (P.card : ℝ) ^ 3 := by ring rw [e] apply mul_le_mul_of_nonneg_right _ (by positivity) have : 0 ≤ ε ^ 2 * (10 - 4 * ε) := mul_nonneg (sq_nonneg ε) (by linarith) linarith linarith open Classical in /-- **INVERSE Theorem 11.24′ ⇒ `hW`** (the wide case of the master outline, in the form `main_of_W_XE_needle` consumes): from the per-polygon circle count `WideCircles` (steps 1–4, LEAN-4), step 5 (`step5_circle`, i.e. GLIDE Cor. 9.6 via `cor96_gen`) with `θ = 10⁻⁴`, `τ = θ/(4(28k₀ + 20))`, `ε ≤ min(ε₀(ζ₀, τ), θ/32)`, and the transport `ℝ² → ℂ`. The hypothesis `S(P) > R(n)` of `WideThm` is not used (Thm 11.24′ is unconditional). -/ theorem wide_thm_of_circles (hWC : WideCircles) : ∀ ζ₀ > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm ζ₀ (1 / 10000) ε n₃ := by intro ζ₀ hζ₀ obtain ⟨k₀, hk₀⟩ := hWC (min ζ₀ 1) (lt_min hζ₀ one_pos) (min_le_right _ _) obtain ⟨τ, hτ⟩ : ∃ τ : ℝ, τ = 1 / 10000 / (4 * (28 * (k₀ : ℝ) + 20)) := ⟨_, rfl⟩ have hτd : (0 : ℝ) < 4 * (28 * (k₀ : ℝ) + 20) := by positivity have hτ0 : 0 < τ := by rw [hτ]; positivity have hτθ : 4 * (28 * (k₀ : ℝ) + 20) * τ ≤ 1 / 10000 := by rw [hτ, mul_div_cancel₀ _ hτd.ne'] obtain ⟨ε₀, hε₀, hεk⟩ := hk₀ τ hτ0 obtain ⟨N₀, hN₀⟩ := step5_circle (θ := 1 / 10000) (by norm_num) (by norm_num) k₀ refine ⟨min ε₀ (1 / 320000), lt_min hε₀ (by norm_num), ?_⟩ intro ε hε0 hεle obtain ⟨n₀, hn₀⟩ := hεk ε hε0 (le_trans hεle (min_le_left _ _)) have hε32 : 32 * ε ≤ 1 / 10000 := by have := le_trans hεle (min_le_right ε₀ (1 / 320000)) linarith refine ⟨max (max n₀ N₀) 3, ?_⟩ intro n hn P hcard hP _hSR hFat hNF have h3 : 3 ≤ n := le_trans (le_max_right _ _) hn have hn0 : n₀ ≤ n := le_trans (le_trans (le_max_left _ _) (le_max_left _ _)) hn have hN0 : N₀ ≤ n := le_trans (le_trans (le_max_right _ _) (le_max_left _ _)) hn haveI hnz : NeZero n := ⟨by omega⟩ obtain ⟨v, hvi, hccw, himg, hch⟩ := plane_ccw_labelling2 h3 P hcard hP have hS := nf_S_lower hε0.le (by linarith) (by omega) hNF obtain ⟨U, hU, hUf⟩ := hNF have hUch : ∀ u ∈ U, 2 * (1 - ε) * (n : ℝ) ≤ ((chO v u).card : ℝ) := by intro u hu rw [hch u, ← hcard] linarith [hUf u hu] have hU' : (1 / 2 - ε) * (n : ℝ) ≤ U.card := by rw [← hcard]; exact hU obtain ⟨C, hCpos, hCc, hCk, hCoff⟩ := hn₀ n hn0 hnz v hccw hvi (fun t ht => labels_T hP hvi himg ht) (Metric.diam (P : Set (EuclideanSpace ℝ (Fin 2)))) (diam_C himg) (fat_C (fat_mono (min_le_left _ _) hFat) himg) U hU' hUch -- the vertex set in `ℂ` obtain ⟨Q, hQ⟩ : ∃ Q : Finset ℂ, Q = P.image Complex.orthonormalBasisOneI.repr.symm := ⟨_, rfl⟩ have hQc : Q.card = n := by rw [hQ, card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective, hcard] have hQi : ∀ z ∈ Q, z ∉ convexHull ℝ ((Q : Set ℂ) \ {z}) := by intro z hz rw [hQ] at hz ⊢ exact convexIndep_image_C hP hz have hpe : (2 - 8 * ε) * (Q.card : ℝ) ^ 3 ≤ (pe Q.offDiag Q.offDiag : ℝ) := by rw [hQc, ← hcard] rw [Erdos94Infra.sum_sq_mult_eq, ← pairEnergy_image_C] at hS have e : (Erdos94Infra.pairEnergy (P.image Complex.orthonormalBasisOneI.repr.symm) : ℝ) = (pe (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag : ℝ) := rfl rw [e, ← hQ] at hS linarith -- the circle family as a `Fin` family obtain ⟨c, hc⟩ : ∃ c : Fin C.card → ℂ, c = fun i => ((C.equivFin.symm i : C) : ℂ × ℝ).1 := ⟨_, rfl⟩ obtain ⟨ρ, hρ⟩ : ∃ ρ : Fin C.card → ℝ, ρ = fun i => ((C.equivFin.symm i : C) : ℂ × ℝ).2 := ⟨_, rfl⟩ have hcinj : Function.Injective c := by intro i j hij rw [hc] at hij have h1 := hCc _ (C.equivFin.symm i).2 _ (C.equivFin.symm j).2 hij exact C.equivFin.symm.injective (Subtype.ext h1) have hρpos : ∀ i, 0 < ρ i := by intro i rw [hρ] exact hCpos _ (C.equivFin.symm i).2 have hcρ : ∀ x : ℂ × ℝ, ∀ hx : x ∈ C, c (C.equivFin ⟨x, hx⟩) = x.1 ∧ ρ (C.equivFin ⟨x, hx⟩) = x.2 := by intro x hx rw [hc, hρ] simp have hE : ((Q.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i)).card : ℝ) ≤ τ * Q.card := by rw [hQc] refine le_trans ?_ hCoff have hsub : Q.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i) ⊆ ((univ : Finset (ZMod n)).filter (fun x => ∀ c ∈ C, ‖v x - c.1‖ ≠ c.2)).image v := by intro z hz rw [mem_filter] at hz obtain ⟨hzQ, hzc⟩ := hz have hzv : z ∈ univ.image v := by rw [himg, ← hQ]; exact hzQ obtain ⟨x, _, hx⟩ := mem_image.mp hzv refine mem_image.mpr ⟨x, mem_filter.mpr ⟨mem_univ x, fun c' hc' => ?_⟩, hx⟩ have h1 := hzc (C.equivFin ⟨c', hc'⟩) rw [(hcρ c' hc').1, (hcρ c' hc').2, ← hx] at h1 exact h1 exact_mod_cast le_trans (card_le_card hsub) card_image_le obtain ⟨i, hi⟩ := hN₀ Q hQi (by rw [hQc]; exact hN0) (le_trans (le_refl _) hCk) c hcinj ρ hρpos hε32 hτ0.le hτθ hE hpe -- back to the plane refine ⟨Complex.orthonormalBasisOneI.repr (c i), ρ i, hρpos i, ?_⟩ have hsplit := card_filter_add_card_filter_not (s := Q) (fun z => ‖z - c i‖ = ρ i) have hle : (P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr (c i)) ≠ ρ i)).card ≤ (Q.filter (fun z => ¬ ‖z - c i‖ = ρ i)).card := by refine card_le_card_of_injOn Complex.orthonormalBasisOneI.repr.symm ?_ ?_ · intro p hp have hp' := mem_filter.mp hp refine mem_filter.mpr ⟨by rw [hQ]; exact mem_image_of_mem _ hp'.1, ?_⟩ have e : ‖Complex.orthonormalBasisOneI.repr.symm p - c i‖ = dist p (Complex.orthonormalBasisOneI.repr (c i)) := by rw [← dist_eq_norm] conv_lhs => rw [← Complex.orthonormalBasisOneI.repr.symm_apply_apply (c i)] rw [Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] rw [e] exact hp'.2 · intro p _ q _ h exact Complex.orthonormalBasisOneI.repr.symm.injective h have hle' : ((P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr (c i)) ≠ ρ i)).card : ℝ) ≤ ((Q.filter (fun z => ¬ ‖z - c i‖ = ρ i)).card : ℝ) := by exact_mod_cast hle have hsplit' : ((Q.filter (fun z => ‖z - c i‖ = ρ i)).card : ℝ) + ((Q.filter (fun z => ¬ ‖z - c i‖ = ρ i)).card : ℝ) = Q.card := by exact_mod_cast hsplit rw [hcard] rw [hQc] at hsplit' hi linarith /-- **The master outline with hL1 AND hW discharged** (modulo LEAN-4's `WideCircles`): `S(P) ≤ R(n)` for all large `n` from `WideCircles` (INVERSE Thm 11.24′ steps 1–4, audited), (XE^rich_0) and the needle case. -/ theorem main_of_circles_XE_needle (hWC : WideCircles) (hXE : XErich) (hNeedle : ∃ ζ₀ > 0, ∃ ε₁ > 0, ∀ ε, 0 < ε → ε ≤ ε₁ → ∃ n₂, NeedleThm ζ₀ ε n₂) : ∃ N : ℕ, ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := main_of_W_XE_needle (wide_thm_of_circles hWC) hXE hNeedle end Erdos94ThmA /-! ### LEAN-5: INVERSE Thm 11.24′ UNWEAKENED (no `S > R(n)`, any exception fraction θ) from `WideCircles` -/ namespace Erdos94ThmA open Finset /-- **INVERSE Theorem 11.24′ as stated** (no counterexample hypothesis; any exception fraction `θ`): a fat convex `n`-gon (`n ≥ n₃`) with near-full classes is near-concyclic. The needle proof (INVERSE Thm 11.41′) applies it to a fat core that need not be a counterexample, with `θ_K = 5·10⁻⁵` (AUDIT3 §125–§126, §129 item 3). -/ def WideThm0 (ζ₀ θ ε : ℝ) (n₃ : ℕ) : Prop := ∀ n ≥ n₃, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → Fat ζ₀ P → NFconcl ε P → NearConcyclic θ P /-- `NearConcyclic` is monotone in the exception fraction. -/ theorem nearConcyclic_mono {θ θ' : ℝ} (h : θ ≤ θ') {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : NearConcyclic θ P) : NearConcyclic θ' P := by obtain ⟨O, ρ, hρ, hc⟩ := hP exact ⟨O, ρ, hρ, le_trans hc (mul_le_mul_of_nonneg_right h (Nat.cast_nonneg _))⟩ /-- The unweakened theorem gives the weakened `WideThm` used by `main_of_links` (drop the hypothesis `S > R(n)`). -/ theorem wideThm_of_wide0 {ζ₀ θ ε : ℝ} {n₃ : ℕ} (h : WideThm0 ζ₀ θ ε n₃) : WideThm ζ₀ θ ε n₃ := fun n hn P hc hP _ hF hNF => h n hn P hc hP hF hNF open Classical in /-- **INVERSE Theorem 11.24′ (unweakened) from `WideCircles`**: for every `ζ₀ > 0` and `θ > 0` there is `ε₀ > 0` such that for `ε ≤ ε₀` and large `n`, `WideThm0 ζ₀ θ ε n₃`. Same proof as `wide_thm_of_circles` with `θ` in place of `10⁻⁴` (`τ = θ′/(4(28k₀ + 20))`, `ε ≤ min(ε₀(ζ₀, τ), θ′/32)`, `θ′ = min(θ, 1)`). -/ theorem wide0_of_circles (hWC : WideCircles) : ∀ ζ₀ > 0, ∀ θ' > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm0 ζ₀ θ' ε n₃ := by intro ζ₀ hζ₀ θ' hθ' obtain ⟨θ, hθ⟩ : ∃ θ : ℝ, θ = min θ' 1 := ⟨_, rfl⟩ have hθ0 : 0 < θ := by rw [hθ]; exact lt_min hθ' one_pos have hθ1 : θ ≤ 1 := by rw [hθ]; exact min_le_right _ _ have hθθ : θ ≤ θ' := by rw [hθ]; exact min_le_left _ _ obtain ⟨k₀, hk₀⟩ := hWC (min ζ₀ 1) (lt_min hζ₀ one_pos) (min_le_right _ _) obtain ⟨τ, hτ⟩ : ∃ τ : ℝ, τ = θ / (4 * (28 * (k₀ : ℝ) + 20)) := ⟨_, rfl⟩ have hτd : (0 : ℝ) < 4 * (28 * (k₀ : ℝ) + 20) := by positivity have hτ0 : 0 < τ := by rw [hτ]; exact div_pos hθ0 hτd have hτθ : 4 * (28 * (k₀ : ℝ) + 20) * τ ≤ θ := by rw [hτ, mul_div_cancel₀ _ hτd.ne'] obtain ⟨ε₀, hε₀, hεk⟩ := hk₀ τ hτ0 obtain ⟨N₀, hN₀⟩ := step5_circle (θ := θ) hθ0 hθ1 k₀ refine ⟨min ε₀ (θ / 32), lt_min hε₀ (by positivity), ?_⟩ intro ε hε0 hεle obtain ⟨n₀, hn₀⟩ := hεk ε hε0 (le_trans hεle (min_le_left _ _)) have hε32 : 32 * ε ≤ θ := by have := le_trans hεle (min_le_right ε₀ (θ / 32)) linarith refine ⟨max (max n₀ N₀) 3, ?_⟩ intro n hn P hcard hP hFat hNF have h3 : 3 ≤ n := le_trans (le_max_right _ _) hn have hn0 : n₀ ≤ n := le_trans (le_trans (le_max_left _ _) (le_max_left _ _)) hn have hN0 : N₀ ≤ n := le_trans (le_trans (le_max_right _ _) (le_max_left _ _)) hn haveI hnz : NeZero n := ⟨by omega⟩ obtain ⟨v, hvi, hccw, himg, hch⟩ := plane_ccw_labelling2 h3 P hcard hP have hS := nf_S_lower hε0.le (by linarith) (by omega) hNF obtain ⟨U, hU, hUf⟩ := hNF have hUch : ∀ u ∈ U, 2 * (1 - ε) * (n : ℝ) ≤ ((chO v u).card : ℝ) := by intro u hu rw [hch u, ← hcard] linarith [hUf u hu] have hU' : (1 / 2 - ε) * (n : ℝ) ≤ U.card := by rw [← hcard]; exact hU obtain ⟨C, hCpos, hCc, hCk, hCoff⟩ := hn₀ n hn0 hnz v hccw hvi (fun t ht => labels_T hP hvi himg ht) (Metric.diam (P : Set (EuclideanSpace ℝ (Fin 2)))) (diam_C himg) (fat_C (fat_mono (min_le_left _ _) hFat) himg) U hU' hUch -- the vertex set in `ℂ` obtain ⟨Q, hQ⟩ : ∃ Q : Finset ℂ, Q = P.image Complex.orthonormalBasisOneI.repr.symm := ⟨_, rfl⟩ have hQc : Q.card = n := by rw [hQ, card_image_of_injective _ Complex.orthonormalBasisOneI.repr.symm.injective, hcard] have hQi : ∀ z ∈ Q, z ∉ convexHull ℝ ((Q : Set ℂ) \ {z}) := by intro z hz rw [hQ] at hz ⊢ exact convexIndep_image_C hP hz have hpe : (2 - 8 * ε) * (Q.card : ℝ) ^ 3 ≤ (pe Q.offDiag Q.offDiag : ℝ) := by rw [hQc, ← hcard] rw [Erdos94Infra.sum_sq_mult_eq, ← pairEnergy_image_C] at hS have e : (Erdos94Infra.pairEnergy (P.image Complex.orthonormalBasisOneI.repr.symm) : ℝ) = (pe (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag (P.image Complex.orthonormalBasisOneI.repr.symm).offDiag : ℝ) := rfl rw [e, ← hQ] at hS linarith -- the circle family as a `Fin` family obtain ⟨c, hc⟩ : ∃ c : Fin C.card → ℂ, c = fun i => ((C.equivFin.symm i : C) : ℂ × ℝ).1 := ⟨_, rfl⟩ obtain ⟨ρ, hρ⟩ : ∃ ρ : Fin C.card → ℝ, ρ = fun i => ((C.equivFin.symm i : C) : ℂ × ℝ).2 := ⟨_, rfl⟩ have hcinj : Function.Injective c := by intro i j hij rw [hc] at hij have h1 := hCc _ (C.equivFin.symm i).2 _ (C.equivFin.symm j).2 hij exact C.equivFin.symm.injective (Subtype.ext h1) have hρpos : ∀ i, 0 < ρ i := by intro i rw [hρ] exact hCpos _ (C.equivFin.symm i).2 have hcρ : ∀ x : ℂ × ℝ, ∀ hx : x ∈ C, c (C.equivFin ⟨x, hx⟩) = x.1 ∧ ρ (C.equivFin ⟨x, hx⟩) = x.2 := by intro x hx rw [hc, hρ] simp have hE : ((Q.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i)).card : ℝ) ≤ τ * Q.card := by rw [hQc] refine le_trans ?_ hCoff have hsub : Q.filter (fun z => ∀ i, ‖z - c i‖ ≠ ρ i) ⊆ ((univ : Finset (ZMod n)).filter (fun x => ∀ c ∈ C, ‖v x - c.1‖ ≠ c.2)).image v := by intro z hz rw [mem_filter] at hz obtain ⟨hzQ, hzc⟩ := hz have hzv : z ∈ univ.image v := by rw [himg, ← hQ]; exact hzQ obtain ⟨x, _, hx⟩ := mem_image.mp hzv refine mem_image.mpr ⟨x, mem_filter.mpr ⟨mem_univ x, fun c' hc' => ?_⟩, hx⟩ have h1 := hzc (C.equivFin ⟨c', hc'⟩) rw [(hcρ c' hc').1, (hcρ c' hc').2, ← hx] at h1 exact h1 exact_mod_cast le_trans (card_le_card hsub) card_image_le obtain ⟨i, hi⟩ := hN₀ Q hQi (by rw [hQc]; exact hN0) (le_trans (le_refl _) hCk) c hcinj ρ hρpos hε32 hτ0.le hτθ hE hpe -- back to the plane refine nearConcyclic_mono hθθ ⟨Complex.orthonormalBasisOneI.repr (c i), ρ i, hρpos i, ?_⟩ have hsplit := card_filter_add_card_filter_not (s := Q) (fun z => ‖z - c i‖ = ρ i) have hle : (P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr (c i)) ≠ ρ i)).card ≤ (Q.filter (fun z => ¬ ‖z - c i‖ = ρ i)).card := by refine card_le_card_of_injOn Complex.orthonormalBasisOneI.repr.symm ?_ ?_ · intro p hp have hp' := mem_filter.mp hp refine mem_filter.mpr ⟨by rw [hQ]; exact mem_image_of_mem _ hp'.1, ?_⟩ have e : ‖Complex.orthonormalBasisOneI.repr.symm p - c i‖ = dist p (Complex.orthonormalBasisOneI.repr (c i)) := by rw [← dist_eq_norm] conv_lhs => rw [← Complex.orthonormalBasisOneI.repr.symm_apply_apply (c i)] rw [Complex.orthonormalBasisOneI.repr.symm.isometry.dist_eq] rw [e] exact hp'.2 · intro p _ q _ h exact Complex.orthonormalBasisOneI.repr.symm.injective h have hle' : ((P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr (c i)) ≠ ρ i)).card : ℝ) ≤ ((Q.filter (fun z => ¬ ‖z - c i‖ = ρ i)).card : ℝ) := by exact_mod_cast hle have hsplit' : ((Q.filter (fun z => ‖z - c i‖ = ρ i)).card : ℝ) + ((Q.filter (fun z => ¬ ‖z - c i‖ = ρ i)).card : ℝ) = Q.card := by exact_mod_cast hsplit rw [hcard] rw [hQc] at hsplit' hi linarith /-- `hW` of `main_of_W_XE_needle` as the `θ = 10⁻⁴` specialisation of the unweakened theorem. -/ theorem wide_thm_of_wide0 (hWC : WideCircles) : ∀ ζ₀ > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm ζ₀ (1 / 10000) ε n₃ := by intro ζ₀ hζ₀ obtain ⟨ε₀, hε₀, h⟩ := wide0_of_circles hWC ζ₀ hζ₀ (1 / 10000) (by norm_num) refine ⟨ε₀, hε₀, fun ε hε hεle => ?_⟩ obtain ⟨n₃, hn₃⟩ := h ε hε hεle exact ⟨n₃, wideThm_of_wide0 hn₃⟩ end Erdos94ThmA /-! ### LEAN-5 Q1: INVERSE Theorem 11.36 (1D-ization): `S ≤ n(n − 1)(2n − 1)/6 + 2Σ_u f(u)E_u` for ANY order -/ namespace Erdos94ThmA open Finset open Classical in /-- `a_u(x) = #{y ∈ P : x ≺ y, |xy| = u}` (INVERSE Thm 11.36); the total order `≺` on `P` is given by a ranking `rk`, injective on `P`: `x ≺ y ⇔ rk x < rk y`. -/ noncomputable def lat {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (u : ℝ) (x : X) : ℕ := (P.filter (fun y => rk x < rk y ∧ dist x y = u)).card /-- `E_u = Σ_x (a_u(x) − 1)⁺` (truncated subtraction in `ℕ`). -/ noncomputable def latE {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (u : ℝ) : ℕ := ∑ x ∈ P, (lat P rk u x - 1) open Classical in /-- `r_x = #{y ∈ P : x ≺ y}`. -/ noncomputable def latR {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (x : X) : ℕ := (P.filter (fun y => rk x < rk y)).card open Classical in /-- `f(u) = Σ_x a_u(x)`: every unordered `u`-pair is counted once, at its `≺`-smaller end. -/ theorem mult_eq_sum_lat {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (hrk : Set.InjOn rk P) (u : ℝ) : distanceMultiplicity P u = ∑ x ∈ P, lat P rk u x := by obtain ⟨F, hF⟩ : ∃ F, F = P.offDiag.filter (fun p : X × X => dist p.1 p.2 = u) := ⟨_, rfl⟩ have h1 : F.filter (fun p => rk p.1 < rk p.2) = (P ×ˢ P).filter (fun p => rk p.1 < rk p.2 ∧ dist p.1 p.2 = u) := by ext p rw [hF, mem_filter, mem_filter, mem_filter, mem_offDiag, mem_product] constructor · rintro ⟨⟨⟨h1, h2, _⟩, h4⟩, h5⟩ exact ⟨⟨h1, h2⟩, h5, h4⟩ · rintro ⟨⟨h1, h2⟩, h5, h4⟩ exact ⟨⟨⟨h1, h2, fun h => by rw [h] at h5; exact lt_irrefl _ h5⟩, h4⟩, h5⟩ have h2 : ((P ×ˢ P).filter (fun p => rk p.1 < rk p.2 ∧ dist p.1 p.2 = u)).card = ∑ x ∈ P, lat P rk u x := by rw [card_filter, sum_product] refine sum_congr rfl (fun x _ => ?_) unfold lat rw [card_filter] have h3 : (F.filter (fun p => ¬ rk p.1 < rk p.2)).card = (F.filter (fun p => rk p.1 < rk p.2)).card := by apply card_bij (fun p _ => (p.2, p.1)) · intro p hp rw [hF, mem_filter, mem_filter, mem_offDiag] at hp obtain ⟨⟨⟨ha, hb, hab⟩, hd⟩, hlt⟩ := hp rw [hF, mem_filter, mem_filter, mem_offDiag] refine ⟨⟨⟨hb, ha, fun h => hab h.symm⟩, by rw [dist_comm]; exact hd⟩, ?_⟩ show rk p.2 < rk p.1 rcases lt_trichotomy (rk p.1) (rk p.2) with h | h | h · exact absurd h hlt · exact absurd (hrk ha hb h) hab · exact h · intro p₁ _ p₂ _ h simp only [Prod.mk.injEq] at h exact Prod.ext h.2 h.1 · intro q hq rw [hF, mem_filter, mem_filter, mem_offDiag] at hq obtain ⟨⟨⟨ha, hb, hab⟩, hd⟩, hlt⟩ := hq refine ⟨(q.2, q.1), ?_, rfl⟩ rw [hF, mem_filter, mem_filter, mem_offDiag] exact ⟨⟨⟨hb, ha, fun h => hab h.symm⟩, by rw [dist_comm]; exact hd⟩, not_lt.mpr hlt.le⟩ have h4 := card_filter_add_card_filter_not (s := F) (fun p : X × X => rk p.1 < rk p.2) unfold distanceMultiplicity rw [← hF, ← h4, h3, h1, h2] omega open Classical in /-- `Σ_{u ∈ W} a_u(x) ≤ r_x` for any finite set `W` of classes (distinct classes count disjoint sets of later points). -/ theorem sum_lat_le {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (W : Finset ℝ) (x : X) : ∑ u ∈ W, lat P rk u x ≤ latR P rk x := by unfold lat latR rw [← card_biUnion] · apply card_le_card intro y hy rw [mem_biUnion] at hy obtain ⟨u, _, hy⟩ := hy rw [mem_filter] at hy ⊢ exact ⟨hy.1, hy.2.1⟩ · intro u _ u' _ huu' rw [Function.onFun, disjoint_filter] intro y _ h1 h2 exact huu' (h1.2.symm.trans h2.2) /-- `ab ≤ min(a, b) + (a − 1)⁺b + a(b − 1)⁺` for natural numbers. -/ theorem mul_le_min_add (a b : ℕ) : a * b ≤ min a b + (a - 1) * b + a * (b - 1) := by rcases a with _ | a · simp rcases b with _ | b · simp have h1 : 1 ≤ min (a + 1) (b + 1) := le_min (by omega) (by omega) simp only [Nat.add_sub_cancel] nlinarith /-- `Σ_{a, b < n} min(a, b)`, closed form: `6T + 3n² = 2n³ + n`, i.e. `T = n(n − 1)(2n − 1)/6`. -/ theorem sum_min_range (n : ℕ) : 6 * (∑ a ∈ range n, ∑ b ∈ range n, min a b) + 3 * n ^ 2 = 2 * n ^ 3 + n := by induction n with | zero => simp | succ n ih => have e1 : ∑ a ∈ range (n + 1), ∑ b ∈ range (n + 1), min a b = ∑ a ∈ range n, ∑ b ∈ range n, min a b + 2 * ∑ a ∈ range n, a + n := by rw [sum_range_succ] simp only [sum_range_succ] rw [sum_add_distrib] have ha : ∑ a ∈ range n, min a n = ∑ a ∈ range n, a := sum_congr rfl (fun a ha => min_eq_left (le_of_lt (mem_range.mp ha))) have hb : ∑ b ∈ range n, min n b = ∑ b ∈ range n, b := sum_congr rfl (fun b hb => min_eq_right (le_of_lt (mem_range.mp hb))) rw [ha, hb, min_self] ring have e2 := sum_range_id_mul_two n rw [e1] have e3 : 2 * ∑ a ∈ range n, a = n * (n - 1) := by rw [mul_comm]; exact e2 rw [e3] rcases n with _ | m · simp · simp only [Nat.add_sub_cancel] at ih ⊢ push_cast at ih ⊢ nlinarith [ih] open Classical in /-- The ranks `r_x` enumerate `0, …, n − 1`: `Σ_{x, x′ ∈ P} min(r_x, r_{x′}) = Σ_{a, b < n} min(a, b)`. -/ theorem sum_min_latR {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (hrk : Set.InjOn rk P) : ∑ x ∈ P, ∑ x' ∈ P, min (latR P rk x) (latR P rk x') = ∑ a ∈ range P.card, ∑ b ∈ range P.card, min a b := by have hlt : ∀ x ∈ P, latR P rk x < P.card := by intro x hx unfold latR apply card_lt_card refine ⟨filter_subset _ _, fun h => ?_⟩ have := h hx rw [mem_filter] at this exact lt_irrefl _ this.2 have hinj : Set.InjOn (latR P rk) P := by have key : ∀ x ∈ P, ∀ x' ∈ P, rk x < rk x' → latR P rk x' < latR P rk x := by intro x hx x' hx' hlt' unfold latR apply card_lt_card refine ⟨fun y hy => ?_, fun h => ?_⟩ · rw [mem_filter] at hy ⊢ exact ⟨hy.1, lt_trans hlt' hy.2⟩ · have := h (mem_filter.mpr ⟨hx', hlt'⟩) rw [mem_filter] at this exact lt_irrefl _ this.2 intro x hx x' hx' h by_contra hne rcases lt_trichotomy (rk x) (rk x') with h1 | h1 | h1 · have := key x hx x' hx' h1 omega · exact hne (hrk hx hx' h1) · have := key x' hx' x hx h1 omega have himg : P.image (latR P rk) = range P.card := by apply eq_of_subset_of_card_le · intro a ha rw [mem_image] at ha obtain ⟨x, hx, rfl⟩ := ha exact mem_range.mpr (hlt x hx) · rw [card_image_of_injOn hinj, card_range] rw [← himg, sum_image hinj] refine sum_congr rfl (fun x _ => ?_) rw [sum_image hinj] open Classical in /-- **INVERSE Theorem 11.36 (1D-ization inequality)** [audited INV3-A4], in `ℕ` and for any finite set `W` of classes (the paper's statement is `W = distanceSet P`; any `W` gives the partial-energy form of its remark): for every finite `P` in a metric space and every total order (ranking `rk` injective on `P`), `6·Σ_{u∈W} f(u)² + 3n² ≤ 2n³ + n + 12·Σ_{u∈W} f(u)E_u`, i.e. `Σ_W f² ≤ n(n − 1)(2n − 1)/6 + 2Σ_W f E`. -/ theorem thm1136_nat {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (hrk : Set.InjOn rk P) (W : Finset ℝ) : 6 * ∑ u ∈ W, distanceMultiplicity P u ^ 2 + 3 * P.card ^ 2 ≤ 2 * P.card ^ 3 + P.card + 12 * ∑ u ∈ W, distanceMultiplicity P u * latE P rk u := by have hf := mult_eq_sum_lat P rk hrk -- expand f(u)² = Σ_x Σ_x' a a' have hsq : ∀ u, distanceMultiplicity P u ^ 2 = ∑ x ∈ P, ∑ x' ∈ P, lat P rk u x * lat P rk u x' := by intro u rw [hf u, sq, sum_mul_sum] have hstep : ∀ u, ∑ x ∈ P, ∑ x' ∈ P, lat P rk u x * lat P rk u x' ≤ ∑ x ∈ P, ∑ x' ∈ P, min (lat P rk u x) (lat P rk u x') + 2 * (distanceMultiplicity P u * latE P rk u) := by intro u have h1 : ∑ x ∈ P, ∑ x' ∈ P, lat P rk u x * lat P rk u x' ≤ ∑ x ∈ P, ∑ x' ∈ P, (min (lat P rk u x) (lat P rk u x') + (lat P rk u x - 1) * lat P rk u x' + lat P rk u x * (lat P rk u x' - 1)) := sum_le_sum (fun x _ => sum_le_sum (fun x' _ => mul_le_min_add _ _)) have h2 : ∑ x ∈ P, ∑ x' ∈ P, (min (lat P rk u x) (lat P rk u x') + (lat P rk u x - 1) * lat P rk u x' + lat P rk u x * (lat P rk u x' - 1)) = ∑ x ∈ P, ∑ x' ∈ P, min (lat P rk u x) (lat P rk u x') + (∑ x ∈ P, (lat P rk u x - 1)) * (∑ x' ∈ P, lat P rk u x') + (∑ x ∈ P, lat P rk u x) * (∑ x' ∈ P, (lat P rk u x' - 1)) := by rw [sum_mul_sum, sum_mul_sum, ← sum_add_distrib, ← sum_add_distrib] refine sum_congr rfl (fun x _ => ?_) rw [← sum_add_distrib, ← sum_add_distrib] rw [h2] at h1 unfold latE rw [← hf u] at h1 linarith -- Σ_u min(a_u x, a_u x') ≤ min(r_x, r_x') have hmin : ∀ x x', ∑ u ∈ W, min (lat P rk u x) (lat P rk u x') ≤ min (latR P rk x) (latR P rk x') := by intro x x' refine le_min ?_ ?_ · exact le_trans (sum_le_sum (fun u _ => min_le_left _ _)) (sum_lat_le P rk W x) · exact le_trans (sum_le_sum (fun u _ => min_le_right _ _)) (sum_lat_le P rk W x') have hT := sum_min_range P.card have hR := sum_min_latR P rk hrk have hA : ∑ u ∈ W, distanceMultiplicity P u ^ 2 ≤ ∑ x ∈ P, ∑ x' ∈ P, min (latR P rk x) (latR P rk x') + 2 * ∑ u ∈ W, distanceMultiplicity P u * latE P rk u := by calc ∑ u ∈ W, distanceMultiplicity P u ^ 2 = ∑ u ∈ W, ∑ x ∈ P, ∑ x' ∈ P, lat P rk u x * lat P rk u x' := sum_congr rfl (fun u _ => hsq u) _ ≤ ∑ u ∈ W, (∑ x ∈ P, ∑ x' ∈ P, min (lat P rk u x) (lat P rk u x') + 2 * (distanceMultiplicity P u * latE P rk u)) := sum_le_sum (fun u _ => hstep u) _ = ∑ x ∈ P, ∑ x' ∈ P, ∑ u ∈ W, min (lat P rk u x) (lat P rk u x') + 2 * ∑ u ∈ W, distanceMultiplicity P u * latE P rk u := by rw [sum_add_distrib, ← mul_sum] congr 1 rw [sum_comm] refine sum_congr rfl (fun x _ => ?_) rw [sum_comm] _ ≤ ∑ x ∈ P, ∑ x' ∈ P, min (latR P rk x) (latR P rk x') + 2 * ∑ u ∈ W, distanceMultiplicity P u * latE P rk u := by gcongr with x _ x' _ exact hmin x x' rw [hR] at hA linarith open Classical in /-- **INVERSE Theorem 11.36**, real form: `Σ_{u∈W} f(u)² ≤ n(n − 1)(2n − 1)/6 + 2Σ_{u∈W} f(u)E_u ≤ n³/3 + 2Σ_W f E` (`W = distanceSet P` gives `S(P)`). -/ theorem thm1136 {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (hrk : Set.InjOn rk P) (W : Finset ℝ) : ∑ u ∈ W, (distanceMultiplicity P u : ℝ) ^ 2 ≤ (P.card : ℝ) * (P.card - 1) * (2 * P.card - 1) / 6 + 2 * ∑ u ∈ W, (distanceMultiplicity P u : ℝ) * (latE P rk u : ℝ) := by have h := thm1136_nat P rk hrk W have h' : 6 * ∑ u ∈ W, (distanceMultiplicity P u : ℝ) ^ 2 + 3 * (P.card : ℝ) ^ 2 ≤ 2 * (P.card : ℝ) ^ 3 + P.card + 12 * ∑ u ∈ W, (distanceMultiplicity P u : ℝ) * (latE P rk u : ℝ) := by exact_mod_cast h nlinarith end Erdos94ThmA /-! ### INVERSE Thm 11.24′ (unconditional), the vertex-count interface: helper lemmas (scale choice, budgets) -/ namespace Erdos94ThmA open Finset /-- Exactly `K` elements of `U` lie below its `(K+1)`-th smallest element. -/ theorem card_lt_usort {U : Finset ℝ} {K : ℕ} (hK : K < U.card) : (U.filter (fun u => u < usort U K)).card = K := by have hsub : U.filter (fun u => u < usort U K) = (range K).image (usort U) := by ext u rw [mem_filter, mem_image] constructor · rintro ⟨hu, hlt⟩ have hrange : u ∈ Set.range (U.orderEmbOfFin rfl) := by rw [Finset.range_orderEmbOfFin] exact hu obtain ⟨⟨i, hi⟩, hie⟩ := hrange have hui : usort U i = u := by unfold usort rw [dif_pos hi] exact hie refine ⟨i, mem_range.mpr ?_, hui⟩ by_contra hc push Not at hc rcases Nat.eq_or_lt_of_le hc with h | h · rw [← hui, ← h] at hlt exact lt_irrefl _ hlt · have := usort_lt h hi rw [hui] at this linarith · rintro ⟨i, hi, rfl⟩ exact ⟨usort_mem (by have := mem_range.mp hi; omega), usort_lt (mem_range.mp hi) hK⟩ rw [hsub, card_image_of_injOn, card_range] intro i hi j hj h by_contra hne have hi' := mem_range.mp (mem_coe.mp hi) have hj' := mem_range.mp (mem_coe.mp hj) rcases lt_or_gt_of_ne hne with h' | h' · have := usort_lt h' (by omega : j < U.card) rw [h] at this exact lt_irrefl _ this · have := usort_lt h' (by omega : i < U.card) rw [h] at this exact lt_irrefl _ this /-- If more than `K` elements of `U` lie below `a`, the `(K+1)`-th smallest does. -/ theorem usort_lt_of_card {U : Finset ℝ} {K : ℕ} {a : ℝ} (h : K < (U.filter (fun u => u < a)).card) : usort U K < a := by have hK : K < U.card := lt_of_lt_of_le h (card_le_card (filter_subset _ _)) by_contra hc push Not at hc have hsub : U.filter (fun u => u < a) ⊆ U.filter (fun u => u < usort U K) := by intro u hu rw [mem_filter] at hu ⊢ exact ⟨hu.1, lt_of_lt_of_le hu.2 hc⟩ have := card_le_card hsub rw [card_lt_usort hK] at this omega open Classical in /-- `Σ_x def(x) ≤ εnK + |B|²/2` (from `dfc_total` and the near-full class sizes). -/ theorem dfc_sum_le {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) {ε : ℝ} (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (u₀ : ℝ) : (∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) ≤ ε * n * (U.filter (fun u => u < u₀)).card + ((thinB v u₀).card : ℝ) ^ 2 / 2 := by have h := dfc_total hv U u₀ have hsq : (thinB v u₀).card * (thinB v u₀).card - (thinB v u₀).card ≤ (thinB v u₀).card * (thinB v u₀).card := Nat.sub_le _ _ have hR : (2 * ∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) + ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) ≤ 2 * n * (U.filter (fun u => u < u₀)).card + ((thinB v u₀).card : ℝ) * (thinB v u₀).card := by have h' := h.trans (Nat.add_le_add_left hsq _) exact_mod_cast h' have hlow : ∑ u ∈ U.filter (fun u => u < u₀), (2 * (1 - ε) * (n : ℝ)) ≤ ∑ u ∈ U.filter (fun u => u < u₀), ((chO v u).card : ℝ) := sum_le_sum (fun u hu => hU2 u (mem_filter.mp hu).1) rw [sum_const, nsmul_eq_mul] at hlow nlinarith open Classical in /-- `Σ_x nf(x) ≤ 3εn²`. -/ theorem nfc_sum_le {n : ℕ} [NeZero n] (v : ZMod n → ℂ) (U : Finset ℝ) {ε : ℝ} (hε0 : 0 ≤ ε) (hε1 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (u₀ : ℝ) : (∑ x, (nfc v U u₀ x : ℝ)) ≤ 3 * ε * n ^ 2 := by have a := nfc_total v U u₀ have b := (thm119_Ptot v U hε0 hε1 hU1 hU2).1 have a' : ((∑ y, nfc v U u₀ y : ℕ) : ℝ) ≤ ((((univ : Finset (ZMod n)) ×ˢ univ).filter (fun p => p.1 ≠ p.2 ∧ dist (v p.1) (v p.2) ∉ U)).card : ℝ) := by exact_mod_cast a push_cast at a' linarith /-- `t² ≤ a·t + b` with `a, b ≥ 0` gives `t ≤ a + √b`. -/ theorem quad_le {t a b : ℝ} (ht : 0 ≤ t) (ha : 0 ≤ a) (hb : 0 ≤ b) (h : t ^ 2 ≤ a * t + b) : t ≤ a + Real.sqrt b := by by_contra hc push Not at hc have hs : 0 ≤ Real.sqrt b := Real.sqrt_nonneg b have h1 : Real.sqrt b < t - a := by linarith have h2 : b < (t - a) ^ 2 := by have := mul_lt_mul'' h1 h1 hs hs rw [Real.mul_self_sqrt hb] at this nlinarith nlinarith /-- The number of windows: `nWin n w ≤ 2n/w + 1`. -/ theorem nWin_le {n w : ℕ} (hw : 1 ≤ w) : (nWin n w : ℝ) ≤ 2 * n / w + 1 := by have h := (nWin_spec (n := n) hw).1 have hs1 : 1 ≤ (w + 1) / 2 := by omega have hsR : (w : ℝ) / 2 ≤ (((w + 1) / 2 : ℕ) : ℝ) := by rw [div_le_iff₀ (by norm_num)] have : w ≤ (w + 1) / 2 * 2 := by omega exact_mod_cast this have hR : (nWin n w : ℝ) * (((w + 1) / 2 : ℕ) : ℝ) + 1 ≤ n + (((w + 1) / 2 : ℕ) : ℝ) := by exact_mod_cast h have hw0 : (0 : ℝ) < w := by exact_mod_cast (show 0 < w by omega) have hs0 : (0 : ℝ) < (((w + 1) / 2 : ℕ) : ℝ) := by exact_mod_cast hs1 have h1 : (nWin n w : ℝ) ≤ n / (((w + 1) / 2 : ℕ) : ℝ) + 1 := by rw [div_add_one hs0.ne', le_div_iff₀ hs0] linarith have h2 : (n : ℝ) / (((w + 1) / 2 : ℕ) : ℝ) ≤ 2 * n / w := by rw [div_le_div_iff₀ hs0 hw0] nlinarith [Nat.cast_nonneg (α := ℝ) n] linarith end Erdos94ThmA /-! ### INVERSE Thm 11.24′ (unconditional) vertex-count interface, part 2: arithmetic lemmas (kept small: heartbeats) -/ namespace Erdos94ThmA open Finset theorem wide_nfacts {κ n Mp : ℝ} (hκ0 : 0 < κ) (hκ64 : κ ≤ 1 / 64) (hMp8 : 8 ≤ Mp) (hn : 1000 * Mp / κ ^ 3 ≤ n) : 8000 ≤ κ * n ∧ 8000 * n ≤ (κ * n) ^ 2 ∧ 11 / κ ≤ n := by have hk3 : 0 < κ ^ 3 := by positivity have h1 : 1000 * Mp ≤ κ ^ 3 * n := by rw [div_le_iff₀ hk3] at hn; linarith have h2 : 8000 ≤ κ ^ 3 * n := by linarith have hn0 : 0 ≤ n := le_trans (by positivity) hn have hk1 : κ ≤ 1 := by linarith have hk2 : κ ^ 2 ≤ 1 := by nlinarith have e1 : κ ^ 3 * n ≤ κ * n := by have : κ ^ 3 ≤ κ := by calc κ ^ 3 = κ * κ ^ 2 := by ring _ ≤ κ * 1 := mul_le_mul_of_nonneg_left hk2 hκ0.le _ = κ := mul_one κ exact mul_le_mul_of_nonneg_right this hn0 have e2 : κ ^ 3 * n ≤ κ ^ 2 * n := by have : κ ^ 3 ≤ κ ^ 2 := by calc κ ^ 3 = κ ^ 2 * κ := by ring _ ≤ κ ^ 2 * 1 := mul_le_mul_of_nonneg_left hk1 (by positivity) _ = κ ^ 2 := mul_one _ exact mul_le_mul_of_nonneg_right this hn0 refine ⟨by linarith, ?_, ?_⟩ · have : 8000 * n ≤ κ ^ 2 * n * n := mul_le_mul_of_nonneg_right (by linarith) hn0 nlinarith · rw [div_le_iff₀ hκ0] linarith open Classical in /-- Thm 11.9″ (S1) at the chosen scale: the `(K+1)`-th near-full distance is `< ζ₀D/4` once `K ≤ κn`, `8Mpκ ≤ 1`. -/ theorem wide_S1 {n : ℕ} [NeZero n] (hn3 : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (U : Finset ℝ) {ε κ ζ₀ D : ℝ} (hε0 : 0 ≤ ε) (hε100 : ε ≤ 1 / 100) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) (hD : ∀ a b : ZMod n, ‖v a - v b‖ ≤ D) (hD0 : 0 < D) (hζ0 : 0 < ζ₀) (hκ0 : 0 < κ) (hκ1 : κ * (4 * (16 / ζ₀ + 2)) ≤ 1 / 8) (hεκ : ε ≤ κ / 64) {K : ℕ} (hK1 : (K : ℝ) ≤ κ * n) (hκn : 8000 ≤ κ * n) : usort U K < ζ₀ * D / 4 := by have hcl := classes_lower hn3 hv U hε0 hε100 hU1 hU2 hD (u₀ := ζ₀ * D / 4) (by positivity) have e : 4 * (4 * D / (ζ₀ * D / 4) + 2) = 4 * (16 / ζ₀ + 2) := by field_simp; ring rw [e] at hcl obtain ⟨Mp, hMp⟩ : ∃ M : ℝ, M = 4 * (16 / ζ₀ + 2) := ⟨_, rfl⟩ rw [← hMp] at hcl hκ1 have hMp0 : 0 < Mp := by rw [hMp]; positivity apply usort_lt_of_card by_contra hc push Not at hc have hc' : ((U.filter (fun u => u < ζ₀ * D / 4)).card : ℝ) ≤ K := by exact_mod_cast hc have hnpos : (0 : ℝ) < n := by have : (3 : ℝ) ≤ n := by exact_mod_cast hn3 linarith obtain ⟨Kp, hKp⟩ : ∃ k : ℝ, k = ((U.filter (fun u => u < ζ₀ * D / 4)).card : ℝ) := ⟨_, rfl⟩ rw [← hKp] at hcl hc' have h2 : (n : ℝ) ≤ Mp * (1 + 2 * Kp + 6 * ε * n) := by have e2 : Mp * (n + 2 * (n * Kp + 3 * ε * n ^ 2)) = n * (Mp * (1 + 2 * Kp + 6 * ε * n)) := by ring rw [e2, sq] at hcl exact le_of_mul_le_mul_left hcl hnpos have h3 : Mp * (2 * Kp) ≤ 2 * (Mp * κ) * n := by have := mul_le_mul_of_nonneg_left (hc'.trans hK1) hMp0.le linarith have h4 : Mp * (6 * ε * n) ≤ 6 * (Mp * κ) * n / 64 := by have a : ε * n ≤ κ / 64 * n := mul_le_mul_of_nonneg_right hεκ hnpos.le have := mul_le_mul_of_nonneg_left a hMp0.le linarith have h5 : Mp * κ * n ≤ n / 8 := by have := mul_le_mul_of_nonneg_right hκ1 hnpos.le linarith have h6 : Mp ≤ n / 1000 := by have h7 : Mp * (κ * n) ≤ n / 8 := by linarith have h8 : Mp * 8000 ≤ Mp * (κ * n) := mul_le_mul_of_nonneg_left hκn hMp0.le linarith have h9 : 0 ≤ Mp * κ * n := by positivity linarith /-- (S2) arithmetic: `B² ≤ M_B(B + 2(BK + 3εn²))`, `ε ≤ κ²`, `K ≤ κn`, `κn ≥ 1` ⇒ `B ≤ (3M_B + √(6M_B))κn`. -/ theorem wide_thin {B MB ε κ n K : ℝ} (hB0 : 0 ≤ B) (hMB0 : 0 < MB) (hε0 : 0 ≤ ε) (hεκ : ε ≤ κ ^ 2) (hκ0 : 0 < κ) (hn0 : 0 ≤ n) (hK0 : 0 ≤ K) (hK1 : K ≤ κ * n) (hκn1 : 1 ≤ κ * n) (hthin : B ^ 2 ≤ MB * (B + 2 * (B * K + 3 * ε * n ^ 2))) : B ≤ (3 * MB + Real.sqrt (6 * MB)) * (κ * n) := by have hq := quad_le hB0 (by positivity : (0 : ℝ) ≤ MB * (1 + 2 * K)) (by positivity : (0 : ℝ) ≤ 6 * MB * ε * n ^ 2) (by linarith) have hsq : Real.sqrt (6 * MB * ε * n ^ 2) ≤ Real.sqrt (6 * MB) * (κ * n) := by rw [show 6 * MB * ε * n ^ 2 = (6 * MB) * (ε * n ^ 2) by ring, Real.sqrt_mul (by positivity)] have h1 : Real.sqrt (ε * n ^ 2) ≤ κ * n := by rw [Real.sqrt_le_left (by positivity)] have : ε * n ^ 2 ≤ κ ^ 2 * n ^ 2 := mul_le_mul_of_nonneg_right hεκ (by positivity) linarith [show (κ * n) ^ 2 = κ ^ 2 * n ^ 2 by ring] exact mul_le_mul_of_nonneg_left h1 (Real.sqrt_nonneg _) have h2 : MB * (1 + 2 * K) ≤ 3 * MB * (κ * n) := by have : 1 + 2 * K ≤ 3 * (κ * n) := by linarith nlinarith linarith /-- Bad-window arithmetic: `#bad ≤ N₀(ζ₀)` (the count does not depend on `κ`). -/ theorem wide_bad_arith {bd Z wR T X CB CT : ℝ} (hX : 0 < X) (hCB : 0 ≤ CB) (hwR : X / 5 ≤ wR) (hbd : bd ≤ 2 + 6 * Z / wR + T / (2 * (1 / 10000) * wR ^ 2)) (hZ : Z ≤ (2 + 2 * CB ^ 2) * X) (hT : T ≤ (CT + 1) * X ^ 2) (hCT : 0 ≤ CT) : bd ≤ 2 + 120 * (1 + CB ^ 2) + 500000 * (CT + 1) := by have hw0 : 0 < wR := by linarith have h1 : 6 * Z / wR ≤ 120 * (1 + CB ^ 2) := by rw [div_le_iff₀ hw0] have h3 : (2 + 2 * CB ^ 2) * X ≤ (2 + 2 * CB ^ 2) * (5 * wR) := mul_le_mul_of_nonneg_left (by linarith) (by positivity) nlinarith have h2 : T / (2 * (1 / 10000) * wR ^ 2) ≤ 500000 * (CT + 1) := by rw [div_le_iff₀ (by positivity)] have hw2 : X ^ 2 ≤ 25 * wR ^ 2 := by have := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ X / 5) hwR 2 nlinarith have : (CT + 1) * X ^ 2 ≤ (CT + 1) * (25 * wR ^ 2) := mul_le_mul_of_nonneg_left hw2 (by linarith) nlinarith linarith /-- Final arithmetic of the vertex count. -/ theorem wide_E_arith {E d f Xt bd wR KR X sk n CB CT N0 : ℝ} (hX0 : 0 ≤ X) (hCB : 0 ≤ CB) (hN0 : 0 ≤ N0) (hE : E ≤ 11 * (6 * d + 6 * f + 241 * Xt + (KR + KR / 480 + 1) * (bd + 1)) + bd * wR) (hd : d ≤ 480 * (1 + CB ^ 2) * X) (hf : f ≤ 2880 * X) (hXt : Xt ≤ 6 * Real.sqrt (21 * (CT + 1)) * sk * n) (hbad1 : bd * wR ≤ N0 * X / 4) (hbad2 : (KR + KR / 480 + 1) * (bd + 1) ≤ 2 * X * (N0 + 1)) (hk : X ≤ sk * n) : E ≤ (11 * (2880 * (1 + CB ^ 2) + 17280 + 1446 * Real.sqrt (21 * (CT + 1)) + 2 * (N0 + 1)) + N0 / 4) * sk * n := by have p1 : 2880 * (1 + CB ^ 2) * X ≤ 2880 * (1 + CB ^ 2) * (sk * n) := mul_le_mul_of_nonneg_left hk (by positivity) have p3 : 2 * (N0 + 1) * X ≤ 2 * (N0 + 1) * (sk * n) := mul_le_mul_of_nonneg_left hk (by positivity) have p4 : N0 * X ≤ N0 * (sk * n) := mul_le_mul_of_nonneg_left hk hN0 have e : (11 * (2880 * (1 + CB ^ 2) + 17280 + 1446 * Real.sqrt (21 * (CT + 1)) + 2 * (N0 + 1)) + N0 / 4) * sk * n = 11 * (2880 * (1 + CB ^ 2) * (sk * n) + 17280 * (sk * n) + 1446 * (Real.sqrt (21 * (CT + 1)) * sk * n) + 2 * (N0 + 1) * (sk * n)) + N0 * (sk * n) / 4 := by ring rw [e] have e2 : 241 * (6 * Real.sqrt (21 * (CT + 1)) * sk * n) = 1446 * (Real.sqrt (21 * (CT + 1)) * sk * n) := by ring linarith /-- Counting by Markov: `#{x : t < f x} ≤ c` from `Σ f ≤ T` when `T ≤ c·t`. -/ theorem markov_le {α : Type*} (s : Finset α) (d : α → ℕ) {T t c : ℝ} (ht : 0 < t) (hsum : (∑ x ∈ s, d x : ℝ) ≤ T) (hTc : T ≤ c * t) : ((s.filter (fun x => t < d x)).card : ℝ) ≤ c := by have h := markov_card s d ht hsum by_contra hcon push Not at hcon have := mul_lt_mul_of_pos_right hcon ht linarith end Erdos94ThmA /-! ### INVERSE Thm 11.24′ (unconditional) vertex-count interface, part 3: budget lemmas and `wide_circles : WideCircles` -/ namespace Erdos94ThmA open Finset open Classical in /-- The non-anchors: `#{y : |F_{u₀}(y)| < 2w} ≤ (2 + 2C_B²)κn` (they have `def(y) > K/2`). -/ theorem wide_Zcount {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) (U : Finset ℝ) {u₀ ε κ B CB : ℝ} {K w : ℕ} (hKc : (U.filter (fun u => u < u₀)).card = K) (hw4 : 4 * w ≤ K) (hK0 : (0 : ℝ) < K) (hdfc : (∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) ≤ ε * n * K + B ^ 2 / 2) (hB2 : B ^ 2 ≤ CB ^ 2 * (κ * n) ^ 2) (hεnK : ε * n * K ≤ κ * (κ * n) * (κ * n)) (hκ64 : κ ≤ 1 / 64) (hκ0 : 0 < κ) (hKpos : κ * n / 2 ≤ (K : ℝ)) : ((((univ : Finset (ZMod n)).filter (fun y => (Fu0 v u₀ y).card < 2 * w)).card : ℝ)) ≤ (2 + 2 * CB ^ 2) * (κ * n) := by have hw4R : (4 : ℝ) * w ≤ K := by exact_mod_cast hw4 have hsub : (univ : Finset (ZMod n)).filter (fun y => (Fu0 v u₀ y).card < 2 * w) ⊆ (univ : Finset (ZMod n)).filter (fun y => (K : ℝ) / 2 < dfc v (U.filter (fun u => u < u₀)) y) := by intro y hy rw [mem_filter] at hy ⊢ refine ⟨mem_univ _, ?_⟩ have h1 := Fu0_card hv U u₀ y rw [hKc] at h1 have h2 : K < dfc v (U.filter (fun u => u < u₀)) y + 2 * w := by omega have h3 : (K : ℝ) < dfc v (U.filter (fun u => u < u₀)) y + 2 * w := by exact_mod_cast h2 linarith have hcR : ((((univ : Finset (ZMod n)).filter (fun y => (Fu0 v u₀ y).card < 2 * w)).card : ℝ)) ≤ (((univ : Finset (ZMod n)).filter (fun y => (K : ℝ) / 2 < dfc v (U.filter (fun u => u < u₀)) y)).card : ℝ) := by exact_mod_cast card_le_card hsub have hX0 : 0 ≤ κ * n := by positivity have hm := markov_le (univ : Finset (ZMod n)) (fun y => dfc v (U.filter (fun u => u < u₀)) y) (T := ε * n * K + B ^ 2 / 2) (t := (K : ℝ) / 2) (c := (2 + 2 * CB ^ 2) * (κ * n)) (by positivity) hdfc (by have h3 : κ * (κ * n) * (κ * n) ≤ (κ * n) * (κ * n) / 64 := by have := mul_le_mul_of_nonneg_right hκ64 (mul_nonneg hX0 hX0); linarith have h4 : (2 + 2 * CB ^ 2) * (κ * n) * (κ * n / 4) ≤ (2 + 2 * CB ^ 2) * (κ * n) * ((K : ℝ) / 2) := mul_le_mul_of_nonneg_left (by linarith) (by positivity) have e : (2 + 2 * CB ^ 2) * (κ * n) * (κ * n / 4) = (κ * n) * (κ * n) / 2 + CB ^ 2 * (κ * n) ^ 2 / 2 := by ring nlinarith) beta_reduce at hm linarith /-- `#{x : K/480 < def(x)} ≤ 480(1 + C_B²)κn`. -/ theorem wide_dcount {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (U : Finset ℝ) {u₀ ε κ B CB : ℝ} {K : ℕ} (hK0 : (0 : ℝ) < K) (hdfc : (∑ x, (dfc v (U.filter (fun u => u < u₀)) x : ℝ)) ≤ ε * n * K + B ^ 2 / 2) (hB2 : B ^ 2 ≤ CB ^ 2 * (κ * n) ^ 2) (hεnK : ε * n * K ≤ κ * (κ * n) * (κ * n)) (hκ64 : κ ≤ 1 / 64) (hκ0 : 0 < κ) (hKpos : κ * n / 2 ≤ (K : ℝ)) : (((univ : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < dfc v (U.filter (fun u => u < u₀)) x)).card : ℝ) ≤ 480 * (1 + CB ^ 2) * (κ * n) := by have hX0 : 0 ≤ κ * n := by positivity exact markov_le (univ : Finset (ZMod n)) (fun y => dfc v (U.filter (fun u => u < u₀)) y) (T := ε * n * K + B ^ 2 / 2) (by positivity) hdfc (by have h3 : κ * (κ * n) * (κ * n) ≤ (κ * n) * (κ * n) / 64 := by have := mul_le_mul_of_nonneg_right hκ64 (mul_nonneg hX0 hX0); linarith have h4 : 480 * (1 + CB ^ 2) * (κ * n) * (κ * n / 2 / 480) ≤ 480 * (1 + CB ^ 2) * (κ * n) * ((K : ℝ) / 480) := mul_le_mul_of_nonneg_left (by linarith) (by positivity) have e : 480 * (1 + CB ^ 2) * (κ * n) * (κ * n / 2 / 480) = (κ * n) * (κ * n) / 2 + CB ^ 2 * (κ * n) ^ 2 / 2 := by ring nlinarith) /-- `#{x : K/480 < nf(x)} ≤ 2880κn`. -/ theorem wide_fcount {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (U : Finset ℝ) {u₀ ε κ : ℝ} {K : ℕ} (hK0 : (0 : ℝ) < K) (hnfc : (∑ x, (nfc v U u₀ x : ℝ)) ≤ 3 * ε * n ^ 2) (hεκ : ε ≤ κ ^ 2) (hκ0 : 0 < κ) (hKpos : κ * n / 2 ≤ (K : ℝ)) : (((univ : Finset (ZMod n)).filter (fun x => (K : ℝ) / 480 < nfc v U u₀ x)).card : ℝ) ≤ 2880 * (κ * n) := by have hX0 : 0 ≤ κ * n := by positivity exact markov_le (univ : Finset (ZMod n)) (fun y => nfc v U u₀ y) (T := 3 * ε * n ^ 2) (by positivity) hnfc (by have h1 : 3 * ε * (n : ℝ) ^ 2 ≤ 3 * (κ * n) * (κ * n) := by have := mul_le_mul_of_nonneg_right hεκ (by positivity : (0 : ℝ) ≤ (n : ℝ) ^ 2) nlinarith have h4 : 2880 * (κ * n) * (κ * n / 2 / 480) ≤ 2880 * (κ * n) * ((K : ℝ) / 480) := mul_le_mul_of_nonneg_left (by linarith) (by positivity) nlinarith) /-- The changed-pair total: `18εn² + 18B² + 24εnK + 2Km ≤ (C_T + 1)(κn)²`. -/ theorem wide_Tsum {ε κ n B CB CT K m : ℝ} (hε0 : 0 ≤ ε) (hεκ : ε ≤ κ ^ 2) (hκ0 : 0 < κ) (hκ64 : κ ≤ 1 / 64) (hn0 : 0 ≤ n) (hK0 : 0 ≤ K) (hK1 : K ≤ κ * n) (hm0 : 0 ≤ m) (hmR : m ≤ 11 / κ) (hB2 : B ^ 2 ≤ CB ^ 2 * (κ * n) ^ 2) (hεnK : ε * n * K ≤ κ * (κ * n) * (κ * n)) (hX : 8000 * n ≤ (κ * n) ^ 2) (hCT : CT = 42 + 18 * CB ^ 2) : 18 * ε * n ^ 2 + 18 * B ^ 2 + 24 * ε * n * K + 2 * K * m ≤ (CT + 1) * (κ * n) ^ 2 := by have hX0 : 0 ≤ κ * n := by positivity have h1 : ε * n ^ 2 ≤ (κ * n) ^ 2 := by have := mul_le_mul_of_nonneg_right hεκ (by positivity : (0 : ℝ) ≤ n ^ 2) nlinarith have h2 : ε * n * K ≤ (κ * n) ^ 2 := by have h3 : κ * (κ * n) * (κ * n) ≤ (κ * n) * (κ * n) / 64 := by have := mul_le_mul_of_nonneg_right hκ64 (mul_nonneg hX0 hX0) linarith nlinarith have h3 : 2 * K * m ≤ 22 * n := by have : K * m ≤ κ * n * (11 / κ) := mul_le_mul hK1 hmR hm0 hX0 rw [show κ * n * (11 / κ) = 11 * n by field_simp] at this linarith rw [hCT] nlinarith /-- The number of windows at the chosen scale: `m ≤ 11/κ`. -/ theorem wide_mR {n w : ℕ} {κ : ℝ} (hκ0 : 0 < κ) (hκ1 : κ ≤ 1) (hw1 : 1 ≤ w) (hwR : κ * n / 5 ≤ (w : ℝ)) : (nWin n w : ℝ) ≤ 11 / κ := by have h1 := nWin_le (n := n) hw1 have hw0 : (0 : ℝ) < w := by exact_mod_cast (show 0 < w by omega) have h2 : 2 * (n : ℝ) / w ≤ 10 / κ := by rw [div_le_div_iff₀ hw0 hκ0] nlinarith have h3 : (1 : ℝ) ≤ 1 / κ := by rw [le_div_iff₀ hκ0]; linarith have : (11 : ℝ) / κ = 10 / κ + 1 / κ := by ring linarith open Classical in /-- The window exceptions `Σ_good 6√((chg+1)/2) ≤ 6√(21(CT+1))·√κ·n`. -/ theorem wide_xtot {n : ℕ} [NeZero n] {v : ZMod n → ℂ} {u₀ : ℝ} {w m : ℕ} {κ CT S : ℝ} (hκ0 : 0 < κ) (hCT : 42 ≤ CT) (hmR : (m : ℝ) ≤ 11 / κ) (hn11 : 11 / κ ≤ n) (hX : 8000 * n ≤ (κ * n) ^ 2) (hS : ∑ k ∈ (range m).filter (fun k => anchW v u₀ w k), ((chgW v (winK w k)).card : ℝ) ≤ S) (hSle : S ≤ (CT + 1) * (κ * n) ^ 2) : ∑ k ∈ (range m).filter (fun k => goodW v u₀ w k), 6 * Real.sqrt ((((chgW v (winK w k)).card : ℝ) + 1) / 2) ≤ 6 * Real.sqrt (21 * (CT + 1)) * Real.sqrt κ * n := by rw [← mul_sum] have hss := sum_sqrt_le ((range m).filter (fun k => goodW v u₀ w k)) (fun k => (((chgW v (winK w k)).card : ℝ) + 1) / 2) (fun k _ => by positivity) have hgc : (((range m).filter (fun k => goodW v u₀ w k)).card : ℝ) ≤ m := by have := card_le_card (filter_subset (fun k => goodW v u₀ w k) (range m)) rw [card_range] at this exact_mod_cast this have hgsub : (range m).filter (fun k => goodW v u₀ w k) ⊆ (range m).filter (fun k => anchW v u₀ w k) := by intro k hk rw [mem_filter] at hk ⊢ exact ⟨hk.1, hk.2.1⟩ have hgs : ∑ k ∈ (range m).filter (fun k => goodW v u₀ w k), ((chgW v (winK w k)).card : ℝ) ≤ (CT + 1) * (κ * n) ^ 2 := le_trans (sum_le_sum_of_subset_of_nonneg hgsub (fun _ _ _ => Nat.cast_nonneg _)) (hS.trans hSle) have hSum : ∑ k ∈ (range m).filter (fun k => goodW v u₀ w k), (((chgW v (winK w k)).card : ℝ) + 1) / 2 ≤ ((CT + 1) * (κ * n) ^ 2 + m) / 2 := by rw [← sum_div, sum_add_distrib, sum_const, nsmul_eq_mul, mul_one] apply div_le_div_of_nonneg_right _ (by norm_num) linarith have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg _ have hm11 : (m : ℝ) ≤ (κ * n) ^ 2 := by have h1 : (m : ℝ) ≤ n := hmR.trans hn11 have h2 : (n : ℝ) ≤ 8000 * n := by linarith linarith have hpos : (0 : ℝ) ≤ ∑ k ∈ (range m).filter (fun k => goodW v u₀ w k), (((chgW v (winK w k)).card : ℝ) + 1) / 2 := by positivity have hprod : (((range m).filter (fun k => goodW v u₀ w k)).card : ℝ) * ∑ k ∈ (range m).filter (fun k => goodW v u₀ w k), (((chgW v (winK w k)).card : ℝ) + 1) / 2 ≤ 21 * (CT + 1) * κ * n ^ 2 := by calc _ ≤ (m : ℝ) * (((CT + 1) * (κ * n) ^ 2 + m) / 2) := mul_le_mul hgc hSum hpos (Nat.cast_nonneg _) _ ≤ (11 / κ) * (((CT + 2) * (κ * n) ^ 2) / 2) := by apply mul_le_mul hmR _ (by positivity) (by positivity) apply div_le_div_of_nonneg_right _ (by norm_num) linarith _ = 5.5 * (CT + 2) * κ * n ^ 2 := by field_simp; ring _ ≤ 21 * (CT + 1) * κ * n ^ 2 := by have : 5.5 * (CT + 2) ≤ 21 * (CT + 1) := by linarith exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right this hκ0.le) (by positivity) have hsq : Real.sqrt (21 * (CT + 1) * κ * n ^ 2) = Real.sqrt (21 * (CT + 1)) * Real.sqrt κ * n := by rw [Real.sqrt_mul (by positivity), Real.sqrt_mul (by positivity), Real.sqrt_sq hn0] have h1 := Real.sqrt_le_sqrt hprod rw [hsq] at h1 have h2 := hss.trans h1 linarith end Erdos94ThmA /-! ### INVERSE Thm 11.24′ (unconditional) vertex-count interface, part 4: the per-polygon core and `wide_circles` -/ namespace Erdos94ThmA open Finset /-- The final arithmetic of `wide_core` (separate declaration: heartbeats). -/ theorem wide_tail {Ec dc fc Xt bd KR wR κ n τ A CB CT N0 : ℝ} (hκ0 : 0 < κ) (hκ64 : κ ≤ 1 / 64) (hn0 : 0 ≤ n) (hK0 : 0 ≤ KR) (hK1 : KR ≤ κ * n) (hw4 : 4 * wR ≤ KR) (hw0 : 0 ≤ wR) (hbd0 : 0 ≤ bd) (hE : Ec ≤ 11 * (6 * dc + 6 * fc + 241 * Xt + (KR + KR / 480 + 1) * (bd + 1)) + bd * wR) (hd : dc ≤ 480 * (1 + CB ^ 2) * (κ * n)) (hf : fc ≤ 2880 * (κ * n)) (hXt : Xt ≤ 6 * Real.sqrt (21 * (CT + 1)) * Real.sqrt κ * n) (hbadN : bd ≤ N0) (hκ2 : κ ≤ (τ / A) ^ 2) (hτ : 0 < τ) (hA : A = 11 * (2880 * (1 + CB ^ 2) + 17280 + 1446 * Real.sqrt (21 * (CT + 1)) + 2 * (N0 + 1)) + N0 / 4) (hA0 : 0 < A) (hCB0 : 0 ≤ CB) (hN00 : 0 < N0) (hκn1 : 2 ≤ κ * n) : Ec ≤ τ * n := by have hsk : κ ≤ Real.sqrt κ := by have h1 : Real.sqrt κ ≤ 1 := by rw [Real.sqrt_le_one]; linarith have h2 := Real.mul_self_sqrt hκ0.le have h3 := Real.sqrt_nonneg κ nlinarith have hskτ : Real.sqrt κ ≤ τ / A := by have := Real.sqrt_le_sqrt hκ2 rwa [Real.sqrt_sq (by positivity)] at this have hbad1 : bd * wR ≤ N0 * (κ * n) / 4 := by have := mul_le_mul hbadN (show wR ≤ κ * n / 4 by linarith) hw0 hN00.le linarith have hbad2 : (KR + KR / 480 + 1) * (bd + 1) ≤ 2 * (κ * n) * (N0 + 1) := mul_le_mul (by linarith) (by linarith) (by positivity) (by positivity) have hfin := wide_E_arith (by positivity) hCB0 hN00.le hE hd hf hXt hbad1 hbad2 (mul_le_mul_of_nonneg_right hsk hn0) rw [← hA] at hfin calc Ec ≤ A * Real.sqrt κ * n := hfin _ ≤ A * (τ / A) * n := by apply mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hskτ hA0.le) hn0 _ = τ * n := by field_simp open Classical in /-- The per-polygon core of `wide_circles` (all constants given). -/ theorem wide_core {ζ₀ s MB CB CT N0 A κ ε τ : ℝ} (hζ0 : 0 < ζ₀) (hζ1 : ζ₀ ≤ 1) (hs : s = Real.sin (ζ₀ / 8 / 2)) (hs0 : 0 < s) (hMB : MB = 16 * (4 * ((1 + s) / s) + 2)) (hMB0 : 0 < MB) (hCB : CB = 3 * MB + Real.sqrt (6 * MB)) (hCB0 : 0 ≤ CB) (hCT : CT = 42 + 18 * CB ^ 2) (hCT42 : 42 ≤ CT) (hN0 : N0 = 2 + 120 * (1 + CB ^ 2) + 500000 * (CT + 1)) (hN00 : 0 < N0) (hA : A = 11 * (2880 * (1 + CB ^ 2) + 17280 + 1446 * Real.sqrt (21 * (CT + 1)) + 2 * (N0 + 1)) + N0 / 4) (hA0 : 0 < A) (hκ0 : 0 < κ) (hκ64 : κ ≤ 1 / 64) (hκMp : κ * (4 * (16 / ζ₀ + 2)) ≤ 1 / 8) (hκ2 : κ ≤ (τ / A) ^ 2) (hτ : 0 < τ) (hε0 : 0 < ε) (hεκ : ε ≤ κ ^ 2) (hε100 : ε ≤ 1 / 100) {n : ℕ} [NeZero n] (hn3 : 3 ≤ n) (hκn : 8000 ≤ κ * n) (hX : 8000 * n ≤ (κ * n) ^ 2) (hn11 : 11 / κ ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (hvi : Function.Injective v) (hT : ∀ t : ℂ, t ≠ 0 → ((univ : Finset (ZMod n)).filter (fun x => ∃ y, v y = v x + t)).card ≤ 2) {D : ℝ} (hD : ∀ a b, ‖v a - v b‖ ≤ D) (hfat : ∀ u : ℂ, ‖u‖ = 1 → ∃ z z', ζ₀ * D ≤ ((starRingEnd ℂ) u * (v z - v z')).re) (U : Finset ℝ) (hU1 : (1 / 2 - ε) * n ≤ U.card) (hU2 : ∀ u ∈ U, 2 * (1 - ε) * n ≤ (chO v u).card) : ∃ C : Finset (ℂ × ℝ), (∀ c ∈ C, 0 < c.2) ∧ (∀ c ∈ C, ∀ c' ∈ C, c.1 = c'.1 → c = c') ∧ C.card ≤ ⌈N0⌉₊ + 1 ∧ (((univ : Finset (ZMod n)).filter (fun x => ∀ c ∈ C, ‖v x - c.1‖ ≠ c.2)).card : ℝ) ≤ τ * n := by have hL := ccw_leftTurns hn3 hv have hn0R : (0 : ℝ) ≤ n := Nat.cast_nonneg _ have hεκ' : ε ≤ κ / 64 := by have : κ ^ 2 ≤ κ / 64 := by have := mul_le_mul_of_nonneg_left hκ64 hκ0.le linarith [show κ ^ 2 = κ * κ by ring] linarith -- the scale obtain ⟨K, hK⟩ : ∃ K : ℕ, K = ⌊κ * n⌋₊ := ⟨_, rfl⟩ have hK1 : (K : ℝ) ≤ κ * n := by rw [hK]; exact Nat.floor_le (by positivity) have hK2 : κ * n - 1 < (K : ℝ) := by rw [hK] have := Nat.lt_floor_add_one (κ * (n : ℝ)) linarith have hκn64 : κ * (n : ℝ) ≤ n / 64 := by have := mul_le_mul_of_nonneg_right hκ64 hn0R linarith have hKU : K < U.card := by have h1 : (K : ℝ) < U.card := by have h3 : 0.49 * (n : ℝ) ≤ (1 / 2 - ε) * n := mul_le_mul_of_nonneg_right (by linarith) hn0R linarith exact_mod_cast h1 obtain ⟨u₀, hu₀⟩ : ∃ u, u = usort U K := ⟨_, rfl⟩ have hKc : (U.filter (fun u => u < u₀)).card = K := by rw [hu₀]; exact card_lt_usort hKU have h01 : (0 : ZMod n) ≠ 1 := fun h => by have := congrArg ZMod.val h rw [ZMod.val_zero, val_one_of_three hn3] at this omega have hD0 : 0 < D := lt_of_lt_of_le (norm_pos_iff.mpr (sub_ne_zero.mpr (fun h => h01 (hvi h)))) (hD 0 1) have hu₀U : u₀ ∈ U := by rw [hu₀]; exact usort_mem hKU have hu₀0 : 0 < u₀ := by have h1 := hU2 u₀ hu₀U have h2 : 0 < (chO v u₀).card := by have h3 : (0 : ℝ) < 2 * (1 - ε) * n := by have a : (0 : ℝ) < 1 - ε := by linarith have b : (0 : ℝ) < n := by linarith positivity have : (0 : ℝ) < (chO v u₀).card := lt_of_lt_of_le h3 h1 exact_mod_cast this obtain ⟨p, hp⟩ := card_pos.mp h2 obtain ⟨hne, hd⟩ := mem_chO.mp hp rw [← hd] exact dist_pos.mpr (fun h => hne (hvi h)) have hS1 : u₀ < ζ₀ * D / 4 := by rw [hu₀] exact wide_S1 hn3 hv U hε0.le hε100 hU1 hU2 hD hD0 hζ0 hκ0 hκMp hεκ' hK1 hκn -- (S2) have hsmall : u₀ + 2 * (ζ₀ / 8) * D < ζ₀ * D := by have : 0 < ζ₀ * D := by positivity linarith have hthin := thin_card_bound hn3 hv U hε0.le hε100 hU1 hU2 (η := ζ₀ / 8) (by positivity) (by linarith) hfat hD hsmall hu₀0 rw [← hs, hKc] at hthin have eMB : 16 * (4 * ((1 + s) * u₀ / s) / u₀ + 2) = MB := by rw [hMB]; field_simp rw [eMB] at hthin obtain ⟨B, hB⟩ : ∃ B : ℝ, B = ((thinB v u₀).card : ℝ) := ⟨_, rfl⟩ rw [← hB] at hthin have hB0 : 0 ≤ B := by rw [hB]; exact Nat.cast_nonneg _ have hBle : B ≤ CB * (κ * n) := by rw [hCB] exact wide_thin hB0 hMB0 hε0.le hεκ hκ0 hn0R (Nat.cast_nonneg _) hK1 (by linarith) hthin have hB2 : B ^ 2 ≤ CB ^ 2 * (κ * n) ^ 2 := by have := pow_le_pow_left₀ hB0 hBle 2 rw [mul_pow] at this exact this -- windows obtain ⟨w, hw⟩ : ∃ w : ℕ, w = K / 4 := ⟨_, rfl⟩ have hw4 : 4 * w ≤ K := by omega have hwR : κ * n / 5 ≤ (w : ℝ) := by have h1 : (K : ℝ) ≤ 4 * w + 3 := by have : K ≤ 4 * w + 3 := by omega exact_mod_cast this linarith have hw71 : 71 ≤ w := by have : (71 : ℝ) ≤ w := by linarith exact_mod_cast this have hwn : w < n := by have : (w : ℝ) < n := by have h4R : (4 : ℝ) * w ≤ K := by exact_mod_cast hw4 linarith exact_mod_cast this obtain ⟨y₀, hH0⟩ := H0_almost hn3 hv obtain ⟨hbad, hsumA⟩ := bad_count' hn3 hv hH0 U hε0.le hε100 hU1 hU2 hu₀0 (w := w) (by omega) hwn rw [hKc, ← hB] at hbad hsumA obtain ⟨m, hm⟩ : ∃ m : ℕ, m = nWin n w := ⟨_, rfl⟩ rw [← hm] at hbad hsumA have hmR : (m : ℝ) ≤ 11 / κ := by rw [hm] exact wide_mR hκ0 (by linarith) (by omega) hwR have hdfc := dfc_sum_le hL U hU2 u₀ rw [hKc, ← hB] at hdfc have hnfc := nfc_sum_le v U hε0.le hε100 hU1 hU2 u₀ have hK0 : (0 : ℝ) < K := by linarith have hKpos : (κ * n) / 2 ≤ (K : ℝ) := by linarith have hεnK : ε * n * K ≤ κ * (κ * n) * (κ * n) := by have a : ε * n ≤ κ ^ 2 * n := mul_le_mul_of_nonneg_right hεκ hn0R have b := mul_le_mul a hK1 hK0.le (by positivity) have e : κ ^ 2 * n * (κ * n) = κ * (κ * n) * (κ * n) := by ring linarith have hZ := wide_Zcount hL U hKc hw4 hK0 hdfc hB2 hεnK hκ64 hκ0 hKpos have hTsum := wide_Tsum hε0.le hεκ hκ0 hκ64 hn0R hK0.le hK1 (Nat.cast_nonneg _) hmR hB2 hεnK hX hCT have hbadN : (((range m).filter (fun k => ¬ goodW v u₀ w k)).card : ℝ) ≤ N0 := by rw [hN0] exact wide_bad_arith (by linarith) hCB0 hwR hbad hZ hTsum (by linarith) have hXtot := wide_xtot hκ0 hCT42 hmR hn11 hX hsumA hTsum -- steps 1–4 obtain ⟨C, hCpos, hCdist, hCcard, hE⟩ := circles_from_windows hn3 hv hvi hT U (u₀ := u₀) (by rw [hKc]; omega) hw71 hwn rw [hKc, ← hm] at hE rw [← hm] at hCcard refine ⟨C, hCpos, hCdist, ?_, ?_⟩ · have h1 : (C.card : ℝ) ≤ N0 + 1 := by have : (C.card : ℝ) ≤ (((range m).filter (fun k => ¬ goodW v u₀ w k)).card : ℝ) + 1 := by exact_mod_cast hCcard linarith have h2 : N0 ≤ (⌈N0⌉₊ : ℝ) := Nat.le_ceil N0 have : (C.card : ℝ) ≤ ((⌈N0⌉₊ + 1 : ℕ) : ℝ) := by push_cast; linarith exact_mod_cast this · have hd := wide_dcount (v := v) U (u₀ := u₀) hK0 hdfc hB2 hεnK hκ64 hκ0 hKpos have hf := wide_fcount (v := v) U hK0 hnfc hεκ hκ0 hKpos have hw4R : (4 : ℝ) * w ≤ K := by exact_mod_cast hw4 exact wide_tail hκ0 hκ64 hn0R hK0.le hK1 hw4R (Nat.cast_nonneg _) (Nat.cast_nonneg _) hE hd hf hXtot hbadN hκ2 hτ hA hA0 hCB0 hN00 (by linarith) open Classical in /-- **`wide_circles : WideCircles`** — INVERSE Theorem 11.24′, unconditional vertex-count form (LEAN-5's interface, `WideCircles`): `k₀ = ⌈N₀(ζ₀)⌉ + 1`; given `τ`, `κ = min(1/(8Mp), (τ/A)²)`, `ε₀ = min(κ², 1/100)`, `n₀ = ⌈1000Mp/κ³⌉ + 1000`. -/ theorem wide_circles : WideCircles := by unfold WideCircles intro ζ₀ hζ0 hζ1 obtain ⟨s, hs⟩ : ∃ s : ℝ, s = Real.sin (ζ₀ / 8 / 2) := ⟨_, rfl⟩ have hs0 : 0 < s := by rw [hs] exact Real.sin_pos_of_pos_of_lt_pi (by positivity) (by linarith [Real.two_le_pi]) obtain ⟨MB, hMB⟩ : ∃ M : ℝ, M = 16 * (4 * ((1 + s) / s) + 2) := ⟨_, rfl⟩ obtain ⟨Mp, hMp⟩ : ∃ M : ℝ, M = 4 * (16 / ζ₀ + 2) := ⟨_, rfl⟩ obtain ⟨CB, hCB⟩ : ∃ C : ℝ, C = 3 * MB + Real.sqrt (6 * MB) := ⟨_, rfl⟩ obtain ⟨CT, hCT⟩ : ∃ C : ℝ, C = 42 + 18 * CB ^ 2 := ⟨_, rfl⟩ obtain ⟨N0, hN0⟩ : ∃ N : ℝ, N = 2 + 120 * (1 + CB ^ 2) + 500000 * (CT + 1) := ⟨_, rfl⟩ obtain ⟨A, hA⟩ : ∃ A : ℝ, A = 11 * (2880 * (1 + CB ^ 2) + 17280 + 1446 * Real.sqrt (21 * (CT + 1)) + 2 * (N0 + 1)) + N0 / 4 := ⟨_, rfl⟩ have hMB0 : 0 < MB := by rw [hMB]; positivity have hMp8 : 8 ≤ Mp := by rw [hMp] have : 0 ≤ 16 / ζ₀ := by positivity linarith have hCB0 : 0 ≤ CB := by rw [hCB]; positivity have hCT42 : 42 ≤ CT := by rw [hCT] have := sq_nonneg CB linarith have hN00 : 0 < N0 := by rw [hN0]; positivity have hA0 : 0 < A := by rw [hA]; positivity refine ⟨⌈N0⌉₊ + 1, fun τ hτ => ?_⟩ obtain ⟨κ, hκ⟩ : ∃ κ : ℝ, κ = min (1 / (8 * Mp)) ((τ / A) ^ 2) := ⟨_, rfl⟩ have hκ0 : 0 < κ := by rw [hκ]; exact lt_min (by positivity) (by positivity) have hκ1 : κ ≤ 1 / (8 * Mp) := by rw [hκ]; exact min_le_left _ _ have hκ2 : κ ≤ (τ / A) ^ 2 := by rw [hκ]; exact min_le_right _ _ have hκ64 : κ ≤ 1 / 64 := by refine hκ1.trans ?_ rw [div_le_div_iff₀ (by positivity) (by norm_num)] linarith have hκMp : κ * (4 * (16 / ζ₀ + 2)) ≤ 1 / 8 := by rw [← hMp] have := mul_le_mul_of_nonneg_right hκ1 (by linarith : (0 : ℝ) ≤ Mp) rwa [show 1 / (8 * Mp) * Mp = 1 / 8 by field_simp] at this refine ⟨min (κ ^ 2) (1 / 100), lt_min (by positivity) (by norm_num), fun ε hε0 hεle => ?_⟩ have hεκ : ε ≤ κ ^ 2 := hεle.trans (min_le_left _ _) have hε100 : ε ≤ 1 / 100 := hεle.trans (min_le_right _ _) refine ⟨⌈1000 * Mp / κ ^ 3⌉₊ + 1000, fun n hn0 hn v hv hvi hT D hD hfat U hU1 hU2 => ?_⟩ have hnκ : 1000 * Mp / κ ^ 3 ≤ (n : ℝ) := by have := Nat.le_ceil (1000 * Mp / κ ^ 3) have h2 : ((⌈1000 * Mp / κ ^ 3⌉₊ : ℕ) : ℝ) ≤ n := by exact_mod_cast (show ⌈1000 * Mp / κ ^ 3⌉₊ ≤ n by omega) linarith obtain ⟨hκn, hX, hn11⟩ := wide_nfacts hκ0 hκ64 hMp8 hnκ exact @wide_core ζ₀ s MB CB CT N0 A κ ε τ hζ0 hζ1 hs hs0 hMB hMB0 hCB hCB0 hCT hCT42 hN0 hN00 hA hA0 hκ0 hκ64 hκMp hκ2 hτ hε0 hεκ hε100 n hn (by omega) hκn hX hn11 v hv hvi hT D hD hfat U hU1 hU2 end Erdos94ThmA /-! ### hL1 and hW discharged: the master outline from the two OPEN Props only -/ namespace Erdos94ThmA /-- **hW discharged**: the wide case (INVERSE Thm 11.24′ in the `WideThm` form used by `main_of_XE_needle`). -/ theorem wide_thm : ∀ ζ₀ > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm ζ₀ (1 / 10000) ε n₃ := wide_thm_of_circles wide_circles /-- **INVERSE Theorem 11.24′, unweakened** (no `S > R(n)`, any exception fraction `θ′ > 0`), as needed by the needle recursion (INVERSE §11.26). -/ theorem wide_thm0 : ∀ ζ₀ > 0, ∀ θ' > 0, ∃ ε₀ > 0, ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ n₃, WideThm0 ζ₀ θ' ε n₃ := wide0_of_circles wide_circles /-- **The master outline with only the two OPEN inputs** (`hL1 = link1_of_XE`, `hW = wide_thm` are now theorems): (XE^rich_0) and the needle case give `S(P) ≤ R(n)` for all large `n`; the task's `target` is then `Erdos94Infra.target_of_large_class N (fun n hn P h1 h2 _ => hN n hn P h1 h2)`. -/ theorem main_of_open_inputs (hXE : XErich) (hNeedle : ∃ ζ₀ > 0, ∃ ε₁ > 0, ∀ ε, 0 < ε → ε ≤ ε₁ → ∃ n₂, NeedleThm ζ₀ ε n₂) : ∃ N : ℕ, ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := main_of_XE_needle link1_of_XE wide_thm hXE hNeedle end Erdos94ThmA /-! ### LEAN-5 Q2: INVERSE Lemma 11.47 (bases of right-doubles; a unique left apex) and Cor. 11.47′ (needle concentration) -/ namespace Erdos94ThmA open Finset /-- A point equidistant from `y ≠ z` lies on the perpendicular bisector: `x = (y + z)/2 + s·I(z − y)`, `s` real. -/ theorem bis_param {x y z : ℂ} (hyz : y ≠ z) (h : dist x y = dist x z) : ∃ s : ℝ, x = (y + z) / 2 + (s : ℂ) * (Complex.I * (z - y)) := by have hD0 : (z.re - y.re) ^ 2 + (z.im - y.im) ^ 2 ≠ 0 := by intro h0 apply hyz have h1 : z.re - y.re = 0 := by nlinarith [sq_nonneg (z.re - y.re), sq_nonneg (z.im - y.im)] have h2 : z.im - y.im = 0 := by nlinarith [sq_nonneg (z.re - y.re), sq_nonneg (z.im - y.im)] exact Complex.ext (by linarith) (by linarith) have hsq : (x.re - y.re) ^ 2 + (x.im - y.im) ^ 2 = (x.re - z.re) ^ 2 + (x.im - z.im) ^ 2 := by rw [Complex.dist_eq_re_im, Complex.dist_eq_re_im] at h exact (Real.sqrt_inj (by positivity) (by positivity)).mp h obtain ⟨D, hD⟩ : ∃ D : ℝ, D = (z.re - y.re) ^ 2 + (z.im - y.im) ^ 2 := ⟨_, rfl⟩ have hD0' : D ≠ 0 := by rw [hD]; exact hD0 obtain ⟨s, hs⟩ : ∃ s : ℝ, s = ((x.im - (y.im + z.im) / 2) * (z.re - y.re) - (x.re - (y.re + z.re) / 2) * (z.im - y.im)) / D := ⟨_, rfl⟩ have hsD : s * D = (x.im - (y.im + z.im) / 2) * (z.re - y.re) - (x.re - (y.re + z.re) / 2) * (z.im - y.im) := by rw [hs]; field_simp have hre : x.re = (y.re + z.re) / 2 - s * (z.im - y.im) := by have key : (x.re - (y.re + z.re) / 2 + s * (z.im - y.im)) * D = 0 := by have e : (x.re - (y.re + z.re) / 2 + s * (z.im - y.im)) * D = (x.re - (y.re + z.re) / 2) * D + (s * D) * (z.im - y.im) := by ring rw [e, hsD, hD] linear_combination (z.re - y.re) / 2 * hsq have := (mul_eq_zero.mp key).resolve_right hD0' linarith have him : x.im = (y.im + z.im) / 2 + s * (z.re - y.re) := by have key : (x.im - (y.im + z.im) / 2 - s * (z.re - y.re)) * D = 0 := by have e : (x.im - (y.im + z.im) / 2 - s * (z.re - y.re)) * D = (x.im - (y.im + z.im) / 2) * D - (s * D) * (z.re - y.re) := by ring rw [e, hsD, hD] linear_combination (z.im - y.im) / 2 * hsq have := (mul_eq_zero.mp key).resolve_right hD0' linarith refine ⟨s, Complex.ext ?_ ?_⟩ · simp only [Complex.add_re, Complex.mul_re, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im, Complex.sub_re, Complex.sub_im, Complex.mul_im, Complex.div_ofNat_re] rw [hre]; ring · simp only [Complex.add_im, Complex.mul_re, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im, Complex.sub_re, Complex.sub_im, Complex.mul_im, Complex.div_ofNat_im] rw [him]; ring /-- Real and imaginary parts along the bisector. -/ theorem bis_re_im {y z : ℂ} (s : ℝ) : ((y + z) / 2 + (s : ℂ) * (Complex.I * (z - y))).re = (y.re + z.re) / 2 - s * (z.im - y.im) ∧ ((y + z) / 2 + (s : ℂ) * (Complex.I * (z - y))).im = (y.im + z.im) / 2 + s * (z.re - y.re) := by constructor · simp only [Complex.add_re, Complex.mul_re, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im, Complex.sub_re, Complex.sub_im, Complex.mul_im, Complex.div_ofNat_re] ring · simp only [Complex.add_im, Complex.mul_re, Complex.ofReal_re, Complex.ofReal_im, Complex.I_re, Complex.I_im, Complex.sub_re, Complex.sub_im, Complex.mul_im, Complex.div_ofNat_im] ring /-- **Unique left apex** (INVERSE Lemma 11.47, flagged step; AUDIT3 §127): in a convex-independent `P ⊂ ℂ`, at most one point of `P` on the perpendicular bisector of `y ≠ z` (`y, z ∈ P`) has abscissa `≤ min(Re y, Re z)`. -/ theorem left_apex_unique {P : Finset ℂ} (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) {y z x x' : ℂ} (hy : y ∈ P) (hz : z ∈ P) (hyz : y ≠ z) (hx : x ∈ P) (hx' : x' ∈ P) (h1 : dist x y = dist x z) (h2 : dist x' y = dist x' z) (hl1 : x.re ≤ y.re ∧ x.re ≤ z.re) (hl2 : x'.re ≤ y.re ∧ x'.re ≤ z.re) : x = x' := by obtain ⟨s, hs⟩ := bis_param hyz h1 obtain ⟨s', hs'⟩ := bis_param hyz h2 have hxre : x.re = (y.re + z.re) / 2 - s * (z.im - y.im) := by rw [hs]; exact (bis_re_im s).1 have hx're : x'.re = (y.re + z.re) / 2 - s' * (z.im - y.im) := by rw [hs']; exact (bis_re_im s').1 have hne_of : ∀ {a : ℂ}, dist a y = dist a z → a ≠ y ∧ a ≠ z := by intro a ha constructor · intro hay rw [hay, dist_self] at ha exact hyz (dist_eq_zero.mp ha.symm) · intro haz rw [haz, dist_self] at ha exact hyz (dist_eq_zero.mp ha).symm have hmem : ∀ {a b : ℂ}, b ∈ P → b ≠ a → b ∈ convexHull ℝ ((P : Set ℂ) \ {a}) := by intro a b hb hba exact subset_convexHull ℝ _ ((Set.mem_sdiff b).mpr ⟨hb, fun h => hba (Set.mem_singleton_iff.mp h)⟩) have hmid : ∀ {a : ℂ}, y ≠ a → z ≠ a → (1 / 2 : ℝ) • y + (1 / 2 : ℝ) • z ∈ convexHull ℝ ((P : Set ℂ) \ {a}) := by intro a hya hza exact (convex_convexHull ℝ _) (hmem hy hya) (hmem hz hza) (by norm_num) (by norm_num) (by norm_num) have hmid_eq : (1 / 2 : ℝ) • y + (1 / 2 : ℝ) • z = (y + z) / 2 := by rw [Complex.real_smul, Complex.real_smul]; push_cast; ring -- the bisector is not vertical have hw : z.im - y.im ≠ 0 := by intro h0 have hre : y.re ≠ z.re := fun h => hyz (Complex.ext h (by linarith)) have hx2 : x.re = (y.re + z.re) / 2 := by rw [hxre, h0]; ring rcases lt_or_gt_of_ne hre with h | h <;> linarith [hl1.1, hl1.2] -- s ≠ 0, s' ≠ 0: otherwise the apex is the midpoint have hs0 : s ≠ 0 := by intro h0 apply hP x hx have : x = (1 / 2 : ℝ) • y + (1 / 2 : ℝ) • z := by rw [hmid_eq, hs, h0]; push_cast; ring have hm := hmid (a := x) (hne_of h1).1.symm (hne_of h1).2.symm rw [← this] at hm exact hm have hs'0 : s' ≠ 0 := by intro h0 apply hP x' hx' have : x' = (1 / 2 : ℝ) • y + (1 / 2 : ℝ) • z := by rw [hmid_eq, hs', h0]; push_cast; ring have hm := hmid (a := x') (hne_of h2).1.symm (hne_of h2).2.symm rw [← this] at hm exact hm -- left of both ⇒ s and s' have the sign of Im(z − y) have hsw : 0 ≤ s * (z.im - y.im) := by linarith [hl1.1, hl1.2] have hsw' : 0 ≤ s' * (z.im - y.im) := by linarith [hl2.1, hl2.2] have hpos : 0 < s * s' := by rcases lt_or_gt_of_ne hw with hw' | hw' · have h3 : s < 0 := lt_of_le_of_ne (by nlinarith) hs0 have h4 : s' < 0 := lt_of_le_of_ne (by nlinarith) hs'0 nlinarith · have h3 : 0 < s := lt_of_le_of_ne (by nlinarith) (Ne.symm hs0) have h4 : 0 < s' := lt_of_le_of_ne (by nlinarith) (Ne.symm hs'0) nlinarith by_contra hne have hss : s ≠ s' := fun h => hne (by rw [hs, hs', h]) -- the nearer apex lies in the convex hull of y, z and the farther one have hin : ∀ {a a' : ℂ} {t t' : ℝ}, a ∈ P → a' ∈ P → a ≠ a' → dist a y = dist a z → a = (y + z) / 2 + (t : ℂ) * (Complex.I * (z - y)) → a' = (y + z) / 2 + (t' : ℂ) * (Complex.I * (z - y)) → t' ≠ 0 → 0 < t * t' → t * t < t' * t' → False := by intro a a' t t' ha ha' haa' hda hta hta' ht'0 htt hlt apply hP a ha have hl0 : 0 < t / t' := by have : t / t' = (t * t') / (t' * t') := by field_simp rw [this] exact div_pos htt (mul_self_pos.mpr ht'0) have hl1' : t / t' < 1 := by have : t / t' = (t * t') / (t' * t') := by field_simp rw [this, div_lt_one (mul_self_pos.mpr ht'0)] nlinarith have hrepr : a = (1 - t / t') • ((1 / 2 : ℝ) • y + (1 / 2 : ℝ) • z) + (t / t') • a' := by rw [hmid_eq, hta, hta', Complex.real_smul, Complex.real_smul] have ht' : (t' : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr ht'0 push_cast field_simp ring have hm := (convex_convexHull ℝ ((P : Set ℂ) \ {a})) (hmid (a := a) (hne_of hda).1.symm (hne_of hda).2.symm) (hmem (a := a) ha' (Ne.symm haa')) (by linarith : (0 : ℝ) ≤ 1 - t / t') hl0.le (by ring) rw [← hrepr] at hm exact hm rcases lt_trichotomy (s * s) (s' * s') with hlt | heq | hgt · exact hin hx hx' hne h1 hs hs' hs'0 hpos hlt · apply hss have : (s - s') * (s + s') = 0 := by linarith rcases mul_eq_zero.mp this with h | h · linarith · nlinarith · exact hin hx' hx (Ne.symm hne) h2 hs' hs hs0 (by linarith) hgt /-- A left apex in a horizontal strip of height `h`: `(Re y − Re z)² ≤ 2h·|Im y − Im z|` (INVERSE Lemma 11.47). -/ theorem left_apex_strip {x y z : ℂ} (hyz : y ≠ z) (h1 : dist x y = dist x z) (hl : x.re ≤ y.re ∧ x.re ≤ z.re) {b h : ℝ} (hx : b ≤ x.im ∧ x.im ≤ b + h) (hy : b ≤ y.im ∧ y.im ≤ b + h) (hz : b ≤ z.im ∧ z.im ≤ b + h) : (y.re - z.re) ^ 2 ≤ 2 * h * |y.im - z.im| := by obtain ⟨s, hs⟩ := bis_param hyz h1 have hxre : x.re = (y.re + z.re) / 2 - s * (z.im - y.im) := by rw [hs]; exact (bis_re_im s).1 have hxim : x.im = (y.im + z.im) / 2 + s * (z.re - y.re) := by rw [hs]; exact (bis_re_im s).2 -- A := m_re − x_re ≥ |Δre|/2 ≥ 0, and A·Δre = (x_im − m_im)·Δim obtain ⟨A, hA⟩ : ∃ A : ℝ, A = (y.re + z.re) / 2 - x.re := ⟨_, rfl⟩ obtain ⟨C, hC⟩ : ∃ C : ℝ, C = x.im - (y.im + z.im) / 2 := ⟨_, rfl⟩ have hAC : A * (z.re - y.re) = C * (z.im - y.im) := by rw [hA, hC, hxre, hxim]; ring have hA2 : |z.re - y.re| ≤ 2 * A := by rw [abs_le]; constructor <;> linarith [hl.1, hl.2] have hC1 : |C| ≤ h := by rw [hC, abs_le]; constructor <;> linarith [hx.1, hx.2, hy.1, hy.2, hz.1, hz.2] have hA0 : 0 ≤ A := by have := abs_nonneg (z.re - y.re); linarith have key : (z.re - y.re) ^ 2 ≤ 2 * (A * |z.re - y.re|) := by have : (z.re - y.re) ^ 2 = |z.re - y.re| * |z.re - y.re| := by rw [← sq, sq_abs] rw [this] have := mul_le_mul_of_nonneg_right hA2 (abs_nonneg (z.re - y.re)) linarith have key2 : A * |z.re - y.re| = |C| * |z.im - y.im| := by rw [← abs_of_nonneg hA0, ← abs_mul, ← abs_mul, hAC] have key3 : |C| * |z.im - y.im| ≤ h * |z.im - y.im| := mul_le_mul_of_nonneg_right hC1 (abs_nonneg _) have e1 : (y.re - z.re) ^ 2 = (z.re - y.re) ^ 2 := by ring have e2 : |y.im - z.im| = |z.im - y.im| := abs_sub_comm _ _ rw [e1, e2] linarith /-- `2(a − 1)⁺ ≤ a(a − 1)` in `ℕ`. -/ theorem two_pred_le (a : ℕ) : 2 * (a - 1) ≤ a * (a - 1) := by rcases Nat.lt_or_ge a 2 with h | h · interval_cases a <;> simp · exact Nat.mul_le_mul_right _ h open Classical in /-- `a_u(x)(a_u(x) − 1)` = the ordered pairs of distinct later `u`-partners of `x`. -/ theorem lat_pairs {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (u : ℝ) (x : X) : lat P rk u x * (lat P rk u x - 1) = (P.offDiag.filter (fun p => (rk x < rk p.1 ∧ dist x p.1 = u) ∧ (rk x < rk p.2 ∧ dist x p.2 = u))).card := by unfold lat rw [Nat.mul_sub_one, ← offDiag_card] congr 1 ext p simp only [mem_offDiag, mem_filter] tauto open Classical in /-- **INVERSE Lemma 11.47 (bases of right-doubles)** [audited INV4-A2, AUDIT3 §127]. `P ⊂ ℂ` convex independent in the strip `b ≤ Im ≤ b + h`, totally ordered by a ranking `rk` (injective on `P`) that refines the abscissa (`Re x < Re y ⇒ rk x < rk y`; ties allowed). Then for every finite set `W` of classes `2·Σ_{u∈W} E_u ≤ #{(y, z) ∈ P° : (Re y − Re z)² ≤ 2h|Im y − Im z|}` — the paper's `Σ_u E_u ≤ N_□` in ordered pairs. The proof: `2(a − 1)⁺ ≤ a(a − 1)`, and an ordered pair of distinct right `u`-partners of `x` determines `x` (unique left apex, `left_apex_unique`) and `u = |xy|`, and lies in `N_□` (`left_apex_strip`). -/ theorem lemma1147 {P : Finset ℂ} (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) (rk : ℂ → ℕ) (hord : ∀ x ∈ P, ∀ y ∈ P, x.re < y.re → rk x < rk y) {b h : ℝ} (hstrip : ∀ x ∈ P, b ≤ x.im ∧ x.im ≤ b + h) (W : Finset ℝ) : 2 * ∑ u ∈ W, latE P rk u ≤ (P.offDiag.filter (fun p => (p.1.re - p.2.re) ^ 2 ≤ 2 * h * |p.1.im - p.2.im|)).card := by have hleft : ∀ x ∈ P, ∀ y ∈ P, rk x < rk y → x.re ≤ y.re := by intro x hx y hy hxy by_contra hc push_neg at hc have := hord y hy x hx hc omega -- the triples (u, x, (y, z)) obtain ⟨T, hT⟩ : ∃ T : Finset ((ℝ × ℂ) × (ℂ × ℂ)), T = ((W ×ˢ P) ×ˢ P.offDiag).filter (fun q => (rk q.1.2 < rk q.2.1 ∧ dist q.1.2 q.2.1 = q.1.1) ∧ (rk q.1.2 < rk q.2.2 ∧ dist q.1.2 q.2.2 = q.1.1)) := ⟨_, rfl⟩ have hTsum : ∑ u ∈ W, ∑ x ∈ P, lat P rk u x * (lat P rk u x - 1) = T.card := by rw [hT, card_filter, sum_product, sum_product] refine sum_congr rfl (fun u _ => sum_congr rfl (fun x _ => ?_)) rw [lat_pairs, card_filter] have hTle : T.card ≤ (P.offDiag.filter (fun p => (p.1.re - p.2.re) ^ 2 ≤ 2 * h * |p.1.im - p.2.im|)).card := by refine card_le_card_of_injOn (fun q => q.2) ?_ ?_ · intro q hq rw [hT, mem_coe, mem_filter, mem_product, mem_product] at hq obtain ⟨⟨⟨_, hx⟩, hyz⟩, ⟨h1, h2⟩, ⟨h3, h4⟩⟩ := hq have hyz' := mem_offDiag.mp hyz refine mem_filter.mpr ⟨hyz, ?_⟩ exact left_apex_strip hyz'.2.2 (h2.trans h4.symm) ⟨hleft _ hx _ hyz'.1 h1, hleft _ hx _ hyz'.2.1 h3⟩ (hstrip _ hx) (hstrip _ hyz'.1) (hstrip _ hyz'.2.1) · intro q hq q' hq' hqq rw [hT, mem_coe, mem_filter, mem_product, mem_product] at hq hq' obtain ⟨⟨⟨_, hx⟩, hyz⟩, ⟨h1, h2⟩, ⟨h3, h4⟩⟩ := hq obtain ⟨⟨⟨_, hx'⟩, hyz''⟩, ⟨h1', h2'⟩, ⟨h3', h4'⟩⟩ := hq' have hqq' : q.2 = q'.2 := hqq have hyz' := mem_offDiag.mp hyz have hxx : q.1.2 = q'.1.2 := by rw [← hqq'] at h2' h4' h1' h3' exact left_apex_unique hP hyz'.1 hyz'.2.1 hyz'.2.2 hx hx' (h2.trans h4.symm) (h2'.trans h4'.symm) ⟨hleft _ hx _ hyz'.1 h1, hleft _ hx _ hyz'.2.1 h3⟩ ⟨hleft _ hx' _ hyz'.1 h1', hleft _ hx' _ hyz'.2.1 h3'⟩ have huu : q.1.1 = q'.1.1 := by rw [← h2, ← h2', hxx, hqq'] exact Prod.ext (Prod.ext huu hxx) hqq' have hE : 2 * ∑ u ∈ W, latE P rk u ≤ ∑ u ∈ W, ∑ x ∈ P, lat P rk u x * (lat P rk u x - 1) := by rw [mul_sum] refine sum_le_sum (fun u _ => ?_) unfold latE rw [mul_sum] exact sum_le_sum (fun x _ => two_pred_le _) rw [hTsum] at hE exact le_trans hE hTle /-- `E_u ≤ f(u)` (`(a − 1)⁺ ≤ a`). -/ theorem latE_le_mult {X : Type*} [MetricSpace X] (P : Finset X) (rk : X → ℕ) (hrk : Set.InjOn rk P) (u : ℝ) : latE P rk u ≤ distanceMultiplicity P u := by rw [mult_eq_sum_lat P rk hrk u] unfold latE exact sum_le_sum (fun x _ => Nat.sub_le _ _) /-- The lexicographic `(Re, Im)` order on `ℂ`. -/ def lexC (a b : ℂ) : Prop := a.re < b.re ∨ (a.re = b.re ∧ a.im < b.im) theorem lexC_trans {a b c : ℂ} (h1 : lexC a b) (h2 : lexC b c) : lexC a c := by unfold lexC at * rcases h1 with h1 | ⟨h1, h1'⟩ <;> rcases h2 with h2 | ⟨h2, h2'⟩ · left; linarith · left; linarith · left; linarith · right; exact ⟨h1.trans h2, h1'.trans h2'⟩ theorem lexC_irrefl (a : ℂ) : ¬ lexC a a := by unfold lexC rintro (h | ⟨_, h⟩) <;> exact lt_irrefl _ h theorem lexC_total {a b : ℂ} (h : a ≠ b) : lexC a b ∨ lexC b a := by unfold lexC rcases lt_trichotomy a.re b.re with h1 | h1 | h1 · left; left; exact h1 · rcases lt_trichotomy a.im b.im with h2 | h2 | h2 · left; right; exact ⟨h1, h2⟩ · exact absurd (Complex.ext h1 h2) h · right; right; exact ⟨h1.symm, h2⟩ · right; left; exact h1 open Classical in /-- The abscissa ranking: `rk x = #{y ∈ P : y <_lex x}`; injective on `P` and refining the abscissa. -/ noncomputable def reRank (P : Finset ℂ) (x : ℂ) : ℕ := (P.filter (fun y => lexC y x)).card open Classical in theorem reRank_lt {P : Finset ℂ} {x y : ℂ} (hx : x ∈ P) (h : lexC x y) : reRank P x < reRank P y := by unfold reRank apply card_lt_card refine ⟨fun w hw => ?_, fun hsub => ?_⟩ · rw [mem_filter] at hw ⊢ exact ⟨hw.1, lexC_trans hw.2 h⟩ · have := hsub (mem_filter.mpr ⟨hx, h⟩) rw [mem_filter] at this exact lexC_irrefl _ this.2 theorem reRank_inj (P : Finset ℂ) : Set.InjOn (reRank P) P := by intro x hx y hy h by_contra hne rcases lexC_total hne with h1 | h1 · have := reRank_lt hx h1; omega · have := reRank_lt hy h1; omega theorem reRank_ord (P : Finset ℂ) : ∀ x ∈ P, ∀ y ∈ P, x.re < y.re → reRank P x < reRank P y := fun x hx _ _ h => reRank_lt hx (Or.inl h) /-- Arithmetic of Cor. 11.47′. -/ theorem cor1147_arith {n N sE S F ε : ℝ} (hn : 1 ≤ n) (hε0 : 0 < ε) (hε1 : ε ≤ 1) (hEN : sE ≤ N) (hS : S ≤ n * (n - 1) * (2 * n - 1) / 6 + 2 * F) (hF : F ≤ (1 + ε) * n * sE + (1 + ε) * ε * n ^ 3) (hR : n ^ 2 * (n - 1) / 2 - n ^ 2 / 4 < S) : (1 / 12 - 13 * ε / 12) * n ^ 2 - n / 2 ≤ N := by have hn0 : 0 < n := by linarith have h1 : n ^ 3 / 6 - n ^ 2 / 4 - n / 6 - 2 * (1 + ε) * ε * n ^ 3 < 2 * (1 + ε) * n * N := by have : (1 + ε) * n * sE ≤ (1 + ε) * n * N := mul_le_mul_of_nonneg_left hEN (by positivity) nlinarith have h2 : n ^ 2 / 6 - n / 4 - 1 / 6 - 2 * (1 + ε) * ε * n ^ 2 < 2 * (1 + ε) * N := by have e : n ^ 3 / 6 - n ^ 2 / 4 - n / 6 - 2 * (1 + ε) * ε * n ^ 3 = n * (n ^ 2 / 6 - n / 4 - 1 / 6 - 2 * (1 + ε) * ε * n ^ 2) := by ring rw [e, show 2 * (1 + ε) * n * N = n * (2 * (1 + ε) * N) by ring] at h1 exact lt_of_mul_lt_mul_left h1 hn0.le have h3 : 2 * (1 + ε) * ((1 / 12 - 13 * ε / 12) * n ^ 2 - n / 2) ≤ n ^ 2 / 6 - n / 4 - 1 / 6 - 2 * (1 + ε) * ε * n ^ 2 := by nlinarith [sq_nonneg (ε * n)] have h4 : 2 * (1 + ε) * ((1 / 12 - 13 * ε / 12) * n ^ 2 - n / 2) ≤ 2 * (1 + ε) * N := by linarith exact le_of_mul_le_mul_left h4 (by positivity) open Classical in /-- **INVERSE Corollary 11.47′ (needle concentration with ANY tips)** [audited INV4-A2; constant as re-derived in AUDIT3 §127]. `P ⊂ ℂ` convex independent, `n = |P|`, in a horizontal strip `b ≤ Im ≤ b + h`, with `S(P) > R(n)` and `D⁺(P) = Σ_u f(u)(f(u) − n)⁺ ≤ ε²n³` (`0 < ε ≤ 1`) ⇒ `N_□ ≥ (1/12 − 13ε/12)n² − n/2`, where `N_□` = unordered pairs `{y, z}` with `(Re y − Re z)² ≤ 2h|Im y − Im z|` (= half the ordered ones). No (NF), no tip hypothesis. -/ theorem cor1147 {P : Finset ℂ} (hP : ∀ a ∈ P, a ∉ convexHull ℝ ((P : Set ℂ) \ {a})) {b h : ℝ} (hstrip : ∀ x ∈ P, b ≤ x.im ∧ x.im ≤ b + h) {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε ≤ 1) (hSR : Erdos94Infra.ngonValue P.card < ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2) (hD : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - P.card) 0 ≤ ε ^ 2 * (P.card : ℝ) ^ 3) : (1 / 12 - 13 * ε / 12) * (P.card : ℝ) ^ 2 - P.card / 2 ≤ ((P.offDiag.filter (fun p => (p.1.re - p.2.re) ^ 2 ≤ 2 * h * |p.1.im - p.2.im|)).card : ℝ) / 2 := by rcases Nat.eq_zero_or_pos P.card with h0 | hpos · rw [h0]; push_cast have : (0 : ℝ) ≤ ((P.offDiag.filter (fun p => (p.1.re - p.2.re) ^ 2 ≤ 2 * h * |p.1.im - p.2.im|)).card : ℝ) / 2 := by positivity nlinarith have hn : (1 : ℝ) ≤ P.card := by exact_mod_cast hpos obtain ⟨n, hn'⟩ : ∃ n : ℝ, n = P.card := ⟨_, rfl⟩ rw [← hn'] at hn hD ⊢ have hrk := reRank_inj P have h36 := thm1136 P (reRank P) hrk (distanceSet P) have h47 := lemma1147 hP (reRank P) (reRank_ord P) hstrip (distanceSet P) -- split Σ f E have hF : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) * (latE P (reRank P) u : ℝ) ≤ (1 + ε) * n * ∑ u ∈ distanceSet P, (latE P (reRank P) u : ℝ) + (1 + ε) * ε * n ^ 3 := by have hper : ∀ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) * (latE P (reRank P) u : ℝ) ≤ (1 + ε) * n * (latE P (reRank P) u : ℝ) + (1 + ε) / ε * ((distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - n) 0) := by intro u _ have hE0 : (0 : ℝ) ≤ latE P (reRank P) u := Nat.cast_nonneg _ have hEf : (latE P (reRank P) u : ℝ) ≤ distanceMultiplicity P u := by exact_mod_cast latE_le_mult P (reRank P) hrk u have hf0 : (0 : ℝ) ≤ distanceMultiplicity P u := Nat.cast_nonneg _ have hm0 : 0 ≤ (1 + ε) / ε * ((distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - n) 0) := mul_nonneg (by positivity) (mul_nonneg hf0 (le_max_right _ _)) rcases le_or_gt (distanceMultiplicity P u : ℝ) ((1 + ε) * n) with hle | hlt · have := mul_le_mul_of_nonneg_right hle hE0 linarith · have hmax : max ((distanceMultiplicity P u : ℝ) - n) 0 = (distanceMultiplicity P u : ℝ) - n := max_eq_left (by nlinarith) rw [hmax] have h1 : (distanceMultiplicity P u : ℝ) * (latE P (reRank P) u : ℝ) ≤ (distanceMultiplicity P u : ℝ) * (distanceMultiplicity P u : ℝ) := mul_le_mul_of_nonneg_left hEf hf0 have h2 : (distanceMultiplicity P u : ℝ) * (distanceMultiplicity P u : ℝ) ≤ (1 + ε) / ε * ((distanceMultiplicity P u : ℝ) * ((distanceMultiplicity P u : ℝ) - n)) := by rw [div_mul_eq_mul_div, le_div_iff₀ hε0] have : ε * (distanceMultiplicity P u : ℝ) ≤ (1 + ε) * ((distanceMultiplicity P u : ℝ) - n) := by nlinarith nlinarith have h3 : 0 ≤ (1 + ε) * n * (latE P (reRank P) u : ℝ) := by positivity linarith have hsum := sum_le_sum hper rw [sum_add_distrib, ← mul_sum, ← mul_sum] at hsum have hD' : (1 + ε) / ε * ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) * max ((distanceMultiplicity P u : ℝ) - n) 0 ≤ (1 + ε) * ε * n ^ 3 := by have := mul_le_mul_of_nonneg_left hD (by positivity : (0 : ℝ) ≤ (1 + ε) / ε) have e : (1 + ε) / ε * (ε ^ 2 * n ^ 3) = (1 + ε) * ε * n ^ 3 := by field_simp linarith linarith have hEs : ∑ u ∈ distanceSet P, (latE P (reRank P) u : ℝ) ≤ ((P.offDiag.filter (fun p => (p.1.re - p.2.re) ^ 2 ≤ 2 * h * |p.1.im - p.2.im|)).card : ℝ) / 2 := by have : (2 * ∑ u ∈ distanceSet P, latE P (reRank P) u : ℕ) ≤ (P.offDiag.filter (fun p => (p.1.re - p.2.re) ^ 2 ≤ 2 * h * |p.1.im - p.2.im|)).card := h47 have h' : 2 * ∑ u ∈ distanceSet P, (latE P (reRank P) u : ℝ) ≤ ((P.offDiag.filter (fun p => (p.1.re - p.2.re) ^ 2 ≤ 2 * h * |p.1.im - p.2.im|)).card : ℝ) := by exact_mod_cast this linarith have hR := ngonValue_ge P.card rw [← hn'] at hR h36 exact cor1147_arith hn hε0 hε1 hEs h36 hF (lt_of_le_of_lt hR hSR) end Erdos94ThmA /-! ### GLIDE Lemma 12.5 + Remark 13.3: the quarter-turn partition (≤ 4 arcs), the third hit, the class counts, and the arc-pair interface for `XErich` -/ namespace Erdos94ThmA open Finset /-- Dropping the empty blocks of a partition indexed by `Fin t`: the remaining blocks are re-indexed by `Fin s`, `s ≤ t`. -/ theorem compress_blocks {α : Type*} {t : ℕ} (B : Fin t → Finset α) (Q : Finset α → Prop) (hcov : ∀ x, ∃ i, x ∈ B i) (hdisj : ∀ i j, i ≠ j → Disjoint (B i) (B j)) (hQ : ∀ i, (B i).Nonempty → Q (B i)) : ∃ s : ℕ, s ≤ t ∧ ∃ A : Fin s → Finset α, (∀ x, ∃ i, x ∈ A i) ∧ (∀ i j, i ≠ j → Disjoint (A i) (A j)) ∧ (∀ i, Q (A i)) := by classical obtain ⟨K, hK⟩ : ∃ K : Finset (Fin t), K = univ.filter (fun i => (B i).Nonempty) := ⟨_, rfl⟩ refine ⟨K.card, ?_, fun i => B (K.equivFin.symm i).1, ?_, ?_, ?_⟩ · calc K.card ≤ (univ : Finset (Fin t)).card := card_le_card (by rw [hK]; exact filter_subset _ _) _ = t := by rw [card_univ, Fintype.card_fin] · intro x obtain ⟨i, hi⟩ := hcov x have hiK : i ∈ K := by rw [hK, mem_filter]; exact ⟨mem_univ _, ⟨x, hi⟩⟩ refine ⟨K.equivFin ⟨i, hiK⟩, ?_⟩ simp only [Equiv.symm_apply_apply] exact hi · intro i j hij apply hdisj intro h apply hij have : K.equivFin.symm i = K.equivFin.symm j := Subtype.ext h exact K.equivFin.symm.injective this · have hKmem : ∀ k ∈ K, (B k).Nonempty := by intro k hk rw [hK, mem_filter] at hk exact hk.2 intro i exact hQ _ (hKmem _ (K.equivFin.symm i).2) /-- The cumulative turning `T(i) = τ(0, i)` of a counterclockwise polygon is `< 2π` for `0 ≤ i < n`. -/ theorem turning_zero_lt {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) {i : ℕ} (hi : i < n) : turning v 0 i < 2 * Real.pi := by have hL := ccw_leftTurns hn hv have htot := turning_total_eq hn hv have hfull := turning_full v 0 rw [htot] at hfull have hs := turning_succ v 0 (n - 1) rw [show n - 1 + 1 = n by omega, hfull] at hs have hpos := extAng_pos hL ((0 : ZMod n) + ((n - 1 : ℕ) : ZMod n)) have hmono := turning_mono hL 0 (show i ≤ n - 1 by omega) linarith open Classical in /-- The `k`-th quadrant class of labels `0 ≤ i < n`: `kπ/2 ≤ τ(0, i) < (k + 1)π/2`. -/ noncomputable def qtCls {n : ℕ} (v : ZMod n → ℂ) (k : ℕ) : Finset ℕ := (range n).filter (fun i => (k : ℝ) * (Real.pi / 2) ≤ turning v 0 i ∧ turning v 0 i < ((k : ℝ) + 1) * (Real.pi / 2)) theorem qtCls_mem {n : ℕ} {v : ZMod n → ℂ} {k i : ℕ} : i ∈ qtCls v k ↔ i < n ∧ (k : ℝ) * (Real.pi / 2) ≤ turning v 0 i ∧ turning v 0 i < ((k : ℝ) + 1) * (Real.pi / 2) := by unfold qtCls rw [mem_filter, mem_range] /-- A nonempty quadrant class is a quarter-turn arc (it is an interval of labels, by monotonicity of `τ(0, ·)`). -/ theorem qtCls_qtarc {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (k : ℕ) (hne : (qtCls v k).Nonempty) : QTArc v ((qtCls v k).image (fun i : ℕ => (i : ZMod n))) := by have hL := ccw_leftTurns hn hv obtain ⟨p, hp⟩ : ∃ p, p = (qtCls v k).min' hne := ⟨_, rfl⟩ obtain ⟨q, hq⟩ : ∃ q, q = (qtCls v k).max' hne := ⟨_, rfl⟩ have hpm : p ∈ qtCls v k := by rw [hp]; exact min'_mem _ _ have hqm : q ∈ qtCls v k := by rw [hq]; exact max'_mem _ _ have hpq : p ≤ q := by rw [hp, hq]; exact min'_le _ _ (max'_mem _ _) have hpM := qtCls_mem.mp hpm have hqM := qtCls_mem.mp hqm refine ⟨(p : ZMod n), q - p, by omega, ?_, ?_⟩ · ext y rw [mem_image, mem_image] constructor · rintro ⟨j, hj, rfl⟩ have hpj : p ≤ j := by rw [hp]; exact min'_le _ _ hj have hjq : j ≤ q := by rw [hq]; exact le_max' _ _ hj refine ⟨j - p, mem_range.mpr (by omega), ?_⟩ rw [← Nat.cast_add, Nat.add_sub_cancel' hpj] · rintro ⟨i, hi, rfl⟩ rw [mem_range] at hi refine ⟨p + i, ?_, by push_cast; ring⟩ rw [qtCls_mem] refine ⟨by omega, ?_, ?_⟩ · linarith [turning_mono hL 0 (show p ≤ p + i by omega), hpM.2.1] · linarith [turning_mono hL 0 (show p + i ≤ q by omega), hqM.2.2] · have hs := turning_split v 0 p (q - p - 1) rw [zero_add] at hs have hmono := turning_mono hL 0 (show p + (q - p - 1) ≤ q by omega) have h1 := hpM.2.1 have h2 := hqM.2.2 have e : ((k : ℝ) + 1) * (Real.pi / 2) = (k : ℝ) * (Real.pi / 2) + Real.pi / 2 := by ring linarith /-- Every label lies in one of the four quadrant classes. -/ theorem qtCls_cover {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) (x : ZMod n) : ∃ k, k < 4 ∧ x ∈ (qtCls v k).image (fun i : ℕ => (i : ZMod n)) := by have hL := ccw_leftTurns hn hv have hx := ZMod.val_lt x have hT0 := turning_nonneg hL 0 x.val have hT1 := turning_zero_lt hn hv hx have hmem : ∀ k : ℕ, (k : ℝ) * (Real.pi / 2) ≤ turning v 0 x.val → turning v 0 x.val < ((k : ℝ) + 1) * (Real.pi / 2) → x ∈ (qtCls v k).image (fun i : ℕ => (i : ZMod n)) := by intro k h1 h2 exact mem_image.mpr ⟨x.val, qtCls_mem.mpr ⟨hx, h1, h2⟩, ZMod.natCast_zmod_val x⟩ have hpi := Real.pi_pos by_cases h1 : turning v 0 x.val < Real.pi / 2 · exact ⟨0, by norm_num, hmem 0 (by push_cast; linarith) (by push_cast; linarith)⟩ by_cases h2 : turning v 0 x.val < Real.pi · exact ⟨1, by norm_num, hmem 1 (by push_cast; linarith) (by push_cast; linarith)⟩ by_cases h3 : turning v 0 x.val < 3 * (Real.pi / 2) · exact ⟨2, by norm_num, hmem 2 (by push_cast; linarith) (by push_cast; linarith)⟩ · exact ⟨3, by norm_num, hmem 3 (by push_cast; linarith) (by push_cast; linarith)⟩ /-- Distinct quadrant classes are disjoint (as sets of labels in `ZMod n`). -/ theorem qtCls_disj {n : ℕ} {v : ZMod n → ℂ} {k k' : ℕ} (hkk : k ≠ k') : Disjoint ((qtCls v k).image (fun i : ℕ => (i : ZMod n))) ((qtCls v k').image (fun i : ℕ => (i : ZMod n))) := by rw [disjoint_left] intro y hy hy' rw [mem_image] at hy hy' obtain ⟨i, hi, rfl⟩ := hy obtain ⟨i', hi', he⟩ := hy' rw [qtCls_mem] at hi hi' have hii : i' = i := by have h1 := congrArg ZMod.val he rw [ZMod.val_natCast, ZMod.val_natCast, Nat.mod_eq_of_lt hi.1, Nat.mod_eq_of_lt hi'.1] at h1 exact h1 rw [hii] at hi' have hpi : (0 : ℝ) ≤ Real.pi / 2 := by linarith [Real.pi_pos] rcases Nat.lt_or_gt_of_ne hkk with h | h · have h' : (k : ℝ) + 1 ≤ k' := by exact_mod_cast h have := mul_le_mul_of_nonneg_right h' hpi linarith [hi.2.2, hi'.2.1] · have h' : (k' : ℝ) + 1 ≤ k := by exact_mod_cast h have := mul_le_mul_of_nonneg_right h' hpi linarith [hi.2.1, hi'.2.2] /-- **GLIDE Lemma 12.5, the partition.** Every counterclockwise strictly convex `n`-gon (`n ≥ 3`) has a partition of its labels into `s ≤ 4` quarter-turn arcs (consecutive labels whose interior exterior angles sum to `< π/2`): the classes of `⌊τ(0, i)/(π/2)⌋ ∈ {0, 1, 2, 3}`, empty classes dropped (total turning `2π`, `turning_total_eq`). -/ theorem qt_partition {n : ℕ} [NeZero n] (hn : 3 ≤ n) {v : ZMod n → ℂ} (hv : CCWPoly v) : ∃ s : ℕ, s ≤ 4 ∧ ∃ A : Fin s → Finset (ZMod n), (∀ x, ∃ i, x ∈ A i) ∧ (∀ i j, i ≠ j → Disjoint (A i) (A j)) ∧ (∀ i, QTArc v (A i)) := by apply compress_blocks (fun k : Fin 4 => (qtCls v k.val).image (fun i : ℕ => (i : ZMod n))) (QTArc v) · intro x obtain ⟨k, hk, hx⟩ := qtCls_cover hn hv x exact ⟨⟨k, hk⟩, hx⟩ · intro i j hij exact qtCls_disj (fun h => hij (Fin.ext h)) · intro i hne apply qtCls_qtarc hn hv obtain ⟨y, hy⟩ := hne obtain ⟨j, hj, _⟩ := mem_image.mp hy exact ⟨j, hj⟩ /-- **The arc-pair interface of (XE^rich_0).** To prove `XErich` it suffices to bound the rich cross energy `S^rich(A, B)` of every ordered pair of DISJOINT quarter-turn arcs of every large counterexample: the partition clause of `XErich` (`s ≤ 5`, covering, pairwise disjoint, `QTArc`) is supplied by `qt_partition`. -/ theorem xerich_of_arcs (h : ∀ ε > 0, ∃ n₁ : ℕ, ∀ n ≥ n₁, ∀ hn : NeZero n, ∀ v : ZMod n → ℂ, 3 ≤ n → CCWPoly v → Function.Injective v → Erdos94Infra.ngonValue n < ∑ u ∈ distanceSet ((@Finset.univ (ZMod n) (@ZMod.fintype n hn)).image v), (distanceMultiplicity ((@Finset.univ (ZMod n) (@ZMod.fintype n hn)).image v) u : ℝ) ^ 2 → ∀ Ai Aj : Finset (ZMod n), QTArc v Ai → QTArc v Aj → Disjoint Ai Aj → (@Srich n hn v Ai Aj : ℝ) ≤ ε * (n : ℝ) ^ 3) : XErich := by intro ε hε obtain ⟨n₁, hn₁⟩ := h ε hε refine ⟨n₁, fun n hn hNZ v h3 hv hinj hS => ?_⟩ obtain ⟨s, hs, A, hcov, hdisj, hqt⟩ := @qt_partition n hNZ h3 v hv exact ⟨s, by omega, A, hcov, hdisj, hqt, fun i j hij => hn₁ n hn hNZ v h3 hv hinj hS (A i) (A j) (hqt i) (hqt j) (hdisj i j hij)⟩ open Classical in /-- **GLIDE Lemma 12.5(i) (the third hit is long).** If `m_u(x) ≥ 3` and `x` lies in a quarter-turn arc `A`, then `x` has a `u`-partner outside `A` (inside `A` it sees `u` at most twice, `qtarc_le_two`). -/ theorem third_hit {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {A : Finset (ZMod n)} (hA : QTArc v A) {x : ZMod n} (hx : x ∈ A) {u : ℝ} (h3 : 3 ≤ mUv v x u) : ∃ y, y ∉ A ∧ y ≠ x ∧ dist (v x) (v y) = u := by by_contra hno push_neg at hno have hsub : univ.filter (fun y => y ≠ x ∧ dist (v x) (v y) = u) ⊆ A.filter (fun y => y ≠ x ∧ dist (v x) (v y) = u) := by intro y hy rw [mem_filter] at hy ⊢ refine ⟨?_, hy.2⟩ by_contra hyA exact hno y hyA hy.2.1 hy.2.2 have h2 := qtarc_le_two hv hA hx u have hc := card_le_card hsub unfold mUv at h3 omega open Classical in /-- Rich vertices are counted by the cross terms: `#{x : m_u(x) ≥ 3} ≤ Σ_{i≠j} R_ij(u)` (each rich `x` has a partner in another arc, by `third_hit`). -/ theorem rich_le_sumR {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {s : ℕ} (A : Fin s → Finset (ZMod n)) (hcov : ∀ x, ∃ i, x ∈ A i) (hqt : ∀ i, QTArc v (A i)) (u : ℝ) : (univ.filter (fun x => 3 ≤ mUv v x u)).card ≤ ∑ ij ∈ (univ : Finset (Fin s)).offDiag, Rrich v (A ij.1) (A ij.2) u := by obtain ⟨Rs, hRs⟩ : ∃ S : Finset (ZMod n × ZMod n), S = (univ : Finset (Fin s)).offDiag.biUnion (fun ij => (A ij.1 ×ˢ A ij.2).filter (fun p => dist (v p.1) (v p.2) = u ∧ 3 ≤ mUv v p.1 u)) := ⟨_, rfl⟩ have hsub : univ.filter (fun x => 3 ≤ mUv v x u) ⊆ Rs.image Prod.fst := by intro x hx rw [mem_filter] at hx obtain ⟨i, hi⟩ := hcov x obtain ⟨y, hyA, _, hd⟩ := third_hit hv (hqt i) hi hx.2 obtain ⟨j, hj⟩ := hcov y have hij : i ≠ j := fun e => hyA (e ▸ hj) rw [mem_image] refine ⟨(x, y), ?_, rfl⟩ rw [hRs, mem_biUnion] exact ⟨(i, j), mem_offDiag.mpr ⟨mem_univ _, mem_univ _, hij⟩, mem_filter.mpr ⟨mem_product.mpr ⟨hi, hj⟩, hd, hx.2⟩⟩ calc (univ.filter (fun x => 3 ≤ mUv v x u)).card ≤ (Rs.image Prod.fst).card := card_le_card hsub _ ≤ Rs.card := card_image_le _ ≤ _ := by rw [hRs]; exact card_biUnion_le theorem offDiag_fin_card_le {s : ℕ} (hs : s ≤ 5) : (((univ : Finset (Fin s)).offDiag.card : ℕ) : ℝ) ≤ 20 := by rw [offDiag_card, card_univ, Fintype.card_fin] have h1 : s * s - s ≤ 20 := by interval_cases s <;> norm_num exact_mod_cast h1 /-- `Σ_u Σ_{i≠j} R_ij(u)² = Σ_{i≠j} S^rich_ij ≤ 20M` for `s ≤ 5` arcs (any distance set `D` containing all distances). -/ theorem sumR2_le {n : ℕ} [NeZero n] (v : ZMod n → ℂ) {s : ℕ} (hs : s ≤ 5) (A : Fin s → Finset (ZMod n)) {M : ℝ} (hM0 : 0 ≤ M) (hM : ∀ i j, i ≠ j → (Srich v (A i) (A j) : ℝ) ≤ M) (D : Finset ℝ) (hD : ∀ p : ZMod n × ZMod n, dist (v p.1) (v p.2) ∈ D) : ∑ u ∈ D, ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 ≤ 20 * M := by have hTc := offDiag_fin_card_le hs rw [sum_comm] have h : ∀ ij ∈ (univ : Finset (Fin s)).offDiag, ∑ u ∈ D, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 ≤ M := by intro ij hij rw [← Srich_eq_sum v (A ij.1) (A ij.2) D (fun p _ => hD p)] rw [mem_offDiag] at hij exact hM ij.1 ij.2 hij.2.2 calc ∑ ij ∈ (univ : Finset (Fin s)).offDiag, ∑ u ∈ D, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 ≤ ∑ _ij ∈ (univ : Finset (Fin s)).offDiag, M := sum_le_sum h _ = ((univ : Finset (Fin s)).offDiag.card : ℝ) * M := by rw [sum_const, nsmul_eq_mul] _ ≤ 20 * M := mul_le_mul_of_nonneg_right hTc hM0 /-- Cauchy–Schwarz over the `≤ 20` ordered arc pairs. -/ theorem sumR_sq_le {n : ℕ} [NeZero n] (v : ZMod n → ℂ) {s : ℕ} (hs : s ≤ 5) (A : Fin s → Finset (ZMod n)) (u : ℝ) : (∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ)) ^ 2 ≤ 20 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by have h := sq_sum_le_card_mul_sum_sq (s := (univ : Finset (Fin s)).offDiag) (f := fun ij => (Rrich v (A ij.1) (A ij.2) u : ℝ)) have h0 : 0 ≤ ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by positivity exact le_trans h (mul_le_mul_of_nonneg_right (offDiag_fin_card_le hs) h0) open Classical in /-- **GLIDE Lemma 12.5(ii).** For a partition into `s ≤ 5` quarter-turn arcs with `S^rich_ij ≤ M` (`i ≠ j`), the number of `ε`-rich classes (`≥ εn` vertices `x` with `m_u(x) ≥ 3`) satisfies `#·(εn)² ≤ 400M`. -/ theorem rich_class_count {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {s : ℕ} (hs : s ≤ 5) (A : Fin s → Finset (ZMod n)) (hcov : ∀ x, ∃ i, x ∈ A i) (hqt : ∀ i, QTArc v (A i)) {M : ℝ} (hM0 : 0 ≤ M) (hM : ∀ i j, i ≠ j → (Srich v (A i) (A j) : ℝ) ≤ M) {ε : ℝ} (hε : 0 < ε) (D : Finset ℝ) (hD : ∀ p : ZMod n × ZMod n, dist (v p.1) (v p.2) ∈ D) : ((D.filter (fun u => ε * n ≤ ((univ.filter (fun x => 3 ≤ mUv v x u)).card : ℝ))).card : ℝ) * (ε * n) ^ 2 ≤ 400 * M := by have hper : ∀ u ∈ D.filter (fun u => ε * n ≤ ((univ.filter (fun x => 3 ≤ mUv v x u)).card : ℝ)), (ε * n) ^ 2 ≤ 20 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by intro u hu rw [mem_filter] at hu have h1 : ((univ.filter (fun x => 3 ≤ mUv v x u)).card : ℝ) ≤ ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) := by exact_mod_cast rich_le_sumR hv A hcov hqt u have hεn : 0 ≤ ε * n := by positivity have h2 : (ε * n) ^ 2 ≤ (∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ)) ^ 2 := pow_le_pow_left₀ hεn (le_trans hu.2 h1) 2 exact le_trans h2 (sumR_sq_le v hs A u) have hsum := sum_le_sum hper rw [sum_const, nsmul_eq_mul] at hsum have hsub : ∑ u ∈ D.filter (fun u => ε * n ≤ ((univ.filter (fun x => 3 ≤ mUv v x u)).card : ℝ)), (20 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) ≤ ∑ u ∈ D, (20 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun u _ _ => by positivity) have hD20 : ∑ u ∈ D, (20 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) = 20 * ∑ u ∈ D, ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by rw [mul_sum] have h20 := sumR2_le v hs A hM0 hM D hD linarith open Classical in /-- **GLIDE Remark 13.3 (count of overfull classes).** For a partition into `s ≤ 5` quarter-turn arcs with `S^rich_ij ≤ M` (`i ≠ j`): the classes with `|chO u| = 2f(u) ≥ 2(1 + ε)n` satisfy `#·(εn)² ≤ 100M`, i.e. `#{u : f(u) ≥ (1 + ε)n} ≤ 100·max S^rich_ij/(ε²n²)` (no assumption on multiplicities). -/ theorem overfull_class_count {n : ℕ} [NeZero n] {v : ZMod n → ℂ} (hv : LeftTurns v) {s : ℕ} (hs : s ≤ 5) (A : Fin s → Finset (ZMod n)) (hcov : ∀ x, ∃ i, x ∈ A i) (hdisj : ∀ i j, i ≠ j → Disjoint (A i) (A j)) (hqt : ∀ i, QTArc v (A i)) {M : ℝ} (hM0 : 0 ≤ M) (hM : ∀ i j, i ≠ j → (Srich v (A i) (A j) : ℝ) ≤ M) {ε : ℝ} (hε : 0 < ε) (D : Finset ℝ) (hD : ∀ p : ZMod n × ZMod n, dist (v p.1) (v p.2) ∈ D) : ((D.filter (fun u => 2 * (1 + ε) * n ≤ ((chO v u).card : ℝ))).card : ℝ) * (ε * n) ^ 2 ≤ 100 * M := by have hper : ∀ u ∈ D.filter (fun u => 2 * (1 + ε) * n ≤ ((chO v u).card : ℝ)), (ε * n) ^ 2 ≤ 5 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by intro u hu rw [mem_filter] at hu have h1 : ((chO v u).card : ℝ) ≤ 2 * n + ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) := by exact_mod_cast chO_le_rich hv A hcov hdisj hqt u have hεn : 0 ≤ 2 * (ε * n) := by positivity have h2 : (2 * (ε * n)) ^ 2 ≤ (∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ)) ^ 2 := pow_le_pow_left₀ hεn (by linarith [hu.2]) 2 have h3 := sumR_sq_le v hs A u nlinarith have hsum := sum_le_sum hper rw [sum_const, nsmul_eq_mul] at hsum have hsub : ∑ u ∈ D.filter (fun u => 2 * (1 + ε) * n ≤ ((chO v u).card : ℝ)), (5 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) ≤ ∑ u ∈ D, (5 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun u _ _ => by positivity) have hD20 : ∑ u ∈ D, (5 * ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2) = 5 * ∑ u ∈ D, ∑ ij ∈ (univ : Finset (Fin s)).offDiag, (Rrich v (A ij.1) (A ij.2) u : ℝ) ^ 2 := by rw [mul_sum] have h20 := sumR2_le v hs A hM0 hM D hD linarith end Erdos94ThmA /-! ### LEAN-5 Q3a: orientation-preserving isometries `z ↦ az + b` (`‖a‖ = 1`) as pairs, domains, (T), GLIDE Lemma 14.5 -/ namespace Erdos94ThmA open Finset /-- The map `z ↦ a z + b` of the pair `g = (a, b)` (an orientation-preserving isometry when `‖a‖ = 1`). -/ def isoApp (g : ℂ × ℂ) (z : ℂ) : ℂ := g.1 * z + g.2 /-- Composition: `isoApp (isoComp g h) = isoApp g ∘ isoApp h`. -/ def isoComp (g h : ℂ × ℂ) : ℂ × ℂ := (g.1 * h.1, g.1 * h.2 + g.2) /-- The inverse of `(a, b)` with `‖a‖ = 1`: `z ↦ ā z − ā b`. -/ def isoInv (g : ℂ × ℂ) : ℂ × ℂ := ((starRingEnd ℂ) g.1, -((starRingEnd ℂ) g.1 * g.2)) /-- The conjugate `g ψ g⁻¹`. -/ def isoConj (g ψ : ℂ × ℂ) : ℂ × ℂ := isoComp g (isoComp ψ (isoInv g)) open Classical in /-- `dom g = {v ∈ B : g(v) ∈ B}`. -/ noncomputable def isoDom (B : Finset ℂ) (g : ℂ × ℂ) : Finset ℂ := B.filter (fun v => isoApp g v ∈ B) theorem isoApp_comp (g h : ℂ × ℂ) (z : ℂ) : isoApp (isoComp g h) z = isoApp g (isoApp h z) := by unfold isoApp isoComp; ring theorem conj_mul_unit {a : ℂ} (ha : ‖a‖ = 1) : (starRingEnd ℂ) a * a = 1 := by rw [mul_comm]; exact (unit_facts ha).1 theorem isoInv_app {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) (z : ℂ) : isoApp (isoInv g) (isoApp g z) = z := by unfold isoApp isoInv have h := conj_mul_unit hg linear_combination z * h theorem app_isoInv {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) (z : ℂ) : isoApp g (isoApp (isoInv g) z) = z := by unfold isoApp isoInv have h := (unit_facts hg).1 linear_combination (z - g.2) * h theorem isoInv_unit {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) : ‖(isoInv g).1‖ = 1 := by unfold isoInv; simp [hg] theorem isoComp_unit {g h : ℂ × ℂ} (hg : ‖g.1‖ = 1) (hh : ‖h.1‖ = 1) : ‖(isoComp g h).1‖ = 1 := by unfold isoComp; simp [hg, hh] theorem isoConj_unit {g ψ : ℂ × ℂ} (hg : ‖g.1‖ = 1) (hψ : ‖ψ.1‖ = 1) : ‖(isoConj g ψ).1‖ = 1 := isoComp_unit hg (isoComp_unit hψ (isoInv_unit hg)) theorem isoApp_conj {g ψ : ℂ × ℂ} (z : ℂ) : isoApp (isoConj g ψ) z = isoApp g (isoApp ψ (isoApp (isoInv g) z)) := by unfold isoConj; rw [isoApp_comp, isoApp_comp] /-- The linear part of a conjugate is unchanged. -/ theorem isoConj_fst {g ψ : ℂ × ℂ} (hg : ‖g.1‖ = 1) : (isoConj g ψ).1 = ψ.1 := by unfold isoConj isoComp isoInv simp only have h := (unit_facts hg).1 linear_combination ψ.1 * h theorem isoApp_inj {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) : Function.Injective (isoApp g) := by intro z w h have := congrArg (isoApp (isoInv g)) h rwa [isoInv_app hg, isoInv_app hg] at this /-- Pairs with the same action are equal. -/ theorem iso_ext {g h : ℂ × ℂ} (H : ∀ z, isoApp g z = isoApp h z) : g = h := by have h0 := H 0 have h1 := H 1 unfold isoApp at h0 h1 simp only [mul_zero, zero_add, mul_one] at h0 h1 exact Prod.ext (by rw [h0] at h1; exact add_right_cancel h1) h0 theorem isoApp_sub (g : ℂ × ℂ) (z w : ℂ) : isoApp g z - isoApp g w = g.1 * (z - w) := by unfold isoApp; ring theorem isoApp_norm_sub {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) (z w : ℂ) : ‖isoApp g z - isoApp g w‖ = ‖z - w‖ := by rw [isoApp_sub, norm_mul, hg, one_mul] theorem isoDom_sub (B : Finset ℂ) (g : ℂ × ℂ) : isoDom B g ⊆ B := filter_subset _ _ open Classical in /-- A non-trivial translation has at most two points of a (T)-set in its domain. -/ theorem dom_transl_le_two {B : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) {φ : ℂ × ℂ} (h1 : φ.1 = 1) (h2 : φ.2 ≠ 0) : (isoDom B φ).card ≤ 2 := by have e : isoDom B φ = B.filter (fun x => x + φ.2 ∈ B) := by unfold isoDom isoApp refine filter_congr (fun x _ => ?_) rw [h1, one_mul] rw [e] exact hT _ h2 open Classical in /-- Two DISTINCT isometries with the same linear part share at most two domain points (their quotient is a non-trivial translation, GLIDE Thm 15.5 step (3)). -/ theorem dom_inter_le_two {B : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) {φ ψ : ℂ × ℂ} (hφ : ‖φ.1‖ = 1) (h1 : φ.1 = ψ.1) (hne : φ ≠ ψ) : (isoDom B φ ∩ isoDom B ψ).card ≤ 2 := by have ht : ψ.2 - φ.2 ≠ 0 := by intro h exact hne (Prod.ext h1 (by linear_combination -h)) refine le_trans (card_le_card_of_injOn (isoApp φ) ?_ ?_) (hT _ ht) · intro v hv have hv' := mem_inter.mp hv have ha := (mem_filter.mp hv'.1).2 have hb := (mem_filter.mp hv'.2).2 refine mem_filter.mpr ⟨ha, ?_⟩ have e : isoApp φ v + (ψ.2 - φ.2) = isoApp ψ v := by unfold isoApp; rw [h1]; ring rw [e]; exact hb · intro v _ w _ h exact isoApp_inj hφ h /-- A rotation about `z` (fixing `z`) is determined by the image of one point `v ≠ z`. -/ theorem rot_determined {k k' : ℂ × ℂ} {z v : ℂ} (hk : isoApp k z = z) (hk' : isoApp k' z = z) (hv : v ≠ z) (h : isoApp k v = isoApp k' v) : k = k' := by have e1 : k.1 * (v - z) = k'.1 * (v - z) := by rw [← isoApp_sub, ← isoApp_sub, hk, hk', h] have hvz : v - z ≠ 0 := sub_ne_zero.mpr hv have h1 : k.1 = k'.1 := mul_right_cancel₀ hvz e1 have h2 : k.2 = k'.2 := by unfold isoApp at hk hk' rw [h1] at hk linear_combination hk - hk' exact Prod.ext h1 h2 open Classical in /-- `Σ_{ρ ∈ T} #{x ∈ B : |x − z| = ρ} = #{x ∈ B : |x − z| ∈ T}`. -/ theorem sum_circle_card (B : Finset ℂ) (z : ℂ) (T : Finset ℝ) : ∑ ρ ∈ T, (B.filter (fun x => ‖x - z‖ = ρ)).card = (B.filter (fun x => ‖x - z‖ ∈ T)).card := by rw [card_eq_sum_card_fiberwise (f := fun x => ‖x - z‖) (t := T)] · refine sum_congr rfl (fun ρ hρ => ?_) congr 1 ext x simp only [mem_filter] constructor · intro h; exact ⟨⟨h.1, h.2 ▸ hρ⟩, h.2⟩ · intro h; exact ⟨h.1.1, h.2⟩ · intro x hx exact (mem_filter.mp hx).2 open Classical in /-- **GLIDE Lemma 14.5 (one centre ⇒ few circles)** [audited], with the centre allowed in `B` (AUDIT3 §128: each domain counts `≥ τN + 1` points, the `+1` paying for `z` itself). If `R` is a set of rotations about `z` (`‖a‖ = 1`, `a ≠ 1`, `k(z) = z`) with `|dom k| ≥ τ|B| + 1`, then some set of radii `ρs` (all `> 0`) has `#ρs·(|R|τ) ≤ 2|B|` and carries `≥ |R|τ/2` points of `B`. -/ theorem lemma145 {B : Finset ℂ} {z : ℂ} {R : Finset (ℂ × ℂ)} {τ : ℝ} (hτ : 0 < τ) (hR : ∀ k ∈ R, ‖k.1‖ = 1 ∧ k.1 ≠ 1 ∧ isoApp k z = z ∧ τ * B.card + 1 ≤ (isoDom B k).card) : ∃ ρs : Finset ℝ, (∀ ρ ∈ ρs, 0 < ρ) ∧ (ρs.card : ℝ) * (R.card * τ) ≤ 2 * B.card ∧ (R.card : ℝ) * τ / 2 ≤ (B.filter (fun x => ‖x - z‖ ∈ ρs)).card := by rcases R.eq_empty_or_nonempty with hRe | hRne · refine ⟨∅, fun ρ h => absurd h (notMem_empty ρ), ?_, ?_⟩ · rw [hRe]; simp · rw [hRe]; simp obtain ⟨k₀, hk₀⟩ := hRne have hNpos : (0 : ℝ) < B.card := by have h1 := (hR k₀ hk₀).2.2.2 have h2 : ((isoDom B k₀).card : ℝ) ≤ B.card := by exact_mod_cast card_le_card (isoDom_sub B k₀) nlinarith -- the pairs (v, k v), v ≠ z obtain ⟨Pr, hPr⟩ : ∃ Pr : Finset (ℂ × ℂ), Pr = (B ×ˢ B).filter (fun p => p.1 ≠ z ∧ p.1 ≠ p.2 ∧ ‖p.1 - z‖ = ‖p.2 - z‖) := ⟨_, rfl⟩ obtain ⟨S, hS⟩ : ∃ S : Finset ((ℂ × ℂ) × ℂ), S = (R ×ˢ B).filter (fun q => q.2 ∈ isoDom B q.1 ∧ q.2 ≠ z) := ⟨_, rfl⟩ have hSPr : S.card ≤ Pr.card := by refine card_le_card_of_injOn (fun q => (q.2, isoApp q.1 q.2)) ?_ ?_ · intro q hq rw [hS, mem_coe, mem_filter, mem_product] at hq obtain ⟨⟨hk, _⟩, hv, hvz⟩ := hq obtain ⟨hk1, hka, hkz, _⟩ := hR _ hk have hv' := mem_filter.mp hv rw [hPr, mem_coe, mem_filter, mem_product] refine ⟨⟨hv'.1, hv'.2⟩, hvz, ?_, ?_⟩ · intro h have h' : q.2 = isoApp q.1 q.2 := h apply hka have e1 : q.1.1 * (q.2 - z) = 1 * (q.2 - z) := by rw [← isoApp_sub, hkz, ← h']; ring exact mul_right_cancel₀ (sub_ne_zero.mpr hvz) e1 · show ‖q.2 - z‖ = ‖isoApp q.1 q.2 - z‖ conv_rhs => rw [← hkz] rw [isoApp_norm_sub hk1] · intro q hq q' hq' h rw [hS, mem_coe, mem_filter, mem_product] at hq hq' have h' : q.2 = q'.2 ∧ isoApp q.1 q.2 = isoApp q'.1 q'.2 := Prod.mk.inj h have hkk : q.1 = q'.1 := by apply rot_determined (hR _ hq.1.1).2.2.1 (hR _ hq'.1.1).2.2.1 hq.2.2 rw [h'.2, ← h'.1] exact Prod.ext hkk h'.1 have hSlow : (R.card : ℝ) * (τ * B.card) ≤ S.card := by have hcount : S.card = ∑ k ∈ R, (B.filter (fun v => v ∈ isoDom B k ∧ v ≠ z)).card := by rw [hS, card_filter, sum_product] refine sum_congr rfl (fun k _ => ?_) rw [card_filter] have hper : ∀ k ∈ R, τ * B.card ≤ ((B.filter (fun v => v ∈ isoDom B k ∧ v ≠ z)).card : ℝ) := by intro k hk have h1 := (hR k hk).2.2.2 have hsub : isoDom B k ⊆ insert z (B.filter (fun v => v ∈ isoDom B k ∧ v ≠ z)) := by intro v hv by_cases hvz : v = z · rw [hvz]; exact mem_insert_self _ _ · exact mem_insert_of_mem (mem_filter.mpr ⟨isoDom_sub B k hv, hv, hvz⟩) have h2 := le_trans (card_le_card hsub) (card_insert_le _ _) have h3 : ((isoDom B k).card : ℝ) ≤ ((B.filter (fun v => v ∈ isoDom B k ∧ v ≠ z)).card : ℝ) + 1 := by exact_mod_cast h2 linarith rw [hcount] push_cast have := sum_le_sum hper rw [sum_const, nsmul_eq_mul] at this exact this -- the radii and the circles obtain ⟨rads, hrads⟩ : ∃ rads : Finset ℝ, rads = (B.filter (fun x => x ≠ z)).image (fun x => ‖x - z‖) := ⟨_, rfl⟩ have hrads_pos : ∀ ρ ∈ rads, 0 < ρ := by intro ρ hρ rw [hrads, mem_image] at hρ obtain ⟨x, hx, rfl⟩ := hρ exact norm_pos_iff.mpr (sub_ne_zero.mpr (mem_filter.mp hx).2) obtain ⟨m, hm⟩ : ∃ m : ℝ → ℕ, m = fun ρ => (B.filter (fun x => ‖x - z‖ = ρ)).card := ⟨_, rfl⟩ have hPrle : (Pr.card : ℝ) ≤ ∑ ρ ∈ rads, ((m ρ : ℝ) * m ρ - m ρ) := by rw [card_eq_sum_card_fiberwise (f := fun p => ‖p.1 - z‖) (t := rads)] · push_cast refine sum_le_sum (fun ρ _ => ?_) have hsub : Pr.filter (fun p => ‖p.1 - z‖ = ρ) ⊆ (B.filter (fun x => ‖x - z‖ = ρ)).offDiag := by intro p hp rw [hPr, mem_filter, mem_filter, mem_product] at hp obtain ⟨⟨⟨h1, h2⟩, _, h3, h4⟩, h5⟩ := hp rw [mem_offDiag, mem_filter, mem_filter] exact ⟨⟨h1, h5⟩, ⟨h2, h4 ▸ h5⟩, h3⟩ have h1 := card_le_card hsub rw [offDiag_card] at h1 have h2 : (B.filter (fun x => ‖x - z‖ = ρ)).card ≤ (B.filter (fun x => ‖x - z‖ = ρ)).card * (B.filter (fun x => ‖x - z‖ = ρ)).card := Nat.le_mul_self _ have h3 : (((Pr.filter (fun p => ‖p.1 - z‖ = ρ)).card : ℕ) : ℝ) ≤ (((B.filter (fun x => ‖x - z‖ = ρ)).card * (B.filter (fun x => ‖x - z‖ = ρ)).card - (B.filter (fun x => ‖x - z‖ = ρ)).card : ℕ) : ℝ) := by exact_mod_cast h1 rw [Nat.cast_sub h2] at h3 push_cast at h3 rw [hm] exact h3 · intro p hp rw [hPr, mem_coe, mem_filter, mem_product] at hp rw [hrads, mem_coe, mem_image] exact ⟨p.1, mem_filter.mpr ⟨hp.1.1, hp.2.1⟩, rfl⟩ have hsum_m : ∀ T : Finset ℝ, ((∑ ρ ∈ T, m ρ : ℕ) : ℝ) = (B.filter (fun x => ‖x - z‖ ∈ T)).card := by intro T rw [hm, sum_circle_card] have hsum_le : ∀ T : Finset ℝ, ∑ ρ ∈ T, (m ρ : ℝ) ≤ B.card := by intro T have := hsum_m T push_cast at this rw [this] exact_mod_cast card_le_card (filter_subset _ _) have hm_le : ∀ ρ, (m ρ : ℝ) ≤ B.card := by intro ρ rw [hm] exact_mod_cast card_le_card (filter_subset _ _) -- rich radii obtain ⟨ρs, hρs⟩ : ∃ ρs : Finset ℝ, ρs = rads.filter (fun ρ => (R.card : ℝ) * τ / 2 ≤ m ρ) := ⟨_, rfl⟩ refine ⟨ρs, fun ρ hρ => hrads_pos ρ (by rw [hρs] at hρ; exact (mem_filter.mp hρ).1), ?_, ?_⟩ · have h1 : (ρs.card : ℝ) * ((R.card : ℝ) * τ / 2) ≤ ∑ ρ ∈ ρs, (m ρ : ℝ) := by have := sum_le_sum (s := ρs) (f := fun _ => (R.card : ℝ) * τ / 2) (g := fun ρ => (m ρ : ℝ)) (fun ρ hρ => by rw [hρs] at hρ; exact (mem_filter.mp hρ).2) rw [sum_const, nsmul_eq_mul] at this exact this have h2 := hsum_le ρs nlinarith · -- poor radii carry little have hsplit := sum_filter_add_sum_filter_not rads (fun ρ => (R.card : ℝ) * τ / 2 ≤ m ρ) (fun ρ => (m ρ : ℝ) * m ρ - m ρ) have hpoor : ∑ ρ ∈ rads.filter (fun ρ => ¬ ((R.card : ℝ) * τ / 2 ≤ m ρ)), ((m ρ : ℝ) * m ρ - m ρ) ≤ (R.card : ℝ) * τ / 2 * B.card := by have h1 : ∀ ρ ∈ rads.filter (fun ρ => ¬ ((R.card : ℝ) * τ / 2 ≤ m ρ)), (m ρ : ℝ) * m ρ - m ρ ≤ (R.card : ℝ) * τ / 2 * m ρ := by intro ρ hρ have h := (mem_filter.mp hρ).2 push_neg at h have h0 : (0 : ℝ) ≤ m ρ := Nat.cast_nonneg _ nlinarith have h2 := sum_le_sum h1 rw [← mul_sum] at h2 have h3 := hsum_le (rads.filter (fun ρ => ¬ ((R.card : ℝ) * τ / 2 ≤ m ρ))) have h4 : (0 : ℝ) ≤ (R.card : ℝ) * τ / 2 := by positivity nlinarith have hrich : ∑ ρ ∈ rads.filter (fun ρ => (R.card : ℝ) * τ / 2 ≤ m ρ), ((m ρ : ℝ) * m ρ - m ρ) ≤ B.card * ∑ ρ ∈ ρs, (m ρ : ℝ) := by rw [hρs, mul_sum] refine sum_le_sum (fun ρ _ => ?_) have h0 : (0 : ℝ) ≤ m ρ := Nat.cast_nonneg _ have := hm_le ρ nlinarith have hSPr' : (S.card : ℝ) ≤ Pr.card := by exact_mod_cast hSPr have hfin : (R.card : ℝ) * τ / 2 * B.card ≤ B.card * ∑ ρ ∈ ρs, (m ρ : ℝ) := by nlinarith have hfin' : (R.card : ℝ) * τ / 2 ≤ ∑ ρ ∈ ρs, (m ρ : ℝ) := by rw [mul_comm] at hfin exact le_of_mul_le_mul_left hfin hNpos have := hsum_m ρs push_cast at this rw [this] at hfin' exact hfin' end Erdos94ThmA /-! ### LEAN-5 Q3b: GLIDE Thm 15.5 step (1) — the four-fold count `Σ_{g,h,k} |dom g h⁻¹ k g⁻¹| ≥ κ₂⁴N|𝒢|³` -/ namespace Erdos94ThmA open Finset open Classical in /-- `Σ_φ |F φ| = Σ_v #{φ : v ∈ F φ}` for subsets of `B`. -/ theorem sum_card_eq_cnt {ι : Type*} (B : Finset ℂ) (S : Finset ι) (F : ι → Finset ℂ) (hF : ∀ g ∈ S, F g ⊆ B) : ∑ g ∈ S, (F g).card = ∑ v ∈ B, (S.filter (fun g => v ∈ F g)).card := by have hc : ∀ g ∈ S, (F g).card = ∑ v ∈ B, if v ∈ F g then 1 else 0 := by intro g hg rw [sum_boole, Nat.cast_id, filter_mem_eq_inter, inter_eq_right.mpr (hF g hg)] rw [sum_congr rfl hc, sum_comm] refine sum_congr rfl (fun v _ => ?_) rw [sum_boole, Nat.cast_id] open Classical in /-- `Σ_{φ,φ′} |F φ ∩ F φ′| = Σ_v #{φ : v ∈ F φ}²`. -/ theorem sum_inter_eq_cnt_sq {ι : Type*} (B : Finset ℂ) (S : Finset ι) (F : ι → Finset ℂ) (hF : ∀ g ∈ S, F g ⊆ B) : ∑ g ∈ S, ∑ g' ∈ S, (F g ∩ F g').card = ∑ v ∈ B, (S.filter (fun g => v ∈ F g)).card ^ 2 := by have hci : ∀ g ∈ S, ∀ g' ∈ S, (F g ∩ F g').card = ∑ v ∈ B, (if v ∈ F g then 1 else 0) * (if v ∈ F g' then 1 else 0) := by intro g hg g' _ have e : ∀ v, ((if v ∈ F g then 1 else 0) * (if v ∈ F g' then 1 else 0) : ℕ) = if v ∈ F g ∩ F g' then 1 else 0 := by intro v by_cases h1 : v ∈ F g <;> by_cases h2 : v ∈ F g' <;> simp [h1, h2] simp_rw [e] rw [sum_boole, Nat.cast_id, filter_mem_eq_inter, inter_eq_right.mpr (le_trans inter_subset_left (hF g hg))] calc ∑ g ∈ S, ∑ g' ∈ S, (F g ∩ F g').card = ∑ g ∈ S, ∑ g' ∈ S, ∑ v ∈ B, (if v ∈ F g then 1 else 0) * (if v ∈ F g' then 1 else 0) := sum_congr rfl (fun g hg => sum_congr rfl (fun g' hg' => hci g hg g' hg')) _ = ∑ g ∈ S, ∑ v ∈ B, ∑ g' ∈ S, (if v ∈ F g then 1 else 0) * (if v ∈ F g' then 1 else 0) := sum_congr rfl (fun g _ => sum_comm) _ = ∑ v ∈ B, ∑ g ∈ S, ∑ g' ∈ S, (if v ∈ F g then 1 else 0) * (if v ∈ F g' then 1 else 0) := sum_comm _ = ∑ v ∈ B, (S.filter (fun g => v ∈ F g)).card ^ 2 := by refine sum_congr rfl (fun v _ => ?_) have e2 : (S.filter (fun g => v ∈ F g)).card = ∑ g ∈ S, if v ∈ F g then 1 else 0 := by rw [sum_boole, Nat.cast_id] rw [e2, sq, sum_mul_sum] open Classical in /-- Cauchy–Schwarz for a family of subsets of `B`: `(Σ_g |F_g|)² ≤ |B|·Σ_{g,g′} |F_g ∩ F_{g′}|`. -/ theorem sum_inter_ge {ι : Type*} (B : Finset ℂ) (S : Finset ι) (F : ι → Finset ℂ) (hF : ∀ g ∈ S, F g ⊆ B) : (∑ g ∈ S, (F g).card) ^ 2 ≤ B.card * ∑ g ∈ S, ∑ g' ∈ S, (F g ∩ F g').card := by rw [sum_card_eq_cnt B S F hF, sum_inter_eq_cnt_sq B S F hF] exact sq_sum_le_card_mul_sum_sq open Classical in /-- Step (1), one triple: `#{(v, w) : v ∈ dom g ∩ dom k, w ∈ dom g ∩ dom h, k(v) = h(w)} ≤ |dom(g h⁻¹ k g⁻¹)|` (`(v, w) ↦ g(v)`; `g h⁻¹ k g⁻¹ (g v) = g w ∈ B`). -/ theorem conj_dom_ge {B : Finset ℂ} {g h k : ℂ × ℂ} (hg : ‖g.1‖ = 1) (hh : ‖h.1‖ = 1) : ((B ×ˢ B).filter (fun p => (p.1 ∈ isoDom B g ∧ p.1 ∈ isoDom B k) ∧ (p.2 ∈ isoDom B g ∧ p.2 ∈ isoDom B h) ∧ isoApp k p.1 = isoApp h p.2)).card ≤ (isoDom B (isoConj g (isoComp (isoInv h) k))).card := by refine card_le_card_of_injOn (fun p => isoApp g p.1) ?_ ?_ · intro p hp rw [mem_coe, mem_filter] at hp obtain ⟨_, ⟨hv1, _⟩, ⟨hw1, _⟩, hkh⟩ := hp rw [mem_coe] refine mem_filter.mpr ⟨(mem_filter.mp hv1).2, ?_⟩ rw [isoApp_conj, isoInv_app hg, isoApp_comp, hkh, isoInv_app hh] exact (mem_filter.mp hw1).2 · intro p hp p' hp' hpp rw [mem_coe, mem_filter] at hp hp' have hv : p.1 = p'.1 := isoApp_inj hg hpp have hw : p.2 = p'.2 := by apply isoApp_inj hh rw [← hp.2.2.2, ← hp'.2.2.2, hv] exact Prod.ext hv hw open Classical in /-- Step (1), fixed outer factor `g`: `(Σ_k |dom g ∩ dom k|)² ≤ N·Σ_{h,k} |dom(g h⁻¹ k g⁻¹)|`. -/ theorem fourfold_g {B : Finset ℂ} {Gs : Finset (ℂ × ℂ)} (hG : ∀ g ∈ Gs, ‖g.1‖ = 1) {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) : (∑ k ∈ Gs, (isoDom B g ∩ isoDom B k).card) ^ 2 ≤ B.card * ∑ h ∈ Gs, ∑ k ∈ Gs, (isoDom B (isoConj g (isoComp (isoInv h) k))).card := by -- A x = {(k, v) : v ∈ dom g ∩ dom k, k v = x} obtain ⟨A, hA⟩ : ∃ A : ℂ → Finset ((ℂ × ℂ) × ℂ), A = fun x => (Gs ×ˢ B).filter (fun q => (q.2 ∈ isoDom B g ∧ q.2 ∈ isoDom B q.1) ∧ isoApp q.1 q.2 = x) := ⟨_, rfl⟩ -- T = {((h, k), (v, w))} obtain ⟨T, hT⟩ : ∃ T : Finset (((ℂ × ℂ) × (ℂ × ℂ)) × (ℂ × ℂ)), T = ((Gs ×ˢ Gs) ×ˢ (B ×ˢ B)).filter (fun q => (q.2.1 ∈ isoDom B g ∧ q.2.1 ∈ isoDom B q.1.2) ∧ (q.2.2 ∈ isoDom B g ∧ q.2.2 ∈ isoDom B q.1.1) ∧ isoApp q.1.2 q.2.1 = isoApp q.1.1 q.2.2) := ⟨_, rfl⟩ have hTle : T.card ≤ ∑ h ∈ Gs, ∑ k ∈ Gs, (isoDom B (isoConj g (isoComp (isoInv h) k))).card := by have e : T.card = ∑ h ∈ Gs, ∑ k ∈ Gs, ((B ×ˢ B).filter (fun p => (p.1 ∈ isoDom B g ∧ p.1 ∈ isoDom B k) ∧ (p.2 ∈ isoDom B g ∧ p.2 ∈ isoDom B h) ∧ isoApp k p.1 = isoApp h p.2)).card := by rw [hT, card_filter, sum_product, sum_product] refine sum_congr rfl (fun h _ => sum_congr rfl (fun k _ => ?_)) rw [card_filter] rw [e] exact sum_le_sum (fun h hh => sum_le_sum (fun k _ => conj_dom_ge hg (hG h hh))) have hTfib : ∑ x ∈ B, (A x).card ^ 2 ≤ T.card := by rw [card_eq_sum_card_fiberwise (f := fun q => isoApp q.1.2 q.2.1) (t := B)] · refine sum_le_sum (fun x _ => ?_) rw [sq, ← card_product] refine card_le_card_of_injOn (fun p => ((p.2.1, p.1.1), (p.1.2, p.2.2))) ?_ ?_ · intro p hp rw [mem_coe, mem_product, hA, mem_filter, mem_filter, mem_product, mem_product] at hp obtain ⟨⟨⟨hk, hv⟩, hvd, hkx⟩, ⟨⟨hh, hw⟩, hwd, hhx⟩⟩ := hp rw [mem_coe, mem_filter, hT, mem_filter, mem_product, mem_product, mem_product] exact ⟨⟨⟨⟨hh, hk⟩, ⟨hv, hw⟩⟩, hvd, hwd, hkx.trans hhx.symm⟩, hkx⟩ · intro p _ p' _ hpp simp only [Prod.mk.injEq] at hpp obtain ⟨⟨h1, h2⟩, h3, h4⟩ := hpp exact Prod.ext (Prod.ext h2 h3) (Prod.ext h1 h4) · intro q hq rw [hT, mem_coe, mem_filter] at hq exact (mem_filter.mp hq.2.1.2).2 have hAsum : ∑ x ∈ B, (A x).card = ∑ k ∈ Gs, (isoDom B g ∩ isoDom B k).card := by have e1 : ((Gs ×ˢ B).filter (fun q => q.2 ∈ isoDom B g ∧ q.2 ∈ isoDom B q.1)).card = ∑ x ∈ B, (A x).card := by rw [card_eq_sum_card_fiberwise (f := fun q => isoApp q.1 q.2) (t := B)] · refine sum_congr rfl (fun x _ => ?_) rw [hA, filter_filter] · intro q hq rw [mem_coe, mem_filter] at hq exact (mem_filter.mp hq.2.2).2 rw [← e1, card_filter, sum_product] refine sum_congr rfl (fun k _ => ?_) rw [← card_filter] congr 1 ext v simp only [mem_filter, mem_inter] constructor · rintro ⟨_, h1, h2⟩; exact ⟨h1, h2⟩ · rintro ⟨h1, h2⟩; exact ⟨isoDom_sub B g h1, h1, h2⟩ have hCS : (∑ x ∈ B, (A x).card) ^ 2 ≤ B.card * ∑ x ∈ B, (A x).card ^ 2 := sq_sum_le_card_mul_sum_sq rw [hAsum] at hCS calc (∑ k ∈ Gs, (isoDom B g ∩ isoDom B k).card) ^ 2 ≤ B.card * ∑ x ∈ B, (A x).card ^ 2 := hCS _ ≤ B.card * T.card := Nat.mul_le_mul_left _ hTfib _ ≤ B.card * ∑ h ∈ Gs, ∑ k ∈ Gs, (isoDom B (isoConj g (isoComp (isoInv h) k))).card := Nat.mul_le_mul_left _ hTle open Classical in /-- **GLIDE Thm 15.5, step (1): the four-fold count** [audited, AUDIT3 §128]: `(Σ_g |dom g|)⁴ ≤ N³·|𝒢|·Σ_{g,h,k ∈ 𝒢} |dom(g h⁻¹ k g⁻¹)|`; with `|dom g| ≥ κ₂N` this is `Σ ≥ κ₂⁴N|𝒢|³`. -/ theorem fourfold {B : Finset ℂ} {Gs : Finset (ℂ × ℂ)} (hG : ∀ g ∈ Gs, ‖g.1‖ = 1) : (∑ g ∈ Gs, (isoDom B g).card) ^ 4 ≤ B.card ^ 3 * Gs.card * ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs, (isoDom B (isoConj g (isoComp (isoInv h) k))).card := by have hD := sum_inter_ge B Gs (fun g => isoDom B g) (fun g _ => isoDom_sub B g) have hC : (∑ g ∈ Gs, ∑ k ∈ Gs, (isoDom B g ∩ isoDom B k).card) ^ 2 ≤ Gs.card * ∑ g ∈ Gs, (∑ k ∈ Gs, (isoDom B g ∩ isoDom B k).card) ^ 2 := sq_sum_le_card_mul_sum_sq have hB : ∑ g ∈ Gs, (∑ k ∈ Gs, (isoDom B g ∩ isoDom B k).card) ^ 2 ≤ ∑ g ∈ Gs, B.card * ∑ h ∈ Gs, ∑ k ∈ Gs, (isoDom B (isoConj g (isoComp (isoInv h) k))).card := sum_le_sum (fun g hg => fourfold_g hG (hG g hg)) rw [← mul_sum] at hB calc (∑ g ∈ Gs, (isoDom B g).card) ^ 4 = ((∑ g ∈ Gs, (isoDom B g).card) ^ 2) ^ 2 := by ring _ ≤ (B.card * ∑ g ∈ Gs, ∑ g' ∈ Gs, (isoDom B g ∩ isoDom B g').card) ^ 2 := Nat.pow_le_pow_left hD 2 _ = B.card ^ 2 * (∑ g ∈ Gs, ∑ g' ∈ Gs, (isoDom B g ∩ isoDom B g').card) ^ 2 := by ring _ ≤ B.card ^ 2 * (Gs.card * (B.card * ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs, (isoDom B (isoConj g (isoComp (isoInv h) k))).card)) := Nat.mul_le_mul_left _ (le_trans hC (Nat.mul_le_mul_left _ hB)) _ = B.card ^ 3 * Gs.card * ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs, (isoDom B (isoConj g (isoComp (isoInv h) k))).card := by ring end Erdos94ThmA /-! ### LEAN-5 Q3c: GLIDE Thm 15.5 steps (2)–(6) — rich isometry families of a (T)-set have a common centre -/ namespace Erdos94ThmA open Finset /-- `h⁻¹k` with `h.1 = k.1` is a translation, non-trivial when `h ≠ k`. -/ theorem quot_transl {h k : ℂ × ℂ} (hh : ‖h.1‖ = 1) (h1 : h.1 = k.1) : (isoComp (isoInv h) k).1 = 1 ∧ (h ≠ k → (isoComp (isoInv h) k).2 ≠ 0) := by refine ⟨?_, fun hne h0 => hne ?_⟩ · unfold isoComp isoInv; simp only; rw [← h1]; exact conj_mul_unit hh · unfold isoComp isoInv at h0 simp only at h0 have hc : (starRingEnd ℂ) h.1 ≠ 0 := by intro hc; have := conj_mul_unit hh; rw [hc, zero_mul] at this; exact zero_ne_one this have h3 : (starRingEnd ℂ) h.1 * (k.2 - h.2) = 0 := by linear_combination h0 have h2 := (mul_eq_zero.mp h3).resolve_left hc exact Prod.ext h1 (by linear_combination -h2) /-- The conjugate of a non-trivial translation is a non-trivial translation. -/ theorem isoConj_transl {g ψ : ℂ × ℂ} (hg : ‖g.1‖ = 1) (h1 : ψ.1 = 1) (h2 : ψ.2 ≠ 0) : (isoConj g ψ).1 = 1 ∧ (isoConj g ψ).2 ≠ 0 := by refine ⟨by rw [isoConj_fst hg, h1], ?_⟩ have e : (isoConj g ψ).2 = g.1 * ψ.2 := by unfold isoConj isoComp isoInv simp only rw [h1] have := (unit_facts hg).1 linear_combination (-g.2) * this rw [e] have hg0 : g.1 ≠ 0 := by intro h; rw [h, norm_zero] at hg; exact zero_ne_one hg exact mul_ne_zero hg0 h2 /-- `g′ (g′⁻¹ g) = g` as pairs. -/ theorem isoComp_inv_cancel {g g' : ℂ × ℂ} (hg' : ‖g'.1‖ = 1) : isoComp g' (isoComp (isoInv g') g) = g := by have h := (unit_facts hg').1 unfold isoComp isoInv refine Prod.ext ?_ ?_ · simp only; linear_combination g.1 * h · simp only; linear_combination (g.2 - g'.2) * h open Classical in /-- **Step (3) counting**: subsets `F φ ⊆ B` (`φ ∈ V`) with pairwise intersections `≤ 2` have `Σ_φ |F φ| ≤ |B| + |V|(|V| − 1)` (`3c ≤ 2 + c²` for the cover multiplicity `c`). -/ theorem few_values {ι : Type*} (B : Finset ℂ) (V : Finset ι) (F : ι → Finset ℂ) (hF : ∀ φ ∈ V, F φ ⊆ B) (h2 : ∀ φ ∈ V, ∀ φ' ∈ V, φ ≠ φ' → (F φ ∩ F φ').card ≤ 2) : ∑ φ ∈ V, (F φ).card ≤ B.card + V.card * (V.card - 1) := by have hsum := sum_card_eq_cnt B V F hF have hsq := sum_inter_eq_cnt_sq B V F hF have hup : ∑ φ ∈ V, ∑ φ' ∈ V, (F φ ∩ F φ').card ≤ ∑ φ ∈ V, ((F φ).card + 2 * (V.card - 1)) := by refine sum_le_sum (fun φ hφ => ?_) rw [← add_sum_erase V _ hφ, inter_self] have : ∑ φ' ∈ V.erase φ, (F φ ∩ F φ').card ≤ ∑ φ' ∈ V.erase φ, 2 := sum_le_sum (fun φ' hφ' => h2 φ hφ φ' (mem_of_mem_erase hφ') (Ne.symm (ne_of_mem_erase hφ'))) rw [sum_const, card_erase_of_mem hφ, smul_eq_mul] at this omega rw [sum_add_distrib, sum_const, smul_eq_mul] at hup have hper : ∀ v ∈ B, 3 * (V.filter (fun φ => v ∈ F φ)).card ≤ 2 + (V.filter (fun φ => v ∈ F φ)).card ^ 2 := by intro v _ obtain ⟨c, hc⟩ : ∃ c, c = (V.filter (fun φ => v ∈ F φ)).card := ⟨_, rfl⟩ rw [← hc] rcases Nat.lt_or_ge c 3 with h | h · interval_cases c <;> simp · nlinarith have h3 := sum_le_sum hper rw [← mul_sum, sum_add_distrib, sum_const, smul_eq_mul] at h3 rw [hsum] rw [hsq] at hup rw [hsum] at hup have hV : V.card * (2 * (V.card - 1)) = 2 * (V.card * (V.card - 1)) := by ring omega /-- The centre of a rotation `ψ` (`ψ.1 ≠ 1`) is its unique fixed point. -/ theorem rot_fixed {ψ : ℂ × ℂ} (hψ : ψ.1 ≠ 1) : isoApp ψ (ψ.2 / (1 - ψ.1)) = ψ.2 / (1 - ψ.1) ∧ ∀ w, isoApp ψ w = w → w = ψ.2 / (1 - ψ.1) := by have h1 : (1 : ℂ) - ψ.1 ≠ 0 := sub_ne_zero.mpr (Ne.symm hψ) constructor · unfold isoApp; field_simp; ring · intro w hw unfold isoApp at hw rw [eq_div_iff h1] linear_combination -hw end Erdos94ThmA /-! ### LEAN-5 Q3d: GLIDE Thm 15.5 steps (2)–(5) as separate lemmas -/ namespace Erdos94ThmA open Finset open Classical in /-- Splitting a triple sum by a relation between the last two indices. -/ theorem sum_split_rel {α : Type*} (Gs : Finset α) (r : α → α → Prop) (f : α → α → α → ℝ) : ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs, f g h k = ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs.filter (fun k => r h k), f g h k + ∑ p ∈ (Gs ×ˢ Gs).filter (fun p => ¬ r p.1 p.2), ∑ g ∈ Gs, f g p.1 p.2 := by have e1 : ∀ g h, ∑ k ∈ Gs, f g h k = ∑ k ∈ Gs.filter (fun k => r h k), f g h k + ∑ k ∈ Gs.filter (fun k => ¬ r h k), f g h k := fun g h => (sum_filter_add_sum_filter_not _ _ _).symm have hR : ∑ p ∈ (Gs ×ˢ Gs).filter (fun p => ¬ r p.1 p.2), ∑ g ∈ Gs, f g p.1 p.2 = ∑ h ∈ Gs, ∑ k ∈ Gs.filter (fun k => ¬ r h k), ∑ g ∈ Gs, f g h k := by rw [sum_filter, sum_product] refine sum_congr rfl (fun h _ => ?_) rw [sum_filter] have hL : ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs.filter (fun k => ¬ r h k), f g h k = ∑ h ∈ Gs, ∑ k ∈ Gs.filter (fun k => ¬ r h k), ∑ g ∈ Gs, f g h k := by rw [sum_comm] exact sum_congr rfl (fun h _ => sum_comm) rw [hR, ← hL] simp_rw [e1, sum_add_distrib] /-- Markov: if `Σ f ≥ aN|s|` with `f ≤ N`, then `#{f ≥ aN/2} ≥ (a/2)|s|`. -/ theorem markov_big {α : Type*} (s : Finset α) (f : α → ℝ) {N a : ℝ} (hN : 0 < N) (ha : 0 ≤ a) (hf : ∀ x ∈ s, f x ≤ N) (hsum : a * N * s.card ≤ ∑ x ∈ s, f x) : a / 2 * s.card ≤ ((s.filter (fun x => a * N / 2 ≤ f x)).card : ℝ) := by classical have hsp := sum_filter_add_sum_filter_not s (fun x => a * N / 2 ≤ f x) f have h1 : ∑ x ∈ s.filter (fun x => a * N / 2 ≤ f x), f x ≤ (s.filter (fun x => a * N / 2 ≤ f x)).card * N := by have := sum_le_sum (fun x (hx : x ∈ s.filter (fun x => a * N / 2 ≤ f x)) => hf x (mem_filter.mp hx).1) rw [sum_const, nsmul_eq_mul] at this exact this have h2 : ∑ x ∈ s.filter (fun x => ¬ a * N / 2 ≤ f x), f x ≤ s.card * (a * N / 2) := by have := sum_le_sum (fun x (hx : x ∈ s.filter (fun x => ¬ a * N / 2 ≤ f x)) => (not_le.mp (mem_filter.mp hx).2).le) rw [sum_const, nsmul_eq_mul] at this have h3 : ((s.filter (fun x => ¬ a * N / 2 ≤ f x)).card : ℝ) ≤ s.card := by exact_mod_cast card_le_card (filter_subset _ _) have h4 : (0 : ℝ) ≤ a * N / 2 := by positivity nlinarith have h5 : a / 2 * s.card * N ≤ (s.filter (fun x => a * N / 2 ≤ f x)).card * N := by nlinarith exact le_of_mul_le_mul_right h5 hN open Classical in /-- **Thm 15.5 steps (1)–(2)**: some pair `(h, k)` with different angles `h.1 ≠ k.1` has `Σ_g |dom g(h⁻¹k)g⁻¹| ≥ κ₂⁴N|𝒢|/2` (the equal-angle triples are translations: ≤ `|𝒢|²N + 2|𝒢|³` by (T)). -/ theorem step2_pair {B : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) {Gs : Finset (ℂ × ℂ)} (hG : ∀ g ∈ Gs, ‖g.1‖ = 1) {κ₂ : ℝ} (hκ₂ : 0 < κ₂) (hN : (0 : ℝ) < B.card) (hG4 : 4 ≤ κ₂ ^ 4 * Gs.card) (hN8 : 8 ≤ κ₂ ^ 4 * B.card) (hdom : ∀ g ∈ Gs, κ₂ * B.card ≤ (isoDom B g).card) : ∃ h ∈ Gs, ∃ k ∈ Gs, h.1 ≠ k.1 ∧ κ₂ ^ 4 * B.card * Gs.card / 2 ≤ ∑ g ∈ Gs, ((isoDom B (isoConj g (isoComp (isoInv h) k))).card : ℝ) := by have hG0 : (0 : ℝ) < Gs.card := by by_contra h; push_neg at h have : (Gs.card : ℝ) = 0 := le_antisymm h (Nat.cast_nonneg _) rw [this] at hG4; linarith obtain ⟨f, hf⟩ : ∃ f : ℂ × ℂ → ℂ × ℂ → ℂ × ℂ → ℝ, f = fun g h k => ((isoDom B (isoConj g (isoComp (isoInv h) k))).card : ℝ) := ⟨_, rfl⟩ -- step (1) have h1 : κ₂ ^ 4 * B.card * Gs.card ^ 3 ≤ ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs, f g h k := by have h4 := fourfold (B := B) hG have hsum : κ₂ * B.card * Gs.card ≤ ((∑ g ∈ Gs, (isoDom B g).card : ℕ) : ℝ) := by push_cast have := sum_le_sum (fun g hg => hdom g hg) rw [sum_const, nsmul_eq_mul] at this linarith have h4' : ((∑ g ∈ Gs, (isoDom B g).card : ℕ) : ℝ) ^ 4 ≤ (B.card : ℝ) ^ 3 * Gs.card * ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs, f g h k := by simp only [hf]; exact_mod_cast h4 have h5 : (κ₂ * B.card * Gs.card) ^ 4 ≤ ((∑ g ∈ Gs, (isoDom B g).card : ℕ) : ℝ) ^ 4 := pow_le_pow_left₀ (by positivity) hsum 4 have h6 : (κ₂ * B.card * Gs.card) ^ 4 = (B.card : ℝ) ^ 3 * Gs.card * (κ₂ ^ 4 * B.card * Gs.card ^ 3) := by ring rw [h6] at h5 exact le_of_mul_le_mul_left (le_trans h5 h4') (by positivity) -- step (2): equal angles have hNB : ∀ φ : ℂ × ℂ, ((isoDom B φ).card : ℝ) ≤ B.card := fun φ => by exact_mod_cast card_le_card (isoDom_sub B φ) have hEq : ∀ g ∈ Gs, ∀ h ∈ Gs, ∑ k ∈ Gs.filter (fun k => h.1 = k.1), f g h k ≤ B.card + 2 * Gs.card := by intro g hg h hh have hmem : h ∈ Gs.filter (fun k => h.1 = k.1) := mem_filter.mpr ⟨hh, rfl⟩ rw [← add_sum_erase _ _ hmem] have h1 : ∑ k ∈ (Gs.filter (fun k => h.1 = k.1)).erase h, f g h k ≤ ∑ k ∈ (Gs.filter (fun k => h.1 = k.1)).erase h, (2 : ℝ) := by refine sum_le_sum (fun k hk => ?_) have hk' := mem_filter.mp (mem_of_mem_erase hk) have hne : h ≠ k := Ne.symm (ne_of_mem_erase hk) obtain ⟨q1, q2⟩ := quot_transl (hG h hh) hk'.2 obtain ⟨c1, c2⟩ := isoConj_transl (hG g hg) q1 (q2 hne) simp only [hf] exact_mod_cast dom_transl_le_two hT c1 c2 rw [sum_const, nsmul_eq_mul] at h1 have h2 : (((Gs.filter (fun k => h.1 = k.1)).erase h).card : ℝ) ≤ Gs.card := by exact_mod_cast le_trans card_erase_le (card_le_card (filter_subset _ _)) have h3 : f g h h ≤ B.card := by simp only [hf]; exact hNB _ nlinarith have hEqsum : ∑ g ∈ Gs, ∑ h ∈ Gs, ∑ k ∈ Gs.filter (fun k => h.1 = k.1), f g h k ≤ Gs.card * (Gs.card * (B.card + 2 * Gs.card)) := by have := sum_le_sum (fun g hg => sum_le_sum (fun h hh => hEq g hg h hh)) simp only [sum_const, nsmul_eq_mul] at this exact this have hsplit := sum_split_rel Gs (fun h k => h.1 = k.1) f obtain ⟨Q, hQ⟩ : ∃ Q : Finset ((ℂ × ℂ) × (ℂ × ℂ)), Q = (Gs ×ˢ Gs).filter (fun p => ¬ p.1.1 = p.2.1) := ⟨_, rfl⟩ rw [← hQ] at hsplit have hQbig : κ₂ ^ 4 * B.card * Gs.card ^ 3 / 2 ≤ ∑ p ∈ Q, ∑ g ∈ Gs, f g p.1 p.2 := by have e : (Gs.card : ℝ) * (Gs.card * (B.card + 2 * Gs.card)) = Gs.card ^ 2 * B.card + 2 * Gs.card ^ 3 := by ring have h2 : (Gs.card : ℝ) ^ 2 * B.card ≤ κ₂ ^ 4 * B.card * Gs.card ^ 3 / 4 := by have : (0 : ℝ) ≤ Gs.card ^ 2 * B.card := by positivity nlinarith have h3 : 2 * (Gs.card : ℝ) ^ 3 ≤ κ₂ ^ 4 * B.card * Gs.card ^ 3 / 4 := by have : (0 : ℝ) < Gs.card ^ 3 := by positivity nlinarith linarith have hQcard : (Q.card : ℝ) ≤ Gs.card * Gs.card := by rw [hQ] have := card_le_card (filter_subset (fun p : (ℂ × ℂ) × (ℂ × ℂ) => ¬ p.1.1 = p.2.1) (Gs ×ˢ Gs)) rw [card_product] at this exact_mod_cast this have hQne : Q.Nonempty := by rcases Q.eq_empty_or_nonempty with h | h · rw [h, sum_empty] at hQbig have : 0 < κ₂ ^ 4 * B.card * Gs.card ^ 3 / 2 := by positivity linarith · exact h obtain ⟨p, hp, hpbig⟩ : ∃ p ∈ Q, κ₂ ^ 4 * B.card * Gs.card / 2 ≤ ∑ g ∈ Gs, f g p.1 p.2 := by apply exists_le_of_sum_le hQne rw [sum_const, nsmul_eq_mul] have : (Q.card : ℝ) * (κ₂ ^ 4 * B.card * Gs.card / 2) ≤ Gs.card * Gs.card * (κ₂ ^ 4 * B.card * Gs.card / 2) := mul_le_mul_of_nonneg_right hQcard (by positivity) nlinarith rw [hQ, mem_filter, mem_product] at hp refine ⟨p.1, hp.1.1, p.2, hp.1.2, hp.2, ?_⟩ simp only [hf] at hpbig exact hpbig open Classical in /-- **Thm 15.5 step (3)**: conjugates `gψg⁻¹` (`g ∈ Gs₁`) with `|dom| ≥ a` and `2N ≤ Ma`, `M² < N` take fewer than `M` values, so one value is taken by `≥ |Gs₁|/M` of them. -/ theorem step3_value {B : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) {Gs₁ : Finset (ℂ × ℂ)} (hG : ∀ g ∈ Gs₁, ‖g.1‖ = 1) {ψ : ℂ × ℂ} (hψ : ‖ψ.1‖ = 1) {a : ℝ} {M : ℕ} (hMa : 2 * (B.card : ℝ) ≤ M * a) (hMN : (M : ℝ) * M < B.card) (hbig : ∀ g ∈ Gs₁, a ≤ (isoDom B (isoConj g ψ)).card) (hne : Gs₁.Nonempty) : ∃ ψ' : ℂ × ℂ, (Gs₁.card : ℝ) ≤ M * (Gs₁.filter (fun g => isoConj g ψ = ψ')).card := by obtain ⟨V, hV⟩ : ∃ V : Finset (ℂ × ℂ), V = Gs₁.image (fun g => isoConj g ψ) := ⟨_, rfl⟩ have hVprop : ∀ φ ∈ V, φ.1 = ψ.1 ∧ ‖φ.1‖ = 1 ∧ a ≤ ((isoDom B φ).card : ℝ) := by intro φ hφ rw [hV, mem_image] at hφ obtain ⟨g, hg, rfl⟩ := hφ exact ⟨isoConj_fst (hG g hg), isoConj_unit (hG g hg) hψ, hbig g hg⟩ have hVne : V.Nonempty := by rw [hV]; exact hne.image _ have hVlt : (V.card : ℝ) ≤ M := by by_contra hcon push_neg at hcon have hMV : M ≤ V.card := by exact_mod_cast hcon.le obtain ⟨V', hV'V, hV'c⟩ := exists_subset_card_eq hMV have hfv := few_values B V' (fun φ => isoDom B φ) (fun φ _ => isoDom_sub B φ) (fun φ hφ φ' hφ' hne => dom_inter_le_two hT (hVprop φ (hV'V hφ)).2.1 ((hVprop φ (hV'V hφ)).1.trans (hVprop φ' (hV'V hφ')).1.symm) hne) rw [hV'c] at hfv have hlow : (M : ℝ) * a ≤ ∑ φ ∈ V', ((isoDom B φ).card : ℝ) := by have := sum_le_sum (fun φ (hφ : φ ∈ V') => (hVprop φ (hV'V hφ)).2.2) rw [sum_const, nsmul_eq_mul, hV'c] at this exact this have hfv' : ∑ φ ∈ V', ((isoDom B φ).card : ℝ) ≤ B.card + M * M := by have h1 : ((∑ φ ∈ V', (isoDom B φ).card : ℕ) : ℝ) ≤ ((B.card + M * (M - 1) : ℕ) : ℝ) := by exact_mod_cast hfv have h2 : M * (M - 1) ≤ M * M := Nat.mul_le_mul_left _ (Nat.sub_le _ _) have h3 : ((B.card + M * (M - 1) : ℕ) : ℝ) ≤ ((B.card + M * M : ℕ) : ℝ) := by exact_mod_cast (by omega) push_cast at h1 h3 linarith linarith have hV0 : (0 : ℝ) < V.card := by exact_mod_cast card_pos.mpr hVne obtain ⟨ψ', _, hψ'big⟩ : ∃ ψ' ∈ V, (Gs₁.card : ℝ) / V.card ≤ ((Gs₁.filter (fun g => isoConj g ψ = ψ')).card : ℝ) := by have hfib : Gs₁.card = ∑ y ∈ V, (Gs₁.filter (fun g => isoConj g ψ = y)).card := card_eq_sum_card_fiberwise (fun g hg => by rw [hV]; exact mem_image_of_mem _ hg) apply exists_le_of_sum_le hVne rw [sum_const, nsmul_eq_mul, mul_div_cancel₀ _ hV0.ne'] have : ((Gs₁.card : ℕ) : ℝ) = ((∑ y ∈ V, (Gs₁.filter (fun g => isoConj g ψ = y)).card : ℕ) : ℝ) := by rw [← hfib] rw [this] push_cast exact le_refl _ refine ⟨ψ', ?_⟩ have h1 : (Gs₁.card : ℝ) = V.card * ((Gs₁.card : ℝ) / V.card) := (mul_div_cancel₀ _ hV0.ne').symm have h2 : (0 : ℝ) ≤ (Gs₁.card : ℝ) / V.card := div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) have h3 : (V.card : ℝ) * ((Gs₁.card : ℝ) / V.card) ≤ M * ((Gs₁.card : ℝ) / V.card) := mul_le_mul_of_nonneg_right hVlt h2 have h4 : (M : ℝ) * ((Gs₁.card : ℝ) / V.card) ≤ M * ((Gs₁.filter (fun g => isoConj g ψ = ψ')).card : ℝ) := mul_le_mul_of_nonneg_left hψ'big (Nat.cast_nonneg _) linarith /-- **Thm 15.5 step (4)**: if `gψg⁻¹ = g′ψg′⁻¹` then `g′⁻¹g` fixes the centre of the rotation `ψ`. -/ theorem step4_centre {ψ : ℂ × ℂ} (hψ1 : ψ.1 ≠ 1) {g g' : ℂ × ℂ} (hg : ‖g.1‖ = 1) (hg' : ‖g'.1‖ = 1) (hc : isoConj g ψ = isoConj g' ψ) : isoApp (isoComp (isoInv g') g) (ψ.2 / (1 - ψ.1)) = ψ.2 / (1 - ψ.1) := by obtain ⟨hz1, hz2⟩ := rot_fixed hψ1 have h1 : isoApp (isoConj g ψ) (isoApp g (ψ.2 / (1 - ψ.1))) = isoApp g (ψ.2 / (1 - ψ.1)) := by rw [isoApp_conj, isoInv_app hg, hz1] rw [hc, isoApp_conj] at h1 have h2 : isoApp ψ (isoApp (isoInv g') (isoApp g (ψ.2 / (1 - ψ.1)))) = isoApp (isoInv g') (isoApp g (ψ.2 / (1 - ψ.1))) := by have := congrArg (isoApp (isoInv g')) h1 rwa [isoInv_app hg'] at this rw [isoApp_comp] exact hz2 _ h2 /-- Rich off-diagonal pairs: `0 ≤ f ≤ N` on `S × S`, `Σ f ≥ cN|S|²`, `c|S| ≥ 2` ⇒ `≥ c|S|²/4` pairs `p.1 ≠ p.2` with `f p ≥ cN/4`. -/ theorem rich_pairs {α : Type*} [DecidableEq α] (S : Finset α) (f : α × α → ℝ) {N c : ℝ} (hN : 0 < N) (hc : 0 ≤ c) (hf : ∀ p ∈ S ×ˢ S, f p ≤ N) (hsum : c * N * S.card ^ 2 ≤ ∑ p ∈ S ×ˢ S, f p) (hS : 2 ≤ c * S.card) : c * S.card ^ 2 / 4 ≤ (((S ×ˢ S).filter (fun p => p.1 ≠ p.2 ∧ c / 4 * N ≤ f p)).card : ℝ) := by obtain ⟨Rich, hRich⟩ : ∃ Rich : Finset (α × α), Rich = (S ×ˢ S).filter (fun p => p.1 ≠ p.2 ∧ c / 4 * N ≤ f p) := ⟨_, rfl⟩ rw [← hRich] have hterm : ∀ p ∈ S ×ˢ S, f p ≤ (if p.1 = p.2 then N else 0) + (if p ∈ Rich then N else 0) + c / 4 * N := by intro p hp have h0 := hf p hp have hc4 : (0 : ℝ) ≤ c / 4 * N := by positivity by_cases h1 : p.1 = p.2 · rw [if_pos h1] have : (0 : ℝ) ≤ (if p ∈ Rich then N else 0) := by split_ifs <;> linarith linarith · rw [if_neg h1, zero_add] by_cases h2 : p ∈ Rich · rw [if_pos h2]; linarith · rw [if_neg h2, zero_add] by_contra hcon push_neg at hcon exact h2 (by rw [hRich, mem_filter]; exact ⟨hp, h1, hcon.le⟩) have hs := sum_le_sum hterm rw [sum_add_distrib, sum_add_distrib, sum_const, nsmul_eq_mul, card_product] at hs have hdiag : ∑ p ∈ S ×ˢ S, (if p.1 = p.2 then N else 0) = S.card * N := by rw [sum_ite, sum_const_zero, add_zero, sum_const, nsmul_eq_mul] congr 1 have hd : ((S ×ˢ S).filter (fun p : α × α => p.1 = p.2)) = S.image (fun x => (x, x)) := by ext p simp only [mem_filter, mem_product, mem_image] constructor · rintro ⟨⟨h1, _⟩, h3⟩; exact ⟨p.1, h1, Prod.ext rfl h3⟩ · rintro ⟨x, hx, rfl⟩; exact ⟨⟨hx, hx⟩, rfl⟩ rw [hd, card_image_of_injective _ (fun a b h => (Prod.mk.inj h).1)] have hrichs : ∑ p ∈ S ×ˢ S, (if p ∈ Rich then N else 0) = Rich.card * N := by have hsub : (S ×ˢ S) ∩ Rich = Rich := inter_eq_right.mpr (by rw [hRich]; exact filter_subset _ _) rw [sum_ite_mem, hsub, sum_const, nsmul_eq_mul] rw [hdiag, hrichs] at hs push_cast at hs have hk : c * S.card ^ 2 * N ≤ (S.card + Rich.card + S.card * S.card * (c / 4)) * N := by nlinarith have hk' := le_of_mul_le_mul_right hk hN have : (S.card : ℝ) ≤ c * S.card ^ 2 / 2 := by nlinarith nlinarith open Classical in /-- **Thm 15.5 step (5)**: a family `Gs′` whose quotients `g′⁻¹g` all fix `z`, with `|dom g| ≥ κ₂N` and `κ₂²|Gs′| ≥ 2`, yields `≥ κ₂²|Gs′|/4` distinct non-trivial rotations about `z` with `|dom| ≥ κ₂²N/4`. -/ theorem step5_rich {B : Finset ℂ} {Gs' : Finset (ℂ × ℂ)} (hG : ∀ g ∈ Gs', ‖g.1‖ = 1) {z : ℂ} (hcen : ∀ g ∈ Gs', ∀ g' ∈ Gs', isoApp (isoComp (isoInv g') g) z = z) {κ₂ : ℝ} (hκ₂ : 0 < κ₂) (hN : (0 : ℝ) < B.card) (hdom : ∀ g ∈ Gs', κ₂ * B.card ≤ (isoDom B g).card) (hG2 : 2 ≤ κ₂ ^ 2 * Gs'.card) : ∃ R : Finset (ℂ × ℂ), (∀ k ∈ R, ‖k.1‖ = 1 ∧ k.1 ≠ 1 ∧ isoApp k z = z ∧ κ₂ ^ 2 / 4 * B.card ≤ (isoDom B k).card) ∧ κ₂ ^ 2 * Gs'.card / 4 ≤ R.card := by -- |dom(g′⁻¹g)| ≥ |im g ∩ im g′| have hdomG : ∀ g ∈ Gs', ∀ g' ∈ Gs', ((isoDom B g).image (isoApp g) ∩ (isoDom B g').image (isoApp g')).card ≤ (isoDom B (isoComp (isoInv g') g)).card := by intro g hg g' hg' have hgu := hG g hg have hg'u := hG g' hg' refine card_le_card_of_injOn (isoApp (isoInv g)) ?_ ?_ · intro x hx rw [mem_coe, mem_inter, mem_image, mem_image] at hx obtain ⟨⟨v, hv, hvx⟩, ⟨v', hv', hv'x⟩⟩ := hx rw [mem_coe] refine mem_filter.mpr ⟨?_, ?_⟩ · rw [← hvx, isoInv_app hgu]; exact (mem_filter.mp hv).1 · rw [isoApp_comp, app_isoInv hgu, ← hv'x, isoInv_app hg'u] exact (mem_filter.mp hv').1 · intro x _ y _ h exact isoApp_inj (isoInv_unit hgu) h have himsum : κ₂ ^ 2 * B.card * Gs'.card ^ 2 ≤ ∑ p ∈ Gs' ×ˢ Gs', ((isoDom B (isoComp (isoInv p.2) p.1)).card : ℝ) := by have hsi := sum_inter_ge B Gs' (fun g => (isoDom B g).image (isoApp g)) (fun g _ => by intro x hx rw [mem_image] at hx obtain ⟨v, hv, rfl⟩ := hx exact (mem_filter.mp hv).2) have hcardim : ∀ g ∈ Gs', ((isoDom B g).image (isoApp g)).card = (isoDom B g).card := fun g hg => card_image_of_injective _ (isoApp_inj (hG g hg)) rw [sum_congr rfl hcardim] at hsi have h1 : κ₂ * B.card * Gs'.card ≤ ((∑ g ∈ Gs', (isoDom B g).card : ℕ) : ℝ) := by push_cast have := sum_le_sum (fun g hg => hdom g hg) rw [sum_const, nsmul_eq_mul] at this linarith have h2 : ((∑ g ∈ Gs', (isoDom B g).card : ℕ) : ℝ) ^ 2 ≤ B.card * ∑ g ∈ Gs', ∑ g' ∈ Gs', (((isoDom B g).image (isoApp g) ∩ (isoDom B g').image (isoApp g')).card : ℝ) := by exact_mod_cast hsi have h3 : ∑ g ∈ Gs', ∑ g' ∈ Gs', (((isoDom B g).image (isoApp g) ∩ (isoDom B g').image (isoApp g')).card : ℝ) ≤ ∑ p ∈ Gs' ×ˢ Gs', ((isoDom B (isoComp (isoInv p.2) p.1)).card : ℝ) := by rw [sum_product] exact sum_le_sum (fun g hg => sum_le_sum (fun g' hg' => by exact_mod_cast hdomG g hg g' hg')) have h4 : (κ₂ * B.card * Gs'.card) ^ 2 ≤ ((∑ g ∈ Gs', (isoDom B g).card : ℕ) : ℝ) ^ 2 := pow_le_pow_left₀ (by positivity) h1 2 have h5 : (κ₂ * B.card * Gs'.card) ^ 2 = (B.card : ℝ) * (κ₂ ^ 2 * B.card * Gs'.card ^ 2) := by ring rw [h5] at h4 have h6 := le_trans h4 (le_trans h2 (mul_le_mul_of_nonneg_left h3 (Nat.cast_nonneg _))) exact le_of_mul_le_mul_left h6 hN have hrich := rich_pairs Gs' (fun p => ((isoDom B (isoComp (isoInv p.2) p.1)).card : ℝ)) hN (sq_nonneg κ₂) (fun p _ => by exact_mod_cast card_le_card (isoDom_sub B _)) himsum hG2 obtain ⟨Rich, hRich⟩ : ∃ Rich : Finset ((ℂ × ℂ) × (ℂ × ℂ)), Rich = (Gs' ×ˢ Gs').filter (fun p => p.1 ≠ p.2 ∧ κ₂ ^ 2 / 4 * B.card ≤ ((isoDom B (isoComp (isoInv p.2) p.1)).card : ℝ)) := ⟨_, rfl⟩ have hrich' : κ₂ ^ 2 * Gs'.card ^ 2 / 4 ≤ (Rich.card : ℝ) := by rw [hRich]; exact hrich obtain ⟨R, hR⟩ : ∃ R : Finset (ℂ × ℂ), R = Rich.image (fun p => isoComp (isoInv p.2) p.1) := ⟨_, rfl⟩ refine ⟨R, ?_, ?_⟩ · intro k hk rw [hR, mem_image] at hk obtain ⟨p, hp, rfl⟩ := hk rw [hRich, mem_filter, mem_product] at hp obtain ⟨⟨hp1, hp2⟩, hne, hbig⟩ := hp have hu1 := hG p.1 hp1 have hu2 := hG p.2 hp2 have hfz := hcen p.1 hp1 p.2 hp2 refine ⟨isoComp_unit (isoInv_unit hu2) hu1, ?_, hfz, hbig⟩ intro h1 apply hne have hk2 : (isoComp (isoInv p.2) p.1).2 = 0 := by unfold isoApp at hfz rw [h1, one_mul] at hfz linear_combination hfz have hkid : isoComp (isoInv p.2) p.1 = (1, 0) := Prod.ext h1 hk2 have := isoComp_inv_cancel (g := p.1) hu2 rw [hkid] at this unfold isoComp at this rw [← this] simp · have hfib : ∀ r ∈ Rich.image (fun p => isoComp (isoInv p.2) p.1), (Rich.filter (fun p => isoComp (isoInv p.2) p.1 = r)).card ≤ Gs'.card := by intro r _ refine card_le_card_of_injOn (fun p => p.2) ?_ ?_ · intro p hp rw [mem_coe, mem_filter, hRich, mem_filter, mem_product] at hp exact hp.1.1.2 · intro p hp p' hp' h rw [mem_coe, mem_filter, hRich, mem_filter, mem_product] at hp hp' have h2 : p.2 = p'.2 := h have hu := hG p.2 hp.1.1.2 have h1 : p.1 = p'.1 := by have e1 := isoComp_inv_cancel (g := p.1) hu have e2 := isoComp_inv_cancel (g := p'.1) hu rw [hp.2] at e1 rw [h2, hp'.2] at e2 rw [← h2] at e2 rw [← e1, ← e2] exact Prod.ext h1 h2 have h1 := card_le_mul_card_image Rich Gs'.card hfib rw [← hR] at h1 have h2 : (Rich.card : ℝ) ≤ Gs'.card * R.card := by exact_mod_cast h1 have hG'pos : (0 : ℝ) < Gs'.card := by by_contra h; push_neg at h have : (Gs'.card : ℝ) = 0 := le_antisymm h (Nat.cast_nonneg _) rw [this] at hG2; linarith have h3 : κ₂ ^ 2 * Gs'.card / 4 * Gs'.card ≤ R.card * Gs'.card := by nlinarith exact le_of_mul_le_mul_right h3 hG'pos end Erdos94ThmA /-! ### LEAN-5 Q3e: GLIDE Theorem 15.5 ((CEN) for rich isometry families of a (T)-set), assembled -/ namespace Erdos94ThmA open Finset /-- The size conditions of Theorem 15.5 (AUDIT3 §128's `N₀`, plus `N ≥ 8/κ₂²` for Lemma 14.5 with `τ = κ₂²/8`). -/ theorem thm155_sizes {κ₁ κ₂ N : ℝ} (hκ₁ : 0 < κ₁) (hκ₂ : 0 < κ₂) (hκ₂1 : κ₂ ≤ 1) {M : ℕ} (hM : M = ⌈8 / κ₂ ^ 4⌉₊) {L : ℝ} (hL : L = 4 / (κ₁ * κ₂ ^ 4) + 8 / κ₂ ^ 4 + 72 / (κ₁ * κ₂ ^ 10) + 8 / κ₂ ^ 2) (hN : ((⌈L⌉₊ + M * M + 1 : ℕ) : ℝ) ≤ N) : 0 < N ∧ 4 < κ₁ * κ₂ ^ 4 * N ∧ 8 ≤ κ₂ ^ 4 * N ∧ (M : ℝ) * M < N ∧ 72 ≤ κ₁ * κ₂ ^ 10 * N ∧ 8 ≤ κ₂ ^ 2 * N ∧ 8 ≤ (M : ℝ) * κ₂ ^ 4 ∧ (M : ℝ) * κ₂ ^ 4 ≤ 9 := by push_cast at hN have hc := Nat.le_ceil L have hMM : (0 : ℝ) ≤ (M : ℝ) * M := by positivity have hk4 : 0 < κ₂ ^ 4 := by positivity have hk2 : 0 < κ₂ ^ 2 := by positivity have hk10 : 0 < κ₂ ^ 10 := by positivity have t1 : 0 ≤ 4 / (κ₁ * κ₂ ^ 4) := by positivity have t2 : 0 ≤ 8 / κ₂ ^ 4 := by positivity have t3 : 0 ≤ 72 / (κ₁ * κ₂ ^ 10) := by positivity have t4 : 0 ≤ 8 / κ₂ ^ 2 := by positivity have hLN : L + 1 ≤ N := by linarith have hN0 : 0 < N := by linarith refine ⟨hN0, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · have : 4 / (κ₁ * κ₂ ^ 4) < N := by linarith rw [div_lt_iff₀ (by positivity)] at this; linarith · have : 8 / κ₂ ^ 4 ≤ N := by linarith rw [div_le_iff₀ hk4] at this; linarith · have : (0 : ℝ) ≤ ⌈L⌉₊ := Nat.cast_nonneg _ linarith · have : 72 / (κ₁ * κ₂ ^ 10) ≤ N := by linarith rw [div_le_iff₀ (by positivity)] at this; linarith · have : 8 / κ₂ ^ 2 ≤ N := by linarith rw [div_le_iff₀ hk2] at this; linarith · have : 8 / κ₂ ^ 4 ≤ M := by rw [hM]; exact Nat.le_ceil _ rw [div_le_iff₀ hk4] at this; linarith · have h1 : (M : ℝ) < 8 / κ₂ ^ 4 + 1 := by rw [hM]; exact Nat.ceil_lt_add_one (by positivity) have h2 : κ₂ ^ 4 ≤ 1 := pow_le_one₀ hκ₂.le hκ₂1 have h3 : (M : ℝ) * κ₂ ^ 4 < (8 / κ₂ ^ 4 + 1) * κ₂ ^ 4 := mul_lt_mul_of_pos_right h1 hk4 have h4 : (8 / κ₂ ^ 4 + 1) * κ₂ ^ 4 = 8 + κ₂ ^ 4 := by field_simp linarith /-- Arithmetic of the circle count. -/ theorem arith155_d {κ₁ κ₂ N R c : ℝ} (hκ₁ : 0 < κ₁) (hκ₂ : 0 < κ₂) (hN : 0 < N) (hR : κ₁ * κ₂ ^ 10 / 160 * N ≤ R) (hc : c * (R * (κ₂ ^ 2 / 8)) ≤ 2 * N) (hc0 : 0 ≤ c) : c ≤ 2560 / (κ₁ * κ₂ ^ 12) := by have hpos : (0 : ℝ) < κ₁ * κ₂ ^ 12 := by positivity rw [le_div_iff₀ hpos] have h1 : c * (κ₁ * κ₂ ^ 10 / 160 * N * (κ₂ ^ 2 / 8)) ≤ c * (R * (κ₂ ^ 2 / 8)) := mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right hR (by positivity)) hc0 have e : c * (κ₁ * κ₂ ^ 10 / 160 * N * (κ₂ ^ 2 / 8)) = c * (κ₁ * κ₂ ^ 12) / 1280 * N := by ring have h3 : c * (κ₁ * κ₂ ^ 12) / 1280 * N ≤ 2 * N := by linarith have h4 : c * (κ₁ * κ₂ ^ 12) / 1280 ≤ 2 := by by_contra hcon push_neg at hcon have := mul_lt_mul_of_pos_right hcon hN linarith linarith /-- Arithmetic of the covered points. -/ theorem arith155_e {κ₁ κ₂ N R P : ℝ} (hκ₂ : 0 < κ₂) (hR : κ₁ * κ₂ ^ 10 / 160 * N ≤ R) (hP : R * (κ₂ ^ 2 / 8) / 2 ≤ P) : κ₁ * κ₂ ^ 12 / 2560 * N ≤ P := by have h1 : κ₁ * κ₂ ^ 10 / 160 * N * (κ₂ ^ 2 / 8) / 2 ≤ R * (κ₂ ^ 2 / 8) / 2 := by have := mul_le_mul_of_nonneg_right hR (by positivity : (0 : ℝ) ≤ κ₂ ^ 2 / 8) linarith have e : κ₁ * κ₂ ^ 10 / 160 * N * (κ₂ ^ 2 / 8) / 2 = κ₁ * κ₂ ^ 12 / 2560 * N := by ring linarith /-- Arithmetic of step (3): `|Gs₁| ≥ κ₂⁴|𝒢|/4`, `|Gs₁| ≤ M|Gs′|`, `Mκ₂⁴ ≤ 9` ⇒ `|Gs′| ≥ κ₂⁸|𝒢|/36`. -/ theorem arith155_a {κ₂ G G₁ G' M : ℝ} (hk4 : 0 < κ₂ ^ 4) (hG₁ : κ₂ ^ 4 / 2 / 2 * G ≤ G₁) (hG₁' : G₁ ≤ M * G') (hM9 : M * κ₂ ^ 4 ≤ 9) (hG' : 0 ≤ G') : κ₂ ^ 8 * G / 36 ≤ G' := by have h1 : κ₂ ^ 4 * (κ₂ ^ 4 / 2 / 2 * G) ≤ κ₂ ^ 4 * (M * G') := mul_le_mul_of_nonneg_left (le_trans hG₁ hG₁') hk4.le have h2 : κ₂ ^ 4 * (M * G') ≤ 9 * G' := by have := mul_le_mul_of_nonneg_right hM9 hG' linarith have e : κ₂ ^ 4 * (κ₂ ^ 4 / 2 / 2 * G) = κ₂ ^ 8 * G / 4 := by ring linarith /-- Arithmetic of step (5): `|Gs′| ≥ κ₂⁸|𝒢|/36`, `|𝒢| ≥ κ₁N`, `κ₁κ₂¹⁰N ≥ 72` ⇒ `κ₂²|Gs′| ≥ 2`. -/ theorem arith155_b {κ₁ κ₂ N G G' : ℝ} (hk2 : 0 < κ₂ ^ 2) (hk10 : 0 < κ₂ ^ 10) (hG' : κ₂ ^ 8 * G / 36 ≤ G') (hGc : κ₁ * N ≤ G) (hNd : 72 ≤ κ₁ * κ₂ ^ 10 * N) : 2 ≤ κ₂ ^ 2 * G' := by have h1 : κ₂ ^ 2 * (κ₂ ^ 8 * G / 36) ≤ κ₂ ^ 2 * G' := mul_le_mul_of_nonneg_left hG' hk2.le have h2 : κ₂ ^ 10 * (κ₁ * N) ≤ κ₂ ^ 10 * G := mul_le_mul_of_nonneg_left hGc hk10.le have e1 : κ₂ ^ 2 * (κ₂ ^ 8 * G / 36) = κ₂ ^ 10 * G / 36 := by ring have e2 : κ₂ ^ 10 * (κ₁ * N) = κ₁ * κ₂ ^ 10 * N := by ring linarith /-- Arithmetic of the rotation count: `|R| ≥ κ₂²|Gs′|/4 ≥ κ₁κ₂¹⁰N/144 ≥ κ₁κ₂¹⁰N/160`. -/ theorem arith155_c {κ₁ κ₂ N G G' R : ℝ} (hk2 : 0 < κ₂ ^ 2) (hk10 : 0 < κ₂ ^ 10) (hκ₁ : 0 < κ₁) (hN : 0 < N) (hG' : κ₂ ^ 8 * G / 36 ≤ G') (hGc : κ₁ * N ≤ G) (hR : κ₂ ^ 2 * G' / 4 ≤ R) : κ₁ * κ₂ ^ 10 / 160 * N ≤ R := by have h1 : κ₂ ^ 2 * (κ₂ ^ 8 * G / 36) ≤ κ₂ ^ 2 * G' := mul_le_mul_of_nonneg_left hG' hk2.le have h2 : κ₂ ^ 10 * (κ₁ * N) ≤ κ₂ ^ 10 * G := mul_le_mul_of_nonneg_left hGc hk10.le have e1 : κ₂ ^ 2 * (κ₂ ^ 8 * G / 36) = κ₂ ^ 10 * G / 36 := by ring have e2 : κ₂ ^ 10 * (κ₁ * N) = κ₁ * κ₂ ^ 10 * N := by ring have h3 : 0 ≤ κ₁ * κ₂ ^ 10 * N := by positivity linarith open Classical in /-- **GLIDE Theorem 15.5, steps (1)–(5)**, under explicit size conditions: a centre `z` with `≥ κ₁κ₂¹⁰N/160` distinct non-trivial rotations about it, each with `|dom| ≥ κ₂²N/4`. -/ theorem thm155_rot {κ₁ κ₂ : ℝ} (hκ₁ : 0 < κ₁) (hκ₂ : 0 < κ₂) {B : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) {Gs : Finset (ℂ × ℂ)} (hG : ∀ g ∈ Gs, ‖g.1‖ = 1) (hGc : κ₁ * B.card ≤ Gs.card) (hdom : ∀ g ∈ Gs, κ₂ * B.card ≤ (isoDom B g).card) {M : ℕ} (hN0 : (0 : ℝ) < B.card) (hNa : 4 < κ₁ * κ₂ ^ 4 * B.card) (hN8 : 8 ≤ κ₂ ^ 4 * B.card) (hNM : (M : ℝ) * M < B.card) (hNd : 72 ≤ κ₁ * κ₂ ^ 10 * B.card) (hM8 : 8 ≤ (M : ℝ) * κ₂ ^ 4) (hM9 : (M : ℝ) * κ₂ ^ 4 ≤ 9) : ∃ z : ℂ, ∃ R : Finset (ℂ × ℂ), (∀ k ∈ R, ‖k.1‖ = 1 ∧ k.1 ≠ 1 ∧ isoApp k z = z ∧ κ₂ ^ 2 / 4 * B.card ≤ (isoDom B k).card) ∧ κ₁ * κ₂ ^ 10 / 160 * B.card ≤ R.card := by have hk2 : 0 < κ₂ ^ 2 := by positivity have hk4 : 0 < κ₂ ^ 4 := by positivity have hk10 : 0 < κ₂ ^ 10 := by positivity have hG4 : 4 ≤ κ₂ ^ 4 * Gs.card := by have h1 := mul_le_mul_of_nonneg_left hGc hk4.le have e : κ₂ ^ 4 * (κ₁ * B.card) = κ₁ * κ₂ ^ 4 * B.card := by ring linarith obtain ⟨h₀, hh₀, k₀, hk₀, hhk, hbig⟩ := step2_pair hT hG hκ₂ hN0 hG4 hN8 hdom obtain ⟨ψ, hψ⟩ : ∃ ψ : ℂ × ℂ, ψ = isoComp (isoInv h₀) k₀ := ⟨_, rfl⟩ rw [← hψ] at hbig have hψu : ‖ψ.1‖ = 1 := by rw [hψ]; exact isoComp_unit (isoInv_unit (hG h₀ hh₀)) (hG k₀ hk₀) have hψ1 : ψ.1 ≠ 1 := by intro h1 apply hhk rw [hψ] at h1 unfold isoComp isoInv at h1 simp only at h1 have := (unit_facts (hG h₀ hh₀)).1 linear_combination k₀.1 * this - h₀.1 * h1 have hmk := markov_big Gs (fun g => ((isoDom B (isoConj g ψ)).card : ℝ)) hN0 (by positivity : (0 : ℝ) ≤ κ₂ ^ 4 / 2) (fun g _ => by exact_mod_cast card_le_card (isoDom_sub B _)) (by linarith) obtain ⟨Gs₁, hGs₁⟩ : ∃ Gs₁ : Finset (ℂ × ℂ), Gs₁ = Gs.filter (fun g => κ₂ ^ 4 / 2 * (B.card : ℝ) / 2 ≤ ((isoDom B (isoConj g ψ)).card : ℝ)) := ⟨_, rfl⟩ have hGs₁c : κ₂ ^ 4 / 2 / 2 * (Gs.card : ℝ) ≤ Gs₁.card := by rw [hGs₁]; exact hmk have hGs₁sub : ∀ g ∈ Gs₁, g ∈ Gs ∧ κ₂ ^ 4 / 2 * (B.card : ℝ) / 2 ≤ ((isoDom B (isoConj g ψ)).card : ℝ) := by intro g hg; rw [hGs₁] at hg; exact mem_filter.mp hg have hGpos : (0 : ℝ) < Gs.card := by by_contra h; push_neg at h have : (Gs.card : ℝ) = 0 := le_antisymm h (Nat.cast_nonneg _) rw [this] at hG4; linarith have hGs₁ne : Gs₁.Nonempty := by have : (0 : ℝ) < Gs₁.card := lt_of_lt_of_le (by positivity) hGs₁c exact card_pos.mp (by exact_mod_cast this) have hMa : 2 * (B.card : ℝ) ≤ M * (κ₂ ^ 4 / 2 * (B.card : ℝ) / 2) := by have := mul_le_mul_of_nonneg_right hM8 hN0.le have e : (M : ℝ) * (κ₂ ^ 4 / 2 * (B.card : ℝ) / 2) = (M * κ₂ ^ 4) * B.card / 4 := by ring rw [e]; linarith obtain ⟨ψ', hψ'⟩ := step3_value hT (fun g hg => hG g (hGs₁sub g hg).1) hψu (M := M) (a := κ₂ ^ 4 / 2 * (B.card : ℝ) / 2) hMa hNM (fun g hg => (hGs₁sub g hg).2) hGs₁ne obtain ⟨Gs', hGs'⟩ : ∃ Gs' : Finset (ℂ × ℂ), Gs' = Gs₁.filter (fun g => isoConj g ψ = ψ') := ⟨_, rfl⟩ rw [← hGs'] at hψ' have hGs'sub : ∀ g ∈ Gs', g ∈ Gs ∧ isoConj g ψ = ψ' := by intro g hg rw [hGs'] at hg exact ⟨(hGs₁sub g (mem_filter.mp hg).1).1, (mem_filter.mp hg).2⟩ have hG'big := arith155_a hk4 hGs₁c hψ' hM9 (Nat.cast_nonneg _) have hcen : ∀ g ∈ Gs', ∀ g' ∈ Gs', isoApp (isoComp (isoInv g') g) (ψ.2 / (1 - ψ.1)) = ψ.2 / (1 - ψ.1) := by intro g hg g' hg' exact step4_centre hψ1 (hG g (hGs'sub g hg).1) (hG g' (hGs'sub g' hg').1) ((hGs'sub g hg).2.trans (hGs'sub g' hg').2.symm) have hG2 := arith155_b hk2 hk10 hG'big hGc hNd obtain ⟨R, hRprop, hRc⟩ := step5_rich (fun g hg => hG g (hGs'sub g hg).1) hcen hκ₂ hN0 (fun g hg => hdom g (hGs'sub g hg).1) hG2 exact ⟨ψ.2 / (1 - ψ.1), R, hRprop, arith155_c hk2 hk10 hκ₁ hN0 hG'big hGc hRc⟩ open Classical in /-- **GLIDE Theorem 15.5 ((CEN) for rich isometry families)** [audited CORRECT WITH FIXES, AUDIT3 §128]. Let `B ⊂ ℂ` satisfy (T) (no non-trivial translation maps 3 points of `B` into `B`) and let `𝒢` be a finite set of orientation-preserving isometries `z ↦ az + b` (`‖a‖ = 1`, as pairs `(a, b)`) with `|𝒢| ≥ κ₁N` and `|dom g| ≥ κ₂N` for all `g` (`dom g = {v ∈ B : g(v) ∈ B}`, `N = |B|`). Then for `N ≥ N₀(κ₁, κ₂)` there is a point `z` that is the centre of `≥ κ₁κ₂¹⁰N/160` distinct non-trivial rotations with `|dom| ≥ κ₂²N/4`, and `≥ κ₁κ₂¹²N/2560` points of `B` lie on `≤ 2560/(κ₁κ₂¹²)` circles about `z`. Audit fixes applied: step (0) is not used (deleted); Lemma 14.5 is applied with `τ = κ₂²/8` so that the centre may lie in `B` (hence `2560` in place of the paper's `1280`). -/ theorem thm155 {κ₁ κ₂ : ℝ} (hκ₁ : 0 < κ₁) (hκ₂ : 0 < κ₂) (hκ₂1 : κ₂ ≤ 1) : ∃ N₀ : ℕ, ∀ B : Finset ℂ, N₀ ≤ B.card → (∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) → ∀ Gs : Finset (ℂ × ℂ), (∀ g ∈ Gs, ‖g.1‖ = 1) → κ₁ * B.card ≤ Gs.card → (∀ g ∈ Gs, κ₂ * B.card ≤ (isoDom B g).card) → ∃ z : ℂ, (∃ R : Finset (ℂ × ℂ), (∀ k ∈ R, ‖k.1‖ = 1 ∧ k.1 ≠ 1 ∧ isoApp k z = z ∧ κ₂ ^ 2 / 4 * B.card ≤ (isoDom B k).card) ∧ κ₁ * κ₂ ^ 10 / 160 * B.card ≤ R.card) ∧ ∃ ρs : Finset ℝ, (∀ ρ ∈ ρs, 0 < ρ) ∧ (ρs.card : ℝ) ≤ 2560 / (κ₁ * κ₂ ^ 12) ∧ κ₁ * κ₂ ^ 12 / 2560 * B.card ≤ (B.filter (fun x => ‖x - z‖ ∈ ρs)).card := by obtain ⟨M, hM⟩ : ∃ M : ℕ, M = ⌈8 / κ₂ ^ 4⌉₊ := ⟨_, rfl⟩ obtain ⟨L, hL⟩ : ∃ L : ℝ, L = 4 / (κ₁ * κ₂ ^ 4) + 8 / κ₂ ^ 4 + 72 / (κ₁ * κ₂ ^ 10) + 8 / κ₂ ^ 2 := ⟨_, rfl⟩ refine ⟨⌈L⌉₊ + M * M + 1, ?_⟩ intro B hN hT Gs hG hGc hdom obtain ⟨hN0, hNa, hN8, hNM, hNd, hNe, hM8, hM9⟩ := thm155_sizes hκ₁ hκ₂ hκ₂1 hM hL (N := B.card) (by exact_mod_cast hN) obtain ⟨z, R, hRprop, hRbig⟩ := thm155_rot hκ₁ hκ₂ hT hG hGc hdom hN0 hNa hN8 hNM hNd hM8 hM9 have hR145 : ∀ k ∈ R, ‖k.1‖ = 1 ∧ k.1 ≠ 1 ∧ isoApp k z = z ∧ κ₂ ^ 2 / 8 * B.card + 1 ≤ (isoDom B k).card := by intro k hk obtain ⟨a1, a2, a3, a4⟩ := hRprop k hk refine ⟨a1, a2, a3, ?_⟩ have e : κ₂ ^ 2 / 4 * (B.card : ℝ) = κ₂ ^ 2 / 8 * B.card + κ₂ ^ 2 * B.card / 8 := by ring linarith obtain ⟨ρs, hρpos, hρcard, hρcov⟩ := lemma145 (by positivity : (0 : ℝ) < κ₂ ^ 2 / 8) hR145 exact ⟨z, ⟨R, hRprop, hRbig⟩, ρs, hρpos, arith155_d hκ₁ hκ₂ hN0 hRbig hρcard (Nat.cast_nonneg _), arith155_e hκ₂ hRbig hρcov⟩ end Erdos94ThmA /-! ### LEAN-5 Q7: INVERSE Lemma 11.28 (deleting δn vertices keeps (NF)) and Cor. 11.29 (the fat-subset case) -/ namespace Erdos94ThmA open Finset /-- `NFconcl` is monotone in `ε`. -/ theorem nfconcl_mono {ε ε' : ℝ} (h : ε ≤ ε') {P : Finset (EuclideanSpace ℝ (Fin 2))} (hP : NFconcl ε P) : NFconcl ε' P := by obtain ⟨U, hU, hf⟩ := hP refine ⟨U, le_trans (mul_le_mul_of_nonneg_right (by linarith) (Nat.cast_nonneg _)) hU, fun u hu => ?_⟩ exact le_trans (mul_le_mul_of_nonneg_right (by linarith) (Nat.cast_nonneg _)) (hf u hu) /-- Convex independence passes to subsets. -/ theorem convexIndep_subset {P P' : Finset (EuclideanSpace ℝ (Fin 2))} (hsub : P' ⊆ P) (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) : EuclideanGeometry.ConvexIndep (P' : Set (EuclideanSpace ℝ (Fin 2))) := by intro a ha h exact hP a (hsub ha) (convexHull_mono (Set.diff_subset_diff_left (coe_subset.mpr hsub)) h) open Classical in /-- Ordered `u`-pairs of `P ∖ E` = ordered `u`-pairs of `P` avoiding `E`. -/ theorem offDiag_sdiff_filter (P E : Finset (EuclideanSpace ℝ (Fin 2))) (u : ℝ) : (P \ E).offDiag.filter (fun p => dist p.1 p.2 = u) = (P.offDiag.filter (fun p => dist p.1 p.2 = u)).filter (fun p => ¬ (p.1 ∈ E ∨ p.2 ∈ E)) := by ext p simp only [mem_filter, mem_offDiag, mem_sdiff] tauto open Classical in /-- **INVERSE Lemma 11.28 (robust needles: deleting `δn` vertices keeps (NF))** [audited INV3-A2, AUDIT2 §108–§109]. If `P` has `(NF_ε)` and `E ⊆ P` with `|E| ≤ δn` (`δ > 0`), then `P ∖ E` has `(NF_{ε+√δ})` (with respect to its own size `n′ = |P ∖ E|`). Proof: the ordered `u`-pairs meeting `E` total `≤ 2|E|n`, so `< √δ·n` classes lose more than `2√δ·n` ordered pairs; every other near-full class keeps `f ≥ (1 − ε − √δ)n ≥ (1 − ε − √δ)n′`. -/ theorem nf_delete {P E : Finset (EuclideanSpace ℝ (Fin 2))} (hEP : E ⊆ P) {ε δ : ℝ} (hε0 : 0 ≤ ε) (hδ0 : 0 < δ) (hE : (E.card : ℝ) ≤ δ * P.card) (hNF : NFconcl ε P) : NFconcl (ε + Real.sqrt δ) (P \ E) := by obtain ⟨U, hU, hf⟩ := hNF have hsq : 0 < Real.sqrt δ := Real.sqrt_pos.mpr hδ0 have hsq2 : Real.sqrt δ * Real.sqrt δ = δ := Real.mul_self_sqrt hδ0.le rcases Nat.eq_zero_or_pos P.card with hP0 | hPpos · -- empty P: everything is trivial have hPe : P = ∅ := card_eq_zero.mp hP0 refine ⟨U, ?_, fun u _ => ?_⟩ · rw [hPe, empty_sdiff, card_empty]; simp · rw [hPe, empty_sdiff, card_empty]; simp have hN : (0 : ℝ) < P.card := by exact_mod_cast hPpos -- D(u) = ordered u-pairs of P meeting E obtain ⟨D, hD⟩ : ∃ D : ℝ → ℕ, D = fun u => ((P.offDiag.filter (fun p => dist p.1 p.2 = u)).filter (fun p => p.1 ∈ E ∨ p.2 ∈ E)).card := ⟨_, rfl⟩ have hsplit : ∀ u, (P.offDiag.filter (fun p => dist p.1 p.2 = u)).card = ((P \ E).offDiag.filter (fun p => dist p.1 p.2 = u)).card + D u := by intro u rw [offDiag_sdiff_filter, hD, add_comm] exact (card_filter_add_card_filter_not _).symm -- Σ_{u∈U} D(u) ≤ 2|E|n have hDsum : (∑ u ∈ U, (D u : ℝ)) ≤ 2 * E.card * P.card := by have h1 : ∑ u ∈ U, D u ≤ (P.offDiag.filter (fun p => p.1 ∈ E ∨ p.2 ∈ E)).card := by have e : ∀ u ∈ U, D u = ((P.offDiag.filter (fun p => p.1 ∈ E ∨ p.2 ∈ E)).filter (fun p => dist p.1 p.2 = u)).card := by intro u _ rw [hD] simp only congr 1 ext p simp only [mem_filter] tauto rw [sum_congr rfl e, ← card_biUnion] · apply card_le_card intro p hp rw [mem_biUnion] at hp obtain ⟨u, _, hp⟩ := hp exact (mem_filter.mp hp).1 · intro u _ u' _ huu' rw [Function.onFun, disjoint_filter] intro p _ h1 h2 exact huu' (h1.symm.trans h2) have h2 : (P.offDiag.filter (fun p => p.1 ∈ E ∨ p.2 ∈ E)) ⊆ (E ×ˢ P) ∪ (P ×ˢ E) := by intro p hp rw [mem_filter, mem_offDiag] at hp rw [mem_union, mem_product, mem_product] rcases hp.2 with h | h · exact Or.inl ⟨h, hp.1.2.1⟩ · exact Or.inr ⟨hp.1.1, h⟩ have h3 := le_trans h1 (le_trans (card_le_card h2) (card_union_le _ _)) rw [card_product, card_product] at h3 have h4 : ((∑ u ∈ U, D u : ℕ) : ℝ) ≤ ((E.card * P.card + P.card * E.card : ℕ) : ℝ) := by exact_mod_cast h3 push_cast at h4 linarith -- the bad classes obtain ⟨Ub, hUb⟩ : ∃ Ub : Finset ℝ, Ub = U.filter (fun u => 2 * Real.sqrt δ * P.card < D u) := ⟨_, rfl⟩ obtain ⟨Ug, hUg⟩ : ∃ Ug : Finset ℝ, Ug = U.filter (fun u => ¬ (2 * Real.sqrt δ * P.card < D u)) := ⟨_, rfl⟩ have hUsplit : (Ub.card : ℝ) + Ug.card = U.card := by rw [hUb, hUg]; exact_mod_cast card_filter_add_card_filter_not _ have hUb_le : (Ub.card : ℝ) ≤ Real.sqrt δ * P.card := by have h1 : (Ub.card : ℝ) * (2 * Real.sqrt δ * P.card) ≤ ∑ u ∈ Ub, (D u : ℝ) := by have := sum_le_sum (fun u (hu : u ∈ Ub) => (by rw [hUb] at hu; exact (mem_filter.mp hu).2.le : 2 * Real.sqrt δ * P.card ≤ (D u : ℝ))) rw [sum_const, nsmul_eq_mul] at this exact this have h2 : ∑ u ∈ Ub, (D u : ℝ) ≤ ∑ u ∈ U, (D u : ℝ) := sum_le_sum_of_subset_of_nonneg (by rw [hUb]; exact filter_subset _ _) (fun _ _ _ => Nat.cast_nonneg _) have h3 : (Ub.card : ℝ) * (2 * Real.sqrt δ * P.card) ≤ 2 * (Real.sqrt δ * P.card) * (Real.sqrt δ * P.card) := by have : 2 * (E.card : ℝ) * P.card ≤ 2 * (δ * P.card) * P.card := by nlinarith have e : 2 * (Real.sqrt δ * P.card) * (Real.sqrt δ * P.card) = 2 * (δ * P.card) * P.card := by linear_combination 2 * (P.card : ℝ) ^ 2 * hsq2 linarith have hpos : 0 < 2 * Real.sqrt δ * P.card := by positivity have h4 : (Ub.card : ℝ) * (2 * Real.sqrt δ * P.card) ≤ (Real.sqrt δ * P.card) * (2 * Real.sqrt δ * P.card) := by linarith exact le_of_mul_le_mul_right h4 hpos have hn' : ((P \ E).card : ℝ) ≤ P.card := by exact_mod_cast card_le_card sdiff_subset have hn'0 : (0 : ℝ) ≤ (P \ E).card := Nat.cast_nonneg _ refine ⟨Ug, ?_, fun u hu => ?_⟩ · -- (1/2 − ε − √δ)n′ ≤ |Ug| have h1 : (1 / 2 - ε - Real.sqrt δ) * P.card ≤ Ug.card := by nlinarith rcases le_or_gt 0 (1 / 2 - (ε + Real.sqrt δ)) with hc | hc · have := mul_le_mul_of_nonneg_left hn' hc linarith · have h2 : (1 / 2 - (ε + Real.sqrt δ)) * ((P \ E).card : ℝ) ≤ 0 := mul_nonpos_of_nonpos_of_nonneg hc.le hn'0 have h3 : (0 : ℝ) ≤ Ug.card := Nat.cast_nonneg _ linarith · -- f_{P∖E}(u) ≥ (1 − ε − √δ)n′ have huU : u ∈ U := by rw [hUg] at hu; exact (mem_filter.mp hu).1 have hDu : (D u : ℝ) ≤ 2 * Real.sqrt δ * P.card := by rw [hUg] at hu; exact not_lt.mp (mem_filter.mp hu).2 have hfu := hf u huU have hm1 := Erdos94Infra.mult_cast P u have hm2 := Erdos94Infra.mult_cast (P \ E) u have hs := hsplit u have hs' : ((P.offDiag.filter (fun p => dist p.1 p.2 = u)).card : ℝ) = (((P \ E).offDiag.filter (fun p => dist p.1 p.2 = u)).card : ℝ) + D u := by exact_mod_cast hs have h1 : (1 - ε - Real.sqrt δ) * P.card ≤ distanceMultiplicity (P \ E) u := by rw [hm2] rw [hm1] at hfu linarith rcases le_or_gt 0 (1 - (ε + Real.sqrt δ)) with hc | hc · have := mul_le_mul_of_nonneg_left hn' hc linarith · have h2 : (1 - (ε + Real.sqrt δ)) * ((P \ E).card : ℝ) ≤ 0 := mul_nonpos_of_nonpos_of_nonneg hc.le hn'0 have h3 : (0 : ℝ) ≤ distanceMultiplicity (P \ E) u := Nat.cast_nonneg _ linarith open Classical in /-- **INVERSE Corollary 11.29 (the needle case is only the ROBUST needle case)** [audited INV3-A2]. For every `ζ₀ > 0` and `θ > 0` there are `ε₁ > 0` and `δ > 0` such that for `ε ≤ ε₁` and all large `n`: if a convex `n`-gon `P` has `(NF_ε)` and SOME subset `P′ ⊆ P` with `|P′| ≥ (1 − δ)n` is fat (`Fat ζ₀ P′`), then `P` is near-concyclic with exception fraction `θ`. (Unweakened Thm 11.24′ `wide_thm0` for `P′` at `θ/2` and `ε + √δ`, Lemma 11.28 for the `(NF)` of `P′`, then the `≤ δn ≤ θn/2` deleted vertices.) -/ theorem cor1129 : ∀ ζ₀ : ℝ, 0 < ζ₀ → ∀ θ : ℝ, 0 < θ → ∃ ε₁ : ℝ, 0 < ε₁ ∧ ∃ δ : ℝ, 0 < δ ∧ ∀ ε : ℝ, 0 < ε → ε ≤ ε₁ → ∃ n₄ : ℕ, ∀ n ≥ n₄, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → NFconcl ε P → ∀ P' ⊆ P, (1 - δ) * (n : ℝ) ≤ P'.card → Fat ζ₀ P' → NearConcyclic θ P := by intro ζ₀ hζ₀ θ hθ obtain ⟨ε₀, hε₀, hW⟩ := wide_thm0 ζ₀ hζ₀ (θ / 2) (by positivity) obtain ⟨δ, hδ⟩ : ∃ δ : ℝ, δ = min (min (ε₀ ^ 2 / 4) (θ / 2)) (1 / 2) := ⟨_, rfl⟩ have hδ0 : 0 < δ := by rw [hδ]; exact lt_min (lt_min (by positivity) (by positivity)) (by norm_num) have hδa : δ ≤ ε₀ ^ 2 / 4 := by rw [hδ]; exact le_trans (min_le_left _ _) (min_le_left _ _) have hδb : δ ≤ θ / 2 := by rw [hδ]; exact le_trans (min_le_left _ _) (min_le_right _ _) have hδc : δ ≤ 1 / 2 := by rw [hδ]; exact min_le_right _ _ have hsqδ : Real.sqrt δ ≤ ε₀ / 2 := by rw [show ε₀ / 2 = Real.sqrt ((ε₀ / 2) ^ 2) from (Real.sqrt_sq (by positivity)).symm] exact Real.sqrt_le_sqrt (by nlinarith) refine ⟨ε₀ / 2, by positivity, δ, hδ0, fun ε hε hεle => ?_⟩ obtain ⟨n₃, hn₃⟩ := hW (ε + Real.sqrt δ) (by positivity) (by linarith) refine ⟨2 * n₃ + 1, fun n hn P hcard hP hNF P' hP'P hP'c hFat => ?_⟩ -- E = P ∖ P′ have hE : P \ (P \ P') = P' := Finset.sdiff_sdiff_eq_self hP'P have hEc : ((P \ P').card : ℝ) ≤ δ * P.card := by have h1 : (P \ P').card = P.card - P'.card := card_sdiff_of_subset hP'P have h2 : P'.card ≤ P.card := card_le_card hP'P have h3 : ((P \ P').card : ℝ) = P.card - P'.card := by rw [h1]; push_cast [h2]; ring rw [h3, hcard] linarith have hNF' := nf_delete sdiff_subset hε.le hδ0 hEc hNF rw [hE] at hNF' have hP'n : n₃ ≤ P'.card := by have h1 : ((2 * n₃ + 1 : ℕ) : ℝ) ≤ n := by exact_mod_cast hn push_cast at h1 have h2 : (n : ℝ) / 2 ≤ P'.card := by nlinarith have h3 : (n₃ : ℝ) ≤ P'.card := by linarith exact_mod_cast h3 obtain ⟨O, ρ, hρ, hk⟩ := hn₃ P'.card hP'n P' rfl (convexIndep_subset hP'P hP) hFat hNF' refine ⟨O, ρ, hρ, ?_⟩ have hsub : P.filter (fun p => dist p O ≠ ρ) ⊆ (P'.filter (fun p => dist p O ≠ ρ)) ∪ (P \ P') := by intro p hp rw [mem_filter] at hp rw [mem_union, mem_filter, mem_sdiff] by_cases h : p ∈ P' · exact Or.inl ⟨h, hp.2⟩ · exact Or.inr ⟨hp.1, h⟩ have h1 := le_trans (card_le_card hsub) (card_union_le _ _) have h2 : ((P.filter (fun p => dist p O ≠ ρ)).card : ℝ) ≤ ((P'.filter (fun p => dist p O ≠ ρ)).card : ℝ) + ((P \ P').card : ℝ) := by exact_mod_cast h1 have h3 : (P'.card : ℝ) ≤ P.card := by exact_mod_cast card_le_card hP'P have h4 : θ / 2 * (P'.card : ℝ) ≤ θ / 2 * P.card := mul_le_mul_of_nonneg_left h3 (by positivity) have h5 : δ * (P.card : ℝ) ≤ θ / 2 * P.card := mul_le_mul_of_nonneg_right hδb (Nat.cast_nonneg _) linarith end Erdos94ThmA /-! ### SOLO slice A1 -/ /-! ## SOLO module A (part 1): frames, rotated rank, half-frame rows (Brass–Pach rows in label form) -/ namespace E94S open Finset /-- Three-point lemma, upper quadrant: `a`, `b` in the open first quadrant, `b` lower and clockwise from `a`. -/ theorem tp_up {a1 a2 b1 b2 : ℝ} (hb1 : 0 < b1) (hb2 : 0 < b2) (hab : b2 < a2) (hor : 0 < a1 * b2 - a2 * b1) : b1 ^ 2 + b2 ^ 2 < a1 ^ 2 + a2 ^ 2 := by have h0 : b2 * b1 < a2 * b1 := mul_lt_mul_of_pos_right hab hb1 have h1 : b1 * b2 < a1 * b2 := by nlinarith have h2 : b1 < a1 := lt_of_mul_lt_mul_right h1 hb2.le nlinarith /-- Three-point lemma, lower quadrant. -/ theorem tp_dn {a1 a2 b1 b2 : ℝ} (ha1 : 0 < a1) (hb1 : 0 < b1) (ha2 : a2 < 0) (hab : b2 < a2) (hor : 0 < a1 * b2 - a2 * b1) : a1 ^ 2 + a2 ^ 2 < b1 ^ 2 + b2 ^ 2 := by have h0 : b2 * b1 < a2 * b1 := mul_lt_mul_of_pos_right hab hb1 have h1 : b1 * b2 < a1 * b2 := by nlinarith have hb2 : b2 < 0 := by linarith have h2 : a1 < b1 := by by_contra hcon push_neg at hcon nlinarith [mul_nonneg (sub_nonneg.mpr hcon) (neg_nonneg.mpr hb2.le)] nlinarith /-- The area functional of a frame `(X, H)`. -/ def ar (X H : ℕ → ℝ) (i j k : ℕ) : ℝ := (X j - X i) * (H k - H i) - (H j - H i) * (X k - X i) theorem ar_cyc (X H : ℕ → ℝ) (i j k : ℕ) : ar X H i j k = ar X H j k i := by unfold ar; ring /-- Bitonicity: on a convex quadrilateral `q, i, j, p` (counterclockwise) with `q` above `j` above `p`, `i` is above `j`. -/ theorem bitonic {X H : ℕ → ℝ} {q i j p : ℕ} (h1 : 0 < ar X H i j p) (h2 : 0 < ar X H q i j) (h3 : 0 < ar X H q j p) (hqj : H j < H q) (hjp : H p < H j) : H j < H i := by by_contra hcon push_neg at hcon have key : ar X H i j p * (H q - H j) + ar X H q i j * (H j - H p) + ar X H q j p * (H j - H i) = 0 := by unfold ar; ring have e1 := mul_pos h1 (sub_pos.mpr hqj) have e2 := mul_pos h2 (sub_pos.mpr hjp) have e3 := mul_nonneg h3.le (sub_nonneg.mpr hcon) linarith /-- Rotated rank: labels `≥ q` first (in order), then labels `< q`. -/ def rk (N q i : ℕ) : ℕ := if q ≤ i then i - q else i + N - q theorem rk_inj {N q i j : ℕ} (hq : q < N) (hi : i < N) (hj : j < N) (h : rk N q i = rk N q j) : i = j := by unfold rk at h split_ifs at h <;> omega theorem rk_self (N q : ℕ) : rk N q q = 0 := by unfold rk; simp /-- Orientation is positive along the rotated order. -/ theorem ar_rot {X H : ℕ → ℝ} {N : ℕ} (hor : ∀ i j k, i < j → j < k → k < N → 0 < ar X H i j k) {q i j k : ℕ} (hq : q < N) (hi : i < N) (hj : j < N) (hk : k < N) (hij : rk N q i < rk N q j) (hjk : rk N q j < rk N q k) : 0 < ar X H i j k := by unfold rk at hij hjk by_cases h1 : q ≤ i <;> by_cases h2 : q ≤ j <;> by_cases h3 : q ≤ k <;> simp only [h1, h2, h3, if_true, if_false] at hij hjk · exact hor i j k (by omega) (by omega) hk · rw [← ar_cyc] exact hor k i j (by omega) (by omega) hj · omega · rw [ar_cyc] exact hor j k i (by omega) (by omega) hi · omega · omega · omega · exact hor i j k (by omega) (by omega) hk /-- Squared frame distance. -/ def fD (X H : ℕ → ℝ) (x y : ℕ) : ℝ := (X x - X y) ^ 2 + (H x - H y) ^ 2 /-- A row `(pole, Y, increasing?)` is monotone for the frame distance. -/ def FRowOK (X H : ℕ → ℝ) (r : ℕ × Finset ℕ × Bool) : Prop := (r.1 ∉ r.2.1) ∧ ∀ y ∈ r.2.1, ∀ y' ∈ r.2.1, y < y' → if r.2.2 then fD X H r.1 y < fD X H r.1 y' else fD X H r.1 y' < fD X H r.1 y /-- A row covers the pair `{i, j}`. -/ def RCov (r : ℕ × Finset ℕ × Bool) (i j : ℕ) : Prop := (r.1 = i ∧ j ∈ r.2.1) ∨ (r.1 = j ∧ i ∈ r.2.1) open Classical in /-- The free ends of the pole `x` in the half frame with top `q` and bottom `p`: `up` = before `x` on the arc (higher), `hi` = labels `≥ q`. -/ noncomputable def hfY (I : Finset ℕ) (X : ℕ → ℝ) (N q p : ℕ) (up hi : Bool) (x : ℕ) : Finset ℕ := I.filter (fun y => (if up then rk N q y < rk N q x ∧ rk N q x ≤ rk N q p else rk N q x < rk N q y ∧ rk N q y ≤ rk N q p) ∧ X x < X y ∧ (if hi then q ≤ y else y < q)) /-- The four rows of the pole `x`: the `up` rows are decreasing in the label, the others increasing. -/ noncomputable def hfRow (I : Finset ℕ) (X : ℕ → ℝ) (N q p : ℕ) (up hi : Bool) (x : ℕ) : ℕ × Finset ℕ × Bool := (x, hfY I X N q p up hi x, !up) /-- (F1) heights decrease along the arc from the top `q` to the bottom `p`. -/ theorem hf_F1 {X H : ℕ → ℝ} {N : ℕ} (hor : ∀ i j k, i < j → j < k → k < N → 0 < ar X H i j k) {I : Finset ℕ} (hIN : ∀ i ∈ I, i < N) (hH : ∀ i ∈ I, ∀ j ∈ I, H i = H j → i = j) {q p : ℕ} (hq : q ∈ I) (hp : p ∈ I) (hqmax : ∀ i ∈ I, H i ≤ H q) (hpmin : ∀ i ∈ I, H p ≤ H i) {i j : ℕ} (hi : i ∈ I) (hj : j ∈ I) (hij : rk N q i < rk N q j) (hjp : rk N q j ≤ rk N q p) : H j < H i := by have hqN := hIN q hq have hpN := hIN p hp have hiN := hIN i hi have hjN := hIN j hj have hjq : j ≠ q := by intro h rw [h, rk_self] at hij omega have hHjq : H j < H q := lt_of_le_of_ne (hqmax j hj) (fun h => hjq (hH j hj q hq h)) by_cases hiq : i = q · rw [hiq]; exact hHjq by_cases hjp' : j = p · rw [hjp'] have hip : i ≠ p := by intro h rw [h, hjp'] at hij omega exact lt_of_le_of_ne (hpmin i hi) (fun h => hip (hH p hp i hi h).symm) have hHpj : H p < H j := lt_of_le_of_ne (hpmin j hj) (fun h => hjp' (hH p hp j hj h).symm) have hqi : rk N q q < rk N q i := by rw [rk_self] rcases Nat.eq_zero_or_pos (rk N q i) with h0 | h0 · exact absurd (rk_inj hqN hiN hqN (by rw [h0, rk_self])) hiq · exact h0 have hjp2 : rk N q j < rk N q p := lt_of_le_of_ne hjp (fun h => hjp' (rk_inj hqN hjN hpN h)) exact bitonic (ar_rot hor hqN hiN hjN hpN hij hjp2) (ar_rot hor hqN hqN hiN hjN hqi hij) (ar_rot hor hqN hqN hjN hpN (lt_trans hqi hij) hjp2) hHjq hHpj /-- Free ends before the pole on the arc: the farther back, the farther away. -/ theorem hf_up {X H : ℕ → ℝ} {N : ℕ} (hor : ∀ i j k, i < j → j < k → k < N → 0 < ar X H i j k) {I : Finset ℕ} (hIN : ∀ i ∈ I, i < N) (hH : ∀ i ∈ I, ∀ j ∈ I, H i = H j → i = j) {q p : ℕ} (hq : q ∈ I) (hp : p ∈ I) (hqmax : ∀ i ∈ I, H i ≤ H q) (hpmin : ∀ i ∈ I, H p ≤ H i) {x y y' : ℕ} (hx : x ∈ I) (hy : y ∈ I) (hy' : y' ∈ I) (hr : rk N q y < rk N q y') (hy'x : rk N q y' < rk N q x) (hxp : rk N q x ≤ rk N q p) (hXy : X x < X y) (hXy' : X x < X y') : fD X H x y' < fD X H x y := by have hHa := hf_F1 hor hIN hH hq hp hqmax hpmin hy hy' hr (le_trans hy'x.le hxp) have hHb := hf_F1 hor hIN hH hq hp hqmax hpmin hy' hx hy'x hxp have hO := ar_rot hor (hIN q hq) (hIN y hy) (hIN y' hy') (hIN x hx) hr hy'x have hO' : 0 < (X y - X x) * (H y' - H x) - (H y - H x) * (X y' - X x) := by unfold ar at hO; nlinarith [hO] have h := tp_up (a1 := X y - X x) (a2 := H y - H x) (b1 := X y' - X x) (b2 := H y' - H x) (by linarith) (by linarith) (by linarith) hO' unfold fD nlinarith [h] /-- Free ends after the pole on the arc: the farther on, the farther away. -/ theorem hf_dn {X H : ℕ → ℝ} {N : ℕ} (hor : ∀ i j k, i < j → j < k → k < N → 0 < ar X H i j k) {I : Finset ℕ} (hIN : ∀ i ∈ I, i < N) (hH : ∀ i ∈ I, ∀ j ∈ I, H i = H j → i = j) {q p : ℕ} (hq : q ∈ I) (hp : p ∈ I) (hqmax : ∀ i ∈ I, H i ≤ H q) (hpmin : ∀ i ∈ I, H p ≤ H i) {x y y' : ℕ} (hx : x ∈ I) (hy : y ∈ I) (hy' : y' ∈ I) (hxy : rk N q x < rk N q y) (hr : rk N q y < rk N q y') (hy'p : rk N q y' ≤ rk N q p) (hXy : X x < X y) (hXy' : X x < X y') : fD X H x y < fD X H x y' := by have hHa := hf_F1 hor hIN hH hq hp hqmax hpmin hx hy hxy (le_trans hr.le hy'p) have hHb := hf_F1 hor hIN hH hq hp hqmax hpmin hy hy' hr hy'p have hO := ar_rot hor (hIN q hq) (hIN x hx) (hIN y hy) (hIN y' hy') hxy hr have hO' : 0 < (X y - X x) * (H y' - H x) - (H y - H x) * (X y' - X x) := by unfold ar at hO; nlinarith [hO] have h := tp_dn (a1 := X y - X x) (a2 := H y - H x) (b1 := X y' - X x) (b2 := H y' - H x) (by linarith) (by linarith) (by linarith) (by linarith) hO' unfold fD nlinarith [h] /-- (F2) the half-frame rows are monotone in the label. -/ theorem hf_rowOK {X H : ℕ → ℝ} {N : ℕ} (hor : ∀ i j k, i < j → j < k → k < N → 0 < ar X H i j k) {I : Finset ℕ} (hIN : ∀ i ∈ I, i < N) (hH : ∀ i ∈ I, ∀ j ∈ I, H i = H j → i = j) {q p : ℕ} (hq : q ∈ I) (hp : p ∈ I) (hqmax : ∀ i ∈ I, H i ≤ H q) (hpmin : ∀ i ∈ I, H p ≤ H i) (up hi : Bool) {x : ℕ} (hx : x ∈ I) : FRowOK X H (hfRow I X N q p up hi x) := by classical have hqN := hIN q hq refine ⟨fun h => ?_, ?_⟩ · have h1 := (mem_filter.mp h).2.2.1 exact lt_irrefl _ h1 · intro y hy y' hy' hyy' have hy1 := mem_filter.mp hy have hy'1 := mem_filter.mp hy' obtain ⟨hyI, hyA, hyX, hyB⟩ := hy1 obtain ⟨hy'I, hy'A, hy'X, hy'B⟩ := hy'1 have hr : rk N q y < rk N q y' := by unfold rk cases hi · simp only [Bool.false_eq_true, if_false] at hyB hy'B rw [if_neg (not_le.mpr hyB), if_neg (not_le.mpr hy'B)]; omega · simp only [if_true] at hyB hy'B rw [if_pos hyB, if_pos hy'B]; omega cases up · simp only [Bool.false_eq_true, if_false] at hyA hy'A show (if (hfRow I X N q p false hi x).2.2 then _ else _) simp only [hfRow, Bool.not_false, if_true] exact hf_dn hor hIN hH hq hp hqmax hpmin hx hyI hy'I hyA.1 hr hy'A.2 hyX hy'X · simp only [if_true] at hyA hy'A show (if (hfRow I X N q p true hi x).2.2 then _ else _) simp only [hfRow, Bool.not_true, Bool.false_eq_true, if_false] exact hf_up hor hIN hH hq hp hqmax hpmin hx hyI hy'I hr hy'A.1 hy'A.2 hyX hy'X /-- Every pair inside the arc from `q` to `p` is covered by one of the half-frame rows. -/ theorem hf_cover {X : ℕ → ℝ} {N : ℕ} {I : Finset ℕ} (hIN : ∀ i ∈ I, i < N) (hX : ∀ i ∈ I, ∀ j ∈ I, X i = X j → i = j) {q p : ℕ} (hq : q ∈ I) {i j : ℕ} (hi : i ∈ I) (hj : j ∈ I) (hij : i ≠ j) (hip : rk N q i ≤ rk N q p) (hjp : rk N q j ≤ rk N q p) : ∃ up hi : Bool, ∃ x ∈ I, RCov (hfRow I X N q p up hi x) i j := by classical have hqN := hIN q hq have key : ∀ a ∈ I, ∀ b ∈ I, a ≠ b → rk N q a ≤ rk N q p → rk N q b ≤ rk N q p → X a < X b → ∃ up hi : Bool, b ∈ hfY I X N q p up hi a := by intro a ha b hb hab hap hbp hXab have hne : rk N q a ≠ rk N q b := fun h => hab (rk_inj hqN (hIN a ha) (hIN b hb) h) rcases lt_or_gt_of_ne hne with h | h · by_cases hqb : q ≤ b · exact ⟨false, true, mem_filter.mpr ⟨hb, by simpa using ⟨h, hbp⟩, hXab, by simpa using hqb⟩⟩ · exact ⟨false, false, mem_filter.mpr ⟨hb, by simpa using ⟨h, hbp⟩, hXab, by simpa using hqb⟩⟩ · by_cases hqb : q ≤ b · exact ⟨true, true, mem_filter.mpr ⟨hb, by simpa using ⟨h, hap⟩, hXab, by simpa using hqb⟩⟩ · exact ⟨true, false, mem_filter.mpr ⟨hb, by simpa using ⟨h, hap⟩, hXab, by simpa using hqb⟩⟩ have hXne : X i ≠ X j := fun h => hij (hX i hi j hj h) rcases lt_or_gt_of_ne hXne with h | h · obtain ⟨up, hi', h2⟩ := key i hi j hj hij hip hjp h exact ⟨up, hi', i, hi, Or.inl ⟨rfl, h2⟩⟩ · obtain ⟨up, hi', h2⟩ := key j hj i hi (Ne.symm hij) hjp hip h exact ⟨up, hi', j, hj, Or.inr ⟨rfl, h2⟩⟩ end E94S /-! ### SOLO slice A2 -/ /-! ## SOLO module A (part 2): frames of a labelled polygon, generic frames, frame rows -/ namespace E94S open Finset /-- Abscissa of the frame `θ = α + iβ` (not normalised). -/ def fX (v : ℕ → ℂ) (α β : ℝ) (i : ℕ) : ℝ := α * (v i).re + β * (v i).im /-- Height of the frame `θ = α + iβ`. -/ def fH (v : ℕ → ℂ) (α β : ℝ) (i : ℕ) : ℝ := -β * (v i).re + α * (v i).im /-- Orientation of the triple of labels `i, j, k`. -/ def ori (v : ℕ → ℂ) (i j k : ℕ) : ℝ := ((v j).re - (v i).re) * ((v k).im - (v i).im) - ((v j).im - (v i).im) * ((v k).re - (v i).re) /-- Squared distance of two labelled points. -/ def dsq (v : ℕ → ℂ) (x y : ℕ) : ℝ := ((v x).re - (v y).re) ^ 2 + ((v x).im - (v y).im) ^ 2 /-- A counterclockwise strictly convex polygon on the labels `< N`: increasing triples are positively oriented. -/ def Ccw (v : ℕ → ℂ) (N : ℕ) : Prop := ∀ i j k, i < j → j < k → k < N → 0 < ori v i j k theorem ar_frame (v : ℕ → ℂ) (α β : ℝ) (i j k : ℕ) : ar (fX v α β) (fH v α β) i j k = (α ^ 2 + β ^ 2) * ori v i j k := by unfold ar fX fH ori; ring theorem fD_frame (v : ℕ → ℂ) (α β : ℝ) (x y : ℕ) : fD (fX v α β) (fH v α β) x y = (α ^ 2 + β ^ 2) * dsq v x y := by unfold fD fX fH dsq; ring theorem dsq_nonneg (v : ℕ → ℂ) (x y : ℕ) : 0 ≤ dsq v x y := by unfold dsq; positivity theorem dist_eq_sqrt_dsq (v : ℕ → ℂ) (x y : ℕ) : dist (v x) (v y) = Real.sqrt (dsq v x y) := by rw [Complex.dist_eq_re_im]; rfl theorem dist_lt_of_dsq_lt {v : ℕ → ℂ} {x y x' y' : ℕ} (h : dsq v x y < dsq v x' y') : dist (v x) (v y) < dist (v x') (v y') := by rw [dist_eq_sqrt_dsq, dist_eq_sqrt_dsq] exact Real.sqrt_lt_sqrt (dsq_nonneg v x y) h theorem frame_or {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) {α β : ℝ} (hc : 0 < α ^ 2 + β ^ 2) : ∀ i j k, i < j → j < k → k < N → 0 < ar (fX v α β) (fH v α β) i j k := by intro i j k hij hjk hk rw [ar_frame] exact mul_pos hc (hccw i j k hij hjk hk) /-- A row is monotone (in the label) for the true distance from its pole. -/ def RowOK (v : ℕ → ℂ) (r : ℕ × Finset ℕ × Bool) : Prop := (r.1 ∉ r.2.1) ∧ ∀ y ∈ r.2.1, ∀ y' ∈ r.2.1, y < y' → if r.2.2 then dist (v r.1) (v y) < dist (v r.1) (v y') else dist (v r.1) (v y') < dist (v r.1) (v y) theorem rowOK_of_frame {v : ℕ → ℂ} {α β : ℝ} (hc : 0 < α ^ 2 + β ^ 2) {r : ℕ × Finset ℕ × Bool} (h : FRowOK (fX v α β) (fH v α β) r) : RowOK v r := by refine ⟨h.1, fun y hy y' hy' hyy' => ?_⟩ have h2 := h.2 y hy y' hy' hyy' rw [fD_frame, fD_frame] at h2 by_cases hb : r.2.2 · rw [if_pos hb] at h2 ⊢ exact dist_lt_of_dsq_lt (lt_of_mul_lt_mul_left h2 hc.le) · rw [if_neg hb] at h2 ⊢ exact dist_lt_of_dsq_lt (lt_of_mul_lt_mul_left h2 hc.le) /-- A finite family of positive margins has a common small scale. -/ theorem exists_small (J : Finset ℕ) (h d : ℕ → ℝ) (hpos : ∀ i ∈ J, 0 < h i) : ∃ ε : ℝ, 0 < ε ∧ ∀ i ∈ J, ε * |d i| < h i := by classical induction J using Finset.induction_on with | empty => exact ⟨1, one_pos, fun i hi => absurd hi (Finset.notMem_empty i)⟩ | insert a s ha ih => obtain ⟨ε, hε, hs⟩ := ih (fun i hi => hpos i (mem_insert_of_mem hi)) have ha0 := hpos a (mem_insert_self a s) have hden : 0 < |d a| + 1 := by positivity refine ⟨min ε (h a / (|d a| + 1)), lt_min hε (div_pos ha0 hden), fun i hi => ?_⟩ rcases mem_insert.mp hi with rfl | hi' · have h1 : min ε (h i / (|d i| + 1)) ≤ h i / (|d i| + 1) := min_le_right _ _ have h2 : h i / (|d i| + 1) * |d i| < h i := by rw [div_mul_eq_mul_div, div_lt_iff₀ hden] nlinarith [abs_nonneg (d i)] nlinarith [abs_nonneg (d i)] · have h1 : min ε (h a / (|d a| + 1)) ≤ ε := min_le_left _ _ nlinarith [abs_nonneg (d i), hs i hi'] /-- **Generic frames with a prescribed lowest vertex.** -/ theorem exists_frame {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) {I : Finset ℕ} (hI : ∀ i ∈ I, i < N) {x : ℕ} (hx : x ∈ I) : ∃ α β : ℝ, 0 < α ^ 2 + β ^ 2 ∧ (∀ i ∈ I, ∀ j ∈ I, fX v α β i = fX v α β j → i = j) ∧ (∀ i ∈ I, ∀ j ∈ I, fH v α β i = fH v α β j → i = j) ∧ ∀ i ∈ I, i ≠ x → fH v α β x < fH v α β i := by classical have hxN := hI x hx by_cases hne : (I.erase x).Nonempty swap · have hall : ∀ i ∈ I, i = x := by intro i hi by_contra hix exact hne ⟨i, mem_erase.mpr ⟨hix, hi⟩⟩ refine ⟨1, 0, by norm_num, ?_, ?_, ?_⟩ · intro i hi j hj _; rw [hall i hi, hall j hj] · intro i hi j hj _; rw [hall i hi, hall j hj] · intro i hi hix; exact absurd (hall i hi) hix obtain ⟨s, hs, hmin⟩ := (I.erase x).exists_min_image (rk N x) hne have hsI : s ∈ I := (mem_erase.mp hs).2 have hsx : s ≠ x := (mem_erase.mp hs).1 have hsN := hI s hsI obtain ⟨α₀, hα₀⟩ : ∃ a : ℝ, a = (v s).re - (v x).re := ⟨_, rfl⟩ obtain ⟨β₀, hβ₀⟩ : ∃ b : ℝ, b = (v s).im - (v x).im := ⟨_, rfl⟩ have hE : 0 < α₀ ^ 2 + β₀ ^ 2 := by rcases lt_or_eq_of_le (by positivity : 0 ≤ α₀ ^ 2 + β₀ ^ 2) with h | h · exact h · exfalso have h1 : α₀ = 0 := by have h' : α₀ ^ 2 ≤ 0 := by nlinarith [sq_nonneg β₀] exact pow_eq_zero_iff (two_ne_zero) |>.mp (le_antisymm h' (sq_nonneg _)) have h2 : β₀ = 0 := by have h' : β₀ ^ 2 ≤ 0 := by nlinarith [sq_nonneg α₀] exact pow_eq_zero_iff (two_ne_zero) |>.mp (le_antisymm h' (sq_nonneg _)) apply hsx apply hinj s hsN x hxN apply Complex.ext <;> linarith -- the base frame: `s` and `x` at the same height, everything else higher have hF1 : ∀ i ∈ I, i ≠ x → i ≠ s → fH v α₀ β₀ x < fH v α₀ β₀ i := by intro i hi hix his have hor1 : ∀ a b c, a < b → b < c → c < N → 0 < ar (fun k => (v k).re) (fun k => (v k).im) a b c := fun a b c hab hbc hc => hccw a b c hab hbc hc have hr1 : rk N x x < rk N x s := by rw [rk_self] rcases Nat.eq_zero_or_pos (rk N x s) with h0 | h0 · exact absurd (rk_inj hxN hsN hxN (by rw [h0, rk_self])) hsx · exact h0 have hr2 : rk N x s < rk N x i := lt_of_le_of_ne (hmin i (mem_erase.mpr ⟨hix, hi⟩)) (fun h => his (rk_inj hxN hsN (hI i hi) h).symm) have := ar_rot hor1 hxN hxN hsN (hI i hi) hr1 hr2 unfold ar at this unfold fH rw [hα₀, hβ₀] nlinarith [this] have hF2 : fH v α₀ β₀ s = fH v α₀ β₀ x := by unfold fH; rw [hα₀, hβ₀]; ring have hF3 : fX v α₀ β₀ s - fX v α₀ β₀ x = α₀ ^ 2 + β₀ ^ 2 := by unfold fX; rw [hα₀, hβ₀]; ring obtain ⟨ε, hε, hεs⟩ := exists_small ((I.erase x).erase s) (fun i => fH v α₀ β₀ i - fH v α₀ β₀ x) (fun i => fX v α₀ β₀ i - fX v α₀ β₀ x) (fun i hi => by have h1 := mem_erase.mp hi have h2 := mem_erase.mp h1.2 exact sub_pos.mpr (hF1 i h2.2 h2.1 h1.1)) obtain ⟨F, hF⟩ : ∃ F : Finset ℝ, F = (I ×ˢ I).image (fun ij => (fX v α₀ β₀ ij.2 - fX v α₀ β₀ ij.1) / (fH v α₀ β₀ ij.1 - fH v α₀ β₀ ij.2)) ∪ (I ×ˢ I).image (fun ij => (fH v α₀ β₀ ij.1 - fH v α₀ β₀ ij.2) / (fX v α₀ β₀ ij.1 - fX v α₀ β₀ ij.2)) := ⟨_, rfl⟩ obtain ⟨σ, hσI, hσF⟩ := (Set.Ioo_infinite (show -ε < 0 by linarith)).exists_notMem_finset F have hσ1 : -ε < σ := hσI.1 have hσ2 : σ < 0 := hσI.2 have eX : ∀ i, fX v (α₀ - σ * β₀) (β₀ + σ * α₀) i = fX v α₀ β₀ i + σ * fH v α₀ β₀ i := by intro i; unfold fX fH; ring have eH : ∀ i, fH v (α₀ - σ * β₀) (β₀ + σ * α₀) i = fH v α₀ β₀ i - σ * fX v α₀ β₀ i := by intro i; unfold fX fH; ring have hbase : ∀ i ∈ I, ∀ j ∈ I, fX v α₀ β₀ i = fX v α₀ β₀ j → fH v α₀ β₀ i = fH v α₀ β₀ j → i = j := by intro i hi j hj h1 h2 apply hinj i (hI i hi) j (hI j hj) unfold fX at h1 unfold fH at h2 have e1 : (α₀ ^ 2 + β₀ ^ 2) * ((v i).re - (v j).re) = 0 := by linear_combination α₀ * h1 - β₀ * h2 have e2 : (α₀ ^ 2 + β₀ ^ 2) * ((v i).im - (v j).im) = 0 := by linear_combination β₀ * h1 + α₀ * h2 have e3 := (mul_eq_zero.mp e1).resolve_left hE.ne' have e4 := (mul_eq_zero.mp e2).resolve_left hE.ne' apply Complex.ext <;> linarith refine ⟨α₀ - σ * β₀, β₀ + σ * α₀, ?_, ?_, ?_, ?_⟩ · have : (α₀ - σ * β₀) ^ 2 + (β₀ + σ * α₀) ^ 2 = (α₀ ^ 2 + β₀ ^ 2) * (1 + σ ^ 2) := by ring rw [this]; positivity · intro i hi j hj h rw [eX, eX] at h by_cases hH : fH v α₀ β₀ i = fH v α₀ β₀ j · exact hbase i hi j hj (by rw [hH] at h; linarith) hH · exfalso apply hσF rw [hF] apply mem_union_left refine mem_image.mpr ⟨(i, j), mem_product.mpr ⟨hi, hj⟩, ?_⟩ have hd : fH v α₀ β₀ i - fH v α₀ β₀ j ≠ 0 := sub_ne_zero.mpr hH show (fX v α₀ β₀ j - fX v α₀ β₀ i) / (fH v α₀ β₀ i - fH v α₀ β₀ j) = σ rw [div_eq_iff hd] linarith · intro i hi j hj h rw [eH, eH] at h by_cases hXe : fX v α₀ β₀ i = fX v α₀ β₀ j · exact hbase i hi j hj hXe (by rw [hXe] at h; linarith) · exfalso apply hσF rw [hF] apply mem_union_right refine mem_image.mpr ⟨(i, j), mem_product.mpr ⟨hi, hj⟩, ?_⟩ have hd : fX v α₀ β₀ i - fX v α₀ β₀ j ≠ 0 := sub_ne_zero.mpr hXe show (fH v α₀ β₀ i - fH v α₀ β₀ j) / (fX v α₀ β₀ i - fX v α₀ β₀ j) = σ rw [div_eq_iff hd] linarith · intro i hi hix rw [eH, eH] by_cases his : i = s · rw [his, hF2] nlinarith [hF3] · have h1 := hεs i (mem_erase.mpr ⟨his, mem_erase.mpr ⟨hix, hi⟩⟩) have h2 : -(σ * (fX v α₀ β₀ i - fX v α₀ β₀ x)) ≥ -(ε * |fX v α₀ β₀ i - fX v α₀ β₀ x|) := by have h3 : σ * (fX v α₀ β₀ i - fX v α₀ β₀ x) ≤ |σ| * |fX v α₀ β₀ i - fX v α₀ β₀ x| := by rw [← abs_mul]; exact le_abs_self _ have h4 : |σ| ≤ ε := by rw [abs_le]; constructor <;> linarith nlinarith [abs_nonneg (fX v α₀ β₀ i - fX v α₀ β₀ x)] linarith /-- Two chords cross (in the label order): the endpoints are distinct and exactly one of `p`, `q` lies strictly between `i` and `j`. -/ def Crs (i j p q : ℕ) : Prop := i ≠ p ∧ i ≠ q ∧ j ≠ p ∧ j ≠ q ∧ ((((i < p ∧ p < j) ∨ (j < p ∧ p < i)) ∧ ¬ ((i < q ∧ q < j) ∨ (j < q ∧ q < i))) ∨ (¬ ((i < p ∧ p < j) ∨ (j < p ∧ p < i)) ∧ ((i < q ∧ q < j) ∨ (j < q ∧ q < i)))) /-- Two labels whose chord does not cross `{p, q}` lie on a common closed arc of `{p, q}`. -/ theorem arc_of_not_crs {N i j p q : ℕ} (hi : i < N) (hj : j < N) (hp : p < N) (hq : q < N) (hpq : p ≠ q) (h : ¬ Crs i j p q) : (rk N q i ≤ rk N q p ∧ rk N q j ≤ rk N q p) ∨ (rk N p i ≤ rk N p q ∧ rk N p j ≤ rk N p q) := by unfold Crs at h unfold rk split_ifs <;> omega open Classical in /-- The eight rows of every pole of `I` in the frame `(α, β)` with top `q` and bottom `p`. -/ noncomputable def frameRows (v : ℕ → ℂ) (N : ℕ) (I : Finset ℕ) (α β : ℝ) (q p : ℕ) : Finset (ℕ × Finset ℕ × Bool) := (I ×ˢ ((univ : Finset Bool) ×ˢ ((univ : Finset Bool) ×ˢ (univ : Finset Bool)))).image (fun a => if a.2.2.2 then hfRow I (fX v (-α) (-β)) N p q a.2.1 a.2.2.1 a.1 else hfRow I (fX v α β) N q p a.2.1 a.2.2.1 a.1) theorem frameRows_card (v : ℕ → ℂ) (N : ℕ) (I : Finset ℕ) (α β : ℝ) (q p : ℕ) : (frameRows v N I α β q p).card ≤ 8 * I.card := by classical unfold frameRows refine le_trans card_image_le ?_ rw [card_product, card_product, card_product] simp omega theorem frameRows_pole (v : ℕ → ℂ) (N : ℕ) (I : Finset ℕ) (α β : ℝ) (q p x : ℕ) : ((frameRows v N I α β q p).filter (fun r => r.1 = x)).card ≤ 8 := by classical have hsub : (frameRows v N I α β q p).filter (fun r => r.1 = x) ⊆ ((({x} : Finset ℕ) ×ˢ ((univ : Finset Bool) ×ˢ ((univ : Finset Bool) ×ˢ (univ : Finset Bool)))).image (fun a => if a.2.2.2 then hfRow I (fX v (-α) (-β)) N p q a.2.1 a.2.2.1 a.1 else hfRow I (fX v α β) N q p a.2.1 a.2.2.1 a.1)) := by intro r hr obtain ⟨hr1, hr2⟩ := mem_filter.mp hr unfold frameRows at hr1 obtain ⟨a, ha, rfl⟩ := mem_image.mp hr1 refine mem_image.mpr ⟨a, ?_, rfl⟩ have ha1 : a.1 = x := by by_cases hfl : a.2.2.2 · rw [if_pos hfl] at hr2; exact hr2 · rw [if_neg hfl] at hr2; exact hr2 refine mem_product.mpr ⟨by rw [ha1]; exact mem_singleton_self x, ?_⟩ simp refine le_trans (card_le_card hsub) (le_trans card_image_le ?_) rw [card_product, card_product, card_product] simp theorem hfRow_sub (I : Finset ℕ) (X : ℕ → ℝ) (N q p : ℕ) (up hi : Bool) (x : ℕ) : (hfRow I X N q p up hi x).1 = x ∧ (hfRow I X N q p up hi x).2.1 ⊆ I := by classical refine ⟨rfl, ?_⟩ unfold hfRow hfY exact filter_subset _ _ /-- The rows of a generic frame are monotone, live inside `I`, and cover every pair of `I` whose chord does not cross the chord of the two extremes. -/ theorem frameRows_spec {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) {I : Finset ℕ} (hI : ∀ i ∈ I, i < N) {α β : ℝ} (hc : 0 < α ^ 2 + β ^ 2) (hX : ∀ i ∈ I, ∀ j ∈ I, fX v α β i = fX v α β j → i = j) (hH : ∀ i ∈ I, ∀ j ∈ I, fH v α β i = fH v α β j → i = j) {q p : ℕ} (hq : q ∈ I) (hp : p ∈ I) (hqmax : ∀ i ∈ I, fH v α β i ≤ fH v α β q) (hpmin : ∀ i ∈ I, fH v α β p ≤ fH v α β i) (hpq : p ≠ q) : (∀ r ∈ frameRows v N I α β q p, RowOK v r ∧ r.1 ∈ I ∧ r.2.1 ⊆ I) ∧ ∀ i ∈ I, ∀ j ∈ I, i ≠ j → ¬ Crs i j p q → ∃ r ∈ frameRows v N I α β q p, RCov r i j := by classical have hc' : 0 < (-α) ^ 2 + (-β) ^ 2 := by nlinarith have eX : ∀ i, fX v (-α) (-β) i = -fX v α β i := by intro i; unfold fX; ring have eH : ∀ i, fH v (-α) (-β) i = -fH v α β i := by intro i; unfold fH; ring have hX' : ∀ i ∈ I, ∀ j ∈ I, fX v (-α) (-β) i = fX v (-α) (-β) j → i = j := by intro i hi j hj h; rw [eX, eX] at h; exact hX i hi j hj (neg_injective h) have hH' : ∀ i ∈ I, ∀ j ∈ I, fH v (-α) (-β) i = fH v (-α) (-β) j → i = j := by intro i hi j hj h; rw [eH, eH] at h; exact hH i hi j hj (neg_injective h) constructor · intro r hr unfold frameRows at hr obtain ⟨a, ha, rfl⟩ := mem_image.mp hr have haI : a.1 ∈ I := (mem_product.mp ha).1 by_cases hfl : a.2.2.2 · rw [if_pos hfl] refine ⟨rowOK_of_frame hc' ?_, haI, (hfRow_sub _ _ _ _ _ _ _ _).2⟩ exact hf_rowOK (frame_or hccw hc') hI hH' hp hq (fun i hi => by rw [eH, eH]; exact neg_le_neg (hpmin i hi)) (fun i hi => by rw [eH, eH]; exact neg_le_neg (hqmax i hi)) a.2.1 a.2.2.1 haI · rw [if_neg hfl] refine ⟨rowOK_of_frame hc ?_, haI, (hfRow_sub _ _ _ _ _ _ _ _).2⟩ exact hf_rowOK (frame_or hccw hc) hI hH hq hp hqmax hpmin a.2.1 a.2.2.1 haI · intro i hi j hj hij hcr rcases arc_of_not_crs (hI i hi) (hI j hj) (hI p hp) (hI q hq) hpq hcr with h | h · obtain ⟨up, hi', x, hx, hcov⟩ := hf_cover hI hX hq hi hj hij h.1 h.2 refine ⟨hfRow I (fX v α β) N q p up hi' x, ?_, hcov⟩ unfold frameRows refine mem_image.mpr ⟨(x, up, hi', false), ?_, by simp⟩ simp [hx] · obtain ⟨up, hi', x, hx, hcov⟩ := hf_cover hI hX' hp hi hj hij h.1 h.2 refine ⟨hfRow I (fX v (-α) (-β)) N p q up hi' x, ?_, hcov⟩ unfold frameRows refine mem_image.mpr ⟨(x, up, hi', true), ?_, by simp⟩ simp [hx] end E94S /-! ### SOLO slice A3 -/ /-! ## SOLO module A (part 3): the node step of the Brass–Pach recursion -/ namespace E94S open Finset /-- For an injective key there is an element with exactly `k` elements below it. -/ theorem exists_rank {f : ℕ → ℕ} : ∀ (k : ℕ) (W : Finset ℕ), (∀ a ∈ W, ∀ b ∈ W, f a = f b → a = b) → k < W.card → ∃ a ∈ W, (W.filter (fun i => f i < f a)).card = k := by intro k induction k with | zero => intro W _ hk obtain ⟨m, hm, hmin⟩ := W.exists_min_image f (card_pos.mp hk) refine ⟨m, hm, ?_⟩ rw [card_eq_zero, filter_eq_empty_iff] intro i hi exact not_lt.mpr (hmin i hi) | succ k ih => intro W hf hk obtain ⟨m, hm, hmin⟩ := W.exists_min_image f (card_pos.mp (by omega)) have hcard : (W.erase m).card = W.card - 1 := card_erase_of_mem hm obtain ⟨a, ha, hcnt⟩ := ih (W.erase m) (fun a ha b hb h => hf a (mem_erase.mp ha).2 b (mem_erase.mp hb).2 h) (by omega) have haW := (mem_erase.mp ha).2 have ham : a ≠ m := (mem_erase.mp ha).1 have hlt : f m < f a := lt_of_le_of_ne (hmin a haW) (fun h => ham (hf m hm a haW h).symm) refine ⟨a, haW, ?_⟩ have e : W.filter (fun i => f i < f a) = insert m ((W.erase m).filter (fun i => f i < f a)) := by ext i simp only [mem_filter, mem_insert, mem_erase] constructor · rintro ⟨hi, hia⟩ by_cases him : i = m · exact Or.inl him · exact Or.inr ⟨⟨him, hi⟩, hia⟩ · rintro (rfl | ⟨⟨_, hi⟩, hia⟩) · exact ⟨hm, hlt⟩ · exact ⟨hi, hia⟩ rw [e, card_insert_of_notMem, hcnt] simp theorem crs_symm {i j p q : ℕ} (h : Crs i j p q) : Crs j i p q := by unfold Crs at h ⊢ omega theorem rcov_symm {r : ℕ × Finset ℕ × Bool} {i j : ℕ} (h : RCov r i j) : RCov r j i := by unfold RCov at h ⊢ tauto /-- Arithmetic of the potential: the two children carry at most `3/4` of the squared size. -/ theorem step_arith {a b k l r m : ℕ} (ha : a ≤ k + r) (hb : b ≤ k + r) (hab : a + b ≤ l + r) (hk : 2 * k ≤ l) (hr : r ≤ l) (hm : l + r ≤ m) : 4 * (a ^ 2 + b ^ 2) ≤ 3 * m ^ 2 := by have h1 : a * a ≤ (k + r) * a := Nat.mul_le_mul_right a ha have h2 : b * b ≤ (k + r) * b := Nat.mul_le_mul_right b hb have h3 : (k + r) * (a + b) ≤ (k + r) * (l + r) := Nat.mul_le_mul_left _ hab have h4 : 4 * (k + r) * (l + r) ≤ 3 * (l + r) * (l + r) := Nat.mul_le_mul_right _ (by omega) have h5 : (l + r) * (l + r) ≤ m * m := Nat.mul_le_mul hm hm nlinarith [h1, h2, h3, h4, h5] /-- **The core of the node step.** Frame 1 has left uncovered only pairs joining `W` to `V`; a second frame whose lowest vertex is the `σ`-median of `W` then splits the uncovered pairs into two disjoint children. -/ theorem step_core {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) {I : Finset ℕ} (hI : ∀ i ∈ I, i < N) {R₁ : Finset (ℕ × Finset ℕ × Bool)} {W V : Finset ℕ} (hW : W ⊆ I) (hV : V ⊆ I) (hWV : Disjoint W V) (hcard : W.card + V.card + 2 ≤ I.card) (hVW : V.card ≤ W.card) {σ : ℕ → ℕ} (hσ : ∀ a ∈ W, ∀ b ∈ W, σ a = σ b → a = b) (hlink : ∀ p₂ ∈ W, ∀ q₂ ∈ I, ∀ a' ∈ W, ∀ a ∈ W, ∀ c ∈ V, σ a' < σ p₂ → σ p₂ < σ a → Crs a' c p₂ q₂ → Crs a c p₂ q₂ → False) (hcov : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → (∃ r ∈ R₁, RCov r i j) ∨ (i ∈ W ∧ j ∈ V) ∨ (j ∈ W ∧ i ∈ V)) : ∃ R₂ : Finset (ℕ × Finset ℕ × Bool), ∃ I₁ I₂ : Finset ℕ, R₂.card ≤ 8 * I.card ∧ (∀ x, (R₂.filter (fun r => r.1 = x)).card ≤ 8) ∧ (∀ r ∈ R₂, RowOK v r ∧ r.1 ∈ I ∧ r.2.1 ⊆ I) ∧ I₁ ⊆ I ∧ I₂ ⊆ I ∧ Disjoint I₁ I₂ ∧ 4 * (I₁.card ^ 2 + I₂.card ^ 2) ≤ 3 * I.card ^ 2 ∧ ∀ i ∈ I, ∀ j ∈ I, i ≠ j → (∃ r ∈ R₁ ∪ R₂, RCov r i j) ∨ (i ∈ I₁ ∧ j ∈ I₁) ∨ (i ∈ I₂ ∧ j ∈ I₂) := by classical by_cases hW0 : W.card = 0 · have hWe : W = ∅ := card_eq_zero.mp hW0 have hVe : V = ∅ := card_eq_zero.mp (by omega) refine ⟨∅, ∅, ∅, by simp, by simp, by simp, by simp, by simp, by simp, by simp, ?_⟩ intro i hi j hj hij rcases hcov i hi j hj hij with h | h | h · obtain ⟨r, hr, hc⟩ := h exact Or.inl ⟨r, mem_union_left _ hr, hc⟩ · rw [hWe] at h; exact absurd h.1 (notMem_empty i) · rw [hWe] at h; exact absurd h.1 (notMem_empty j) obtain ⟨p₂, hp₂W, hrank⟩ := exists_rank (W.card / 2) W hσ (Nat.div_lt_self (by omega) (by norm_num)) have hp₂I := hW hp₂W obtain ⟨α, β, hc, hX, hH, hlow⟩ := exists_frame hccw hinj hI hp₂I obtain ⟨q₂, hq₂I, hqmax⟩ := I.exists_max_image (fH v α β) ⟨p₂, hp₂I⟩ have hpmin : ∀ i ∈ I, fH v α β p₂ ≤ fH v α β i := by intro i hi by_cases h : i = p₂ · rw [h] · exact (hlow i hi h).le have hpq : p₂ ≠ q₂ := by intro h have hall : ∀ i ∈ I, i = p₂ := by intro i hi by_contra hne have h1 := hlow i hi hne have h2 := hqmax i hi rw [← h] at h2 linarith have : I.card ≤ 1 := card_le_one.mpr (fun a ha b hb => by rw [hall a ha, hall b hb]) omega obtain ⟨hR2ok, hR2cov⟩ := frameRows_spec hccw hI hc hX hH hq₂I hp₂I hqmax hpmin hpq obtain ⟨Wa, hWa⟩ : ∃ Wa : Finset ℕ, Wa = W.filter (fun i => σ i < σ p₂) := ⟨_, rfl⟩ obtain ⟨Wb, hWb⟩ : ∃ Wb : Finset ℕ, Wb = W.filter (fun i => σ p₂ < σ i) := ⟨_, rfl⟩ obtain ⟨VA, hVA⟩ : ∃ VA : Finset ℕ, VA = V.filter (fun j => ∃ i ∈ Wa, Crs i j p₂ q₂) := ⟨_, rfl⟩ obtain ⟨VB, hVB⟩ : ∃ VB : Finset ℕ, VB = V.filter (fun j => ¬ ∃ i ∈ Wa, Crs i j p₂ q₂) := ⟨_, rfl⟩ have hWaW : Wa ⊆ W := by rw [hWa]; exact filter_subset _ _ have hWbW : Wb ⊆ W := by rw [hWb]; exact filter_subset _ _ have hVAV : VA ⊆ V := by rw [hVA]; exact filter_subset _ _ have hVBV : VB ⊆ V := by rw [hVB]; exact filter_subset _ _ have hWac : Wa.card = W.card / 2 := by rw [hWa]; exact hrank have hWbc : Wb.card + Wa.card + 1 ≤ W.card := by have hd1 : Disjoint Wb Wa := by rw [hWa, hWb, disjoint_left] intro i h1 h2 have := (mem_filter.mp h1).2 have := (mem_filter.mp h2).2 omega have hd2 : p₂ ∉ Wb ∪ Wa := by rw [hWa, hWb] intro h rcases mem_union.mp h with h | h · have := (mem_filter.mp h).2; omega · have := (mem_filter.mp h).2; omega have hsub : insert p₂ (Wb ∪ Wa) ⊆ W := by intro i hi rcases mem_insert.mp hi with rfl | hi · exact hp₂W · rcases mem_union.mp hi with h | h · exact hWbW h · exact hWaW h have := card_le_card hsub rw [card_insert_of_notMem hd2, card_union_of_disjoint hd1] at this omega have hVc : VA.card + VB.card = V.card := by rw [hVA, hVB] exact card_filter_add_card_filter_not _ have hdWV : ∀ A ⊆ W, ∀ B ⊆ V, Disjoint A B := fun A hA B hB => disjoint_of_subset_left hA (disjoint_of_subset_right hB hWV) refine ⟨frameRows v N I α β q₂ p₂, Wa ∪ VA, Wb ∪ VB, frameRows_card _ _ _ _ _ _ _, fun x => frameRows_pole _ _ _ _ _ _ _ x, hR2ok, union_subset (hWaW.trans hW) (hVAV.trans hV), union_subset (hWbW.trans hW) (hVBV.trans hV), ?_, ?_, ?_⟩ · rw [disjoint_union_left, disjoint_union_right, disjoint_union_right] refine ⟨⟨?_, hdWV Wa hWaW VB hVBV⟩, ⟨(hdWV Wb hWbW VA hVAV).symm, ?_⟩⟩ · rw [hWa, hWb, disjoint_left] intro i h1 h2 have := (mem_filter.mp h1).2 have := (mem_filter.mp h2).2 omega · rw [hVA, hVB, disjoint_left] intro i h1 h2 exact (mem_filter.mp h2).2 (mem_filter.mp h1).2 · have h1 : (Wa ∪ VA).card = Wa.card + VA.card := card_union_of_disjoint (hdWV Wa hWaW VA hVAV) have h2 : (Wb ∪ VB).card = Wb.card + VB.card := card_union_of_disjoint (hdWV Wb hWbW VB hVBV) have hVAc : VA.card ≤ V.card := card_le_card hVAV have hVBc : VB.card ≤ V.card := card_le_card hVBV have hdiv : 2 * (W.card / 2) ≤ W.card := Nat.mul_div_le _ _ refine step_arith (a := (Wa ∪ VA).card) (b := (Wb ∪ VB).card) (k := W.card / 2) (l := W.card) (r := V.card) (m := I.card) (by omega) (by omega) (by omega) hdiv hVW (by omega) · intro i hi j hj hij have main : ∀ a ∈ W, ∀ c ∈ V, a ≠ c → (∃ r ∈ R₁ ∪ frameRows v N I α β q₂ p₂, RCov r a c) ∨ (a ∈ Wa ∪ VA ∧ c ∈ Wa ∪ VA) ∨ (a ∈ Wb ∪ VB ∧ c ∈ Wb ∪ VB) := by intro a ha c hc' hac by_cases hcr : Crs a c p₂ q₂ · have hap : a ≠ p₂ := hcr.1 have hne : σ a ≠ σ p₂ := fun h => hap (hσ a ha p₂ hp₂W h) rcases lt_or_gt_of_ne hne with h | h · have haWa : a ∈ Wa := by rw [hWa]; exact mem_filter.mpr ⟨ha, h⟩ refine Or.inr (Or.inl ⟨mem_union_left _ haWa, mem_union_right _ ?_⟩) rw [hVA] exact mem_filter.mpr ⟨hc', a, haWa, hcr⟩ · have haWb : a ∈ Wb := by rw [hWb]; exact mem_filter.mpr ⟨ha, h⟩ refine Or.inr (Or.inr ⟨mem_union_left _ haWb, mem_union_right _ ?_⟩) rw [hVB] refine mem_filter.mpr ⟨hc', ?_⟩ rintro ⟨a', ha', hcr'⟩ rw [hWa] at ha' have h1 := mem_filter.mp ha' exact hlink p₂ hp₂W q₂ hq₂I a' h1.1 a ha c hc' h1.2 h hcr' hcr · obtain ⟨r, hr, hrc⟩ := hR2cov a (hW ha) c (hV hc') hac hcr exact Or.inl ⟨r, mem_union_right _ hr, hrc⟩ rcases hcov i hi j hj hij with h | h | h · obtain ⟨r, hr, hc'⟩ := h exact Or.inl ⟨r, mem_union_left _ hr, hc'⟩ · exact main i h.1 j h.2 hij · rcases main j h.1 i h.2 (Ne.symm hij) with h' | h' | h' · obtain ⟨r, hr, hc'⟩ := h' exact Or.inl ⟨r, hr, rcov_symm hc'⟩ · exact Or.inr (Or.inl ⟨h'.2, h'.1⟩) · exact Or.inr (Or.inr ⟨h'.2, h'.1⟩) /-- **The node step.** Every node `I` of a counterclockwise polygon has `≤ 16|I|` monotone rows inside `I` and two disjoint children with `|I₁|² + |I₂|² ≤ (3/4)|I|²` such that every pair of `I` is covered by a row or lies in a child. -/ theorem node_step {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) (I : Finset ℕ) (hI : ∀ i ∈ I, i < N) : ∃ T : Finset (ℕ × Finset ℕ × Bool) × Finset ℕ × Finset ℕ, T.1.card ≤ 16 * I.card ∧ (∀ x, (T.1.filter (fun r => r.1 = x)).card ≤ 16) ∧ (∀ r ∈ T.1, RowOK v r ∧ r.1 ∈ I ∧ r.2.1 ⊆ I) ∧ T.2.1 ⊆ I ∧ T.2.2 ⊆ I ∧ Disjoint T.2.1 T.2.2 ∧ 4 * (T.2.1.card ^ 2 + T.2.2.card ^ 2) ≤ 3 * I.card ^ 2 ∧ ∀ i ∈ I, ∀ j ∈ I, i ≠ j → (∃ r ∈ T.1, RCov r i j) ∨ (i ∈ T.2.1 ∧ j ∈ T.2.1) ∨ (i ∈ T.2.2 ∧ j ∈ T.2.2) := by classical by_cases hsmall : I.card ≤ 1 · refine ⟨(∅, ∅, ∅), by simp, by simp, by simp, by simp, by simp, by simp, by simp, ?_⟩ intro i hi j hj hij exact absurd (card_le_one.mp hsmall i hi j hj) hij have hne : I.Nonempty := card_pos.mp (by omega) obtain ⟨x₀, hx₀⟩ := hne obtain ⟨α, β, hc, hX, hH, _⟩ := exists_frame hccw hinj hI hx₀ obtain ⟨q, hqI, hqmax⟩ := I.exists_max_image (fH v α β) ⟨x₀, hx₀⟩ obtain ⟨p, hpI, hpmin⟩ := I.exists_min_image (fH v α β) ⟨x₀, hx₀⟩ have hpq : p ≠ q := by intro h have hall : ∀ i ∈ I, i = p := by intro i hi apply hH i hi p hpI have h1 := hpmin i hi have h2 := hqmax i hi rw [← h] at h2 linarith have : I.card ≤ 1 := card_le_one.mpr (fun a ha b hb => by rw [hall a ha, hall b hb]) omega obtain ⟨hR1ok, hR1cov⟩ := frameRows_spec hccw hI hc hX hH hqI hpI hqmax hpmin hpq obtain ⟨lo, hi, hlohi, hlh⟩ : ∃ lo hi : ℕ, lo < hi ∧ ((lo = p ∧ hi = q) ∨ (lo = q ∧ hi = p)) := by rcases lt_or_gt_of_ne hpq with h | h · exact ⟨p, q, h, Or.inl ⟨rfl, rfl⟩⟩ · exact ⟨q, p, h, Or.inr ⟨rfl, rfl⟩⟩ have hloI : lo ∈ I := by rcases hlh with h | h <;> rw [h.1] <;> assumption have hhiI : hi ∈ I := by rcases hlh with h | h <;> rw [h.2] <;> assumption have hhiN := hI hi hhiI obtain ⟨In, hIn⟩ : ∃ In : Finset ℕ, In = I.filter (fun i => lo < i ∧ i < hi) := ⟨_, rfl⟩ obtain ⟨Out, hOut⟩ : ∃ Out : Finset ℕ, Out = I.filter (fun i => i < lo ∨ hi < i) := ⟨_, rfl⟩ have hInI : In ⊆ I := by rw [hIn]; exact filter_subset _ _ have hOutI : Out ⊆ I := by rw [hOut]; exact filter_subset _ _ have hmIn : ∀ i, i ∈ In ↔ i ∈ I ∧ lo < i ∧ i < hi := by intro i; rw [hIn, mem_filter] have hmOut : ∀ i, i ∈ Out ↔ i ∈ I ∧ (i < lo ∨ hi < i) := by intro i; rw [hOut, mem_filter] have hdis : Disjoint In Out := by rw [disjoint_left] intro i h1 h2 have := (hmIn i).mp h1 have := (hmOut i).mp h2 omega have hcard : In.card + Out.card + 2 ≤ I.card := by have hsub : insert lo (insert hi (In ∪ Out)) ⊆ I := by intro i hi' rcases mem_insert.mp hi' with rfl | hi' · exact hloI rcases mem_insert.mp hi' with rfl | hi' · exact hhiI rcases mem_union.mp hi' with h | h · exact hInI h · exact hOutI h have h1 : hi ∉ In ∪ Out := by intro h rcases mem_union.mp h with h | h · have := (hmIn hi).mp h; omega · have := (hmOut hi).mp h; omega have h2 : lo ∉ insert hi (In ∪ Out) := by intro h rcases mem_insert.mp h with h | h · omega rcases mem_union.mp h with h | h · have := (hmIn lo).mp h; omega · have := (hmOut lo).mp h; omega have := card_le_card hsub rw [card_insert_of_notMem h2, card_insert_of_notMem h1, card_union_of_disjoint hdis] at this omega -- frame 1 leaves only pairs joining `In` to `Out` have hcov1 : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → (∃ r ∈ frameRows v N I α β q p, RCov r i j) ∨ (i ∈ In ∧ j ∈ Out) ∨ (j ∈ In ∧ i ∈ Out) := by intro i hi' j hj hij by_cases hcr : Crs i j p q · right rw [hmIn, hmOut, hmIn, hmOut] unfold Crs at hcr rcases hlh with ⟨h1, h2⟩ | ⟨h1, h2⟩ <;> subst h1 <;> subst h2 · by_cases hin : lo < i ∧ i < hi · exact Or.inl ⟨⟨hi', hin⟩, hj, by omega⟩ · exact Or.inr ⟨⟨hj, by omega⟩, hi', by omega⟩ · by_cases hin : lo < i ∧ i < hi · exact Or.inl ⟨⟨hi', hin⟩, hj, by omega⟩ · exact Or.inr ⟨⟨hj, by omega⟩, hi', by omega⟩ · exact Or.inl (hR1cov i hi' j hj hij hcr) by_cases hcase : Out.card ≤ In.card · -- the inner arc is the larger one: `σ = id` obtain ⟨R₂, I₁, I₂, h1, h1p, h2, h3, h4, h5, h6, h7⟩ := step_core hccw hinj hI (R₁ := frameRows v N I α β q p) (W := In) (V := Out) hInI hOutI hdis hcard hcase (σ := fun i => i) (fun a _ b _ h => h) (by intro p₂ hp₂ q₂ _ a' ha' a ha c hc' h1 h2 hcr' hcr have := (hmIn p₂).mp hp₂ have := (hmIn a').mp ha' have := (hmIn a).mp ha have := (hmOut c).mp hc' unfold Crs at hcr' hcr omega) hcov1 refine ⟨(frameRows v N I α β q p ∪ R₂, I₁, I₂), ?_, ?_, ?_, h3, h4, h5, h6, h7⟩ · have := frameRows_card v N I α β q p have := card_union_le (frameRows v N I α β q p) R₂ simp only omega · intro x simp only rw [filter_union] have := frameRows_pole v N I α β q p x have := h1p x have := card_union_le ((frameRows v N I α β q p).filter (fun r => r.1 = x)) (R₂.filter (fun r => r.1 = x)) omega · intro r hr rcases mem_union.mp hr with h | h · exact hR1ok r h · exact h2 r h · -- the outer arc is the larger one: order it as "above `hi`" first, then "below `lo`" obtain ⟨R₂, I₁, I₂, h1, h1p, h2, h3, h4, h5, h6, h7⟩ := step_core hccw hinj hI (R₁ := frameRows v N I α β q p) (W := Out) (V := In) hOutI hInI hdis.symm (by omega) (by omega) (σ := fun i => if hi < i then i else i + N) (by intro a ha b hb h have := (hmOut a).mp ha have := (hmOut b).mp hb have := hI a (hOutI ha) have := hI b (hOutI hb) split_ifs at h <;> omega) (by intro p₂ hp₂ q₂ _ a' ha' a ha c hc' h1 h2 hcr' hcr have := (hmOut p₂).mp hp₂ have := (hmOut a').mp ha' have := (hmOut a).mp ha have := (hmIn c).mp hc' have := hI p₂ (hOutI hp₂) have := hI a' (hOutI ha') have := hI a (hOutI ha) unfold Crs at hcr' hcr split_ifs at h1 h2 <;> omega) (by intro i hi' j hj hij rcases hcov1 i hi' j hj hij with h | h | h · exact Or.inl h · exact Or.inr (Or.inr ⟨h.2, h.1⟩) · exact Or.inr (Or.inl ⟨h.2, h.1⟩)) refine ⟨(frameRows v N I α β q p ∪ R₂, I₁, I₂), ?_, ?_, ?_, h3, h4, h5, h6, h7⟩ · have := frameRows_card v N I α β q p have := card_union_le (frameRows v N I α β q p) R₂ simp only omega · intro x simp only rw [filter_union] have := frameRows_pole v N I α β q p x have := h1p x have := card_union_le ((frameRows v N I α β q p).filter (fun r => r.1 = x)) (R₂.filter (fun r => r.1 = x)) omega · intro r hr rcases mem_union.mp hr with h | h · exact hR1ok r h · exact h2 r h end E94S /-! ### SOLO slice A4 -/ /-! ## SOLO module A (part 4): the levels of the Brass–Pach recursion -/ namespace E94S open Finset open Classical in /-- The node step, chosen once and for all. -/ noncomputable def stepF (v : ℕ → ℂ) (N : ℕ) (I : Finset ℕ) : Finset (ℕ × Finset ℕ × Bool) × Finset ℕ × Finset ℕ := if h : Ccw v N ∧ (∀ i < N, ∀ j < N, v i = v j → i = j) ∧ ∀ i ∈ I, i < N then Classical.choose (node_step h.1 h.2.1 I h.2.2) else (∅, ∅, ∅) theorem stepF_spec {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) {I : Finset ℕ} (hI : ∀ i ∈ I, i < N) : (stepF v N I).1.card ≤ 16 * I.card ∧ (∀ x, ((stepF v N I).1.filter (fun r => r.1 = x)).card ≤ 16) ∧ (∀ r ∈ (stepF v N I).1, RowOK v r ∧ r.1 ∈ I ∧ r.2.1 ⊆ I) ∧ (stepF v N I).2.1 ⊆ I ∧ (stepF v N I).2.2 ⊆ I ∧ Disjoint (stepF v N I).2.1 (stepF v N I).2.2 ∧ 4 * ((stepF v N I).2.1.card ^ 2 + (stepF v N I).2.2.card ^ 2) ≤ 3 * I.card ^ 2 ∧ ∀ i ∈ I, ∀ j ∈ I, i ≠ j → (∃ r ∈ (stepF v N I).1, RCov r i j) ∨ (i ∈ (stepF v N I).2.1 ∧ j ∈ (stepF v N I).2.1) ∨ (i ∈ (stepF v N I).2.2 ∧ j ∈ (stepF v N I).2.2) := by classical have h : Ccw v N ∧ (∀ i < N, ∀ j < N, v i = v j → i = j) ∧ ∀ i ∈ I, i < N := ⟨hccw, hinj, hI⟩ unfold stepF rw [dif_pos h] exact Classical.choose_spec (node_step h.1 h.2.1 I h.2.2) /-- The nodes of depth `l`. -/ noncomputable def nodes (v : ℕ → ℂ) (N : ℕ) : ℕ → Finset (Finset ℕ) | 0 => {range N} | l + 1 => (nodes v N l).biUnion (fun I => {(stepF v N I).2.1, (stepF v N I).2.2}) /-- The rows of depth `l`. -/ noncomputable def lrows (v : ℕ → ℂ) (N : ℕ) (l : ℕ) : Finset (ℕ × Finset ℕ × Bool) := (nodes v N l).biUnion (fun I => (stepF v N I).1) theorem nodes_lt {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) : ∀ l, ∀ I ∈ nodes v N l, ∀ i ∈ I, i < N := by intro l induction l with | zero => intro I hI i hi simp only [nodes, mem_singleton] at hI rw [hI] at hi exact mem_range.mp hi | succ l ih => intro J hJ i hi simp only [nodes, mem_biUnion, mem_insert, mem_singleton] at hJ obtain ⟨I, hI, hJ⟩ := hJ have hs := stepF_spec hccw hinj (ih I hI) rcases hJ with rfl | rfl · exact ih I hI i (hs.2.2.2.1 hi) · exact ih I hI i (hs.2.2.2.2.1 hi) theorem nodes_disj {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) : ∀ l, ∀ I ∈ nodes v N l, ∀ J ∈ nodes v N l, I ≠ J → Disjoint I J := by intro l induction l with | zero => intro I hI J hJ hIJ simp only [nodes, mem_singleton] at hI hJ exact absurd (hI.trans hJ.symm) hIJ | succ l ih => intro A hA B hB hAB simp only [nodes, mem_biUnion, mem_insert, mem_singleton] at hA hB obtain ⟨I, hI, hA⟩ := hA obtain ⟨J, hJ, hB⟩ := hB have hsI := stepF_spec hccw hinj (nodes_lt hccw hinj l I hI) have hsJ := stepF_spec hccw hinj (nodes_lt hccw hinj l J hJ) have hAI : A ⊆ I := by rcases hA with rfl | rfl; exact hsI.2.2.2.1; exact hsI.2.2.2.2.1 have hBJ : B ⊆ J := by rcases hB with rfl | rfl; exact hsJ.2.2.2.1; exact hsJ.2.2.2.2.1 by_cases hIJ : I = J · subst hIJ rcases hA with rfl | rfl <;> rcases hB with rfl | rfl · exact absurd rfl hAB · exact hsI.2.2.2.2.2.1 · exact hsI.2.2.2.2.2.1.symm · exact absurd rfl hAB · exact disjoint_of_subset_left hAI (disjoint_of_subset_right hBJ (ih I hI J hJ hIJ)) theorem nodes_sum_card {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) (l : ℕ) : ∑ I ∈ nodes v N l, I.card ≤ N := by classical have h1 : ((nodes v N l).biUnion id).card = ∑ I ∈ nodes v N l, I.card := card_biUnion (fun I hI J hJ hIJ => nodes_disj hccw hinj l I hI J hJ hIJ) rw [← h1] have h2 : (nodes v N l).biUnion id ⊆ range N := by intro i hi obtain ⟨I, hI, hiI⟩ := mem_biUnion.mp hi exact mem_range.mpr (nodes_lt hccw hinj l I hI i hiI) have := card_le_card h2 rwa [card_range] at this /-- A sum over a `biUnion` is at most the sum of the sums. -/ theorem sum_biUnion_le' {ι β : Type*} [DecidableEq β] (s : Finset ι) (t : ι → Finset β) (f : β → ℕ) : ∑ x ∈ s.biUnion t, f x ≤ ∑ i ∈ s, ∑ x ∈ t i, f x := by classical induction s using Finset.induction_on with | empty => simp | insert a s ha ih => rw [biUnion_insert, sum_insert ha] have h1 : ∑ x ∈ t a ∪ s.biUnion t, f x ≤ ∑ x ∈ t a, f x + ∑ x ∈ s.biUnion t, f x := by have := sum_union_inter (s₁ := t a) (s₂ := s.biUnion t) (f := f) omega omega theorem nodes_sq {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) : ∀ l, 4 ^ l * ∑ I ∈ nodes v N l, I.card ^ 2 ≤ 3 ^ l * N ^ 2 := by classical intro l induction l with | zero => simp [nodes] | succ l ih => have h1 : ∑ J ∈ nodes v N (l + 1), J.card ^ 2 ≤ ∑ I ∈ nodes v N l, ∑ J ∈ ({(stepF v N I).2.1, (stepF v N I).2.2} : Finset (Finset ℕ)), J.card ^ 2 := by simp only [nodes] exact sum_biUnion_le' _ _ _ have h2 : ∀ I ∈ nodes v N l, 4 * ∑ J ∈ ({(stepF v N I).2.1, (stepF v N I).2.2} : Finset (Finset ℕ)), J.card ^ 2 ≤ 3 * I.card ^ 2 := by intro I hI have hs := stepF_spec hccw hinj (nodes_lt hccw hinj l I hI) have h3 : ∑ J ∈ ({(stepF v N I).2.1, (stepF v N I).2.2} : Finset (Finset ℕ)), J.card ^ 2 ≤ (stepF v N I).2.1.card ^ 2 + (stepF v N I).2.2.card ^ 2 := by by_cases he : (stepF v N I).2.1 = (stepF v N I).2.2 · rw [he]; simp · rw [sum_pair he] have := hs.2.2.2.2.2.2.1 omega have h4 : 4 * ∑ I ∈ nodes v N l, ∑ J ∈ ({(stepF v N I).2.1, (stepF v N I).2.2} : Finset (Finset ℕ)), J.card ^ 2 ≤ 3 * ∑ I ∈ nodes v N l, I.card ^ 2 := by rw [mul_sum, mul_sum] exact sum_le_sum h2 calc 4 ^ (l + 1) * ∑ J ∈ nodes v N (l + 1), J.card ^ 2 ≤ 4 ^ (l + 1) * ∑ I ∈ nodes v N l, ∑ J ∈ ({(stepF v N I).2.1, (stepF v N I).2.2} : Finset (Finset ℕ)), J.card ^ 2 := Nat.mul_le_mul_left _ h1 _ = 4 ^ l * (4 * ∑ I ∈ nodes v N l, ∑ J ∈ ({(stepF v N I).2.1, (stepF v N I).2.2} : Finset (Finset ℕ)), J.card ^ 2) := by ring _ ≤ 4 ^ l * (3 * ∑ I ∈ nodes v N l, I.card ^ 2) := Nat.mul_le_mul_left _ h4 _ = 3 * (4 ^ l * ∑ I ∈ nodes v N l, I.card ^ 2) := by ring _ ≤ 3 * (3 ^ l * N ^ 2) := Nat.mul_le_mul_left _ ih _ = 3 ^ (l + 1) * N ^ 2 := by ring theorem lrows_card {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) (l : ℕ) : (lrows v N l).card ≤ 16 * N := by classical unfold lrows refine le_trans card_biUnion_le ?_ have h1 : ∑ I ∈ nodes v N l, (stepF v N I).1.card ≤ ∑ I ∈ nodes v N l, 16 * I.card := sum_le_sum (fun I hI => (stepF_spec hccw hinj (nodes_lt hccw hinj l I hI)).1) rw [← mul_sum] at h1 have := nodes_sum_card hccw hinj l omega theorem lrows_ok {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) (l : ℕ) : ∀ r ∈ lrows v N l, RowOK v r ∧ ∃ I ∈ nodes v N l, r.1 ∈ I ∧ r.2.1 ⊆ I := by intro r hr unfold lrows at hr obtain ⟨I, hI, hrI⟩ := mem_biUnion.mp hr have hs := (stepF_spec hccw hinj (nodes_lt hccw hinj l I hI)).2.2.1 r hrI exact ⟨hs.1, I, hI, hs.2.1, hs.2.2⟩ /-- At most `16` rows of a given depth have a given pole. -/ theorem lrows_pole {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) (l x : ℕ) : ((lrows v N l).filter (fun r => r.1 = x)).card ≤ 16 := by classical have hsub : (lrows v N l).filter (fun r => r.1 = x) ⊆ ((nodes v N l).filter (fun I => x ∈ I)).biUnion (fun I => (stepF v N I).1.filter (fun r => r.1 = x)) := by intro r hr obtain ⟨hr1, hr2⟩ := mem_filter.mp hr unfold lrows at hr1 obtain ⟨I, hI, hrI⟩ := mem_biUnion.mp hr1 have hs := (stepF_spec hccw hinj (nodes_lt hccw hinj l I hI)).2.2.1 r hrI refine mem_biUnion.mpr ⟨I, mem_filter.mpr ⟨hI, ?_⟩, mem_filter.mpr ⟨hrI, hr2⟩⟩ rw [← hr2]; exact hs.2.1 have hone : ((nodes v N l).filter (fun I => x ∈ I)).card ≤ 1 := by rw [card_le_one] intro I hI J hJ obtain ⟨hI1, hI2⟩ := mem_filter.mp hI obtain ⟨hJ1, hJ2⟩ := mem_filter.mp hJ by_contra hne exact (disjoint_left.mp (nodes_disj hccw hinj l I hI1 J hJ1 hne)) hI2 hJ2 refine le_trans (card_le_card hsub) (le_trans card_biUnion_le ?_) have h1 : ∑ I ∈ (nodes v N l).filter (fun I => x ∈ I), ((stepF v N I).1.filter (fun r => r.1 = x)).card ≤ ∑ _I ∈ (nodes v N l).filter (fun I => x ∈ I), 16 := by refine sum_le_sum (fun I hI => ?_) exact (stepF_spec hccw hinj (nodes_lt hccw hinj l I (mem_filter.mp hI).1)).2.1 x rw [sum_const, smul_eq_mul] at h1 omega theorem cover_lvl {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) : ∀ l, ∀ i < N, ∀ j < N, i ≠ j → (∃ l' < l, ∃ r ∈ lrows v N l', RCov r i j) ∨ ∃ I ∈ nodes v N l, i ∈ I ∧ j ∈ I := by intro l induction l with | zero => intro i hi j hj _ exact Or.inr ⟨range N, by simp [nodes], mem_range.mpr hi, mem_range.mpr hj⟩ | succ l ih => intro i hi j hj hij rcases ih i hi j hj hij with ⟨l', hl', h⟩ | ⟨I, hI, hiI, hjI⟩ · exact Or.inl ⟨l', by omega, h⟩ · have hs := stepF_spec hccw hinj (nodes_lt hccw hinj l I hI) rcases hs.2.2.2.2.2.2.2 i hiI j hjI hij with ⟨r, hr, hc⟩ | h | h · exact Or.inl ⟨l, by omega, r, mem_biUnion.mpr ⟨I, hI, hr⟩, hc⟩ · refine Or.inr ⟨(stepF v N I).2.1, ?_, h.1, h.2⟩ simp only [nodes, mem_biUnion, mem_insert, mem_singleton] exact ⟨I, hI, Or.inl rfl⟩ · refine Or.inr ⟨(stepF v N I).2.2, ?_, h.1, h.2⟩ simp only [nodes, mem_biUnion, mem_insert, mem_singleton] exact ⟨I, hI, Or.inr rfl⟩ theorem pow_bern (L : ℕ) : (3 + L) * 3 ^ L ≤ 3 * 4 ^ L := by induction L with | zero => simp | succ L ih => have e1 : (3 + (L + 1)) * 3 ^ (L + 1) ≤ 4 * ((3 + L) * 3 ^ L) := by have : 0 < 3 ^ L := by positivity rw [pow_succ] nlinarith calc (3 + (L + 1)) * 3 ^ (L + 1) ≤ 4 * ((3 + L) * 3 ^ L) := e1 _ ≤ 4 * (3 * 4 ^ L) := Nat.mul_le_mul_left _ ih _ = 3 * 4 ^ (L + 1) := by ring /-- Every pair is covered by a row of depth `< N²`. -/ theorem cover_all {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) {i j : ℕ} (hi : i < N) (hj : j < N) (hij : i ≠ j) : ∃ l < N ^ 2, ∃ r ∈ lrows v N l, RCov r i j := by classical rcases cover_lvl hccw hinj (N ^ 2) i hi j hj hij with h | ⟨I, hI, hiI, hjI⟩ · exact h · exfalso have h2 : 2 ≤ I.card := by have hsub : ({i, j} : Finset ℕ) ⊆ I := by intro x hx rcases mem_insert.mp hx with rfl | hx · exact hiI · rw [mem_singleton.mp hx]; exact hjI have := card_le_card hsub rwa [card_pair hij] at this have h3 : 4 ≤ ∑ J ∈ nodes v N (N ^ 2), J.card ^ 2 := by have h4 : I.card ^ 2 ≤ ∑ J ∈ nodes v N (N ^ 2), J.card ^ 2 := single_le_sum (f := fun J : Finset ℕ => J.card ^ 2) (fun _ _ => Nat.zero_le _) hI nlinarith have h5 := nodes_sq hccw hinj (N ^ 2) have h6 := pow_bern (N ^ 2) have h7 : 4 ^ (N ^ 2) * 4 ≤ 3 ^ (N ^ 2) * N ^ 2 := le_trans (Nat.mul_le_mul_left _ h3) h5 have h8 : 0 < 3 ^ (N ^ 2) := by positivity nlinarith /-- The ordered pairs `(pole, free end)` of the rows of depth `l`. -/ noncomputable def lpairs (v : ℕ → ℂ) (N : ℕ) (l : ℕ) : Finset (ℕ × ℕ) := (lrows v N l).biUnion (fun r => r.2.1.image (fun y => (r.1, y))) theorem lpairs_card {v : ℕ → ℂ} {N : ℕ} (hccw : Ccw v N) (hinj : ∀ i < N, ∀ j < N, v i = v j → i = j) (l : ℕ) : 4 ^ l * (lpairs v N l).card ≤ 3 ^ l * N ^ 2 := by classical have hsub : lpairs v N l ⊆ (nodes v N l).biUnion (fun I => I ×ˢ I) := by intro x hx unfold lpairs at hx obtain ⟨r, hr, hxr⟩ := mem_biUnion.mp hx obtain ⟨y, hy, rfl⟩ := mem_image.mp hxr obtain ⟨_, I, hI, h1, h2⟩ := lrows_ok hccw hinj l r hr exact mem_biUnion.mpr ⟨I, hI, mem_product.mpr ⟨h1, h2 hy⟩⟩ have h1 : (lpairs v N l).card ≤ ∑ I ∈ nodes v N l, I.card ^ 2 := by refine le_trans (card_le_card hsub) (le_trans card_biUnion_le ?_) refine sum_le_sum (fun I _ => ?_) rw [card_product, sq] exact le_trans (Nat.mul_le_mul_left _ h1) (nodes_sq hccw hinj l) end E94S /-! ### SOLO slice B2a -/ /-! ## SOLO module B (part 2a): window algebra — the pole relation and the line case -/ namespace E94S open Finset /-- Squared distance of two complex numbers in coordinates. -/ def dq (z w : ℂ) : ℝ := (z.re - w.re) ^ 2 + (z.im - w.im) ^ 2 theorem dq_nonneg (z w : ℂ) : 0 ≤ dq z w := by unfold dq; positivity theorem dist_eq_sqrt_dq (z w : ℂ) : dist z w = Real.sqrt (dq z w) := by rw [Complex.dist_eq_re_im]; rfl theorem dq_eq_of_dist_eq {z w z' w' : ℂ} (h : dist z w = dist z' w') : dq z w = dq z' w' := by rw [dist_eq_sqrt_dq, dist_eq_sqrt_dq] at h have h1 := Real.sq_sqrt (dq_nonneg z w) have h2 := Real.sq_sqrt (dq_nonneg z' w') rw [h] at h1 linarith theorem dist_eq_of_dq_eq {z w z' w' : ℂ} (h : dq z w = dq z' w') : dist z w = dist z' w' := by rw [dist_eq_sqrt_dq, dist_eq_sqrt_dq, h] /-- Cross product (orientation) of three complex points. -/ def cr3 (a b c : ℂ) : ℝ := (b.re - a.re) * (c.im - a.im) - (b.im - a.im) * (c.re - a.re) /-- The real-linear map with matrix `((l11, l12), (l21, l22))` sends `u` to `u'`. -/ def LinMap (l11 l12 l21 l22 : ℝ) (u u' : ℂ) : Prop := l11 * u.re + l12 * u.im = u'.re ∧ l21 * u.re + l22 * u.im = u'.im /-- The transposed matrix applied to `z`. -/ def linT (l11 l12 l21 l22 : ℝ) (z : ℂ) : ℂ := ⟨l11 * z.re + l21 * z.im, l12 * z.re + l22 * z.im⟩ /-- The matrix applied to `z`. -/ def linA (l11 l12 l21 l22 : ℝ) (z : ℂ) : ℂ := ⟨l11 * z.re + l12 * z.im, l21 * z.re + l22 * z.im⟩ theorem linMap_linA (l11 l12 l21 l22 : ℝ) (u : ℂ) : LinMap l11 l12 l21 l22 u (linA l11 l12 l21 l22 u) := ⟨rfl, rfl⟩ /-- Three non-collinear points and three targets: the linear part of the affine map exists. -/ theorem exists_lin {Y1 Y2 Y3 Z1 Z2 Z3 : ℂ} (hdet : cr3 Y1 Y2 Y3 ≠ 0) : ∃ l11 l12 l21 l22 : ℝ, LinMap l11 l12 l21 l22 (Y2 - Y1) (Z2 - Z1) ∧ LinMap l11 l12 l21 l22 (Y3 - Y1) (Z3 - Z1) := by refine ⟨((Z2.re - Z1.re) * (Y3.im - Y1.im) - (Z3.re - Z1.re) * (Y2.im - Y1.im)) / cr3 Y1 Y2 Y3, ((Z3.re - Z1.re) * (Y2.re - Y1.re) - (Z2.re - Z1.re) * (Y3.re - Y1.re)) / cr3 Y1 Y2 Y3, ((Z2.im - Z1.im) * (Y3.im - Y1.im) - (Z3.im - Z1.im) * (Y2.im - Y1.im)) / cr3 Y1 Y2 Y3, ((Z3.im - Z1.im) * (Y2.re - Y1.re) - (Z2.im - Z1.im) * (Y3.re - Y1.re)) / cr3 Y1 Y2 Y3, ?_, ?_⟩ · unfold LinMap simp only [Complex.sub_re, Complex.sub_im] constructor · rw [div_mul_eq_mul_div, div_mul_eq_mul_div, ← add_div, div_eq_iff hdet]; unfold cr3; ring · rw [div_mul_eq_mul_div, div_mul_eq_mul_div, ← add_div, div_eq_iff hdet]; unfold cr3; ring · unfold LinMap simp only [Complex.sub_re, Complex.sub_im] constructor · rw [div_mul_eq_mul_div, div_mul_eq_mul_div, ← add_div, div_eq_iff hdet]; unfold cr3; ring · rw [div_mul_eq_mul_div, div_mul_eq_mul_div, ← add_div, div_eq_iff hdet]; unfold cr3; ring /-- **The pole relation.** If `(P, P')` and `(S, S')` are both equidistant solutions for the three matches `(Y_i, Z_i)` and `L` maps `Y_i - Y_1` to `Z_i - Z_1`, then `P - S = Lᵀ (P' - S')`. -/ theorem pole_rel {Y1 Y2 Y3 Z1 Z2 Z3 P P' S S' : ℂ} {l11 l12 l21 l22 : ℝ} (hdet : cr3 Y1 Y2 Y3 ≠ 0) (hL2 : LinMap l11 l12 l21 l22 (Y2 - Y1) (Z2 - Z1)) (hL3 : LinMap l11 l12 l21 l22 (Y3 - Y1) (Z3 - Z1)) (hP1 : dq P Y1 = dq P' Z1) (hP2 : dq P Y2 = dq P' Z2) (hP3 : dq P Y3 = dq P' Z3) (hS1 : dq S Y1 = dq S' Z1) (hS2 : dq S Y2 = dq S' Z2) (hS3 : dq S Y3 = dq S' Z3) : P - S = linT l11 l12 l21 l22 (P' - S') := by unfold LinMap at hL2 hL3 simp only [Complex.sub_re, Complex.sub_im] at hL2 hL3 obtain ⟨hL2a, hL2b⟩ := hL2 obtain ⟨hL3a, hL3b⟩ := hL3 unfold dq at hP1 hP2 hP3 hS1 hS2 hS3 unfold cr3 at hdet have e2 : (P.re - S.re) * (Y2.re - Y1.re) + (P.im - S.im) * (Y2.im - Y1.im) = (P'.re - S'.re) * (Z2.re - Z1.re) + (P'.im - S'.im) * (Z2.im - Z1.im) := by linear_combination (1 / 2 : ℝ) * (hP1 - hP2 - hS1 + hS2) have e3 : (P.re - S.re) * (Y3.re - Y1.re) + (P.im - S.im) * (Y3.im - Y1.im) = (P'.re - S'.re) * (Z3.re - Z1.re) + (P'.im - S'.im) * (Z3.im - Z1.im) := by linear_combination (1 / 2 : ℝ) * (hP1 - hP3 - hS1 + hS3) obtain ⟨W1, hW1⟩ : ∃ W1 : ℝ, W1 = (P.re - S.re) - (l11 * (P'.re - S'.re) + l21 * (P'.im - S'.im)) := ⟨_, rfl⟩ obtain ⟨W2, hW2⟩ : ∃ W2 : ℝ, W2 = (P.im - S.im) - (l12 * (P'.re - S'.re) + l22 * (P'.im - S'.im)) := ⟨_, rfl⟩ have f2 : W1 * (Y2.re - Y1.re) + W2 * (Y2.im - Y1.im) = 0 := by rw [hW1, hW2] linear_combination e2 - (P'.re - S'.re) * hL2a - (P'.im - S'.im) * hL2b have f3 : W1 * (Y3.re - Y1.re) + W2 * (Y3.im - Y1.im) = 0 := by rw [hW1, hW2] linear_combination e3 - (P'.re - S'.re) * hL3a - (P'.im - S'.im) * hL3b have g1 : W1 * ((Y2.re - Y1.re) * (Y3.im - Y1.im) - (Y2.im - Y1.im) * (Y3.re - Y1.re)) = 0 := by linear_combination (Y3.im - Y1.im) * f2 - (Y2.im - Y1.im) * f3 have g2 : W2 * ((Y2.re - Y1.re) * (Y3.im - Y1.im) - (Y2.im - Y1.im) * (Y3.re - Y1.re)) = 0 := by linear_combination (Y2.re - Y1.re) * f3 - (Y3.re - Y1.re) * f2 have k1 : W1 = 0 := (mul_eq_zero.mp g1).resolve_right hdet have k2 : W2 = 0 := (mul_eq_zero.mp g2).resolve_right hdet apply Complex.ext · simp only [Complex.sub_re, linT, Complex.sub_im] linarith · simp only [Complex.sub_im, linT, Complex.sub_re] linarith /-- **The line relation.** With a fourth match, the primed poles of two solutions differ by a vector orthogonal to `e = L (Y4 - Y1) - (Z4 - Z1)`. -/ theorem line_rel {Y1 Y4 Z1 Z4 P P' S S' : ℂ} {l11 l12 l21 l22 : ℝ} (hrel : P - S = linT l11 l12 l21 l22 (P' - S')) (hP1 : dq P Y1 = dq P' Z1) (hP4 : dq P Y4 = dq P' Z4) (hS1 : dq S Y1 = dq S' Z1) (hS4 : dq S Y4 = dq S' Z4) : (P'.re - S'.re) * ((linA l11 l12 l21 l22 (Y4 - Y1)).re - (Z4.re - Z1.re)) + (P'.im - S'.im) * ((linA l11 l12 l21 l22 (Y4 - Y1)).im - (Z4.im - Z1.im)) = 0 := by unfold dq at hP1 hP4 hS1 hS4 have h1 := congrArg Complex.re hrel have h2 := congrArg Complex.im hrel simp only [Complex.sub_re, Complex.sub_im, linT] at h1 h2 simp only [linA, Complex.sub_re, Complex.sub_im] have e4 : (P.re - S.re) * (Y4.re - Y1.re) + (P.im - S.im) * (Y4.im - Y1.im) = (P'.re - S'.re) * (Z4.re - Z1.re) + (P'.im - S'.im) * (Z4.im - Z1.im) := by linear_combination (1 / 2 : ℝ) * (hP1 - hP4 - hS1 + hS4) rw [h1, h2] at e4 linear_combination e4 /-- Two nonzero-orthogonality relations to a common nonzero vector force collinearity. -/ theorem cr3_zero_of_orth {A B C : ℂ} {e1 e2 : ℝ} (he : e1 ≠ 0 ∨ e2 ≠ 0) (h1 : (B.re - A.re) * e1 + (B.im - A.im) * e2 = 0) (h2 : (C.re - A.re) * e1 + (C.im - A.im) * e2 = 0) : cr3 A B C = 0 := by unfold cr3 rcases he with he | he · have : e1 * ((B.re - A.re) * (C.im - A.im) - (B.im - A.im) * (C.re - A.re)) = 0 := by linear_combination (C.im - A.im) * h1 - (B.im - A.im) * h2 exact (mul_eq_zero.mp this).resolve_left he · have : e2 * ((B.re - A.re) * (C.im - A.im) - (B.im - A.im) * (C.re - A.re)) = 0 := by linear_combination (B.re - A.re) * h2 - (C.re - A.re) * h1 exact (mul_eq_zero.mp this).resolve_left he end E94S /-! ### SOLO slice B2b -/ /-! ## SOLO module B (part 2b): window algebra — similarity matrices, the isometry case and the circle case -/ namespace E94S open Finset /-- A matrix with `L Lᵀ = Λ·I` is a scaled rotation or a scaled reflection. -/ theorem sim_cases {l11 l12 l21 l22 Λ : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) : (l22 = l11 ∧ l12 = -l21) ∨ (l22 = -l11 ∧ l12 = l21) := by have hdet : (l11 * l22 - l12 * l21 - Λ) * (l11 * l22 - l12 * l21 + Λ) = 0 := by linear_combination (l21 ^ 2 + l22 ^ 2) * hr1 + Λ * hr2 - (l11 * l21 + l12 * l22) * hr3 rcases mul_eq_zero.mp hdet with h | h · left have h2 : (l22 - l11) ^ 2 + (l12 + l21) ^ 2 = 0 := by linear_combination hr1 + hr2 - 2 * h constructor <;> nlinarith [sq_nonneg (l22 - l11), sq_nonneg (l12 + l21)] · right have h2 : (l22 + l11) ^ 2 + (l12 - l21) ^ 2 = 0 := by linear_combination hr1 + hr2 + 2 * h constructor <;> nlinarith [sq_nonneg (l22 + l11), sq_nonneg (l12 - l21)] /-- The key identity of an affine window whose matrix satisfies `L Lᵀ = Λ·I`: for a solution `(P, P')` with `P = Lᵀ P' + q₀` of the match `(Y, Z)`, and any `c'` with `(Λ - 1) c' = -(Z - L (Y - q₀))`. -/ theorem sim_key {l11 l12 l21 l22 Λ : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) {q₀ Y Z c' P P' : ℂ} (hP : P = linT l11 l12 l21 l22 P' + q₀) (hc1 : (Λ - 1) * c'.re = -(Z.re - (l11 * (Y.re - q₀.re) + l12 * (Y.im - q₀.im)))) (hc2 : (Λ - 1) * c'.im = -(Z.im - (l21 * (Y.re - q₀.re) + l22 * (Y.im - q₀.im)))) (h : dq P Y = dq P' Z) : (Λ - 1) * (dq P' c' - (c'.re ^ 2 + c'.im ^ 2)) + dq q₀ Y - (Z.re ^ 2 + Z.im ^ 2) = 0 := by have h1 := congrArg Complex.re hP have h2 := congrArg Complex.im hP simp only [Complex.add_re, Complex.add_im, linT] at h1 h2 unfold dq at h ⊢ rw [h1, h2] at h linear_combination h - P'.re ^ 2 * hr1 - P'.im ^ 2 * hr2 - 2 * P'.re * P'.im * hr3 - 2 * P'.re * hc1 - 2 * P'.im * hc2 /-- In an affine window with `L Lᵀ = Λ·I`, `Λ ≠ 1`: all primed poles are equidistant from `c'`. -/ theorem sim_poles' {l11 l12 l21 l22 Λ : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) (hΛ : Λ ≠ 1) {q₀ Y Z c' P P' S S' : ℂ} (hP : P = linT l11 l12 l21 l22 P' + q₀) (hS : S = linT l11 l12 l21 l22 S' + q₀) (hc1 : (Λ - 1) * c'.re = -(Z.re - (l11 * (Y.re - q₀.re) + l12 * (Y.im - q₀.im)))) (hc2 : (Λ - 1) * c'.im = -(Z.im - (l21 * (Y.re - q₀.re) + l22 * (Y.im - q₀.im)))) (h : dq P Y = dq P' Z) (h' : dq S Y = dq S' Z) : dq P' c' = dq S' c' := by have e1 := sim_key hr1 hr2 hr3 hP hc1 hc2 h have e2 := sim_key hr1 hr2 hr3 hS hc1 hc2 h' have e3 : (Λ - 1) * (dq P' c' - dq S' c') = 0 := by linear_combination e1 - e2 have := (mul_eq_zero.mp e3).resolve_left (sub_ne_zero.mpr hΛ) linarith /-- The unprimed poles lie on the circle about `c = Lᵀ c' + q₀` of squared radius `Λ·|P' - c'|²`. -/ theorem sim_poles {l11 l12 l21 l22 Λ : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) {q₀ c' P P' : ℂ} (hP : P = linT l11 l12 l21 l22 P' + q₀) : dq P (linT l11 l12 l21 l22 c' + q₀) = Λ * dq P' c' := by have h1 := congrArg Complex.re hP have h2 := congrArg Complex.im hP simp only [Complex.add_re, Complex.add_im, linT] at h1 h2 unfold dq simp only [Complex.add_re, Complex.add_im, linT] rw [h1, h2] linear_combination ((P'.re - c'.re) ^ 2) * hr1 + ((P'.im - c'.im) ^ 2) * hr2 + 2 * (P'.re - c'.re) * (P'.im - c'.im) * hr3 /-- Rows `L Lᵀ = Λ·I` give columns `Lᵀ L = Λ·I`. -/ theorem sim_cols {l11 l12 l21 l22 Λ : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) : l11 ^ 2 + l21 ^ 2 = Λ ∧ l12 ^ 2 + l22 ^ 2 = Λ ∧ l11 * l12 + l21 * l22 = 0 := by rcases sim_cases hr1 hr2 hr3 with ⟨h22, h12⟩ | ⟨h22, h12⟩ · refine ⟨?_, ?_, ?_⟩ · linear_combination hr2 + (-l11 - l22) * h22 · linear_combination hr1 + (l11 + l22) * h22 · linear_combination hr3 + (-l12 + l21) * h22 · refine ⟨?_, ?_, ?_⟩ · linear_combination hr2 + (l11 - l22) * h22 · linear_combination hr1 + (-l11 + l22) * h22 · linear_combination (-1 : ℝ) * hr3 + (l12 + l21) * h22 /-- The free ends: `Z - c' = L (Y - c)`, hence `|Z - c'|² = Λ |Y - c|²`. -/ theorem sim_free' {l11 l12 l21 l22 Λ : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) {q₀ Y Z c' : ℂ} (hc1 : (Λ - 1) * c'.re = -(Z.re - (l11 * (Y.re - q₀.re) + l12 * (Y.im - q₀.im)))) (hc2 : (Λ - 1) * c'.im = -(Z.im - (l21 * (Y.re - q₀.re) + l22 * (Y.im - q₀.im)))) : dq Z c' = Λ * dq Y (linT l11 l12 l21 l22 c' + q₀) := by obtain ⟨k1, k2, k3⟩ := sim_cols hr1 hr2 hr3 have hZ1 : Z.re - c'.re = l11 * (Y.re - (l11 * c'.re + l21 * c'.im + q₀.re)) + l12 * (Y.im - (l12 * c'.re + l22 * c'.im + q₀.im)) := by linear_combination hc1 + c'.re * hr1 + c'.im * hr3 have hZ2 : Z.im - c'.im = l21 * (Y.re - (l11 * c'.re + l21 * c'.im + q₀.re)) + l22 * (Y.im - (l12 * c'.re + l22 * c'.im + q₀.im)) := by linear_combination hc2 + c'.re * hr3 + c'.im * hr2 unfold dq simp only [Complex.add_re, Complex.add_im, linT] rw [hZ1, hZ2] linear_combination ((Y.re - (l11 * c'.re + l21 * c'.im + q₀.re)) ^ 2) * k1 + ((Y.im - (l12 * c'.re + l22 * c'.im + q₀.im)) ^ 2) * k2 + 2 * (Y.re - (l11 * c'.re + l21 * c'.im + q₀.re)) * (Y.im - (l12 * c'.re + l22 * c'.im + q₀.im)) * k3 /-- The free ends `Y` lie on the circle about `c` of squared radius `|P' - c'|²`. -/ theorem sim_free {l11 l12 l21 l22 Λ : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) (hΛ : Λ ≠ 1) {q₀ Y Z c' P P' : ℂ} (hP : P = linT l11 l12 l21 l22 P' + q₀) (hc1 : (Λ - 1) * c'.re = -(Z.re - (l11 * (Y.re - q₀.re) + l12 * (Y.im - q₀.im)))) (hc2 : (Λ - 1) * c'.im = -(Z.im - (l21 * (Y.re - q₀.re) + l22 * (Y.im - q₀.im)))) (h : dq P Y = dq P' Z) : dq Y (linT l11 l12 l21 l22 c' + q₀) = dq P' c' := by obtain ⟨k1, k2, k3⟩ := sim_cols hr1 hr2 hr3 have e1 := sim_key hr1 hr2 hr3 hP hc1 hc2 h have e3 : (Λ - 1) * (dq P' c' - dq Y (linT l11 l12 l21 l22 c' + q₀)) = 0 := by unfold dq at e1 ⊢ simp only [Complex.add_re, Complex.add_im, linT] linear_combination e1 - (Λ - 1) * (c'.re ^ 2 * hr1 + c'.im ^ 2 * hr2 + 2 * c'.re * c'.im * hr3) + ((Y.re - q₀.re) ^ 2 * k1 + (Y.im - q₀.im) ^ 2 * k2 + 2 * (Y.re - q₀.re) * (Y.im - q₀.im) * k3) + (Z.re + (l11 * (Y.re - q₀.re) + l12 * (Y.im - q₀.im) - (Λ - 1) * c'.re)) * hc1 + (Z.im + (l21 * (Y.re - q₀.re) + l22 * (Y.im - q₀.im) - (Λ - 1) * c'.im)) * hc2 have := (mul_eq_zero.mp e3).resolve_left (sub_ne_zero.mpr hΛ) linarith end E94S /-! ### SOLO slice B2c -/ /-! ## SOLO module B (part 2c): window algebra — the orthogonal case gives an isometry -/ namespace E94S open Finset /-- A point equidistant (pairwise with `Z`) from three non-collinear points equals `Z`. -/ theorem eq_of_three_equidist {A B C W Z : ℂ} (hdet : cr3 A B C ≠ 0) (hA : dq A W = dq A Z) (hB : dq B W = dq B Z) (hC : dq C W = dq C Z) : W = Z := by unfold dq at hA hB hC unfold cr3 at hdet have e1 : (B.re - A.re) * (W.re - Z.re) + (B.im - A.im) * (W.im - Z.im) = 0 := by linear_combination (1 / 2 : ℝ) * (hA - hB) have e2 : (C.re - A.re) * (W.re - Z.re) + (C.im - A.im) * (W.im - Z.im) = 0 := by linear_combination (1 / 2 : ℝ) * (hA - hC) have g1 : (W.re - Z.re) * ((B.re - A.re) * (C.im - A.im) - (B.im - A.im) * (C.re - A.re)) = 0 := by linear_combination (C.im - A.im) * e1 - (B.im - A.im) * e2 have g2 : (W.im - Z.im) * ((B.re - A.re) * (C.im - A.im) - (B.im - A.im) * (C.re - A.re)) = 0 := by linear_combination (B.re - A.re) * e2 - (C.re - A.re) * e1 have k1 := (mul_eq_zero.mp g1).resolve_right hdet have k2 := (mul_eq_zero.mp g2).resolve_right hdet apply Complex.ext <;> linarith /-- For an orthogonal matrix, `P = Lᵀ P' + q₀` inverts to `P' = L (P - q₀)`. -/ theorem orth_inv {l11 l12 l21 l22 : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = 1) (hr2 : l21 ^ 2 + l22 ^ 2 = 1) (hr3 : l11 * l21 + l12 * l22 = 0) {q₀ P P' : ℂ} (hP : P = linT l11 l12 l21 l22 P' + q₀) : P' = linA l11 l12 l21 l22 (P - q₀) := by have h1 := congrArg Complex.re hP have h2 := congrArg Complex.im hP simp only [Complex.add_re, Complex.add_im, linT] at h1 h2 apply Complex.ext · simp only [linA, Complex.sub_re, Complex.sub_im] rw [h1, h2] linear_combination (-P'.re) * hr1 - P'.im * hr3 · simp only [linA, Complex.sub_re, Complex.sub_im] rw [h1, h2] linear_combination (-P'.re) * hr3 - P'.im * hr2 /-- An orthogonal matrix preserves squared distances. -/ theorem orth_dq {l11 l12 l21 l22 : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = 1) (hr2 : l21 ^ 2 + l22 ^ 2 = 1) (hr3 : l11 * l21 + l12 * l22 = 0) (q₀ z w : ℂ) : dq (linA l11 l12 l21 l22 (z - q₀)) (linA l11 l12 l21 l22 (w - q₀)) = dq z w := by obtain ⟨k1, k2, k3⟩ := sim_cols hr1 hr2 hr3 unfold dq simp only [linA, Complex.sub_re, Complex.sub_im] linear_combination ((z.re - w.re) ^ 2) * k1 + ((z.im - w.im) ^ 2) * k2 + 2 * (z.re - w.re) * (z.im - w.im) * k3 /-- **Orthogonal windows.** Three solutions with non-collinear primed poles force `L (Y - q₀) = Z`. -/ theorem orth_base {l11 l12 l21 l22 : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = 1) (hr2 : l21 ^ 2 + l22 ^ 2 = 1) (hr3 : l11 * l21 + l12 * l22 = 0) {q₀ Y Z P1 P1' P2 P2' P3 P3' : ℂ} (hdet : cr3 P1' P2' P3' ≠ 0) (h1 : P1 = linT l11 l12 l21 l22 P1' + q₀) (h2 : P2 = linT l11 l12 l21 l22 P2' + q₀) (h3 : P3 = linT l11 l12 l21 l22 P3' + q₀) (e1 : dq P1 Y = dq P1' Z) (e2 : dq P2 Y = dq P2' Z) (e3 : dq P3 Y = dq P3' Z) : linA l11 l12 l21 l22 (Y - q₀) = Z := by have i1 := orth_inv hr1 hr2 hr3 h1 have i2 := orth_inv hr1 hr2 hr3 h2 have i3 := orth_inv hr1 hr2 hr3 h3 have d1 := orth_dq hr1 hr2 hr3 q₀ P1 Y have d2 := orth_dq hr1 hr2 hr3 q₀ P2 Y have d3 := orth_dq hr1 hr2 hr3 q₀ P3 Y rw [← i1] at d1 rw [← i2] at d2 rw [← i3] at d3 exact eq_of_three_equidist hdet (by rw [d1, e1]) (by rw [d2, e2]) (by rw [d3, e3]) /-- A rotation matrix is multiplication by a unit complex number. -/ theorem linA_rot (l11 l21 : ℝ) (z : ℂ) : linA l11 (-l21) l21 l11 z = (⟨l11, l21⟩ : ℂ) * z := by apply Complex.ext <;> simp [linA, Complex.mul_re, Complex.mul_im] <;> ring /-- A reflection matrix is multiplication of the conjugate by a unit complex number. -/ theorem linA_refl (l11 l21 : ℝ) (z : ℂ) : linA l11 l21 l21 (-l11) z = (⟨l11, l21⟩ : ℂ) * (starRingEnd ℂ) z := by apply Complex.ext <;> simp [linA, Complex.mul_re, Complex.mul_im] <;> ring theorem norm_mk_eq_one {a b : ℝ} (h : a ^ 2 + b ^ 2 = 1) : ‖(⟨a, b⟩ : ℂ)‖ = 1 := by rw [Complex.norm_def, Complex.normSq_mk] rw [show a * a + b * b = 1 by nlinarith] exact Real.sqrt_one /-- **Orthogonal windows are explained by an isometry.** If `L` is orthogonal and `L (Y₁ - q₀) = Z₁`, then `g(z) = L (z - q₀)` is a proper or improper isometry (in complex form) with `g(P) = P'` for every pole pair with `P = Lᵀ P' + q₀`, and `g(Y) = Z` for every match `(Y, Z)` with `Z - Z₁ = L (Y - Y₁)`. -/ theorem orth_iso {l11 l12 l21 l22 : ℝ} (hr1 : l11 ^ 2 + l12 ^ 2 = 1) (hr2 : l21 ^ 2 + l22 ^ 2 = 1) (hr3 : l11 * l21 + l12 * l22 = 0) {q₀ Y1 Z1 : ℂ} (hbase : linA l11 l12 l21 l22 (Y1 - q₀) = Z1) : ∃ g : ℂ × ℂ, ‖g.1‖ = 1 ∧ (((∀ P P' : ℂ, P = linT l11 l12 l21 l22 P' + q₀ → g.1 * P + g.2 = P') ∧ (∀ Y Z : ℂ, LinMap l11 l12 l21 l22 (Y - Y1) (Z - Z1) → g.1 * Y + g.2 = Z)) ∨ ((∀ P P' : ℂ, P = linT l11 l12 l21 l22 P' + q₀ → g.1 * (starRingEnd ℂ) P + g.2 = P') ∧ (∀ Y Z : ℂ, LinMap l11 l12 l21 l22 (Y - Y1) (Z - Z1) → g.1 * (starRingEnd ℂ) Y + g.2 = Z))) := by obtain ⟨k1, _, _⟩ := sim_cols hr1 hr2 hr3 have hfree : ∀ Y Z : ℂ, LinMap l11 l12 l21 l22 (Y - Y1) (Z - Z1) → linA l11 l12 l21 l22 (Y - q₀) = Z := by intro Y Z hYZ unfold LinMap at hYZ simp only [Complex.sub_re, Complex.sub_im] at hYZ have b1 := congrArg Complex.re hbase have b2 := congrArg Complex.im hbase simp only [linA, Complex.sub_re, Complex.sub_im] at b1 b2 apply Complex.ext · simp only [linA, Complex.sub_re, Complex.sub_im] linarith [hYZ.1] · simp only [linA, Complex.sub_re, Complex.sub_im] linarith [hYZ.2] rcases sim_cases hr1 hr2 hr3 with ⟨h22, h12⟩ | ⟨h22, h12⟩ · refine ⟨(⟨l11, l21⟩, -((⟨l11, l21⟩ : ℂ) * q₀)), norm_mk_eq_one k1, Or.inl ⟨?_, ?_⟩⟩ · intro P P' hP have := orth_inv hr1 hr2 hr3 hP rw [h22, h12, linA_rot] at this rw [this]; ring · intro Y Z hYZ have := hfree Y Z hYZ rw [h22, h12, linA_rot] at this rw [← this]; ring · refine ⟨(⟨l11, l21⟩, -((⟨l11, l21⟩ : ℂ) * (starRingEnd ℂ) q₀)), norm_mk_eq_one k1, Or.inr ⟨?_, ?_⟩⟩ · intro P P' hP have := orth_inv hr1 hr2 hr3 hP rw [h22, h12, linA_refl] at this rw [this, map_sub]; ring · intro Y Z hYZ have := hfree Y Z hYZ rw [h22, h12, linA_refl] at this rw [← this, map_sub]; ring end E94S /-! ### SOLO slice B3a -/ /-! ## SOLO module B (part 3a): windows of a labelled polygon — affine structure and the three types -/ namespace E94S open Finset theorem ori_eq_cr3 (v : ℕ → ℂ) (i j k : ℕ) : ori v i j k = cr3 (v i) (v j) (v k) := rfl /-- Three distinct vertices of a counterclockwise polygon are not collinear. -/ theorem ccw_cr3_ne {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) {i j k : ℕ} (hi : i < n) (hj : j < n) (hk : k < n) (hij : i ≠ j) (hik : i ≠ k) (hjk : j ≠ k) : cr3 (v i) (v j) (v k) ≠ 0 := by have s1 : cr3 (v i) (v j) (v k) = -cr3 (v j) (v i) (v k) := by unfold cr3; ring have s2 : cr3 (v i) (v j) (v k) = -cr3 (v i) (v k) (v j) := by unfold cr3; ring have s3 : cr3 (v i) (v j) (v k) = cr3 (v j) (v k) (v i) := by unfold cr3; ring have s4 : cr3 (v i) (v j) (v k) = cr3 (v k) (v i) (v j) := by unfold cr3; ring have s5 : cr3 (v i) (v j) (v k) = -cr3 (v k) (v j) (v i) := by unfold cr3; ring rcases lt_or_gt_of_ne hij with h1 | h1 <;> rcases lt_or_gt_of_ne hik with h2 | h2 <;> rcases lt_or_gt_of_ne hjk with h3 | h3 · have := hccw i j k h1 h3 hk; rw [ori_eq_cr3] at this; exact this.ne' · have := hccw i k j h2 h3 hj; rw [ori_eq_cr3] at this; rw [s2]; linarith · omega · have := hccw k i j h2 h1 hj; rw [ori_eq_cr3] at this; rw [s4]; exact this.ne' · have := hccw j i k h1 h2 hk; rw [ori_eq_cr3] at this; rw [s1]; linarith · omega · have := hccw j k i h3 h2 hi; rw [ori_eq_cr3] at this; rw [s3]; exact this.ne' · have := hccw k j i h3 h1 hi; rw [ori_eq_cr3] at this; rw [s5]; linarith theorem linT_sub (l11 l12 l21 l22 : ℝ) (z w : ℂ) : linT l11 l12 l21 l22 (z - w) = linT l11 l12 l21 l22 z - linT l11 l12 l21 l22 w := by apply Complex.ext <;> simp [linT] <;> ring theorem dq_eq_zero {z w : ℂ} (h : dq z w = 0) : z = w := by unfold dq at h apply Complex.ext <;> nlinarith [sq_nonneg (z.re - w.re), sq_nonneg (z.im - w.im)] /-- A window: four matches with distinct free ends on both sides, labels below `n`. -/ def IsWin (n : ℕ) (w : Finset (ℕ × ℕ)) : Prop := w.card = 4 ∧ (∀ m ∈ w, m.1 < n ∧ m.2 < n) ∧ (∀ m ∈ w, ∀ m' ∈ w, m.1 = m'.1 → m = m') ∧ (∀ m ∈ w, ∀ m' ∈ w, m.2 = m'.2 → m = m') open Classical in /-- The pole pairs of a window. -/ noncomputable def wsol (v : ℕ → ℂ) (n : ℕ) (w : Finset (ℕ × ℕ)) : Finset (ℕ × ℕ) := ((range n) ×ˢ (range n)).filter (fun pp => ∀ m ∈ w, dq (v pp.1) (v m.1) = dq (v pp.2) (v m.2)) theorem mem_wsol {v : ℕ → ℂ} {n : ℕ} {w : Finset (ℕ × ℕ)} {pp : ℕ × ℕ} : pp ∈ wsol v n w ↔ (pp.1 < n ∧ pp.2 < n) ∧ ∀ m ∈ w, dq (v pp.1) (v m.1) = dq (v pp.2) (v m.2) := by classical unfold wsol rw [mem_filter, mem_product, mem_range, mem_range] /-- **The affine structure of a window with at least three pole pairs.** -/ theorem win_class {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {w : Finset (ℕ × ℕ)} (hw : IsWin n w) (h3 : 3 ≤ (wsol v n w).card) : ∃ l11 l12 l21 l22 : ℝ, ∃ q₀ : ℂ, (∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q₀) ∧ (∀ m ∈ w, ∀ m' ∈ w, LinMap l11 l12 l21 l22 (v m.1 - v m'.1) (v m.2 - v m'.2)) ∧ l11 * l22 - l12 * l21 ≠ 0 := by classical obtain ⟨hcard, hlt, hinj1, hinj2⟩ := hw obtain ⟨m1, t, hm1t, rfl, ht⟩ := card_eq_succ.mp hcard obtain ⟨m2, m3, m4, h23, h24, h34, rfl⟩ := card_eq_three.mp ht have hm1 : m1 ∈ insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ)) := mem_insert_self _ _ have hm2 : m2 ∈ insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ)) := by simp have hm3 : m3 ∈ insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ)) := by simp have hm4 : m4 ∈ insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ)) := by simp have h12 : m1 ≠ m2 := by intro h; apply hm1t; rw [h]; simp have h13 : m1 ≠ m3 := by intro h; apply hm1t; rw [h]; simp have h14 : m1 ≠ m4 := by intro h; apply hm1t; rw [h]; simp have hY : cr3 (v m1.1) (v m2.1) (v m3.1) ≠ 0 := ccw_cr3_ne hccw (hlt m1 hm1).1 (hlt m2 hm2).1 (hlt m3 hm3).1 (fun h => h12 (hinj1 m1 hm1 m2 hm2 h)) (fun h => h13 (hinj1 m1 hm1 m3 hm3 h)) (fun h => h23 (hinj1 m2 hm2 m3 hm3 h)) have hZ : cr3 (v m1.2) (v m2.2) (v m3.2) ≠ 0 := ccw_cr3_ne hccw (hlt m1 hm1).2 (hlt m2 hm2).2 (hlt m3 hm3).2 (fun h => h12 (hinj2 m1 hm1 m2 hm2 h)) (fun h => h13 (hinj2 m1 hm1 m3 hm3 h)) (fun h => h23 (hinj2 m2 hm2 m3 hm3 h)) obtain ⟨l11, l12, l21, l22, hL2, hL3⟩ := exists_lin (Z1 := v m1.2) (Z2 := v m2.2) (Z3 := v m3.2) hY -- determinant have hdet : l11 * l22 - l12 * l21 ≠ 0 := by intro h0 apply hZ have a := hL2.1 have b := hL2.2 have c := hL3.1 have d := hL3.2 simp only [Complex.sub_re, Complex.sub_im] at a b c d unfold cr3 rw [← a, ← b, ← c, ← d] linear_combination ((v m2.1).re - (v m1.1).re) * ((v m3.1).im - (v m1.1).im) * h0 - ((v m2.1).im - (v m1.1).im) * ((v m3.1).re - (v m1.1).re) * h0 -- the pole relation between any two solutions have hrel : ∀ pp ∈ wsol v n (insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ))), ∀ ss ∈ wsol v n (insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ))), v pp.1 - v ss.1 = linT l11 l12 l21 l22 (v pp.2 - v ss.2) := by intro pp hpp ss hss have hp := (mem_wsol.mp hpp).2 have hs := (mem_wsol.mp hss).2 exact pole_rel hY hL2 hL3 (hp m1 hm1) (hp m2 hm2) (hp m3 hm3) (hs m1 hm1) (hs m2 hm2) (hs m3 hm3) have hT0 : linT l11 l12 l21 l22 0 = 0 := by apply Complex.ext <;> simp [linT] -- the primed pole determines the solution have hsec : ∀ pp ∈ wsol v n (insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ))), ∀ ss ∈ wsol v n (insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ))), pp.2 = ss.2 → pp = ss := by intro pp hpp ss hss h have h1 := hrel pp hpp ss hss rw [h, sub_self, hT0, sub_eq_zero] at h1 exact Prod.ext (hinj pp.1 (mem_wsol.mp hpp).1.1 ss.1 (mem_wsol.mp hss).1.1 h1) h -- the fourth match is affine as well have h4 : LinMap l11 l12 l21 l22 (v m4.1 - v m1.1) (v m4.2 - v m1.2) := by by_contra hne obtain ⟨a, ha, b, hb, c, hc, hab, hac, hbc⟩ := two_lt_card.mp (show 2 < (wsol v n (insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ)))).card by omega) have la := (mem_wsol.mp ha).2 have lb := (mem_wsol.mp hb).2 have lc := (mem_wsol.mp hc).2 have r1 := line_rel (hrel b hb a ha) (lb m1 hm1) (lb m4 hm4) (la m1 hm1) (la m4 hm4) have r2 := line_rel (hrel c hc a ha) (lc m1 hm1) (lc m4 hm4) (la m1 hm1) (la m4 hm4) have he : (linA l11 l12 l21 l22 (v m4.1 - v m1.1)).re - ((v m4.2).re - (v m1.2).re) ≠ 0 ∨ (linA l11 l12 l21 l22 (v m4.1 - v m1.1)).im - ((v m4.2).im - (v m1.2).im) ≠ 0 := by by_contra hcon push_neg at hcon apply hne unfold LinMap simp only [linA, Complex.sub_re, Complex.sub_im] at hcon ⊢ constructor <;> linarith [hcon.1, hcon.2] have hcol := cr3_zero_of_orth he r1 r2 exact ccw_cr3_ne hccw (mem_wsol.mp ha).1.2 (mem_wsol.mp hb).1.2 (mem_wsol.mp hc).1.2 (fun h => hab (hsec a ha b hb h)) (fun h => hac (hsec a ha c hc h)) (fun h => hbc (hsec b hb c hc h)) hcol -- base solution have hne : (wsol v n (insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ)))).Nonempty := card_pos.mp (by omega) obtain ⟨p0, hp0⟩ := hne have hall : ∀ m ∈ insert m1 ({m2, m3, m4} : Finset (ℕ × ℕ)), LinMap l11 l12 l21 l22 (v m.1 - v m1.1) (v m.2 - v m1.2) := by intro m hm simp only [mem_insert, mem_singleton] at hm rcases hm with rfl | rfl | rfl | rfl · unfold LinMap; simp · exact hL2 · exact hL3 · exact h4 refine ⟨l11, l12, l21, l22, v p0.1 - linT l11 l12 l21 l22 (v p0.2), ?_, ?_, hdet⟩ · intro pp hpp have := hrel pp hpp p0 hp0 rw [linT_sub] at this linear_combination this · intro m hm m' hm' have a := hall m hm have b := hall m' hm' unfold LinMap at a b ⊢ simp only [Complex.sub_re, Complex.sub_im] at a b ⊢ constructor · linear_combination a.1 - b.1 · linear_combination a.2 - b.2 /-- In a window with its affine data, the primed pole determines the pole pair, and so does the unprimed pole. -/ theorem wsol_inj {v : ℕ → ℂ} {n : ℕ} (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {w : Finset (ℕ × ℕ)} {l11 l12 l21 l22 : ℝ} {q₀ : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q₀) (hdet : l11 * l22 - l12 * l21 ≠ 0) : (∀ pp ∈ wsol v n w, ∀ ss ∈ wsol v n w, pp.2 = ss.2 → pp = ss) ∧ (∀ pp ∈ wsol v n w, ∀ ss ∈ wsol v n w, pp.1 = ss.1 → pp = ss) := by constructor · intro pp hpp ss hss h have h1 := hpole pp hpp have h2 := hpole ss hss rw [h] at h1 exact Prod.ext (hinj pp.1 (mem_wsol.mp hpp).1.1 ss.1 (mem_wsol.mp hss).1.1 (h1.trans h2.symm)) h · intro pp hpp ss hss h have h1 := hpole pp hpp have h2 := hpole ss hss rw [h, h2] at h1 have e1 := congrArg Complex.re h1 have e2 := congrArg Complex.im h1 simp only [Complex.add_re, Complex.add_im, linT] at e1 e2 have g1 : (l11 * l22 - l12 * l21) * ((v pp.2).re - (v ss.2).re) = 0 := by linear_combination (-l22) * e1 + l21 * e2 have g2 : (l11 * l22 - l12 * l21) * ((v pp.2).im - (v ss.2).im) = 0 := by linear_combination l12 * e1 - l11 * e2 have k1 := (mul_eq_zero.mp g1).resolve_left hdet have k2 := (mul_eq_zero.mp g2).resolve_left hdet have : v pp.2 = v ss.2 := by apply Complex.ext <;> linarith exact Prod.ext h (hinj pp.2 (mem_wsol.mp hpp).1.2 ss.2 (mem_wsol.mp hss).1.2 this) end E94S /-! ### SOLO slice B3b -/ /-! ## SOLO module B (part 3b): isometry windows are explained, similarity windows are circle configurations -/ namespace E94S open Finset /-- The vertex set of a labelled polygon. -/ noncomputable def pts (v : ℕ → ℂ) (n : ℕ) : Finset ℂ := (range n).image v theorem mem_pts {v : ℕ → ℂ} {n i : ℕ} (hi : i < n) : v i ∈ pts v n := mem_image.mpr ⟨i, mem_range.mpr hi, rfl⟩ /-- Proper isometry `z ↦ g.1 z + g.2` (for `‖g.1‖ = 1`). -/ def iapp (g : ℂ × ℂ) (z : ℂ) : ℂ := g.1 * z + g.2 /-- Improper isometry `z ↦ g.1 z̄ + g.2` (for `‖g.1‖ = 1`). -/ def iappc (g : ℂ × ℂ) (z : ℂ) : ℂ := g.1 * (starRingEnd ℂ) z + g.2 open Classical in /-- The domain of a proper isometry in `B`. -/ noncomputable def idom (B : Finset ℂ) (g : ℂ × ℂ) : Finset ℂ := B.filter (fun z => iapp g z ∈ B) open Classical in /-- The domain of an improper isometry in `B`. -/ noncomputable def idomc (B : Finset ℂ) (g : ℂ × ℂ) : Finset ℂ := B.filter (fun z => iappc g z ∈ B) /-- The ordered pair `(a, b)` is carried to `(c, d)` by an isometry with at least `T` points of `B` in its domain. -/ def Expl (B : Finset ℂ) (T : ℝ) (a b c d : ℂ) : Prop := ∃ g : ℂ × ℂ, ‖g.1‖ = 1 ∧ ((iapp g a = c ∧ iapp g b = d ∧ T ≤ ((idom B g).card : ℝ)) ∨ (iappc g a = c ∧ iappc g b = d ∧ T ≤ ((idomc B g).card : ℝ))) open Classical in /-- The radius-swap configuration: `P`, `Y` on circles about `c` of squared radii `r1`, `r2`; `P'`, `Z` on circles about `c'` of squared radii `r2`, `r1`; the circles of `P` and of `P'` carry at least `T` points of `B`. -/ def SimCfg (B : Finset ℂ) (T : ℝ) (P Y P' Z : ℂ) : Prop := ∃ c c' : ℂ, ∃ r1 r2 : ℝ, 0 < r1 ∧ 0 < r2 ∧ dq P c = r1 ∧ dq Y c = r2 ∧ dq P' c' = r2 ∧ dq Z c' = r1 ∧ T ≤ ((B.filter (fun z => dq z c = r1)).card : ℝ) ∧ T ≤ ((B.filter (fun z => dq z c' = r2)).card : ℝ) /-- **Orthogonal windows.** With at least three pole pairs, every match of every pole pair is explained by one isometry whose domain contains all the poles. -/ theorem win_iso_expl {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {w : Finset (ℕ × ℕ)} (hw : IsWin n w) (h3 : 3 ≤ (wsol v n w).card) {l11 l12 l21 l22 : ℝ} {q₀ : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q₀) (hlin : ∀ m ∈ w, ∀ m' ∈ w, LinMap l11 l12 l21 l22 (v m.1 - v m'.1) (v m.2 - v m'.2)) (hdet : l11 * l22 - l12 * l21 ≠ 0) (hr1 : l11 ^ 2 + l12 ^ 2 = 1) (hr2 : l21 ^ 2 + l22 ^ 2 = 1) (hr3 : l11 * l21 + l12 * l22 = 0) : ∀ pp ∈ wsol v n w, ∀ m ∈ w, Expl (pts v n) ((wsol v n w).card : ℝ) (v pp.1) (v m.1) (v pp.2) (v m.2) := by classical obtain ⟨hsec, hfst⟩ := wsol_inj hinj hpole hdet obtain ⟨a, ha, b, hb, c, hc, hab, hac, hbc⟩ := two_lt_card.mp (show 2 < (wsol v n w).card by omega) have hcr : cr3 (v a.2) (v b.2) (v c.2) ≠ 0 := ccw_cr3_ne hccw (mem_wsol.mp ha).1.2 (mem_wsol.mp hb).1.2 (mem_wsol.mp hc).1.2 (fun h => hab (hsec a ha b hb h)) (fun h => hac (hsec a ha c hc h)) (fun h => hbc (hsec b hb c hc h)) have hwne : w.Nonempty := card_pos.mp (by rw [hw.1]; norm_num) obtain ⟨m1, hm1⟩ := hwne have hbase := orth_base hr1 hr2 hr3 hcr (hpole a ha) (hpole b hb) (hpole c hc) ((mem_wsol.mp ha).2 m1 hm1) ((mem_wsol.mp hb).2 m1 hm1) ((mem_wsol.mp hc).2 m1 hm1) obtain ⟨g, hg1, hg⟩ := orth_iso hr1 hr2 hr3 hbase intro pp hpp m hm rcases hg with ⟨hgP, hgY⟩ | ⟨hgP, hgY⟩ · refine ⟨g, hg1, Or.inl ⟨hgP _ _ (hpole pp hpp), hgY _ _ (hlin m hm m1 hm1), ?_⟩⟩ have hsub : (wsol v n w).image (fun ss => v ss.1) ⊆ idom (pts v n) g := by intro z hz obtain ⟨ss, hss, rfl⟩ := mem_image.mp hz unfold idom refine mem_filter.mpr ⟨mem_pts (mem_wsol.mp hss).1.1, ?_⟩ show g.1 * v ss.1 + g.2 ∈ pts v n rw [hgP _ _ (hpole ss hss)] exact mem_pts (mem_wsol.mp hss).1.2 have hcard : ((wsol v n w).image (fun ss => v ss.1)).card = (wsol v n w).card := card_image_of_injOn (fun x hx y hy h => hfst x hx y hy (hinj x.1 (mem_wsol.mp hx).1.1 y.1 (mem_wsol.mp hy).1.1 h)) have := card_le_card hsub rw [hcard] at this exact_mod_cast this · refine ⟨g, hg1, Or.inr ⟨hgP _ _ (hpole pp hpp), hgY _ _ (hlin m hm m1 hm1), ?_⟩⟩ have hsub : (wsol v n w).image (fun ss => v ss.1) ⊆ idomc (pts v n) g := by intro z hz obtain ⟨ss, hss, rfl⟩ := mem_image.mp hz unfold idomc refine mem_filter.mpr ⟨mem_pts (mem_wsol.mp hss).1.1, ?_⟩ show g.1 * (starRingEnd ℂ) (v ss.1) + g.2 ∈ pts v n rw [hgP _ _ (hpole ss hss)] exact mem_pts (mem_wsol.mp hss).1.2 have hcard : ((wsol v n w).image (fun ss => v ss.1)).card = (wsol v n w).card := card_image_of_injOn (fun x hx y hy h => hfst x hx y hy (hinj x.1 (mem_wsol.mp hx).1.1 y.1 (mem_wsol.mp hy).1.1 h)) have := card_le_card hsub rw [hcard] at this exact_mod_cast this /-- **Similarity windows.** If `L Lᵀ = Λ·I` with `Λ ≠ 1`, every match of every pole pair is a radius-swap configuration whose two pole circles carry all the poles. -/ theorem win_sim_cfg {v : ℕ → ℂ} {n : ℕ} (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {w : Finset (ℕ × ℕ)} (hw : IsWin n w) (h2 : 2 ≤ (wsol v n w).card) {l11 l12 l21 l22 Λ : ℝ} {q₀ : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q₀) (hlin : ∀ m ∈ w, ∀ m' ∈ w, LinMap l11 l12 l21 l22 (v m.1 - v m'.1) (v m.2 - v m'.2)) (hdet : l11 * l22 - l12 * l21 ≠ 0) (hr1 : l11 ^ 2 + l12 ^ 2 = Λ) (hr2 : l21 ^ 2 + l22 ^ 2 = Λ) (hr3 : l11 * l21 + l12 * l22 = 0) (hΛ : Λ ≠ 1) : ∀ pp ∈ wsol v n w, ∀ m ∈ w, SimCfg (pts v n) ((wsol v n w).card : ℝ) (v pp.1) (v m.1) (v pp.2) (v m.2) := by classical obtain ⟨hsec, hfst⟩ := wsol_inj hinj hpole hdet have hwne : w.Nonempty := card_pos.mp (by rw [hw.1]; norm_num) obtain ⟨m1, hm1⟩ := hwne obtain ⟨p0, hp0, p1, hp1, hp01⟩ := one_lt_card.mp (show 1 < (wsol v n w).card by omega) have hΛ1 : Λ - 1 ≠ 0 := sub_ne_zero.mpr hΛ obtain ⟨c', hc'⟩ : ∃ c' : ℂ, c' = ⟨-((v m1.2).re - (l11 * ((v m1.1).re - q₀.re) + l12 * ((v m1.1).im - q₀.im))) / (Λ - 1), -((v m1.2).im - (l21 * ((v m1.1).re - q₀.re) + l22 * ((v m1.1).im - q₀.im))) / (Λ - 1)⟩ := ⟨_, rfl⟩ have hc1 : ∀ m ∈ w, (Λ - 1) * c'.re = -((v m.2).re - (l11 * ((v m.1).re - q₀.re) + l12 * ((v m.1).im - q₀.im))) := by intro m hm have hl := (hlin m hm m1 hm1).1 simp only [Complex.sub_re, Complex.sub_im] at hl rw [hc'] simp only rw [mul_div_cancel₀ _ hΛ1] linarith have hc2 : ∀ m ∈ w, (Λ - 1) * c'.im = -((v m.2).im - (l21 * ((v m.1).re - q₀.re) + l22 * ((v m.1).im - q₀.im))) := by intro m hm have hl := (hlin m hm m1 hm1).2 simp only [Complex.sub_re, Complex.sub_im] at hl rw [hc'] simp only rw [mul_div_cancel₀ _ hΛ1] linarith -- all primed poles at the same squared distance `s2` from `c'` have hs : ∀ pp ∈ wsol v n w, dq (v pp.2) c' = dq (v p0.2) c' := by intro pp hpp exact sim_poles' hr1 hr2 hr3 hΛ (hpole pp hpp) (hpole p0 hp0) (hc1 m1 hm1) (hc2 m1 hm1) ((mem_wsol.mp hpp).2 m1 hm1) ((mem_wsol.mp hp0).2 m1 hm1) have hs2pos : 0 < dq (v p0.2) c' := by rcases lt_or_eq_of_le (dq_nonneg (v p0.2) c') with h | h · exact h · exfalso have e0 := dq_eq_zero h.symm have e1 := dq_eq_zero ((hs p1 hp1).trans h.symm) apply hp01 exact hsec p0 hp0 p1 hp1 (hinj p0.2 (mem_wsol.mp hp0).1.2 p1.2 (mem_wsol.mp hp1).1.2 (e0.trans e1.symm)) have hΛpos : 0 < Λ := by rcases lt_or_eq_of_le (show 0 ≤ Λ by rw [← hr1]; positivity) with h | h · exact h · exfalso apply hdet have e1 : l11 = 0 := by nlinarith [sq_nonneg l11, sq_nonneg l12] have e2 : l12 = 0 := by nlinarith [sq_nonneg l11, sq_nonneg l12] rw [e1, e2]; ring intro pp hpp m hm refine ⟨linT l11 l12 l21 l22 c' + q₀, c', Λ * dq (v p0.2) c', dq (v p0.2) c', mul_pos hΛpos hs2pos, hs2pos, ?_, ?_, hs pp hpp, ?_, ?_, ?_⟩ · rw [sim_poles hr1 hr2 hr3 (hpole pp hpp), hs pp hpp] · exact sim_free hr1 hr2 hr3 hΛ (hpole p0 hp0) (hc1 m hm) (hc2 m hm) ((mem_wsol.mp hp0).2 m hm) · rw [sim_free' hr1 hr2 hr3 (hc1 m hm) (hc2 m hm), sim_free hr1 hr2 hr3 hΛ (hpole p0 hp0) (hc1 m hm) (hc2 m hm) ((mem_wsol.mp hp0).2 m hm)] · have hsub : (wsol v n w).image (fun ss => v ss.1) ⊆ (pts v n).filter (fun z => dq z (linT l11 l12 l21 l22 c' + q₀) = Λ * dq (v p0.2) c') := by intro z hz obtain ⟨ss, hss, rfl⟩ := mem_image.mp hz refine mem_filter.mpr ⟨mem_pts (mem_wsol.mp hss).1.1, ?_⟩ rw [sim_poles hr1 hr2 hr3 (hpole ss hss), hs ss hss] have hcard : ((wsol v n w).image (fun ss => v ss.1)).card = (wsol v n w).card := card_image_of_injOn (fun x hx y hy h => hfst x hx y hy (hinj x.1 (mem_wsol.mp hx).1.1 y.1 (mem_wsol.mp hy).1.1 h)) have := card_le_card hsub rw [hcard] at this exact_mod_cast this · have hsub : (wsol v n w).image (fun ss => v ss.2) ⊆ (pts v n).filter (fun z => dq z c' = dq (v p0.2) c') := by intro z hz obtain ⟨ss, hss, rfl⟩ := mem_image.mp hz exact mem_filter.mpr ⟨mem_pts (mem_wsol.mp hss).1.2, hs ss hss⟩ have hcard : ((wsol v n w).image (fun ss => v ss.2)).card = (wsol v n w).card := card_image_of_injOn (fun x hx y hy h => hsec x hx y hy (hinj x.2 (mem_wsol.mp hx).1.2 y.2 (mem_wsol.mp hy).1.2 h)) have := card_le_card hsub rw [hcard] at this exact_mod_cast this end E94S /-! ### SOLO slice B3c -/ /-! ## SOLO module B (part 3c): counting the poorly explained radius-swap configurations -/ namespace E94S open Finset theorem dq_eq_normSq (z w : ℂ) : dq z w = Complex.normSq (z - w) := by unfold dq rw [Complex.normSq_apply] simp only [Complex.sub_re, Complex.sub_im] ring theorem norm_eq_of_dq_eq {z w z' w' : ℂ} (h : dq z w = dq z' w') : ‖z - w‖ = ‖z' - w'‖ := by rw [dq_eq_normSq, dq_eq_normSq] at h rw [Complex.norm_def, Complex.norm_def, h] /-- The circle through three non-collinear points is unique. -/ theorem circle_unique {z1 z2 z3 c d : ℂ} {r s : ℝ} (hdet : cr3 z1 z2 z3 ≠ 0) (h1 : dq z1 c = r) (h2 : dq z2 c = r) (h3 : dq z3 c = r) (k1 : dq z1 d = s) (k2 : dq z2 d = s) (k3 : dq z3 d = s) : c = d ∧ r = s := by have hcd : c = d := by unfold dq at h1 h2 h3 k1 k2 k3 unfold cr3 at hdet have e1 : (z2.re - z1.re) * (c.re - d.re) + (z2.im - z1.im) * (c.im - d.im) = 0 := by linear_combination (1 / 2 : ℝ) * (h1 - h2 - k1 + k2) have e2 : (z3.re - z1.re) * (c.re - d.re) + (z3.im - z1.im) * (c.im - d.im) = 0 := by linear_combination (1 / 2 : ℝ) * (h1 - h3 - k1 + k3) have g1 : (c.re - d.re) * ((z2.re - z1.re) * (z3.im - z1.im) - (z2.im - z1.im) * (z3.re - z1.re)) = 0 := by linear_combination (z3.im - z1.im) * e1 - (z2.im - z1.im) * e2 have g2 : (c.im - d.im) * ((z2.re - z1.re) * (z3.im - z1.im) - (z2.im - z1.im) * (z3.re - z1.re)) = 0 := by linear_combination (z2.re - z1.re) * e2 - (z3.re - z1.re) * e1 have a1 := (mul_eq_zero.mp g1).resolve_right hdet have a2 := (mul_eq_zero.mp g2).resolve_right hdet apply Complex.ext <;> linarith refine ⟨hcd, ?_⟩ rw [← h1, ← k1, hcd] /-- The proper isometry with `c ↦ c'`, `Y ↦ P'`. -/ noncomputable def gpOf (c c' Y P' : ℂ) : ℂ × ℂ := ((P' - c') / (Y - c), c' - (P' - c') / (Y - c) * c) /-- The improper isometry with `c ↦ c'`, `Y ↦ P'`. -/ noncomputable def gmOf (c c' Y P' : ℂ) : ℂ × ℂ := ((P' - c') / (starRingEnd ℂ) (Y - c), c' - (P' - c') / (starRingEnd ℂ) (Y - c) * (starRingEnd ℂ) c) /-- Side–side–side in coordinates: `w, u` and `x, v` with `|w| = |x|`, `|u| = |v| ≠ 0`, `⟨w,u⟩ = ⟨x,v⟩`. -/ theorem sss_real {w1 w2 u1 u2 x1 x2 v1 v2 : ℝ} (ea : w1 ^ 2 + w2 ^ 2 = x1 ^ 2 + x2 ^ 2) (eb : u1 ^ 2 + u2 ^ 2 = v1 ^ 2 + v2 ^ 2) (ec : w1 * u1 + w2 * u2 = x1 * v1 + x2 * v2) (hN : u1 ^ 2 + u2 ^ 2 ≠ 0) : (x1 * u1 - x2 * u2 = v1 * w1 - v2 * w2 ∧ x1 * u2 + x2 * u1 = v1 * w2 + v2 * w1) ∨ (x1 * u1 + x2 * u2 = v1 * w1 + v2 * w2 ∧ -(x1 * u2) + x2 * u1 = -(v1 * w2) + v2 * w1) := by have es : (w2 * u1 - w1 * u2 - (x2 * v1 - x1 * v2)) * (w2 * u1 - w1 * u2 + (x2 * v1 - x1 * v2)) = 0 := by linear_combination (v1 ^ 2 + v2 ^ 2) * ea + (w1 ^ 2 + w2 ^ 2) * eb - (w1 * u1 + w2 * u2 + (x1 * v1 + x2 * v2)) * ec rcases mul_eq_zero.mp es with hs | hs · left constructor · have : (u1 ^ 2 + u2 ^ 2) * (x1 * u1 - x2 * u2 - (v1 * w1 - v2 * w2)) = 0 := by linear_combination (u1 * v1 - u2 * v2) * (-ec) + (u1 * v2 + u2 * v1) * hs + (x1 * u1 - x2 * u2) * eb have := (mul_eq_zero.mp this).resolve_left hN linarith · have : (u1 ^ 2 + u2 ^ 2) * (x1 * u2 + x2 * u1 - (v1 * w2 + v2 * w1)) = 0 := by linear_combination (u1 * v2 + u2 * v1) * (-ec) - (u1 * v1 - u2 * v2) * hs + (x1 * u2 + x2 * u1) * eb have := (mul_eq_zero.mp this).resolve_left hN linarith · right constructor · have : (u1 ^ 2 + u2 ^ 2) * (x1 * u1 + x2 * u2 - (v1 * w1 + v2 * w2)) = 0 := by linear_combination (u1 * v1 + u2 * v2) * (-ec) + (-(u1 * v2) + u2 * v1) * hs + (x1 * u1 + x2 * u2) * eb have := (mul_eq_zero.mp this).resolve_left hN linarith · have : (u1 ^ 2 + u2 ^ 2) * (-(x1 * u2) + x2 * u1 - (-(v1 * w2) + v2 * w1)) = 0 := by linear_combination (-(u1 * v2) + u2 * v1) * ec + (u1 * v1 + u2 * v2) * hs + (u1 * x2 - u2 * x1) * eb have := (mul_eq_zero.mp this).resolve_left hN linarith /-- **Side–side–side.** If `|P - c| = |Z - c'|`, `|Y - c| = |P' - c'| ≠ 0` and `|P - Y| = |Z - P'|`, one of the two isometries with `c ↦ c'`, `Y ↦ P'` sends `P` to `Z`. -/ theorem sss_iso {c c' P Y P' Z : ℂ} (hY : Y ≠ c) (h1 : dq P c = dq Z c') (h2 : dq Y c = dq P' c') (h3 : dq P Y = dq Z P') : ‖(gpOf c c' Y P').1‖ = 1 ∧ ‖(gmOf c c' Y P').1‖ = 1 ∧ iapp (gpOf c c' Y P') Y = P' ∧ iappc (gmOf c c' Y P') Y = P' ∧ (iapp (gpOf c c' Y P') P = Z ∨ iappc (gmOf c c' Y P') P = Z) := by have hu : Y - c ≠ 0 := sub_ne_zero.mpr hY have hcu : (starRingEnd ℂ) (Y - c) ≠ 0 := by intro h; exact hu ((map_eq_zero _).mp h) have hn : ‖P' - c'‖ = ‖Y - c‖ := (norm_eq_of_dq_eq h2).symm have hupos : 0 < ‖Y - c‖ := norm_pos_iff.mpr hu refine ⟨?_, ?_, ?_, ?_, ?_⟩ · show ‖(P' - c') / (Y - c)‖ = 1 rw [norm_div, hn, div_self hupos.ne'] · show ‖(P' - c') / (starRingEnd ℂ) (Y - c)‖ = 1 rw [norm_div, RCLike.norm_conj, hn, div_self hupos.ne'] · show (P' - c') / (Y - c) * Y + (c' - (P' - c') / (Y - c) * c) = P' field_simp ring · show (P' - c') / (starRingEnd ℂ) (Y - c) * (starRingEnd ℂ) Y + (c' - (P' - c') / (starRingEnd ℂ) (Y - c) * (starRingEnd ℂ) c) = P' have : (starRingEnd ℂ) Y = (starRingEnd ℂ) (Y - c) + (starRingEnd ℂ) c := by rw [map_sub]; ring rw [this] field_simp ring · unfold dq at h1 h2 h3 have hN : (Y.re - c.re) ^ 2 + (Y.im - c.im) ^ 2 ≠ 0 := by intro h0 apply hu have a1 : Y.re - c.re = 0 := by nlinarith [sq_nonneg (Y.re - c.re), sq_nonneg (Y.im - c.im)] have a2 : Y.im - c.im = 0 := by nlinarith [sq_nonneg (Y.re - c.re), sq_nonneg (Y.im - c.im)] apply Complex.ext · simpa using a1 · simpa using a2 have ec : (P.re - c.re) * (Y.re - c.re) + (P.im - c.im) * (Y.im - c.im) = (Z.re - c'.re) * (P'.re - c'.re) + (Z.im - c'.im) * (P'.im - c'.im) := by linear_combination (1 / 2 : ℝ) * (h1 + h2 - h3) rcases sss_real h1 h2 ec hN with ⟨k1, k2⟩ | ⟨k1, k2⟩ · left show (P' - c') / (Y - c) * P + (c' - (P' - c') / (Y - c) * c) = Z have key : (Z - c') * (Y - c) = (P' - c') * (P - c) := by apply Complex.ext · simp only [Complex.mul_re, Complex.sub_re, Complex.sub_im] linarith · simp only [Complex.mul_im, Complex.sub_re, Complex.sub_im] linarith have e : Z - c' = (P' - c') / (Y - c) * (P - c) := by rw [div_mul_eq_mul_div, eq_div_iff hu]; exact key linear_combination (-1 : ℂ) * e · right show (P' - c') / (starRingEnd ℂ) (Y - c) * (starRingEnd ℂ) P + (c' - (P' - c') / (starRingEnd ℂ) (Y - c) * (starRingEnd ℂ) c) = Z have key : (Z - c') * (starRingEnd ℂ) (Y - c) = (P' - c') * (starRingEnd ℂ) (P - c) := by apply Complex.ext · simp only [Complex.mul_re, Complex.sub_re, Complex.sub_im, Complex.conj_re, Complex.conj_im] linarith · simp only [Complex.mul_im, Complex.sub_re, Complex.sub_im, Complex.conj_re, Complex.conj_im] linarith have hP : (starRingEnd ℂ) P = (starRingEnd ℂ) (P - c) + (starRingEnd ℂ) c := by rw [map_sub]; ring rw [hP] have e : Z - c' = (P' - c') / (starRingEnd ℂ) (Y - c) * (starRingEnd ℂ) (P - c) := by rw [div_mul_eq_mul_div, eq_div_iff hcu]; exact key linear_combination (-1 : ℂ) * e end E94S /-! ### SOLO slice B3d -/ /-! ## SOLO module B (part 3d): few poorly explained radius-swap configurations -/ namespace E94S open Finset theorem dq_comm (z w : ℂ) : dq z w = dq w z := by unfold dq; ring theorem dq_self (z : ℂ) : dq z z = 0 := by unfold dq; ring open Classical in /-- **Fixed circles.** For fixed centres and radii, the radius-swap configurations whose swap isometry is poor number at most `2T|B|²`: the swap isometry is determined by `(Y, P')` up to orientation and has fewer than `T` points in its domain. -/ theorem sim_fixed {B : Finset ℂ} {T : ℝ} (hT : 0 ≤ T) (c c' : ℂ) (r1 r2 : ℝ) (hr2 : 0 < r2) : (((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => dq q.1 c = r1 ∧ dq q.2.1 c = r2 ∧ dq q.2.2.1 c' = r2 ∧ dq q.2.2.2 c' = r1 ∧ dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1)).card : ℝ) ≤ 2 * T * (B.card : ℝ) ^ 2 := by obtain ⟨Fp, hFp⟩ : ∃ Fp : ℂ × ℂ → Finset (ℂ × ℂ × ℂ × ℂ), Fp = fun yp => if ((idom B (gpOf c c' yp.1 yp.2)).card : ℝ) < T then (idom B (gpOf c c' yp.1 yp.2)).image (fun P => (P, yp.1, yp.2, iapp (gpOf c c' yp.1 yp.2) P)) else ∅ := ⟨_, rfl⟩ obtain ⟨Fm, hFm⟩ : ∃ Fm : ℂ × ℂ → Finset (ℂ × ℂ × ℂ × ℂ), Fm = fun yp => if ((idomc B (gmOf c c' yp.1 yp.2)).card : ℝ) < T then (idomc B (gmOf c c' yp.1 yp.2)).image (fun P => (P, yp.1, yp.2, iappc (gmOf c c' yp.1 yp.2) P)) else ∅ := ⟨_, rfl⟩ have hFpc : ∀ yp, ((Fp yp).card : ℝ) ≤ T := by intro yp rw [hFp] simp only split_ifs with h · exact le_trans (by exact_mod_cast card_image_le) h.le · simpa using hT have hFmc : ∀ yp, ((Fm yp).card : ℝ) ≤ T := by intro yp rw [hFm] simp only split_ifs with h · exact le_trans (by exact_mod_cast card_image_le) h.le · simpa using hT have hsub : (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => dq q.1 c = r1 ∧ dq q.2.1 c = r2 ∧ dq q.2.2.1 c' = r2 ∧ dq q.2.2.2 c' = r1 ∧ dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1) ⊆ (B ×ˢ B).biUnion (fun yp => Fp yp ∪ Fm yp) := by intro q hq obtain ⟨P, Y, P', Z⟩ := q simp only [mem_filter, mem_product] at hq obtain ⟨⟨hPB, hYB, hP'B, hZB⟩, e1, e2, e3, e4, e5, hne⟩ := hq have hYc : Y ≠ c := by intro h rw [h, dq_self] at e2 linarith obtain ⟨n1, n2, a1, a2, hor⟩ := sss_iso (c := c) (c' := c') (P := P) (Y := Y) (P' := P') (Z := Z) hYc (e1.trans e4.symm) (e2.trans e3.symm) (by rw [e5]; exact dq_comm _ _) refine mem_biUnion.mpr ⟨(Y, P'), mem_product.mpr ⟨hYB, hP'B⟩, ?_⟩ rcases hor with h | h · apply mem_union_left have hlt : ((idom B (gpOf c c' Y P')).card : ℝ) < T := by by_contra hcon push_neg at hcon exact hne ⟨gpOf c c' Y P', n1, Or.inl ⟨h, a1, hcon⟩⟩ rw [hFp] simp only rw [if_pos hlt] refine mem_image.mpr ⟨P, ?_, by rw [h]⟩ unfold idom exact mem_filter.mpr ⟨hPB, by rw [h]; exact hZB⟩ · apply mem_union_right have hlt : ((idomc B (gmOf c c' Y P')).card : ℝ) < T := by by_contra hcon push_neg at hcon exact hne ⟨gmOf c c' Y P', n2, Or.inr ⟨h, a2, hcon⟩⟩ rw [hFm] simp only rw [if_pos hlt] refine mem_image.mpr ⟨P, ?_, by rw [h]⟩ unfold idomc exact mem_filter.mpr ⟨hPB, by rw [h]; exact hZB⟩ have h1 : ((B ×ˢ B).biUnion (fun yp => Fp yp ∪ Fm yp)).card ≤ ∑ yp ∈ B ×ˢ B, ((Fp yp).card + (Fm yp).card) := le_trans card_biUnion_le (sum_le_sum (fun yp _ => card_union_le _ _)) have h2 : ((∑ yp ∈ B ×ˢ B, ((Fp yp).card + (Fm yp).card) : ℕ) : ℝ) ≤ ∑ _yp ∈ B ×ˢ B, (2 * T) := by push_cast refine sum_le_sum (fun yp _ => ?_) linarith [hFpc yp, hFmc yp] rw [sum_const, card_product, nsmul_eq_mul] at h2 have h3 : ((((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => dq q.1 c = r1 ∧ dq q.2.1 c = r2 ∧ dq q.2.2.1 c' = r2 ∧ dq q.2.2.2 c' = r1 ∧ dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1)).card : ℕ) : ℝ) ≤ ((∑ yp ∈ B ×ˢ B, ((Fp yp).card + (Fm yp).card) : ℕ) : ℝ) := by exact_mod_cast le_trans (card_le_card hsub) h1 push_cast at h2 h3 nlinarith [h2, h3] open Classical in /-- **Few poorly explained radius-swap configurations.** -/ theorem sim_count {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {T : ℝ} (hT : 0 ≤ T) {t : ℕ} (ht : 3 ≤ t) : (((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ SimCfg B (t : ℝ) q.1 q.2.1 q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1)).card : ℝ) * ((t.choose 3 : ℕ) : ℝ) ^ 2 ≤ 2 * T * (B.card : ℝ) ^ 2 * ((B.card.choose 3 : ℕ) : ℝ) ^ 2 := by obtain ⟨Bad, hBad⟩ : ∃ Bad : Finset (ℂ × ℂ × ℂ × ℂ), Bad = (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ SimCfg B (t : ℝ) q.1 q.2.1 q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1) := ⟨_, rfl⟩ rw [← hBad] obtain ⟨TT, hTT⟩ : ∃ TT : Finset (Finset ℂ × Finset ℂ), TT = (powersetCard 3 B) ×ˢ (powersetCard 3 B) := ⟨_, rfl⟩ obtain ⟨Rel, hRel⟩ : ∃ Rel : ℂ × ℂ × ℂ × ℂ → Finset ℂ × Finset ℂ → Prop, Rel = fun q tt => ∃ c c' : ℂ, ∃ r1 r2 : ℝ, 0 < r2 ∧ dq q.1 c = r1 ∧ dq q.2.1 c = r2 ∧ dq q.2.2.1 c' = r2 ∧ dq q.2.2.2 c' = r1 ∧ (∀ z ∈ tt.1, dq z c = r1) ∧ (∀ z ∈ tt.2, dq z c' = r2) := ⟨_, rfl⟩ have hdc := sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow (s := Bad) (t := TT) Rel -- lower bound for each bad configuration have hlow : ∀ q ∈ Bad, (t.choose 3) ^ 2 ≤ (bipartiteAbove Rel TT q).card := by intro q hq rw [hBad] at hq obtain ⟨_, _, ⟨c, c', r1, r2, _, hr2, e1, e2, e3, e4, hh1, hh2⟩, _⟩ := mem_filter.mp hq have k1 : t ≤ (B.filter (fun z => dq z c = r1)).card := by exact_mod_cast hh1 have k2 : t ≤ (B.filter (fun z => dq z c' = r2)).card := by exact_mod_cast hh2 have hsub : (powersetCard 3 (B.filter (fun z => dq z c = r1))) ×ˢ (powersetCard 3 (B.filter (fun z => dq z c' = r2))) ⊆ bipartiteAbove Rel TT q := by intro tt htt obtain ⟨h1, h2⟩ := mem_product.mp htt obtain ⟨s1, c1⟩ := mem_powersetCard.mp h1 obtain ⟨s2, c2⟩ := mem_powersetCard.mp h2 unfold bipartiteAbove refine mem_filter.mpr ⟨?_, ?_⟩ · rw [hTT] exact mem_product.mpr ⟨mem_powersetCard.mpr ⟨s1.trans (filter_subset _ _), c1⟩, mem_powersetCard.mpr ⟨s2.trans (filter_subset _ _), c2⟩⟩ · rw [hRel] exact ⟨c, c', r1, r2, hr2, e1, e2, e3, e4, fun z hz => (mem_filter.mp (s1 hz)).2, fun z hz => (mem_filter.mp (s2 hz)).2⟩ have := card_le_card hsub rw [card_product, card_powersetCard, card_powersetCard] at this have m1 := Nat.choose_le_choose 3 k1 have m2 := Nat.choose_le_choose 3 k2 calc (t.choose 3) ^ 2 = t.choose 3 * t.choose 3 := sq _ _ ≤ _ := Nat.mul_le_mul m1 m2 _ ≤ _ := this -- upper bound for each pair of triples have hup : ∀ tt ∈ TT, ((bipartiteBelow Rel Bad tt).card : ℝ) ≤ 2 * T * (B.card : ℝ) ^ 2 := by intro tt htt by_cases hne : (bipartiteBelow Rel Bad tt).Nonempty swap · rw [not_nonempty_iff_eq_empty] at hne rw [hne] simp only [card_empty, Nat.cast_zero] positivity obtain ⟨q0, hq0⟩ := hne unfold bipartiteBelow at hq0 obtain ⟨_, hrel0⟩ := mem_filter.mp hq0 rw [hRel] at hrel0 obtain ⟨c, c', r1, r2, hr2, _, _, _, _, ht1, ht2⟩ := hrel0 rw [hTT] at htt obtain ⟨h1, h2⟩ := mem_product.mp htt obtain ⟨s1, c1⟩ := mem_powersetCard.mp h1 obtain ⟨s2, c2⟩ := mem_powersetCard.mp h2 obtain ⟨x1, x2, x3, x12, x13, x23, hx⟩ := card_eq_three.mp c1 obtain ⟨y1, y2, y3, y12, y13, y23, hy⟩ := card_eq_three.mp c2 have hxB : x1 ∈ B ∧ x2 ∈ B ∧ x3 ∈ B := by refine ⟨s1 ?_, s1 ?_, s1 ?_⟩ <;> rw [hx] <;> simp have hyB : y1 ∈ B ∧ y2 ∈ B ∧ y3 ∈ B := by refine ⟨s2 ?_, s2 ?_, s2 ?_⟩ <;> rw [hy] <;> simp have hxt : x1 ∈ tt.1 ∧ x2 ∈ tt.1 ∧ x3 ∈ tt.1 := by refine ⟨?_, ?_, ?_⟩ <;> rw [hx] <;> simp have hyt : y1 ∈ tt.2 ∧ y2 ∈ tt.2 ∧ y3 ∈ tt.2 := by refine ⟨?_, ?_, ?_⟩ <;> rw [hy] <;> simp have hcx := hnc x1 hxB.1 x2 hxB.2.1 x3 hxB.2.2 x12 x13 x23 have hcy := hnc y1 hyB.1 y2 hyB.2.1 y3 hyB.2.2 y12 y13 y23 have hsub : bipartiteBelow Rel Bad tt ⊆ (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => dq q.1 c = r1 ∧ dq q.2.1 c = r2 ∧ dq q.2.2.1 c' = r2 ∧ dq q.2.2.2 c' = r1 ∧ dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1) := by intro q hq unfold bipartiteBelow at hq obtain ⟨hqB, hrel⟩ := mem_filter.mp hq rw [hRel] at hrel obtain ⟨d, d', s1', s2', _, f1, f2, f3, f4, g1, g2⟩ := hrel obtain ⟨hd, hs1⟩ := circle_unique hcx (g1 x1 hxt.1) (g1 x2 hxt.2.1) (g1 x3 hxt.2.2) (ht1 x1 hxt.1) (ht1 x2 hxt.2.1) (ht1 x3 hxt.2.2) obtain ⟨hd', hs2⟩ := circle_unique hcy (g2 y1 hyt.1) (g2 y2 hyt.2.1) (g2 y3 hyt.2.2) (ht2 y1 hyt.1) (ht2 y2 hyt.2.1) (ht2 y3 hyt.2.2) rw [hBad] at hqB obtain ⟨hmem, hmatch, _, hpoor⟩ := mem_filter.mp hqB rw [hd, hs1] at f1 rw [hd, hs2] at f2 rw [hd', hs2] at f3 rw [hd', hs1] at f4 exact mem_filter.mpr ⟨hmem, f1, f2, f3, f4, hmatch, hpoor⟩ exact le_trans (by exact_mod_cast card_le_card hsub) (sim_fixed hT c c' r1 r2 hr2) have e1 : (Bad.card : ℝ) * ((t.choose 3 : ℕ) : ℝ) ^ 2 ≤ ((∑ q ∈ Bad, (bipartiteAbove Rel TT q).card : ℕ) : ℝ) := by have : Bad.card * (t.choose 3) ^ 2 ≤ ∑ q ∈ Bad, (bipartiteAbove Rel TT q).card := by rw [← smul_eq_mul, ← sum_const] exact sum_le_sum hlow exact_mod_cast this have e2 : ((∑ tt ∈ TT, (bipartiteBelow Rel Bad tt).card : ℕ) : ℝ) ≤ (TT.card : ℝ) * (2 * T * (B.card : ℝ) ^ 2) := by push_cast rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum hup have e3 : (TT.card : ℝ) = ((B.card.choose 3 : ℕ) : ℝ) ^ 2 := by rw [hTT, card_product, card_powersetCard] push_cast ring rw [hdc] at e1 rw [e3] at e2 linarith end E94S /-! ### SOLO slice B1a -/ /-! ## SOLO module B (part 1a): quadruples, levels and the tail of the row decomposition -/ namespace E94S open Finset /-- Counting through a relation that is total on `s` and injective from `t` back to `s`. -/ theorem card_le_of_rel {α β : Type*} (s : Finset α) (t : Finset β) (R : α → β → Prop) (hex : ∀ a ∈ s, ∃ b ∈ t, R a b) (huniq : ∀ a ∈ s, ∀ a' ∈ s, ∀ b ∈ t, R a b → R a' b → a = a') : s.card ≤ t.card := by classical rcases s.eq_empty_or_nonempty with h | ⟨a0, ha0⟩ · rw [h]; simp obtain ⟨b0, _, _⟩ := hex a0 ha0 obtain ⟨f, hf⟩ : ∃ f : α → β, ∀ a ∈ s, f a ∈ t ∧ R a (f a) := ⟨fun a => if h : a ∈ s then Classical.choose (hex a h) else b0, fun a ha => by simp only [dif_pos ha] exact Classical.choose_spec (hex a ha)⟩ refine card_le_card_of_injOn f (fun a ha => (hf a ha).1) ?_ intro a ha a' ha' hfa have h1 := (hf a ha).2 have h2 := (hf a' ha').2 rw [← hfa] at h2 exact huniq a ha a' ha' (f a) (hf a ha).1 h1 h2 /-- Distances from the pole are injective along a monotone row. -/ theorem row_inj {v : ℕ → ℂ} {r : ℕ × Finset ℕ × Bool} (hr : RowOK v r) {y y' : ℕ} (hy : y ∈ r.2.1) (hy' : y' ∈ r.2.1) (h : dq (v r.1) (v y) = dq (v r.1) (v y')) : y = y' := by have hd := dist_eq_of_dq_eq h by_contra hne rcases lt_or_gt_of_ne hne with hlt | hlt · have := hr.2 y hy y' hy' hlt by_cases hb : r.2.2 · rw [if_pos hb] at this; linarith · rw [if_neg hb] at this; linarith · have := hr.2 y' hy' y hy hlt by_cases hb : r.2.2 · rw [if_pos hb] at this; linarith · rw [if_neg hb] at this; linarith open Classical in /-- Ordered quadruples of labels `(a, b, c, d)` with `a ≠ b`, `c ≠ d`, `|v_a v_b| = |v_c v_d|`. -/ noncomputable def Qd (v : ℕ → ℂ) (n : ℕ) : Finset (ℕ × ℕ × ℕ × ℕ) := ((range n) ×ˢ (range n) ×ˢ (range n) ×ˢ (range n)).filter (fun q => q.1 ≠ q.2.1 ∧ q.2.2.1 ≠ q.2.2.2 ∧ dq (v q.1) (v q.2.1) = dq (v q.2.2.1) (v q.2.2.2)) theorem mem_Qd {v : ℕ → ℂ} {n : ℕ} {q : ℕ × ℕ × ℕ × ℕ} : q ∈ Qd v n ↔ (q.1 < n ∧ q.2.1 < n ∧ q.2.2.1 < n ∧ q.2.2.2 < n) ∧ q.1 ≠ q.2.1 ∧ q.2.2.1 ≠ q.2.2.2 ∧ dq (v q.1) (v q.2.1) = dq (v q.2.2.1) (v q.2.2.2) := by classical unfold Qd simp only [mem_filter, mem_product, mem_range] /-- The pair `{a, b}` is covered by a row of depth `l`. -/ def AtL (v : ℕ → ℂ) (n l a b : ℕ) : Prop := ∃ r ∈ lrows v n l, RCov r a b open Classical in /-- **Level count.** Quadruples whose first pair is covered at depth `l` and second pair at depth `m`. -/ theorem lvl_count {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (l m : ℕ) : ((Qd v n).filter (fun q => AtL v n l q.1 q.2.1 ∧ AtL v n m q.2.2.1 q.2.2.2)).card ≤ 4 * (lpairs v n l).card * (lrows v n m).card := by have key := card_le_of_rel ((Qd v n).filter (fun q => AtL v n l q.1 q.2.1 ∧ AtL v n m q.2.2.1 q.2.2.2)) ((lpairs v n l) ×ˢ ((univ : Finset Bool) ×ˢ ((lrows v n m) ×ˢ (univ : Finset Bool)))) (fun q β => (if β.2.1 then (q.1, q.2.1) = β.1 else (q.2.1, q.1) = β.1) ∧ (if β.2.2.2 then β.2.2.1.1 = q.2.2.1 ∧ q.2.2.2 ∈ β.2.2.1.2.1 else β.2.2.1.1 = q.2.2.2 ∧ q.2.2.1 ∈ β.2.2.1.2.1)) (by intro q hq obtain ⟨_, ⟨r1, hr1, hc1⟩, ⟨r2, hr2, hc2⟩⟩ := mem_filter.mp hq have hp : ∀ x y, x = r1.1 → y ∈ r1.2.1 → (x, y) ∈ lpairs v n l := by intro x y hx hy unfold lpairs exact mem_biUnion.mpr ⟨r1, hr1, mem_image.mpr ⟨y, hy, by rw [hx]⟩⟩ rcases hc1 with ⟨e1, e2⟩ | ⟨e1, e2⟩ <;> rcases hc2 with ⟨f1, f2⟩ | ⟨f1, f2⟩ · exact ⟨((q.1, q.2.1), true, r2, true), by simp [hp q.1 q.2.1 e1.symm e2, hr2], by simp [f1, f2]⟩ · exact ⟨((q.1, q.2.1), true, r2, false), by simp [hp q.1 q.2.1 e1.symm e2, hr2], by simp [f1, f2]⟩ · exact ⟨((q.2.1, q.1), false, r2, true), by simp [hp q.2.1 q.1 e1.symm e2, hr2], by simp [f1, f2]⟩ · exact ⟨((q.2.1, q.1), false, r2, false), by simp [hp q.2.1 q.1 e1.symm e2, hr2], by simp [f1, f2]⟩) (by intro q hq q' hq' β hβ hR hR' obtain ⟨hqQ, _⟩ := mem_filter.mp hq obtain ⟨hq'Q, _⟩ := mem_filter.mp hq' have hd := (mem_Qd.mp hqQ).2.2.2 have hd' := (mem_Qd.mp hq'Q).2.2.2 have hrow := (lrows_ok hccw hinj m β.2.2.1 (mem_product.mp (mem_product.mp (mem_product.mp hβ).2).2).1).1 obtain ⟨a, b, c, d⟩ := q obtain ⟨a', b', c', d'⟩ := q' simp only at hR hR' hd hd' have hab : a = a' ∧ b = b' := by by_cases hb : β.2.1 · rw [if_pos hb] at hR hR' have := hR.1.trans hR'.1.symm exact ⟨(Prod.mk.inj this).1, (Prod.mk.inj this).2⟩ · rw [if_neg hb] at hR hR' have := hR.1.trans hR'.1.symm exact ⟨(Prod.mk.inj this).2, (Prod.mk.inj this).1⟩ obtain ⟨rfl, rfl⟩ := hab by_cases hb : β.2.2.2 · rw [if_pos hb] at hR hR' have hc : c = c' := hR.2.1.symm.trans hR'.2.1 subst hc have : d = d' := row_inj hrow hR.2.2 hR'.2.2 (by rw [hR.2.1, ← hd, ← hd']) rw [this] · rw [if_neg hb] at hR hR' have hdd : d = d' := hR.2.1.symm.trans hR'.2.1 subst hdd have : c = c' := row_inj hrow hR.2.2 hR'.2.2 (by rw [hR.2.1, dq_comm (v d) (v c), dq_comm (v d) (v c'), ← hd, ← hd']) rw [this]) rw [card_product, card_product, card_product] at key simp only [card_univ, Fintype.card_bool] at key nlinarith [key] end E94S /-! ### SOLO slice B1b -/ /-! ## SOLO module B (part 1b): the tail of the row decomposition is small; `S = O(n³)` -/ namespace E94S open Finset open Classical in /-- The quadruples whose two pairs are covered at depths `l` and `m`. -/ noncomputable def Qlm (v : ℕ → ℂ) (n l m : ℕ) : Finset (ℕ × ℕ × ℕ × ℕ) := (Qd v n).filter (fun q => AtL v n l q.1 q.2.1 ∧ AtL v n m q.2.2.1 q.2.2.2) theorem Qlm_swap (v : ℕ → ℂ) (n l m : ℕ) : (Qlm v n l m).card ≤ (Qlm v n m l).card := by classical refine card_le_card_of_injOn (fun q => (q.2.2.1, q.2.2.2, q.1, q.2.1)) ?_ ?_ · intro q hq unfold Qlm at hq ⊢ obtain ⟨hQ, h1, h2⟩ := mem_filter.mp hq obtain ⟨⟨a1, a2, a3, a4⟩, b1, b2, b3⟩ := mem_Qd.mp hQ exact mem_filter.mpr ⟨mem_Qd.mpr ⟨⟨a3, a4, a1, a2⟩, b2, b1, b3.symm⟩, h2, h1⟩ · intro q _ q' _ h simp only [Prod.mk.injEq] at h obtain ⟨h1, h2, h3, h4⟩ := h exact Prod.ext h3 (Prod.ext h4 (Prod.ext h1 h2)) theorem pow_78 {l m : ℕ} (h : m ≤ l) : ((3 : ℝ) / 4) ^ l ≤ (7 / 8) ^ l * (7 / 8) ^ m := by have h1 : ((3 : ℝ) / 4) ^ l ≤ ((7 / 8) * (7 / 8)) ^ l := pow_le_pow_left₀ (by norm_num) (by norm_num) l rw [mul_pow] at h1 have h2 : ((7 : ℝ) / 8) ^ l ≤ (7 / 8) ^ m := pow_le_pow_of_le_one (by norm_num) (by norm_num) h have h3 : (0 : ℝ) ≤ (7 / 8) ^ l := by positivity nlinarith theorem lpairs_real {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (l : ℕ) : ((lpairs v n l).card : ℝ) ≤ (3 / 4) ^ l * (n : ℝ) ^ 2 := by have h := lpairs_card hccw hinj l have h' : ((4 : ℝ) ^ l) * ((lpairs v n l).card : ℝ) ≤ (3 : ℝ) ^ l * (n : ℝ) ^ 2 := by exact_mod_cast h have h4 : (0 : ℝ) < 4 ^ l := by positivity rw [div_pow, div_mul_eq_mul_div, le_div_iff₀ h4] linarith /-- The level count in real form. -/ theorem Qlm_real {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (l m : ℕ) : ((Qlm v n l m).card : ℝ) ≤ 64 * (n : ℝ) ^ 3 * ((7 / 8) ^ l * (7 / 8) ^ m) := by have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg n have key : ∀ a b : ℕ, ((Qlm v n a b).card : ℝ) ≤ 64 * (n : ℝ) ^ 3 * (3 / 4) ^ a := by intro a b have h1 : (Qlm v n a b).card ≤ 4 * (lpairs v n a).card * (lrows v n b).card := lvl_count hccw hinj a b have h2 := lrows_card hccw hinj b have h3 := lpairs_real hccw hinj a have h1' : ((Qlm v n a b).card : ℝ) ≤ 4 * ((lpairs v n a).card : ℝ) * ((lrows v n b).card : ℝ) := by exact_mod_cast h1 have h2' : ((lrows v n b).card : ℝ) ≤ 16 * n := by exact_mod_cast h2 have h4 : (0 : ℝ) ≤ ((lpairs v n a).card : ℝ) := Nat.cast_nonneg _ have h5 : (0 : ℝ) ≤ (3 / 4 : ℝ) ^ a := by positivity nlinarith [mul_le_mul_of_nonneg_left h2' h4, mul_le_mul_of_nonneg_right h3 hn0] have hn3 : (0 : ℝ) ≤ 64 * (n : ℝ) ^ 3 := by positivity rcases le_total m l with h | h · exact le_trans (key l m) (mul_le_mul_of_nonneg_left (pow_78 h) hn3) · have h1 : ((Qlm v n l m).card : ℝ) ≤ ((Qlm v n m l).card : ℝ) := by exact_mod_cast Qlm_swap v n l m have h2 := pow_78 h rw [mul_comm] at h2 exact le_trans h1 (le_trans (key m l) (mul_le_mul_of_nonneg_left h2 hn3)) theorem geom78 (a b : ℕ) : ∑ i ∈ Ico a b, ((7 : ℝ) / 8) ^ i ≤ 8 * (7 / 8) ^ a := by have h := geom_sum_Ico_le_of_lt_one (x := (7 : ℝ) / 8) (m := a) (n := b) (by norm_num) (by norm_num) have e : ((7 : ℝ) / 8) ^ a / (1 - 7 / 8) = 8 * (7 / 8) ^ a := by ring rw [e] at h exact h theorem geom78' (b : ℕ) : ∑ i ∈ range b, ((7 : ℝ) / 8) ^ i ≤ 8 := by have h := geom78 0 b rw [Nat.Ico_zero_eq_range] at h simpa using h /-- The pair `{a, b}` is covered at a depth `< L`. -/ def MainP (v : ℕ → ℂ) (n L a b : ℕ) : Prop := ∃ l < L, AtL v n l a b open Classical in /-- **The tail is small.** Quadruples with a pair not covered before depth `L`. -/ theorem tail_bound {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L : ℕ) : (((Qd v n).filter (fun q => ¬ (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2))).card : ℝ) ≤ 8192 * (7 / 8) ^ L * (n : ℝ) ^ 3 := by obtain ⟨P1, hP1⟩ : ∃ P1 : Finset (ℕ × ℕ), P1 = (Ico L (n ^ 2)) ×ˢ (range (n ^ 2)) := ⟨_, rfl⟩ obtain ⟨P2, hP2⟩ : ∃ P2 : Finset (ℕ × ℕ), P2 = (range (n ^ 2)) ×ˢ (Ico L (n ^ 2)) := ⟨_, rfl⟩ have hsub : (Qd v n).filter (fun q => ¬ (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2)) ⊆ (P1 ∪ P2).biUnion (fun lm => Qlm v n lm.1 lm.2) := by intro q hq obtain ⟨hQ, hnot⟩ := mem_filter.mp hq obtain ⟨⟨a1, a2, a3, a4⟩, b1, b2, _⟩ := mem_Qd.mp hQ obtain ⟨l, hl, r, hr, hc⟩ := cover_all hccw hinj a1 a2 b1 obtain ⟨m, hm, r', hr', hc'⟩ := cover_all hccw hinj a3 a4 b2 have hlm : L ≤ l ∨ L ≤ m := by by_contra hcon push_neg at hcon exact hnot ⟨⟨l, hcon.1, r, hr, hc⟩, ⟨m, hcon.2, r', hr', hc'⟩⟩ refine mem_biUnion.mpr ⟨(l, m), ?_, ?_⟩ · rw [hP1, hP2] rcases hlm with h | h · exact mem_union_left _ (mem_product.mpr ⟨mem_Ico.mpr ⟨h, hl⟩, mem_range.mpr hm⟩) · exact mem_union_right _ (mem_product.mpr ⟨mem_range.mpr hl, mem_Ico.mpr ⟨h, hm⟩⟩) · unfold Qlm exact mem_filter.mpr ⟨hQ, ⟨r, hr, hc⟩, ⟨r', hr', hc'⟩⟩ have h1 : (((Qd v n).filter (fun q => ¬ (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2))).card : ℝ) ≤ ∑ lm ∈ P1 ∪ P2, ((Qlm v n lm.1 lm.2).card : ℝ) := by have := le_trans (card_le_card hsub) card_biUnion_le exact_mod_cast this have h2 : ∑ lm ∈ P1 ∪ P2, ((Qlm v n lm.1 lm.2).card : ℝ) ≤ ∑ lm ∈ P1 ∪ P2, 64 * (n : ℝ) ^ 3 * ((7 / 8) ^ lm.1 * (7 / 8) ^ lm.2) := sum_le_sum (fun lm _ => Qlm_real hccw hinj lm.1 lm.2) have hnn : ∀ lm : ℕ × ℕ, (0 : ℝ) ≤ 64 * (n : ℝ) ^ 3 * ((7 / 8) ^ lm.1 * (7 / 8) ^ lm.2) := by intro lm; positivity have h3 : ∑ lm ∈ P1 ∪ P2, 64 * (n : ℝ) ^ 3 * ((7 / 8 : ℝ) ^ lm.1 * (7 / 8) ^ lm.2) ≤ ∑ lm ∈ P1, 64 * (n : ℝ) ^ 3 * ((7 / 8 : ℝ) ^ lm.1 * (7 / 8) ^ lm.2) + ∑ lm ∈ P2, 64 * (n : ℝ) ^ 3 * ((7 / 8 : ℝ) ^ lm.1 * (7 / 8) ^ lm.2) := by have := sum_union_inter (s₁ := P1) (s₂ := P2) (f := fun lm : ℕ × ℕ => 64 * (n : ℝ) ^ 3 * ((7 / 8 : ℝ) ^ lm.1 * (7 / 8) ^ lm.2)) have h0 : (0 : ℝ) ≤ ∑ lm ∈ P1 ∩ P2, 64 * (n : ℝ) ^ 3 * ((7 / 8 : ℝ) ^ lm.1 * (7 / 8) ^ lm.2) := sum_nonneg (fun lm _ => hnn lm) linarith have hn3 : (0 : ℝ) ≤ 64 * (n : ℝ) ^ 3 := by positivity have g1 := geom78 L (n ^ 2) have g2 := geom78' (n ^ 2) have g1' : (0 : ℝ) ≤ ∑ i ∈ Ico L (n ^ 2), ((7 : ℝ) / 8) ^ i := sum_nonneg (fun i _ => by positivity) have g2' : (0 : ℝ) ≤ ∑ i ∈ range (n ^ 2), ((7 : ℝ) / 8) ^ i := sum_nonneg (fun i _ => by positivity) have hpL : (0 : ℝ) ≤ (7 / 8) ^ L := by positivity have h4 : ∑ lm ∈ P1, 64 * (n : ℝ) ^ 3 * ((7 / 8 : ℝ) ^ lm.1 * (7 / 8) ^ lm.2) ≤ 64 * (n : ℝ) ^ 3 * (64 * (7 / 8) ^ L) := by rw [hP1, ← mul_sum, sum_product, ← sum_mul_sum] refine mul_le_mul_of_nonneg_left ?_ hn3 nlinarith [mul_le_mul g1 g2 g2' (by positivity : (0 : ℝ) ≤ 8 * (7 / 8) ^ L)] have h5 : ∑ lm ∈ P2, 64 * (n : ℝ) ^ 3 * ((7 / 8 : ℝ) ^ lm.1 * (7 / 8) ^ lm.2) ≤ 64 * (n : ℝ) ^ 3 * (64 * (7 / 8) ^ L) := by rw [hP2, ← mul_sum, sum_product, ← sum_mul_sum] refine mul_le_mul_of_nonneg_left ?_ hn3 nlinarith [mul_le_mul g2 g1 g1' (by norm_num : (0 : ℝ) ≤ 8)] nlinarith [h1, h2, h3, h4, h5] open Classical in /-- **`S = O(n³)` in quadruple form.** -/ theorem Qd_card_le {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) : ((Qd v n).card : ℝ) ≤ 8192 * (n : ℝ) ^ 3 := by have h := tail_bound hccw hinj 0 have e : (Qd v n).filter (fun q => ¬ (MainP v n 0 q.1 q.2.1 ∧ MainP v n 0 q.2.2.1 q.2.2.2)) = Qd v n := by apply filter_true_of_mem intro q _ hcon obtain ⟨⟨l, hl, _⟩, _⟩ := hcon omega rw [e] at h simpa using h end E94S /-! ### SOLO slice B1c -/ /-! ## SOLO module B (part 1c): main rows, matches of a row pair, cells and windows -/ namespace E94S open Finset /-- The rows of depth `< L`. -/ noncomputable def Rws (v : ℕ → ℂ) (n L : ℕ) : Finset (ℕ × Finset ℕ × Bool) := (range L).biUnion (lrows v n) theorem Rws_card {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L : ℕ) : (Rws v n L).card ≤ 16 * L * n := by classical unfold Rws refine le_trans card_biUnion_le ?_ have h1 : ∑ l ∈ range L, (lrows v n l).card ≤ ∑ _l ∈ range L, 16 * n := sum_le_sum (fun l _ => lrows_card hccw hinj l) rw [sum_const, card_range, smul_eq_mul] at h1 nlinarith [h1] theorem Rws_ok {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L : ℕ) : ∀ r ∈ Rws v n L, RowOK v r ∧ r.1 < n ∧ ∀ y ∈ r.2.1, y < n := by intro r hr unfold Rws at hr obtain ⟨l, _, hrl⟩ := mem_biUnion.mp hr obtain ⟨hok, I, hI, h1, h2⟩ := lrows_ok hccw hinj l r hrl exact ⟨hok, nodes_lt hccw hinj l I hI r.1 h1, fun y hy => nodes_lt hccw hinj l I hI y (h2 hy)⟩ theorem Rws_pole {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L x : ℕ) : ((Rws v n L).filter (fun r => r.1 = x)).card ≤ 16 * L := by classical unfold Rws rw [filter_biUnion] refine le_trans card_biUnion_le ?_ have h1 : ∑ l ∈ range L, ((lrows v n l).filter (fun r => r.1 = x)).card ≤ ∑ _l ∈ range L, 16 := sum_le_sum (fun l _ => lrows_pole hccw hinj l x) rw [sum_const, card_range, smul_eq_mul] at h1 omega theorem mainP_iff {v : ℕ → ℂ} {n L a b : ℕ} : MainP v n L a b ↔ ∃ r ∈ Rws v n L, RCov r a b := by unfold MainP AtL Rws constructor · rintro ⟨l, hl, r, hr, hc⟩ exact ⟨r, mem_biUnion.mpr ⟨l, mem_range.mpr hl, hr⟩, hc⟩ · rintro ⟨r, hr, hc⟩ obtain ⟨l, hl, hrl⟩ := mem_biUnion.mp hr exact ⟨l, mem_range.mp hl, r, hrl, hc⟩ open Classical in /-- The matches of a pair of rows. -/ noncomputable def ms (v : ℕ → ℂ) (r r' : ℕ × Finset ℕ × Bool) : Finset (ℕ × ℕ) := (r.2.1 ×ˢ r'.2.1).filter (fun m => dq (v r.1) (v m.1) = dq (v r'.1) (v m.2)) theorem mem_ms {v : ℕ → ℂ} {r r' : ℕ × Finset ℕ × Bool} {m : ℕ × ℕ} : m ∈ ms v r r' ↔ (m.1 ∈ r.2.1 ∧ m.2 ∈ r'.2.1) ∧ dq (v r.1) (v m.1) = dq (v r'.1) (v m.2) := by classical unfold ms rw [mem_filter, mem_product] theorem dq_lt_of_dist_lt {z w z' w' : ℂ} (h : dist z w < dist z' w') : dq z w < dq z' w' := by rw [dist_eq_sqrt_dq, dist_eq_sqrt_dq] at h by_contra hcon push_neg at hcon exact absurd (Real.sqrt_le_sqrt hcon) (not_le.mpr h) /-- Monotone rows: a smaller distance means an earlier label (increasing rows) or a later one (decreasing rows). -/ theorem row_mono_le {v : ℕ → ℂ} {r : ℕ × Finset ℕ × Bool} (hr : RowOK v r) {y y' : ℕ} (hy : y ∈ r.2.1) (hy' : y' ∈ r.2.1) (h : dq (v r.1) (v y) ≤ dq (v r.1) (v y')) : if r.2.2 then y ≤ y' else y' ≤ y := by by_cases hb : r.2.2 · rw [if_pos hb] by_contra hcon push_neg at hcon have := hr.2 y' hy' y hy hcon rw [if_pos hb] at this linarith [dq_lt_of_dist_lt this] · rw [if_neg hb] by_contra hcon push_neg at hcon have := hr.2 y hy y' hy' hcon rw [if_neg hb] at this linarith [dq_lt_of_dist_lt this] /-- The cell (pair of label blocks of length `G`) of a match. -/ def cellOf (G : ℕ) (m : ℕ × ℕ) : ℕ × ℕ := (m.1 / G, m.2 / G) /-- **Staircase.** The matches of two monotone rows meet at most `2⌊n/G⌋ + 1` cells. -/ theorem cells_card {v : ℕ → ℂ} {n G : ℕ} {r r' : ℕ × Finset ℕ × Bool} (hr : RowOK v r) (hr' : RowOK v r') (hlt : ∀ y ∈ r.2.1, y < n) (hlt' : ∀ y ∈ r'.2.1, y < n) : ((ms v r r').image (cellOf G)).card ≤ 2 * (n / G) + 1 := by classical have hK : ∀ m ∈ ms v r r', m.1 / G ≤ n / G ∧ m.2 / G ≤ n / G := by intro m hm obtain ⟨⟨h1, h2⟩, _⟩ := mem_ms.mp hm exact ⟨Nat.div_le_div_right (hlt m.1 h1).le, Nat.div_le_div_right (hlt' m.2 h2).le⟩ have hcard := card_le_card_of_injOn (s := (ms v r r').image (cellOf G)) (t := range (2 * (n / G) + 1)) (fun c => if r.2.2 = r'.2.2 then c.1 + c.2 else c.1 + (n / G - c.2)) (by intro c hc obtain ⟨m, hm, rfl⟩ := mem_image.mp hc have h12 := hK m hm simp only [cellOf, coe_range, Set.mem_Iio] generalize n / G = K at h12 ⊢ generalize m.1 / G = i at h12 ⊢ generalize m.2 / G = j at h12 ⊢ split_ifs <;> omega) (by intro c hc c' hc' hkey obtain ⟨m, hm, rfl⟩ := mem_image.mp hc obtain ⟨m', hm', rfl⟩ := mem_image.mp hc' have b1 := hK m hm have b2 := hK m' hm' obtain ⟨⟨h1, h2⟩, e⟩ := mem_ms.mp hm obtain ⟨⟨h1', h2'⟩, e'⟩ := mem_ms.mp hm' simp only [cellOf] at hkey ⊢ generalize hKK : n / G = K at b1 b2 hkey -- comparability have comp : ∀ a ∈ ms v r r', ∀ b ∈ ms v r r', dq (v r.1) (v a.1) ≤ dq (v r.1) (v b.1) → (if r.2.2 then a.1 / G ≤ b.1 / G else b.1 / G ≤ a.1 / G) ∧ (if r'.2.2 then a.2 / G ≤ b.2 / G else b.2 / G ≤ a.2 / G) := by intro a ha b hb hab obtain ⟨⟨a1, a2⟩, ea⟩ := mem_ms.mp ha obtain ⟨⟨b1', b2'⟩, eb⟩ := mem_ms.mp hb have m1 := row_mono_le hr a1 b1' hab have m2 := row_mono_le hr' a2 b2' (by rw [← ea, ← eb]; exact hab) constructor · by_cases hb1 : r.2.2 · rw [if_pos hb1] at m1 ⊢; exact Nat.div_le_div_right m1 · rw [if_neg hb1] at m1 ⊢; exact Nat.div_le_div_right m1 · by_cases hb2 : r'.2.2 · rw [if_pos hb2] at m2 ⊢; exact Nat.div_le_div_right m2 · rw [if_neg hb2] at m2 ⊢; exact Nat.div_le_div_right m2 rcases le_total (dq (v r.1) (v m.1)) (dq (v r.1) (v m'.1)) with hle | hle · obtain ⟨c1, c2⟩ := comp m hm m' hm' hle by_cases hb1 : r.2.2 <;> by_cases hb2 : r'.2.2 <;> simp only [hb1, hb2, if_true, if_false, Bool.true_eq_false, Bool.false_eq_true] at c1 c2 hkey <;> (apply Prod.ext <;> simp only <;> omega) · obtain ⟨c1, c2⟩ := comp m' hm' m hm hle by_cases hb1 : r.2.2 <;> by_cases hb2 : r'.2.2 <;> simp only [hb1, hb2, if_true, if_false, Bool.true_eq_false, Bool.false_eq_true] at c1 c2 hkey <;> (apply Prod.ext <;> simp only <;> omega)) rwa [card_range] at hcard /-- The block of labels with quotient `i` by `G`. -/ noncomputable def blk (n G i : ℕ) : Finset ℕ := (range n).filter (fun y => y / G = i) theorem blk_card (n G i : ℕ) (hG : 0 < G) : (blk n G i).card ≤ G := by have hsub : blk n G i ⊆ Ico (i * G) (i * G + G) := by intro y hy unfold blk at hy obtain ⟨_, h⟩ := mem_filter.mp hy rw [mem_Ico] have h1 := Nat.div_mul_le_self y G have h2 := Nat.lt_div_mul_add hG (a := y) rw [h] at h1 h2 exact ⟨h1, h2⟩ have := card_le_card hsub rwa [Nat.card_Ico, Nat.add_sub_cancel_left] at this open Classical in /-- All potential windows: four pairs of labels inside one cell. -/ noncomputable def Wins (n G : ℕ) : Finset (Finset (ℕ × ℕ)) := ((range (n / G + 1)) ×ˢ (range (n / G + 1))).biUnion (fun ij => powersetCard 4 ((blk n G ij.1) ×ˢ (blk n G ij.2))) theorem Wins_card (n G : ℕ) (hG : 0 < G) : (Wins n G).card ≤ (n / G + 1) ^ 2 * G ^ 8 := by classical unfold Wins refine le_trans card_biUnion_le ?_ have h1 : ∀ ij ∈ (range (n / G + 1)) ×ˢ (range (n / G + 1)), (powersetCard 4 ((blk n G ij.1) ×ˢ (blk n G ij.2))).card ≤ G ^ 8 := by intro ij _ rw [card_powersetCard, card_product] have a := blk_card n G ij.1 hG have b := blk_card n G ij.2 hG have c : (blk n G ij.1).card * (blk n G ij.2).card ≤ G * G := Nat.mul_le_mul a b calc ((blk n G ij.1).card * (blk n G ij.2).card).choose 4 ≤ (G * G).choose 4 := Nat.choose_le_choose 4 c _ ≤ (G * G) ^ 4 := Nat.choose_le_pow (G * G) 4 _ = G ^ 8 := by ring have h2 := sum_le_sum h1 rw [sum_const, card_product, card_range, smul_eq_mul] at h2 calc _ ≤ (n / G + 1) * (n / G + 1) * G ^ 8 := h2 _ = (n / G + 1) ^ 2 * G ^ 8 := by ring open Classical in /-- **Cells versus windows.** A set `A` of matches of two monotone rows: at most `3` per cell in sparse cells, and every match of a dense cell lies in a window made of matches of the same row pair. -/ theorem cell_split {v : ℕ → ℂ} {n G : ℕ} {r r' : ℕ × Finset ℕ × Bool} (hr : RowOK v r) (hr' : RowOK v r') (hlt : ∀ y ∈ r.2.1, y < n) (hlt' : ∀ y ∈ r'.2.1, y < n) {A : Finset (ℕ × ℕ)} (hA : A ⊆ ms v r r') : A.card ≤ 3 * (2 * (n / G) + 1) + 4 * ((Wins n G).filter (fun w => w ⊆ ms v r r' ∧ ∃ m ∈ w, m ∈ A)).card := by obtain ⟨cnt, hcnt⟩ : ∃ cnt : ℕ × ℕ → ℕ, cnt = fun m => ((ms v r r').filter (fun m' => cellOf G m' = cellOf G m)).card := ⟨_, rfl⟩ have hsplit := card_filter_add_card_filter_not (s := A) (fun m => cnt m ≤ 3) -- sparse cells have hs : (A.filter (fun m => cnt m ≤ 3)).card ≤ 3 * (2 * (n / G) + 1) := by have h1 := card_le_mul_card_image (f := cellOf G) (A.filter (fun m => cnt m ≤ 3)) 3 (by intro c hc obtain ⟨a0, ha0, rfl⟩ := mem_image.mp hc obtain ⟨_, ha03⟩ := mem_filter.mp ha0 rw [hcnt] at ha03 refine le_trans (card_le_card ?_) ha03 intro a ha obtain ⟨ha1, ha2⟩ := mem_filter.mp ha exact mem_filter.mpr ⟨hA (mem_filter.mp ha1).1, ha2⟩) have h2 : ((A.filter (fun m => cnt m ≤ 3)).image (cellOf G)).card ≤ 2 * (n / G) + 1 := le_trans (card_le_card (image_subset_image ((filter_subset _ _).trans hA))) (cells_card hr hr' hlt hlt') calc _ ≤ 3 * ((A.filter (fun m => cnt m ≤ 3)).image (cellOf G)).card := h1 _ ≤ 3 * (2 * (n / G) + 1) := Nat.mul_le_mul_left _ h2 -- dense cells have hex : ∀ m ∈ A.filter (fun m => ¬ cnt m ≤ 3), ∃ w : Finset (ℕ × ℕ), {m} ⊆ w ∧ w ⊆ (ms v r r').filter (fun m' => cellOf G m' = cellOf G m) ∧ w.card = 4 := by intro m hm obtain ⟨hmA, hm4⟩ := mem_filter.mp hm rw [hcnt] at hm4 push_neg at hm4 exact exists_subsuperset_card_eq (singleton_subset_iff.mpr (mem_filter.mpr ⟨hA hmA, rfl⟩)) (by simp) hm4 obtain ⟨W, hW⟩ : ∃ W : ℕ × ℕ → Finset (ℕ × ℕ), ∀ m ∈ A.filter (fun m => ¬ cnt m ≤ 3), {m} ⊆ W m ∧ W m ⊆ (ms v r r').filter (fun m' => cellOf G m' = cellOf G m) ∧ (W m).card = 4 := ⟨fun m => if h : m ∈ A.filter (fun m => ¬ cnt m ≤ 3) then Classical.choose (hex m h) else ∅, fun m hm => by simp only [dif_pos hm] exact Classical.choose_spec (hex m hm)⟩ have hd : (A.filter (fun m => ¬ cnt m ≤ 3)).card ≤ 4 * ((Wins n G).filter (fun w => w ⊆ ms v r r' ∧ ∃ m ∈ w, m ∈ A)).card := by have h1 := card_le_mul_card_image (f := W) (A.filter (fun m => ¬ cnt m ≤ 3)) 4 (by intro w hw obtain ⟨a0, ha0, rfl⟩ := mem_image.mp hw rw [← (hW a0 ha0).2.2] refine card_le_card ?_ intro a ha obtain ⟨ha1, ha2⟩ := mem_filter.mp ha rw [← ha2] exact singleton_subset_iff.mp (hW a ha1).1) have h2 : (A.filter (fun m => ¬ cnt m ≤ 3)).image W ⊆ (Wins n G).filter (fun w => w ⊆ ms v r r' ∧ ∃ m ∈ w, m ∈ A) := by intro w hw obtain ⟨a, ha, rfl⟩ := mem_image.mp hw obtain ⟨h1', h2', h3'⟩ := hW a ha have haA := (mem_filter.mp ha).1 obtain ⟨⟨a1, a2⟩, _⟩ := mem_ms.mp (hA haA) refine mem_filter.mpr ⟨?_, h2'.trans (filter_subset _ _), a, singleton_subset_iff.mp h1', haA⟩ unfold Wins refine mem_biUnion.mpr ⟨cellOf G a, ?_, ?_⟩ · simp only [cellOf, mem_product, mem_range] exact ⟨Nat.lt_succ_of_le (Nat.div_le_div_right (hlt a.1 a1).le), Nat.lt_succ_of_le (Nat.div_le_div_right (hlt' a.2 a2).le)⟩ · refine mem_powersetCard.mpr ⟨?_, h3'⟩ intro x hx obtain ⟨hx1, hx2⟩ := mem_filter.mp (h2' hx) obtain ⟨⟨x1, x2⟩, _⟩ := mem_ms.mp hx1 simp only [cellOf, Prod.mk.injEq] at hx2 unfold blk exact mem_product.mpr ⟨mem_filter.mpr ⟨mem_range.mpr (hlt x.1 x1), hx2.1⟩, mem_filter.mpr ⟨mem_range.mpr (hlt' x.2 x2), hx2.2⟩⟩ calc _ ≤ 4 * ((A.filter (fun m => ¬ cnt m ≤ 3)).image W).card := h1 _ ≤ _ := Nat.mul_le_mul_left _ (card_le_card h2) omega end E94S /-! ### SOLO slice B1d -/ /-! ## SOLO module B (part 1d): from matches to windows, and the three types of rich windows -/ namespace E94S open Finset theorem expl_mono {B : Finset ℂ} {T T' : ℝ} (h : T ≤ T') {a b c d : ℂ} (he : Expl B T' a b c d) : Expl B T a b c d := by obtain ⟨g, hg, hcase⟩ := he rcases hcase with ⟨h1, h2, h3⟩ | ⟨h1, h2, h3⟩ · exact ⟨g, hg, Or.inl ⟨h1, h2, le_trans h h3⟩⟩ · exact ⟨g, hg, Or.inr ⟨h1, h2, le_trans h h3⟩⟩ theorem simCfg_mono {B : Finset ℂ} {T T' : ℝ} (h : T ≤ T') {P Y P' Z : ℂ} (hs : SimCfg B T' P Y P' Z) : SimCfg B T P Y P' Z := by obtain ⟨c, c', r1, r2, a1, a2, a3, a4, a5, a6, a7, a8⟩ := hs exact ⟨c, c', r1, r2, a1, a2, a3, a4, a5, a6, le_trans h a7, le_trans h a8⟩ /-- A rich window that is affine but not a similarity (the Ivory case). -/ def ConicRich (v : ℕ → ℂ) (n : ℕ) (T' : ℝ) (w : Finset (ℕ × ℕ)) : Prop := IsWin n w ∧ T' ≤ ((wsol v n w).card : ℝ) ∧ ∃ l11 l12 l21 l22 : ℝ, ∃ q₀ : ℂ, (∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q₀) ∧ (∀ m ∈ w, ∀ m' ∈ w, LinMap l11 l12 l21 l22 (v m.1 - v m'.1) (v m.2 - v m'.2)) ∧ l11 * l22 - l12 * l21 ≠ 0 ∧ ¬ (l21 ^ 2 + l22 ^ 2 = l11 ^ 2 + l12 ^ 2 ∧ l11 * l21 + l12 * l22 = 0) /-- A window contained in the matches of two monotone rows is a window in the sense of `IsWin`. -/ theorem isWin_of_sub {v : ℕ → ℂ} {n G : ℕ} {r r' : ℕ × Finset ℕ × Bool} (hr : RowOK v r) (hr' : RowOK v r') (hlt : ∀ y ∈ r.2.1, y < n) (hlt' : ∀ y ∈ r'.2.1, y < n) {w : Finset (ℕ × ℕ)} (hw : w ∈ Wins n G) (hsub : w ⊆ ms v r r') : IsWin n w := by classical unfold Wins at hw obtain ⟨ij, _, hw2⟩ := mem_biUnion.mp hw obtain ⟨_, hc⟩ := mem_powersetCard.mp hw2 refine ⟨hc, ?_, ?_, ?_⟩ · intro m hm obtain ⟨⟨h1, h2⟩, _⟩ := mem_ms.mp (hsub hm) exact ⟨hlt m.1 h1, hlt' m.2 h2⟩ · intro m hm m' hm' h obtain ⟨⟨h1, h2⟩, e⟩ := mem_ms.mp (hsub hm) obtain ⟨⟨h1', h2'⟩, e'⟩ := mem_ms.mp (hsub hm') have : m.2 = m'.2 := row_inj hr' h2 h2' (by rw [← e, ← e', h]) exact Prod.ext h this · intro m hm m' hm' h obtain ⟨⟨h1, h2⟩, e⟩ := mem_ms.mp (hsub hm) obtain ⟨⟨h1', h2'⟩, e'⟩ := mem_ms.mp (hsub hm') have : m.1 = m'.1 := row_inj hr h1 h1' (by rw [e, e', h]) exact Prod.ext this h open Classical in /-- **Row pairs through a window.** For a potential window `w`, the pairs of main rows whose matches contain `w` and contain a match of `w` that is neither explained (threshold `T`) nor a radius-swap configuration (threshold `T'`) number at most `μ²·T'`, or `μ²·|wsol w|` when `w` is a rich Ivory window; `μ = 16L` bounds the rows per pole. -/ theorem window_pairs_bound {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L G : ℕ) {T T' : ℝ} (hTT : T ≤ T') (hT3 : 3 ≤ T') {w : Finset (ℕ × ℕ)} (hw : w ∈ Wins n G) : ((((Rws v n L) ×ˢ (Rws v n L)).filter (fun rr => w ⊆ ms v rr.1 rr.2 ∧ ∃ m ∈ w, ¬ Expl (pts v n) T (v rr.1.1) (v m.1) (v rr.2.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v rr.1.1) (v m.1) (v rr.2.1) (v m.2))).card : ℝ) ≤ ((16 * L : ℕ) : ℝ) ^ 2 * (T' + if ConicRich v n T' w then ((wsol v n w).card : ℝ) else 0) := by obtain ⟨Nw, hNw⟩ : ∃ Nw : Finset ((ℕ × Finset ℕ × Bool) × (ℕ × Finset ℕ × Bool)), Nw = ((Rws v n L) ×ˢ (Rws v n L)).filter (fun rr => w ⊆ ms v rr.1 rr.2 ∧ ∃ m ∈ w, ¬ Expl (pts v n) T (v rr.1.1) (v m.1) (v rr.2.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v rr.1.1) (v m.1) (v rr.2.1) (v m.2)) := ⟨_, rfl⟩ rw [← hNw] have hT0 : (0 : ℝ) ≤ T' := by linarith have hμ0 : (0 : ℝ) ≤ ((16 * L : ℕ) : ℝ) ^ 2 := by positivity by_cases hne : Nw.Nonempty swap · rw [not_nonempty_iff_eq_empty] at hne rw [hne] simp only [card_empty, Nat.cast_zero] refine mul_nonneg hμ0 ?_ split_ifs · positivity · linarith -- the map to pole pairs have hmem : ∀ rr ∈ Nw, (rr.1 ∈ Rws v n L ∧ rr.2 ∈ Rws v n L) ∧ w ⊆ ms v rr.1 rr.2 ∧ ∃ m ∈ w, ¬ Expl (pts v n) T (v rr.1.1) (v m.1) (v rr.2.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v rr.1.1) (v m.1) (v rr.2.1) (v m.2) := by intro rr hrr rw [hNw] at hrr obtain ⟨h1, h2⟩ := mem_filter.mp hrr exact ⟨mem_product.mp h1, h2⟩ have hsol : ∀ rr ∈ Nw, (rr.1.1, rr.2.1) ∈ wsol v n w := by intro rr hrr obtain ⟨⟨h1, h2⟩, hsub, _⟩ := hmem rr hrr refine mem_wsol.mpr ⟨⟨(Rws_ok hccw hinj L rr.1 h1).2.1, (Rws_ok hccw hinj L rr.2 h2).2.1⟩, ?_⟩ intro m hm exact (mem_ms.mp (hsub hm)).2 have hfib : Nw.card ≤ (16 * L) ^ 2 * (Nw.image (fun rr => (rr.1.1, rr.2.1))).card := by refine card_le_mul_card_image (f := fun rr : (ℕ × Finset ℕ × Bool) × (ℕ × Finset ℕ × Bool) => (rr.1.1, rr.2.1)) Nw ((16 * L) ^ 2) ?_ intro pp _ have hsub : Nw.filter (fun rr => (rr.1.1, rr.2.1) = pp) ⊆ ((Rws v n L).filter (fun r => r.1 = pp.1)) ×ˢ ((Rws v n L).filter (fun r => r.1 = pp.2)) := by intro rr hrr obtain ⟨h1, h2⟩ := mem_filter.mp hrr obtain ⟨⟨a1, a2⟩, _⟩ := hmem rr h1 have e1 : rr.1.1 = pp.1 := by rw [← h2] have e2 : rr.2.1 = pp.2 := by rw [← h2] exact mem_product.mpr ⟨mem_filter.mpr ⟨a1, e1⟩, mem_filter.mpr ⟨a2, e2⟩⟩ refine le_trans (card_le_card hsub) ?_ rw [card_product, sq] exact Nat.mul_le_mul (Rws_pole hccw hinj L pp.1) (Rws_pole hccw hinj L pp.2) have himg : (Nw.image (fun rr => (rr.1.1, rr.2.1))).card ≤ (wsol v n w).card := by refine card_le_card ?_ intro pp hpp obtain ⟨rr, hrr, rfl⟩ := mem_image.mp hpp exact hsol rr hrr have hmain : (Nw.card : ℝ) ≤ ((16 * L : ℕ) : ℝ) ^ 2 * ((wsol v n w).card : ℝ) := by have : Nw.card ≤ (16 * L) ^ 2 * (wsol v n w).card := le_trans hfib (Nat.mul_le_mul_left _ himg) exact_mod_cast this -- the window is a genuine window obtain ⟨rr0, hrr0⟩ := hne obtain ⟨⟨a1, a2⟩, hsub0, m0, hm0, hne0, hns0⟩ := hmem rr0 hrr0 have ok1 := Rws_ok hccw hinj L rr0.1 a1 have ok2 := Rws_ok hccw hinj L rr0.2 a2 have hwin : IsWin n w := isWin_of_sub ok1.1 ok2.1 ok1.2.2 ok2.2.2 hw hsub0 by_cases hrich : T' ≤ ((wsol v n w).card : ℝ) swap · push_neg at hrich have : (Nw.card : ℝ) ≤ ((16 * L : ℕ) : ℝ) ^ 2 * T' := le_trans hmain (mul_le_mul_of_nonneg_left hrich.le hμ0) refine le_trans this (mul_le_mul_of_nonneg_left ?_ hμ0) split_ifs · linarith [(Nat.cast_nonneg (wsol v n w).card : (0 : ℝ) ≤ _)] · linarith have h3 : 3 ≤ (wsol v n w).card := by have : (3 : ℝ) ≤ ((wsol v n w).card : ℝ) := le_trans hT3 hrich exact_mod_cast this obtain ⟨l11, l12, l21, l22, q₀, hpole, hlin, hdet⟩ := win_class hccw hinj hwin h3 by_cases hsim : l21 ^ 2 + l22 ^ 2 = l11 ^ 2 + l12 ^ 2 ∧ l11 * l21 + l12 * l22 = 0 · -- similarity windows have no bad match at all exfalso by_cases hΛ : l11 ^ 2 + l12 ^ 2 = 1 · have := win_iso_expl hccw hinj hwin h3 hpole hlin hdet hΛ (hsim.1.trans hΛ) hsim.2 (rr0.1.1, rr0.2.1) (hsol rr0 hrr0) m0 hm0 exact hne0 (expl_mono (le_trans hTT hrich) this) · have := win_sim_cfg hinj hwin (by omega) hpole hlin hdet rfl hsim.1 hsim.2 hΛ (rr0.1.1, rr0.2.1) (hsol rr0 hrr0) m0 hm0 exact hns0 (simCfg_mono hrich this) · have hcr : ConicRich v n T' w := ⟨hwin, hrich, l11, l12, l21, l22, q₀, hpole, hlin, hdet, hsim⟩ rw [if_pos hcr] nlinarith [hmain] end E94S /-! ### SOLO slice B1e -/ /-! ## SOLO module B (part 1e): summing over row pairs -/ namespace E94S open Finset theorem expl_swap {B : Finset ℂ} {T : ℝ} {a b c d : ℂ} (h : Expl B T a b c d) : Expl B T b a d c := by obtain ⟨g, hg, hcase⟩ := h rcases hcase with ⟨h1, h2, h3⟩ | ⟨h1, h2, h3⟩ · exact ⟨g, hg, Or.inl ⟨h2, h1, h3⟩⟩ · exact ⟨g, hg, Or.inr ⟨h2, h1, h3⟩⟩ /-- A match of ordered pairs none of whose isometries (of either pairing) has `T` points in its domain. -/ def PoorP (B : Finset ℂ) (T : ℝ) (a b c d : ℂ) : Prop := ¬ Expl B T a b c d ∧ ¬ Expl B T a b d c theorem poorP_swap1 {B : Finset ℂ} {T : ℝ} {a b c d : ℂ} (h : PoorP B T a b c d) : PoorP B T b a c d := ⟨fun he => h.2 (expl_swap he), fun he => h.1 (expl_swap he)⟩ theorem poorP_swap2 {B : Finset ℂ} {T : ℝ} {a b c d : ℂ} (h : PoorP B T a b c d) : PoorP B T a b d c := ⟨h.2, h.1⟩ open Classical in /-- The matches `(r, r', m)` of pairs of main rows that satisfy `Bd`. -/ noncomputable def RMB (v : ℕ → ℂ) (n L : ℕ) (Bd : (ℕ × Finset ℕ × Bool) → (ℕ × Finset ℕ × Bool) → ℕ × ℕ → Prop) : Finset ((ℕ × Finset ℕ × Bool) × (ℕ × Finset ℕ × Bool) × (ℕ × ℕ)) := ((Rws v n L) ×ˢ (Rws v n L)).biUnion (fun rr => ((ms v rr.1 rr.2).filter (Bd rr.1 rr.2)).image (fun m => (rr.1, rr.2, m))) theorem mem_RMB {v : ℕ → ℂ} {n L : ℕ} {Bd : (ℕ × Finset ℕ × Bool) → (ℕ × Finset ℕ × Bool) → ℕ × ℕ → Prop} {x : (ℕ × Finset ℕ × Bool) × (ℕ × Finset ℕ × Bool) × (ℕ × ℕ)} : x ∈ RMB v n L Bd ↔ x.1 ∈ Rws v n L ∧ x.2.1 ∈ Rws v n L ∧ x.2.2 ∈ ms v x.1 x.2.1 ∧ Bd x.1 x.2.1 x.2.2 := by classical unfold RMB constructor · intro hx obtain ⟨rr, hrr, hx2⟩ := mem_biUnion.mp hx obtain ⟨m, hm, rfl⟩ := mem_image.mp hx2 obtain ⟨h1, h2⟩ := mem_filter.mp hm exact ⟨(mem_product.mp hrr).1, (mem_product.mp hrr).2, h1, h2⟩ · rintro ⟨h1, h2, h3, h4⟩ exact mem_biUnion.mpr ⟨(x.1, x.2.1), mem_product.mpr ⟨h1, h2⟩, mem_image.mpr ⟨x.2.2, mem_filter.mpr ⟨h3, h4⟩, rfl⟩⟩ open Classical in /-- The contribution of the rich Ivory windows. -/ noncomputable def conicSum (v : ℕ → ℂ) (n G : ℕ) (T' : ℝ) : ℝ := ∑ w ∈ Wins n G, if ConicRich v n T' w then ((wsol v n w).card : ℝ) else 0 open Classical in /-- **Matches that are neither explained nor radius-swap configurations.** -/ theorem rm_bad_bound {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L G : ℕ) {T T' : ℝ} (hTT : T ≤ T') (hT3 : 3 ≤ T') : ((RMB v n L (fun r r' m => ¬ Expl (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v r.1) (v m.1) (v r'.1) (v m.2))).card : ℝ) ≤ 3 * (2 * ((n / G : ℕ) : ℝ) + 1) * ((Rws v n L).card : ℝ) ^ 2 + 4 * (((16 * L : ℕ) : ℝ) ^ 2 * (T' * ((Wins n G).card : ℝ) + conicSum v n G T')) := by obtain ⟨Bd, hBd⟩ : ∃ Bd : (ℕ × Finset ℕ × Bool) → (ℕ × Finset ℕ × Bool) → ℕ × ℕ → Prop, Bd = fun r r' m => ¬ Expl (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v r.1) (v m.1) (v r'.1) (v m.2) := ⟨_, rfl⟩ rw [← hBd] obtain ⟨Rel, hRel⟩ : ∃ Rel : (ℕ × Finset ℕ × Bool) × (ℕ × Finset ℕ × Bool) → Finset (ℕ × ℕ) → Prop, Rel = fun rr w => w ⊆ ms v rr.1 rr.2 ∧ ∃ m ∈ w, m ∈ (ms v rr.1 rr.2).filter (Bd rr.1 rr.2) := ⟨_, rfl⟩ -- step 1: sum over row pairs have h1 : (RMB v n L Bd).card ≤ ∑ rr ∈ (Rws v n L) ×ˢ (Rws v n L), ((ms v rr.1 rr.2).filter (Bd rr.1 rr.2)).card := by unfold RMB exact le_trans card_biUnion_le (sum_le_sum (fun rr _ => card_image_le)) -- step 2: cells and windows for each row pair have h2 : ∀ rr ∈ (Rws v n L) ×ˢ (Rws v n L), ((ms v rr.1 rr.2).filter (Bd rr.1 rr.2)).card ≤ 3 * (2 * (n / G) + 1) + 4 * (bipartiteAbove Rel (Wins n G) rr).card := by intro rr hrr obtain ⟨a1, a2⟩ := mem_product.mp hrr have ok1 := Rws_ok hccw hinj L rr.1 a1 have ok2 := Rws_ok hccw hinj L rr.2 a2 have := cell_split (G := G) ok1.1 ok2.1 ok1.2.2 ok2.2.2 (A := (ms v rr.1 rr.2).filter (Bd rr.1 rr.2)) (filter_subset _ _) unfold bipartiteAbove rw [hRel] convert this using 4 ext w simp only [mem_filter] have h3 : ∑ rr ∈ (Rws v n L) ×ˢ (Rws v n L), ((ms v rr.1 rr.2).filter (Bd rr.1 rr.2)).card ≤ 3 * (2 * (n / G) + 1) * (Rws v n L).card ^ 2 + 4 * ∑ rr ∈ (Rws v n L) ×ˢ (Rws v n L), (bipartiteAbove Rel (Wins n G) rr).card := by refine le_trans (sum_le_sum h2) ?_ rw [sum_add_distrib, sum_const, card_product, smul_eq_mul, ← mul_sum] nlinarith rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow] at h3 -- step 3: each window have h4 : ∀ w ∈ Wins n G, ((bipartiteBelow Rel ((Rws v n L) ×ˢ (Rws v n L)) w).card : ℝ) ≤ ((16 * L : ℕ) : ℝ) ^ 2 * (T' + if ConicRich v n T' w then ((wsol v n w).card : ℝ) else 0) := by intro w hw refine le_trans ?_ (window_pairs_bound hccw hinj L G hTT hT3 hw) have hsub : bipartiteBelow Rel ((Rws v n L) ×ˢ (Rws v n L)) w ⊆ ((Rws v n L) ×ˢ (Rws v n L)).filter (fun rr => w ⊆ ms v rr.1 rr.2 ∧ ∃ m ∈ w, ¬ Expl (pts v n) T (v rr.1.1) (v m.1) (v rr.2.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v rr.1.1) (v m.1) (v rr.2.1) (v m.2)) := by intro rr hrr unfold bipartiteBelow at hrr obtain ⟨hr1, hr2⟩ := mem_filter.mp hrr rw [hRel] at hr2 obtain ⟨hsubw, m, hm, hmA⟩ := hr2 have := (mem_filter.mp hmA).2 rw [hBd] at this exact mem_filter.mpr ⟨hr1, hsubw, m, hm, this⟩ exact_mod_cast card_le_card hsub have h5 : ((∑ w ∈ Wins n G, (bipartiteBelow Rel ((Rws v n L) ×ˢ (Rws v n L)) w).card : ℕ) : ℝ) ≤ ((16 * L : ℕ) : ℝ) ^ 2 * (T' * ((Wins n G).card : ℝ) + conicSum v n G T') := by rw [Nat.cast_sum] refine le_trans (sum_le_sum h4) (le_of_eq ?_) unfold conicSum rw [← mul_sum, sum_add_distrib, sum_const, nsmul_eq_mul] ring have h6 : ((RMB v n L Bd).card : ℝ) ≤ ((3 * (2 * (n / G) + 1) * (Rws v n L).card ^ 2 + 4 * ∑ w ∈ Wins n G, (bipartiteBelow Rel ((Rws v n L) ×ˢ (Rws v n L)) w).card : ℕ) : ℝ) := by exact_mod_cast le_trans h1 h3 rw [Nat.cast_sum] at h5 push_cast at h6 linarith end E94S /-! ### SOLO slice B1f -/ /-! ## SOLO module B (part 1f): poor quadruples in terms of windows, circle configurations and the tail -/ namespace E94S open Finset open Classical in /-- The poorly explained radius-swap configurations among the points of `B`. -/ noncomputable def simBad (B : Finset ℂ) (T T' : ℝ) : Finset (ℂ × ℂ × ℂ × ℂ) := (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q => dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ SimCfg B T' q.1 q.2.1 q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1) open Classical in /-- **Matches that are radius-swap configurations with a poor swap isometry.** -/ theorem rm_sim_bound {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L : ℕ) (T T' : ℝ) : (RMB v n L (fun r r' m => SimCfg (pts v n) T' (v r.1) (v m.1) (v r'.1) (v m.2) ∧ ¬ Expl (pts v n) T (v r.1) (v m.1) (v m.2) (v r'.1))).card ≤ (16 * L) ^ 2 * (simBad (pts v n) T T').card := by obtain ⟨S, hS⟩ : ∃ S : Finset ((ℕ × Finset ℕ × Bool) × (ℕ × Finset ℕ × Bool) × (ℕ × ℕ)), S = RMB v n L (fun r r' m => SimCfg (pts v n) T' (v r.1) (v m.1) (v r'.1) (v m.2) ∧ ¬ Expl (pts v n) T (v r.1) (v m.1) (v m.2) (v r'.1)) := ⟨_, rfl⟩ rw [← hS] have hmem : ∀ x ∈ S, x.1 ∈ Rws v n L ∧ x.2.1 ∈ Rws v n L ∧ x.2.2 ∈ ms v x.1 x.2.1 ∧ SimCfg (pts v n) T' (v x.1.1) (v x.2.2.1) (v x.2.1.1) (v x.2.2.2) ∧ ¬ Expl (pts v n) T (v x.1.1) (v x.2.2.1) (v x.2.2.2) (v x.2.1.1) := by intro x hx rw [hS] at hx exact mem_RMB.mp hx have hlab : ∀ x ∈ S, x.1.1 < n ∧ x.2.2.1 < n ∧ x.2.1.1 < n ∧ x.2.2.2 < n := by intro x hx obtain ⟨h1, h2, h3, _⟩ := hmem x hx have ok1 := Rws_ok hccw hinj L x.1 h1 have ok2 := Rws_ok hccw hinj L x.2.1 h2 obtain ⟨⟨m1, m2⟩, _⟩ := mem_ms.mp h3 exact ⟨ok1.2.1, ok1.2.2 _ m1, ok2.2.1, ok2.2.2 _ m2⟩ have h1 := card_le_mul_card_image (f := fun x : (ℕ × Finset ℕ × Bool) × (ℕ × Finset ℕ × Bool) × (ℕ × ℕ) => (v x.1.1, v x.2.2.1, v x.2.1.1, v x.2.2.2)) S ((16 * L) ^ 2) (by intro b hb obtain ⟨x0, hx0, rfl⟩ := mem_image.mp hb have l0 := hlab x0 hx0 have hsub : S.filter (fun x => (v x.1.1, v x.2.2.1, v x.2.1.1, v x.2.2.2) = (v x0.1.1, v x0.2.2.1, v x0.2.1.1, v x0.2.2.2)) ⊆ (((Rws v n L).filter (fun r => r.1 = x0.1.1)) ×ˢ ((Rws v n L).filter (fun r => r.1 = x0.2.1.1))).image (fun rr => (rr.1, rr.2, x0.2.2)) := by intro x hx obtain ⟨hxS, hxe⟩ := mem_filter.mp hx have lx := hlab x hxS simp only [Prod.mk.injEq] at hxe obtain ⟨e1, e2, e3, e4⟩ := hxe have f1 := hinj _ lx.1 _ l0.1 e1 have f2 := hinj _ lx.2.1 _ l0.2.1 e2 have f3 := hinj _ lx.2.2.1 _ l0.2.2.1 e3 have f4 := hinj _ lx.2.2.2 _ l0.2.2.2 e4 obtain ⟨a1, a2, _⟩ := hmem x hxS refine mem_image.mpr ⟨(x.1, x.2.1), mem_product.mpr ⟨mem_filter.mpr ⟨a1, f1⟩, mem_filter.mpr ⟨a2, f3⟩⟩, ?_⟩ exact Prod.ext rfl (Prod.ext rfl (Prod.ext f2.symm f4.symm)) refine le_trans (card_le_card hsub) (le_trans card_image_le ?_) rw [card_product, sq] exact Nat.mul_le_mul (Rws_pole hccw hinj L _) (Rws_pole hccw hinj L _)) refine le_trans h1 (Nat.mul_le_mul_left _ (card_le_card ?_)) intro b hb obtain ⟨x, hx, rfl⟩ := mem_image.mp hb obtain ⟨_, _, h3, h4, h5⟩ := hmem x hx have lx := hlab x hx unfold simBad refine mem_filter.mpr ⟨?_, (mem_ms.mp h3).2, h4, h5⟩ simp only [mem_product] exact ⟨mem_pts lx.1, mem_pts lx.2.1, mem_pts lx.2.2.1, mem_pts lx.2.2.2⟩ open Classical in /-- **Main poor quadruples are poor matches of main rows** (up to the four orientations). -/ theorem main_to_rm {v : ℕ → ℂ} {n : ℕ} (L : ℕ) (T : ℝ) : ((Qd v n).filter (fun q => (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2) ∧ PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card ≤ 4 * (RMB v n L (fun r r' m => PoorP (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2))).card := by have key := card_le_of_rel ((Qd v n).filter (fun q => (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2) ∧ PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))) ((RMB v n L (fun r r' m => PoorP (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2))) ×ˢ ((univ : Finset Bool) ×ˢ (univ : Finset Bool))) (fun q β => (if β.2.1 then (q.1, q.2.1) = (β.1.1.1, β.1.2.2.1) else (q.2.1, q.1) = (β.1.1.1, β.1.2.2.1)) ∧ (if β.2.2 then (q.2.2.1, q.2.2.2) = (β.1.2.1.1, β.1.2.2.2) else (q.2.2.2, q.2.2.1) = (β.1.2.1.1, β.1.2.2.2))) (by intro q hq obtain ⟨hQ, ⟨hM1, hM2⟩, hpoor⟩ := mem_filter.mp hq obtain ⟨_, _, _, hd⟩ := mem_Qd.mp hQ obtain ⟨r, hr, hc⟩ := mainP_iff.mp hM1 obtain ⟨r', hr', hc'⟩ := mainP_iff.mp hM2 rcases hc with ⟨e1, e2⟩ | ⟨e1, e2⟩ <;> rcases hc' with ⟨f1, f2⟩ | ⟨f1, f2⟩ · refine ⟨((r, r', (q.2.1, q.2.2.2)), true, true), ?_, by simp [e1, f1]⟩ refine mem_product.mpr ⟨mem_RMB.mpr ⟨hr, hr', mem_ms.mpr ⟨⟨e2, f2⟩, ?_⟩, ?_⟩, by simp⟩ · simp only; rw [e1, f1]; exact hd · simp only; rw [e1, f1]; exact hpoor · refine ⟨((r, r', (q.2.1, q.2.2.1)), true, false), ?_, by simp [e1, f1]⟩ refine mem_product.mpr ⟨mem_RMB.mpr ⟨hr, hr', mem_ms.mpr ⟨⟨e2, f2⟩, ?_⟩, ?_⟩, by simp⟩ · simp only; rw [e1, f1, hd]; exact dq_comm _ _ · simp only; rw [e1, f1]; exact poorP_swap2 hpoor · refine ⟨((r, r', (q.1, q.2.2.2)), false, true), ?_, by simp [e1, f1]⟩ refine mem_product.mpr ⟨mem_RMB.mpr ⟨hr, hr', mem_ms.mpr ⟨⟨e2, f2⟩, ?_⟩, ?_⟩, by simp⟩ · simp only; rw [e1, f1, ← hd]; exact dq_comm _ _ · simp only; rw [e1, f1]; exact poorP_swap1 hpoor · refine ⟨((r, r', (q.1, q.2.2.1)), false, false), ?_, by simp [e1, f1]⟩ refine mem_product.mpr ⟨mem_RMB.mpr ⟨hr, hr', mem_ms.mpr ⟨⟨e2, f2⟩, ?_⟩, ?_⟩, by simp⟩ · simp only; rw [e1, f1, dq_comm (v q.2.1) (v q.1), hd]; exact dq_comm _ _ · simp only; rw [e1, f1]; exact poorP_swap2 (poorP_swap1 hpoor)) (by intro q _ q' _ β _ hR hR' obtain ⟨a, b, c, d⟩ := q obtain ⟨a', b', c', d'⟩ := q' simp only at hR hR' have hab : a = a' ∧ b = b' := by by_cases hb : β.2.1 · rw [if_pos hb] at hR hR' have := hR.1.trans hR'.1.symm exact ⟨(Prod.mk.inj this).1, (Prod.mk.inj this).2⟩ · rw [if_neg hb] at hR hR' have := hR.1.trans hR'.1.symm exact ⟨(Prod.mk.inj this).2, (Prod.mk.inj this).1⟩ have hcd : c = c' ∧ d = d' := by by_cases hb : β.2.2 · rw [if_pos hb] at hR hR' have := hR.2.trans hR'.2.symm exact ⟨(Prod.mk.inj this).1, (Prod.mk.inj this).2⟩ · rw [if_neg hb] at hR hR' have := hR.2.trans hR'.2.symm exact ⟨(Prod.mk.inj this).2, (Prod.mk.inj this).1⟩ rw [hab.1, hab.2, hcd.1, hcd.2]) rw [card_product, card_product] at key simp only [card_univ, Fintype.card_bool] at key omega open Classical in /-- **Poor quadruples: the pre-RIT inequality.** -/ theorem poor_bound {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L G : ℕ) {T T' : ℝ} (hTT : T ≤ T') (hT3 : 3 ≤ T') : (((Qd v n).filter (fun q => PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card : ℝ) ≤ 8192 * (7 / 8) ^ L * (n : ℝ) ^ 3 + 4 * (3 * (2 * ((n / G : ℕ) : ℝ) + 1) * ((Rws v n L).card : ℝ) ^ 2 + 4 * (((16 * L : ℕ) : ℝ) ^ 2 * (T' * ((Wins n G).card : ℝ) + conicSum v n G T')) + ((16 * L : ℕ) : ℝ) ^ 2 * ((simBad (pts v n) T T').card : ℝ)) := by have htail := tail_bound hccw hinj L have hbad := rm_bad_bound hccw hinj L G hTT hT3 have hsim := rm_sim_bound hccw hinj L T T' have hmain := main_to_rm (v := v) (n := n) L T -- poor matches are bad or radius-swap have hsplit : (RMB v n L (fun r r' m => PoorP (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2))).card ≤ (RMB v n L (fun r r' m => ¬ Expl (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v r.1) (v m.1) (v r'.1) (v m.2))).card + (RMB v n L (fun r r' m => SimCfg (pts v n) T' (v r.1) (v m.1) (v r'.1) (v m.2) ∧ ¬ Expl (pts v n) T (v r.1) (v m.1) (v m.2) (v r'.1))).card := by refine le_trans (card_le_card ?_) (card_union_le _ _) intro x hx obtain ⟨h1, h2, h3, h4⟩ := mem_RMB.mp hx by_cases hs : SimCfg (pts v n) T' (v x.1.1) (v x.2.2.1) (v x.2.1.1) (v x.2.2.2) · exact mem_union_right _ (mem_RMB.mpr ⟨h1, h2, h3, hs, h4.2⟩) · exact mem_union_left _ (mem_RMB.mpr ⟨h1, h2, h3, h4.1, hs⟩) -- poor quadruples are in the tail or main have hq : ((Qd v n).filter (fun q => PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card ≤ ((Qd v n).filter (fun q => ¬ (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2))).card + ((Qd v n).filter (fun q => (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2) ∧ PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card := by refine le_trans (card_le_card ?_) (card_union_le _ _) intro q hq obtain ⟨h1, h2⟩ := mem_filter.mp hq by_cases hm : MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2 · exact mem_union_right _ (mem_filter.mpr ⟨h1, hm, h2⟩) · exact mem_union_left _ (mem_filter.mpr ⟨h1, hm⟩) have c1 : (((Qd v n).filter (fun q => PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card : ℝ) ≤ (((Qd v n).filter (fun q => ¬ (MainP v n L q.1 q.2.1 ∧ MainP v n L q.2.2.1 q.2.2.2))).card : ℝ) + 4 * ((RMB v n L (fun r r' m => PoorP (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2))).card : ℝ) := by have := le_trans hq (Nat.add_le_add_left hmain _) exact_mod_cast this have c2 : ((RMB v n L (fun r r' m => PoorP (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2))).card : ℝ) ≤ ((RMB v n L (fun r r' m => ¬ Expl (pts v n) T (v r.1) (v m.1) (v r'.1) (v m.2) ∧ ¬ SimCfg (pts v n) T' (v r.1) (v m.1) (v r'.1) (v m.2))).card : ℝ) + ((16 * L : ℕ) : ℝ) ^ 2 * ((simBad (pts v n) T T').card : ℝ) := by have := le_trans hsplit (Nat.add_le_add_left hsim _) exact_mod_cast this linarith end E94S /-! ### SOLO slice B5a -/ /-! ## SOLO module B (part 5a): the radius-swap count in closed form -/ namespace E94S open Finset theorem two_choose_two (t : ℕ) : 2 * (t + 2).choose 2 = (t + 2) * (t + 1) := by induction t with | zero => decide | succ t ih => have h := Nat.choose_succ_succ (t + 2) 1 have h1 : (t + 2).choose 1 = t + 2 := Nat.choose_one_right _ have e : (t + 1 + 2).choose 2 = (t + 2).choose 1 + (t + 2).choose 2 := h rw [e, h1] nlinarith [ih] theorem six_choose_three (t : ℕ) : 6 * (t + 3).choose 3 = (t + 3) * (t + 2) * (t + 1) := by induction t with | zero => decide | succ t ih => have e : (t + 1 + 3).choose 3 = (t + 3).choose 2 + (t + 3).choose 3 := Nat.choose_succ_succ (t + 3) 2 have h2 := two_choose_two (t + 1) rw [e] nlinarith [ih, h2] theorem six_choose_three_le (n : ℕ) : 6 * n.choose 3 ≤ n ^ 3 := by rcases Nat.lt_or_ge n 3 with h | h · have : n.choose 3 = 0 := Nat.choose_eq_zero_of_lt h rw [this]; simp · obtain ⟨t, rfl⟩ : ∃ t, n = t + 3 := ⟨n - 3, by omega⟩ rw [six_choose_three] nlinarith [Nat.zero_le t] open Classical in /-- **Radius-swap count, closed form.** With `T' ≥ 6`: `|simBad| ≤ 128·T·|B|⁸ / T'⁶`. -/ theorem simBad_le {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {T T' : ℝ} (hT : 0 ≤ T) (hT' : 6 ≤ T') : ((simBad B T T').card : ℝ) * T' ^ 6 ≤ 128 * T * (B.card : ℝ) ^ 8 := by obtain ⟨t, ht⟩ : ∃ t : ℕ, t = ⌊T'⌋₊ := ⟨_, rfl⟩ have hT'0 : (0 : ℝ) ≤ T' := by linarith have ht1 : (t : ℝ) ≤ T' := by rw [ht]; exact Nat.floor_le hT'0 have ht2 : T' < (t : ℝ) + 1 := by rw [ht]; exact Nat.lt_floor_add_one T' have ht3 : 3 ≤ t := by have : (5 : ℝ) < (t : ℝ) := by linarith have : 5 < t := by exact_mod_cast this omega have hsub : simBad B T T' ⊆ (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 ∧ SimCfg B (t : ℝ) q.1 q.2.1 q.2.2.1 q.2.2.2 ∧ ¬ Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1) := by intro q hq unfold simBad at hq obtain ⟨h1, h2, h3, h4⟩ := mem_filter.mp hq exact mem_filter.mpr ⟨h1, h2, simCfg_mono ht1 h3, h4⟩ have hcount := sim_count hnc hT ht3 have h1 : ((simBad B T T').card : ℝ) * ((t.choose 3 : ℕ) : ℝ) ^ 2 ≤ 2 * T * (B.card : ℝ) ^ 2 * ((B.card.choose 3 : ℕ) : ℝ) ^ 2 := by refine le_trans (mul_le_mul_of_nonneg_right ?_ (by positivity)) hcount exact_mod_cast card_le_card hsub -- 6·C(t,3) ≥ (T'/2)³ and 6·C(|B|,3) ≤ |B|³ obtain ⟨s, rfl⟩ : ∃ s, t = s + 3 := ⟨t - 3, by omega⟩ have e1 : (6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ) = ((s : ℝ) + 3) * ((s : ℝ) + 2) * ((s : ℝ) + 1) := by have := six_choose_three s exact_mod_cast this have e2 : (6 : ℝ) * ((B.card.choose 3 : ℕ) : ℝ) ≤ (B.card : ℝ) ^ 3 := by have := six_choose_three_le B.card exact_mod_cast this have hs0 : (0 : ℝ) ≤ (s : ℝ) := Nat.cast_nonneg s push_cast at ht1 ht2 have hhalf : T' / 2 ≤ (s : ℝ) + 1 := by linarith have hhalf0 : (0 : ℝ) ≤ T' / 2 := by linarith have e3 : (T' / 2) ^ 3 ≤ (6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ) := by rw [e1] have a1 : (T' / 2) ^ 3 ≤ ((s : ℝ) + 1) ^ 3 := pow_le_pow_left₀ hhalf0 hhalf 3 nlinarith [mul_nonneg hs0 hs0, mul_nonneg (mul_nonneg hs0 hs0) hs0] have hc0 : (0 : ℝ) ≤ (((s + 3).choose 3 : ℕ) : ℝ) := Nat.cast_nonneg _ have hb0 : (0 : ℝ) ≤ ((B.card.choose 3 : ℕ) : ℝ) := Nat.cast_nonneg _ have hsb0 : (0 : ℝ) ≤ ((simBad B T T').card : ℝ) := Nat.cast_nonneg _ have hB0 : (0 : ℝ) ≤ (B.card : ℝ) := Nat.cast_nonneg _ have e4 : ((T' / 2) ^ 3) ^ 2 ≤ ((6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ)) ^ 2 := pow_le_pow_left₀ (by positivity) e3 2 have e5 : ((6 : ℝ) * ((B.card.choose 3 : ℕ) : ℝ)) ^ 2 ≤ ((B.card : ℝ) ^ 3) ^ 2 := pow_le_pow_left₀ (by positivity) e2 2 have f1 : ((simBad B T T').card : ℝ) * ((T' / 2) ^ 3) ^ 2 ≤ ((simBad B T T').card : ℝ) * ((6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ)) ^ 2 := mul_le_mul_of_nonneg_left e4 hsb0 have f2 : ((simBad B T T').card : ℝ) * ((6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ)) ^ 2 ≤ 2 * T * (B.card : ℝ) ^ 2 * ((6 : ℝ) * ((B.card.choose 3 : ℕ) : ℝ)) ^ 2 := by nlinarith [h1] have f3 : 2 * T * (B.card : ℝ) ^ 2 * ((6 : ℝ) * ((B.card.choose 3 : ℕ) : ℝ)) ^ 2 ≤ 2 * T * (B.card : ℝ) ^ 2 * ((B.card : ℝ) ^ 3) ^ 2 := mul_le_mul_of_nonneg_left e5 (by positivity) have f4 : ((simBad B T T').card : ℝ) * ((T' / 2) ^ 3) ^ 2 = ((simBad B T T').card : ℝ) * T' ^ 6 / 64 := by ring have f5 : 2 * T * (B.card : ℝ) ^ 2 * ((B.card : ℝ) ^ 3) ^ 2 = 2 * T * (B.card : ℝ) ^ 8 := by ring rw [f4] at f1 rw [f5] at f3 linarith end E94S /-! ### SOLO slice B5b -/ /-! ## SOLO module B (part 5b): the rich-isometry theorem (RIT), assuming the Ivory count -/ namespace E94S open Finset /-- The Ivory count: rich non-similarity windows carry `O(n²)` pole pairs in total. -/ def ConicBound : Prop := ∀ τ' : ℝ, 0 < τ' → ∀ G : ℕ, 0 < G → ∃ C : ℝ, ∃ n₁ : ℕ, ∀ n ≥ n₁, ∀ v : ℕ → ℂ, Ccw v n → (∀ i < n, ∀ j < n, v i = v j → i = j) → conicSum v n G (τ' * n) ≤ C * (n : ℝ) ^ 2 theorem pts_card {v : ℕ → ℂ} {n : ℕ} (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) : (pts v n).card = n := by unfold pts rw [card_image_of_injOn, card_range] intro i hi j hj h exact hinj i (mem_range.mp hi) j (mem_range.mp hj) h theorem pts_nc {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) : ∀ a ∈ pts v n, ∀ b ∈ pts v n, ∀ c ∈ pts v n, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0 := by intro a ha b hb c hc hab hac hbc unfold pts at ha hb hc obtain ⟨i, hi, rfl⟩ := mem_image.mp ha obtain ⟨j, hj, rfl⟩ := mem_image.mp hb obtain ⟨k, hk, rfl⟩ := mem_image.mp hc exact ccw_cr3_ne hccw (mem_range.mp hi) (mem_range.mp hj) (mem_range.mp hk) (fun h => hab (by rw [h])) (fun h => hac (by rw [h])) (fun h => hbc (by rw [h])) theorem rit_t2 {ε M G n k u R2 : ℝ} (hG0 : 0 < G) (hGr : 180 * M ≤ ε * G) (huG : u * G = n) (hk0 : 0 ≤ k) (hkle : k ≤ u) (hNG : 1 ≤ u) (hR20 : 0 ≤ R2) (hR2 : R2 ≤ M * n ^ 2) (hn : 0 < n) : 4 * (3 * (2 * k + 1) * R2) ≤ ε / 5 * n ^ 3 := by have a : (2 * k + 1) * R2 ≤ 3 * u * (M * n ^ 2) := mul_le_mul (by linarith) hR2 hR20 (by linarith) have b : 3 * u * (M * n ^ 2) * G = 3 * M * n ^ 3 := by have : 3 * u * (M * n ^ 2) * G = 3 * M * n ^ 2 * (u * G) := by ring rw [this, huG]; ring have hn3 : 0 < n ^ 3 := by positivity have c : 36 * M * n ^ 3 ≤ ε / 5 * G * n ^ 3 := mul_le_mul_of_nonneg_right (by linarith) hn3.le have d : 4 * (3 * (2 * k + 1) * R2) * G ≤ ε / 5 * n ^ 3 * G := by have e1 : 4 * (3 * (2 * k + 1) * R2) * G = 12 * ((2 * k + 1) * R2 * G) := by ring have e2 : (2 * k + 1) * R2 * G ≤ 3 * u * (M * n ^ 2) * G := mul_le_mul_of_nonneg_right a hG0.le rw [b] at e2 rw [e1] linarith exact le_of_mul_le_mul_right d hG0 theorem rit_t3 {ε M G n τ' W : ℝ} (hε : 0 < ε) (hM0 : 0 ≤ M) (hG0 : 0 < G) (hτ'eq : τ' * (320 * (M + 1) * G ^ 6) = ε) (hτ' : 0 < τ') (hn : 0 < n) (hW2 : W ≤ 4 * n ^ 2 * G ^ 6) : 4 * (4 * (M * (τ' * n * W))) ≤ ε / 5 * n ^ 3 := by have a : 64 * M * τ' * G ^ 6 * (5 * (M + 1)) = M * ε := by rw [← hτ'eq]; ring have b : 64 * M * τ' * G ^ 6 ≤ ε / 5 := by have h1 : 64 * M * τ' * G ^ 6 * (5 * (M + 1)) ≤ ε / 5 * (5 * (M + 1)) := by rw [a]; nlinarith exact le_of_mul_le_mul_right h1 (by positivity) have c : τ' * n * W ≤ τ' * n * (4 * n ^ 2 * G ^ 6) := mul_le_mul_of_nonneg_left hW2 (by positivity) have d : 4 * (4 * (M * (τ' * n * W))) ≤ 16 * (M * (τ' * n * (4 * n ^ 2 * G ^ 6))) := by have := mul_le_mul_of_nonneg_left c hM0 linarith have e : 16 * (M * (τ' * n * (4 * n ^ 2 * G ^ 6))) = 64 * M * τ' * G ^ 6 * n ^ 3 := by ring have hn3 : 0 < n ^ 3 := by positivity have f : 64 * M * τ' * G ^ 6 * n ^ 3 ≤ ε / 5 * n ^ 3 := mul_le_mul_of_nonneg_right b hn3.le linarith theorem rit_t4 {ε M n C cs : ℝ} (hM0 : 0 ≤ M) (hn : 0 < n) (hcs : cs ≤ C * n ^ 2) (hnC : 80 * (M + 1) * (|C| + 1) ≤ ε * n) : 4 * (4 * (M * cs)) ≤ ε / 5 * n ^ 3 := by have h1 : cs ≤ |C| * n ^ 2 := le_trans hcs (mul_le_mul_of_nonneg_right (le_abs_self C) (by positivity)) have h2 : 16 * M * |C| ≤ ε / 5 * n := by nlinarith [abs_nonneg C, mul_nonneg hM0 (abs_nonneg C)] have h3 : 16 * M * |C| * n ^ 2 ≤ ε / 5 * n * n ^ 2 := mul_le_mul_of_nonneg_right h2 (by positivity) have h4 : M * cs ≤ M * (|C| * n ^ 2) := mul_le_mul_of_nonneg_left h1 hM0 have e : ε / 5 * n * n ^ 2 = ε / 5 * n ^ 3 := by ring linarith theorem rit_t5 {ε M n τ τ' sb : ℝ} (hM0 : 0 ≤ M) (hτ' : 0 < τ') (hτ : 0 < τ) (hn : 0 < n) (hτ2 : τ * (2560 * (M + 1)) ≤ ε * τ' ^ 6) (hsb2 : sb * τ' ^ 6 ≤ 128 * τ * n ^ 3) : 4 * (M * sb) ≤ ε / 5 * n ^ 3 := by have hτ6 : (0 : ℝ) < τ' ^ 6 := by positivity have hn3 : 0 < n ^ 3 := by positivity have h1 : M * (sb * τ' ^ 6) ≤ M * (128 * τ * n ^ 3) := mul_le_mul_of_nonneg_left hsb2 hM0 have h2 : 512 * M * τ ≤ ε / 5 * τ' ^ 6 := by nlinarith [mul_nonneg hM0 hτ.le] have h3 : 512 * M * τ * n ^ 3 ≤ ε / 5 * τ' ^ 6 * n ^ 3 := mul_le_mul_of_nonneg_right h2 hn3.le have h4 : 4 * (M * sb) * τ' ^ 6 ≤ ε / 5 * n ^ 3 * τ' ^ 6 := by have e1 : 4 * (M * sb) * τ' ^ 6 = 4 * (M * (sb * τ' ^ 6)) := by ring rw [e1] linarith exact le_of_mul_le_mul_right h4 hτ6 theorem Rws_sq_le {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (L : ℕ) : ((Rws v n L).card : ℝ) ^ 2 ≤ ((16 * L : ℕ) : ℝ) ^ 2 * (n : ℝ) ^ 2 := by have hR : ((Rws v n L).card : ℝ) ≤ ((16 * L : ℕ) : ℝ) * n := by exact_mod_cast Rws_card hccw hinj L have h0 : (0 : ℝ) ≤ ((Rws v n L).card : ℝ) := Nat.cast_nonneg _ have := pow_le_pow_left₀ h0 hR 2 rw [mul_pow] at this exact this theorem Wins_le {n G : ℕ} (hG : 0 < G) (hnG : G ≤ n) : ((Wins n G).card : ℝ) ≤ 4 * (n : ℝ) ^ 2 * (G : ℝ) ^ 6 := by have hG0 : (0 : ℝ) < G := by exact_mod_cast hG have hW : ((Wins n G).card : ℝ) ≤ (((n / G : ℕ) : ℝ) + 1) ^ 2 * (G : ℝ) ^ 8 := by exact_mod_cast Wins_card n G hG have hk : ((n / G : ℕ) : ℝ) ≤ (n : ℝ) / G := Nat.cast_div_le have hk0 : (0 : ℝ) ≤ ((n / G : ℕ) : ℝ) := Nat.cast_nonneg _ have hu : 1 ≤ (n : ℝ) / G := by rw [le_div_iff₀ hG0] have : (G : ℝ) ≤ n := by exact_mod_cast hnG linarith have h1 : ((n / G : ℕ) : ℝ) + 1 ≤ 2 * ((n : ℝ) / G) := by linarith have h2 : (((n / G : ℕ) : ℝ) + 1) ^ 2 ≤ (2 * ((n : ℝ) / G)) ^ 2 := pow_le_pow_left₀ (by linarith) h1 2 have h3 : (((n / G : ℕ) : ℝ) + 1) ^ 2 * (G : ℝ) ^ 8 ≤ (2 * ((n : ℝ) / G)) ^ 2 * (G : ℝ) ^ 8 := mul_le_mul_of_nonneg_right h2 (by positivity) have h4 : (2 * ((n : ℝ) / G)) ^ 2 * (G : ℝ) ^ 8 = 4 * (n : ℝ) ^ 2 * (G : ℝ) ^ 6 := by field_simp ring linarith theorem simBad_n {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {τ τ' : ℝ} (hτ : 0 < τ) (hn : (0 : ℝ) < n) (hn6 : 6 ≤ τ' * (n : ℝ)) : ((simBad (pts v n) (τ * n) (τ' * n)).card : ℝ) * τ' ^ 6 ≤ 128 * τ * (n : ℝ) ^ 3 := by have hsb := simBad_le (B := pts v n) (pts_nc hccw) (T := τ * n) (T' := τ' * n) (by positivity) hn6 rw [pts_card hinj] at hsb have e1 : ((simBad (pts v n) (τ * n) (τ' * n)).card : ℝ) * (τ' * (n : ℝ)) ^ 6 = (((simBad (pts v n) (τ * n) (τ' * n)).card : ℝ) * τ' ^ 6) * (n : ℝ) ^ 6 := by ring have e2 : 128 * (τ * (n : ℝ)) * (n : ℝ) ^ 8 = (128 * τ * (n : ℝ) ^ 3) * (n : ℝ) ^ 6 := by ring rw [e1, e2] at hsb exact le_of_mul_le_mul_right hsb (by positivity) open Classical in /-- The core estimate behind RIT for fixed parameters. -/ theorem rit_core {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {ε M τ τ' C : ℝ} {L G : ℕ} (hε : 0 < ε) (hM : M = ((16 * L : ℕ) : ℝ) ^ 2) (hL : 8192 * (7 / 8 : ℝ) ^ L ≤ ε / 5) (hGpos : 0 < G) (hGr : 180 * M ≤ ε * (G : ℝ)) (hτ'pos : 0 < τ') (hτ'eq : τ' * (320 * (M + 1) * (G : ℝ) ^ 6) = ε) (hτpos : 0 < τ) (hττ' : τ ≤ τ') (hτ2 : τ * (2560 * (M + 1)) ≤ ε * τ' ^ 6) (hnG : G ≤ n) (hn6 : 6 ≤ τ' * (n : ℝ)) (hnC : 80 * (M + 1) * (|C| + 1) ≤ ε * (n : ℝ)) (hcs : conicSum v n G (τ' * n) ≤ C * (n : ℝ) ^ 2) : (((Qd v n).filter (fun q => PoorP (pts v n) (τ * n) (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card : ℝ) ≤ ε * (n : ℝ) ^ 3 := by have hM0 : 0 ≤ M := by rw [hM]; positivity have hG0 : (0 : ℝ) < G := by exact_mod_cast hGpos have hnGr : (G : ℝ) ≤ (n : ℝ) := by exact_mod_cast hnG have hN0 : (0 : ℝ) < n := lt_of_lt_of_le hG0 hnGr have hpb := poor_bound hccw hinj L G (T := τ * n) (T' := τ' * n) (mul_le_mul_of_nonneg_right hττ' hN0.le) (by linarith) rw [← hM] at hpb have hN3 : (0 : ℝ) < (n : ℝ) ^ 3 := by positivity have t1 : 8192 * (7 / 8 : ℝ) ^ L * (n : ℝ) ^ 3 ≤ ε / 5 * (n : ℝ) ^ 3 := mul_le_mul_of_nonneg_right hL hN3.le have hk : ((n / G : ℕ) : ℝ) ≤ (n : ℝ) / G := Nat.cast_div_le have hu1 : 1 ≤ (n : ℝ) / G := by rw [le_div_iff₀ hG0]; linarith have huG : (n : ℝ) / G * (G : ℝ) = n := by field_simp have hR2 : ((Rws v n L).card : ℝ) ^ 2 ≤ M * (n : ℝ) ^ 2 := by rw [hM]; exact Rws_sq_le hccw hinj L have t2 := rit_t2 (ε := ε) hG0 hGr huG (Nat.cast_nonneg (n / G)) hk hu1 (by positivity) hR2 hN0 have t3 := rit_t3 hε hM0 hG0 hτ'eq hτ'pos hN0 (Wins_le hGpos hnG) have t4 := rit_t4 hM0 hN0 hcs hnC have t5 := rit_t5 hM0 hτ'pos hτpos hN0 hτ2 (simBad_n hccw hinj hτpos hN0 hn6) linarith open Classical in /-- **RIT (rich-isometry theorem), modulo the Ivory count.** For every `ε > 0` there is `τ > 0` such that in every large counterclockwise polygon all but `εn³` of the ordered quadruples `(a, b, c, d)` with `|ab| = |cd|` are explained by an isometry (carrying `a, b` to `c, d` or to `d, c`) with at least `τn` vertices in its domain. -/ theorem rit_of_conic (hC : ConicBound) (ε : ℝ) (hε : 0 < ε) : ∃ τ : ℝ, 0 < τ ∧ ∃ n₀ : ℕ, ∀ n ≥ n₀, ∀ v : ℕ → ℂ, Ccw v n → (∀ i < n, ∀ j < n, v i = v j → i = j) → (((Qd v n).filter (fun q => PoorP (pts v n) (τ * n) (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card : ℝ) ≤ ε * (n : ℝ) ^ 3 := by obtain ⟨L, hL⟩ := exists_pow_lt_of_lt_one (show 0 < ε / 40960 by positivity) (show (7 / 8 : ℝ) < 1 by norm_num) obtain ⟨M, hM⟩ : ∃ M : ℝ, M = ((16 * L : ℕ) : ℝ) ^ 2 := ⟨_, rfl⟩ have hM0 : 0 ≤ M := by rw [hM]; positivity obtain ⟨G, hG⟩ : ∃ G : ℕ, G = ⌈180 * M / ε⌉₊ + 1 := ⟨_, rfl⟩ have hGpos : 0 < G := by omega have hG0 : (0 : ℝ) < G := by exact_mod_cast hGpos have hGr : 180 * M ≤ ε * (G : ℝ) := by have h1 : 180 * M / ε ≤ (G : ℝ) := by rw [hG]; push_cast linarith [Nat.le_ceil (180 * M / ε)] rw [div_le_iff₀ hε] at h1 linarith obtain ⟨τ', hτ'⟩ : ∃ τ' : ℝ, τ' = ε / (320 * (M + 1) * (G : ℝ) ^ 6) := ⟨_, rfl⟩ have hτ'pos : 0 < τ' := by rw [hτ']; positivity have hτ'eq : τ' * (320 * (M + 1) * (G : ℝ) ^ 6) = ε := by rw [hτ']; field_simp obtain ⟨C, n₁, hCn⟩ := hC τ' hτ'pos G hGpos obtain ⟨τ, hτ⟩ : ∃ τ : ℝ, τ = min τ' (ε * τ' ^ 6 / (2560 * (M + 1))) := ⟨_, rfl⟩ have hτpos : 0 < τ := by rw [hτ]; exact lt_min hτ'pos (by positivity) have hττ' : τ ≤ τ' := by rw [hτ]; exact min_le_left _ _ have hτ2 : τ * (2560 * (M + 1)) ≤ ε * τ' ^ 6 := by have : τ ≤ ε * τ' ^ 6 / (2560 * (M + 1)) := by rw [hτ]; exact min_le_right _ _ rw [le_div_iff₀ (by positivity)] at this exact this refine ⟨τ, hτpos, max (max n₁ G) (max ⌈6 / τ'⌉₊ ⌈80 * (M + 1) * (|C| + 1) / ε⌉₊), ?_⟩ intro n hn v hccw hinj have hn1 : n₁ ≤ n := le_trans (le_trans (le_max_left _ _) (le_max_left _ _)) hn have hnG : G ≤ n := le_trans (le_trans (le_max_right _ _) (le_max_left _ _)) hn have hn6' : ⌈6 / τ'⌉₊ ≤ n := le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) hn have hnC' : ⌈80 * (M + 1) * (|C| + 1) / ε⌉₊ ≤ n := le_trans (le_trans (le_max_right _ _) (le_max_right _ _)) hn have hn6 : 6 ≤ τ' * (n : ℝ) := by have h1 : 6 / τ' ≤ (n : ℝ) := le_trans (Nat.le_ceil _) (by exact_mod_cast hn6') rw [div_le_iff₀ hτ'pos] at h1 linarith have hnC : 80 * (M + 1) * (|C| + 1) ≤ ε * (n : ℝ) := by have h1 : 80 * (M + 1) * (|C| + 1) / ε ≤ (n : ℝ) := le_trans (Nat.le_ceil _) (by exact_mod_cast hnC') rw [div_le_iff₀ hε] at h1 linarith exact rit_core hccw hinj hε hM (by linarith) hGpos hGr hτ'pos hτ'eq hτpos hττ' hτ2 hnG hn6 hnC (hCn n hn1 v hccw hinj) end E94S /-! ### SOLO slice C1 -/ /-! ## SOLO module C (part 1): the sub-family with a common image point (from the steps of GLIDE Thm 15.5) -/ namespace E94S open Finset Erdos94ThmA theorem iapp_eq (g : ℂ × ℂ) (z : ℂ) : iapp g z = isoApp g z := rfl theorem idom_eq (B : Finset ℂ) (g : ℂ × ℂ) : idom B g = isoDom B g := rfl open Classical in /-- **GLIDE Theorem 15.5, steps (1)–(4), as a statement about a sub-family.** A family of `≥ κ₁N` proper isometries with `≥ κ₂N` points of `B` in each domain contains a sub-family of `≥ κ₂⁸/36` of it all of whose members send one point `z` to the same point. -/ theorem thm155_sub {κ₁ κ₂ : ℝ} (hκ₁ : 0 < κ₁) (hκ₂ : 0 < κ₂) {B : Finset ℂ} (hT : ∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) {Gs : Finset (ℂ × ℂ)} (hG : ∀ g ∈ Gs, ‖g.1‖ = 1) (hGc : κ₁ * B.card ≤ Gs.card) (hdom : ∀ g ∈ Gs, κ₂ * B.card ≤ (isoDom B g).card) {M : ℕ} (hN0 : (0 : ℝ) < B.card) (hNa : 4 < κ₁ * κ₂ ^ 4 * B.card) (hN8 : 8 ≤ κ₂ ^ 4 * B.card) (hNM : (M : ℝ) * M < B.card) (hM8 : 8 ≤ (M : ℝ) * κ₂ ^ 4) (hM9 : (M : ℝ) * κ₂ ^ 4 ≤ 9) : ∃ z : ℂ, ∃ Gs' : Finset (ℂ × ℂ), Gs' ⊆ Gs ∧ κ₂ ^ 8 * Gs.card / 36 ≤ Gs'.card ∧ ∀ g ∈ Gs', ∀ g' ∈ Gs', isoApp g z = isoApp g' z := by have hk2 : 0 < κ₂ ^ 2 := by positivity have hk4 : 0 < κ₂ ^ 4 := by positivity have hk10 : 0 < κ₂ ^ 10 := by positivity have hG4 : 4 ≤ κ₂ ^ 4 * Gs.card := by have h1 := mul_le_mul_of_nonneg_left hGc hk4.le have e : κ₂ ^ 4 * (κ₁ * B.card) = κ₁ * κ₂ ^ 4 * B.card := by ring linarith obtain ⟨h₀, hh₀, k₀, hk₀, hhk, hbig⟩ := step2_pair hT hG hκ₂ hN0 hG4 hN8 hdom obtain ⟨ψ, hψ⟩ : ∃ ψ : ℂ × ℂ, ψ = isoComp (isoInv h₀) k₀ := ⟨_, rfl⟩ rw [← hψ] at hbig have hψu : ‖ψ.1‖ = 1 := by rw [hψ]; exact isoComp_unit (isoInv_unit (hG h₀ hh₀)) (hG k₀ hk₀) have hψ1 : ψ.1 ≠ 1 := by intro h1 apply hhk rw [hψ] at h1 unfold isoComp isoInv at h1 simp only at h1 have := (unit_facts (hG h₀ hh₀)).1 linear_combination k₀.1 * this - h₀.1 * h1 have hmk := markov_big Gs (fun g => ((isoDom B (isoConj g ψ)).card : ℝ)) hN0 (by positivity : (0 : ℝ) ≤ κ₂ ^ 4 / 2) (fun g _ => by exact_mod_cast card_le_card (isoDom_sub B _)) (by linarith) obtain ⟨Gs₁, hGs₁⟩ : ∃ Gs₁ : Finset (ℂ × ℂ), Gs₁ = Gs.filter (fun g => κ₂ ^ 4 / 2 * (B.card : ℝ) / 2 ≤ ((isoDom B (isoConj g ψ)).card : ℝ)) := ⟨_, rfl⟩ have hGs₁c : κ₂ ^ 4 / 2 / 2 * (Gs.card : ℝ) ≤ Gs₁.card := by rw [hGs₁]; exact hmk have hGs₁sub : ∀ g ∈ Gs₁, g ∈ Gs ∧ κ₂ ^ 4 / 2 * (B.card : ℝ) / 2 ≤ ((isoDom B (isoConj g ψ)).card : ℝ) := by intro g hg; rw [hGs₁] at hg; exact mem_filter.mp hg have hGpos : (0 : ℝ) < Gs.card := by by_contra h; push_neg at h have : (Gs.card : ℝ) = 0 := le_antisymm h (Nat.cast_nonneg _) rw [this] at hG4; linarith have hGs₁ne : Gs₁.Nonempty := by have : (0 : ℝ) < Gs₁.card := lt_of_lt_of_le (by positivity) hGs₁c exact card_pos.mp (by exact_mod_cast this) have hMa : 2 * (B.card : ℝ) ≤ M * (κ₂ ^ 4 / 2 * (B.card : ℝ) / 2) := by have := mul_le_mul_of_nonneg_right hM8 hN0.le have e : (M : ℝ) * (κ₂ ^ 4 / 2 * (B.card : ℝ) / 2) = (M * κ₂ ^ 4) * B.card / 4 := by ring rw [e]; linarith obtain ⟨ψ', hψ'⟩ := step3_value hT (fun g hg => hG g (hGs₁sub g hg).1) hψu (M := M) (a := κ₂ ^ 4 / 2 * (B.card : ℝ) / 2) hMa hNM (fun g hg => (hGs₁sub g hg).2) hGs₁ne obtain ⟨Gs', hGs'⟩ : ∃ Gs' : Finset (ℂ × ℂ), Gs' = Gs₁.filter (fun g => isoConj g ψ = ψ') := ⟨_, rfl⟩ rw [← hGs'] at hψ' have hGs'sub : ∀ g ∈ Gs', g ∈ Gs ∧ isoConj g ψ = ψ' := by intro g hg rw [hGs'] at hg exact ⟨(hGs₁sub g (mem_filter.mp hg).1).1, (mem_filter.mp hg).2⟩ have hG'big := arith155_a hk4 hGs₁c hψ' hM9 (Nat.cast_nonneg _) have hcen : ∀ g ∈ Gs', ∀ g' ∈ Gs', isoApp (isoComp (isoInv g') g) (ψ.2 / (1 - ψ.1)) = ψ.2 / (1 - ψ.1) := by intro g hg g' hg' exact step4_centre hψ1 (hG g (hGs'sub g hg).1) (hG g' (hGs'sub g' hg').1) ((hGs'sub g hg).2.trans (hGs'sub g' hg').2.symm) refine ⟨ψ.2 / (1 - ψ.1), Gs', fun g hg => (hGs'sub g hg).1, hG'big, ?_⟩ intro g hg g' hg' have h := hcen g hg g' hg' rw [isoApp_comp] at h have h2 := app_isoInv (hG g' (hGs'sub g' hg').1) (isoApp g (ψ.2 / (1 - ψ.1))) rw [h] at h2 exact h2.symm end E94S /-! ### SOLO slice C2a -/ /-! ## SOLO module C (part 2a): heavy circles, structured pairs, and families with a common image point -/ namespace E94S open Finset open Classical in /-- The circle about `z` of squared radius `ρ` carries at least `D` points of `B`. -/ def Heavy (B : Finset ℂ) (D : ℝ) (z : ℂ) (ρ : ℝ) : Prop := D ≤ ((B.filter (fun x => dq x z = ρ)).card : ℝ) /-- A structured pair: both endpoints lie on heavy circles about a common centre. -/ def Struct (B : Finset ℂ) (D : ℝ) (a b : ℂ) : Prop := ∃ z : ℂ, Heavy B D z (dq a z) ∧ Heavy B D z (dq b z) open Classical in /-- The domain in `B` of a map. -/ noncomputable def fdom (B : Finset ℂ) (φ : ℂ → ℂ) : Finset ℂ := B.filter (fun p => φ p ∈ B) open Classical in /-- The ordered unstructured pairs inside the domain of a map. -/ noncomputable def ucount (B : Finset ℂ) (D : ℝ) (φ : ℂ → ℂ) : ℕ := ((fdom B φ ×ˢ fdom B φ).filter (fun ab => ab.1 ≠ ab.2 ∧ ¬ Struct B D ab.1 ab.2)).card open Classical in /-- The points of the domain on light circles about `z`. -/ noncomputable def lset (B : Finset ℂ) (D : ℝ) (z : ℂ) (φ : ℂ → ℂ) : Finset ℂ := (fdom B φ).filter (fun p => ¬ Heavy B D z (dq p z)) /-- An unstructured pair has an endpoint on a light circle about any given centre. -/ theorem ucount_le (B : Finset ℂ) (D : ℝ) (z : ℂ) (φ : ℂ → ℂ) : ucount B D φ ≤ 2 * (lset B D z φ).card * B.card := by classical have hsub : (fdom B φ ×ˢ fdom B φ).filter (fun ab => ab.1 ≠ ab.2 ∧ ¬ Struct B D ab.1 ab.2) ⊆ (lset B D z φ ×ˢ B) ∪ (B ×ˢ lset B D z φ) := by intro ab hab obtain ⟨h1, _, h3⟩ := mem_filter.mp hab obtain ⟨ha, hb⟩ := mem_product.mp h1 have haB : ab.1 ∈ B := (mem_filter.mp ha).1 have hbB : ab.2 ∈ B := (mem_filter.mp hb).1 by_cases hl : Heavy B D z (dq ab.1 z) · have hl2 : ¬ Heavy B D z (dq ab.2 z) := fun h => h3 ⟨z, hl, h⟩ exact mem_union_right _ (mem_product.mpr ⟨haB, mem_filter.mpr ⟨hb, hl2⟩⟩) · exact mem_union_left _ (mem_product.mpr ⟨mem_filter.mpr ⟨ha, hl⟩, hbB⟩) unfold ucount refine le_trans (card_le_card hsub) (le_trans (card_union_le _ _) ?_) rw [card_product, card_product] nlinarith open Classical in /-- **Light points of a family with a common image.** -/ theorem light_sum {ι : Type*} [DecidableEq ι] (B : Finset ℂ) {D : ℝ} (hD : 0 ≤ D) (Gs : Finset ι) (φ : ι → ℂ → ℂ) (hiso : ∀ g ∈ Gs, ∀ a b : ℂ, dq (φ g a) (φ g b) = dq a b) (z zs : ℂ) (hz : ∀ g ∈ Gs, φ g z = zs) (hsep : ∀ g ∈ Gs, ∀ g' ∈ Gs, ∀ p : ℂ, p ≠ z → φ g p = φ g' p → g = g') : ((∑ g ∈ Gs, (lset B D z (φ g)).card : ℕ) : ℝ) ≤ D * (B.card : ℝ) + (Gs.card : ℝ) := by -- the target set of pairs obtain ⟨T, hT⟩ : ∃ T : Finset (ℂ × ℂ), T = (B ×ˢ B).filter (fun pp => ¬ Heavy B D z (dq pp.1 z) ∧ dq pp.2 zs = dq pp.1 z) := ⟨_, rfl⟩ -- |T| ≤ D·|B| have hTcard : (T.card : ℝ) ≤ D * (B.card : ℝ) := by have hsub : T ⊆ B.biUnion (fun p' => (B.filter (fun p => ¬ Heavy B D z (dq p z) ∧ dq p z = dq p' zs)).image (fun p => (p, p'))) := by intro pp hpp rw [hT] at hpp obtain ⟨h1, h2, h3⟩ := mem_filter.mp hpp obtain ⟨ha, hb⟩ := mem_product.mp h1 exact mem_biUnion.mpr ⟨pp.2, hb, mem_image.mpr ⟨pp.1, mem_filter.mpr ⟨ha, h2, h3.symm⟩, rfl⟩⟩ have h1 : T.card ≤ ∑ p' ∈ B, (B.filter (fun p => ¬ Heavy B D z (dq p z) ∧ dq p z = dq p' zs)).card := le_trans (card_le_card hsub) (le_trans card_biUnion_le (sum_le_sum (fun p' _ => card_image_le))) have h2 : ∀ p' ∈ B, ((B.filter (fun p => ¬ Heavy B D z (dq p z) ∧ dq p z = dq p' zs)).card : ℝ) ≤ D := by intro p' _ by_cases hne : (B.filter (fun p => ¬ Heavy B D z (dq p z) ∧ dq p z = dq p' zs)).Nonempty · obtain ⟨p, hp⟩ := hne obtain ⟨_, hlight, hρ⟩ := mem_filter.mp hp rw [hρ] at hlight unfold Heavy at hlight push_neg at hlight refine le_trans ?_ hlight.le have : B.filter (fun p => ¬ Heavy B D z (dq p z) ∧ dq p z = dq p' zs) ⊆ B.filter (fun x => dq x z = dq p' zs) := by intro x hx obtain ⟨hxB, _, hx2⟩ := mem_filter.mp hx exact mem_filter.mpr ⟨hxB, hx2⟩ exact_mod_cast card_le_card this · rw [not_nonempty_iff_eq_empty] at hne rw [hne] simpa using hD have h3 : ((∑ p' ∈ B, (B.filter (fun p => ¬ Heavy B D z (dq p z) ∧ dq p z = dq p' zs)).card : ℕ) : ℝ) ≤ ∑ _p' ∈ B, D := by push_cast exact sum_le_sum h2 rw [sum_const, nsmul_eq_mul] at h3 have h1' : (T.card : ℝ) ≤ ((∑ p' ∈ B, (B.filter (fun p => ¬ Heavy B D z (dq p z) ∧ dq p z = dq p' zs)).card : ℕ) : ℝ) := by exact_mod_cast h1 linarith -- injection of the light points other than `z` obtain ⟨S, hS⟩ : ∃ S : ι → Finset (ℂ × ℂ), S = fun g => ((lset B D z (φ g)).erase z).image (fun p => (p, φ g p)) := ⟨_, rfl⟩ have hScard : ∀ g, (S g).card = ((lset B D z (φ g)).erase z).card := by intro g rw [hS] exact card_image_of_injective _ (fun a b h => (Prod.mk.inj h).1) have hSsub : ∀ g ∈ Gs, S g ⊆ T := by intro g hg pp hpp rw [hS] at hpp obtain ⟨p, hp, rfl⟩ := mem_image.mp hpp obtain ⟨_, hp2⟩ := mem_erase.mp hp unfold lset at hp2 obtain ⟨hp3, hp4⟩ := mem_filter.mp hp2 unfold fdom at hp3 obtain ⟨hpB, hφB⟩ := mem_filter.mp hp3 rw [hT] refine mem_filter.mpr ⟨mem_product.mpr ⟨hpB, hφB⟩, hp4, ?_⟩ show dq (φ g p) zs = dq p z rw [← hz g hg, hiso g hg] have hSdisj : ∀ g ∈ Gs, ∀ g' ∈ Gs, g ≠ g' → Disjoint (S g) (S g') := by intro g hg g' hg' hne rw [disjoint_left] intro pp h1 h2 rw [hS] at h1 h2 obtain ⟨p, hp, rfl⟩ := mem_image.mp h1 obtain ⟨p', hp', hpp'⟩ := mem_image.mp h2 obtain ⟨e1, e2⟩ := Prod.mk.inj hpp' rw [e1] at e2 exact hne (hsep g hg g' hg' p (mem_erase.mp hp).1 e2.symm) have hU : (Gs.biUnion S).card = ∑ g ∈ Gs, (S g).card := card_biUnion hSdisj have hUT : (Gs.biUnion S).card ≤ T.card := card_le_card (biUnion_subset.mpr hSsub) have hsum : ∑ g ∈ Gs, (lset B D z (φ g)).card ≤ ∑ g ∈ Gs, ((S g).card + 1) := by refine sum_le_sum (fun g _ => ?_) rw [hScard] by_cases hzm : z ∈ lset B D z (φ g) · rw [card_erase_of_mem hzm] have : 0 < (lset B D z (φ g)).card := card_pos.mpr ⟨z, hzm⟩ omega · rw [erase_eq_of_notMem hzm] omega rw [sum_add_distrib, sum_const, smul_eq_mul, mul_one, ← hU] at hsum have : ((∑ g ∈ Gs, (lset B D z (φ g)).card : ℕ) : ℝ) ≤ (T.card : ℝ) + (Gs.card : ℝ) := by have := le_trans hsum (Nat.add_le_add_right hUT _) exact_mod_cast this linarith /-- **A large family with a common image has a member with few unstructured pairs.** -/ theorem common_image_contra {ι : Type*} [DecidableEq ι] (B : Finset ℂ) {δ₁ θ c₀ : ℝ} (hB : (0 : ℝ) < B.card) (hδ : 0 ≤ δ₁) (hθ : 0 < θ) (hδ₁ : 4 * δ₁ ≤ θ * c₀) (hNθ : 4 ≤ θ * (B.card : ℝ)) (Gs : Finset ι) (φ : ι → ℂ → ℂ) (hiso : ∀ g ∈ Gs, ∀ a b : ℂ, dq (φ g a) (φ g b) = dq a b) (z zs : ℂ) (hz : ∀ g ∈ Gs, φ g z = zs) (hsep : ∀ g ∈ Gs, ∀ g' ∈ Gs, ∀ p : ℂ, p ≠ z → φ g p = φ g' p → g = g') (hcard : c₀ * (B.card : ℝ) ≤ (Gs.card : ℝ)) (hne : Gs.Nonempty) (hbad : ∀ g ∈ Gs, θ * (B.card : ℝ) ^ 2 < (ucount B (δ₁ * B.card) (φ g) : ℝ)) : False := by classical have hls := light_sum B (D := δ₁ * B.card) (by positivity) Gs φ hiso z zs hz hsep have hl : ∀ g ∈ Gs, θ * (B.card : ℝ) / 2 < ((lset B (δ₁ * B.card) z (φ g)).card : ℝ) := by intro g hg have h1 := hbad g hg have h2 : (ucount B (δ₁ * B.card) (φ g) : ℝ) ≤ 2 * ((lset B (δ₁ * B.card) z (φ g)).card : ℝ) * B.card := by exact_mod_cast ucount_le B (δ₁ * B.card) z (φ g) have h3 : θ * (B.card : ℝ) ^ 2 < 2 * ((lset B (δ₁ * B.card) z (φ g)).card : ℝ) * B.card := lt_of_lt_of_le h1 h2 have h4 : θ * (B.card : ℝ) * (B.card : ℝ) < 2 * ((lset B (δ₁ * B.card) z (φ g)).card : ℝ) * B.card := by nlinarith have := lt_of_mul_lt_mul_right h4 hB.le linarith have hsum : (Gs.card : ℝ) * (θ * (B.card : ℝ) / 2) ≤ ((∑ g ∈ Gs, (lset B (δ₁ * B.card) z (φ g)).card : ℕ) : ℝ) := by push_cast rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum (fun g hg => (hl g hg).le) have hG0 : (0 : ℝ) < Gs.card := by exact_mod_cast card_pos.mpr hne obtain ⟨g0, hg0⟩ := hne have hstrict : (Gs.card : ℝ) * (θ * (B.card : ℝ) / 2) < ((∑ g ∈ Gs, (lset B (δ₁ * B.card) z (φ g)).card : ℕ) : ℝ) := by push_cast rw [← nsmul_eq_mul, ← sum_const] exact sum_lt_sum (fun g hg => (hl g hg).le) ⟨g0, hg0, hl g0 hg0⟩ have a : (Gs.card : ℝ) * (θ * (B.card : ℝ) / 2) - (Gs.card : ℝ) < δ₁ * (B.card : ℝ) * (B.card : ℝ) := by linarith have b : (Gs.card : ℝ) * (θ * (B.card : ℝ) / 4) ≤ (Gs.card : ℝ) * (θ * (B.card : ℝ) / 2) - (Gs.card : ℝ) := by have : (Gs.card : ℝ) * 1 ≤ (Gs.card : ℝ) * (θ * (B.card : ℝ) / 4) := mul_le_mul_of_nonneg_left (by linarith) hG0.le linarith have c : (Gs.card : ℝ) * θ * (B.card : ℝ) < 4 * δ₁ * (B.card : ℝ) * (B.card : ℝ) := by linarith have d : (Gs.card : ℝ) * θ < 4 * δ₁ * (B.card : ℝ) := lt_of_mul_lt_mul_right c hB.le have e : 4 * δ₁ * (B.card : ℝ) ≤ θ * c₀ * (B.card : ℝ) := mul_le_mul_of_nonneg_right hδ₁ hB.le have f : θ * (c₀ * (B.card : ℝ)) ≤ θ * (Gs.card : ℝ) := mul_le_mul_of_nonneg_left hcard hθ.le linarith end E94S /-! ### SOLO slice C2b -/ /-! ## SOLO module C (part 2b): the finite families of rich isometries -/ namespace E94S open Finset theorem normSq_eq_one {a : ℂ} (h : ‖a‖ = 1) : Complex.normSq a = 1 := by rw [Complex.normSq_eq_norm_sq, h]; norm_num theorem conj_mul_self_of_norm {a : ℂ} (h : ‖a‖ = 1) : a * (starRingEnd ℂ) a = 1 := by rw [Complex.mul_conj, normSq_eq_one h]; simp theorem iapp_dq {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) (a b : ℂ) : dq (iapp g a) (iapp g b) = dq a b := by rw [dq_eq_normSq, dq_eq_normSq] have : iapp g a - iapp g b = g.1 * (a - b) := by unfold iapp; ring rw [this, Complex.normSq_mul, normSq_eq_one hg, one_mul] theorem iappc_dq {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) (a b : ℂ) : dq (iappc g a) (iappc g b) = dq a b := by rw [dq_eq_normSq, dq_eq_normSq] have : iappc g a - iappc g b = g.1 * (starRingEnd ℂ) (a - b) := by unfold iappc; rw [map_sub]; ring rw [this, Complex.normSq_mul, normSq_eq_one hg, one_mul, Complex.normSq_conj] theorem ne_of_dq_ne {a b : ℂ} (h : a ≠ b) : dq a b ≠ 0 := fun h0 => h (dq_eq_zero h0) /-- Two proper isometries agreeing at two distinct points are equal. -/ theorem iapp_sep {g g' : ℂ × ℂ} {z p : ℂ} (hpz : p ≠ z) (h1 : iapp g z = iapp g' z) (h2 : iapp g p = iapp g' p) : g = g' := by unfold iapp at h1 h2 have e : (g.1 - g'.1) * (p - z) = 0 := by linear_combination h2 - h1 have e1 : g.1 = g'.1 := sub_eq_zero.mp ((mul_eq_zero.mp e).resolve_right (sub_ne_zero.mpr hpz)) have e2 : g.2 = g'.2 := by rw [e1] at h1; linear_combination h1 exact Prod.ext e1 e2 /-- Two improper isometries agreeing at two distinct points are equal. -/ theorem iappc_sep {g g' : ℂ × ℂ} {z p : ℂ} (hpz : p ≠ z) (h1 : iappc g z = iappc g' z) (h2 : iappc g p = iappc g' p) : g = g' := by unfold iappc at h1 h2 have e : (g.1 - g'.1) * (starRingEnd ℂ) (p - z) = 0 := by rw [map_sub]; linear_combination h2 - h1 have hc : (starRingEnd ℂ) (p - z) ≠ 0 := fun h => (sub_ne_zero.mpr hpz) ((map_eq_zero _).mp h) have e1 : g.1 = g'.1 := sub_eq_zero.mp ((mul_eq_zero.mp e).resolve_right hc) have e2 : g.2 = g'.2 := by rw [e1] at h1; linear_combination h1 exact Prod.ext e1 e2 /-- The proper isometry carrying `(a, b)` to `(c, d)`, for `q = (a, b, c, d)`. -/ noncomputable def gp4 (q : ℂ × ℂ × ℂ × ℂ) : ℂ × ℂ := ((q.2.2.2 - q.2.2.1) / (q.2.1 - q.1), q.2.2.1 - (q.2.2.2 - q.2.2.1) / (q.2.1 - q.1) * q.1) /-- The improper isometry carrying `(a, b)` to `(c, d)`. -/ noncomputable def gm4 (q : ℂ × ℂ × ℂ × ℂ) : ℂ × ℂ := ((q.2.2.2 - q.2.2.1) / (starRingEnd ℂ) (q.2.1 - q.1), q.2.2.1 - (q.2.2.2 - q.2.2.1) / (starRingEnd ℂ) (q.2.1 - q.1) * (starRingEnd ℂ) q.1) theorem gp4_unique {g : ℂ × ℂ} {a b c d : ℂ} (hab : a ≠ b) (h1 : iapp g a = c) (h2 : iapp g b = d) : g = gp4 (a, b, c, d) := by unfold iapp at h1 h2 have hne : b - a ≠ 0 := sub_ne_zero.mpr (Ne.symm hab) have e1 : g.1 = (d - c) / (b - a) := by rw [eq_div_iff hne]; linear_combination h2 - h1 unfold gp4 apply Prod.ext · exact e1 · simp only rw [← e1]; linear_combination h1 theorem gm4_unique {g : ℂ × ℂ} {a b c d : ℂ} (hab : a ≠ b) (h1 : iappc g a = c) (h2 : iappc g b = d) : g = gm4 (a, b, c, d) := by unfold iappc at h1 h2 have hne : (starRingEnd ℂ) (b - a) ≠ 0 := fun h => (sub_ne_zero.mpr (Ne.symm hab)) ((map_eq_zero _).mp h) have e1 : g.1 = (d - c) / (starRingEnd ℂ) (b - a) := by rw [eq_div_iff hne, map_sub]; linear_combination h2 - h1 unfold gm4 apply Prod.ext · exact e1 · simp only rw [← e1]; linear_combination h1 open Classical in /-- Ordered quadruples of points `(a, b, c, d)` of `B` with `a ≠ b`, `c ≠ d`, `|ab| = |cd|`. -/ noncomputable def QP (B : Finset ℂ) : Finset (ℂ × ℂ × ℂ × ℂ) := (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q => q.1 ≠ q.2.1 ∧ q.2.2.1 ≠ q.2.2.2 ∧ dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2) open Classical in /-- The proper isometries with at least `T` points of `B` in their domain (and at least two). -/ noncomputable def Gp (B : Finset ℂ) (T : ℝ) : Finset (ℂ × ℂ) := ((QP B).image gp4).filter (fun g => ‖g.1‖ = 1 ∧ T ≤ ((idom B g).card : ℝ)) open Classical in /-- The improper isometries with at least `T` points of `B` in their domain (and at least two). -/ noncomputable def Gm (B : Finset ℂ) (T : ℝ) : Finset (ℂ × ℂ) := ((QP B).image gm4).filter (fun g => ‖g.1‖ = 1 ∧ T ≤ ((idomc B g).card : ℝ)) open Classical in /-- **Explained unstructured pairs are covered by the rich isometries.** -/ theorem expl_cover (B : Finset ℂ) (D T : ℝ) : ((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B D q.1 q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)).card ≤ ∑ g ∈ Gp B T, ucount B D (iapp g) + ∑ g ∈ Gm B T, ucount B D (iappc g) := by have hsub : (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B D q.1 q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2) ⊆ (Gp B T).biUnion (fun g => ((fdom B (iapp g) ×ˢ fdom B (iapp g)).filter (fun ab => ab.1 ≠ ab.2 ∧ ¬ Struct B D ab.1 ab.2)).image (fun ab => (ab.1, ab.2, iapp g ab.1, iapp g ab.2))) ∪ (Gm B T).biUnion (fun g => ((fdom B (iappc g) ×ˢ fdom B (iappc g)).filter (fun ab => ab.1 ≠ ab.2 ∧ ¬ Struct B D ab.1 ab.2)).image (fun ab => (ab.1, ab.2, iappc g ab.1, iappc g ab.2))) := by intro q hq obtain ⟨a, b, c, d⟩ := q simp only [mem_filter, mem_product] at hq obtain ⟨⟨haB, hbB, hcB, hdB⟩, hab, hns, g, hg1, hcase⟩ := hq rcases hcase with ⟨e1, e2, e3⟩ | ⟨e1, e2, e3⟩ · apply mem_union_left have hcd : c ≠ d := by intro h have := iapp_dq hg1 a b rw [e1, e2, h, dq_self] at this exact ne_of_dq_ne hab this.symm have hqQ : (a, b, c, d) ∈ QP B := by unfold QP simp only [mem_filter, mem_product] refine ⟨⟨haB, hbB, hcB, hdB⟩, hab, hcd, ?_⟩ rw [← e1, ← e2, iapp_dq hg1] have hgG : g ∈ Gp B T := by unfold Gp refine mem_filter.mpr ⟨mem_image.mpr ⟨(a, b, c, d), hqQ, (gp4_unique hab e1 e2).symm⟩, hg1, e3⟩ refine mem_biUnion.mpr ⟨g, hgG, mem_image.mpr ⟨(a, b), ?_, by simp [e1, e2]⟩⟩ refine mem_filter.mpr ⟨mem_product.mpr ⟨?_, ?_⟩, hab, hns⟩ · unfold fdom; exact mem_filter.mpr ⟨haB, by rw [e1]; exact hcB⟩ · unfold fdom; exact mem_filter.mpr ⟨hbB, by rw [e2]; exact hdB⟩ · apply mem_union_right have hcd : c ≠ d := by intro h have := iappc_dq hg1 a b rw [e1, e2, h, dq_self] at this exact ne_of_dq_ne hab this.symm have hqQ : (a, b, c, d) ∈ QP B := by unfold QP simp only [mem_filter, mem_product] refine ⟨⟨haB, hbB, hcB, hdB⟩, hab, hcd, ?_⟩ rw [← e1, ← e2, iappc_dq hg1] have hgG : g ∈ Gm B T := by unfold Gm refine mem_filter.mpr ⟨mem_image.mpr ⟨(a, b, c, d), hqQ, (gm4_unique hab e1 e2).symm⟩, hg1, e3⟩ refine mem_biUnion.mpr ⟨g, hgG, mem_image.mpr ⟨(a, b), ?_, by simp [e1, e2]⟩⟩ refine mem_filter.mpr ⟨mem_product.mpr ⟨?_, ?_⟩, hab, hns⟩ · unfold fdom; exact mem_filter.mpr ⟨haB, by rw [e1]; exact hcB⟩ · unfold fdom; exact mem_filter.mpr ⟨hbB, by rw [e2]; exact hdB⟩ refine le_trans (card_le_card hsub) (le_trans (card_union_le _ _) ?_) refine Nat.add_le_add ?_ ?_ · exact le_trans card_biUnion_le (sum_le_sum (fun g _ => card_image_le)) · exact le_trans card_biUnion_le (sum_le_sum (fun g _ => card_image_le)) end E94S /-! ### SOLO slice C2c -/ /-! ## SOLO module C (part 2c): there are `O(n/τ²)` rich isometries -/ namespace E94S open Finset theorem pairs_real_ge {m : ℕ} {T : ℝ} (hT : 1 ≤ T) (hm : T ≤ (m : ℝ)) : T * (T - 1) ≤ ((m * m - m : ℕ) : ℝ) := by have h1 : m ≤ m * m := Nat.le_mul_self m rw [Nat.cast_sub h1] push_cast nlinarith open Classical in /-- **Count of rich proper isometries.** -/ theorem Gp_card (B : Finset ℂ) {T : ℝ} (hT : 1 ≤ T) : ((Gp B T).card : ℝ) * (T * (T - 1)) ≤ ((QP B).card : ℝ) := by obtain ⟨S, hS⟩ : ∃ S : ℂ × ℂ → Finset (ℂ × ℂ × ℂ × ℂ), S = fun g => (idom B g).offDiag.image (fun ab => (ab.1, ab.2, iapp g ab.1, iapp g ab.2)) := ⟨_, rfl⟩ have hgm : ∀ g ∈ Gp B T, ‖g.1‖ = 1 ∧ T ≤ ((idom B g).card : ℝ) := by intro g hg unfold Gp at hg exact (mem_filter.mp hg).2 have hSsub : ∀ g ∈ Gp B T, S g ⊆ QP B := by intro g hg q hq rw [hS] at hq obtain ⟨ab, hab, rfl⟩ := mem_image.mp hq obtain ⟨ha, hb, hne⟩ := mem_offDiag.mp hab unfold idom at ha hb obtain ⟨haB, hga⟩ := mem_filter.mp ha obtain ⟨hbB, hgb⟩ := mem_filter.mp hb have hg1 := (hgm g hg).1 unfold QP simp only [mem_filter, mem_product] refine ⟨⟨haB, hbB, hga, hgb⟩, hne, ?_, (iapp_dq hg1 ab.1 ab.2).symm⟩ intro h have := iapp_dq hg1 ab.1 ab.2 rw [h, dq_self] at this exact ne_of_dq_ne hne this.symm have hSdisj : ∀ g ∈ Gp B T, ∀ g' ∈ Gp B T, g ≠ g' → Disjoint (S g) (S g') := by intro g _ g' _ hne rw [disjoint_left] intro q h1 h2 rw [hS] at h1 h2 obtain ⟨ab, hab, rfl⟩ := mem_image.mp h1 obtain ⟨ab', _, he⟩ := mem_image.mp h2 obtain ⟨_, _, hne'⟩ := mem_offDiag.mp hab simp only [Prod.mk.injEq] at he obtain ⟨e1, e2, e3, e4⟩ := he rw [e1] at e3 rw [e2] at e4 exact hne ((gp4_unique hne' rfl rfl).trans (gp4_unique hne' e3 e4).symm) have hScard : ∀ g ∈ Gp B T, T * (T - 1) ≤ ((S g).card : ℝ) := by intro g hg have : (S g).card = (idom B g).card * (idom B g).card - (idom B g).card := by rw [hS] simp only rw [card_image_of_injective, offDiag_card] intro x y h simp only [Prod.mk.injEq] at h exact Prod.ext h.1 h.2.1 rw [this] exact pairs_real_ge hT (hgm g hg).2 have hU : ((Gp B T).biUnion S).card = ∑ g ∈ Gp B T, (S g).card := card_biUnion hSdisj have hUQ : ((Gp B T).biUnion S).card ≤ (QP B).card := card_le_card (biUnion_subset.mpr hSsub) have h1 : ((Gp B T).card : ℝ) * (T * (T - 1)) ≤ ((∑ g ∈ Gp B T, (S g).card : ℕ) : ℝ) := by push_cast rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum hScard have h2 : ((∑ g ∈ Gp B T, (S g).card : ℕ) : ℝ) ≤ ((QP B).card : ℝ) := by rw [← hU] exact_mod_cast hUQ linarith open Classical in /-- **Count of rich improper isometries.** -/ theorem Gm_card (B : Finset ℂ) {T : ℝ} (hT : 1 ≤ T) : ((Gm B T).card : ℝ) * (T * (T - 1)) ≤ ((QP B).card : ℝ) := by obtain ⟨S, hS⟩ : ∃ S : ℂ × ℂ → Finset (ℂ × ℂ × ℂ × ℂ), S = fun g => (idomc B g).offDiag.image (fun ab => (ab.1, ab.2, iappc g ab.1, iappc g ab.2)) := ⟨_, rfl⟩ have hgm : ∀ g ∈ Gm B T, ‖g.1‖ = 1 ∧ T ≤ ((idomc B g).card : ℝ) := by intro g hg unfold Gm at hg exact (mem_filter.mp hg).2 have hSsub : ∀ g ∈ Gm B T, S g ⊆ QP B := by intro g hg q hq rw [hS] at hq obtain ⟨ab, hab, rfl⟩ := mem_image.mp hq obtain ⟨ha, hb, hne⟩ := mem_offDiag.mp hab unfold idomc at ha hb obtain ⟨haB, hga⟩ := mem_filter.mp ha obtain ⟨hbB, hgb⟩ := mem_filter.mp hb have hg1 := (hgm g hg).1 unfold QP simp only [mem_filter, mem_product] refine ⟨⟨haB, hbB, hga, hgb⟩, hne, ?_, (iappc_dq hg1 ab.1 ab.2).symm⟩ intro h have := iappc_dq hg1 ab.1 ab.2 rw [h, dq_self] at this exact ne_of_dq_ne hne this.symm have hSdisj : ∀ g ∈ Gm B T, ∀ g' ∈ Gm B T, g ≠ g' → Disjoint (S g) (S g') := by intro g _ g' _ hne rw [disjoint_left] intro q h1 h2 rw [hS] at h1 h2 obtain ⟨ab, hab, rfl⟩ := mem_image.mp h1 obtain ⟨ab', _, he⟩ := mem_image.mp h2 obtain ⟨_, _, hne'⟩ := mem_offDiag.mp hab simp only [Prod.mk.injEq] at he obtain ⟨e1, e2, e3, e4⟩ := he rw [e1] at e3 rw [e2] at e4 exact hne ((gm4_unique hne' rfl rfl).trans (gm4_unique hne' e3 e4).symm) have hScard : ∀ g ∈ Gm B T, T * (T - 1) ≤ ((S g).card : ℝ) := by intro g hg have : (S g).card = (idomc B g).card * (idomc B g).card - (idomc B g).card := by rw [hS] simp only rw [card_image_of_injective, offDiag_card] intro x y h simp only [Prod.mk.injEq] at h exact Prod.ext h.1 h.2.1 rw [this] exact pairs_real_ge hT (hgm g hg).2 have hU : ((Gm B T).biUnion S).card = ∑ g ∈ Gm B T, (S g).card := card_biUnion hSdisj have hUQ : ((Gm B T).biUnion S).card ≤ (QP B).card := card_le_card (biUnion_subset.mpr hSsub) have h1 : ((Gm B T).card : ℝ) * (T * (T - 1)) ≤ ((∑ g ∈ Gm B T, (S g).card : ℕ) : ℝ) := by push_cast rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum hScard have h2 : ((∑ g ∈ Gm B T, (S g).card : ℕ) : ℝ) ≤ ((QP B).card : ℝ) := by rw [← hU] exact_mod_cast hUQ linarith theorem ucount_le_sq (B : Finset ℂ) (D : ℝ) (φ : ℂ → ℂ) : ucount B D φ ≤ B.card ^ 2 := by classical unfold ucount refine le_trans (card_le_card (filter_subset _ _)) ?_ rw [card_product, sq] have : (fdom B φ).card ≤ B.card := card_le_card (filter_subset _ _) exact Nat.mul_le_mul this this end E94S /-! ### SOLO slice C3a -/ /-! ## SOLO module C (part 3a): few rich proper isometries have many unstructured pairs in their domain -/ namespace E94S open Finset Erdos94ThmA open Classical in /-- **Proper case.** For large `B` with property (T), fewer than `κ₁|B|` of the `τ|B|`-rich proper isometries have more than `θ|B|²` unstructured pairs (w.r.t. `δ₁|B|`-heavy circles) in their domain. -/ theorem bad_proper_few {κ₁ τ θ : ℝ} (hκ₁ : 0 < κ₁) (hτ : 0 < τ) (hτ1 : τ ≤ 1) (hθ : 0 < θ) : ∃ δ₁ : ℝ, 0 < δ₁ ∧ ∃ n₀ : ℕ, ∀ B : Finset ℂ, n₀ ≤ B.card → (∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) → (((Gp B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (δ₁ * B.card) (iapp g) : ℝ))).card : ℝ) < κ₁ * B.card := by obtain ⟨c₀, hc₀⟩ : ∃ c₀ : ℝ, c₀ = τ ^ 8 * κ₁ / 36 := ⟨_, rfl⟩ have hc₀pos : 0 < c₀ := by rw [hc₀]; positivity obtain ⟨M, hM⟩ : ∃ M : ℕ, M = ⌈8 / τ ^ 4⌉₊ := ⟨_, rfl⟩ obtain ⟨Lr, hLr⟩ : ∃ Lr : ℝ, Lr = 4 / (κ₁ * τ ^ 4) + 8 / τ ^ 4 + 72 / (κ₁ * τ ^ 10) + 8 / τ ^ 2 := ⟨_, rfl⟩ refine ⟨θ * c₀ / 4, by positivity, max (⌈Lr⌉₊ + M * M + 1) ⌈4 / θ⌉₊, ?_⟩ intro B hn hT by_contra hcon push_neg at hcon obtain ⟨Gs, hGs⟩ : ∃ Gs : Finset (ℂ × ℂ), Gs = (Gp B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (θ * c₀ / 4 * B.card) (iapp g) : ℝ)) := ⟨_, rfl⟩ rw [← hGs] at hcon have hn1 : ((⌈Lr⌉₊ + M * M + 1 : ℕ) : ℝ) ≤ (B.card : ℝ) := by exact_mod_cast le_trans (le_max_left _ _) hn have hn2 : 4 ≤ θ * (B.card : ℝ) := by have h1 : 4 / θ ≤ (B.card : ℝ) := le_trans (Nat.le_ceil _) (by exact_mod_cast le_trans (le_max_right _ _) hn) rw [div_le_iff₀ hθ] at h1 linarith obtain ⟨hN0, hNa, hN8, hNM, _, _, hM8, hM9⟩ := thm155_sizes hκ₁ hτ hτ1 hM hLr hn1 have hmem : ∀ g ∈ Gs, (‖g.1‖ = 1 ∧ τ * (B.card : ℝ) ≤ ((idom B g).card : ℝ)) ∧ θ * (B.card : ℝ) ^ 2 < (ucount B (θ * c₀ / 4 * B.card) (iapp g) : ℝ) := by intro g hg rw [hGs] at hg obtain ⟨h1, h2⟩ := mem_filter.mp hg unfold Gp at h1 exact ⟨(mem_filter.mp h1).2, h2⟩ obtain ⟨z, Gs', hsub, hbig, hcomm⟩ := thm155_sub hκ₁ hτ hT (fun g hg => (hmem g hg).1.1) hcon (fun g hg => (hmem g hg).1.2) hN0 hNa hN8 hNM hM8 hM9 have hcard : c₀ * (B.card : ℝ) ≤ (Gs'.card : ℝ) := by have h1 : τ ^ 8 * (κ₁ * (B.card : ℝ)) / 36 ≤ τ ^ 8 * (Gs.card : ℝ) / 36 := by have : τ ^ 8 * (κ₁ * (B.card : ℝ)) ≤ τ ^ 8 * (Gs.card : ℝ) := mul_le_mul_of_nonneg_left hcon (by positivity) linarith have e : c₀ * (B.card : ℝ) = τ ^ 8 * (κ₁ * (B.card : ℝ)) / 36 := by rw [hc₀]; ring linarith have hne : Gs'.Nonempty := by have : (0 : ℝ) < (Gs'.card : ℝ) := lt_of_lt_of_le (by positivity) hcard exact card_pos.mp (by exact_mod_cast this) obtain ⟨g0, hg0⟩ := hne exact common_image_contra B (δ₁ := θ * c₀ / 4) (θ := θ) (c₀ := c₀) hN0 (by positivity) hθ (by linarith) hn2 Gs' (fun g => iapp g) (fun g hg a b => iapp_dq (hmem g (hsub hg)).1.1 a b) z (iapp g0 z) (fun g hg => hcomm g hg g0 hg0) (fun g hg g' hg' p hp h => iapp_sep hp ((hcomm g hg g0 hg0).trans (hcomm g' hg' g0 hg0).symm) h) hcard ⟨g0, hg0⟩ (fun g hg => (hmem g (hsub hg)).2) end E94S /-! ### SOLO slice C3b -/ /-! ## SOLO module C (part 3b): the improper case, through a carrier isometry -/ namespace E94S open Finset Erdos94ThmA theorem iappc_inj {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) {a b : ℂ} (h : iappc g a = iappc g b) : a = b := by have := iappc_dq hg a b rw [h, dq_self] at this exact dq_eq_zero this.symm /-- The proper isometry `g'⁻¹ ∘ g` for two improper isometries. -/ noncomputable def hmap (g' g : ℂ × ℂ) : ℂ × ℂ := (g'.1 * (starRingEnd ℂ) g.1, g'.1 * ((starRingEnd ℂ) g.2 - (starRingEnd ℂ) g'.2)) theorem hmap_norm {g' g : ℂ × ℂ} (hg' : ‖g'.1‖ = 1) (hg : ‖g.1‖ = 1) : ‖(hmap g' g).1‖ = 1 := by unfold hmap simp only rw [norm_mul, RCLike.norm_conj, hg', hg, mul_one] /-- `g = g' ∘ (g'⁻¹ ∘ g)`. -/ theorem hmap_comp {g' g : ℂ × ℂ} (hg' : ‖g'.1‖ = 1) (p : ℂ) : iappc g' (iapp (hmap g' g) p) = iappc g p := by unfold iappc iapp hmap simp only [map_add, map_mul, map_sub, Complex.conj_conj] have h := conj_mul_self_of_norm hg' linear_combination (g.1 * (starRingEnd ℂ) p + g.2 - g'.2) * h theorem hmap_inj {g' g1 g2 : ℂ × ℂ} (hg' : ‖g'.1‖ = 1) (h : hmap g' g1 = hmap g' g2) : g1 = g2 := by unfold hmap at h have hne : g'.1 ≠ 0 := by intro h0; rw [h0, norm_zero] at hg'; norm_num at hg' obtain ⟨h1, h2⟩ := Prod.mk.inj h have e1 : (starRingEnd ℂ) g1.1 = (starRingEnd ℂ) g2.1 := mul_left_cancel₀ hne h1 have e2 : (starRingEnd ℂ) g1.2 - (starRingEnd ℂ) g'.2 = (starRingEnd ℂ) g2.2 - (starRingEnd ℂ) g'.2 := mul_left_cancel₀ hne h2 have e3 : (starRingEnd ℂ) g1.2 = (starRingEnd ℂ) g2.2 := by linear_combination e2 exact Prod.ext ((starRingEnd ℂ).injective e1) ((starRingEnd ℂ).injective e3) open Classical in /-- The domain of `g'⁻¹ ∘ g` contains (a copy of) the common part of the images of `g` and `g'`. -/ theorem hmap_dom (B : Finset ℂ) {g' g : ℂ × ℂ} (hg' : ‖g'.1‖ = 1) (hg : ‖g.1‖ = 1) : (((idomc B g).image (iappc g)) ∩ ((idomc B g').image (iappc g'))).card ≤ (idom B (hmap g' g)).card := by refine card_le_card_of_injOn (fun w => (starRingEnd ℂ) ((starRingEnd ℂ) g.1 * (w - g.2))) ?_ ?_ · intro w hw obtain ⟨h1, h2⟩ := mem_inter.mp hw obtain ⟨p, hp, rfl⟩ := mem_image.mp h1 obtain ⟨p'', hp'', he⟩ := mem_image.mp h2 have hback : (starRingEnd ℂ) ((starRingEnd ℂ) g.1 * (iappc g p - g.2)) = p := by unfold iappc simp only [map_mul, Complex.conj_conj, add_sub_cancel_right] have h := conj_mul_self_of_norm hg linear_combination p * h simp only [coe_image, mem_coe] rw [hback] unfold idom unfold idomc at hp hp'' refine mem_filter.mpr ⟨(mem_filter.mp hp).1, ?_⟩ have h3 : iappc g' (iapp (hmap g' g) p) = iappc g' p'' := by rw [hmap_comp hg', he] rw [iappc_inj hg' h3] exact (mem_filter.mp hp'').1 · intro w _ w' _ h simp only at h have h1 := (starRingEnd ℂ).injective h have hne : (starRingEnd ℂ) g.1 ≠ 0 := by intro h0 have : g.1 = 0 := (map_eq_zero _).mp h0 rw [this, norm_zero] at hg; norm_num at hg have h2 := mul_left_cancel₀ hne h1 linear_combination h2 end E94S /-! ### SOLO slice C3c -/ /-! ## SOLO module C (part 3c): few rich improper isometries have many unstructured pairs in their domain -/ namespace E94S open Finset Erdos94ThmA open Classical in /-- **A carrier.** If every member of a family of subsets of `B` has at least `a|B|` points, some member `g'` meets at least `a²/2` of the family in at least `a²|B|/2` points each. -/ theorem carrier_exists (B : Finset ℂ) (Gs : Finset (ℂ × ℂ)) (F : ℂ × ℂ → Finset ℂ) (hF : ∀ g ∈ Gs, F g ⊆ B) {a : ℝ} (ha : 0 ≤ a) (hN : (0 : ℝ) < B.card) (hbig : ∀ g ∈ Gs, a * (B.card : ℝ) ≤ ((F g).card : ℝ)) (hne : Gs.Nonempty) : ∃ g' ∈ Gs, a ^ 2 / 2 * (Gs.card : ℝ) ≤ ((Gs.filter (fun g => a ^ 2 * (B.card : ℝ) / 2 ≤ ((F g ∩ F g').card : ℝ))).card : ℝ) := by have hsq := sum_inter_ge B Gs F hF have hsq' : ((∑ g ∈ Gs, (F g).card : ℕ) : ℝ) ^ 2 ≤ (B.card : ℝ) * ((∑ g ∈ Gs, ∑ g' ∈ Gs, (F g ∩ F g').card : ℕ) : ℝ) := by exact_mod_cast hsq have hS1 : (Gs.card : ℝ) * (a * (B.card : ℝ)) ≤ ((∑ g ∈ Gs, (F g).card : ℕ) : ℝ) := by push_cast rw [← nsmul_eq_mul, ← sum_const] exact sum_le_sum hbig have hS1sq : ((Gs.card : ℝ) * (a * (B.card : ℝ))) ^ 2 ≤ ((∑ g ∈ Gs, (F g).card : ℕ) : ℝ) ^ 2 := pow_le_pow_left₀ (by positivity) hS1 2 have hex : ∃ g' ∈ Gs, a ^ 2 * (B.card : ℝ) * (Gs.card : ℝ) ≤ ∑ g ∈ Gs, ((F g ∩ F g').card : ℝ) := by by_contra hcon push_neg at hcon have h1 : ∑ g' ∈ Gs, ∑ g ∈ Gs, ((F g ∩ F g').card : ℝ) < ∑ _g' ∈ Gs, a ^ 2 * (B.card : ℝ) * (Gs.card : ℝ) := sum_lt_sum_of_nonempty hne hcon rw [sum_const, nsmul_eq_mul, sum_comm] at h1 have h2 : ((∑ g ∈ Gs, ∑ g' ∈ Gs, (F g ∩ F g').card : ℕ) : ℝ) = ∑ g ∈ Gs, ∑ g' ∈ Gs, ((F g ∩ F g').card : ℝ) := by push_cast; rfl rw [h2] at hsq' have h3 : (B.card : ℝ) * ∑ g ∈ Gs, ∑ g' ∈ Gs, ((F g ∩ F g').card : ℝ) < (B.card : ℝ) * ((Gs.card : ℝ) * (a ^ 2 * (B.card : ℝ) * (Gs.card : ℝ))) := mul_lt_mul_of_pos_left h1 hN have h4 : (B.card : ℝ) * ((Gs.card : ℝ) * (a ^ 2 * (B.card : ℝ) * (Gs.card : ℝ))) = ((Gs.card : ℝ) * (a * (B.card : ℝ))) ^ 2 := by ring linarith obtain ⟨g', hg', hsum⟩ := hex refine ⟨g', hg', ?_⟩ exact markov_big Gs (fun g => ((F g ∩ F g').card : ℝ)) hN (sq_nonneg a) (fun g hg => by have : (F g ∩ F g').card ≤ B.card := card_le_card (inter_subset_left.trans (hF g hg)) exact_mod_cast this) hsum open Classical in /-- **Improper case.** -/ theorem bad_improper_few {κ₁ τ θ : ℝ} (hκ₁ : 0 < κ₁) (hτ : 0 < τ) (hτ1 : τ ≤ 1) (hθ : 0 < θ) : ∃ δ₁ : ℝ, 0 < δ₁ ∧ ∃ n₀ : ℕ, ∀ B : Finset ℂ, n₀ ≤ B.card → (∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) → (((Gm B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (δ₁ * B.card) (iappc g) : ℝ))).card : ℝ) < κ₁ * B.card := by obtain ⟨k1, hk1⟩ : ∃ k1 : ℝ, k1 = τ ^ 2 / 2 * κ₁ := ⟨_, rfl⟩ obtain ⟨k2, hk2⟩ : ∃ k2 : ℝ, k2 = τ ^ 2 / 2 := ⟨_, rfl⟩ have hk1pos : 0 < k1 := by rw [hk1]; positivity have hk2pos : 0 < k2 := by rw [hk2]; positivity have hk2le : k2 ≤ 1 := by rw [hk2]; nlinarith obtain ⟨c₀, hc₀⟩ : ∃ c₀ : ℝ, c₀ = k2 ^ 8 * k1 / 36 := ⟨_, rfl⟩ have hc₀pos : 0 < c₀ := by rw [hc₀]; positivity obtain ⟨M, hM⟩ : ∃ M : ℕ, M = ⌈8 / k2 ^ 4⌉₊ := ⟨_, rfl⟩ obtain ⟨Lr, hLr⟩ : ∃ Lr : ℝ, Lr = 4 / (k1 * k2 ^ 4) + 8 / k2 ^ 4 + 72 / (k1 * k2 ^ 10) + 8 / k2 ^ 2 := ⟨_, rfl⟩ refine ⟨θ * c₀ / 4, by positivity, max (⌈Lr⌉₊ + M * M + 1) ⌈4 / θ⌉₊, ?_⟩ intro B hn hT by_contra hcon push_neg at hcon obtain ⟨Gs, hGs⟩ : ∃ Gs : Finset (ℂ × ℂ), Gs = (Gm B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (θ * c₀ / 4 * B.card) (iappc g) : ℝ)) := ⟨_, rfl⟩ rw [← hGs] at hcon have hn1 : ((⌈Lr⌉₊ + M * M + 1 : ℕ) : ℝ) ≤ (B.card : ℝ) := by exact_mod_cast le_trans (le_max_left _ _) hn have hn2 : 4 ≤ θ * (B.card : ℝ) := by have h1 : 4 / θ ≤ (B.card : ℝ) := le_trans (Nat.le_ceil _) (by exact_mod_cast le_trans (le_max_right _ _) hn) rw [div_le_iff₀ hθ] at h1 linarith obtain ⟨hN0, hNa, hN8, hNM, _, _, hM8, hM9⟩ := thm155_sizes hk1pos hk2pos hk2le hM hLr hn1 have hmem : ∀ g ∈ Gs, (‖g.1‖ = 1 ∧ τ * (B.card : ℝ) ≤ ((idomc B g).card : ℝ)) ∧ θ * (B.card : ℝ) ^ 2 < (ucount B (θ * c₀ / 4 * B.card) (iappc g) : ℝ) := by intro g hg rw [hGs] at hg obtain ⟨h1, h2⟩ := mem_filter.mp hg unfold Gm at h1 exact ⟨(mem_filter.mp h1).2, h2⟩ have hGsne : Gs.Nonempty := by have : (0 : ℝ) < (Gs.card : ℝ) := lt_of_lt_of_le (by positivity) hcon exact card_pos.mp (by exact_mod_cast this) -- images obtain ⟨Im, hIm⟩ : ∃ Im : ℂ × ℂ → Finset ℂ, Im = fun g => (idomc B g).image (iappc g) := ⟨_, rfl⟩ have hImB : ∀ g ∈ Gs, Im g ⊆ B := by intro g _ w hw rw [hIm] at hw obtain ⟨p, hp, rfl⟩ := mem_image.mp hw unfold idomc at hp exact (mem_filter.mp hp).2 have hImc : ∀ g ∈ Gs, τ * (B.card : ℝ) ≤ ((Im g).card : ℝ) := by intro g hg have : (Im g).card = (idomc B g).card := by rw [hIm] exact card_image_of_injOn (fun a _ b _ h => iappc_inj (hmem g hg).1.1 h) rw [this] exact (hmem g hg).1.2 obtain ⟨g', hg', hmk⟩ := carrier_exists B Gs Im hImB hτ.le hN0 hImc hGsne have hg'1 := (hmem g' hg').1.1 obtain ⟨Gs₁, hGs₁⟩ : ∃ Gs₁ : Finset (ℂ × ℂ), Gs₁ = Gs.filter (fun g => τ ^ 2 * (B.card : ℝ) / 2 ≤ ((Im g ∩ Im g').card : ℝ)) := ⟨_, rfl⟩ rw [← hGs₁] at hmk have hGs₁sub : ∀ g ∈ Gs₁, g ∈ Gs ∧ τ ^ 2 * (B.card : ℝ) / 2 ≤ ((Im g ∩ Im g').card : ℝ) := by intro g hg rw [hGs₁] at hg exact mem_filter.mp hg -- the proper family obtain ⟨H, hH⟩ : ∃ H : Finset (ℂ × ℂ), H = Gs₁.image (hmap g') := ⟨_, rfl⟩ have hHcard : H.card = Gs₁.card := by rw [hH] exact card_image_of_injOn (fun a _ b _ h => hmap_inj hg'1 h) have hHnorm : ∀ h ∈ H, ‖h.1‖ = 1 := by intro h hh rw [hH] at hh obtain ⟨g, hg, rfl⟩ := mem_image.mp hh exact hmap_norm hg'1 (hmem g (hGs₁sub g hg).1).1.1 have hHc : k1 * (B.card : ℝ) ≤ (H.card : ℝ) := by rw [hHcard] have h1 : τ ^ 2 / 2 * (κ₁ * (B.card : ℝ)) ≤ τ ^ 2 / 2 * (Gs.card : ℝ) := mul_le_mul_of_nonneg_left hcon (by positivity) have e : k1 * (B.card : ℝ) = τ ^ 2 / 2 * (κ₁ * (B.card : ℝ)) := by rw [hk1]; ring linarith have hHdom : ∀ h ∈ H, k2 * (B.card : ℝ) ≤ ((isoDom B h).card : ℝ) := by intro h hh rw [hH] at hh obtain ⟨g, hg, rfl⟩ := mem_image.mp hh have h1 := (hGs₁sub g hg).2 have h2 : (Im g ∩ Im g').card ≤ (idom B (hmap g' g)).card := by rw [hIm] exact hmap_dom B hg'1 (hmem g (hGs₁sub g hg).1).1.1 have h3 : ((Im g ∩ Im g').card : ℝ) ≤ ((idom B (hmap g' g)).card : ℝ) := by exact_mod_cast h2 rw [← idom_eq] have e : k2 * (B.card : ℝ) = τ ^ 2 * (B.card : ℝ) / 2 := by rw [hk2]; ring linarith obtain ⟨z, H', hsub, hbig, hcomm⟩ := thm155_sub hk1pos hk2pos hT hHnorm hHc hHdom hN0 hNa hN8 hNM hM8 hM9 -- pull back obtain ⟨Gs2, hGs2⟩ : ∃ Gs2 : Finset (ℂ × ℂ), Gs2 = Gs₁.filter (fun g => hmap g' g ∈ H') := ⟨_, rfl⟩ have hGs2sub : ∀ g ∈ Gs2, g ∈ Gs ∧ hmap g' g ∈ H' := by intro g hg rw [hGs2] at hg obtain ⟨h1, h2⟩ := mem_filter.mp hg exact ⟨(hGs₁sub g h1).1, h2⟩ have hGs2card : H'.card ≤ Gs2.card := by have himg : H' ⊆ Gs2.image (hmap g') := by intro h hh have := hsub hh rw [hH] at this obtain ⟨g, hg, rfl⟩ := mem_image.mp this exact mem_image.mpr ⟨g, by rw [hGs2]; exact mem_filter.mpr ⟨hg, hh⟩, rfl⟩ exact le_trans (card_le_card himg) card_image_le have hcard : c₀ * (B.card : ℝ) ≤ (Gs2.card : ℝ) := by have h1 : k2 ^ 8 * (k1 * (B.card : ℝ)) / 36 ≤ k2 ^ 8 * (H.card : ℝ) / 36 := by have : k2 ^ 8 * (k1 * (B.card : ℝ)) ≤ k2 ^ 8 * (H.card : ℝ) := mul_le_mul_of_nonneg_left hHc (by positivity) linarith have e : c₀ * (B.card : ℝ) = k2 ^ 8 * (k1 * (B.card : ℝ)) / 36 := by rw [hc₀]; ring have h2 : (H'.card : ℝ) ≤ (Gs2.card : ℝ) := by exact_mod_cast hGs2card linarith have hne : Gs2.Nonempty := by have : (0 : ℝ) < (Gs2.card : ℝ) := lt_of_lt_of_le (by positivity) hcard exact card_pos.mp (by exact_mod_cast this) obtain ⟨g0, hg0⟩ := hne have hzs : ∀ g ∈ Gs2, iappc g z = iappc g0 z := by intro g hg rw [← hmap_comp hg'1 (g := g), ← hmap_comp hg'1 (g := g0)] have := hcomm _ (hGs2sub g hg).2 _ (hGs2sub g0 hg0).2 rw [iapp_eq, iapp_eq, this] exact common_image_contra B (δ₁ := θ * c₀ / 4) (θ := θ) (c₀ := c₀) hN0 (by positivity) hθ (by linarith) hn2 Gs2 (fun g => iappc g) (fun g hg a b => iappc_dq (hmem g (hGs2sub g hg).1).1.1 a b) z (iappc g0 z) hzs (fun g hg g' hg' p hp h => iappc_sep hp ((hzs g hg).trans (hzs g' hg').symm) h) hcard ⟨g0, hg0⟩ (fun g hg => (hmem g (hGs2sub g hg).1).2) end E94S /-! ### SOLO slice C4 -/ /-! ## SOLO module C (part 4): Claim U — explained pairs are structured, up to `ε n³` -/ namespace E94S open Finset theorem heavy_mono {B : Finset ℂ} {D D' : ℝ} (h : D ≤ D') {z : ℂ} {ρ : ℝ} (hh : Heavy B D' z ρ) : Heavy B D z ρ := le_trans h hh theorem struct_mono {B : Finset ℂ} {D D' : ℝ} (h : D ≤ D') {a b : ℂ} (hs : Struct B D' a b) : Struct B D a b := by obtain ⟨z, h1, h2⟩ := hs exact ⟨z, heavy_mono h h1, heavy_mono h h2⟩ theorem ucount_mono {B : Finset ℂ} {D D' : ℝ} (h : D ≤ D') (φ : ℂ → ℂ) : ucount B D φ ≤ ucount B D' φ := by classical unfold ucount refine card_le_card ?_ intro ab hab obtain ⟨h1, h2, h3⟩ := mem_filter.mp hab exact mem_filter.mpr ⟨h1, h2, fun hs => h3 (struct_mono h hs)⟩ open Classical in theorem sum_split_bound {α : Type*} (G : Finset α) (u : α → ℝ) {a b : ℝ} (hu : ∀ g ∈ G, u g ≤ b) (ha : 0 ≤ a) (hb : 0 ≤ b) : ∑ g ∈ G, u g ≤ ((G.filter (fun g => a < u g)).card : ℝ) * b + (G.card : ℝ) * a := by have hsp := sum_filter_add_sum_filter_not G (fun g => a < u g) u have h1 : ∑ g ∈ G.filter (fun g => a < u g), u g ≤ ((G.filter (fun g => a < u g)).card : ℝ) * b := by have := sum_le_sum (fun g (hg : g ∈ G.filter (fun g => a < u g)) => hu g (mem_filter.mp hg).1) rw [sum_const, nsmul_eq_mul] at this exact this have h2 : ∑ g ∈ G.filter (fun g => ¬ a < u g), u g ≤ (G.card : ℝ) * a := by have := sum_le_sum (fun g (hg : g ∈ G.filter (fun g => ¬ a < u g)) => not_lt.mp (mem_filter.mp hg).2) rw [sum_const, nsmul_eq_mul] at this have h3 : ((G.filter (fun g => ¬ a < u g)).card : ℝ) ≤ (G.card : ℝ) := by exact_mod_cast card_le_card (filter_subset _ _) nlinarith linarith /-- The number of rich isometries of one orientation, in closed form. -/ theorem rich_card_bound {c N T K τ : ℝ} (hτ : 0 < τ) (hN : 0 < N) (hT : T = τ * N) (hT2 : 2 ≤ T) (hc : c * (T * (T - 1)) ≤ K * N ^ 3) (hc0 : 0 ≤ c) : c * τ ^ 2 ≤ 2 * K * N := by have h1 : T * T / 2 ≤ T * (T - 1) := by nlinarith have h2 : c * (T * T / 2) ≤ K * N ^ 3 := le_trans (mul_le_mul_of_nonneg_left h1 hc0) hc rw [hT] at h2 have h3 : c * τ ^ 2 * (N * N) ≤ 2 * K * N * (N * N) := by nlinarith exact le_of_mul_le_mul_right h3 (by positivity) open Classical in /-- **Claim U.** In a large point set with property (T) and `O(n³)` equal-distance quadruples, all but `ε n³` of the quadruples `(a, b, c, d)` in which `(a, b)` is carried to `(c, d)` by a `τn`-rich isometry have `(a, b)` structured: both endpoints on `δ₁ n`-heavy circles about a common centre. -/ theorem claimU {ε τ K : ℝ} (hε : 0 < ε) (hτ : 0 < τ) (hτ1 : τ ≤ 1) (hK : 0 < K) : ∃ δ₁ : ℝ, 0 < δ₁ ∧ ∃ n₀ : ℕ, ∀ B : Finset ℂ, n₀ ≤ B.card → (∀ t : ℂ, t ≠ 0 → (B.filter (fun x => x + t ∈ B)).card ≤ 2) → ((QP B).card : ℝ) ≤ K * (B.card : ℝ) ^ 3 → (((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B (δ₁ * B.card) q.1 q.2.1 ∧ Expl B (τ * B.card) q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ ε * (B.card : ℝ) ^ 3 := by obtain ⟨θ, hθ⟩ : ∃ θ : ℝ, θ = ε * τ ^ 2 / (16 * K) := ⟨_, rfl⟩ have hθpos : 0 < θ := by rw [hθ]; positivity have hθK : θ * (16 * K) = ε * τ ^ 2 := by rw [hθ]; field_simp obtain ⟨δp, hδp, np, hp⟩ := bad_proper_few (κ₁ := ε / 8) (by positivity) hτ hτ1 hθpos obtain ⟨δm, hδm, nm, hm⟩ := bad_improper_few (κ₁ := ε / 8) (by positivity) hτ hτ1 hθpos refine ⟨min δp δm, lt_min hδp hδm, max (max np nm) (⌈2 / τ⌉₊ + 1), ?_⟩ intro B hn hT hQ have hnp : np ≤ B.card := le_trans (le_trans (le_max_left _ _) (le_max_left _ _)) hn have hnm : nm ≤ B.card := le_trans (le_trans (le_max_right _ _) (le_max_left _ _)) hn have hn2 : 2 ≤ τ * (B.card : ℝ) := by have h1 : 2 / τ ≤ (B.card : ℝ) := by have : ⌈2 / τ⌉₊ ≤ B.card := by have := le_trans (le_max_right _ _) hn; omega exact le_trans (Nat.le_ceil _) (by exact_mod_cast this) rw [div_le_iff₀ hτ] at h1 linarith have hN0 : (0 : ℝ) < B.card := by by_contra hcon push_neg at hcon have : τ * (B.card : ℝ) ≤ 0 := mul_nonpos_of_nonneg_of_nonpos hτ.le hcon linarith have hcov := expl_cover B (min δp δm * B.card) (τ * B.card) -- the proper sum have hN2 : (0 : ℝ) ≤ (B.card : ℝ) ^ 2 := by positivity have hθN : (0 : ℝ) ≤ θ * (B.card : ℝ) ^ 2 := by positivity have sp := sum_split_bound (Gp B (τ * B.card)) (fun g => (ucount B (min δp δm * B.card) (iapp g) : ℝ)) (a := θ * (B.card : ℝ) ^ 2) (b := (B.card : ℝ) ^ 2) (fun g _ => by exact_mod_cast ucount_le_sq B _ _) hθN hN2 have sm := sum_split_bound (Gm B (τ * B.card)) (fun g => (ucount B (min δp δm * B.card) (iappc g) : ℝ)) (a := θ * (B.card : ℝ) ^ 2) (b := (B.card : ℝ) ^ 2) (fun g _ => by exact_mod_cast ucount_le_sq B _ _) hθN hN2 have bp : (((Gp B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (min δp δm * B.card) (iapp g) : ℝ))).card : ℝ) ≤ ε / 8 * B.card := by refine le_trans ?_ (hp B hnp hT).le have hsub : (Gp B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (min δp δm * B.card) (iapp g) : ℝ)) ⊆ (Gp B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (δp * B.card) (iapp g) : ℝ)) := by intro g hg obtain ⟨h1, h2⟩ := mem_filter.mp hg refine mem_filter.mpr ⟨h1, lt_of_lt_of_le h2 ?_⟩ exact_mod_cast ucount_mono (mul_le_mul_of_nonneg_right (min_le_left _ _) hN0.le) (iapp g) exact_mod_cast card_le_card hsub have bm : (((Gm B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (min δp δm * B.card) (iappc g) : ℝ))).card : ℝ) ≤ ε / 8 * B.card := by refine le_trans ?_ (hm B hnm hT).le have hsub : (Gm B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (min δp δm * B.card) (iappc g) : ℝ)) ⊆ (Gm B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (δm * B.card) (iappc g) : ℝ)) := by intro g hg obtain ⟨h1, h2⟩ := mem_filter.mp hg refine mem_filter.mpr ⟨h1, lt_of_lt_of_le h2 ?_⟩ exact_mod_cast ucount_mono (mul_le_mul_of_nonneg_right (min_le_right _ _) hN0.le) (iappc g) exact_mod_cast card_le_card hsub have cp := rich_card_bound hτ hN0 rfl hn2 (le_trans (Gp_card B (by linarith)) hQ) (Nat.cast_nonneg _) have cm := rich_card_bound hτ hN0 rfl hn2 (le_trans (Gm_card B (by linarith)) hQ) (Nat.cast_nonneg _) -- |G|·θ·N² ≤ (ε/8) N³ have key : ∀ c : ℝ, 0 ≤ c → c * τ ^ 2 ≤ 2 * K * (B.card : ℝ) → c * (θ * (B.card : ℝ) ^ 2) ≤ ε / 8 * (B.card : ℝ) ^ 3 := by intro c _ hc have hτ2 : (0 : ℝ) < τ ^ 2 := by positivity have h1 : c * (θ * (B.card : ℝ) ^ 2) * τ ^ 2 ≤ ε / 8 * (B.card : ℝ) ^ 3 * τ ^ 2 := by have e1 : c * (θ * (B.card : ℝ) ^ 2) * τ ^ 2 = (c * τ ^ 2) * (θ * (B.card : ℝ) ^ 2) := by ring have e2 : (c * τ ^ 2) * (θ * (B.card : ℝ) ^ 2) ≤ (2 * K * (B.card : ℝ)) * (θ * (B.card : ℝ) ^ 2) := mul_le_mul_of_nonneg_right hc hθN have e3 : (2 * K * (B.card : ℝ)) * (θ * (B.card : ℝ) ^ 2) = (θ * (16 * K)) / 8 * (B.card : ℝ) ^ 3 := by ring rw [hθK] at e3 rw [e1] linarith exact le_of_mul_le_mul_right h1 hτ2 have kp := key _ (Nat.cast_nonneg (Gp B (τ * B.card)).card) cp have km := key _ (Nat.cast_nonneg (Gm B (τ * B.card)).card) cm have hcov' : (((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B (min δp δm * B.card) q.1 q.2.1 ∧ Expl B (τ * B.card) q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ ∑ g ∈ Gp B (τ * B.card), (ucount B (min δp δm * B.card) (iapp g) : ℝ) + ∑ g ∈ Gm B (τ * B.card), (ucount B (min δp δm * B.card) (iappc g) : ℝ) := by exact_mod_cast hcov have fp : ((Gp B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (min δp δm * B.card) (iapp g) : ℝ))).card * (B.card : ℝ) ^ 2 ≤ ε / 8 * (B.card : ℝ) ^ 3 := by have := mul_le_mul_of_nonneg_right bp hN2 nlinarith [this] have fm : ((Gm B (τ * B.card)).filter (fun g => θ * (B.card : ℝ) ^ 2 < (ucount B (min δp δm * B.card) (iappc g) : ℝ))).card * (B.card : ℝ) ^ 2 ≤ ε / 8 * (B.card : ℝ) ^ 3 := by have := mul_le_mul_of_nonneg_right bm hN2 nlinarith [this] have hN3 : (0 : ℝ) ≤ (B.card : ℝ) ^ 3 := by positivity nlinarith [hcov', sp, sm, fp, fm, kp, km] end E94S /-! ### SOLO slice D1 -/ /-! ## SOLO module D (part 1): the finite set of heavy circles -/ namespace E94S open Finset open Classical in /-- The points of `B` on the circle `C = (centre, squared radius)`. -/ noncomputable def cpts (B : Finset ℂ) (C : ℂ × ℝ) : Finset ℂ := B.filter (fun x => dq x C.1 = C.2) theorem mem_cpts {B : Finset ℂ} {C : ℂ × ℝ} {x : ℂ} : x ∈ cpts B C ↔ x ∈ B ∧ dq x C.1 = C.2 := by classical unfold cpts rw [mem_filter] theorem heavy_iff (B : Finset ℂ) (D : ℝ) (C : ℂ × ℝ) : Heavy B D C.1 C.2 ↔ D ≤ ((cpts B C).card : ℝ) := by classical unfold Heavy cpts rfl open Classical in /-- A circle through three points (a choice). -/ noncomputable def circOf (t : ℂ × ℂ × ℂ) : ℂ × ℝ := if h : ∃ C : ℂ × ℝ, dq t.1 C.1 = C.2 ∧ dq t.2.1 C.1 = C.2 ∧ dq t.2.2 C.1 = C.2 then Classical.choose h else (0, 0) theorem circOf_eq {x1 x2 x3 : ℂ} (hdet : cr3 x1 x2 x3 ≠ 0) {C : ℂ × ℝ} (h1 : dq x1 C.1 = C.2) (h2 : dq x2 C.1 = C.2) (h3 : dq x3 C.1 = C.2) : circOf (x1, x2, x3) = C := by classical have h : ∃ C : ℂ × ℝ, dq x1 C.1 = C.2 ∧ dq x2 C.1 = C.2 ∧ dq x3 C.1 = C.2 := ⟨C, h1, h2, h3⟩ unfold circOf simp only rw [dif_pos h] obtain ⟨k1, k2, k3⟩ := Classical.choose_spec h obtain ⟨e1, e2⟩ := circle_unique hdet k1 k2 k3 h1 h2 h3 exact Prod.ext e1 e2 open Classical in /-- The heavy circles of `B`. -/ noncomputable def HC (B : Finset ℂ) (D : ℝ) : Finset (ℂ × ℝ) := ((B ×ˢ B ×ˢ B).image circOf).filter (fun C => Heavy B D C.1 C.2) theorem HC_heavy {B : Finset ℂ} {D : ℝ} {C : ℂ × ℝ} (hC : C ∈ HC B D) : D ≤ ((cpts B C).card : ℝ) := by classical unfold HC at hC exact (heavy_iff B D C).mp (mem_filter.mp hC).2 theorem mem_HC {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {D : ℝ} (hD : 2 < D) {z : ℂ} {ρ : ℝ} (h : Heavy B D z ρ) : (z, ρ) ∈ HC B D := by classical have hc : D ≤ ((cpts B (z, ρ)).card : ℝ) := (heavy_iff B D (z, ρ)).mp h have h3 : 2 < (cpts B (z, ρ)).card := by have : (2 : ℝ) < ((cpts B (z, ρ)).card : ℝ) := lt_of_lt_of_le hD hc exact_mod_cast this obtain ⟨x1, h1, x2, h2, x3, h3', h12, h13, h23⟩ := two_lt_card.mp h3 obtain ⟨b1, e1⟩ := mem_cpts.mp h1 obtain ⟨b2, e2⟩ := mem_cpts.mp h2 obtain ⟨b3, e3⟩ := mem_cpts.mp h3' unfold HC refine mem_filter.mpr ⟨mem_image.mpr ⟨(x1, x2, x3), ?_, circOf_eq (hnc x1 b1 x2 b2 x3 b3 h12 h13 h23) e1 e2 e3⟩, h⟩ simp only [mem_product] exact ⟨b1, b2, b3⟩ /-- Two distinct circles share at most two points of `B`. -/ theorem cpts_inter_le_two {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {C C' : ℂ × ℝ} (hne : C ≠ C') : (cpts B C ∩ cpts B C').card ≤ 2 := by classical by_contra hcon push_neg at hcon obtain ⟨x1, h1, x2, h2, x3, h3, h12, h13, h23⟩ := two_lt_card.mp hcon obtain ⟨a1, a1'⟩ := mem_inter.mp h1 obtain ⟨a2, a2'⟩ := mem_inter.mp h2 obtain ⟨a3, a3'⟩ := mem_inter.mp h3 obtain ⟨b1, e1⟩ := mem_cpts.mp a1 obtain ⟨b2, e2⟩ := mem_cpts.mp a2 obtain ⟨b3, e3⟩ := mem_cpts.mp a3 obtain ⟨_, f1⟩ := mem_cpts.mp a1' obtain ⟨_, f2⟩ := mem_cpts.mp a2' obtain ⟨_, f3⟩ := mem_cpts.mp a3' obtain ⟨k1, k2⟩ := circle_unique (hnc x1 b1 x2 b2 x3 b3 h12 h13 h23) e1 e2 e3 f1 f2 f3 exact hne (Prod.ext k1 k2) /-- A heavy circle has positive squared radius. -/ theorem HC_pos {B : Finset ℂ} {D : ℝ} (hD : 1 < D) {C : ℂ × ℝ} (hC : C ∈ HC B D) : 0 < C.2 := by classical have hc := HC_heavy hC have h2 : 1 < (cpts B C).card := by have : (1 : ℝ) < ((cpts B C).card : ℝ) := lt_of_lt_of_le hD hc exact_mod_cast this obtain ⟨x, hx, y, hy, hxy⟩ := one_lt_card.mp h2 obtain ⟨_, ex⟩ := mem_cpts.mp hx obtain ⟨_, ey⟩ := mem_cpts.mp hy rcases lt_or_eq_of_le (show 0 ≤ C.2 by rw [← ex]; exact dq_nonneg _ _) with h | h · exact h · exfalso rw [← h] at ex ey exact hxy ((dq_eq_zero ex).trans (dq_eq_zero ey).symm) /-- Bonferroni for almost disjoint circles: `Σ |P(C)| ≤ |⋃ P(C)| + |𝒜|²`. -/ theorem sum_cpts_le {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) (A : Finset (ℂ × ℝ)) : ∑ C ∈ A, (cpts B C).card ≤ (A.biUnion (cpts B)).card + A.card ^ 2 := by classical induction A using Finset.induction_on with | empty => simp | insert C A hC ih => rw [sum_insert hC, biUnion_insert, card_insert_of_notMem hC] have h1 := card_union_add_card_inter (cpts B C) (A.biUnion (cpts B)) have h2 : (cpts B C ∩ A.biUnion (cpts B)).card ≤ 2 * A.card := by have hsub : cpts B C ∩ A.biUnion (cpts B) ⊆ A.biUnion (fun C' => cpts B C ∩ cpts B C') := by intro x hx obtain ⟨hx1, hx2⟩ := mem_inter.mp hx obtain ⟨C', hC', hx3⟩ := mem_biUnion.mp hx2 exact mem_biUnion.mpr ⟨C', hC', mem_inter.mpr ⟨hx1, hx3⟩⟩ refine le_trans (card_le_card hsub) (le_trans card_biUnion_le ?_) have : ∑ C' ∈ A, (cpts B C ∩ cpts B C').card ≤ ∑ _C' ∈ A, 2 := by refine sum_le_sum (fun C' hC' => cpts_inter_le_two hnc ?_) intro h; rw [h] at hC; exact hC hC' rw [sum_const, smul_eq_mul] at this omega nlinarith theorem sum_cpts_HC {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) (D : ℝ) : ∑ C ∈ HC B D, (cpts B C).card ≤ B.card + (HC B D).card ^ 2 := by classical refine le_trans (sum_cpts_le hnc (HC B D)) (Nat.add_le_add_right (card_le_card ?_) _) intro x hx obtain ⟨C, _, hxC⟩ := mem_biUnion.mp hx exact (mem_cpts.mp hxC).1 /-- There are few heavy circles: `|HC|·C(t,3) ≤ C(|B|,3)` for `3 ≤ t ≤ D`. -/ theorem HC_card {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {D : ℝ} {t : ℕ} (ht : 3 ≤ t) (htD : (t : ℝ) ≤ D) : (HC B D).card * t.choose 3 ≤ B.card.choose 3 := by classical have hdisj : ∀ C ∈ HC B D, ∀ C' ∈ HC B D, C ≠ C' → Disjoint (powersetCard 3 (cpts B C)) (powersetCard 3 (cpts B C')) := by intro C _ C' _ hne rw [disjoint_left] intro s hs hs' obtain ⟨h1, hc⟩ := mem_powersetCard.mp hs obtain ⟨h2, _⟩ := mem_powersetCard.mp hs' have : s ⊆ cpts B C ∩ cpts B C' := subset_inter h1 h2 have := card_le_card this have := cpts_inter_le_two hnc hne omega have hU : ((HC B D).biUnion (fun C => powersetCard 3 (cpts B C))).card = ∑ C ∈ HC B D, (powersetCard 3 (cpts B C)).card := card_biUnion hdisj have hsub : (HC B D).biUnion (fun C => powersetCard 3 (cpts B C)) ⊆ powersetCard 3 B := by intro s hs obtain ⟨C, _, hsC⟩ := mem_biUnion.mp hs obtain ⟨h1, hc⟩ := mem_powersetCard.mp hsC exact mem_powersetCard.mpr ⟨h1.trans (fun x hx => (mem_cpts.mp hx).1), hc⟩ have h1 := card_le_card hsub rw [hU, card_powersetCard] at h1 have h2 : ∑ _C ∈ HC B D, t.choose 3 ≤ ∑ C ∈ HC B D, (powersetCard 3 (cpts B C)).card := by refine sum_le_sum (fun C hC => ?_) rw [card_powersetCard] refine Nat.choose_le_choose 3 ?_ have : (t : ℝ) ≤ ((cpts B C).card : ℝ) := le_trans htD (HC_heavy hC) exact_mod_cast this rw [sum_const, smul_eq_mul] at h2 omega end E94S /-! ### SOLO slice D2 -/ /-! ## SOLO module D (part 2): class sizes on concentric circles; structured quadruples -/ namespace E94S open Finset open Classical in /-- On a circle, at most two points of `B` lie at a given distance from a point other than the centre. -/ theorem circle_dist_le_two {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) (C : ℂ × ℝ) {c : ℂ} (hc : c ≠ C.1) (u : ℝ) : ((cpts B C).filter (fun d => dq c d = u)).card ≤ 2 := by have hsub : (cpts B C).filter (fun d => dq c d = u) ⊆ cpts B C ∩ cpts B (c, u) := by intro d hd obtain ⟨h1, h2⟩ := mem_filter.mp hd refine mem_inter.mpr ⟨h1, mem_cpts.mpr ⟨(mem_cpts.mp h1).1, ?_⟩⟩ rw [dq_comm]; exact h2 refine le_trans (card_le_card hsub) (cpts_inter_le_two hnc ?_) intro h exact hc (by rw [h]) open Classical in /-- **Class size for two circles with a common centre**: the pairs `(c, d)` at a given distance. -/ theorem conc_class_le {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {C₃ C₄ : ℂ × ℝ} (hcen : C₃.1 = C₄.1) (h3 : 0 < C₃.2) (h4 : 0 < C₄.2) (u : ℝ) : ((cpts B C₃ ×ˢ cpts B C₄).filter (fun cd => dq cd.1 cd.2 = u)).card ≤ 2 * min (cpts B C₃).card (cpts B C₄).card := by have hne3 : ∀ c ∈ cpts B C₃, c ≠ C₄.1 := by intro c hc h have := (mem_cpts.mp hc).2 rw [h, hcen, dq_self] at this linarith have hne4 : ∀ d ∈ cpts B C₄, d ≠ C₃.1 := by intro d hd h have := (mem_cpts.mp hd).2 rw [h, ← hcen, dq_self] at this linarith have b1 : ((cpts B C₃ ×ˢ cpts B C₄).filter (fun cd => dq cd.1 cd.2 = u)).card ≤ 2 * (cpts B C₃).card := by have hsub : (cpts B C₃ ×ˢ cpts B C₄).filter (fun cd => dq cd.1 cd.2 = u) ⊆ (cpts B C₃).biUnion (fun c => ((cpts B C₄).filter (fun d => dq c d = u)).image (fun d => (c, d))) := by intro cd hcd obtain ⟨h1, h2⟩ := mem_filter.mp hcd obtain ⟨hc, hd⟩ := mem_product.mp h1 exact mem_biUnion.mpr ⟨cd.1, hc, mem_image.mpr ⟨cd.2, mem_filter.mpr ⟨hd, h2⟩, rfl⟩⟩ refine le_trans (card_le_card hsub) (le_trans card_biUnion_le ?_) have : ∑ c ∈ cpts B C₃, (((cpts B C₄).filter (fun d => dq c d = u)).image (fun d => (c, d))).card ≤ ∑ _c ∈ cpts B C₃, 2 := sum_le_sum (fun c hc => le_trans card_image_le (circle_dist_le_two hnc C₄ (hne3 c hc) u)) rw [sum_const, smul_eq_mul] at this omega have b2 : ((cpts B C₃ ×ˢ cpts B C₄).filter (fun cd => dq cd.1 cd.2 = u)).card ≤ 2 * (cpts B C₄).card := by have hsub : (cpts B C₃ ×ˢ cpts B C₄).filter (fun cd => dq cd.1 cd.2 = u) ⊆ (cpts B C₄).biUnion (fun d => ((cpts B C₃).filter (fun c => dq d c = u)).image (fun c => (c, d))) := by intro cd hcd obtain ⟨h1, h2⟩ := mem_filter.mp hcd obtain ⟨hc, hd⟩ := mem_product.mp h1 exact mem_biUnion.mpr ⟨cd.2, hd, mem_image.mpr ⟨cd.1, mem_filter.mpr ⟨hc, by rw [dq_comm]; exact h2⟩, rfl⟩⟩ refine le_trans (card_le_card hsub) (le_trans card_biUnion_le ?_) have : ∑ d ∈ cpts B C₄, (((cpts B C₃).filter (fun c => dq d c = u)).image (fun c => (c, d))).card ≤ ∑ _d ∈ cpts B C₄, 2 := sum_le_sum (fun d hd => le_trans card_image_le (circle_dist_le_two hnc C₃ (hne4 d hd) u)) rw [sum_const, smul_eq_mul] at this omega rcases le_total (cpts B C₃).card (cpts B C₄).card with h | h · rw [min_eq_left h]; exact b1 · rw [min_eq_right h]; exact b2 open Classical in /-- The quadruples with prescribed circles. -/ noncomputable def Eq4 (B : Finset ℂ) (C₁ C₂ C₃ C₄ : ℂ × ℝ) : Finset (ℂ × ℂ × ℂ × ℂ) := (QP B).filter (fun q => q.1 ∈ cpts B C₁ ∧ q.2.1 ∈ cpts B C₂ ∧ q.2.2.1 ∈ cpts B C₃ ∧ q.2.2.2 ∈ cpts B C₄) open Classical in /-- **Energy of two concentric circle pairs.** -/ theorem Eq4_card_le {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) (C₁ C₂ : ℂ × ℝ) {C₃ C₄ : ℂ × ℝ} (hcen : C₃.1 = C₄.1) (h3 : 0 < C₃.2) (h4 : 0 < C₄.2) : (Eq4 B C₁ C₂ C₃ C₄).card ≤ (cpts B C₁).card * (cpts B C₂).card * (2 * min (cpts B C₃).card (cpts B C₄).card) := by have hsub : Eq4 B C₁ C₂ C₃ C₄ ⊆ (cpts B C₁ ×ˢ cpts B C₂).biUnion (fun ab => ((cpts B C₃ ×ˢ cpts B C₄).filter (fun cd => dq cd.1 cd.2 = dq ab.1 ab.2)).image (fun cd => (ab.1, ab.2, cd.1, cd.2))) := by intro q hq unfold Eq4 at hq obtain ⟨hQ, h1, h2, h3', h4'⟩ := mem_filter.mp hq unfold QP at hQ obtain ⟨_, _, _, hd⟩ := mem_filter.mp hQ exact mem_biUnion.mpr ⟨(q.1, q.2.1), mem_product.mpr ⟨h1, h2⟩, mem_image.mpr ⟨(q.2.2.1, q.2.2.2), mem_filter.mpr ⟨mem_product.mpr ⟨h3', h4'⟩, hd.symm⟩, rfl⟩⟩ refine le_trans (card_le_card hsub) (le_trans card_biUnion_le ?_) have : ∑ ab ∈ cpts B C₁ ×ˢ cpts B C₂, (((cpts B C₃ ×ˢ cpts B C₄).filter (fun cd => dq cd.1 cd.2 = dq ab.1 ab.2)).image (fun cd => (ab.1, ab.2, cd.1, cd.2))).card ≤ ∑ _ab ∈ cpts B C₁ ×ˢ cpts B C₂, 2 * min (cpts B C₃).card (cpts B C₄).card := sum_le_sum (fun ab _ => le_trans card_image_le (conc_class_le hnc hcen h3 h4 _)) rw [sum_const, card_product, smul_eq_mul] at this exact this open Classical in /-- The pairs of heavy circles with a common centre (including a circle paired with itself). -/ noncomputable def Conc (B : Finset ℂ) (D : ℝ) : Finset ((ℂ × ℝ) × (ℂ × ℝ)) := ((HC B D) ×ˢ (HC B D)).filter (fun P => P.1.1 = P.2.1) open Classical in /-- **Structured quadruples are covered by concentric circle pairs.** -/ theorem struct_cover {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {D : ℝ} (hD : 2 < D) : (QP B).filter (fun q => Struct B D q.1 q.2.1 ∧ Struct B D q.2.2.1 q.2.2.2) ⊆ ((Conc B D) ×ˢ (Conc B D)).biUnion (fun PP => Eq4 B PP.1.1 PP.1.2 PP.2.1 PP.2.2) := by intro q hq obtain ⟨hQ, ⟨z, hz1, hz2⟩, ⟨z', hz1', hz2'⟩⟩ := mem_filter.mp hq have hQ' := hQ unfold QP at hQ' obtain ⟨hmem, _⟩ := mem_filter.mp hQ' simp only [mem_product] at hmem obtain ⟨ha, hb, hc, hd⟩ := hmem refine mem_biUnion.mpr ⟨(((z, dq q.1 z), (z, dq q.2.1 z)), ((z', dq q.2.2.1 z'), (z', dq q.2.2.2 z'))), ?_, ?_⟩ · unfold Conc refine mem_product.mpr ⟨mem_filter.mpr ⟨mem_product.mpr ⟨mem_HC hnc hD hz1, mem_HC hnc hD hz2⟩, rfl⟩, mem_filter.mpr ⟨mem_product.mpr ⟨mem_HC hnc hD hz1', mem_HC hnc hD hz2'⟩, rfl⟩⟩ · unfold Eq4 exact mem_filter.mpr ⟨hQ, mem_cpts.mpr ⟨ha, rfl⟩, mem_cpts.mpr ⟨hb, rfl⟩, mem_cpts.mpr ⟨hc, rfl⟩, mem_cpts.mpr ⟨hd, rfl⟩⟩ end E94S /-! ### SOLO slice D3a -/ /-! ## SOLO module D (part 3a): the abstract inequality of the endgame -/ namespace E94S open Finset theorem sum_sq_le_sq' {ι : Type*} (s : Finset ι) (N : ι → ℝ) (hN : ∀ a ∈ s, 0 ≤ N a) : ∑ a ∈ s, N a ^ 2 ≤ (∑ a ∈ s, N a) ^ 2 := by classical induction s using Finset.induction_on with | empty => simp | insert x s hx ih => rw [sum_insert hx, sum_insert hx] have h1 := ih (fun a ha => hN a (mem_insert_of_mem ha)) have h2 : 0 ≤ ∑ a ∈ s, N a := sum_nonneg (fun a ha => hN a (mem_insert_of_mem ha)) have h3 := hN x (mem_insert_self x s) nlinarith /-- `3·(ΣN)(ΣN²) ≤ (ΣN)³ + 2ΣN³` for nonnegative reals. -/ theorem abs1 {ι : Type*} (s : Finset ι) (N : ι → ℝ) (hN : ∀ a ∈ s, 0 ≤ N a) : 3 * ((∑ a ∈ s, N a) * ∑ a ∈ s, N a ^ 2) ≤ (∑ a ∈ s, N a) ^ 3 + 2 * ∑ a ∈ s, N a ^ 3 := by classical induction s using Finset.induction_on with | empty => simp | insert x s hx ih => rw [sum_insert hx, sum_insert hx, sum_insert hx] have h1 := ih (fun a ha => hN a (mem_insert_of_mem ha)) have h2 := sum_sq_le_sq' s N (fun a ha => hN a (mem_insert_of_mem ha)) have h3 := hN x (mem_insert_self x s) have h4 : 0 ≤ ∑ a ∈ s, N a := sum_nonneg (fun a ha => hN a (mem_insert_of_mem ha)) have h5 : 0 ≤ N x * ((∑ a ∈ s, N a) ^ 2 - ∑ a ∈ s, N a ^ 2) := mul_nonneg h3 (by linarith) nlinarith theorem abs2 {m N : ℝ} (hN : 0 ≤ N) : 2 * min m N * N ^ 2 ≤ 4 / 3 * N ^ 3 + 2 / 3 * m * N ^ 2 := by have hN2 : 0 ≤ N ^ 2 := by positivity rcases le_total m N with h | h · rw [min_eq_left h] nlinarith [mul_le_mul_of_nonneg_right h hN2] · rw [min_eq_right h] nlinarith [mul_le_mul_of_nonneg_right h hN2] /-- **The abstract endgame inequality.** -/ theorem abs3 {ι : Type*} (s : Finset ι) (N : ι → ℝ) (hN : ∀ a ∈ s, 0 ≤ N a) {m : ℝ} (hm : 0 ≤ m) : ∑ a ∈ s, (2 * min m (N a) * N a ^ 2 + 4 * (N a ^ 2 * ((∑ b ∈ s, N b) - N a))) ≤ 4 / 3 * (∑ a ∈ s, N a) ^ 3 + 2 / 3 * m * (∑ a ∈ s, N a) ^ 2 := by have h1 := abs1 s N hN have h2 := sum_sq_le_sq' s N hN have h3 : ∑ a ∈ s, 2 * min m (N a) * N a ^ 2 ≤ 4 / 3 * ∑ a ∈ s, N a ^ 3 + 2 / 3 * m * ∑ a ∈ s, N a ^ 2 := by rw [mul_sum, mul_sum, ← sum_add_distrib] refine sum_le_sum (fun a ha => ?_) have := abs2 (m := m) (hN a ha) linarith have h4 : ∑ a ∈ s, 4 * (N a ^ 2 * ((∑ b ∈ s, N b) - N a)) = 4 * ((∑ a ∈ s, N a) * ∑ a ∈ s, N a ^ 2) - 4 * ∑ a ∈ s, N a ^ 3 := by rw [← mul_sum, mul_sum (s := s) (a := ∑ a ∈ s, N a), ← mul_sub, ← sum_sub_distrib] congr 1 refine sum_congr rfl (fun a _ => ?_) ring rw [sum_add_distrib, h4] have h5 : 2 / 3 * m * ∑ a ∈ s, N a ^ 2 ≤ 2 / 3 * m * (∑ a ∈ s, N a) ^ 2 := mul_le_mul_of_nonneg_left h2 (by positivity) linarith end E94S /-! ### SOLO slice D3b -/ /-! ## SOLO module D (part 3b): radius classes of heavy circles -/ namespace E94S open Finset open Classical in /-- The number of incidences of `B` with the heavy circles of squared radius `a`. -/ noncomputable def Nr (B : Finset ℂ) (D : ℝ) (a : ℝ) : ℝ := ∑ C ∈ (HC B D).filter (fun C => C.2 = a), ((cpts B C).card : ℝ) theorem Nr_nonneg (B : Finset ℂ) (D a : ℝ) : 0 ≤ Nr B D a := by unfold Nr exact sum_nonneg (fun _ _ => Nat.cast_nonneg _) theorem p_le_Nr {B : Finset ℂ} {D : ℝ} {C : ℂ × ℝ} (hC : C ∈ HC B D) : ((cpts B C).card : ℝ) ≤ Nr B D C.2 := by classical unfold Nr exact single_le_sum (f := fun C : ℂ × ℝ => ((cpts B C).card : ℝ)) (fun _ _ => Nat.cast_nonneg _) (mem_filter.mpr ⟨hC, rfl⟩) open Classical in /-- The total number of incidences with heavy circles. -/ theorem sum_Nr (B : Finset ℂ) (D : ℝ) : ∑ a ∈ (HC B D).image Prod.snd, Nr B D a = ∑ C ∈ HC B D, ((cpts B C).card : ℝ) := by unfold Nr exact sum_fiberwise_of_maps_to (fun C hC => mem_image_of_mem Prod.snd hC) _ open Classical in /-- Fibrewise sum of a function of the radius. -/ theorem sum_radius (B : Finset ℂ) (D : ℝ) (φ : ℝ → ℝ) : ∑ C ∈ HC B D, ((cpts B C).card : ℝ) * φ C.2 = ∑ a ∈ (HC B D).image Prod.snd, Nr B D a * φ a := by rw [← sum_fiberwise_of_maps_to (g := Prod.snd) (t := (HC B D).image Prod.snd) (fun C hC => mem_image_of_mem Prod.snd hC)] refine sum_congr rfl (fun a _ => ?_) unfold Nr rw [sum_mul] refine sum_congr rfl (fun C hC => ?_) rw [(mem_filter.mp hC).2] open Classical in /-- Concentric partners with prescribed radii: the sum of the smaller sizes is at most each radius class. -/ theorem conc_min_le (B : Finset ℂ) (D a b : ℝ) : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), (min ((cpts B P.1).card : ℝ) ((cpts B P.2).card : ℝ)) ≤ min (Nr B D a) (Nr B D b) := by have hmem : ∀ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), P.1 ∈ HC B D ∧ P.2 ∈ HC B D ∧ P.1.1 = P.2.1 ∧ P.1.2 = a ∧ P.2.2 = b := by intro P hP obtain ⟨h1, h2, h3⟩ := mem_filter.mp hP unfold Conc at h1 obtain ⟨h4, h5⟩ := mem_filter.mp h1 exact ⟨(mem_product.mp h4).1, (mem_product.mp h4).2, h5, h2, h3⟩ refine le_min ?_ ?_ · have h1 : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), (min ((cpts B P.1).card : ℝ) ((cpts B P.2).card : ℝ)) ≤ ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), ((cpts B P.1).card : ℝ) := sum_le_sum (fun P _ => min_le_left _ _) have h2 : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), ((cpts B P.1).card : ℝ) = ∑ C ∈ ((Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b)).image Prod.fst, ((cpts B C).card : ℝ) := by rw [sum_image] intro P hP P' hP' h obtain ⟨_, _, e1, _, e2⟩ := hmem P hP obtain ⟨_, _, e1', _, e2'⟩ := hmem P' hP' refine Prod.ext h (Prod.ext ?_ ?_) · rw [← e1, ← e1', h] · rw [e2, e2'] have h3 : ∑ C ∈ ((Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b)).image Prod.fst, ((cpts B C).card : ℝ) ≤ Nr B D a := by unfold Nr refine sum_le_sum_of_subset_of_nonneg ?_ (fun _ _ _ => Nat.cast_nonneg _) intro C hC obtain ⟨P, hP, rfl⟩ := mem_image.mp hC obtain ⟨g1, _, _, g2, _⟩ := hmem P hP exact mem_filter.mpr ⟨g1, g2⟩ linarith · have h1 : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), (min ((cpts B P.1).card : ℝ) ((cpts B P.2).card : ℝ)) ≤ ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), ((cpts B P.2).card : ℝ) := sum_le_sum (fun P _ => min_le_right _ _) have h2 : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b), ((cpts B P.2).card : ℝ) = ∑ C ∈ ((Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b)).image Prod.snd, ((cpts B C).card : ℝ) := by rw [sum_image] intro P hP P' hP' h obtain ⟨_, _, e1, e2, _⟩ := hmem P hP obtain ⟨_, _, e1', e2', _⟩ := hmem P' hP' refine Prod.ext (Prod.ext ?_ ?_) h · rw [e1, e1', h] · rw [e2, e2'] have h3 : ∑ C ∈ ((Conc B D).filter (fun P => P.1.2 = a ∧ P.2.2 = b)).image Prod.snd, ((cpts B C).card : ℝ) ≤ Nr B D b := by unfold Nr refine sum_le_sum_of_subset_of_nonneg ?_ (fun _ _ _ => Nat.cast_nonneg _) intro C hC obtain ⟨P, hP, rfl⟩ := mem_image.mp hC obtain ⟨_, g1, _, _, g2⟩ := hmem P hP exact mem_filter.mpr ⟨g1, g2⟩ linarith /-- The radii of two concentric pairs match (in one of the two orders). -/ def Mt (P P' : (ℂ × ℝ) × (ℂ × ℝ)) : Prop := (P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2) ∨ (P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2) open Classical in /-- The matched partners of a concentric pair: total of twice the smaller sizes. -/ theorem matched_partner_le (B : Finset ℂ) (D : ℝ) (P : (ℂ × ℝ) × (ℂ × ℝ)) : ∑ P' ∈ (Conc B D).filter (fun P' => Mt P P'), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) ≤ if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2 := by have hnn : ∀ P' : (ℂ × ℝ) × (ℂ × ℝ), (0 : ℝ) ≤ 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) := by intro P' have : (0 : ℝ) ≤ min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ) := le_min (Nat.cast_nonneg _) (Nat.cast_nonneg _) linarith by_cases hab : P.1.2 = P.2.2 · rw [if_pos hab] have hsub : (Conc B D).filter (fun P' => Mt P P') ⊆ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.1.2) := by intro P' hP' obtain ⟨h1, h2⟩ := mem_filter.mp hP' refine mem_filter.mpr ⟨h1, ?_⟩ rcases h2 with ⟨e1, e2⟩ | ⟨e1, e2⟩ · exact ⟨e1, by rw [e2, hab]⟩ · exact ⟨by rw [e1, hab], e2⟩ have h1 := sum_le_sum_of_subset_of_nonneg hsub (fun P' _ _ => hnn P') have h2 := conc_min_le B D P.1.2 P.1.2 rw [min_self] at h2 have h3 : ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.1.2), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) = 2 * ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.1.2), (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) := by rw [mul_sum] linarith · rw [if_neg hab] have hsub : (Conc B D).filter (fun P' => Mt P P') ⊆ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2) ∪ (Conc B D).filter (fun P' => P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2) := by intro P' hP' obtain ⟨h1, h2⟩ := mem_filter.mp hP' rcases h2 with h | h · exact mem_union_left _ (mem_filter.mpr ⟨h1, h⟩) · exact mem_union_right _ (mem_filter.mpr ⟨h1, h⟩) have h1 := sum_le_sum_of_subset_of_nonneg hsub (fun P' _ _ => hnn P') have h2 : ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2) ∪ (Conc B D).filter (fun P' => P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) ≤ ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) + ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) := by have := sum_union_inter (s₁ := (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2)) (s₂ := (Conc B D).filter (fun P' => P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2)) (f := fun P' => 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ))) have h0 : (0 : ℝ) ≤ ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2) ∩ (Conc B D).filter (fun P' => P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) := sum_nonneg (fun P' _ => hnn P') linarith have h3 := conc_min_le B D P.1.2 P.2.2 have h4 := conc_min_le B D P.2.2 P.1.2 have h3' := le_trans h3 (min_le_left _ _) have h4' := le_trans h4 (min_le_right _ _) have e3 : ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) = 2 * ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2), (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) := by rw [mul_sum] have e4 : ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2), 2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) = 2 * ∑ P' ∈ (Conc B D).filter (fun P' => P'.1.2 = P.2.2 ∧ P'.2.2 = P.1.2), (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ)) := by rw [mul_sum] linarith end E94S /-! ### SOLO slice D3c -/ /-! ## SOLO module D (part 3c): the matched part of the structured energy -/ namespace E94S open Finset theorem mem_Conc {B : Finset ℂ} {D : ℝ} {P : (ℂ × ℝ) × (ℂ × ℝ)} : P ∈ Conc B D ↔ P.1 ∈ HC B D ∧ P.2 ∈ HC B D ∧ P.1.1 = P.2.1 := by classical unfold Conc rw [mem_filter, mem_product, and_assoc] open Classical in /-- Concentric partners of a different radius carry at most `X - N(a)` incidences. -/ theorem partner_sum_le (B : Finset ℂ) (D : ℝ) (z : ℂ) (a : ℝ) : ∑ C ∈ (HC B D).filter (fun C => z = C.1 ∧ a ≠ C.2), ((cpts B C).card : ℝ) ≤ (∑ b ∈ (HC B D).image Prod.snd, Nr B D b) - Nr B D a := by have h1 : ∑ C ∈ (HC B D).filter (fun C => z = C.1 ∧ a ≠ C.2), ((cpts B C).card : ℝ) ≤ ∑ C ∈ (HC B D).filter (fun C => z = C.1 ∧ a ≠ C.2), Nr B D C.2 := sum_le_sum (fun C hC => p_le_Nr (mem_filter.mp hC).1) have h2 : ∑ C ∈ (HC B D).filter (fun C => z = C.1 ∧ a ≠ C.2), Nr B D C.2 = ∑ b ∈ ((HC B D).filter (fun C => z = C.1 ∧ a ≠ C.2)).image Prod.snd, Nr B D b := by rw [sum_image] intro C hC C' hC' h have e1 := (mem_filter.mp hC).2.1 have e2 := (mem_filter.mp hC').2.1 exact Prod.ext (e1.symm.trans e2) h have h3 : ∑ b ∈ ((HC B D).filter (fun C => z = C.1 ∧ a ≠ C.2)).image Prod.snd, Nr B D b ≤ ∑ b ∈ ((HC B D).image Prod.snd).erase a, Nr B D b := by refine sum_le_sum_of_subset_of_nonneg ?_ (fun _ _ _ => Nr_nonneg B D _) intro b hb obtain ⟨C, hC, rfl⟩ := mem_image.mp hb obtain ⟨g1, _, g2⟩ := mem_filter.mp hC exact mem_erase.mpr ⟨Ne.symm g2, mem_image_of_mem Prod.snd g1⟩ have h4 : ∑ b ∈ ((HC B D).image Prod.snd).erase a, Nr B D b = (∑ b ∈ (HC B D).image Prod.snd, Nr B D b) - Nr B D a := by by_cases ha : a ∈ (HC B D).image Prod.snd · rw [sum_erase_eq_sub ha] · rw [erase_eq_of_notMem ha] have : Nr B D a = 0 := by unfold Nr apply sum_eq_zero intro C hC exfalso obtain ⟨g1, g2⟩ := mem_filter.mp hC exact ha (mem_image.mpr ⟨C, g1, g2⟩) rw [this, sub_zero] linarith open Classical in /-- **The matched part.** With `X` the number of incidences with heavy circles and `m` a bound for the size of each heavy circle, the quadruples on concentric circle pairs with matching radii number at most `(4/3)X³ + (2/3)mX²`. -/ theorem matched_bound {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {D : ℝ} (hD : 1 < D) {m : ℝ} (hm0 : 0 ≤ m) (hm : ∀ C ∈ HC B D, ((cpts B C).card : ℝ) ≤ m) : ∑ PP ∈ ((Conc B D) ×ˢ (Conc B D)).filter (fun PP => Mt PP.1 PP.2), ((Eq4 B PP.1.1 PP.1.2 PP.2.1 PP.2.2).card : ℝ) ≤ 4 / 3 * (∑ C ∈ HC B D, ((cpts B C).card : ℝ)) ^ 3 + 2 / 3 * m * (∑ C ∈ HC B D, ((cpts B C).card : ℝ)) ^ 2 := by obtain ⟨X, hX⟩ : ∃ X : ℝ, X = ∑ b ∈ (HC B D).image Prod.snd, Nr B D b := ⟨_, rfl⟩ have hXs : X = ∑ C ∈ HC B D, ((cpts B C).card : ℝ) := by rw [hX]; exact sum_Nr B D rw [← hXs] -- step 1: for each concentric pair have step1 : ∀ P ∈ Conc B D, ∑ P' ∈ (Conc B D).filter (fun P' => Mt P P'), ((Eq4 B P.1 P.2 P'.1 P'.2).card : ℝ) ≤ ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2) := by intro P _ have h1 : ∑ P' ∈ (Conc B D).filter (fun P' => Mt P P'), ((Eq4 B P.1 P.2 P'.1 P'.2).card : ℝ) ≤ ∑ P' ∈ (Conc B D).filter (fun P' => Mt P P'), ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (2 * (min ((cpts B P'.1).card : ℝ) ((cpts B P'.2).card : ℝ))) := by refine sum_le_sum (fun P' hP' => ?_) obtain ⟨g1, g2, g3⟩ := mem_Conc.mp (mem_filter.mp hP').1 have := Eq4_card_le hnc P.1 P.2 g3 (HC_pos hD g1) (HC_pos hD g2) have h' : ((Eq4 B P.1 P.2 P'.1 P'.2).card : ℝ) ≤ (((cpts B P.1).card * (cpts B P.2).card * (2 * min (cpts B P'.1).card (cpts B P'.2).card) : ℕ) : ℝ) := by exact_mod_cast this push_cast at h' exact h' rw [← mul_sum] at h1 refine le_trans h1 (mul_le_mul_of_nonneg_left (matched_partner_le B D P) (by positivity)) -- step 2: sum over concentric pairs have step2 : ∑ PP ∈ ((Conc B D) ×ˢ (Conc B D)).filter (fun PP => Mt PP.1 PP.2), ((Eq4 B PP.1.1 PP.1.2 PP.2.1 PP.2.2).card : ℝ) ≤ ∑ P ∈ Conc B D, ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2) := by rw [sum_filter, sum_product] refine sum_le_sum (fun P hP => ?_) rw [← sum_filter] exact step1 P hP -- step 3: equal radii have hsp := sum_filter_add_sum_filter_not (Conc B D) (fun P => P.1.2 = P.2.2) (fun P => ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2)) have hdiag : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = P.2.2), ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2) ≤ ∑ a ∈ (HC B D).image Prod.snd, Nr B D a * (min m (Nr B D a) * (2 * Nr B D a)) := by rw [← sum_radius B D (fun a => min m (Nr B D a) * (2 * Nr B D a))] have hPeq : ∀ P ∈ (Conc B D).filter (fun P => P.1.2 = P.2.2), P.1 ∈ HC B D ∧ P.2 = P.1 := by intro P hP obtain ⟨h1, h2⟩ := mem_filter.mp hP obtain ⟨g1, _, g3⟩ := mem_Conc.mp h1 exact ⟨g1, Prod.ext g3.symm h2.symm⟩ have e1 : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = P.2.2), ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2) = ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = P.2.2), ((cpts B P.1).card : ℝ) * ((cpts B P.1).card : ℝ) * (2 * Nr B D P.1.2) := by refine sum_congr rfl (fun P hP => ?_) rw [(hPeq P hP).2] simp have e2 : ∑ P ∈ (Conc B D).filter (fun P => P.1.2 = P.2.2), ((cpts B P.1).card : ℝ) * ((cpts B P.1).card : ℝ) * (2 * Nr B D P.1.2) = ∑ C ∈ ((Conc B D).filter (fun P => P.1.2 = P.2.2)).image Prod.fst, ((cpts B C).card : ℝ) * ((cpts B C).card : ℝ) * (2 * Nr B D C.2) := by rw [sum_image] intro P hP P' hP' h exact Prod.ext h (by rw [(hPeq P hP).2, (hPeq P' hP').2, h]) have e3 : ∑ C ∈ ((Conc B D).filter (fun P => P.1.2 = P.2.2)).image Prod.fst, ((cpts B C).card : ℝ) * ((cpts B C).card : ℝ) * (2 * Nr B D C.2) ≤ ∑ C ∈ HC B D, ((cpts B C).card : ℝ) * ((cpts B C).card : ℝ) * (2 * Nr B D C.2) := by refine sum_le_sum_of_subset_of_nonneg ?_ (fun C _ _ => ?_) · intro C hC obtain ⟨P, hP, rfl⟩ := mem_image.mp hC exact (hPeq P hP).1 · have := Nr_nonneg B D C.2 positivity have e4 : ∑ C ∈ HC B D, ((cpts B C).card : ℝ) * ((cpts B C).card : ℝ) * (2 * Nr B D C.2) ≤ ∑ C ∈ HC B D, ((cpts B C).card : ℝ) * (min m (Nr B D C.2) * (2 * Nr B D C.2)) := by refine sum_le_sum (fun C hC => ?_) have h1 : ((cpts B C).card : ℝ) ≤ min m (Nr B D C.2) := le_min (hm C hC) (p_le_Nr hC) have h2 := Nr_nonneg B D C.2 have h3 : (0 : ℝ) ≤ ((cpts B C).card : ℝ) := Nat.cast_nonneg _ have h4 : ((cpts B C).card : ℝ) * (2 * Nr B D C.2) ≤ min m (Nr B D C.2) * (2 * Nr B D C.2) := mul_le_mul_of_nonneg_right h1 (by positivity) nlinarith [mul_le_mul_of_nonneg_left h4 h3] linarith -- step 4: different radii have hoff : ∑ P ∈ (Conc B D).filter (fun P => ¬ P.1.2 = P.2.2), ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2) ≤ ∑ a ∈ (HC B D).image Prod.snd, Nr B D a * (4 * Nr B D a * (X - Nr B D a)) := by rw [← sum_radius B D (fun a => 4 * Nr B D a * (X - Nr B D a))] have e1 : ∑ P ∈ (Conc B D).filter (fun P => ¬ P.1.2 = P.2.2), ((cpts B P.1).card : ℝ) * ((cpts B P.2).card : ℝ) * (if P.1.2 = P.2.2 then 2 * Nr B D P.1.2 else 4 * Nr B D P.1.2) = ∑ C₁ ∈ HC B D, ∑ C₂ ∈ (HC B D).filter (fun C₂ => C₁.1 = C₂.1 ∧ C₁.2 ≠ C₂.2), ((cpts B C₁).card : ℝ) * ((cpts B C₂).card : ℝ) * (4 * Nr B D C₁.2) := by have : (Conc B D).filter (fun P => ¬ P.1.2 = P.2.2) = ((HC B D) ×ˢ (HC B D)).filter (fun P => P.1.1 = P.2.1 ∧ P.1.2 ≠ P.2.2) := by unfold Conc rw [filter_filter] rw [this, sum_filter, sum_product] refine sum_congr rfl (fun C₁ _ => ?_) rw [sum_filter] refine sum_congr rfl (fun C₂ _ => ?_) by_cases h : C₁.1 = C₂.1 ∧ C₁.2 ≠ C₂.2 · rw [if_pos h, if_pos h, if_neg h.2] · rw [if_neg h, if_neg h] rw [e1] refine sum_le_sum (fun C₁ hC₁ => ?_) have h1 : ∑ C₂ ∈ (HC B D).filter (fun C₂ => C₁.1 = C₂.1 ∧ C₁.2 ≠ C₂.2), ((cpts B C₁).card : ℝ) * ((cpts B C₂).card : ℝ) * (4 * Nr B D C₁.2) = ((cpts B C₁).card : ℝ) * (4 * Nr B D C₁.2) * ∑ C₂ ∈ (HC B D).filter (fun C₂ => C₁.1 = C₂.1 ∧ C₁.2 ≠ C₂.2), ((cpts B C₂).card : ℝ) := by rw [mul_sum] refine sum_congr rfl (fun C₂ _ => ?_) ring rw [h1] have h2 := partner_sum_le B D C₁.1 C₁.2 rw [← hX] at h2 have h3 : (0 : ℝ) ≤ ((cpts B C₁).card : ℝ) * (4 * Nr B D C₁.2) := by have := Nr_nonneg B D C₁.2 positivity nlinarith [mul_le_mul_of_nonneg_left h2 h3] -- step 5: the abstract inequality have habs := abs3 ((HC B D).image Prod.snd) (Nr B D) (fun a _ => Nr_nonneg B D a) hm0 rw [← hX] at habs have hcomb : ∑ a ∈ (HC B D).image Prod.snd, Nr B D a * (min m (Nr B D a) * (2 * Nr B D a)) + ∑ a ∈ (HC B D).image Prod.snd, Nr B D a * (4 * Nr B D a * (X - Nr B D a)) = ∑ a ∈ (HC B D).image Prod.snd, (2 * min m (Nr B D a) * Nr B D a ^ 2 + 4 * (Nr B D a ^ 2 * (X - Nr B D a))) := by rw [← sum_add_distrib] refine sum_congr rfl (fun a _ => ?_) ring linarith end E94S /-! ### SOLO slice D4 -/ /-! ## SOLO module D (part 4): the unmatched part of the structured energy -/ namespace E94S open Finset open Classical in /-- A proper isometry sends at most two points of a circle into a circle of a different radius. -/ theorem circ_iso_le_two {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) {C C' : ℂ × ℝ} (hne : C.2 ≠ C'.2) : ((cpts B C).filter (fun a => iapp g a ∈ cpts B C')).card ≤ 2 := by obtain ⟨w, hw⟩ : ∃ w : ℂ, w = (starRingEnd ℂ) g.1 * (C'.1 - g.2) := ⟨_, rfl⟩ have hgw : iapp g w = C'.1 := by unfold iapp rw [hw] have h := conj_mul_self_of_norm hg linear_combination (C'.1 - g.2) * h have hsub : (cpts B C).filter (fun a => iapp g a ∈ cpts B C') ⊆ cpts B C ∩ cpts B (w, C'.2) := by intro a ha obtain ⟨h1, h2⟩ := mem_filter.mp ha refine mem_inter.mpr ⟨h1, mem_cpts.mpr ⟨(mem_cpts.mp h1).1, ?_⟩⟩ have := (mem_cpts.mp h2).2 rw [← hgw, iapp_dq hg] at this exact this refine le_trans (card_le_card hsub) (cpts_inter_le_two hnc ?_) intro h exact hne (by rw [h]) open Classical in /-- An improper isometry sends at most two points of a circle into a circle of a different radius. -/ theorem circ_isoc_le_two {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {g : ℂ × ℂ} (hg : ‖g.1‖ = 1) {C C' : ℂ × ℝ} (hne : C.2 ≠ C'.2) : ((cpts B C).filter (fun a => iappc g a ∈ cpts B C')).card ≤ 2 := by obtain ⟨w, hw⟩ : ∃ w : ℂ, w = (starRingEnd ℂ) ((starRingEnd ℂ) g.1 * (C'.1 - g.2)) := ⟨_, rfl⟩ have hgw : iappc g w = C'.1 := by unfold iappc rw [hw, Complex.conj_conj] have h := conj_mul_self_of_norm hg linear_combination (C'.1 - g.2) * h have hsub : (cpts B C).filter (fun a => iappc g a ∈ cpts B C') ⊆ cpts B C ∩ cpts B (w, C'.2) := by intro a ha obtain ⟨h1, h2⟩ := mem_filter.mp ha refine mem_inter.mpr ⟨h1, mem_cpts.mpr ⟨(mem_cpts.mp h1).1, ?_⟩⟩ have := (mem_cpts.mp h2).2 rw [← hgw, iappc_dq hg] at this exact this refine le_trans (card_le_card hsub) (cpts_inter_le_two hnc ?_) intro h exact hne (by rw [h]) open Classical in /-- Pairs carried by a map from two circles into two circles, when one of the two single counts is `≤ 2`. -/ theorem pair_count_le (B : Finset ℂ) (φ : ℂ → ℂ) (C₁ C₂ C₃ C₄ : ℂ × ℝ) (h : ((cpts B C₁).filter (fun a => φ a ∈ cpts B C₃)).card ≤ 2 ∨ ((cpts B C₂).filter (fun b => φ b ∈ cpts B C₄)).card ≤ 2) : ((cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => φ ab.1 ∈ cpts B C₃ ∧ φ ab.2 ∈ cpts B C₄)).card ≤ 2 * B.card := by have hb1 : (cpts B C₁).card ≤ B.card := card_le_card (fun x hx => (mem_cpts.mp hx).1) have hb2 : (cpts B C₂).card ≤ B.card := card_le_card (fun x hx => (mem_cpts.mp hx).1) rcases h with h | h · have hsub : (cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => φ ab.1 ∈ cpts B C₃ ∧ φ ab.2 ∈ cpts B C₄) ⊆ ((cpts B C₁).filter (fun a => φ a ∈ cpts B C₃)) ×ˢ cpts B C₂ := by intro ab hab obtain ⟨h1, h2, _⟩ := mem_filter.mp hab exact mem_product.mpr ⟨mem_filter.mpr ⟨(mem_product.mp h1).1, h2⟩, (mem_product.mp h1).2⟩ refine le_trans (card_le_card hsub) ?_ rw [card_product] exact Nat.mul_le_mul h hb2 · have hsub : (cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => φ ab.1 ∈ cpts B C₃ ∧ φ ab.2 ∈ cpts B C₄) ⊆ cpts B C₁ ×ˢ ((cpts B C₂).filter (fun b => φ b ∈ cpts B C₄)) := by intro ab hab obtain ⟨h1, _, h3⟩ := mem_filter.mp hab exact mem_product.mpr ⟨(mem_product.mp h1).1, mem_filter.mpr ⟨(mem_product.mp h1).2, h3⟩⟩ refine le_trans (card_le_card hsub) ?_ rw [card_product, mul_comm] exact Nat.mul_le_mul h hb1 /-- An explained pair is carried by a member of the finite families of rich isometries. -/ theorem expl_in_G {B : Finset ℂ} {T : ℝ} {a b c d : ℂ} (ha : a ∈ B) (hb : b ∈ B) (hc : c ∈ B) (hd : d ∈ B) (hab : a ≠ b) (h : Expl B T a b c d) : (∃ g ∈ Gp B T, ‖g.1‖ = 1 ∧ iapp g a = c ∧ iapp g b = d) ∨ (∃ g ∈ Gm B T, ‖g.1‖ = 1 ∧ iappc g a = c ∧ iappc g b = d) := by classical obtain ⟨g, hg1, hcase⟩ := h rcases hcase with ⟨e1, e2, e3⟩ | ⟨e1, e2, e3⟩ · left have hcd : c ≠ d := by intro h have := iapp_dq hg1 a b rw [e1, e2, h, dq_self] at this exact ne_of_dq_ne hab this.symm have hqQ : (a, b, c, d) ∈ QP B := by unfold QP simp only [mem_filter, mem_product] refine ⟨⟨ha, hb, hc, hd⟩, hab, hcd, ?_⟩ rw [← e1, ← e2, iapp_dq hg1] refine ⟨g, ?_, hg1, e1, e2⟩ unfold Gp exact mem_filter.mpr ⟨mem_image.mpr ⟨(a, b, c, d), hqQ, (gp4_unique hab e1 e2).symm⟩, hg1, e3⟩ · right have hcd : c ≠ d := by intro h have := iappc_dq hg1 a b rw [e1, e2, h, dq_self] at this exact ne_of_dq_ne hab this.symm have hqQ : (a, b, c, d) ∈ QP B := by unfold QP simp only [mem_filter, mem_product] refine ⟨⟨ha, hb, hc, hd⟩, hab, hcd, ?_⟩ rw [← e1, ← e2, iappc_dq hg1] refine ⟨g, ?_, hg1, e1, e2⟩ unfold Gm exact mem_filter.mpr ⟨mem_image.mpr ⟨(a, b, c, d), hqQ, (gm4_unique hab e1 e2).symm⟩, hg1, e3⟩ open Classical in /-- The quadruples on four circles that are explained (in the given order) by a rich isometry, when the radius pairs differ. -/ theorem expl_circles_le {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) (T : ℝ) {C₁ C₂ C₃ C₄ : ℂ × ℝ} (hne : ¬ (C₃.2 = C₁.2 ∧ C₄.2 = C₂.2)) : (((cpts B C₁ ×ˢ cpts B C₂ ×ˢ cpts B C₃ ×ˢ cpts B C₄).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)).card) ≤ 2 * B.card * ((Gp B T).card + (Gm B T).card) := by have hor : C₁.2 ≠ C₃.2 ∨ C₂.2 ≠ C₄.2 := by by_contra hcon push_neg at hcon exact hne ⟨hcon.1.symm, hcon.2.symm⟩ have hGp : ∀ g ∈ Gp B T, ‖g.1‖ = 1 := by intro g hg; unfold Gp at hg; exact (mem_filter.mp hg).2.1 have hGm : ∀ g ∈ Gm B T, ‖g.1‖ = 1 := by intro g hg; unfold Gm at hg; exact (mem_filter.mp hg).2.1 have hsub : (cpts B C₁ ×ˢ cpts B C₂ ×ˢ cpts B C₃ ×ˢ cpts B C₄).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2) ⊆ (Gp B T).biUnion (fun g => ((cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => iapp g ab.1 ∈ cpts B C₃ ∧ iapp g ab.2 ∈ cpts B C₄)).image (fun ab => (ab.1, ab.2, iapp g ab.1, iapp g ab.2))) ∪ (Gm B T).biUnion (fun g => ((cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => iappc g ab.1 ∈ cpts B C₃ ∧ iappc g ab.2 ∈ cpts B C₄)).image (fun ab => (ab.1, ab.2, iappc g ab.1, iappc g ab.2))) := by intro q hq obtain ⟨a, b, c, d⟩ := q simp only [mem_filter, mem_product] at hq obtain ⟨⟨ha, hb, hc, hd⟩, hab, hex⟩ := hq rcases expl_in_G (mem_cpts.mp ha).1 (mem_cpts.mp hb).1 (mem_cpts.mp hc).1 (mem_cpts.mp hd).1 hab hex with ⟨g, hg, _, e1, e2⟩ | ⟨g, hg, _, e1, e2⟩ · refine mem_union_left _ (mem_biUnion.mpr ⟨g, hg, mem_image.mpr ⟨(a, b), ?_, by simp [e1, e2]⟩⟩) exact mem_filter.mpr ⟨mem_product.mpr ⟨ha, hb⟩, by rw [e1]; exact hc, by rw [e2]; exact hd⟩ · refine mem_union_right _ (mem_biUnion.mpr ⟨g, hg, mem_image.mpr ⟨(a, b), ?_, by simp [e1, e2]⟩⟩) exact mem_filter.mpr ⟨mem_product.mpr ⟨ha, hb⟩, by rw [e1]; exact hc, by rw [e2]; exact hd⟩ refine le_trans (card_le_card hsub) (le_trans (card_union_le _ _) ?_) have h1 : ((Gp B T).biUnion (fun g => ((cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => iapp g ab.1 ∈ cpts B C₃ ∧ iapp g ab.2 ∈ cpts B C₄)).image (fun ab => (ab.1, ab.2, iapp g ab.1, iapp g ab.2)))).card ≤ (Gp B T).card * (2 * B.card) := by refine le_trans card_biUnion_le ?_ have : ∑ g ∈ Gp B T, (((cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => iapp g ab.1 ∈ cpts B C₃ ∧ iapp g ab.2 ∈ cpts B C₄)).image (fun ab => (ab.1, ab.2, iapp g ab.1, iapp g ab.2))).card ≤ ∑ _g ∈ Gp B T, 2 * B.card := by refine sum_le_sum (fun g hg => le_trans card_image_le (pair_count_le B (iapp g) C₁ C₂ C₃ C₄ ?_)) rcases hor with h | h · exact Or.inl (circ_iso_le_two hnc (hGp g hg) h) · exact Or.inr (circ_iso_le_two hnc (hGp g hg) h) rw [sum_const, smul_eq_mul] at this exact this have h2 : ((Gm B T).biUnion (fun g => ((cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => iappc g ab.1 ∈ cpts B C₃ ∧ iappc g ab.2 ∈ cpts B C₄)).image (fun ab => (ab.1, ab.2, iappc g ab.1, iappc g ab.2)))).card ≤ (Gm B T).card * (2 * B.card) := by refine le_trans card_biUnion_le ?_ have : ∑ g ∈ Gm B T, (((cpts B C₁ ×ˢ cpts B C₂).filter (fun ab => iappc g ab.1 ∈ cpts B C₃ ∧ iappc g ab.2 ∈ cpts B C₄)).image (fun ab => (ab.1, ab.2, iappc g ab.1, iappc g ab.2))).card ≤ ∑ _g ∈ Gm B T, 2 * B.card := by refine sum_le_sum (fun g hg => le_trans card_image_le (pair_count_le B (iappc g) C₁ C₂ C₃ C₄ ?_)) rcases hor with h | h · exact Or.inl (circ_isoc_le_two hnc (hGm g hg) h) · exact Or.inr (circ_isoc_le_two hnc (hGm g hg) h) rw [sum_const, smul_eq_mul] at this exact this nlinarith [h1, h2] open Classical in /-- **The unmatched part**, for one pair of concentric circle pairs with different radius pairs. -/ theorem unmatched_bound {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) (T : ℝ) {P P' : (ℂ × ℝ) × (ℂ × ℝ)} (hnm : ¬ Mt P P') : (Eq4 B P.1 P.2 P'.1 P'.2).card ≤ ((QP B).filter (fun q => PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2)).card + 4 * B.card * ((Gp B T).card + (Gm B T).card) := by unfold Mt at hnm push_neg at hnm have hn1 : ¬ (P'.1.2 = P.1.2 ∧ P'.2.2 = P.2.2) := fun h => hnm.1 h.1 h.2 have hn2 : ¬ (P'.2.2 = P.1.2 ∧ P'.1.2 = P.2.2) := fun h => hnm.2 h.2 h.1 have e1 := expl_circles_le hnc T (C₁ := P.1) (C₂ := P.2) (C₃ := P'.1) (C₄ := P'.2) hn1 have e2 := expl_circles_le hnc T (C₁ := P.1) (C₂ := P.2) (C₃ := P'.2) (C₄ := P'.1) hn2 -- the second set, rewritten through the swap of the last two coordinates have hsub : Eq4 B P.1 P.2 P'.1 P'.2 ⊆ (QP B).filter (fun q => PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2) ∪ ((cpts B P.1 ×ˢ cpts B P.2 ×ˢ cpts B P'.1 ×ˢ cpts B P'.2).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2) ∪ ((cpts B P.1 ×ˢ cpts B P.2 ×ˢ cpts B P'.2 ×ˢ cpts B P'.1).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)).image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))) := by intro q hq unfold Eq4 at hq obtain ⟨hQ, h1, h2, h3, h4⟩ := mem_filter.mp hq have hQ' := hQ unfold QP at hQ' obtain ⟨_, hab, _, _⟩ := mem_filter.mp hQ' by_cases hp : PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2 · exact mem_union_left _ (mem_filter.mpr ⟨hQ, hp⟩) · apply mem_union_right unfold PoorP at hp by_cases hx : Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2 · apply mem_union_left refine mem_filter.mpr ⟨?_, hab, hx⟩ simp only [mem_product] exact ⟨h1, h2, h3, h4⟩ · have hx2 : Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1 := by by_contra hcon exact hp ⟨hx, hcon⟩ apply mem_union_right refine mem_image.mpr ⟨(q.1, q.2.1, q.2.2.2, q.2.2.1), mem_filter.mpr ⟨?_, hab, hx2⟩, rfl⟩ simp only [mem_product] exact ⟨h1, h2, h4, h3⟩ have h3 := card_le_card hsub have h4 := card_union_le ((QP B).filter (fun q => PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2)) ((cpts B P.1 ×ˢ cpts B P.2 ×ˢ cpts B P'.1 ×ˢ cpts B P'.2).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2) ∪ ((cpts B P.1 ×ˢ cpts B P.2 ×ˢ cpts B P'.2 ×ˢ cpts B P'.1).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)).image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))) have h5 := card_union_le ((cpts B P.1 ×ˢ cpts B P.2 ×ˢ cpts B P'.1 ×ˢ cpts B P'.2).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)) (((cpts B P.1 ×ˢ cpts B P.2 ×ˢ cpts B P'.2 ×ˢ cpts B P'.1).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)).image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))) have h6 : (((cpts B P.1 ×ˢ cpts B P.2 ×ˢ cpts B P'.2 ×ˢ cpts B P'.1).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)).image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))).card ≤ _ := card_image_le nlinarith [e1, e2, h3, h4, h5, h6] end E94S /-! ### SOLO slice D5 -/ /-! ## SOLO module D (part 5): the endgame inequality in terms of heavy circles -/ namespace E94S open Finset theorem mem_QP {B : Finset ℂ} {q : ℂ × ℂ × ℂ × ℂ} : q ∈ QP B ↔ (q.1 ∈ B ∧ q.2.1 ∈ B ∧ q.2.2.1 ∈ B ∧ q.2.2.2 ∈ B) ∧ q.1 ≠ q.2.1 ∧ q.2.2.1 ≠ q.2.2.2 ∧ dq q.1 q.2.1 = dq q.2.2.1 q.2.2.2 := by classical unfold QP simp only [mem_filter, mem_product] open Classical in /-- Quadruples whose first pair is unstructured: poor, or explained in one of the two orders. -/ theorem unstruct_le (B : Finset ℂ) (D T : ℝ) : ((QP B).filter (fun q => ¬ Struct B D q.1 q.2.1)).card ≤ ((QP B).filter (fun q => PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2)).card + 2 * ((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B D q.1 q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2)).card := by obtain ⟨V, hV⟩ : ∃ V : Finset (ℂ × ℂ × ℂ × ℂ), V = (B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B D q.1 q.2.1 ∧ Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2) := ⟨_, rfl⟩ rw [← hV] have hsub : (QP B).filter (fun q => ¬ Struct B D q.1 q.2.1) ⊆ (QP B).filter (fun q => PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2) ∪ (V ∪ V.image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))) := by intro q hq obtain ⟨hQ, hns⟩ := mem_filter.mp hq obtain ⟨⟨ha, hb, hc, hd⟩, hab, _, _⟩ := mem_QP.mp hQ by_cases hp : PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2 · exact mem_union_left _ (mem_filter.mpr ⟨hQ, hp⟩) · apply mem_union_right unfold PoorP at hp by_cases hx : Expl B T q.1 q.2.1 q.2.2.1 q.2.2.2 · apply mem_union_left rw [hV] refine mem_filter.mpr ⟨?_, hab, hns, hx⟩ simp only [mem_product] exact ⟨ha, hb, hc, hd⟩ · have hx2 : Expl B T q.1 q.2.1 q.2.2.2 q.2.2.1 := by by_contra hcon exact hp ⟨hx, hcon⟩ apply mem_union_right refine mem_image.mpr ⟨(q.1, q.2.1, q.2.2.2, q.2.2.1), ?_, rfl⟩ rw [hV] refine mem_filter.mpr ⟨?_, hab, hns, hx2⟩ simp only [mem_product] exact ⟨ha, hb, hd, hc⟩ have h1 := card_le_card hsub have h2 := card_union_le ((QP B).filter (fun q => PoorP B T q.1 q.2.1 q.2.2.1 q.2.2.2)) (V ∪ V.image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))) have h3 := card_union_le V (V.image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))) have h4 : (V.image (fun q => (q.1, q.2.1, q.2.2.2, q.2.2.1))).card ≤ V.card := card_image_le omega open Classical in /-- Swapping the two pairs: the quadruples with an unstructured second pair. -/ theorem unstruct_swap (B : Finset ℂ) (D : ℝ) : ((QP B).filter (fun q => ¬ Struct B D q.2.2.1 q.2.2.2)).card ≤ ((QP B).filter (fun q => ¬ Struct B D q.1 q.2.1)).card := by refine card_le_card_of_injOn (fun q => (q.2.2.1, q.2.2.2, q.1, q.2.1)) ?_ ?_ · intro q hq obtain ⟨hQ, hns⟩ := mem_filter.mp hq obtain ⟨⟨ha, hb, hc, hd⟩, hab, hcd, he⟩ := mem_QP.mp hQ exact mem_filter.mpr ⟨mem_QP.mpr ⟨⟨hc, hd, ha, hb⟩, hcd, hab, he.symm⟩, hns⟩ · intro q _ q' _ h simp only [Prod.mk.injEq] at h obtain ⟨h1, h2, h3, h4⟩ := h exact Prod.ext h3 (Prod.ext h4 (Prod.ext h1 h2)) open Classical in /-- **The endgame inequality.** -/ theorem endgame_core {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {D : ℝ} (hD : 2 < D) (Ta Tb : ℝ) {m : ℝ} (hm0 : 0 ≤ m) (hm : ∀ C ∈ HC B D, ((cpts B C).card : ℝ) ≤ m) : ((QP B).card : ℝ) ≤ 4 / 3 * (∑ C ∈ HC B D, ((cpts B C).card : ℝ)) ^ 3 + 2 / 3 * m * (∑ C ∈ HC B D, ((cpts B C).card : ℝ)) ^ 2 + ((Conc B D).card : ℝ) ^ 2 * ((((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ))) + 2 * ((((QP B).filter (fun q => PoorP B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 2 * (((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B D q.1 q.2.1 ∧ Expl B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ)) := by -- structured and unstructured quadruples have hsplit : (QP B).card ≤ ((QP B).filter (fun q => Struct B D q.1 q.2.1 ∧ Struct B D q.2.2.1 q.2.2.2)).card + (((QP B).filter (fun q => ¬ Struct B D q.1 q.2.1)).card + ((QP B).filter (fun q => ¬ Struct B D q.2.2.1 q.2.2.2)).card) := by have hsub : QP B ⊆ (QP B).filter (fun q => Struct B D q.1 q.2.1 ∧ Struct B D q.2.2.1 q.2.2.2) ∪ ((QP B).filter (fun q => ¬ Struct B D q.1 q.2.1) ∪ (QP B).filter (fun q => ¬ Struct B D q.2.2.1 q.2.2.2)) := by intro q hq by_cases h1 : Struct B D q.1 q.2.1 · by_cases h2 : Struct B D q.2.2.1 q.2.2.2 · exact mem_union_left _ (mem_filter.mpr ⟨hq, h1, h2⟩) · exact mem_union_right _ (mem_union_right _ (mem_filter.mpr ⟨hq, h2⟩)) · exact mem_union_right _ (mem_union_left _ (mem_filter.mpr ⟨hq, h1⟩)) refine le_trans (card_le_card hsub) (le_trans (card_union_le _ _) ?_) exact Nat.add_le_add_left (card_union_le _ _) _ have hu1 := unstruct_le B D Ta have hu2 := unstruct_swap B D -- the structured part have hss : (((QP B).filter (fun q => Struct B D q.1 q.2.1 ∧ Struct B D q.2.2.1 q.2.2.2)).card : ℝ) ≤ ∑ PP ∈ (Conc B D) ×ˢ (Conc B D), ((Eq4 B PP.1.1 PP.1.2 PP.2.1 PP.2.2).card : ℝ) := by have := le_trans (card_le_card (struct_cover hnc hD)) card_biUnion_le exact_mod_cast this have hsp := sum_filter_add_sum_filter_not ((Conc B D) ×ˢ (Conc B D)) (fun PP => Mt PP.1 PP.2) (fun PP => ((Eq4 B PP.1.1 PP.1.2 PP.2.1 PP.2.2).card : ℝ)) have hmat := matched_bound hnc (by linarith : (1 : ℝ) < D) hm0 hm have hunm : ∑ PP ∈ ((Conc B D) ×ˢ (Conc B D)).filter (fun PP => ¬ Mt PP.1 PP.2), ((Eq4 B PP.1.1 PP.1.2 PP.2.1 PP.2.2).card : ℝ) ≤ ((Conc B D).card : ℝ) ^ 2 * ((((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ))) := by have h1 : ∑ PP ∈ ((Conc B D) ×ˢ (Conc B D)).filter (fun PP => ¬ Mt PP.1 PP.2), ((Eq4 B PP.1.1 PP.1.2 PP.2.1 PP.2.2).card : ℝ) ≤ ∑ _PP ∈ ((Conc B D) ×ˢ (Conc B D)).filter (fun PP => ¬ Mt PP.1 PP.2), ((((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ))) := by refine sum_le_sum (fun PP hPP => ?_) have := unmatched_bound hnc Tb (mem_filter.mp hPP).2 exact_mod_cast this rw [sum_const, nsmul_eq_mul] at h1 have h2 : ((((Conc B D) ×ˢ (Conc B D)).filter (fun PP => ¬ Mt PP.1 PP.2)).card : ℝ) ≤ ((Conc B D).card : ℝ) ^ 2 := by have : (((Conc B D) ×ˢ (Conc B D)).filter (fun PP => ¬ Mt PP.1 PP.2)).card ≤ (Conc B D).card ^ 2 := by refine le_trans (card_le_card (filter_subset _ _)) ?_ rw [card_product, sq] exact_mod_cast this have h3 : (0 : ℝ) ≤ (((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ)) := by positivity exact le_trans h1 (mul_le_mul_of_nonneg_right h2 h3) have hreal : ((QP B).card : ℝ) ≤ (((QP B).filter (fun q => Struct B D q.1 q.2.1 ∧ Struct B D q.2.2.1 q.2.2.2)).card : ℝ) + 2 * ((((QP B).filter (fun q => PoorP B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 2 * (((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B D q.1 q.2.1 ∧ Expl B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ)) := by have : (QP B).card ≤ ((QP B).filter (fun q => Struct B D q.1 q.2.1 ∧ Struct B D q.2.2.1 q.2.2.2)).card + 2 * (((QP B).filter (fun q => PoorP B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card + 2 * ((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B D q.1 q.2.1 ∧ Expl B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card) := by omega exact_mod_cast this linarith end E94S /-! ### SOLO slice D6a -/ /-! ## SOLO module D (part 6a): closed-form bounds for the endgame -/ namespace E94S open Finset /-- The main term: `X ≤ n + H`, `H ≤ n`, every heavy circle below `(1-δ)n`. -/ theorem num_main {n H X δ : ℝ} (hn : 0 ≤ n) (hH0 : 0 ≤ H) (hHn : H ≤ n) (hX0 : 0 ≤ X) (hX : X ≤ n + H) (hδ0 : 0 ≤ δ) (hδ1 : δ ≤ 1) : 4 / 3 * X ^ 3 + 2 / 3 * ((1 - δ) * n) * X ^ 2 ≤ (2 - 2 * δ / 3) * n ^ 3 + 12 * H * n ^ 2 := by have h1 : X ^ 3 ≤ (n + H) ^ 3 := pow_le_pow_left₀ hX0 hX 3 have h2 : X ^ 2 ≤ (n + H) ^ 2 := pow_le_pow_left₀ hX0 hX 2 have h3 : (n + H) ^ 3 ≤ n ^ 3 + 7 * H * n ^ 2 := by have a1 : H * H ≤ H * n := mul_le_mul_of_nonneg_left hHn hH0 have a2 : H * H * H ≤ H * n * n := by have := mul_le_mul a1 hHn hH0 (mul_nonneg hH0 hn) linarith have a3 : H * H * n ≤ H * n * n := mul_le_mul_of_nonneg_right a1 hn nlinarith have h4 : (n + H) ^ 2 ≤ n ^ 2 + 3 * H * n := by have a1 : H * H ≤ H * n := mul_le_mul_of_nonneg_left hHn hH0 nlinarith have h5 : 0 ≤ (1 - δ) * n := mul_nonneg (by linarith) hn have h6 : 2 / 3 * ((1 - δ) * n) * X ^ 2 ≤ 2 / 3 * ((1 - δ) * n) * (n ^ 2 + 3 * H * n) := mul_le_mul_of_nonneg_left (le_trans h2 h4) (by positivity) have h7 : (1 - δ) * n * (3 * H * n) ≤ 1 * n * (3 * H * n) := by have : (1 - δ) * n ≤ 1 * n := mul_le_mul_of_nonneg_right (by linarith) hn exact mul_le_mul_of_nonneg_right this (by positivity) nlinarith [le_trans h1 h3] open Classical in /-- There are at most `8|B|³/D³` heavy circles (for `D ≥ 6`). -/ theorem HC_le {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {D : ℝ} (hD : 6 ≤ D) : ((HC B D).card : ℝ) * D ^ 3 ≤ 8 * (B.card : ℝ) ^ 3 := by obtain ⟨t, ht⟩ : ∃ t : ℕ, t = ⌊D⌋₊ := ⟨_, rfl⟩ have hD0 : (0 : ℝ) ≤ D := by linarith have ht1 : (t : ℝ) ≤ D := by rw [ht]; exact Nat.floor_le hD0 have ht2 : D < (t : ℝ) + 1 := by rw [ht]; exact Nat.lt_floor_add_one D have ht3 : 3 ≤ t := by have : (5 : ℝ) < (t : ℝ) := by linarith have : 5 < t := by exact_mod_cast this omega have hc := HC_card hnc ht3 ht1 obtain ⟨s, rfl⟩ : ∃ s, t = s + 3 := ⟨t - 3, by omega⟩ have e1 : (6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ) = ((s : ℝ) + 3) * ((s : ℝ) + 2) * ((s : ℝ) + 1) := by exact_mod_cast six_choose_three s have e2 : (6 : ℝ) * ((B.card.choose 3 : ℕ) : ℝ) ≤ (B.card : ℝ) ^ 3 := by exact_mod_cast six_choose_three_le B.card have hs0 : (0 : ℝ) ≤ (s : ℝ) := Nat.cast_nonneg s push_cast at ht1 ht2 have hhalf : D / 2 ≤ (s : ℝ) + 1 := by linarith have hhalf0 : (0 : ℝ) ≤ D / 2 := by linarith have e3 : (D / 2) ^ 3 ≤ (6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ) := by rw [e1] have a1 : (D / 2) ^ 3 ≤ ((s : ℝ) + 1) ^ 3 := pow_le_pow_left₀ hhalf0 hhalf 3 nlinarith [mul_nonneg hs0 hs0, mul_nonneg (mul_nonneg hs0 hs0) hs0] have hc' : ((HC B D).card : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ) ≤ ((B.card.choose 3 : ℕ) : ℝ) := by exact_mod_cast hc have hH0 : (0 : ℝ) ≤ ((HC B D).card : ℝ) := Nat.cast_nonneg _ have f1 : ((HC B D).card : ℝ) * (D / 2) ^ 3 ≤ ((HC B D).card : ℝ) * ((6 : ℝ) * (((s + 3).choose 3 : ℕ) : ℝ)) := mul_le_mul_of_nonneg_left e3 hH0 have f2 : ((HC B D).card : ℝ) * (D / 2) ^ 3 = ((HC B D).card : ℝ) * D ^ 3 / 8 := by ring rw [f2] at f1 linarith theorem Conc_card_le (B : Finset ℂ) (D : ℝ) : (Conc B D).card ≤ (HC B D).card ^ 2 := by classical unfold Conc refine le_trans (card_le_card (filter_subset _ _)) ?_ rw [card_product, sq] theorem poorP_mono {B : Finset ℂ} {T T' : ℝ} (h : T ≤ T') {a b c d : ℂ} (hp : PoorP B T a b c d) : PoorP B T' a b c d := ⟨fun he => hp.1 (expl_mono h he), fun he => hp.2 (expl_mono h he)⟩ /-- The final arithmetic of the endgame. -/ theorem num_final {n δ H Cu Q : ℝ} (hn : 0 < n) (hδ : 0 < δ) (hQ : Q ≤ (2 - 2 * δ / 3) * n ^ 3 + 12 * H * n ^ 2 + (δ / 10 * n ^ 3 + Cu * n ^ 2) + 2 * (δ / 60 * n ^ 3 + 2 * (δ / 60 * n ^ 3))) (hbig : 15 * (12 * H + Cu + 3) ≤ 7 * δ * n) : Q ≤ 2 * n ^ 3 - 3 * n ^ 2 := by have hn2 : 0 < n ^ 2 := by positivity have h1 : (12 * H + Cu + 3) * n ^ 2 ≤ 7 * δ / 15 * n * n ^ 2 := by have : 12 * H + Cu + 3 ≤ 7 * δ / 15 * n := by linarith exact mul_le_mul_of_nonneg_right this hn2.le nlinarith end E94S /-! ### SOLO slice D6b -/ /-! ## SOLO module D (part 6b): the endgame for fixed parameters -/ namespace E94S open Finset open Classical in /-- **The endgame for fixed parameters.** Either the equal-distance quadruples number at most `2n³ - 3n²`, or some circle carries at least `(1 - δ)n` points. -/ theorem solo_core {B : Finset ℂ} (hnc : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, a ≠ b → a ≠ c → b ≠ c → cr3 a b c ≠ 0) {δ δ₁ h Ta Tb G₀ : ℝ} (hδ : 0 < δ) (hδ1 : δ ≤ 1) (hδ₁ : 0 < δ₁) (hh : h * δ₁ ^ 3 = 8) (hN : (0 : ℝ) < B.card) (hD6 : 6 ≤ δ₁ * (B.card : ℝ)) (hG₀ : 0 ≤ G₀) (hPa : (((QP B).filter (fun q => PoorP B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ δ / 60 * (B.card : ℝ) ^ 3) (hV : (((B ×ˢ B ×ˢ B ×ˢ B).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct B (δ₁ * B.card) q.1 q.2.1 ∧ Expl B Ta q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ δ / 60 * (B.card : ℝ) ^ 3) (hPb : h ^ 4 * (((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ δ / 10 * (B.card : ℝ) ^ 3) (hG : ((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ) ≤ G₀ * (B.card : ℝ)) (hbig1 : h ^ 2 ≤ (B.card : ℝ)) (hbig2 : 15 * (12 * h ^ 2 + 4 * h ^ 4 * G₀ + 3) ≤ 7 * δ * (B.card : ℝ)) : ((QP B).card : ℝ) ≤ 2 * (B.card : ℝ) ^ 3 - 3 * (B.card : ℝ) ^ 2 ∨ ∃ C : ℂ × ℝ, 0 < C.2 ∧ (1 - δ) * (B.card : ℝ) ≤ ((cpts B C).card : ℝ) := by have hD2 : (2 : ℝ) < δ₁ * (B.card : ℝ) := by linarith by_cases hex : ∃ C ∈ HC B (δ₁ * B.card), (1 - δ) * (B.card : ℝ) ≤ ((cpts B C).card : ℝ) · obtain ⟨C, hC, hCb⟩ := hex exact Or.inr ⟨C, HC_pos (by linarith) hC, hCb⟩ left push_neg at hex have hh0 : 0 < h := by have h3 : 0 < δ₁ ^ 3 := by positivity by_contra hcon push_neg at hcon have : h * δ₁ ^ 3 ≤ 0 := mul_nonpos_of_nonpos_of_nonneg hcon h3.le linarith have hm0 : 0 ≤ (1 - δ) * (B.card : ℝ) := mul_nonneg (by linarith) hN.le have hcore := endgame_core hnc hD2 Ta Tb hm0 (fun C hC => (hex C hC).le) -- the number of heavy circles have hHC : ((HC B (δ₁ * B.card)).card : ℝ) ≤ h := by have h1 := HC_le hnc hD6 have h2 : ((HC B (δ₁ * B.card)).card : ℝ) * (δ₁ * (B.card : ℝ)) ^ 3 = (((HC B (δ₁ * B.card)).card : ℝ) * δ₁ ^ 3) * (B.card : ℝ) ^ 3 := by ring rw [h2] at h1 have hN3 : (0 : ℝ) < (B.card : ℝ) ^ 3 := by positivity have h3 : ((HC B (δ₁ * B.card)).card : ℝ) * δ₁ ^ 3 ≤ 8 := le_of_mul_le_mul_right h1 hN3 rw [← hh] at h3 exact le_of_mul_le_mul_right h3 (by positivity) have hHC0 : (0 : ℝ) ≤ ((HC B (δ₁ * B.card)).card : ℝ) := Nat.cast_nonneg _ have hHC2 : ((HC B (δ₁ * B.card)).card : ℝ) ^ 2 ≤ h ^ 2 := pow_le_pow_left₀ hHC0 hHC 2 -- incidences have hX : ∑ C ∈ HC B (δ₁ * B.card), ((cpts B C).card : ℝ) ≤ (B.card : ℝ) + h ^ 2 := by have := sum_cpts_HC hnc (δ₁ * B.card) have h' : ((∑ C ∈ HC B (δ₁ * B.card), (cpts B C).card : ℕ) : ℝ) ≤ ((B.card + (HC B (δ₁ * B.card)).card ^ 2 : ℕ) : ℝ) := by exact_mod_cast this push_cast at h' linarith have hX0 : (0 : ℝ) ≤ ∑ C ∈ HC B (δ₁ * B.card), ((cpts B C).card : ℝ) := sum_nonneg (fun _ _ => Nat.cast_nonneg _) have hmain := num_main hN.le (by positivity) hbig1 hX0 hX hδ.le hδ1 -- the unmatched term have hConc : ((Conc B (δ₁ * B.card)).card : ℝ) ^ 2 ≤ h ^ 4 := by have h1 : ((Conc B (δ₁ * B.card)).card : ℝ) ≤ ((HC B (δ₁ * B.card)).card : ℝ) ^ 2 := by exact_mod_cast Conc_card_le B (δ₁ * B.card) have h2 : ((Conc B (δ₁ * B.card)).card : ℝ) ≤ h ^ 2 := le_trans h1 hHC2 have h3 := pow_le_pow_left₀ (Nat.cast_nonneg (Conc B (δ₁ * B.card)).card : (0 : ℝ) ≤ _) h2 2 calc ((Conc B (δ₁ * B.card)).card : ℝ) ^ 2 ≤ (h ^ 2) ^ 2 := h3 _ = h ^ 4 := by ring have hpb0 : (0 : ℝ) ≤ (((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) := Nat.cast_nonneg _ have hgg0 : (0 : ℝ) ≤ ((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ) := by positivity have hun : ((Conc B (δ₁ * B.card)).card : ℝ) ^ 2 * ((((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ))) ≤ δ / 10 * (B.card : ℝ) ^ 3 + 4 * h ^ 4 * G₀ * (B.card : ℝ) ^ 2 := by have h1 : (0 : ℝ) ≤ (((QP B).filter (fun q => PoorP B Tb q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) + 4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ)) := by positivity have h2 := mul_le_mul_of_nonneg_right hConc h1 have h3 : 4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ)) ≤ 4 * (B.card : ℝ) * (G₀ * (B.card : ℝ)) := mul_le_mul_of_nonneg_left hG (by positivity) have h4 : h ^ 4 * (4 * (B.card : ℝ) * (((Gp B Tb).card : ℝ) + ((Gm B Tb).card : ℝ))) ≤ h ^ 4 * (4 * (B.card : ℝ) * (G₀ * (B.card : ℝ))) := mul_le_mul_of_nonneg_left h3 (by positivity) nlinarith refine num_final (H := h ^ 2) (Cu := 4 * h ^ 4 * G₀) hN hδ ?_ hbig2 linarith end E94S /-! ### SOLO slice D6c -/ /-! ## SOLO module D (part 6c): the dichotomy for labelled convex polygons -/ namespace E94S open Finset open Classical in theorem QP_pts_filter_le (v : ℕ → ℂ) (n : ℕ) (R : ℂ → ℂ → ℂ → ℂ → Prop) : ((QP (pts v n)).filter (fun q => R q.1 q.2.1 q.2.2.1 q.2.2.2)).card ≤ ((Qd v n).filter (fun q => R (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card := by have hsub : (QP (pts v n)).filter (fun q => R q.1 q.2.1 q.2.2.1 q.2.2.2) ⊆ ((Qd v n).filter (fun q => R (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).image (fun q => (v q.1, v q.2.1, v q.2.2.1, v q.2.2.2)) := by intro q hq obtain ⟨a, b, c, d⟩ := q obtain ⟨hq1, hq2⟩ := mem_filter.mp hq obtain ⟨⟨ha, hb, hc, hd⟩, hab, hcd, he⟩ := mem_QP.mp hq1 have ha' : a ∈ (range n).image v := ha have hb' : b ∈ (range n).image v := hb have hc' : c ∈ (range n).image v := hc have hd' : d ∈ (range n).image v := hd obtain ⟨i, hi, rfl⟩ := mem_image.mp ha' obtain ⟨j, hj, rfl⟩ := mem_image.mp hb' obtain ⟨k, hk, rfl⟩ := mem_image.mp hc' obtain ⟨l, hl, rfl⟩ := mem_image.mp hd' exact mem_image.mpr ⟨(i, j, k, l), mem_filter.mpr ⟨mem_Qd.mpr ⟨⟨mem_range.mp hi, mem_range.mp hj, mem_range.mp hk, mem_range.mp hl⟩, fun hij => hab (congrArg v hij), fun hkl => hcd (congrArg v hkl), he⟩, hq2⟩, rfl⟩ exact le_trans (card_le_card hsub) card_image_le theorem QP_pts_le (v : ℕ → ℂ) (n : ℕ) : (QP (pts v n)).card ≤ (Qd v n).card := by classical have h1 := QP_pts_filter_le v n (fun _ _ _ _ => True) simpa using h1 open Classical in /-- Counting form of RIT on the point set. -/ theorem poor_pts_le {v : ℕ → ℂ} {n : ℕ} {T T' E : ℝ} (hTT : T' ≤ T) (h : (((Qd v n).filter (fun q => PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card : ℝ) ≤ E) : (((QP (pts v n)).filter (fun q => PoorP (pts v n) T' q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ E := by refine le_trans ?_ h have h1 := QP_pts_filter_le v n (fun a b c d => PoorP (pts v n) T' a b c d) have h2 : ((Qd v n).filter (fun q => PoorP (pts v n) T' (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card ≤ ((Qd v n).filter (fun q => PoorP (pts v n) T (v q.1) (v q.2.1) (v q.2.2.1) (v q.2.2.2))).card := by apply card_le_card intro q hq obtain ⟨hq1, hq2⟩ := mem_filter.mp hq exact mem_filter.mpr ⟨hq1, poorP_mono hTT hq2⟩ exact_mod_cast le_trans h1 h2 theorem QP_pts_card_le {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) : ((QP (pts v n)).card : ℝ) ≤ 8192 * (n : ℝ) ^ 3 := by have h1 := Qd_card_le hccw hinj have h2 : ((QP (pts v n)).card : ℝ) ≤ ((Qd v n).card : ℝ) := by exact_mod_cast QP_pts_le v n linarith /-- The number of rich isometries of either kind. -/ theorem G_pts_le {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {τb G₀ : ℝ} (hτb : 0 < τb) (hG₀ : G₀ * τb ^ 2 = 32768) (hn0 : 0 < n) (hTb2 : 2 ≤ τb * (n : ℝ)) : ((Gp (pts v n) (τb * n)).card : ℝ) + ((Gm (pts v n) (τb * n)).card : ℝ) ≤ G₀ * (n : ℝ) := by have hQ := QP_pts_card_le hccw hinj have hnR : (0 : ℝ) < n := by exact_mod_cast hn0 have hT1 : (1 : ℝ) ≤ τb * n := by linarith have hgp := Gp_card (pts v n) hT1 have hgm := Gm_card (pts v n) hT1 have h1 := rich_card_bound hτb hnR rfl hTb2 (le_trans hgp hQ) (Nat.cast_nonneg _) have h2 := rich_card_bound hτb hnR rfl hTb2 (le_trans hgm hQ) (Nat.cast_nonneg _) have hτ2 : 0 < τb ^ 2 := by positivity have h3 : (((Gp (pts v n) (τb * n)).card : ℝ) + ((Gm (pts v n) (τb * n)).card : ℝ)) * τb ^ 2 ≤ G₀ * (n : ℝ) * τb ^ 2 := by have e : G₀ * (n : ℝ) * τb ^ 2 = (G₀ * τb ^ 2) * n := by ring rw [e, hG₀] linarith exact le_of_mul_le_mul_right h3 hτ2 open Classical in /-- The dichotomy for one polygon, all parameters fixed. -/ theorem solo_step {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {δ δ₁ h τa τb G₀ : ℝ} (hδ : 0 < δ) (hδ1 : δ ≤ 1) (hδ₁ : 0 < δ₁) (hh : h * δ₁ ^ 3 = 8) (hτb : 0 < τb) (hG₀ : G₀ * τb ^ 2 = 32768) (hn0 : 0 < n) (hD6 : 6 ≤ δ₁ * (n : ℝ)) (hTb2 : 2 ≤ τb * (n : ℝ)) (hPa : (((QP (pts v n)).filter (fun q => PoorP (pts v n) (τa * n) q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ δ / 60 * (n : ℝ) ^ 3) (hV : ((((pts v n) ×ˢ (pts v n) ×ˢ (pts v n) ×ˢ (pts v n)).filter (fun q : ℂ × ℂ × ℂ × ℂ => q.1 ≠ q.2.1 ∧ ¬ Struct (pts v n) (δ₁ * n) q.1 q.2.1 ∧ Expl (pts v n) (τa * n) q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ δ / 60 * (n : ℝ) ^ 3) (hPb : h ^ 4 * (((QP (pts v n)).filter (fun q => PoorP (pts v n) (τb * n) q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ δ / 10 * (n : ℝ) ^ 3) (hbig1 : h ^ 2 ≤ (n : ℝ)) (hbig2 : 15 * (12 * h ^ 2 + 4 * h ^ 4 * G₀ + 3) ≤ 7 * δ * (n : ℝ)) : ((QP (pts v n)).card : ℝ) ≤ 2 * (n : ℝ) ^ 3 - 3 * (n : ℝ) ^ 2 ∨ ∃ C : ℂ × ℝ, 0 < C.2 ∧ (1 - δ) * (n : ℝ) ≤ ((cpts (pts v n) C).card : ℝ) := by have hcard := pts_card hinj have hG := G_pts_le hccw hinj hτb hG₀ hn0 hTb2 have hτ2 : 0 < τb ^ 2 := by positivity have hG₀0 : 0 ≤ G₀ := by by_contra hcon push_neg at hcon have := mul_neg_of_neg_of_pos hcon hτ2 linarith have hnR : (0 : ℝ) < n := by exact_mod_cast hn0 have key := solo_core (B := pts v n) (pts_nc hccw) (δ := δ) (δ₁ := δ₁) (h := h) (Ta := τa * n) (Tb := τb * n) (G₀ := G₀) hδ hδ1 hδ₁ hh (by rw [hcard]; exact hnR) (by rw [hcard]; exact hD6) hG₀0 (by rw [hcard]; exact hPa) (by rw [hcard]; exact hV) (by rw [hcard]; exact hPb) (by rw [hcard]; exact hG) (by rw [hcard]; exact hbig1) (by rw [hcard]; exact hbig2) rw [hcard] at key exact key theorem ceil_le_of_le {x : ℝ} {m n : ℕ} (h : ⌈x⌉₊ ≤ m) (hm : m ≤ n) : x ≤ (n : ℝ) := le_trans (Nat.le_ceil x) (by exact_mod_cast le_trans h hm) open Classical in /-- **The dichotomy** (conditional on the conic count): for large `n`, a convex `n`-gon either has at most `2n³ - 3n²` equal-distance quadruples or has `(1 - δ)n` of its vertices on one circle. -/ theorem solo_dichotomy (hC : ConicBound) {δ : ℝ} (hδ : 0 < δ) (hδ1 : δ ≤ 1) : ∃ n₀ : ℕ, ∀ n ≥ n₀, ∀ v : ℕ → ℂ, Ccw v n → (∀ i < n, ∀ j < n, v i = v j → i = j) → (∀ t : ℂ, t ≠ 0 → ((pts v n).filter (fun x => x + t ∈ pts v n)).card ≤ 2) → ((QP (pts v n)).card : ℝ) ≤ 2 * (n : ℝ) ^ 3 - 3 * (n : ℝ) ^ 2 ∨ ∃ C : ℂ × ℝ, 0 < C.2 ∧ (1 - δ) * (n : ℝ) ≤ ((cpts (pts v n) C).card : ℝ) := by obtain ⟨τa, hτa, na, hna⟩ := rit_of_conic hC (δ / 60) (by positivity) obtain ⟨τa', hτa'⟩ : ∃ t : ℝ, t = min τa 1 := ⟨_, rfl⟩ have hτa'0 : 0 < τa' := by rw [hτa']; exact lt_min hτa one_pos have hτa'1 : τa' ≤ 1 := by rw [hτa']; exact min_le_right _ _ have hτa'a : τa' ≤ τa := by rw [hτa']; exact min_le_left _ _ obtain ⟨δ₁, hδ₁, nu, hnu⟩ := claimU (ε := δ / 60) (τ := τa') (K := 8192) (by positivity) hτa'0 hτa'1 (by norm_num) obtain ⟨h, hh⟩ : ∃ h : ℝ, h = 8 / δ₁ ^ 3 := ⟨_, rfl⟩ have hd3 : 0 < δ₁ ^ 3 := by positivity have hh0 : 0 < h := by rw [hh]; positivity have hh8 : h * δ₁ ^ 3 = 8 := by rw [hh]; exact div_mul_cancel₀ _ hd3.ne' have hh4 : 0 < h ^ 4 := by positivity obtain ⟨τb, hτb, nb, hnb⟩ := rit_of_conic hC (δ / (10 * h ^ 4)) (by positivity) obtain ⟨τb', hτb'⟩ : ∃ t : ℝ, t = min τb 1 := ⟨_, rfl⟩ have hτb'0 : 0 < τb' := by rw [hτb']; exact lt_min hτb one_pos have hτb'b : τb' ≤ τb := by rw [hτb']; exact min_le_left _ _ have hτb2 : 0 < τb' ^ 2 := by positivity obtain ⟨G₀, hG₀⟩ : ∃ G₀ : ℝ, G₀ = 32768 / τb' ^ 2 := ⟨_, rfl⟩ have hG₀e : G₀ * τb' ^ 2 = 32768 := by rw [hG₀]; exact div_mul_cancel₀ _ hτb2.ne' refine ⟨na + nb + nu + 1 + ⌈6 / δ₁⌉₊ + ⌈2 / τb'⌉₊ + ⌈h ^ 2⌉₊ + ⌈15 * (12 * h ^ 2 + 4 * h ^ 4 * G₀ + 3) / (7 * δ)⌉₊, ?_⟩ intro n hn v hccw hinj hT have hcard := pts_card hinj have hnR0 : (0 : ℝ) ≤ n := Nat.cast_nonneg n have hQ := QP_pts_card_le hccw hinj have e1 : 6 / δ₁ ≤ (n : ℝ) := ceil_le_of_le (m := ⌈6 / δ₁⌉₊) le_rfl (by omega) have e2 : 2 / τb' ≤ (n : ℝ) := ceil_le_of_le (m := ⌈2 / τb'⌉₊) le_rfl (by omega) have e3 : h ^ 2 ≤ (n : ℝ) := ceil_le_of_le (m := ⌈h ^ 2⌉₊) le_rfl (by omega) have e4 : 15 * (12 * h ^ 2 + 4 * h ^ 4 * G₀ + 3) / (7 * δ) ≤ (n : ℝ) := ceil_le_of_le (m := ⌈15 * (12 * h ^ 2 + 4 * h ^ 4 * G₀ + 3) / (7 * δ)⌉₊) le_rfl (by omega) have hV := hnu (pts v n) (by rw [hcard]; omega) hT (by rw [hcard]; exact hQ) rw [hcard] at hV have hPa := poor_pts_le (T' := τa' * n) (mul_le_mul_of_nonneg_right hτa'a hnR0) (hna n (by omega) v hccw hinj) have hPb0 := poor_pts_le (T' := τb' * n) (mul_le_mul_of_nonneg_right hτb'b hnR0) (hnb n (by omega) v hccw hinj) have hPb : h ^ 4 * (((QP (pts v n)).filter (fun q => PoorP (pts v n) (τb' * n) q.1 q.2.1 q.2.2.1 q.2.2.2)).card : ℝ) ≤ δ / 10 * (n : ℝ) ^ 3 := by have h1 := mul_le_mul_of_nonneg_left hPb0 hh4.le have e : h ^ 4 * (δ / (10 * h ^ 4) * (n : ℝ) ^ 3) = δ / 10 * (n : ℝ) ^ 3 := by field_simp rw [e] at h1 exact h1 refine solo_step hccw hinj hδ hδ1 hδ₁ hh8 hτb'0 hG₀e (by omega) ?_ ?_ hPa hV hPb e3 ?_ · have := (div_le_iff₀ hδ₁).mp e1 linarith · have := (div_le_iff₀ hτb'0).mp e2 linarith · have := (div_le_iff₀ (by positivity : (0 : ℝ) < 7 * δ)).mp e4 linarith end E94S /-! ### SOLO slice E1 -/ /-! ## SOLO module E (part 1): quadratic functions and the five-point lemma -/ namespace E94S open Finset /-- A real quadratic polynomial on `ℂ = ℝ²`. -/ def qf (a b d e f k : ℝ) (z : ℂ) : ℝ := a * z.re ^ 2 + 2 * b * (z.re * z.im) + d * z.im ^ 2 + e * z.re + f * z.im + k /-- The quadratic form with matrix `((a, b), (b, d))`. -/ def qA (a b d : ℝ) (u : ℂ) : ℝ := a * u.re ^ 2 + 2 * b * (u.re * u.im) + d * u.im ^ 2 /-- Its bilinear form. -/ def qB (a b d : ℝ) (u w : ℂ) : ℝ := a * (u.re * w.re) + b * (u.re * w.im + u.im * w.re) + d * (u.im * w.im) def IsQF (D : ℂ → ℝ) : Prop := ∃ a b d e f k : ℝ, ∀ z, D z = qf a b d e f k z /-- The point with coordinates `(x, y)` in the affine frame `(p1; p2 - p1, p3 - p1)`. -/ def fp (p1 p2 p3 : ℂ) (x y : ℝ) : ℂ := ⟨p1.re + x * (p2.re - p1.re) + y * (p3.re - p1.re), p1.im + x * (p2.im - p1.im) + y * (p3.im - p1.im)⟩ theorem frame_coords {p1 p2 p3 : ℂ} (hdet : cr3 p1 p2 p3 ≠ 0) (z : ℂ) : ∃ x y : ℝ, z = fp p1 p2 p3 x y := by refine ⟨cr3 p1 z p3 / cr3 p1 p2 p3, cr3 p1 p2 z / cr3 p1 p2 p3, ?_⟩ apply Complex.ext · simp only [fp] field_simp unfold cr3 ring · simp only [fp] field_simp unfold cr3 ring theorem quad_frame (a b d e f k : ℝ) (p1 p2 p3 : ℂ) (x y : ℝ) : qf a b d e f k (fp p1 p2 p3 x y) = qA a b d (p2 - p1) * (x * (x - 1)) + 2 * qB a b d (p2 - p1) (p3 - p1) * (x * y) + qA a b d (p3 - p1) * (y * (y - 1)) + qf a b d e f k p1 * (1 - x - y) + qf a b d e f k p2 * x + qf a b d e f k p3 * y := by unfold qf fp qA qB simp only [Complex.sub_re, Complex.sub_im] ring theorem five_core {A B C A' B' C' a4 b4 c4 a5 b5 c5 : ℝ} (hΔ : b4 * c5 - b5 * c4 ≠ 0) (h4 : A * a4 + B * b4 + C * c4 = 0) (h5 : A * a5 + B * b5 + C * c5 = 0) (h4' : A' * a4 + B' * b4 + C' * c4 = 0) (h5' : A' * a5 + B' * b5 + C' * c5 = 0) : A * B' = A' * B ∧ A * C' = A' * C := by constructor · have h : (b4 * c5 - b5 * c4) * (A * B' - A' * B) = 0 := by linear_combination (-A' * c5) * h4 + (A' * c4) * h5 + (A * c5) * h4' - (A * c4) * h5' have := (mul_eq_zero.mp h).resolve_left hΔ linarith · have h : (b4 * c5 - b5 * c4) * (A * C' - A' * C) = 0 := by linear_combination (A' * b5) * h4 - (A' * b4) * h5 - (A * b5) * h4' + (A * b4) * h5' have := (mul_eq_zero.mp h).resolve_left hΔ linarith /-- A quadratic function vanishing at the three frame points, in frame coordinates. -/ theorem frame_form {D : ℂ → ℝ} (hD : IsQF D) {p1 p2 p3 : ℂ} (z1 : D p1 = 0) (z2 : D p2 = 0) (z3 : D p3 = 0) : ∃ A B C : ℝ, ∀ x y : ℝ, D (fp p1 p2 p3 x y) = A * (x * (x - 1)) + B * (x * y) + C * (y * (y - 1)) := by obtain ⟨a, b, d, e, f, k, hq⟩ := hD refine ⟨qA a b d (p2 - p1), 2 * qB a b d (p2 - p1) (p3 - p1), qA a b d (p3 - p1), fun x y => ?_⟩ rw [hq, quad_frame, ← hq p1, ← hq p2, ← hq p3, z1, z2, z3] ring /-- **Five-point lemma.** Two quadratic functions vanishing at five points, no three of the relevant triples collinear, are proportional. -/ theorem five_pt {D D' : ℂ → ℝ} (hD : IsQF D) (hD' : IsQF D') {p1 p2 p3 p4 p5 : ℂ} (h123 : cr3 p1 p2 p3 ≠ 0) (h124 : cr3 p1 p2 p4 ≠ 0) (h125 : cr3 p1 p2 p5 ≠ 0) (h345 : cr3 p3 p4 p5 ≠ 0) (z1 : D p1 = 0) (z2 : D p2 = 0) (z3 : D p3 = 0) (z4 : D p4 = 0) (z5 : D p5 = 0) (w1 : D' p1 = 0) (w2 : D' p2 = 0) (w3 : D' p3 = 0) (w4 : D' p4 = 0) (w5 : D' p5 = 0) (hne : ∃ z, D' z ≠ 0) : ∃ s : ℝ, ∀ z, D z = s * D' z := by obtain ⟨A, B, C, hF⟩ := frame_form hD z1 z2 z3 obtain ⟨A', B', C', hF'⟩ := frame_form hD' w1 w2 w3 obtain ⟨x4, y4, rfl⟩ := frame_coords h123 p4 obtain ⟨x5, y5, rfl⟩ := frame_coords h123 p5 have h4 := hF x4 y4 have h5 := hF x5 y5 have h4' := hF' x4 y4 have h5' := hF' x5 y5 rw [z4] at h4 rw [z5] at h5 rw [w4] at h4' rw [w5] at h5' have hy4 : y4 ≠ 0 := by intro h0 apply h124 rw [h0] unfold cr3 fp dsimp only ring have hy5 : y5 ≠ 0 := by intro h0 apply h125 rw [h0] unfold cr3 fp dsimp only ring have hx : x4 * (y5 - 1) - x5 * (y4 - 1) ≠ 0 := by intro h0 apply h345 have e : cr3 p3 (fp p1 p2 p3 x4 y4) (fp p1 p2 p3 x5 y5) = (x4 * (y5 - 1) - x5 * (y4 - 1)) * cr3 p1 p2 p3 := by unfold cr3 fp dsimp only ring rw [e, h0, zero_mul] have hΔ : (x4 * y4) * (y5 * (y5 - 1)) - (x5 * y5) * (y4 * (y4 - 1)) ≠ 0 := by have e : (x4 * y4) * (y5 * (y5 - 1)) - (x5 * y5) * (y4 * (y4 - 1)) = y4 * y5 * (x4 * (y5 - 1) - x5 * (y4 - 1)) := by ring rw [e] exact mul_ne_zero (mul_ne_zero hy4 hy5) hx obtain ⟨hAB, hAC⟩ := five_core hΔ h4.symm h5.symm h4'.symm h5'.symm have hA' : A' ≠ 0 := by intro h0 have hB' : B' = 0 := by have h : ((x4 * y4) * (y5 * (y5 - 1)) - (x5 * y5) * (y4 * (y4 - 1))) * B' = 0 := by linear_combination (-(y5 * (y5 - 1))) * h4' + (y4 * (y4 - 1)) * h5' - ((x4 * (x4 - 1)) * (y5 * (y5 - 1)) - (x5 * (x5 - 1)) * (y4 * (y4 - 1))) * h0 exact (mul_eq_zero.mp h).resolve_left hΔ have hC' : C' = 0 := by have h : ((x4 * y4) * (y5 * (y5 - 1)) - (x5 * y5) * (y4 * (y4 - 1))) * C' = 0 := by linear_combination (-(x4 * y4)) * h5' + (x5 * y5) * h4' - ((x5 * (x5 - 1)) * (x4 * y4) - (x4 * (x4 - 1)) * (x5 * y5)) * h0 exact (mul_eq_zero.mp h).resolve_left hΔ obtain ⟨z, hz⟩ := hne obtain ⟨x, y, rfl⟩ := frame_coords h123 z apply hz rw [hF', h0, hB', hC'] ring refine ⟨A / A', fun z => ?_⟩ obtain ⟨x, y, rfl⟩ := frame_coords h123 z rw [hF, hF'] have hB : B = A / A' * B' := by field_simp linarith have hC : C = A / A' * C' := by field_simp linarith rw [hB, hC] field_simp end E94S /-! ### SOLO slice E2 -/ /-! ## SOLO module E (part 2): rigidity of Ivory maps, diagonal coordinates -/ namespace E94S open Finset /-- Coefficient comparison for `D ∘ U = c₃ D` (diagonal quadratic part). -/ theorem diag_coef1 {α β e f k n11 n12 n21 n22 u1 u2 c3 : ℝ} (h1 : ∀ x y : ℝ, α * (n11 * x + n12 * y + u1) ^ 2 + β * (n21 * x + n22 * y + u2) ^ 2 + e * (n11 * x + n12 * y + u1) + f * (n21 * x + n22 * y + u2) + k = c3 * (α * x ^ 2 + β * y ^ 2 + e * x + f * y + k)) : α * n11 ^ 2 + β * n21 ^ 2 = c3 * α ∧ α * (n11 * n12) + β * (n21 * n22) = 0 ∧ α * n12 ^ 2 + β * n22 ^ 2 = c3 * β ∧ 2 * α * (n11 * u1) + 2 * β * (n21 * u2) + e * n11 + f * n21 = c3 * e ∧ 2 * α * (n12 * u1) + 2 * β * (n22 * u2) + e * n12 + f * n22 = c3 * f ∧ α * u1 ^ 2 + β * u2 ^ 2 + e * u1 + f * u2 + k = c3 * k := by have h00 := h1 0 0 have h10 := h1 1 0 have hm0 := h1 (-1) 0 have h01 := h1 0 1 have h0m := h1 0 (-1) have h11 := h1 1 1 refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ · linear_combination (1 / 2 : ℝ) * h10 + (1 / 2 : ℝ) * hm0 - h00 · linear_combination (1 / 2 : ℝ) * h11 - (1 / 2 : ℝ) * h10 - (1 / 2 : ℝ) * h01 + (1 / 2 : ℝ) * h00 · linear_combination (1 / 2 : ℝ) * h01 + (1 / 2 : ℝ) * h0m - h00 · linear_combination (1 / 2 : ℝ) * h10 - (1 / 2 : ℝ) * hm0 · linear_combination (1 / 2 : ℝ) * h01 - (1 / 2 : ℝ) * h0m · linear_combination h00 /-- Coefficient comparison for `|N z|² = |z|² + c Q(z)`. -/ theorem diag_coef2 {α β n11 n12 n21 n22 c : ℝ} (h2 : ∀ x y : ℝ, (n11 * x + n12 * y) ^ 2 + (n21 * x + n22 * y) ^ 2 = x ^ 2 + y ^ 2 + c * (α * x ^ 2 + β * y ^ 2)) : n11 ^ 2 + n21 ^ 2 = 1 + c * α ∧ n11 * n12 + n21 * n22 = 0 ∧ n12 ^ 2 + n22 ^ 2 = 1 + c * β := by have h10 := h2 1 0 have h01 := h2 0 1 have h11 := h2 1 1 refine ⟨?_, ?_, ?_⟩ · linear_combination h10 · linear_combination (1 / 2 : ℝ) * h11 - (1 / 2 : ℝ) * h10 - (1 / 2 : ℝ) * h01 · linear_combination h01 /-- **Normal form.** The linear part is diagonal with entries `±1`, or anti-diagonal. -/ theorem diag_nf {α β e f n11 n12 n21 n22 u1 u2 c3 c : ℝ} (hαβ : α ≠ β) (hc3 : c3 ≠ 0) (hnd : α * β ≠ 0 ∨ (β = 0 ∧ f ≠ 0) ∨ (α = 0 ∧ e ≠ 0)) (q11 : α * n11 ^ 2 + β * n21 ^ 2 = c3 * α) (q12 : α * (n11 * n12) + β * (n21 * n22) = 0) (q22 : α * n12 ^ 2 + β * n22 ^ 2 = c3 * β) (l1 : 2 * α * (n11 * u1) + 2 * β * (n21 * u2) + e * n11 + f * n21 = c3 * e) (l2 : 2 * α * (n12 * u1) + 2 * β * (n22 * u2) + e * n12 + f * n22 = c3 * f) (m11 : n11 ^ 2 + n21 ^ 2 = 1 + c * α) (m12 : n11 * n12 + n21 * n22 = 0) (m22 : n12 ^ 2 + n22 ^ 2 = 1 + c * β) : (n12 = 0 ∧ n21 = 0 ∧ n11 ^ 2 = 1 ∧ n22 ^ 2 = 1 ∧ c3 = 1) ∨ (n11 = 0 ∧ n22 = 0 ∧ n12 ≠ 0 ∧ c3 = -1 ∧ β * n21 ^ 2 = -α ∧ α * n12 ^ 2 = -β ∧ α * β ≠ 0) := by have hd : α - β ≠ 0 := sub_ne_zero.mpr hαβ have p1 : n11 * n12 = 0 := by have h : (α - β) * (n11 * n12) = 0 := by linear_combination q12 - β * m12 exact (mul_eq_zero.mp h).resolve_left hd have p2 : n21 * n22 = 0 := by have h : (α - β) * (n21 * n22) = 0 := by linear_combination α * m12 - q12 exact (mul_eq_zero.mp h).resolve_left hd rcases hnd with hab | ⟨hβ, hf⟩ | ⟨hα, he⟩ · have hα : α ≠ 0 := left_ne_zero_of_mul hab have hβ : β ≠ 0 := right_ne_zero_of_mul hab by_cases h12 : n12 = 0 · left have a1 : n22 ^ 2 = c3 := by have h : β * (n22 ^ 2 - c3) = 0 := by linear_combination q22 - α * (n12) * h12 have := (mul_eq_zero.mp h).resolve_left hβ linarith have a2 : n22 ≠ 0 := by intro h apply hc3 rw [← a1, h] ring have a3 : n21 = 0 := (mul_eq_zero.mp p2).resolve_right a2 have a4 : n11 ^ 2 = c3 := by have h : α * (n11 ^ 2 - c3) = 0 := by linear_combination q11 - β * (n21) * a3 have := (mul_eq_zero.mp h).resolve_left hα linarith have a5 : c = 0 := by have h : (α - β) * c = 0 := by linear_combination a4 - a1 - m11 + m22 + n21 * a3 - n12 * h12 exact (mul_eq_zero.mp h).resolve_left hd have a6 : c3 = 1 := by have : n11 ^ 2 = 1 := by linear_combination m11 - n21 * a3 + α * a5 linarith exact ⟨h12, a3, by rw [a4, a6], by rw [a1, a6], a6⟩ · right have b1 : n11 = 0 := (mul_eq_zero.mp p1).resolve_right h12 have b2 : β * n21 ^ 2 = c3 * α := by linear_combination q11 - α * n11 * b1 have b3 : n21 ≠ 0 := by intro h have h' : c3 * α = 0 := by rw [← b2, h]; ring rcases mul_eq_zero.mp h' with h'' | h'' · exact hc3 h'' · exact hα h'' have b4 : n22 = 0 := (mul_eq_zero.mp p2).resolve_left b3 have b5 : α * n12 ^ 2 = c3 * β := by linear_combination q22 - β * n22 * b4 have b6 : n21 ^ 2 = 1 + c * α := by linear_combination m11 - n11 * b1 have b7 : n12 ^ 2 = 1 + c * β := by linear_combination m22 - n22 * b4 have b8 : c3 = -1 := by have h : (α - β) * (c3 + 1) = 0 := by linear_combination (-1 : ℝ) * b2 + b5 + β * b6 - α * b7 have := (mul_eq_zero.mp h).resolve_left hd linarith exact ⟨b1, b4, h12, b8, by rw [b2, b8]; ring, by rw [b5, b8]; ring, hab⟩ · -- `β = 0`, `f ≠ 0` left have hα : α ≠ 0 := by intro h apply hαβ rw [h, hβ] have a1 : n11 ^ 2 = c3 := by have h : α * (n11 ^ 2 - c3) = 0 := by linear_combination q11 - n21 ^ 2 * hβ have := (mul_eq_zero.mp h).resolve_left hα linarith have a2 : n11 ≠ 0 := by intro h apply hc3 rw [← a1, h] ring have a3 : n12 = 0 := (mul_eq_zero.mp p1).resolve_left a2 have a4 : n22 ^ 2 = 1 := by linear_combination m22 - n12 * a3 + c * hβ have a5 : n22 ≠ 0 := by intro h rw [h] at a4 norm_num at a4 have a6 : n21 = 0 := (mul_eq_zero.mp p2).resolve_right a5 have a7 : n22 = c3 := by have h : f * (n22 - c3) = 0 := by linear_combination l2 - (2 * α * u1 + e) * a3 - (2 * (n22 * u2)) * hβ have := (mul_eq_zero.mp h).resolve_left hf linarith have a8 : c3 = 1 := by have h0 : 0 ≤ c3 := by rw [← a1]; positivity have h : (c3 - 1) * (c3 + 1) = 0 := by rw [← a7]; linear_combination a4 rcases mul_eq_zero.mp h with h' | h' · linarith · linarith exact ⟨a3, a6, by rw [a1, a8], a4, a8⟩ · -- `α = 0`, `e ≠ 0` left have hβ : β ≠ 0 := by intro h apply hαβ rw [h, hα] have a1 : n22 ^ 2 = c3 := by have h : β * (n22 ^ 2 - c3) = 0 := by linear_combination q22 - n12 ^ 2 * hα have := (mul_eq_zero.mp h).resolve_left hβ linarith have a2 : n22 ≠ 0 := by intro h apply hc3 rw [← a1, h] ring have a3 : n21 = 0 := (mul_eq_zero.mp p2).resolve_right a2 have a4 : n11 ^ 2 = 1 := by linear_combination m11 - n21 * a3 + c * hα have a5 : n11 ≠ 0 := by intro h rw [h] at a4 norm_num at a4 have a6 : n12 = 0 := (mul_eq_zero.mp p1).resolve_left a5 have a7 : n11 = c3 := by have h : e * (n11 - c3) = 0 := by linear_combination l1 - (2 * β * u2 + f) * a3 - (2 * (n11 * u1)) * hα have := (mul_eq_zero.mp h).resolve_left he linarith have a8 : c3 = 1 := by have h0 : 0 ≤ c3 := by rw [← a1]; positivity have h : (c3 - 1) * (c3 + 1) = 0 := by rw [← a7]; linear_combination a4 rcases mul_eq_zero.mp h with h' | h' · linarith · linarith exact ⟨a6, a3, a4, by rw [a1, a8], a8⟩ theorem sq_sign {x y : ℝ} (h : x ^ 2 = y ^ 2) (hs : 0 < x ↔ 0 < y) (hx : x ≠ 0) : x = y := by have h0 : (x - y) * (x + y) = 0 := by linear_combination h rcases mul_eq_zero.mp h0 with h1 | h1 · linarith · exfalso rcases lt_or_gt_of_ne hx with h2 | h2 · have h3 : 0 < y := by linarith have := hs.mpr h3 linarith · have := hs.mp h2 linarith /-- **Rigidity in diagonal coordinates.** A solution is determined by three signs. -/ theorem diag_inj {α β e f k : ℝ} (hαβ : α ≠ β) (hnd : α * β ≠ 0 ∨ (β = 0 ∧ f ≠ 0) ∨ (α = 0 ∧ e ≠ 0)) {n11 n12 n21 n22 u1 u2 c3 c : ℝ} (hc3 : c3 ≠ 0) (h1 : ∀ x y : ℝ, α * (n11 * x + n12 * y + u1) ^ 2 + β * (n21 * x + n22 * y + u2) ^ 2 + e * (n11 * x + n12 * y + u1) + f * (n21 * x + n22 * y + u2) + k = c3 * (α * x ^ 2 + β * y ^ 2 + e * x + f * y + k)) (h2 : ∀ x y : ℝ, (n11 * x + n12 * y) ^ 2 + (n21 * x + n22 * y) ^ 2 = x ^ 2 + y ^ 2 + c * (α * x ^ 2 + β * y ^ 2)) {n11' n12' n21' n22' u1' u2' c3' c' : ℝ} (hc3' : c3' ≠ 0) (h1' : ∀ x y : ℝ, α * (n11' * x + n12' * y + u1') ^ 2 + β * (n21' * x + n22' * y + u2') ^ 2 + e * (n11' * x + n12' * y + u1') + f * (n21' * x + n22' * y + u2') + k = c3' * (α * x ^ 2 + β * y ^ 2 + e * x + f * y + k)) (h2' : ∀ x y : ℝ, (n11' * x + n12' * y) ^ 2 + (n21' * x + n22' * y) ^ 2 = x ^ 2 + y ^ 2 + c' * (α * x ^ 2 + β * y ^ 2)) (cd1 : n12 = 0 ↔ n12' = 0) (cd2 : 0 < n11 + n21 ↔ 0 < n11' + n21') (cd3 : 0 < n22 + n12 ↔ 0 < n22' + n12') : n11 = n11' ∧ n12 = n12' ∧ n21 = n21' ∧ n22 = n22' ∧ u1 = u1' ∧ u2 = u2' := by obtain ⟨q11, q12, q22, l1, l2, k0⟩ := diag_coef1 h1 obtain ⟨m11, m12, m22⟩ := diag_coef2 h2 obtain ⟨q11', q12', q22', l1', l2', k0'⟩ := diag_coef1 h1' obtain ⟨m11', m12', m22'⟩ := diag_coef2 h2' clear h1 h2 h1' h2' rcases diag_nf hαβ hc3 hnd q11 q12 q22 l1 l2 m11 m12 m22 with ⟨a1, a2, a3, a4, a5⟩ | ⟨b1, b2, b3, b4, b5, b6, b7⟩ · rcases diag_nf hαβ hc3' hnd q11' q12' q22' l1' l2' m11' m12' m22' with ⟨a1', a2', a3', a4', a5'⟩ | ⟨b1', b2', b3', b4', b5', b6', b7'⟩ · -- both of diagonal type subst a1 a2 a5 a1' a2' a5' have hn11 : n11 ≠ 0 := by intro h rw [h] at a3 norm_num at a3 have hn22 : n22 ≠ 0 := by intro h rw [h] at a4 norm_num at a4 have e11 : n11 = n11' := sq_sign (by rw [a3, a3']) (by simpa using cd2) hn11 have e22 : n22 = n22' := sq_sign (by rw [a4, a4']) (by simpa using cd3) hn22 subst e11 e22 have t1 : α * (u1 - u1') = 0 := by have h : n11 * (α * (u1 - u1')) = 0 := by linear_combination (1 / 2 : ℝ) * l1 - (1 / 2 : ℝ) * l1' exact (mul_eq_zero.mp h).resolve_left hn11 have t2 : β * (u2 - u2') = 0 := by have h : n22 * (β * (u2 - u2')) = 0 := by linear_combination (1 / 2 : ℝ) * l2 - (1 / 2 : ℝ) * l2' exact (mul_eq_zero.mp h).resolve_left hn22 rcases hnd with hab | ⟨hβ, hf⟩ | ⟨hα, he⟩ · have hα : α ≠ 0 := left_ne_zero_of_mul hab have hβ : β ≠ 0 := right_ne_zero_of_mul hab have r1 := (mul_eq_zero.mp t1).resolve_left hα have r2 := (mul_eq_zero.mp t2).resolve_left hβ exact ⟨rfl, rfl, rfl, rfl, by linarith, by linarith⟩ · have hα : α ≠ 0 := by intro h apply hαβ rw [h, hβ] have r1 : u1 = u1' := by have := (mul_eq_zero.mp t1).resolve_left hα linarith subst r1 have h : f * (u2 - u2') = 0 := by linear_combination k0 - k0' - (u2 ^ 2 - u2' ^ 2) * hβ have r2 := (mul_eq_zero.mp h).resolve_left hf exact ⟨rfl, rfl, rfl, rfl, rfl, by linarith⟩ · have hβ : β ≠ 0 := by intro h apply hαβ rw [h, hα] have r2 : u2 = u2' := by have := (mul_eq_zero.mp t2).resolve_left hβ linarith subst r2 have h : e * (u1 - u1') = 0 := by linear_combination k0 - k0' - (u1 ^ 2 - u1' ^ 2) * hα have r1 := (mul_eq_zero.mp h).resolve_left he exact ⟨rfl, rfl, rfl, rfl, by linarith, rfl⟩ · exact absurd (cd1.mp a1) b3' · rcases diag_nf hαβ hc3' hnd q11' q12' q22' l1' l2' m11' m12' m22' with ⟨a1', a2', a3', a4', a5'⟩ | ⟨b1', b2', b3', b4', b5', b6', b7'⟩ · exact absurd (cd1.mpr a1') b3 · -- both of anti-diagonal type subst b1 b2 b4 b1' b2' b4' have hα : α ≠ 0 := left_ne_zero_of_mul b7 have hβ : β ≠ 0 := right_ne_zero_of_mul b7 have hn21 : n21 ≠ 0 := by intro h rw [h] at b5 apply hα linarith have e21 : n21 = n21' := by refine sq_sign ?_ (by simpa using cd2) hn21 have h : β * (n21 ^ 2 - n21' ^ 2) = 0 := by linear_combination b5 - b5' have := (mul_eq_zero.mp h).resolve_left hβ linarith have e12 : n12 = n12' := by refine sq_sign ?_ (by simpa using cd3) b3 have h : α * (n12 ^ 2 - n12' ^ 2) = 0 := by linear_combination b6 - b6' have := (mul_eq_zero.mp h).resolve_left hα linarith subst e21 e12 have t2 : u2 = u2' := by have h : n21 * (β * (u2 - u2')) = 0 := by linear_combination (1 / 2 : ℝ) * l1 - (1 / 2 : ℝ) * l1' have := (mul_eq_zero.mp ((mul_eq_zero.mp h).resolve_left hn21)).resolve_left hβ linarith have t1 : u1 = u1' := by have h : n12 * (α * (u1 - u1')) = 0 := by linear_combination (1 / 2 : ℝ) * l2 - (1 / 2 : ℝ) * l2' have := (mul_eq_zero.mp ((mul_eq_zero.mp h).resolve_left b3)).resolve_left hα linarith exact ⟨rfl, rfl, rfl, rfl, t1, t2⟩ end E94S /-! ### SOLO slice E3 -/ /-! ## SOLO module E (part 3): rigidity of Ivory maps, general conics -/ namespace E94S open Finset /-- Rotation by the unit vector `(x0, y0)`. -/ def rot (x0 y0 : ℝ) (z : ℂ) : ℂ := ⟨x0 * z.re - y0 * z.im, y0 * z.re + x0 * z.im⟩ /-- The inverse rotation. -/ def roti (x0 y0 : ℝ) (z : ℂ) : ℂ := ⟨x0 * z.re + y0 * z.im, -(y0 * z.re) + x0 * z.im⟩ /-- Conjugation of a map by the rotation. -/ def cj (x0 y0 : ℝ) (U : ℂ → ℂ) (z : ℂ) : ℂ := roti x0 y0 (U (rot x0 y0 z)) theorem rot_roti {x0 y0 : ℝ} (hu : x0 ^ 2 + y0 ^ 2 = 1) (z : ℂ) : rot x0 y0 (roti x0 y0 z) = z := by apply Complex.ext · unfold rot roti dsimp only linear_combination z.re * hu · unfold rot roti dsimp only linear_combination z.im * hu theorem roti_rot {x0 y0 : ℝ} (hu : x0 ^ 2 + y0 ^ 2 = 1) (z : ℂ) : roti x0 y0 (rot x0 y0 z) = z := by apply Complex.ext · unfold rot roti dsimp only linear_combination z.re * hu · unfold rot roti dsimp only linear_combination z.im * hu theorem rot_zero (x0 y0 : ℝ) : rot x0 y0 0 = 0 := by apply Complex.ext <;> simp [rot] theorem dq_roti {x0 y0 : ℝ} (hu : x0 ^ 2 + y0 ^ 2 = 1) (z w : ℂ) : dq (roti x0 y0 z) (roti x0 y0 w) = dq z w := by unfold dq roti dsimp only linear_combination ((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) * hu theorem dq_rot_zero {x0 y0 : ℝ} (hu : x0 ^ 2 + y0 ^ 2 = 1) (z : ℂ) : dq (rot x0 y0 z) 0 = dq z 0 := by unfold dq rot simp only [Complex.zero_re, Complex.zero_im, sub_zero] linear_combination (z.re ^ 2 + z.im ^ 2) * hu /-- A unit direction diagonalising the quadratic form. -/ theorem exists_diag_dir (a b d : ℝ) : ∃ x0 y0 : ℝ, x0 ^ 2 + y0 ^ 2 = 1 ∧ b * (x0 ^ 2 - y0 ^ 2) - (a - d) * (x0 * y0) = 0 := by by_cases hb : b = 0 · exact ⟨1, 0, by norm_num, by rw [hb]; ring⟩ · obtain ⟨Δ, hΔ⟩ : ∃ Δ : ℝ, Δ = Real.sqrt ((a - d) ^ 2 + 4 * b ^ 2) := ⟨_, rfl⟩ have hΔ2 : Δ ^ 2 = (a - d) ^ 2 + 4 * b ^ 2 := by rw [hΔ] exact Real.sq_sqrt (by positivity) obtain ⟨t, ht⟩ : ∃ t : ℝ, t = (-(a - d) + Δ) / (2 * b) := ⟨_, rfl⟩ have ht2 : b * t ^ 2 + (a - d) * t - b = 0 := by have e : b * t ^ 2 + (a - d) * t - b = (Δ ^ 2 - (a - d) ^ 2 - 4 * b ^ 2) / (4 * b) := by rw [ht] field_simp ring have e0 : (a - d) ^ 2 + 4 * b ^ 2 - (a - d) ^ 2 - 4 * b ^ 2 = 0 := by ring rw [e, hΔ2, e0, zero_div] obtain ⟨r, hr⟩ : ∃ r : ℝ, r = Real.sqrt (1 + t ^ 2) := ⟨_, rfl⟩ have hr2 : r ^ 2 = 1 + t ^ 2 := by rw [hr] exact Real.sq_sqrt (by positivity) have hr0 : r ^ 2 ≠ 0 := by rw [hr2] positivity refine ⟨1 / r, t / r, ?_, ?_⟩ · have e : (1 / r) ^ 2 + (t / r) ^ 2 = (1 + t ^ 2) / r ^ 2 := by ring rw [e, ← hr2] exact div_self hr0 · have e : b * ((1 / r) ^ 2 - (t / r) ^ 2) - (a - d) * (1 / r * (t / r)) = -(b * t ^ 2 + (a - d) * t - b) / r ^ 2 := by ring rw [e, ht2, neg_zero, zero_div] theorem qf_rot {a b d e f k x0 y0 : ℝ} (hb : b * (x0 ^ 2 - y0 ^ 2) - (a - d) * (x0 * y0) = 0) (z : ℂ) : qf a b d e f k (rot x0 y0 z) = qf (a * x0 ^ 2 + 2 * b * (x0 * y0) + d * y0 ^ 2) 0 (a * y0 ^ 2 - 2 * b * (x0 * y0) + d * x0 ^ 2) (e * x0 + f * y0) (-(e * y0) + f * x0) k z := by unfold qf rot dsimp only linear_combination (2 * (z.re * z.im)) * hb theorem qA_rot {a b d x0 y0 : ℝ} (hb : b * (x0 ^ 2 - y0 ^ 2) - (a - d) * (x0 * y0) = 0) (z : ℂ) : qA a b d (rot x0 y0 z) = (a * x0 ^ 2 + 2 * b * (x0 * y0) + d * y0 ^ 2) * z.re ^ 2 + (a * y0 ^ 2 - 2 * b * (x0 * y0) + d * x0 ^ 2) * z.im ^ 2 := by unfold qA rot dsimp only linear_combination (2 * (z.re * z.im)) * hb /-- The relations satisfied by `U = T₁⁻¹ ∘ T₂` for two Ivory maps with the same pair of conics. -/ def Rig (a b d e f k : ℝ) (U : ℂ → ℂ) : Prop := (∃ n11 n12 n21 n22 : ℝ, ∃ u : ℂ, ∀ z, U z = linA n11 n12 n21 n22 z + u) ∧ ∃ c3 c : ℝ, c3 ≠ 0 ∧ (∀ z, qf a b d e f k (U z) = c3 * qf a b d e f k z) ∧ (∀ z, dq (U z) (U 0) = dq z 0 + c * qA a b d z) /-- The relations in the rotated (diagonal) coordinates. -/ theorem rig_transport {a b d e f k x0 y0 α β e' f' : ℝ} (hu : x0 ^ 2 + y0 ^ 2 = 1) (hq : ∀ z, qf a b d e f k (rot x0 y0 z) = qf α 0 β e' f' k z) (hQ : ∀ z, qA a b d (rot x0 y0 z) = α * z.re ^ 2 + β * z.im ^ 2) {U : ℂ → ℂ} (hU : Rig a b d e f k U) : ∃ n11 n12 n21 n22 u1 u2 c3 c : ℝ, c3 ≠ 0 ∧ (∀ z, cj x0 y0 U z = ⟨n11 * z.re + n12 * z.im + u1, n21 * z.re + n22 * z.im + u2⟩) ∧ (∀ x y : ℝ, α * (n11 * x + n12 * y + u1) ^ 2 + β * (n21 * x + n22 * y + u2) ^ 2 + e' * (n11 * x + n12 * y + u1) + f' * (n21 * x + n22 * y + u2) + k = c3 * (α * x ^ 2 + β * y ^ 2 + e' * x + f' * y + k)) ∧ (∀ x y : ℝ, (n11 * x + n12 * y) ^ 2 + (n21 * x + n22 * y) ^ 2 = x ^ 2 + y ^ 2 + c * (α * x ^ 2 + β * y ^ 2)) := by obtain ⟨⟨m11, m12, m21, m22, u, hUa⟩, c3, c, hc3, h1, h2⟩ := hU have hV : ∀ z, cj x0 y0 U z = ⟨(x0 * (m11 * x0 + m12 * y0) + y0 * (m21 * x0 + m22 * y0)) * z.re + (x0 * (-(m11 * y0) + m12 * x0) + y0 * (-(m21 * y0) + m22 * x0)) * z.im + (x0 * u.re + y0 * u.im), (-(y0 * (m11 * x0 + m12 * y0)) + x0 * (m21 * x0 + m22 * y0)) * z.re + (-(y0 * (-(m11 * y0) + m12 * x0)) + x0 * (-(m21 * y0) + m22 * x0)) * z.im + (-(y0 * u.re) + x0 * u.im)⟩ := by intro z unfold cj rw [hUa] apply Complex.ext · simp only [roti, rot, linA, Complex.add_re, Complex.add_im] ring · simp only [roti, rot, linA, Complex.add_re, Complex.add_im] ring refine ⟨_, _, _, _, _, _, c3, c, hc3, hV, ?_, ?_⟩ · intro x y have h := h1 (rot x0 y0 ⟨x, y⟩) rw [hq] at h have e1 : qf a b d e f k (U (rot x0 y0 ⟨x, y⟩)) = qf α 0 β e' f' k (cj x0 y0 U ⟨x, y⟩) := by rw [← hq] unfold cj rw [rot_roti hu] rw [e1, hV] at h unfold qf at h dsimp only at h linear_combination h · intro x y have h := h2 (rot x0 y0 ⟨x, y⟩) rw [hQ, dq_rot_zero hu] at h have e2 : dq (U (rot x0 y0 ⟨x, y⟩)) (U 0) = dq (cj x0 y0 U ⟨x, y⟩) (cj x0 y0 U 0) := by unfold cj rw [dq_roti hu, rot_zero] rw [e2, hV, hV] at h unfold dq at h simp only [Complex.zero_re, Complex.zero_im, sub_zero] at h linear_combination h theorem code_vals {V : ℂ → ℂ} {n11 n12 n21 n22 u1 u2 : ℝ} (hV : ∀ z, V z = ⟨n11 * z.re + n12 * z.im + u1, n21 * z.re + n22 * z.im + u2⟩) : (V Complex.I - V 0).re = n12 ∧ (V 1 - V 0).re = n11 ∧ (V 1 - V 0).im = n21 ∧ (V Complex.I - V 0).im = n22 := by refine ⟨?_, ?_, ?_, ?_⟩ <;> simp [hV] theorem three_roots {α ε k r1 r2 r3 : ℝ} (hα : α ≠ 0) (h1 : α * r1 ^ 2 + ε * r1 + k = 0) (h2 : α * r2 ^ 2 + ε * r2 + k = 0) (h3 : α * r3 ^ 2 + ε * r3 + k = 0) (h12 : r1 ≠ r2) (h13 : r1 ≠ r3) (h23 : r2 ≠ r3) : False := by have a1 : α * (r1 + r2) + ε = 0 := by have h : (r1 - r2) * (α * (r1 + r2) + ε) = 0 := by linear_combination h1 - h2 exact (mul_eq_zero.mp h).resolve_left (sub_ne_zero.mpr h12) have a2 : α * (r1 + r3) + ε = 0 := by have h : (r1 - r3) * (α * (r1 + r3) + ε) = 0 := by linear_combination h1 - h3 exact (mul_eq_zero.mp h).resolve_left (sub_ne_zero.mpr h13) have h : α * (r2 - r3) = 0 := by linear_combination a1 - a2 rcases mul_eq_zero.mp h with h' | h' · exact hα h' · exact h23 (by linarith) /-- Five points whose `g`-values are roots of one quadratic: three of them share a value. -/ theorem fiber3 {F : Finset ℂ} (hF5 : F.card = 5) (g : ℂ → ℝ) {α ε k : ℝ} (hα : α ≠ 0) (hroot : ∀ p ∈ F, α * (g p) ^ 2 + ε * g p + k = 0) : ∃ p ∈ F, ∃ q ∈ F, ∃ r ∈ F, p ≠ q ∧ p ≠ r ∧ q ≠ r ∧ g p = g q ∧ g p = g r := by classical have hcard : (F.image g).card ≤ 2 := by by_contra hcon push_neg at hcon obtain ⟨r1, h1, r2, h2, r3, h3, h12, h13, h23⟩ := two_lt_card.mp hcon obtain ⟨p1, hp1, rfl⟩ := mem_image.mp h1 obtain ⟨p2, hp2, rfl⟩ := mem_image.mp h2 obtain ⟨p3, hp3, rfl⟩ := mem_image.mp h3 exact three_roots hα (hroot p1 hp1) (hroot p2 hp2) (hroot p3 hp3) h12 h13 h23 obtain ⟨y, _, hy⟩ := exists_lt_card_fiber_of_mul_lt_card_of_maps_to (s := F) (t := F.image g) (f := g) (n := 2) (fun p hp => mem_image_of_mem g hp) (by rw [hF5]; omega) obtain ⟨p, hp, q, hq, r, hr, hpq, hpr, hqr⟩ := two_lt_card.mp hy obtain ⟨hp1, hp2⟩ := mem_filter.mp hp obtain ⟨hq1, hq2⟩ := mem_filter.mp hq obtain ⟨hr1, hr2⟩ := mem_filter.mp hr exact ⟨p, hp1, q, hq1, r, hr1, hpq, hpr, hqr, by rw [hp2, hq2], by rw [hp2, hr2]⟩ /-- Non-degeneracy of a conic through five points, no three collinear, in diagonal coordinates. -/ theorem nondeg {a b d e f k x0 y0 α β e' f' : ℝ} (hu : x0 ^ 2 + y0 ^ 2 = 1) (hαβ : α ≠ β) (hq : ∀ z, qf a b d e f k (rot x0 y0 z) = qf α 0 β e' f' k z) {F : Finset ℂ} (hF5 : F.card = 5) (hFz : ∀ p ∈ F, qf a b d e f k p = 0) (hFnc : ∀ p ∈ F, ∀ q ∈ F, ∀ r ∈ F, p ≠ q → p ≠ r → q ≠ r → cr3 p q r ≠ 0) : α * β ≠ 0 ∨ (β = 0 ∧ f' ≠ 0) ∨ (α = 0 ∧ e' ≠ 0) := by have hz : ∀ p ∈ F, qf α 0 β e' f' k (roti x0 y0 p) = 0 := by intro p hp rw [← hq, rot_roti hu] exact hFz p hp have hxy : x0 ≠ 0 ∨ y0 ≠ 0 := by by_contra hcon push_neg at hcon rw [hcon.1, hcon.2] at hu norm_num at hu by_cases hab : α * β = 0 swap · exact Or.inl hab right rcases mul_eq_zero.mp hab with h0 | h0 · right refine ⟨h0, ?_⟩ intro he have hβ : β ≠ 0 := by intro h apply hαβ rw [h0, h] obtain ⟨p, hp, q, hq', r, hr, hpq, hpr, hqr, e1, e2⟩ := fiber3 hF5 (fun p => (roti x0 y0 p).im) (α := β) (ε := f') (k := k) hβ (by intro p hp show β * (roti x0 y0 p).im ^ 2 + f' * (roti x0 y0 p).im + k = 0 have h := hz p hp unfold qf at h rw [h0, he] at h linear_combination h) apply hFnc p hp q hq' r hr hpq hpr hqr simp only [roti] at e1 e2 refine cr3_zero_of_orth (e1 := -y0) (e2 := x0) ?_ ?_ ?_ · rcases hxy with h | h · exact Or.inr h · left intro h' apply h linarith · linear_combination (-1 : ℝ) * e1 · linear_combination (-1 : ℝ) * e2 · left refine ⟨h0, ?_⟩ intro hf have hα : α ≠ 0 := by intro h apply hαβ rw [h0, h] obtain ⟨p, hp, q, hq', r, hr, hpq, hpr, hqr, e1, e2⟩ := fiber3 hF5 (fun p => (roti x0 y0 p).re) (α := α) (ε := e') (k := k) hα (by intro p hp show α * (roti x0 y0 p).re ^ 2 + e' * (roti x0 y0 p).re + k = 0 have h := hz p hp unfold qf at h rw [h0, hf] at h linear_combination h) apply hFnc p hp q hq' r hr hpq hpr hqr simp only [roti] at e1 e2 refine cr3_zero_of_orth (e1 := x0) (e2 := y0) hxy ?_ ?_ · linear_combination (-1 : ℝ) * e1 · linear_combination (-1 : ℝ) * e2 /-- **Rigidity.** For a non-circular conic through five points, no three collinear, the maps `U` satisfying the Ivory relations are determined by a code with eight values. -/ theorem rigid {a b d e f k : ℝ} (hns : ¬ (a = d ∧ b = 0)) {F : Finset ℂ} (hF5 : F.card = 5) (hFz : ∀ p ∈ F, qf a b d e f k p = 0) (hFnc : ∀ p ∈ F, ∀ q ∈ F, ∀ r ∈ F, p ≠ q → p ≠ r → q ≠ r → cr3 p q r ≠ 0) : ∃ code : (ℂ → ℂ) → Bool × Bool × Bool, ∀ U U' : ℂ → ℂ, Rig a b d e f k U → Rig a b d e f k U' → code U = code U' → U = U' := by classical obtain ⟨x0, y0, hu, hb⟩ := exists_diag_dir a b d obtain ⟨α, hα⟩ : ∃ α : ℝ, α = a * x0 ^ 2 + 2 * b * (x0 * y0) + d * y0 ^ 2 := ⟨_, rfl⟩ obtain ⟨β, hβ⟩ : ∃ β : ℝ, β = a * y0 ^ 2 - 2 * b * (x0 * y0) + d * x0 ^ 2 := ⟨_, rfl⟩ obtain ⟨e', he'⟩ : ∃ e' : ℝ, e' = e * x0 + f * y0 := ⟨_, rfl⟩ obtain ⟨f', hf'⟩ : ∃ f' : ℝ, f' = -(e * y0) + f * x0 := ⟨_, rfl⟩ have hq : ∀ z, qf a b d e f k (rot x0 y0 z) = qf α 0 β e' f' k z := by intro z rw [hα, hβ, he', hf'] exact qf_rot hb z have hQ : ∀ z, qA a b d (rot x0 y0 z) = α * z.re ^ 2 + β * z.im ^ 2 := by intro z rw [hα, hβ] exact qA_rot hb z have hαβ : α ≠ β := by intro h apply hns rw [hα, hβ] at h constructor · linear_combination (x0 ^ 2 - y0 ^ 2) * h - 2 * (2 * x0 * y0) * hb - (a - d) * (x0 ^ 2 + y0 ^ 2 + 1) * hu · linear_combination (1 / 2 : ℝ) * ((2 * x0 * y0) * h + 2 * (x0 ^ 2 - y0 ^ 2) * hb - 2 * b * (x0 ^ 2 + y0 ^ 2 + 1) * hu) have hnd := nondeg hu hαβ hq hF5 hFz hFnc refine ⟨fun U => (decide ((cj x0 y0 U Complex.I - cj x0 y0 U 0).re = 0), decide (0 < (cj x0 y0 U 1 - cj x0 y0 U 0).re + (cj x0 y0 U 1 - cj x0 y0 U 0).im), decide (0 < (cj x0 y0 U Complex.I - cj x0 y0 U 0).im + (cj x0 y0 U Complex.I - cj x0 y0 U 0).re)), ?_⟩ intro U U' hU hU' hcode obtain ⟨n11, n12, n21, n22, u1, u2, c3, c, hc3, hV, h1, h2⟩ := rig_transport hu hq hQ hU obtain ⟨n11', n12', n21', n22', u1', u2', c3', c', hc3', hV', h1', h2'⟩ := rig_transport hu hq hQ hU' obtain ⟨v1, v2, v3, v4⟩ := code_vals hV obtain ⟨v1', v2', v3', v4'⟩ := code_vals hV' simp only [Prod.mk.injEq, decide_eq_decide] at hcode obtain ⟨cd1, cd2, cd3⟩ := hcode rw [v1, v1'] at cd1 rw [v2, v3, v2', v3'] at cd2 rw [v4, v1, v4', v1'] at cd3 obtain ⟨r1, r2, r3, r4, r5, r6⟩ := diag_inj hαβ hnd hc3 h1 h2 hc3' h1' h2' cd1 cd2 cd3 funext w have hw : U w = rot x0 y0 (cj x0 y0 U (roti x0 y0 w)) := by unfold cj rw [rot_roti hu, rot_roti hu] have hw' : U' w = rot x0 y0 (cj x0 y0 U' (roti x0 y0 w)) := by unfold cj rw [rot_roti hu, rot_roti hu] rw [hw, hw', hV, hV', r1, r2, r3, r4, r5, r6] end E94S /-! ### SOLO slice E4 -/ /-! ## SOLO module E (part 4): the affine map of an Ivory window and the rigidity relations -/ namespace E94S open Finset /-- The affine map of a window: primed poles to unprimed poles. -/ def affT (l11 l12 l21 l22 : ℝ) (q : ℂ) (z : ℂ) : ℂ := linT l11 l12 l21 l22 z + q /-- Its inverse. -/ noncomputable def affTi (l11 l12 l21 l22 : ℝ) (q : ℂ) (x : ℂ) : ℂ := ⟨(l22 * (x.re - q.re) - l21 * (x.im - q.im)) / (l11 * l22 - l12 * l21), (-(l12 * (x.re - q.re)) + l11 * (x.im - q.im)) / (l11 * l22 - l12 * l21)⟩ theorem affT_affTi {l11 l12 l21 l22 : ℝ} (hdet : l11 * l22 - l12 * l21 ≠ 0) (q x : ℂ) : affT l11 l12 l21 l22 q (affTi l11 l12 l21 l22 q x) = x := by have hi : (l11 * l22 - l12 * l21) * (l11 * l22 - l12 * l21)⁻¹ = 1 := mul_inv_cancel₀ hdet apply Complex.ext · simp only [affT, affTi, linT, Complex.add_re, div_eq_mul_inv] linear_combination (x.re - q.re) * hi · simp only [affT, affTi, linT, Complex.add_im, div_eq_mul_inv] linear_combination (x.im - q.im) * hi theorem affTi_affT {l11 l12 l21 l22 : ℝ} (hdet : l11 * l22 - l12 * l21 ≠ 0) (q z : ℂ) : affTi l11 l12 l21 l22 q (affT l11 l12 l21 l22 q z) = z := by have hi : (l11 * l22 - l12 * l21) * (l11 * l22 - l12 * l21)⁻¹ = 1 := mul_inv_cancel₀ hdet apply Complex.ext · simp only [affT, affTi, linT, Complex.add_re, Complex.add_im, div_eq_mul_inv] linear_combination z.re * hi · simp only [affT, affTi, linT, Complex.add_re, Complex.add_im, div_eq_mul_inv] linear_combination z.im * hi /-- The quadratic function of a window with respect to one of its matches `(Y, Z)`. -/ def wD (l11 l12 l21 l22 : ℝ) (q Y Z : ℂ) (z : ℂ) : ℝ := dq (affT l11 l12 l21 l22 q z) Y - dq z Z /-- The quadratic form `|Lᵀ w|² - |w|²`. -/ def qL (l11 l12 l21 l22 : ℝ) (w : ℂ) : ℝ := dq (linT l11 l12 l21 l22 w) 0 - dq w 0 theorem wD_qf (l11 l12 l21 l22 : ℝ) (q Y Z z : ℂ) : wD l11 l12 l21 l22 q Y Z z = qf (l11 ^ 2 + l12 ^ 2 - 1) (l11 * l21 + l12 * l22) (l21 ^ 2 + l22 ^ 2 - 1) (2 * (l11 * (q.re - Y.re) + l12 * (q.im - Y.im)) + 2 * Z.re) (2 * (l21 * (q.re - Y.re) + l22 * (q.im - Y.im)) + 2 * Z.im) (dq q Y - (Z.re ^ 2 + Z.im ^ 2)) z := by unfold wD affT linT qf dq simp only [Complex.add_re, Complex.add_im] ring theorem qL_qA (l11 l12 l21 l22 : ℝ) (w : ℂ) : qA (l11 ^ 2 + l12 ^ 2 - 1) (l11 * l21 + l12 * l22) (l21 ^ 2 + l22 ^ 2 - 1) w = qL l11 l12 l21 l22 w := by unfold qL qA linT dq simp only [Complex.zero_re, Complex.zero_im, sub_zero] ring theorem affT_dq (l11 l12 l21 l22 : ℝ) (q x y : ℂ) : dq (affT l11 l12 l21 l22 q x) (affT l11 l12 l21 l22 q y) = dq x y + qL l11 l12 l21 l22 (x - y) := by unfold qL affT linT dq simp only [Complex.add_re, Complex.add_im, Complex.sub_re, Complex.sub_im, Complex.zero_re, Complex.zero_im, sub_zero] ring theorem wD_par (l11 l12 l21 l22 : ℝ) (q Y Z u w : ℂ) : wD l11 l12 l21 l22 q Y Z (u + w) + wD l11 l12 l21 l22 q Y Z (u - w) - 2 * wD l11 l12 l21 l22 q Y Z u = 2 * qL l11 l12 l21 l22 w := by unfold wD qL affT linT dq simp only [Complex.add_re, Complex.add_im, Complex.sub_re, Complex.sub_im, Complex.zero_re, Complex.zero_im, sub_zero] ring theorem isQF_gen (σ τ c1 c2 c0 d1 d2 d0 : ℝ) (Y Z : ℂ) : IsQF (fun x => σ * dq x Y + τ * dq ⟨c1 * x.re + c2 * x.im + c0, d1 * x.re + d2 * x.im + d0⟩ Z) := by refine ⟨σ + τ * (c1 ^ 2 + d1 ^ 2), τ * (c1 * c2 + d1 * d2), σ + τ * (c2 ^ 2 + d2 ^ 2), -(2 * σ * Y.re) + 2 * τ * (c1 * (c0 - Z.re) + d1 * (d0 - Z.im)), -(2 * σ * Y.im) + 2 * τ * (c2 * (c0 - Z.re) + d2 * (d0 - Z.im)), σ * (Y.re ^ 2 + Y.im ^ 2) + τ * ((c0 - Z.re) ^ 2 + (d0 - Z.im) ^ 2), fun x => ?_⟩ unfold dq qf dsimp only ring theorem isQF_wD (l11 l12 l21 l22 : ℝ) (q Y Z : ℂ) : IsQF (wD l11 l12 l21 l22 q Y Z) := ⟨_, _, _, _, _, _, wD_qf l11 l12 l21 l22 q Y Z⟩ theorem isQF_wD_inv {l11 l12 l21 l22 : ℝ} (hdet : l11 * l22 - l12 * l21 ≠ 0) (q Y Z : ℂ) : IsQF (fun x => wD l11 l12 l21 l22 q Y Z (affTi l11 l12 l21 l22 q x)) := by obtain ⟨a, b, d, e, f, k, h⟩ := isQF_gen 1 (-1) (l22 / (l11 * l22 - l12 * l21)) (-l21 / (l11 * l22 - l12 * l21)) ((-(l22 * q.re) + l21 * q.im) / (l11 * l22 - l12 * l21)) (-l12 / (l11 * l22 - l12 * l21)) (l11 / (l11 * l22 - l12 * l21)) ((l12 * q.re - l11 * q.im) / (l11 * l22 - l12 * l21)) Y Z refine ⟨a, b, d, e, f, k, fun x => ?_⟩ rw [← h x] have e1 : affTi l11 l12 l21 l22 q x = ⟨l22 / (l11 * l22 - l12 * l21) * x.re + -l21 / (l11 * l22 - l12 * l21) * x.im + (-(l22 * q.re) + l21 * q.im) / (l11 * l22 - l12 * l21), -l12 / (l11 * l22 - l12 * l21) * x.re + l11 / (l11 * l22 - l12 * l21) * x.im + (l12 * q.re - l11 * q.im) / (l11 * l22 - l12 * l21)⟩ := by apply Complex.ext · simp only [affTi] ring · simp only [affTi] ring show wD l11 l12 l21 l22 q Y Z (affTi l11 l12 l21 l22 q x) = 1 * dq x Y + -1 * dq _ Z unfold wD rw [affT_affTi hdet, e1] ring theorem qf_zero_coef {a b d e f k : ℝ} (h : ∀ z, qf a b d e f k z = 0) : a = 0 ∧ b = 0 ∧ d = 0 := by have h00 := h ⟨0, 0⟩ have h10 := h ⟨1, 0⟩ have hm0 := h ⟨-1, 0⟩ have h01 := h ⟨0, 1⟩ have h0m := h ⟨0, -1⟩ have h11 := h ⟨1, 1⟩ unfold qf at h00 h10 hm0 h01 h0m h11 dsimp only at h00 h10 hm0 h01 h0m h11 refine ⟨?_, ?_, ?_⟩ · linear_combination (1 / 2 : ℝ) * h10 + (1 / 2 : ℝ) * hm0 - h00 · linear_combination (1 / 2 : ℝ) * h11 - (1 / 2 : ℝ) * h10 - (1 / 2 : ℝ) * h01 + (1 / 2 : ℝ) * h00 · linear_combination (1 / 2 : ℝ) * h01 + (1 / 2 : ℝ) * h0m - h00 /-- The quadratic function of an Ivory window is not identically zero. -/ theorem wD_ne {l11 l12 l21 l22 : ℝ} (hns : ¬ (l21 ^ 2 + l22 ^ 2 = l11 ^ 2 + l12 ^ 2 ∧ l11 * l21 + l12 * l22 = 0)) (q Y Z : ℂ) : ∃ z, wD l11 l12 l21 l22 q Y Z z ≠ 0 := by by_contra hcon push_neg at hcon have h : ∀ z, qf (l11 ^ 2 + l12 ^ 2 - 1) (l11 * l21 + l12 * l22) (l21 ^ 2 + l22 ^ 2 - 1) (2 * (l11 * (q.re - Y.re) + l12 * (q.im - Y.im)) + 2 * Z.re) (2 * (l21 * (q.re - Y.re) + l22 * (q.im - Y.im)) + 2 * Z.im) (dq q Y - (Z.re ^ 2 + Z.im ^ 2)) z = 0 := by intro z rw [← wD_qf] exact hcon z obtain ⟨ha, hb, hd⟩ := qf_zero_coef h exact hns ⟨by linarith, hb⟩ theorem exists_five {α : Type*} [DecidableEq α] {F : Finset α} (h : F.card = 5) : ∃ a ∈ F, ∃ b ∈ F, ∃ c ∈ F, ∃ d ∈ F, ∃ e ∈ F, a ≠ b ∧ a ≠ c ∧ a ≠ d ∧ a ≠ e ∧ b ≠ c ∧ b ≠ d ∧ b ≠ e ∧ c ≠ d ∧ c ≠ e ∧ d ≠ e := by obtain ⟨a, t, hat, rfl, ht⟩ := card_eq_succ.mp h obtain ⟨b, t', hbt, rfl, ht'⟩ := card_eq_succ.mp ht obtain ⟨c, d, e, hcd, hce, hde, rfl⟩ := card_eq_three.mp ht' simp only [mem_insert, mem_singleton, not_or] at hat hbt exact ⟨a, by simp, b, by simp, c, by simp, d, by simp, e, by simp, hat.1, hat.2.1, hat.2.2.1, hat.2.2.2, hbt.1, hbt.2.1, hbt.2.2, hcd, hce, hde⟩ /-- Five-point lemma for five vertices of a convex polygon. -/ theorem five_pt_lab {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) {D D' : ℂ → ℝ} (hD : IsQF D) (hD' : IsQF D') {F : Finset ℕ} (hF5 : F.card = 5) (hFn : ∀ i ∈ F, i < n) (hz : ∀ i ∈ F, D (v i) = 0) (hz' : ∀ i ∈ F, D' (v i) = 0) (hne : ∃ z, D z ≠ 0) : ∃ s : ℝ, ∀ z, D' z = s * D z := by obtain ⟨i1, h1, i2, h2, i3, h3, i4, h4, i5, h5, n12, n13, n14, n15, n23, n24, n25, n34, n35, n45⟩ := exists_five hF5 exact five_pt hD' hD (ccw_cr3_ne hccw (hFn i1 h1) (hFn i2 h2) (hFn i3 h3) n12 n13 n23) (ccw_cr3_ne hccw (hFn i1 h1) (hFn i2 h2) (hFn i4 h4) n12 n14 n24) (ccw_cr3_ne hccw (hFn i1 h1) (hFn i2 h2) (hFn i5 h5) n12 n15 n25) (ccw_cr3_ne hccw (hFn i3 h3) (hFn i4 h4) (hFn i5 h5) n34 n35 n45) (hz' i1 h1) (hz' i2 h2) (hz' i3 h3) (hz' i4 h4) (hz' i5 h5) (hz i1 h1) (hz i2 h2) (hz i3 h3) (hz i4 h4) (hz i5 h5) hne /-- The window function vanishes at the primed poles. -/ theorem win_zero {v : ℕ → ℂ} {n : ℕ} {w : Finset (ℕ × ℕ)} {l11 l12 l21 l22 : ℝ} {q : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q) {m : ℕ × ℕ} (hm : m ∈ w) {pp : ℕ × ℕ} (hpp : pp ∈ wsol v n w) : wD l11 l12 l21 l22 q (v m.1) (v m.2) (v pp.2) = 0 := by unfold wD affT rw [← hpole pp hpp] exact sub_eq_zero.mpr ((mem_wsol.mp hpp).2 m hm) theorem win_zero_inv {v : ℕ → ℂ} {n : ℕ} {w : Finset (ℕ × ℕ)} {l11 l12 l21 l22 : ℝ} {q : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q) (hdet : l11 * l22 - l12 * l21 ≠ 0) {m : ℕ × ℕ} (hm : m ∈ w) {pp : ℕ × ℕ} (hpp : pp ∈ wsol v n w) : wD l11 l12 l21 l22 q (v m.1) (v m.2) (affTi l11 l12 l21 l22 q (v pp.1)) = 0 := by have e : affTi l11 l12 l21 l22 q (v pp.1) = v pp.2 := by rw [hpole pp hpp] exact affTi_affT hdet q (v pp.2) rw [e] exact win_zero hpole hm hpp /-- **The rigidity relations**, from the two proportionalities. -/ theorem rig_abs {l11 l12 l21 l22 : ℝ} {q : ℂ} {l11' l12' l21' l22' : ℝ} {q' : ℂ} (hdet : l11 * l22 - l12 * l21 ≠ 0) (hdet' : l11' * l22' - l12' * l21' ≠ 0) {Y Z Y' Z' : ℂ} {s t : ℝ} (hs0 : s ≠ 0) (ht0 : t ≠ 0) (hs : ∀ z, wD l11' l12' l21' l22' q' Y' Z' z = s * wD l11 l12 l21 l22 q Y Z z) (ht : ∀ x, wD l11' l12' l21' l22' q' Y' Z' (affTi l11' l12' l21' l22' q' x) = t * wD l11 l12 l21 l22 q Y Z (affTi l11 l12 l21 l22 q x)) : Rig (l11 ^ 2 + l12 ^ 2 - 1) (l11 * l21 + l12 * l22) (l21 ^ 2 + l22 ^ 2 - 1) (2 * (l11 * (q.re - Y.re) + l12 * (q.im - Y.im)) + 2 * Z.re) (2 * (l21 * (q.re - Y.re) + l22 * (q.im - Y.im)) + 2 * Z.im) (dq q Y - (Z.re ^ 2 + Z.im ^ 2)) (fun z => affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z)) := by have hR1 : ∀ z, wD l11 l12 l21 l22 q Y Z (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z)) = s / t * wD l11 l12 l21 l22 q Y Z z := by intro z have h := ht (affT l11' l12' l21' l22' q' z) rw [affTi_affT hdet', hs] at h rw [div_mul_eq_mul_div, eq_div_iff ht0] linarith have haff : ∀ z, affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z) = linA ((l22 * l11' - l21 * l12') / (l11 * l22 - l12 * l21)) ((l22 * l21' - l21 * l22') / (l11 * l22 - l12 * l21)) ((-(l12 * l11') + l11 * l12') / (l11 * l22 - l12 * l21)) ((-(l12 * l21') + l11 * l22') / (l11 * l22 - l12 * l21)) z + affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0) := by intro z apply Complex.ext · simp only [affTi, affT, linT, linA, Complex.add_re, Complex.add_im, Complex.zero_re, Complex.zero_im] ring · simp only [affTi, affT, linT, linA, Complex.add_re, Complex.add_im, Complex.zero_re, Complex.zero_im] ring have hneg : ∀ z, affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0) - (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z) - affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0)) = affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' (-z)) := by intro z rw [haff z, haff (-z)] apply Complex.ext · simp only [linA, Complex.add_re, Complex.sub_re, Complex.neg_re, Complex.neg_im] ring · simp only [linA, Complex.add_im, Complex.sub_im, Complex.neg_re, Complex.neg_im] ring have key : ∀ z, qL l11 l12 l21 l22 (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z) - affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0)) = s / t * qL l11 l12 l21 l22 z := by intro z have p1 := wD_par l11 l12 l21 l22 q Y Z (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0)) (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z) - affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0)) rw [add_sub_cancel, hneg, hR1 z, hR1 (-z), hR1 0] at p1 have p2 := wD_par l11 l12 l21 l22 q Y Z 0 z rw [zero_add, zero_sub] at p2 linear_combination (-1 / 2 : ℝ) * p1 + (s / t / 2) * p2 have hq' : ∀ z, qL l11' l12' l21' l22' z = s * qL l11 l12 l21 l22 z := by intro z have p1 := wD_par l11' l12' l21' l22' q' Y' Z' 0 z have p2 := wD_par l11 l12 l21 l22 q Y Z 0 z rw [zero_add, zero_sub, hs, hs, hs] at p1 rw [zero_add, zero_sub] at p2 linear_combination (-1 / 2 : ℝ) * p1 + (s / 2) * p2 refine ⟨⟨_, _, _, _, _, haff⟩, s / t, s - s / t, div_ne_zero hs0 ht0, ?_, ?_⟩ · intro z rw [← wD_qf, ← wD_qf] exact hR1 z · intro z have h3 := affT_dq l11 l12 l21 l22 q (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z)) (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0)) rw [affT_affTi hdet, affT_affTi hdet] at h3 have h4 := affT_dq l11' l12' l21' l22' q' z 0 rw [sub_zero] at h4 rw [qL_qA] show dq (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z)) (affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' 0)) = _ linear_combination h4 - h3 - key z + hq' z end E94S /-! ### SOLO slice E5 -/ /-! ## SOLO module E (part 5): at most `8 |Y4|` rich Ivory windows per anchor -/ namespace E94S open Finset /-- Two Ivory windows with a common anchor `(F', F)` give a solution of the rigidity relations. -/ theorem rig_of_windows {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) {w w' : Finset (ℕ × ℕ)} {l11 l12 l21 l22 : ℝ} {q : ℂ} {l11' l12' l21' l22' : ℝ} {q' : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q) (hdet : l11 * l22 - l12 * l21 ≠ 0) (hns : ¬ (l21 ^ 2 + l22 ^ 2 = l11 ^ 2 + l12 ^ 2 ∧ l11 * l21 + l12 * l22 = 0)) (hpole' : ∀ pp ∈ wsol v n w', v pp.1 = linT l11' l12' l21' l22' (v pp.2) + q') (hdet' : l11' * l22' - l12' * l21' ≠ 0) (hns' : ¬ (l21' ^ 2 + l22' ^ 2 = l11' ^ 2 + l12' ^ 2 ∧ l11' * l21' + l12' * l22' = 0)) {m m' : ℕ × ℕ} (hm : m ∈ w) (hm' : m' ∈ w') {F' F : Finset ℕ} (hF'5 : F'.card = 5) (hF5 : F.card = 5) (h1 : F' ⊆ (wsol v n w).image Prod.snd) (h2 : F ⊆ (wsol v n w).image Prod.fst) (h1' : F' ⊆ (wsol v n w').image Prod.snd) (h2' : F ⊆ (wsol v n w').image Prod.fst) : Rig (l11 ^ 2 + l12 ^ 2 - 1) (l11 * l21 + l12 * l22) (l21 ^ 2 + l22 ^ 2 - 1) (2 * (l11 * (q.re - (v m.1).re) + l12 * (q.im - (v m.1).im)) + 2 * (v m.2).re) (2 * (l21 * (q.re - (v m.1).re) + l22 * (q.im - (v m.1).im)) + 2 * (v m.2).im) (dq q (v m.1) - ((v m.2).re ^ 2 + (v m.2).im ^ 2)) (fun z => affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z)) := by classical have hF'n : ∀ i ∈ F', i < n := by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (h1 hi) exact (mem_wsol.mp hpp).1.2 have hFn : ∀ i ∈ F, i < n := by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (h2 hi) exact (mem_wsol.mp hpp).1.1 obtain ⟨s, hs⟩ := five_pt_lab hccw (isQF_wD l11 l12 l21 l22 q (v m.1) (v m.2)) (isQF_wD l11' l12' l21' l22' q' (v m'.1) (v m'.2)) hF'5 hF'n (by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (h1 hi) exact win_zero hpole hm hpp) (by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (h1' hi) exact win_zero hpole' hm' hpp) (wD_ne hns q (v m.1) (v m.2)) have hs0 : s ≠ 0 := by intro h0 obtain ⟨z, hz⟩ := wD_ne hns' q' (v m'.1) (v m'.2) apply hz rw [hs, h0, zero_mul] obtain ⟨t, ht⟩ := five_pt_lab hccw (isQF_wD_inv hdet q (v m.1) (v m.2)) (isQF_wD_inv hdet' q' (v m'.1) (v m'.2)) hF5 hFn (by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (h2 hi) exact win_zero_inv hpole hdet hm hpp) (by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (h2' hi) exact win_zero_inv hpole' hdet' hm' hpp) (by obtain ⟨z, hz⟩ := wD_ne hns q (v m.1) (v m.2) refine ⟨affT l11 l12 l21 l22 q z, ?_⟩ show wD l11 l12 l21 l22 q (v m.1) (v m.2) (affTi l11 l12 l21 l22 q (affT l11 l12 l21 l22 q z)) ≠ 0 rw [affTi_affT hdet] exact hz) have ht' : ∀ x, wD l11' l12' l21' l22' q' (v m'.1) (v m'.2) (affTi l11' l12' l21' l22' q' x) = t * wD l11 l12 l21 l22 q (v m.1) (v m.2) (affTi l11 l12 l21 l22 q x) := ht have ht0 : t ≠ 0 := by intro h0 obtain ⟨z, hz⟩ := wD_ne hns' q' (v m'.1) (v m'.2) apply hz have h := ht' (affT l11' l12' l21' l22' q' z) rw [affTi_affT hdet', h0, zero_mul] at h exact h exact rig_abs hdet hdet' hs0 ht0 hs ht' /-- A window is determined by its affine map, three primed poles and its unprimed free ends. -/ theorem win_unique {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {w w' : Finset (ℕ × ℕ)} (hw : IsWin n w) (hw' : IsWin n w') {l11 l12 l21 l22 : ℝ} {q : ℂ} {l11' l12' l21' l22' : ℝ} {q' : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q) (hpole' : ∀ pp ∈ wsol v n w', v pp.1 = linT l11' l12' l21' l22' (v pp.2) + q') (hT : ∀ z, affT l11 l12 l21 l22 q z = affT l11' l12' l21' l22' q' z) {F' : Finset ℕ} (hF'5 : F'.card = 5) (h1 : F' ⊆ (wsol v n w).image Prod.snd) (h1' : F' ⊆ (wsol v n w').image Prod.snd) (hfst : w.image Prod.fst = w'.image Prod.fst) : w = w' := by classical obtain ⟨i1, a1, i2, a2, i3, a3, i4, a4, i5, a5, n12, n13, n14, n15, n23, n24, n25, n34, n35, n45⟩ := exists_five hF'5 have hF'n : ∀ i ∈ F', i < n := by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (h1 hi) exact (mem_wsol.mp hpp).1.2 have hsub : w ⊆ w' := by intro m hm have hm1' : m.1 ∈ w'.image Prod.fst := by rw [← hfst] exact mem_image_of_mem _ hm obtain ⟨m', hm', hm1⟩ := mem_image.mp hm1' have heq : ∀ i ∈ F', dq (v i) (v m.2) = dq (v i) (v m'.2) := by intro i hi obtain ⟨pp, hpp, hp2⟩ := mem_image.mp (h1 hi) obtain ⟨pp', hpp', hp2'⟩ := mem_image.mp (h1' hi) have e1 := (mem_wsol.mp hpp).2 m hm have e2 := (mem_wsol.mp hpp').2 m' hm' have e3 : v pp.1 = v pp'.1 := by rw [hpole pp hpp, hpole' pp' hpp', hp2, hp2'] exact hT (v i) rw [hp2] at e1 rw [hp2'] at e2 rw [← e1, ← e2, e3, hm1] have hv : v m.2 = v m'.2 := eq_of_three_equidist (ccw_cr3_ne hccw (hF'n i1 a1) (hF'n i2 a2) (hF'n i3 a3) n12 n13 n23) (heq i1 a1) (heq i2 a2) (heq i3 a3) have h2 : m.2 = m'.2 := hinj m.2 (hw.2.1 m hm).2 m'.2 (hw'.2.1 m' hm').2 hv have hmm : m = m' := Prod.ext hm1.symm h2 rw [hmm] exact hm' exact eq_of_subset_of_card_le hsub (by rw [hw.1, hw'.1]) /-- The possible sets of unprimed free ends of a window. -/ noncomputable def Y4 (n G : ℕ) : Finset (Finset ℕ) := (range (n / G + 1)).biUnion (fun i => powersetCard 4 (blk n G i)) theorem Y4_card (n G : ℕ) (hG : 0 < G) : (Y4 n G).card ≤ (n / G + 1) * G ^ 4 := by unfold Y4 refine le_trans card_biUnion_le ?_ have h1 : ∀ i ∈ range (n / G + 1), (powersetCard 4 (blk n G i)).card ≤ G ^ 4 := by intro i _ rw [card_powersetCard] exact le_trans (Nat.choose_le_choose 4 (blk_card n G i hG)) (Nat.choose_le_pow G 4) have h2 := sum_le_sum h1 rw [sum_const, card_range, smul_eq_mul] at h2 exact h2 theorem fst_mem_Y4 {n G : ℕ} {w : Finset (ℕ × ℕ)} (hw : w ∈ Wins n G) (hwin : IsWin n w) : w.image Prod.fst ∈ Y4 n G := by classical unfold Wins at hw obtain ⟨ij, hij, hw2⟩ := mem_biUnion.mp hw obtain ⟨hsub, _⟩ := mem_powersetCard.mp hw2 unfold Y4 refine mem_biUnion.mpr ⟨ij.1, (mem_product.mp hij).1, mem_powersetCard.mpr ⟨?_, ?_⟩⟩ · intro y hy obtain ⟨m, hm, rfl⟩ := mem_image.mp hy exact (mem_product.mp (hsub hm)).1 · rw [card_image_of_injOn, hwin.1] intro m hm m' hm' h exact hwin.2.2.1 m hm m' hm' h open Classical in /-- **Windows per anchor.** -/ theorem anchor_count {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (G : ℕ) (T' : ℝ) {F' F : Finset ℕ} (hF'5 : F'.card = 5) (hF5 : F.card = 5) : ((Wins n G).filter (fun w => ConicRich v n T' w ∧ F' ⊆ (wsol v n w).image Prod.snd ∧ F ⊆ (wsol v n w).image Prod.fst)).card ≤ 8 * (Y4 n G).card := by obtain ⟨W, hW⟩ : ∃ W : Finset (Finset (ℕ × ℕ)), W = (Wins n G).filter (fun w => ConicRich v n T' w ∧ F' ⊆ (wsol v n w).image Prod.snd ∧ F ⊆ (wsol v n w).image Prod.fst) := ⟨_, rfl⟩ rw [← hW] rcases W.eq_empty_or_nonempty with h0 | ⟨w0, hw0⟩ · rw [h0] simp have hmem : ∀ w ∈ W, w ∈ Wins n G ∧ ConicRich v n T' w ∧ F' ⊆ (wsol v n w).image Prod.snd ∧ F ⊆ (wsol v n w).image Prod.fst := by intro w hw rw [hW] at hw exact mem_filter.mp hw obtain ⟨_, ⟨hwin0, _, l11, l12, l21, l22, q, hpole, _, hdet, hns⟩, hA0, hB0⟩ := hmem w0 hw0 obtain ⟨m0, hm0⟩ : w0.Nonempty := card_pos.mp (by rw [hwin0.1]; norm_num) have hns2 : ¬ (l11 ^ 2 + l12 ^ 2 - 1 = l21 ^ 2 + l22 ^ 2 - 1 ∧ l11 * l21 + l12 * l22 = 0) := by intro h exact hns ⟨by linarith [h.1], h.2⟩ have hF'n : ∀ i ∈ F', i < n := by intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (hA0 hi) exact (mem_wsol.mp hpp).1.2 have hFimg : (F'.image v).card = 5 := by rw [card_image_of_injOn, hF'5] intro i hi j hj h exact hinj i (hF'n i hi) j (hF'n j hj) h have hz : ∀ p ∈ F'.image v, qf (l11 ^ 2 + l12 ^ 2 - 1) (l11 * l21 + l12 * l22) (l21 ^ 2 + l22 ^ 2 - 1) (2 * (l11 * (q.re - (v m0.1).re) + l12 * (q.im - (v m0.1).im)) + 2 * (v m0.2).re) (2 * (l21 * (q.re - (v m0.1).re) + l22 * (q.im - (v m0.1).im)) + 2 * (v m0.2).im) (dq q (v m0.1) - ((v m0.2).re ^ 2 + (v m0.2).im ^ 2)) p = 0 := by intro p hp obtain ⟨i, hi, rfl⟩ := mem_image.mp hp obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (hA0 hi) rw [← wD_qf] exact win_zero hpole hm0 hpp have hnc : ∀ p ∈ F'.image v, ∀ p' ∈ F'.image v, ∀ r ∈ F'.image v, p ≠ p' → p ≠ r → p' ≠ r → cr3 p p' r ≠ 0 := by intro p hp p' hp' r hr hpq hpr hqr obtain ⟨i, hi, rfl⟩ := mem_image.mp hp obtain ⟨j, hj, rfl⟩ := mem_image.mp hp' obtain ⟨k, hk, rfl⟩ := mem_image.mp hr exact ccw_cr3_ne hccw (hF'n i hi) (hF'n j hj) (hF'n k hk) (fun h => hpq (by rw [h])) (fun h => hpr (by rw [h])) (fun h => hqr (by rw [h])) obtain ⟨code, hcode⟩ := rigid hns2 hFimg hz hnc have h8 : (univ : Finset (Bool × Bool × Bool)).card = 8 := by decide have key := card_le_of_rel W ((univ : Finset (Bool × Bool × Bool)) ×ˢ (Y4 n G)) (fun w cy => w.image Prod.fst = cy.2 ∧ ∃ l11' l12' l21' l22' : ℝ, ∃ q' : ℂ, (∀ pp ∈ wsol v n w, v pp.1 = linT l11' l12' l21' l22' (v pp.2) + q') ∧ l11' * l22' - l12' * l21' ≠ 0 ∧ ¬ (l21' ^ 2 + l22' ^ 2 = l11' ^ 2 + l12' ^ 2 ∧ l11' * l21' + l12' * l22' = 0) ∧ code (fun z => affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z)) = cy.1) ?_ ?_ · rw [card_product, h8] at key exact key · intro w hw obtain ⟨hwW, ⟨hwin, _, l11', l12', l21', l22', q', hpole', _, hdet', hns'⟩, _, _⟩ := hmem w hw exact ⟨(code (fun z => affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z)), w.image Prod.fst), mem_product.mpr ⟨mem_univ _, fst_mem_Y4 hwW hwin⟩, rfl, l11', l12', l21', l22', q', hpole', hdet', hns', rfl⟩ · intro w hw w' hw' cy _ hR hR' obtain ⟨hf, l11', l12', l21', l22', q', hpole', hdet', hns', hc'⟩ := hR obtain ⟨hf', l11'', l12'', l21'', l22'', q'', hpole'', hdet'', hns'', hc''⟩ := hR' obtain ⟨_, ⟨hwin, _⟩, hA, hB⟩ := hmem w hw obtain ⟨_, ⟨hwin', _⟩, hA', hB'⟩ := hmem w' hw' obtain ⟨m, hm⟩ : w.Nonempty := card_pos.mp (by rw [hwin.1]; norm_num) obtain ⟨m', hm'⟩ : w'.Nonempty := card_pos.mp (by rw [hwin'.1]; norm_num) have r1 := rig_of_windows hccw hpole hdet hns hpole' hdet' hns' hm0 hm hF'5 hF5 hA0 hB0 hA hB have r2 := rig_of_windows hccw hpole hdet hns hpole'' hdet'' hns'' hm0 hm' hF'5 hF5 hA0 hB0 hA' hB' have hU := hcode _ _ r1 r2 (by rw [hc', hc'']) have hT : ∀ z, affT l11' l12' l21' l22' q' z = affT l11'' l12'' l21'' l22'' q'' z := by intro z have h : affTi l11 l12 l21 l22 q (affT l11' l12' l21' l22' q' z) = affTi l11 l12 l21 l22 q (affT l11'' l12'' l21'' l22'' q'' z) := congrFun hU z have h2 := congrArg (affT l11 l12 l21 l22 q) h rw [affT_affTi hdet, affT_affTi hdet] at h2 exact h2 exact win_unique hccw hinj hwin hwin' hpole' hpole'' hT hF'5 hA hA' (by rw [hf, hf']) end E94S /-! ### SOLO slice E6 -/ /-! ## SOLO module E (part 6): the Ivory count -/ namespace E94S open Finset theorem wsol_card_le {v : ℕ → ℂ} {n : ℕ} (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) {w : Finset (ℕ × ℕ)} {l11 l12 l21 l22 : ℝ} {q₀ : ℂ} (hpole : ∀ pp ∈ wsol v n w, v pp.1 = linT l11 l12 l21 l22 (v pp.2) + q₀) (hdet : l11 * l22 - l12 * l21 ≠ 0) : (wsol v n w).card ≤ n := by obtain ⟨inj2, _⟩ := wsol_inj hinj hpole hdet have h := card_le_card_of_injOn (s := wsol v n w) (t := range n) Prod.snd (fun pp hpp => mem_range.mpr (mem_wsol.mp hpp).1.2) (by intro pp hpp ss hss h exact inj2 pp (mem_coe.mp hpp) ss (mem_coe.mp hss) h) rwa [card_range] at h open Classical in /-- **Double counting over anchors.** -/ theorem conic_windows {v : ℕ → ℂ} {n : ℕ} (hccw : Ccw v n) (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (G : ℕ) {T' : ℝ} {t : ℕ} (ht : (t : ℝ) ≤ T') : ((Wins n G).filter (fun w => ConicRich v n T' w)).card * (t.choose 5) ^ 2 ≤ (n.choose 5) ^ 2 * (8 * (Y4 n G).card) := by obtain ⟨A, hA⟩ : ∃ A : Finset (Finset ℕ × Finset ℕ), A = (powersetCard 5 (range n)) ×ˢ (powersetCard 5 (range n)) := ⟨_, rfl⟩ have hAcard : A.card = (n.choose 5) ^ 2 := by rw [hA, card_product, card_powersetCard, card_range, sq] rw [← hAcard] refine card_mul_le_card_mul (r := fun (w : Finset (ℕ × ℕ)) (FF : Finset ℕ × Finset ℕ) => FF.1 ⊆ (wsol v n w).image Prod.snd ∧ FF.2 ⊆ (wsol v n w).image Prod.fst) ?_ ?_ · intro w hw obtain ⟨_, hcr⟩ := mem_filter.mp hw obtain ⟨hwin, hrich, l11, l12, l21, l22, q, hpole, _, hdet, _⟩ := hcr have hsub : (powersetCard 5 ((wsol v n w).image Prod.snd)) ×ˢ (powersetCard 5 ((wsol v n w).image Prod.fst)) ⊆ bipartiteAbove (fun (w : Finset (ℕ × ℕ)) (FF : Finset ℕ × Finset ℕ) => FF.1 ⊆ (wsol v n w).image Prod.snd ∧ FF.2 ⊆ (wsol v n w).image Prod.fst) A w := by intro FF hFF obtain ⟨h1, h2⟩ := mem_product.mp hFF obtain ⟨s1, c1⟩ := mem_powersetCard.mp h1 obtain ⟨s2, c2⟩ := mem_powersetCard.mp h2 unfold bipartiteAbove refine mem_filter.mpr ⟨?_, s1, s2⟩ rw [hA] refine mem_product.mpr ⟨mem_powersetCard.mpr ⟨?_, c1⟩, mem_powersetCard.mpr ⟨?_, c2⟩⟩ · intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (s1 hi) exact mem_range.mpr (mem_wsol.mp hpp).1.2 · intro i hi obtain ⟨pp, hpp, rfl⟩ := mem_image.mp (s2 hi) exact mem_range.mpr (mem_wsol.mp hpp).1.1 refine le_trans ?_ (card_le_card hsub) rw [card_product, card_powersetCard, card_powersetCard] obtain ⟨inj2, inj1⟩ := wsol_inj hinj hpole hdet have e2 : ((wsol v n w).image Prod.snd).card = (wsol v n w).card := card_image_of_injOn (by intro pp hpp ss hss h exact inj2 pp (mem_coe.mp hpp) ss (mem_coe.mp hss) h) have e1 : ((wsol v n w).image Prod.fst).card = (wsol v n w).card := card_image_of_injOn (by intro pp hpp ss hss h exact inj1 pp (mem_coe.mp hpp) ss (mem_coe.mp hss) h) rw [e1, e2, sq] have htw : t ≤ (wsol v n w).card := by have h : (t : ℝ) ≤ ((wsol v n w).card : ℝ) := le_trans ht hrich exact_mod_cast h exact Nat.mul_le_mul (Nat.choose_le_choose 5 htw) (Nat.choose_le_choose 5 htw) · intro FF hFF rw [hA] at hFF obtain ⟨h1, h2⟩ := mem_product.mp hFF have c1 := (mem_powersetCard.mp h1).2 have c2 := (mem_powersetCard.mp h2).2 refine le_trans (card_le_card ?_) (anchor_count hccw hinj G T' c1 c2) intro w hw unfold bipartiteBelow at hw obtain ⟨hw1, hw2⟩ := mem_filter.mp hw obtain ⟨hw3, hw4⟩ := mem_filter.mp hw1 exact mem_filter.mpr ⟨hw3, hw4, hw2.1, hw2.2⟩ open Classical in theorem conicSum_le {v : ℕ → ℂ} {n : ℕ} (hinj : ∀ i < n, ∀ j < n, v i = v j → i = j) (G : ℕ) (T' : ℝ) : conicSum v n G T' ≤ (n : ℝ) * (((Wins n G).filter (fun w => ConicRich v n T' w)).card : ℝ) := by unfold conicSum rw [← sum_filter] have hb : ∀ w ∈ (Wins n G).filter (fun w => ConicRich v n T' w), ((wsol v n w).card : ℝ) ≤ (n : ℝ) := by intro w hw obtain ⟨_, _, _, l11, l12, l21, l22, q, hpole, _, hdet, _⟩ := mem_filter.mp hw exact_mod_cast wsol_card_le hinj hpole hdet have h := sum_le_sum hb rw [sum_const, nsmul_eq_mul] at h linarith theorem choose5_bounds {τ : ℝ} (hτ : 0 < τ) {n t : ℕ} (ht1 : τ * n < (t : ℝ) + 1) (h10 : 10 ≤ τ * n) : ((n.choose 5 : ℕ) : ℝ) * (τ / 4) ^ 5 ≤ ((t.choose 5 : ℕ) : ℝ) := by have ht9 : (9 : ℝ) < t := by linarith have ht9' : 9 < t := by exact_mod_cast ht9 have u1 : ((n.choose 5 : ℕ) : ℝ) ≤ (n : ℝ) ^ 5 / ((Nat.factorial 5 : ℕ) : ℝ) := Nat.choose_le_pow_div 5 n have u2 : (((t + 1 - 5 : ℕ) : ℝ)) ^ 5 / ((Nat.factorial 5 : ℕ) : ℝ) ≤ ((t.choose 5 : ℕ) : ℝ) := Nat.pow_le_choose 5 t have u3 : ((t + 1 - 5 : ℕ) : ℝ) = (t : ℝ) - 4 := by have h : t + 1 - 5 = t - 4 := by omega rw [h, Nat.cast_sub (by omega)] norm_num have f5 : ((Nat.factorial 5 : ℕ) : ℝ) = 120 := by norm_num [Nat.factorial] rw [u3, f5] at u2 rw [f5] at u1 have hn0 : (0 : ℝ) ≤ n := Nat.cast_nonneg n have u4 : τ * n / 4 ≤ (t : ℝ) - 4 := by linarith have u5 : (τ * n / 4) ^ 5 ≤ ((t : ℝ) - 4) ^ 5 := pow_le_pow_left₀ (by positivity) u4 5 have e : (n : ℝ) ^ 5 / 120 * (τ / 4) ^ 5 = (τ * n / 4) ^ 5 / 120 := by ring calc ((n.choose 5 : ℕ) : ℝ) * (τ / 4) ^ 5 ≤ (n : ℝ) ^ 5 / 120 * (τ / 4) ^ 5 := mul_le_mul_of_nonneg_right u1 (by positivity) _ = (τ * n / 4) ^ 5 / 120 := e _ ≤ ((t : ℝ) - 4) ^ 5 / 120 := div_le_div_of_nonneg_right u5 (by norm_num) _ ≤ _ := u2 theorem conic_arith {R cn ct y τ n G4 : ℝ} (hτ : 0 < τ) (hn : 0 < n) (hR : 0 ≤ R) (hcn : 0 < cn) (h1 : R * ct ^ 2 ≤ cn ^ 2 * (8 * y)) (h2 : cn * (τ / 4) ^ 5 ≤ ct) (h3 : y ≤ 2 * n * G4) : n * R ≤ 16 * G4 * (4 / τ) ^ 10 * n ^ 2 := by have a1 : (cn * (τ / 4) ^ 5) ^ 2 ≤ ct ^ 2 := pow_le_pow_left₀ (by positivity) h2 2 have a2 : R * (cn * (τ / 4) ^ 5) ^ 2 ≤ cn ^ 2 * (8 * y) := le_trans (mul_le_mul_of_nonneg_left a1 hR) h1 have a3 : R * (τ / 4) ^ 10 ≤ 8 * y := by have e : R * (cn * (τ / 4) ^ 5) ^ 2 = cn ^ 2 * (R * (τ / 4) ^ 10) := by ring rw [e] at a2 exact le_of_mul_le_mul_left a2 (by positivity) have a4 : (τ / 4) ^ 10 * (4 / τ) ^ 10 = 1 := by rw [← mul_pow] have h : τ / 4 * (4 / τ) = 1 := by field_simp rw [h, one_pow] have a5 : R ≤ 8 * y * (4 / τ) ^ 10 := by have h := mul_le_mul_of_nonneg_right a3 (by positivity : (0 : ℝ) ≤ (4 / τ) ^ 10) have e : R * (τ / 4) ^ 10 * (4 / τ) ^ 10 = R := by rw [mul_assoc, a4, mul_one] rw [e] at h exact h have a6 : 8 * y * (4 / τ) ^ 10 ≤ 8 * (2 * n * G4) * (4 / τ) ^ 10 := mul_le_mul_of_nonneg_right (by linarith) (by positivity) calc n * R ≤ n * (8 * (2 * n * G4) * (4 / τ) ^ 10) := mul_le_mul_of_nonneg_left (le_trans a5 a6) hn.le _ = 16 * G4 * (4 / τ) ^ 10 * n ^ 2 := by ring /-- **The Ivory count.** Rich non-similarity windows carry `O(n²)` pole pairs in total. -/ theorem conicBound : ConicBound := by classical intro τ' hτ' G hG refine ⟨16 * (G : ℝ) ^ 4 * (4 / τ') ^ 10, ⌈10 / τ'⌉₊ + 5, ?_⟩ intro n hn v hccw hinj have hn5 : 5 ≤ n := by omega have hnR : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) have h10 : 10 ≤ τ' * n := by have h1 : 10 / τ' ≤ (n : ℝ) := le_trans (Nat.le_ceil _) (by exact_mod_cast (by omega : ⌈10 / τ'⌉₊ ≤ n)) have := (div_le_iff₀ hτ').mp h1 linarith obtain ⟨t, ht⟩ : ∃ t : ℕ, t = ⌊τ' * n⌋₊ := ⟨_, rfl⟩ have ht1 : (t : ℝ) ≤ τ' * n := by rw [ht] exact Nat.floor_le (by positivity) have ht2 : τ' * n < (t : ℝ) + 1 := by rw [ht] exact Nat.lt_floor_add_one _ have hw := conic_windows hccw hinj G ht1 have hw' : (((Wins n G).filter (fun w => ConicRich v n (τ' * n) w)).card : ℝ) * ((t.choose 5 : ℕ) : ℝ) ^ 2 ≤ ((n.choose 5 : ℕ) : ℝ) ^ 2 * (8 * ((Y4 n G).card : ℝ)) := by exact_mod_cast hw have hc := choose5_bounds hτ' ht2 h10 have hcn : (0 : ℝ) < ((n.choose 5 : ℕ) : ℝ) := by exact_mod_cast Nat.choose_pos hn5 have hy : ((Y4 n G).card : ℝ) ≤ 2 * (n : ℝ) * (G : ℝ) ^ 4 := by have h1 := Y4_card n G hG have h2 : n / G + 1 ≤ 2 * n := by have := Nat.div_le_self n G omega have h3 : (Y4 n G).card ≤ 2 * n * G ^ 4 := le_trans h1 (Nat.mul_le_mul_right _ h2) exact_mod_cast h3 have hs := conicSum_le hinj G (τ' * n) (v := v) (n := n) have hfin := conic_arith hτ' hnR (Nat.cast_nonneg _) hcn hw' hc hy linarith end E94S /-! ### SOLO slice F1 -/ /-! ## SOLO module F: from a convex-independent point set in the plane to the target -/ namespace E94S open Finset Erdos94ThmA /-- A counterclockwise polygon indexed by `ZMod n`, relabelled by `ℕ`. -/ theorem ccw_of_CCWPoly {n : ℕ} [NeZero n] {w : ZMod n → ℂ} (h : CCWPoly w) : Ccw (fun i : ℕ => w (i : ZMod n)) n := by intro i j k hij hjk hk have hj : j < n := lt_trans hjk hk have hi : i < n := lt_trans hij hj have h1 := h (i : ZMod n) (j : ZMod n) (k : ZMod n) (by rw [ZMod.val_cast_of_lt hi, ZMod.val_cast_of_lt hj]; exact hij) (by rw [ZMod.val_cast_of_lt hj, ZMod.val_cast_of_lt hk]; exact hjk) rw [cr_eq] at h1 simp only [Complex.sub_re, Complex.sub_im] at h1 unfold ori exact h1 theorem inj_of_zmod {n : ℕ} [NeZero n] {w : ZMod n → ℂ} (h : Function.Injective w) : ∀ i < n, ∀ j < n, (fun i : ℕ => w (i : ZMod n)) i = (fun i : ℕ => w (i : ZMod n)) j → i = j := by intro i hi j hj hij have h1 : (i : ZMod n) = (j : ZMod n) := h hij have h2 := congrArg ZMod.val h1 rwa [ZMod.val_cast_of_lt hi, ZMod.val_cast_of_lt hj] at h2 open Classical in theorem pts_zmod {n : ℕ} [NeZero n] (w : ZMod n → ℂ) : pts (fun i : ℕ => w (i : ZMod n)) n = univ.image w := by ext z unfold pts constructor · intro hz obtain ⟨i, _, rfl⟩ := mem_image.mp hz exact mem_image.mpr ⟨(i : ZMod n), mem_univ _, rfl⟩ · intro hz obtain ⟨x, _, rfl⟩ := mem_image.mp hz exact mem_image.mpr ⟨x.val, mem_range.mpr (ZMod.val_lt x), by rw [ZMod.natCast_zmod_val]⟩ /-- The pair energy is at most the number of equal-distance quadruples. -/ theorem pairEnergy_le_QP (Q : Finset ℂ) : Erdos94Infra.pairEnergy Q ≤ (QP Q).card := by classical have h1 : Erdos94Infra.pairEnergy Q = ∑ xy ∈ Q.offDiag ×ˢ Q.offDiag, if dist xy.1.1 xy.1.2 = dist xy.2.1 xy.2.2 then 1 else 0 := by unfold Erdos94Infra.pairEnergy exact (sum_product' Q.offDiag Q.offDiag (fun x y => if dist x.1 x.2 = dist y.1 y.2 then 1 else 0)).symm have h2 : (∑ xy ∈ Q.offDiag ×ˢ Q.offDiag, if dist xy.1.1 xy.1.2 = dist xy.2.1 xy.2.2 then 1 else 0) = ((Q.offDiag ×ˢ Q.offDiag).filter (fun xy => dist xy.1.1 xy.1.2 = dist xy.2.1 xy.2.2)).card := by rw [card_filter] rw [h1, h2] refine card_le_card_of_injOn (fun xy => (xy.1.1, xy.1.2, xy.2.1, xy.2.2)) ?_ ?_ · intro xy hxy obtain ⟨h3, h4⟩ := mem_filter.mp (mem_coe.mp hxy) obtain ⟨h5, h6⟩ := mem_product.mp h3 obtain ⟨a1, a2, a3⟩ := mem_offDiag.mp h5 obtain ⟨b1, b2, b3⟩ := mem_offDiag.mp h6 exact mem_coe.mpr (mem_QP.mpr ⟨⟨a1, a2, b1, b2⟩, a3, b3, dq_eq_of_dist_eq h4⟩) · intro xy _ xy' _ h simp only [Prod.mk.injEq] at h obtain ⟨e1, e2, e3, e4⟩ := h exact Prod.ext (Prod.ext e1 e2) (Prod.ext e3 e4) theorem ngon_ge (n : ℕ) : (n : ℝ) ^ 3 / 2 - 3 * (n : ℝ) ^ 2 / 4 ≤ Erdos94Infra.ngonValue n := by unfold Erdos94Infra.ngonValue have hc : ((n.choose 2 : ℕ) : ℝ) = (n : ℝ) * ((n : ℝ) - 1) / 2 := Nat.cast_choose_two ℝ n split_ifs · rw [hc] nlinarith [sq_nonneg (n : ℝ)] · rw [hc] nlinarith [sq_nonneg (n : ℝ)] /-- Case 1: few equal-distance quadruples. -/ theorem case_energy {n : ℕ} {P : Finset (EuclideanSpace ℝ (Fin 2))} (h : ((QP (P.image Complex.orthonormalBasisOneI.repr.symm)).card : ℝ) ≤ 2 * (n : ℝ) ^ 3 - 3 * (n : ℝ) ^ 2) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := by rw [Erdos94Infra.sum_sq_mult_eq, ← pairEnergy_image_C] have h1 : ((Erdos94Infra.pairEnergy (P.image Complex.orthonormalBasisOneI.repr.symm) : ℕ) : ℝ) ≤ ((QP (P.image Complex.orthonormalBasisOneI.repr.symm)).card : ℝ) := by exact_mod_cast pairEnergy_le_QP _ have h2 := ngon_ge n linarith open Classical in /-- Case 2: almost all points on one circle. -/ theorem case_circle {n : ℕ} {P : Finset (EuclideanSpace ℝ (Fin 2))} (hcard : P.card = n) (hP : EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2)))) (hn : 161000 ≤ n) {C : ℂ × ℝ} (hC0 : 0 < C.2) (hC : (1 - 2 / 100000) * (n : ℝ) ≤ ((cpts (P.image Complex.orthonormalBasisOneI.repr.symm) C).card : ℝ)) : ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := by have hρ : 0 < Real.sqrt C.2 := Real.sqrt_pos.mpr hC0 have hsub : (cpts (P.image Complex.orthonormalBasisOneI.repr.symm) C).card ≤ (P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr C.1) = Real.sqrt C.2)).card := by refine card_le_card_of_injOn (fun z => Complex.orthonormalBasisOneI.repr z) ?_ ?_ · intro z hz obtain ⟨hzQ, hzd⟩ := mem_cpts.mp (mem_coe.mp hz) obtain ⟨p, hp, rfl⟩ := mem_image.mp hzQ refine mem_coe.mpr (mem_filter.mpr ⟨?_, ?_⟩) · show Complex.orthonormalBasisOneI.repr (Complex.orthonormalBasisOneI.repr.symm p) ∈ P rw [LinearIsometryEquiv.apply_symm_apply] exact hp · show dist (Complex.orthonormalBasisOneI.repr (Complex.orthonormalBasisOneI.repr.symm p)) (Complex.orthonormalBasisOneI.repr C.1) = Real.sqrt C.2 rw [LinearIsometryEquiv.dist_map, dist_eq_sqrt_dq, hzd] · intro z _ z' _ h exact Complex.orthonormalBasisOneI.repr.injective h have hsplit := card_filter_add_card_filter_not (s := P) (fun p => dist p (Complex.orthonormalBasisOneI.repr C.1) = Real.sqrt C.2) have h1 : ((P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr C.1) = Real.sqrt C.2)).card : ℝ) + ((P.filter (fun p => ¬ dist p (Complex.orthonormalBasisOneI.repr C.1) = Real.sqrt C.2)).card : ℝ) = (n : ℝ) := by rw [← hcard] exact_mod_cast hsplit have h2 : ((cpts (P.image Complex.orthonormalBasisOneI.repr.symm) C).card : ℝ) ≤ ((P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr C.1) = Real.sqrt C.2)).card : ℝ) := by exact_mod_cast hsub have h3 := propC hP (by rw [hcard]; exact hn) (O := Complex.orthonormalBasisOneI.repr C.1) hρ (by rw [hcard] have : ((P.filter (fun p => dist p (Complex.orthonormalBasisOneI.repr C.1) ≠ Real.sqrt C.2)).card : ℝ) = ((P.filter (fun p => ¬ dist p (Complex.orthonormalBasisOneI.repr C.1) = Real.sqrt C.2)).card : ℝ) := rfl rw [this] linarith) rw [hcard] at h3 exact h3 open Classical in /-- **Main theorem** (closed form): for all large `n`, every convex-independent `n`-point set in the plane has `∑ f(u)² ≤ ngonValue n`. -/ theorem solo_main : ∃ N : ℕ, ∀ n ≥ N, ∀ P : Finset (EuclideanSpace ℝ (Fin 2)), P.card = n → EuclideanGeometry.ConvexIndep (P : Set (EuclideanSpace ℝ (Fin 2))) → ∑ u ∈ distanceSet P, (distanceMultiplicity P u : ℝ) ^ 2 ≤ Erdos94Infra.ngonValue n := by obtain ⟨n₀, hn₀⟩ := solo_dichotomy conicBound (δ := 2 / 100000) (by norm_num) (by norm_num) refine ⟨n₀ + 161000, ?_⟩ intro n hn P hcard hP haveI : NeZero n := ⟨by omega⟩ obtain ⟨w, hwinj, hwccw, hwimg, _⟩ := plane_ccw_labelling2 (by omega) P hcard hP have hccw := ccw_of_CCWPoly hwccw have hinj := inj_of_zmod hwinj have hpts : pts (fun i : ℕ => w (i : ZMod n)) n = P.image Complex.orthonormalBasisOneI.repr.symm := by rw [pts_zmod, ← hwimg] have hT : ∀ t : ℂ, t ≠ 0 → ((pts (fun i : ℕ => w (i : ZMod n)) n).filter (fun x => x + t ∈ pts (fun i : ℕ => w (i : ZMod n)) n)).card ≤ 2 := by intro t ht rw [hpts] convert translate_card_le_two_C hP ht rcases hn₀ n (by omega) _ hccw hinj hT with h1 | ⟨C, hC0, hC⟩ · rw [hpts] at h1 exact case_energy h1 · rw [hpts] at hC exact case_circle hcard hP (by omega) hC0 hC end E94S /-- The task statement. -/ theorem target : fcTypeOfName% "Erdos94.erdos_94.variants.regular_ngon" := by rw [Erdos94Infra.target_iff_closed_form, Filter.eventually_atTop] exact E94S.solo_main