Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Finite candidate checker for affine-chart RSG recognition

Definition
rsg_paper_chart_checker

by sirawit · Nov 30, 2026 · Mathlib 0df444a (Lean v4.33.1)

computational-complexitygraph-theory

The executable checker in the proof of Theorem 5.3 parses a graph and a binary chart, decodes a bounded candidate for the projected action and kernel, and checks the algebraic conditions for an edge or full system. It uses elimination over binary rows for the lift tests. The module also defines the candidate enumeration bound and the predicate that the selected kind of system exists within the chart.

Definition code
import Mathlib
import Definitions.Def_rsg_paper_complexity
import Definitions.Def_rsg_paper_structure
import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected
import Mathlib.Data.Finite.Sum
import Mathlib.Data.Fintype.Sum
import Mathlib.Data.Fintype.Sigma
import Mathlib.Data.Set.Card
import Definitions.Def_rsg_recognition_core
import Mathlib.Data.ZMod.Basic
import Mathlib.Tactic.FinCases
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Fintype.Prod
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Ring
import Definitions.Def_rsg_paper_vig_strip
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Logic.Equiv.Sum
import Definitions.Def_QuantumMaxCutFiniteNumericRuntime
import Mathlib.Combinatorics.SimpleGraph.Bipartite
import Mathlib.Data.List.NodupEquivFin
import Mathlib.Combinatorics.SimpleGraph.Prod
import Mathlib.Tactic.LinearCombination
import Definitions.Def_rsg_paper_eig_bipartite_lift
import Mathlib.Analysis.SpecialFunctions.Log.Base
import Mathlib.Algebra.Field.ZMod
import Mathlib.LinearAlgebra.Dual.Lemmas
import Mathlib.LinearAlgebra.Pi
import Mathlib.Data.Sym.Sym2.Order
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.LinearAlgebra.Dimension.Constructions
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
import Mathlib.LinearAlgebra.Dimension.Finrank
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.Logic.Equiv.Fin.Basic

section

set_option autoImplicit false

namespace RSGPaper.EIGLinearSolve

abbrev Word := List Bool
abbrev Row := Word × Bool

def addRows : Word → Word → Word
  | [], b => b
  | a, [] => a
  | a :: as, b :: bs => (a ^^ b) :: addRows as bs

def first (r : Row) : Bool := r.1.head?.getD false

def dropFirst (r : Row) : Row := (r.1.tail, r.2)

def eliminateWith (pivot r : Row) : Row :=
  if first r then (addRows r.1.tail pivot.1.tail, r.2 ^^ pivot.2) else dropFirst r

def eliminate (rows : List Row) : List Row :=
  match rows.find? first with
  | none => rows.map dropFirst
  | some pivot => rows.map (eliminateWith pivot)

def run : ℕ → List Row → Bool
  | 0, rows => rows.all (fun r => !r.2)
  | n + 1, rows => run n (eliminate rows)

end RSGPaper.EIGLinearSolve

end

section

set_option autoImplicit false

namespace RSGPaper.EIGNumericRuntime

open OAI.MetricKMedian.Binary
open OAI.MetricKMedian.Binary.Automatic
open QMCNumericRuntime

def powerOfTwo (digits : List Bool) : ℕ := Word.value (digits.map (fun _ => false) ++ [true])

def boundedRange (fuel : List Bool) (n : ℕ) : List ℕ := (List.range fuel.length).take n

def budgetPower : ℕ → List Bool → List Bool
  | 0, _ => [false]
  | p + 1, fuel => (fuel.product (budgetPower p fuel)).map (fun _ => false)

def scaleTwo : ℕ → List Bool → List Bool
  | 0, fuel => fuel
  | p + 1, fuel => let f := scaleTwo p fuel; f ++ f

end RSGPaper.EIGNumericRuntime

end

section

set_option autoImplicit false

namespace RSGPaper.EIGRawCoefficients

open OAI.MetricKMedian.Binary
open OAI.MetricKMedian.Binary.Automatic
open EIGNumericRuntime

open scoped BigOperators

def xorSum (xs : List Bool) : Bool := xs.foldl (fun x y => x ^^ y) false

end RSGPaper.EIGRawCoefficients

end

section

set_option autoImplicit false

namespace RSGPaper.AffineSolver

open OAI.MetricKMedian.Binary.Automatic

abbrev Word := List Bool

def zeroWord (fuel : Word) : Word := fuel.map fun _ => false

def unit (fuel : Word) (i : ℕ) : Word :=
  (List.range fuel.length).map fun j => decide (j = i)

def row (fuel : Word) (f : Word → Bool) : EIGLinearSolve.Row :=
  let b := f (zeroWord fuel)
  ((List.range fuel.length).map (fun i => f (unit fuel i) ^^ b), b)

def test {E : Type} (fuel : Word) (equations : List E) (evaluate : E → Word → Bool) : Bool :=
  EIGLinearSolve.run fuel.length (equations.map fun e => row fuel (evaluate e))

end RSGPaper.AffineSolver

end

section

set_option autoImplicit false

namespace RSGPaper.ChartParser

open RSGRecognition
open OAI.MetricKMedian.Binary.Automatic
open QMCNumericRuntime (parser_drop_poly parser_take_poly)

abbrev Raw := ℕ × ℕ × ℕ × Word × Word

def unary (bits : Word) : ℕ := bits.findIdx (!·)

def payload (bits : Word) : Word := bits.drop (unary bits + 1)

def split (bits : Word) : Word × Word :=
  let l := unary bits
  let body := payload bits
  (body.take l, body.drop l)

def parse (bits : Word) : Raw :=
  let (g, ch) := split bits
  let d := unary ch
  let labels := payload ch
  let r := unary labels
  (unary g, d, r, payload g, payload labels)

def entry (body : Word) (width row col : ℕ) : Bool :=
  (body[row * width + col]?).getD false

def coordinate (body : Word) (width row : ℕ) : Word := (body.drop (row * width)).take width

end RSGPaper.ChartParser

end

section

set_option autoImplicit false

namespace RSGPaper.ChartNumericInput

open RSGRecognition
open ChartParser
open EIGNumericRuntime
open OAI.MetricKMedian.Binary.Automatic
open OAI.MetricKMedian.Binary
open QMCNumericRuntime (parser_take_poly parser_drop_poly)

abbrev Input := Raw × RSGRecognition.Word

def read (w : RSGRecognition.Word) : Input := (parse w, w)
def order (i : Input) : ℕ := i.1.1
def d (i : Input) : ℕ := i.1.2.1
def r (i : Input) : ℕ := i.1.2.2.1
def graph (i : Input) : RSGRecognition.Word := i.1.2.2.2.1
def chart (i : Input) : RSGRecognition.Word := i.1.2.2.2.2
def fuel (i : Input) : RSGRecognition.Word := i.2

def vertices (i : Input) : List ℕ := boundedRange (fuel i) (order i)

def powerPrefix (w : RSGRecognition.Word) (width : ℕ) : ℕ := powerOfTwo (w.take width)

def positions (i : Input) : List ℕ := boundedRange (fuel i) (powerPrefix (fuel i) (d i))

def labels (i : Input) : List ℕ := boundedRange (fuel i) (powerPrefix (fuel i) (r i))

def adj (i : Input) (u v : ℕ) : Bool := entry (graph i) (order i) u v

def coordinateWord (i : Input) (v : ℕ) : RSGRecognition.Word :=
  coordinate (chart i) (d i + r i) v

def code (i : Input) (v : ℕ) : ℕ × ℕ :=
  let row := coordinateWord i v
  (Word.value (row.take (d i)), Word.value (row.drop (d i)))

def vertex (i : Input) (p u : ℕ) : ℕ :=
  (vertices i).findIdx fun v => decide ((code i v).1 = p) && decide ((code i v).2 = u)

def relation (i : Input) (p q u v : ℕ) : Bool := adj i (vertex i p u) (vertex i q v)

section Correct

variable {n : ℕ} (G : SimpleGraph (Fin n)) (isAdj : DecidableRel G.Adj) (ch : BinaryChart (Fin n))

local notation "data" => read (chartInstanceWord G isAdj ch)

end Correct

end RSGPaper.ChartNumericInput

end

section

set_option autoImplicit false

namespace RSGPaper.ChartBudget

open RSGRecognition
open ChartNumericInput
open EIGNumericRuntime
open OAI.MetricKMedian.Binary.Automatic
open OAI.MetricKMedian.Binary

def slots (d r : ℕ) : ℕ :=
  if r = 0 then 0 else
    let m := (d + 1) * r
    d * d + (m + 1) + (2 * d + 1) * m * r + m

def inputSlots (w : RSGRecognition.Word) : ℕ := slots (d (read w)) (r (read w))

def cap (w : RSGRecognition.Word) : ℕ := powerOfTwo ((List.range (inputSlots w)).map fun _ => false)

end RSGPaper.ChartBudget

end

section

set_option autoImplicit false
set_option maxHeartbeats 1000000

namespace RSGPaper.NumericTransporters

open RSGRecognition
open ChartNumericInput
open OAI.MetricKMedian.Binary.Automatic

abbrev Offset := ℕ × ℕ
abbrev Slot := Input × ℕ × ℕ × ℕ

def offsets (data : Input) : List Offset := (labels data).product (labels data)

def compares (s : Slot) (a z : Offset) : Bool :=
  relation s.1 s.2.1 s.2.2.1 z.1 z.2 ==
    relation s.1 (s.2.1 ^^^ s.2.2.2) (s.2.2.1 ^^^ s.2.2.2) (z.1 ^^^ a.1) (z.2 ^^^ a.2)

def between (s : Slot) (a : Offset) : Bool := (offsets s.1).all (compares s a)

def baseIndex (s : Slot) : ℕ := (offsets s.1).findIdx (between s)

def baseOffset (s : Slot) : Offset := (offsets s.1)[baseIndex s]?.getD (0,0)

def known (s : Slot) : Bool := decide (baseIndex s < (offsets s.1).length)

def stabilizes (s : Slot) (a : Offset) : Bool :=
  between (s.1, s.2.1 ^^^ s.2.2.2, s.2.2.1 ^^^ s.2.2.2, 0) a

section Correct

variable {n : ℕ} (G : SimpleGraph (Fin n)) (isAdj : DecidableRel G.Adj) (ch : BinaryChart (Fin n))

local notation "data" => ChartNumericInput.read (chartInstanceWord G isAdj ch)

end Correct

end RSGPaper.NumericTransporters

end

section

set_option autoImplicit false

namespace RSGPaper.MatrixBits

open EIGRawCoefficients (xorSum)
open OAI.MetricKMedian.Binary.Automatic

abbrev Word := List Bool

def bit (v : Word) (i : ℕ) : Bool := v[i]?.getD false

def columnFold (cols : Word) (entry : ℕ → Bool) (v : Word) : Bool :=
  xorSum ((List.range cols.length).map fun j => entry j && bit v j)

def apply (rows cols : Word) (entry : ℕ → ℕ → Bool) (v : Word) : Word :=
  (List.range rows.length).map fun i => columnFold cols (entry i) v

end RSGPaper.MatrixBits

end

section

set_option autoImplicit false

namespace RSGPaper.TransporterDual

open RSGRecognition
open ChartNumericInput
open NumericTransporters
open OAI.MetricKMedian.Binary.Automatic

open QMCNumericRuntime (parser_take_poly)

abbrev Word := List Bool

def labelFuel (i : Input) : Word := (fuel i).take (r i)

def lowBits (fuel : Word) (a : ℕ) : Word := (List.range fuel.length).map (a.testBit)

def dot (fuel : Word) (a b : ℕ) : Bool := MatrixBits.columnFold fuel (a.testBit) (lowBits fuel b)

def evaluate (data : Input) (coeff x : Offset) : Bool :=
  dot (labelFuel data) coeff.1 x.1 ^^ dot (labelFuel data) coeff.2 x.2

def vanishes (slot : Slot) (coeff x : Offset) : Bool :=
  !(stabilizes slot x) || !(evaluate slot.1 coeff x)

def dual (slot : Slot) (coeff : Offset) : Bool := (offsets slot.1).all (vanishes slot coeff)

section Correct

variable {n : ℕ} (G : SimpleGraph (Fin n)) (isAdj : DecidableRel G.Adj) (ch : BinaryChart (Fin n))

local notation "data" => ChartNumericInput.read (chartInstanceWord G isAdj ch)

end Correct

end RSGPaper.TransporterDual

end

section

set_option autoImplicit false
set_option maxHeartbeats 1200000

namespace RSGPaper.ChartModelBits

open RSGRecognition
open ChartNumericInput
open OAI.MetricKMedian.Binary.Automatic
open OAI.MetricKMedian.Binary
open QMCNumericRuntime (parser_take_poly parser_reverse_poly)
open TransporterDual (labelFuel lowBits)

abbrev Bits := List Bool
abbrev Model := Input × ℕ × ℕ

def maxDim (data : Input) : ℕ := (d data + 1) * r data

def positionFuel (data : Input) : Bits := (fuel data).take (d data)

def dimensionFuel (data : Input) : Bits := (fuel data).take (maxDim data + 1)

def basisArea (data : Input) : ℕ := d data * d data

def dimension (data : Input) (mask : ℕ) : ℕ :=
  (List.range (dimensionFuel data).length).findIdx (fun i => !(mask.testBit (basisArea data + i)))

def model (i : Input) (mask : ℕ) : Model := (i, mask, dimension i mask)

def kernelFuel (q : Model) : Bits := (fuel q.1).take q.2.2

def matrixBase (i : Input) : ℕ := basisArea i + maxDim i + 1
def blockSize (i : Input) : ℕ := maxDim i * r i
def axisBase (i : Input) (axis : ℕ) : ℕ := matrixBase i + axis * (2 * blockSize i)
def readBase (i : Input) : ℕ := axisBase i (d i)
def witnessBase (i : Input) : ℕ := readBase i + blockSize i

def basisBit (q : Model) (row col : ℕ) : Bool := q.2.1.testBit (col * d q.1 + row)

def leftBit (q : Model) (axis row col : ℕ) : Bool :=
  q.2.1.testBit (axisBase q.1 axis + row * r q.1 + col)

def rightBit (q : Model) (axis row col : ℕ) : Bool :=
  q.2.1.testBit (axisBase q.1 axis + blockSize q.1 + row * maxDim q.1 + col)

def readBit (q : Model) (row col : ℕ) : Bool :=
  q.2.1.testBit (readBase q.1 + row * maxDim q.1 + col)

def basisApply (q : Model) (z : Bits) : Bits :=
  MatrixBits.apply (positionFuel q.1) (positionFuel q.1) (basisBit q) z

def basisValue (q : Model) (z : ℕ) : ℕ :=
  Word.value (basisApply q (lowBits (positionFuel q.1) z))

def coefficients (q : Model) (p : ℕ) : ℕ :=
  (positions q.1).findIdx (fun z => decide (basisValue q z = p))

def act (q : Model) (axis : ℕ) (z : Bits) : Bits :=
  let mid := MatrixBits.apply (labelFuel q.1) z (rightBit q axis) z
  EIGLinearSolve.addRows z (MatrixBits.apply z (labelFuel q.1) (leftBit q axis) mid)

def rootRead (q : Model) (z : Bits) : Bits :=
  MatrixBits.apply (labelFuel q.1) z (readBit q) z

abbrev State := Model × ℕ × Bits

def advance (x : State × ℕ) : State :=
  let s := x.1
  (s.1, s.2.1, if s.2.1.testBit x.2 then act s.1 x.2 s.2.2 else s.2.2)

def fold (axes : List ℕ) (s : State) : State := axes.foldl (fun t j => advance (t,j)) s

def profileValue (q : Model) (p : ℕ) (z : Bits) : Bits :=
  let indices := (List.range (positionFuel q.1).length).reverse
  rootRead q (fold indices (q, coefficients q p, z)).2.2

def witnessVector (q : Model) : Bits :=
  (List.range (kernelFuel q).length).map (fun i => q.2.1.testBit (witnessBase q.1 + i))

end RSGPaper.ChartModelBits

end

section

set_option autoImplicit false

namespace RSGPaper.ChartZeroCheck

open RSGRecognition
open ChartNumericInput
open OAI.MetricKMedian.Binary.Automatic

abbrev Pair := ℕ × ℕ

def vertexPairs (data : Input) : List Pair := (vertices data).product (vertices data)

def applyShift (data : Input) (a v : ℕ) : ℕ :=
  let (p,u) := code data v
  vertex data (p ^^^ a) u

def preserved (data : Input) (a : ℕ) (p : Pair) : Bool :=
  adj data p.1 p.2 == adj data (applyShift data a p.1) (applyShift data a p.2)

def automorphism (data : Input) (a : ℕ) : Bool := (vertexPairs data).all (preserved data a)

def direction (i : Input) (u v : ℕ) : ℕ := (code i u).1 ^^^ (code i v).1

def suitable (data : Input) (p : Pair) : Bool :=
  !(adj data p.1 p.2) || automorphism data (direction data p.1 p.2)

def edgeCheck (data : Input) : Bool := (vertexPairs data).all (suitable data)

section Correct

variable {n : ℕ} (G : SimpleGraph (Fin n)) (isAdj : DecidableRel G.Adj) (ch : BinaryChart (Fin n))

local notation "data" => ChartNumericInput.read (chartInstanceWord G isAdj ch)

end Correct

end RSGPaper.ChartZeroCheck

end

section

set_option autoImplicit false
set_option maxHeartbeats 1500000

namespace RSGPaper.ChartPackedLifts

open RSGRecognition
open ChartNumericInput
open ChartModelBits
open EIGNumericRuntime
open OAI.MetricKMedian.Binary.Automatic
open OAI.MetricKMedian.Binary
open QMCNumericRuntime (parser_take_poly)
open TransporterDual (labelFuel)
open ChartZeroCheck (vertexPairs direction)

def nsites (q : Model) : ℕ := (positions q.1).length
def nvertices (q : Model) : ℕ := (vertices q.1).length
def nlabels (q : Model) : ℕ := (labelFuel q.1).length
def nkernel (q : Model) : ℕ := (kernelFuel q).length

def liftSize (q : Model) : ℕ := nsites q * nsites q * nlabels q
def zeroOffset (q : Model) : ℕ := liftSize q
def closureOffset (q : Model) : ℕ := zeroOffset q + nkernel q
def edgeOffset (q : Model) : ℕ := closureOffset q + nsites q * nsites q * nkernel q
def assignmentSize (q : Model) : ℕ := edgeOffset q + nvertices q * nvertices q * nkernel q

def assignmentFuel (q : Model) : Bits :=
  (scaleTwo 2 (budgetPower 3 (false :: fuel q.1))).take (assignmentSize q)

def slice (width assignment : Bits) (offset : ℕ) : Bits :=
  (List.range width.length).map (fun j => MatrixBits.bit assignment (offset + j))

def liftStart (q : Model) (a p : ℕ) : ℕ := (a * nsites q + p) * nlabels q

def closureStart (q : Model) (a b : ℕ) : ℕ := closureOffset q + (a * nsites q + b) * nkernel q

def edgeStart (q : Model) (u v : ℕ) : ℕ := edgeOffset q + (u * nvertices q + v) * nkernel q

def liftWord (q : Model) (assignment : Bits) (a p : ℕ) : Bits :=
  slice (labelFuel q.1) assignment (liftStart q a p)

def zeroParams (q : Model) (assignment : Bits) : Bits :=
  slice (kernelFuel q) assignment (zeroOffset q)

def closureParams (q : Model) (assignment : Bits) (a b : ℕ) : Bits :=
  slice (kernelFuel q) assignment (closureStart q a b)

def edgeParams (q : Model) (assignment : Bits) (u v : ℕ) : Bits :=
  slice (kernelFuel q) assignment (edgeStart q u v)

def labelIndices (q : Model) : List ℕ := List.range (nlabels q)

def positionBits (q : Model) : List (ℕ × ℕ) :=
  (positions q.1).product (labelIndices q)

def sitePairs (q : Model) : List (ℕ × ℕ) := (positions q.1).product (positions q.1)

end RSGPaper.ChartPackedLifts

end

section

set_option autoImplicit false
set_option maxHeartbeats 1700000

namespace RSGPaper.ChartPackedEquations

open RSGRecognition
open ChartNumericInput
open ChartModelBits
open ChartPackedLifts
open OAI.MetricKMedian.Binary.Automatic
open OAI.MetricKMedian.Binary
open NumericTransporters (offsets)

abbrev Equation := ℕ × ℕ × ℕ × ℕ × ℕ × ℕ

def shifts (q : Model) : List (ℕ × ℕ × ℕ) := (positions q.1).product (sitePairs q)

def localKnown (q : Model) (v : ℕ × ℕ × ℕ) : Bool :=
  NumericTransporters.known (q.1,v.2.1,v.2.2,v.1)

def allKnown (q : Model) : Bool := (shifts q).all (localKnown q)

def transportInputs (q : Model) : List Equation :=
  ((shifts q).product (offsets q.1)).map (fun t => (0,t.1.1,t.1.2.1,t.1.2.2,t.2.1,t.2.2))

def zeroInputs (q : Model) : List Equation :=
  (positionBits q).map (fun t => (1,t.1,t.2,0,0,0))

def closureInputs (q : Model) : List Equation :=
  ((sitePairs q).product (positionBits q)).map (fun t => (2,t.1.1,t.1.2,t.2.1,t.2.2,0))

def involutionInputs (q : Model) : List Equation :=
  ((ChartZeroCheck.vertexPairs q.1).product (positionBits q)).map (fun t => (3,t.1.1,t.1.2,t.2.1,t.2.2,0))

def endpointInputs (q : Model) : List Equation :=
  ((ChartZeroCheck.vertexPairs q.1).product (labelIndices q)).map (fun t => (4,t.1.1,t.1.2,t.2,0,0))

def equations (q : Model) : List Equation :=
  transportInputs q ++ zeroInputs q ++ closureInputs q ++ involutionInputs q ++ endpointInputs q

abbrev Context := Model × Bits

def liftValue (x : Context) (a p : ℕ) : ℕ := Word.value (liftWord x.1 x.2 a p)

def transportValue (x : Context) (a p q c e : ℕ) : Bool :=
  let slot := (x.1.1,p,q,a)
  let coeff := (c,e)
  if TransporterDual.dual slot coeff then
    TransporterDual.evaluate x.1.1 coeff (liftValue x a p,liftValue x a q) ^^
      TransporterDual.evaluate x.1.1 coeff (NumericTransporters.baseOffset slot)
  else false

def liftBit (x : Context) (a p j : ℕ) : Bool := MatrixBits.bit (liftWord x.1 x.2 a p) j

def kernelBit (q : Model) (p : ℕ) (coeff : Bits) (j : ℕ) : Bool :=
  MatrixBits.bit (profileValue q p coeff) j

def zeroValue (x : Context) (p j : ℕ) : Bool :=
  liftBit x 0 p j ^^ kernelBit x.1 p (zeroParams x.1 x.2) j

def closureValue (x : Context) (a b p j : ℕ) : Bool :=
  liftBit x b p j ^^ liftBit x a (p ^^^ b) j ^^ liftBit x (a ^^^ b) p j ^^
    kernelBit x.1 p (closureParams x.1 x.2 a b) j

def edgeBit (x : Context) (a u v p j : ℕ) : Bool :=
  liftBit x a p j ^^ kernelBit x.1 p (edgeParams x.1 x.2 u v) j

def involutionValue (x : Context) (u v p j : ℕ) : Bool :=
  if adj x.1.1 u v then
    let a := ChartZeroCheck.direction x.1.1 u v
    edgeBit x a u v p j ^^ edgeBit x a u v (p ^^^ a) j
  else false

def endpointValue (x : Context) (u v j : ℕ) : Bool :=
  if adj x.1.1 u v then
    let a := ChartZeroCheck.direction x.1.1 u v
    edgeBit x a u v (code x.1.1 u).1 j ^^ ((code x.1.1 u).2 ^^^ (code x.1.1 v).2).testBit j
  else false

def evaluate (q : Model) (index : Equation) (a : Bits) : Bool :=
  let x := (q,a)
  let j := index.2
  if index.1 = 0 then transportValue x j.1 j.2.1 j.2.2.1 j.2.2.2.1 j.2.2.2.2
  else if index.1 = 1 then zeroValue x j.1 j.2.1
  else if index.1 = 2 then closureValue x j.1 j.2.1 j.2.2.1 j.2.2.2.1
  else if index.1 = 3 then involutionValue x j.1 j.2.1 j.2.2.1 j.2.2.2.1
  else endpointValue x j.1 j.2.1 j.2.2.1

def liftsExist (q : Model) : Bool :=
  allKnown q && AffineSolver.test (assignmentFuel q) (equations q) (evaluate q)

end RSGPaper.ChartPackedEquations

end

section

set_option autoImplicit false
set_option maxHeartbeats 1700000

namespace RSGPaper.ChartKernelChecks

open RSGRecognition
open ChartNumericInput
open ChartModelBits
open ChartPackedLifts
open ChartPackedEquations (kernelBit)
open ChartZeroCheck (vertexPairs)
open OAI.MetricKMedian.Binary.Automatic
open OAI.MetricKMedian.Binary
open EIGNumericRuntime

abbrev SiteBit := ℕ × ℕ

def kernelIndices (q : Model) : List ℕ := List.range (nkernel q)

def basisValue (q : Model) (p c j : ℕ) : Bool :=
  kernelBit q p (AffineSolver.unit (kernelFuel q) c) j

def shiftValue (q : Model) (move : SiteBit) (point : SiteBit) (assignment : Bits) : Bool :=
  kernelBit q point.1 assignment point.2 ^^ basisValue q (point.1 ^^^ move.1) move.2 point.2

def shiftMember (q : Model) (move : SiteBit) : Bool :=
  AffineSolver.test (kernelFuel q) (positionBits q) (shiftValue q move)

def invariant (q : Model) : Bool :=
  ((positions q.1).product (kernelIndices q)).all (shiftMember q)

def pureImage (q : Model) (c u : ℕ) : ℕ :=
  let (p,a) := code q.1 u
  vertex q.1 p (a ^^^ Word.value (profileValue q p (AffineSolver.unit (kernelFuel q) c)))

def purePreserves (q : Model) (c : ℕ) (e : ℕ × ℕ) : Bool :=
  adj q.1 e.1 e.2 == adj q.1 (pureImage q c e.1) (pureImage q c e.2)

def pureGenerator (q : Model) (c : ℕ) : Bool := (vertexPairs q.1).all (purePreserves q c)

def pure (q : Model) : Bool := (kernelIndices q).all (pureGenerator q)

def rootValue (q : Model) (label j : ℕ) (vars : Bits) : Bool :=
  kernelBit q 0 vars j ^^ label.testBit j

def reachable (q : Model) (label : ℕ) : Bool :=
  AffineSolver.test (kernelFuel q) (labelIndices q) (rootValue q label)

def onto (q : Model) : Bool := (labels q.1).all (reachable q)

abbrev Edge := ℕ × ℕ
abbrev Center := Model × Edge × SiteBit

def centerEquations (q : Model) : List (ℕ × ℕ) :=
  [(2,0)] ++ ([0,1].product (labelIndices q))

def centerValue (ctx : Center) (eq : ℕ × ℕ) (z : Bits) : Bool :=
  let q := ctx.1
  let (u,v) := ctx.2.1
  let (p,j) := ctx.2.2
  if eq.1 = 0 then kernelBit q (code q.1 u).1 z eq.2
  else if eq.1 = 1 then kernelBit q (code q.1 v).1 z eq.2
  else !(kernelBit q p z j ^^ kernelBit q (p ^^^ ChartZeroCheck.direction q.1 u v) z j)

def centerFailure (ctx : Center) : Bool :=
  AffineSolver.test (kernelFuel ctx.1) (centerEquations ctx.1) (centerValue ctx)

def centerAt (q : Model) (e : Edge) : Bool :=
  !(adj q.1 e.1 e.2) || (positionBits q).all (fun point => !(centerFailure (q,e,point)))

def centers (q : Model) : Bool := (vertexPairs q.1).all (centerAt q)

def rootNeighbor (q : Model) (root v : ℕ) : Bool :=
  !(adj q.1 root v) || decide (0 < Word.value (profileValue q (code q.1 v).1 (witnessVector q)))

def rootWitness (q : Model) : Bool :=
  let root := vertex q.1 0 0
  decide (Word.value (profileValue q 0 (witnessVector q)) = 0) &&
    (vertices q.1).all (rootNeighbor q root)

def test (full : Bool) (data : Input) (mask : ℕ) : Bool :=
  if r data = 0 then
    !full && ChartZeroCheck.edgeCheck data
  else
    let q := model data mask
    decide (q.2.2 ≤ maxDim data) && invariant q && pure q && onto q && centers q &&
      ChartPackedEquations.liftsExist q && (!full || rootWitness q)

end RSGPaper.ChartKernelChecks

end

section

set_option autoImplicit false
set_option maxHeartbeats 1800000

namespace RSGPaper.ChartCheckerCorrect

open RSGRecognition
open ChartNumericInput
open ChartModelBits
open ChartPackedLifts

open ChartKernelChecks

def kind (full : Bool) : IndexKind := if full then .full else .edge

def HasChartSystem {n : ℕ} (G : SimpleGraph (Fin n)) (ch : BinaryChart (Fin n))
    (k : IndexKind) : Prop :=
  ∃ σ : IdxType G k → GraphAut G, IsSystem G k σ ∧ ∀ a, InChart ch (σ a).val

section Valid

variable {n : ℕ} (G : SimpleGraph (Fin n)) (isAdj : DecidableRel G.Adj) (ch : BinaryChart (Fin n))
variable (full : Bool)

local notation "word" => chartInstanceWord G isAdj ch
local notation "data" => ChartNumericInput.read word
local notation "system" => HasChartSystem G ch (kind full)

end Valid

end RSGPaper.ChartCheckerCorrect

end
Source
Sirawit Pongnakintr, Riemannian Symmetric Graphs, Hexagon preprint 2611.01261v2, https://hexagonmath.org/2611.01261v2, Theorem 5.3 and its proof.

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me