import Mathlib.Data.Fintype.BigOperatorsimport Mathlib.Algebra.BigOperators.Finimport Mathlib.Algebra.BigOperators.Ring.Finsetimport Mathlib.Tactic.NormNumimport Mathlib.Tactic.Ringimport Mathlib.Data.Rat.Cast.Ordernamespace FiveGrid/-- The one-coordinate third difference on the four signed numerators. -/def four (f : ℤ → ℚ) : ℚ := -f (-3) + 3 * f (-1) - 3 * f 1 + f 3/-- Accumulate the first two elementary symmetric functions of the scaledcoordinate factors. Each point coordinate is its integer numerator over four. -/def quadratic : ℕ → ℤ → ℤ → ℚ| 0, _, e => 256 / (e : ℚ)| n+1, s, e => four fun x => four fun y =>let t := 16 - x*yquadratic n (s+t) (e+s*t)def six (f : ℤ → ℚ) : ℚ :=18*(f 1 - f (-1)) - 12*(f 3 - f (-3)) + 2*(f 9 - f (-9))theorem compress (f : ℤ → ℚ) :(four fun x => four fun y => f (x*y)) = six f := bynorm_num [four, six]ringdef value : ℕ → ℤ → ℤ → ℚ| 0, _, e => 256 / (e : ℚ)| n+1, s, e => six fun p =>let t := 16-pvalue n (s+t) (e+s*t)theorem quadratic_eq (n : ℕ) (s e : ℤ) : quadratic n s e = value n s e := byinduction n generalizing s e with| zero => rfl| succ n ih =>simp only [quadratic, value, ih]exact compress (fun p => value n (s+(16-p)) (e+s*(16-p)))set_option maxRecDepth 100000 inset_option maxHeartbeats 8000000 intheorem negative : quadratic 5 0 0 < -(1/51000 : ℚ) := byrw [quadratic_eq]decide +kernel@[reducible] def Grid : ℕ → Type| 0 => Unit| n+1 => Fin 4 × Grid n@[instance_reducible] instance gridFinite (n : ℕ) : Fintype (Grid n) := byinduction n with| zero => exact inferInstanceAs (Fintype Unit)| succ n ih => exact @instFintypeProd (Fin 4) (Grid n) inferInstance ihdef digit (i : Fin 4) : ℤ := 2 * (i.val : ℤ) - 3def weight (i : Fin 4) : ℚ := ![-1,3,-3,1] idef tensor : (n : ℕ) → Grid n → ℚ| 0, _ => 1| n+1, (i,x) => weight i * tensor n xdef entry : (n : ℕ) → ℤ → ℤ → Grid n → Grid n → ℚ| 0, _, e, _, _ => 256 / (e : ℚ)| n+1, s, e, (i,x), (j,y) =>let t := 16 - digit i * digit jentry n (s+t) (e+s*t) x ylemma four_sum (f : ℤ → ℚ) : (∑ i, weight i * f (digit i)) = four f := byrw [Fin.sum_univ_four]change (-1)*f (-3) + 3*f (-1) + (-3)*f 1 + 1*f 3 = _unfold fourringlemma split (n : ℕ) (f : Grid (n+1) → ℚ) :∑ x, f x = ∑ i : Fin 4, ∑ x : Grid n, f (i,x) := bychange (∑ x : Fin 4 × Grid n, f x) = _rw [Fintype.sum_prod_type]theorem grid_form (n : ℕ) (s e : ℤ) :(∑ x : Grid n, ∑ y : Grid n, tensor n x * tensor n y * entry n s e x y) =quadratic n s e := byinduction n generalizing s e with| zero => simp [Grid, tensor, entry, quadratic]| succ n ih =>rw [split]apply Eq.trans _ (show (∑ i, weight i * (∑ j, weight j *quadratic n (s+(16-digit i*digit j)) (e+s*(16-digit i*digit j)))) = _ from bylet g (a b : ℤ) := quadratic n (s+(16-a*b)) (e+s*(16-a*b))change (∑ i, weight i * (∑ j, weight j * g (digit i) (digit j))) = _simp only [four_sum (g _)]exact four_sum (fun a => four (g a)))apply Finset.sum_congr rflintro i _simp_rw [split n]rw [Finset.sum_comm, Finset.mul_sum]apply Finset.sum_congr rflintro j _rw [← ih]simp only [Finset.mul_sum, tensor, entry]apply Finset.sum_congr rflintro x _apply Finset.sum_congr rflintro y _ringtheorem grid_negative :(∑ x : Grid 5, ∑ y : Grid 5, tensor 5 x * tensor 5 y * entry 5 0 0 x y)< -(1/51000 : ℚ) := byrw [grid_form]exact negativeend FiveGrid