Lean / Reader
Lean reader

WidthCounts.lean

93 lines24 declarationsno sorryimports Std
  1. import Std
  2. /-!
  3. # Polynomial certificates for the width-five and width-six gap models
  4. Use the centre-spacing theorem as input. There are m = w - 2 interior
  5. columns. After a centre in column i, starting the next centre in column j
  6. requires at least g(i,j) = 4 - max(0,j-i) more rows.
  7. The continuation series v_i satisfy
  8. (1-x) v_i - sum_j x^g(i,j) v_j = 1.
  9. Writing v_i = A_i / Q and H = P / Q for the positive-height board series
  10. gives the two polynomial identities below. In particular the aggregate
  11. equation is (1-x)P = x Q + x^3 sum_i A_i.
  12. All coefficients are checked in the Lean kernel using only 'decide'.
  13. The geometric classification of admissible boards is a separate argument.
  14. -/
  15. namespace WidthCounts
  16. /-- Dense integer coefficients, in ascending order of degree. -/
  17. abbrev Poly := List Int
  18. def add : Poly → Poly → Poly
  19. | [], q => q
  20. | p, [] => p
  21. | a :: p, b :: q => (a+b) :: add p q
  22. def sub (p q : Poly) : Poly := add p (q.map (- ·))
  23. /-- Coefficients of x^k p, up to trailing zero coefficients. -/
  24. def shift (k : Nat) (p : Poly) : Poly := List.replicate k 0 ++ p
  25. def trim (p : Poly) : Poly := (p.reverse.dropWhile (· == 0)).reverse
  26. def sum (terms : List Poly) : Poly := terms.foldr add []
  27. def gap (i j : Nat) : Nat := 4 - (j - i)
  28. def residual (v : List Poly) (i : Nat) : Poly :=
  29. let weighted := (List.range v.length).map fun j => shift (gap i j) v[j]!
  30. trim (sub (sub v[i]! (shift 1 v[i]!)) (sum weighted))
  31. def aggregateLeft (p : Poly) : Poly := trim (sub p (shift 1 p))
  32. def aggregateRight (q : Poly) (v : List Poly) : Poly :=
  33. trim (add (shift 1 q) (shift 3 (sum v)))
  34. def states5 : List Poly :=
  35. [[1,0,1,2,0,0,1], [1,0,0,1], [1]]
  36. def states6 : List Poly :=
  37. [[1,1,2,3,0,2,3,0,0,1], [1,0,1,2,0,0,1], [1,0,0,1], [1]]
  38. def Q5 : Poly := [1,-1,0,0,-3,0,-1,-3,0,0,-1]
  39. def P5 : Poly := [0,1,0,3,3,1,4,3,0,1,1]
  40. def Q6 : Poly := [1,-1,0,0,-4,-1,-3,-6,0,-2,-4,0,0,-1]
  41. def P6 : Poly := [0,1,0,4,5,4,9,6,2,6,4,0,1,1]
  42. set_option maxRecDepth 8192
  43. set_option maxHeartbeats 4000000
  44. theorem widthFiveStateEquations :
  45. ∀ i : Fin 3, residual states5 i.val = Q5 := by decide
  46. theorem widthSixStateEquations :
  47. ∀ i : Fin 4, residual states6 i.val = Q6 := by decide
  48. theorem widthFiveOutput : aggregateLeft P5 = aggregateRight Q5 states5 := by decide
  49. theorem widthSixOutput : aggregateLeft P6 = aggregateRight Q6 states6 := by decide
  50. /-- Constant terms needed for inversion in the ring of formal power series. -/
  51. theorem denominatorConstants : Q5.head? = some 1 ∧ Q6.head? = some 1 := by decide
  52. #print axioms widthFiveStateEquations
  53. #print axioms widthSixStateEquations
  54. #print axioms widthFiveOutput
  55. #print axioms widthSixOutput
  56. #print axioms denominatorConstants
  57. /-- The numerator is that of the positive-height generating function.
  58. The following coefficient identity gives coprimality over the rationals. -/
  59. def coprimeWitness (p q : Poly) : Poly :=
  60. trim (add (shift 1 p) (add q (shift 1 q)))
  61. theorem widthFiveBezout : coprimeWitness P5 Q5 = [1] := by decide
  62. theorem widthSixBezout : coprimeWitness P6 Q6 = [1] := by decide
  63. #print axioms widthFiveBezout
  64. #print axioms widthSixBezout
  65. end WidthCounts