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 RookCertificate structure Term where xDegree : Nat uDegree : Nat weight : Int deriving Repr def occupancyEntry (row col : Nat) : Nat := ((List.range 4).filter fun j => !(row.testBit j) && ((row + 2^j)/2 == col)).length def entry (row col : Nat) : List Term := let hold : List Term := if row == col then [⟨0, 0, 1⟩] else [] let count := occupancyEntry row col let 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 ++ empty def 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 col if factors.isEmpty then [] else let rest := expansion fuel (row+1) (cols.erase col) let sgn : Int := if idx % 2 == 0 then 1 else -1 factors.flatMap fun a => rest.map fun b => times a b sgn def 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) 0 def 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 20000 set_option maxHeartbeats 0 theorem signed_expansion : coefficients (expansion 8 0 (List.range 8)) = expected := by decide +kernel #print axioms signed_expansion end RookCertificate