import Std/-!# Polynomial certificates for the width-five and width-six gap modelsUse the centre-spacing theorem as input. There are m = w - 2 interiorcolumns. After a centre in column i, starting the next centre in column jrequires at least g(i,j) = 4 - max(0,j-i) more rows.The continuation series v_i satisfy(1-x) v_i - sum_j x^g(i,j) v_j = 1.Writing v_i = A_i / Q and H = P / Q for the positive-height board seriesgives the two polynomial identities below. In particular the aggregateequation is (1-x)P = x Q + x^3 sum_i A_i.All coefficients are checked in the Lean kernel using only 'decide'.The geometric classification of admissible boards is a separate argument.-/namespace WidthCounts/-- Dense integer coefficients, in ascending order of degree. -/abbrev Poly := List Intdef add : Poly → Poly → Poly| [], q => q| p, [] => p| a :: p, b :: q => (a+b) :: add p qdef sub (p q : Poly) : Poly := add p (q.map (- ·))/-- Coefficients of x^k p, up to trailing zero coefficients. -/def shift (k : Nat) (p : Poly) : Poly := List.replicate k 0 ++ pdef trim (p : Poly) : Poly := (p.reverse.dropWhile (· == 0)).reversedef sum (terms : List Poly) : Poly := terms.foldr add []def gap (i j : Nat) : Nat := 4 - (j - i)def residual (v : List Poly) (i : Nat) : Poly :=let weighted := (List.range v.length).map fun j => shift (gap i j) v[j]!trim (sub (sub v[i]! (shift 1 v[i]!)) (sum weighted))def aggregateLeft (p : Poly) : Poly := trim (sub p (shift 1 p))def aggregateRight (q : Poly) (v : List Poly) : Poly :=trim (add (shift 1 q) (shift 3 (sum v)))def states5 : List Poly :=[[1,0,1,2,0,0,1], [1,0,0,1], [1]]def states6 : List Poly :=[[1,1,2,3,0,2,3,0,0,1], [1,0,1,2,0,0,1], [1,0,0,1], [1]]def Q5 : Poly := [1,-1,0,0,-3,0,-1,-3,0,0,-1]def P5 : Poly := [0,1,0,3,3,1,4,3,0,1,1]def Q6 : Poly := [1,-1,0,0,-4,-1,-3,-6,0,-2,-4,0,0,-1]def P6 : Poly := [0,1,0,4,5,4,9,6,2,6,4,0,1,1]set_option maxRecDepth 8192set_option maxHeartbeats 4000000theorem widthFiveStateEquations :∀ i : Fin 3, residual states5 i.val = Q5 := by decidetheorem widthSixStateEquations :∀ i : Fin 4, residual states6 i.val = Q6 := by decidetheorem widthFiveOutput : aggregateLeft P5 = aggregateRight Q5 states5 := by decidetheorem widthSixOutput : aggregateLeft P6 = aggregateRight Q6 states6 := by decide/-- Constant terms needed for inversion in the ring of formal power series. -/theorem denominatorConstants : Q5.head? = some 1 ∧ Q6.head? = some 1 := by decide#print axioms widthFiveStateEquations#print axioms widthSixStateEquations#print axioms widthFiveOutput#print axioms widthSixOutput#print axioms denominatorConstants/-- The numerator is that of the positive-height generating function.The following coefficient identity gives coprimality over the rationals. -/def coprimeWitness (p q : Poly) : Poly :=trim (add (shift 1 p) (add q (shift 1 q)))theorem widthFiveBezout : coprimeWitness P5 Q5 = [1] := by decidetheorem widthSixBezout : coprimeWitness P6 Q6 = [1] := by decide#print axioms widthFiveBezout#print axioms widthSixBezoutend WidthCounts