import Mathlib.Tacticnamespace 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 := byobtain ⟨x, hx, hmax⟩ := S.exists_max_image (fun x : ℝ => |x|) hnehave hpos := abs_pos.mpr (hnz x hx)have hle := hmax (r*x) (h x hx)change |r*x| ≤ |x| at hlerw [abs_mul] at hlenlinarith/-- 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| := byhave le (u v : ℝ) (hv : v ≠ 0)(huS : ∀ x ∈ S, u/x ∈ S) (hvS : ∀ x ∈ S, v/x ∈ S) : |u| ≤ |v| := byhave hscale := abs_scale_le_one S hne hnz (u/v) (byintro x hxhave 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 hscaleexact hscaleexact 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 := byhave habs := abs_coeff_eq S hne hnz a b ha hb hA hBhave hacs := abs_coeff_eq S hne hnz a c ha hc hA hCrcases 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 := bylet x := S.max' hnehave hx : x ∈ S := S.max'_mem hnehave 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/2U < 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 := bydsimphave h₁ : 0 ≤ n-32 := by linarithhave h₂ := sq_nonneg (n-32)have h₃ := mul_nonneg h₂ h₁constructor· nlinarithconstructor <;> 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+1V < 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 := bydsimphave h₁ : 0 ≤ n-35 := by linarithhave h₂ := sq_nonneg (n-35)have h₃ := mul_nonneg h₂ h₁constructor· nlinarithconstructor <;> 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 := byby_contra hhave he : k%2 = 1 := by omegaexact 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 bulkend Erdos506Spectrum