import Std/- Integer coefficient verification of det(I - x(A+uD)).The two powers in a monomial are the exponents of x and u. -/namespace RookCertificatestructure Term wherexDegree : NatuDegree : Natweight : Intderiving Reprdef occupancyEntry (row col : Nat) : Nat :=((List.range 4).filter fun j =>!(row.testBit j) && ((row + 2^j)/2 == col)).lengthdef entry (row col : Nat) : List Term :=let hold : List Term := if row == col then [⟨0, 0, 1⟩] else []let count := occupancyEntry row collet fill : List Term := if count == 0 then [] else [⟨1, 0, -(Int.ofNat count)⟩]let empty : List Term := if row/2 == col then [⟨1, 1, -1⟩] else []hold ++ fill ++ emptydef times (a b : Term) (sgn : Int) : Term :=⟨a.xDegree + b.xDegree, a.uDegree + b.uDegree, sgn * a.weight * b.weight⟩/-- Laplace expansion through progressively smaller column lists.The first available remaining column has positive cofactor sign. -/def expansion : Nat → Nat → List Nat → List Term| 0, _, _ => [⟨0, 0, 1⟩]| fuel+1, row, cols =>(cols.zipIdx).flatMap fun (col, idx) =>let factors := entry row colif factors.isEmpty then [] elselet rest := expansion fuel (row+1) (cols.erase col)let sgn : Int := if idx % 2 == 0 then 1 else -1factors.flatMap fun a => rest.map fun b => times a b sgndef coefficients (ts : List Term) : List (List Int) :=(List.range 9).map fun i => (List.range 9).map fun j =>ts.foldl (fun acc t => if t.xDegree == i && t.uDegree == j then acc+t.weight else acc) 0def expected : List (List Int) :=[[1,0,0,0,0,0,0,0,0], [-4,-1,0,0,0,0,0,0,0], [4,0,0,0,0,0,0,0,0],[0,1,0,0,0,0,0,0,0], [2,4,1,0,0,0,0,0,0], [-4,-3,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0], [0,-1,0,0,0,0,0,0,0], [1,0,0,0,0,0,0,0,0]]set_option maxRecDepth 20000set_option maxHeartbeats 0theorem signed_expansion : coefficients (expansion 8 0 (List.range 8)) = expected := bydecide +kernel#print axioms signed_expansionend RookCertificate