import Mathlib.Tactic namespace Erdos506Spectrum /-- A real dilation mapping a nonempty finite set of nonzero reals to itself is nonexpanding. -/ theorem abs_scale_le_one (S : Finset ℝ) (hne : S.Nonempty) (hnz : ∀ x ∈ S, x ≠ 0) (r : ℝ) (h : ∀ x ∈ S, r*x ∈ S) : |r| ≤ 1 := by obtain ⟨x, hx, hmax⟩ := S.exists_max_image (fun x : ℝ => |x|) hne have hpos := abs_pos.mpr (hnz x hx) have hle := hmax (r*x) (h x hx) change |r*x| ≤ |x| at hle rw [abs_mul] at hle nlinarith /-- Two inversions x ↦ a/x preserving the same such set have equal coefficient magnitudes. -/ theorem abs_coeff_eq (S : Finset ℝ) (hne : S.Nonempty) (hnz : ∀ x ∈ S, x ≠ 0) (a b : ℝ) (ha : a ≠ 0) (hb : b ≠ 0) (hA : ∀ x ∈ S, a/x ∈ S) (hB : ∀ x ∈ S, b/x ∈ S) : |a| = |b| := by have le (u v : ℝ) (hv : v ≠ 0) (huS : ∀ x ∈ S, u/x ∈ S) (hvS : ∀ x ∈ S, v/x ∈ S) : |u| ≤ |v| := by have hscale := abs_scale_le_one S hne hnz (u/v) (by intro x hx have heq : u / (v / x) = (u/v)*x := by simp [div_eq_mul_inv, mul_comm, mul_left_comm] rw [← heq] exact huS _ (hvS _ hx)) rw [abs_div, div_le_one (abs_pos.mpr hv)] at hscale exact hscale exact le_antisymm (le a b hb hA hB) (le b a ha hB hA) /-- Three distinct real coefficients cannot give three involutions of the indicated form. -/ theorem three_inv_impossible (S : Finset ℝ) (hne : S.Nonempty) (hnz : ∀ x ∈ S, x ≠ 0) (a b c : ℝ) (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0) (hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (hA : ∀ x ∈ S, a/x ∈ S) (hB : ∀ x ∈ S, b/x ∈ S) (hC : ∀ x ∈ S, c/x ∈ S) : False := by have habs := abs_coeff_eq S hne hnz a b ha hb hA hB have hacs := abs_coeff_eq S hne hnz a c ha hc hA hC rcases le_total 0 a with ha' | ha' <;> rcases le_total 0 b with hb' | hb' <;> rcases le_total 0 c with hc' | hc' <;> simp_all [abs_of_nonneg, abs_of_nonpos] /-- Distinct affine reflections fixing infinity cannot both preserve a nonempty finite real set. -/ theorem reflection_coeff_eq (S : Finset ℝ) (hne : S.Nonempty) (a b : ℝ) (hA : ∀ x ∈ S, -x+a ∈ S) (hB : ∀ x ∈ S, -x+b ∈ S) : a=b := by let x := S.max' hne have hx : x ∈ S := S.max'_mem hne have h₁ := S.le_max' _ (hA _ (hB _ hx)) have h₂ := S.le_max' _ (hB _ (hA _ hx)) change -(-x+b)+a ≤ x at h₁ change -(-x+a)+b ≤ x at h₂ linarith /-- The three bounds in the incidence reduction exceed the maximum over the two parities. -/ theorem bulk (n : ℝ) (hn : 32 ≤ n) : let U := n^2-13*n/2+25/2 U < n*(n^2-3*n+20)/36 ∧ U < 1+(n-1)*(n+1)*(n-3)/32 ∧ U < 1+3*(n-3)*(2*n-12)/4 := by dsimp have h₁ : 0 ≤ n-32 := by linarith have h₂ := sq_nonneg (n-32) have h₃ := mul_nonneg h₂ h₁ constructor · nlinarith constructor <;> nlinarith /-- The same incidence bounds exceed the entire second band under general position. -/ theorem general_position_bulk (n : ℝ) (hn : 35 ≤ n) : let V := (n-2)^2+1 V < n*(n^2-3*n+20)/36 ∧ V < 1+(n-1)*(n+1)*(n-3)/32 ∧ V < 1+3*(n-3)*(2*n-12)/4 := by dsimp have h₁ : 0 ≤ n-35 := by linarith have h₂ := sq_nonneg (n-35) have h₃ := mul_nonneg h₂ h₁ constructor · nlinarith constructor <;> nlinarith #print axioms general_position_bulk /-- The counting identity gives the parity improvement once the simultaneous odd equality is ruled out. -/ theorem pair_count_bound (k d t s p q : ℕ) (base count : ℤ) (hp : p ≤ k/2) (hq : q ≤ k/2) (hpartition : 2*t+s+d=k) (hcount : count = base - p - q - t + s) (hodd : k%2=1 → d=1 → p=k/2 → q=k/2 → t=k/2 → False) : base - 3*(↑(k/2) : ℤ) + ↑(k%2) ≤ count := by by_contra h have he : k%2 = 1 := by omega exact hodd he (by omega) (by omega) (by omega) (by omega) #print axioms pair_count_bound #print axioms three_inv_impossible #print axioms reflection_coeff_eq #print axioms bulk end Erdos506Spectrum