Riemannian systems and the recognition language
Definitionrsg_recognition_coreDefines finite graph encodings, the exact-order vertex and edge involutions, the full Loos law on vertices and unordered edges, and the computational classes and 3-SAT benchmark for the recognition question.
import Mathlib.Combinatorics.SimpleGraph.Maps
import Mathlib.Computability.TuringMachine.Computable
import Mathlib.Data.Nat.Bits
import Mathlib.GroupTheory.Perm.Basic
set_option autoImplicit false
namespace RSGRecognition
/-- The subgroup of vertex permutations preserving adjacency in both directions. -/
def GraphAut {V : Type} (G : SimpleGraph V) : Subgroup (Equiv.Perm V) where
carrier := {f | ∀ u v, G.Adj (f u) (f v) ↔ G.Adj u v}
one_mem' := fun _ _ => Iff.rfl
mul_mem' := fun hf hg u v => (hf _ _).trans (hg u v)
inv_mem' := by
intro f hf u v
simpa using (hf (f.symm u) (f.symm v)).symm
/-- Vertices and unordered edges are disjoint sets of indices. -/
abbrev Index {V : Type} (G : SimpleGraph V) := V ⊕ G.edgeSet
/-- The action sends each vertex and each unordered edge to its image. -/
def act {V : Type} (G : SimpleGraph V) (f : GraphAut G) : Index G → Index G :=
let iso : G ≃g G := { f.val with map_rel_iff' := fun {u v} => f.property u v }
Sum.map f.val iso.mapEdgeSet
/-- A valid involution has exact order two and the required local action. -/
def ValidAt {V : Type} (G : SimpleGraph V) (a : Index G) (f : GraphAut G) : Prop :=
f * f = 1 ∧ f ≠ 1 ∧
match a with
| .inl v => f.val v = v ∧ ∀ w, G.Adj v w → f.val w ≠ w
| .inr e => ∀ u v, s(u, v) = e.val → f.val u = v ∧ f.val v = u
/-- The Loos law is stated as an equality after right multiplication by the
outer involution. Its two indices range independently over vertices and edges. -/
def IsRSG {V : Type} (G : SimpleGraph V) : Prop :=
∃ sigma : Index G → GraphAut G,
(∀ a, ValidAt G a (sigma a)) ∧
∀ a b, sigma (act G (sigma a) b) * sigma a = sigma a * sigma b
/-- Each index admits a central witness in its stabilizer in a single subgroup. -/
def HasCentralWitnesses {V : Type} (G : SimpleGraph V) : Prop :=
∃ H : Subgroup (GraphAut G), ∀ a : Index G, ∃ f : H,
ValidAt G a f.val ∧ ∀ h : H, act G h.val a = a → f * h = h * f
abbrev Word := List Bool
def wordEncoding : Computability.Encoding Word Bool where
encode := id
decode := some
decode_encode := fun _ => rfl
/-- An unambiguous length prefix for a word that will be followed by more bits. -/
def frame (w : Word) : Word := List.replicate w.length true ++ [false] ++ w
/-- A unary vertex count followed by the entire adjacency matrix in row-major order. -/
def graphWord {n : ℕ} (G : SimpleGraph (Fin n)) (adj : DecidableRel G.Adj) : Word :=
List.replicate n true ++ [false] ++
(List.ofFn fun i : Fin n => List.ofFn fun j : Fin n =>
@decide (G.Adj i j) (adj i j)).flatten
/-- Valid encodings of arbitrary finite simple RSGs. -/
def rsgLanguage (w : Word) : Prop :=
∃ (n : ℕ) (G : SimpleGraph (Fin n)) (adj : DecidableRel G.Adj),
w = graphWord G adj ∧ IsRSG G
/-- A polynomial-time bound on a deterministic finite multi-stack machine. -/
def PolyTime {β : Type} (output : β → Word) (f : Word → β) : Prop :=
Nonempty (Turing.TM2ComputableInPolyTime wordEncoding.encode output f)
abbrev Language := Word → Prop
def InP (L : Language) : Prop :=
∃ decideWord : Word → Bool,
PolyTime Computability.encodeBool decideWord ∧
∀ w, decideWord w = true ↔ L w
def InNP (L : Language) : Prop :=
∃ (p : Polynomial ℕ) (verify : Word → Bool),
PolyTime Computability.encodeBool verify ∧
∀ w, L w ↔ ∃ certificate : Word,
certificate.length ≤ p.eval w.length ∧ verify (frame w ++ certificate) = true
def ManyOneReduces (L M : Language) : Prop :=
∃ reduce : Word → Word, PolyTime wordEncoding.encode reduce ∧
∀ w, L w ↔ M (reduce w)
def NPHard (M : Language) : Prop :=
∀ L : Language, InNP L → ManyOneReduces L M
/-- A variable number and the value required for the corresponding literal. -/
abbrev Literal := ℕ × Bool
abbrev Clause := Fin 3 → Literal
abbrev Formula := List Clause
def formulaWord (formula : Formula) : Word :=
(formula.map fun clause =>
(List.ofFn fun i : Fin 3 =>
(clause i).2 :: frame (clause i).1.bits).flatten).flatten
def Satisfiable (formula : Formula) : Prop :=
∃ assignment : ℕ → Bool, ∀ clause ∈ formula, ∃ i : Fin 3,
assignment (clause i).1 = (clause i).2
def threeSAT (w : Word) : Prop :=
∃ formula : Formula, w = formulaWord formula ∧ Satisfiable formula
end RSGRecognition
Read-back
What the Lean code literally says, in plain math · Codex GPT-6 independent auditor
For a simple graph on a vertex type, the automorphisms form the subgroup of vertex permutations that preserve adjacency in both directions. The indices are vertices and unordered edges, and an automorphism maps the two endpoints of an edge. A valid assignment at an index has square the identity, differs from the identity, and fixes the indexed vertex while moving every neighbor or exchanges the endpoints of the indexed edge. At an isolated vertex the neighbor condition is vacuous. The RSG predicate requires an assignment of valid automorphisms with for all pairs of indices. The central-witness predicate requires a single subgroup with a valid element at each index commuting with every element of that subgroup fixing the index. Both graph predicates hold on the empty graph.
Words are finite Boolean lists, encoded identically and decoded successfully to themselves. Framing a word of length prepends true bits and a false bit. A graph word is true bits, one false bit, and the full row-major adjacency matrix of a graph with decidable adjacency on . The RSG language consists of such words for graphs satisfying the RSG predicate. The one-false-bit word for belongs to the language, and the empty word is outside it.
For a result type, an output map into Boolean words and a function on Boolean words, polynomial-time computability requires a deterministic finite multi-stack Turing machine receiving the input word itself and producing the encoded output in polynomial time. Deciders and verifiers use the fixed Boolean-to-word encoding. Reductions use the identity output encoding on words. The P predicate requires a Boolean decision function. The NP predicate requires a Boolean verifier and a natural-coefficient polynomial certificate bound. Membership is equivalent to acceptance of some certificate of bounded length appended to the framed instance. A many-one reduction is a polynomial-time word function preserving membership in both directions. NP-hardness requires a reduction from each language in NP.
A formula is a finite list of triples of literals. A literal consists of a variable indexed by a natural number and a required Boolean value. The encoding concatenates the required value followed by the framed binary variable index for each literal in order. The 3-SAT language consists of formula encodings with a total Boolean assignment matching at least one literal in each clause. The empty formula is satisfiable and encodes as the empty word.