Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Typed derivative profiles and colored graph palettes

Definition
rsg_quartic_runtime_02

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

complexity-theorygraph-theorygroup-theory

Defines the affine and quadratic profiles, their typed derivative and row constraints, and the colored graph palettes and chart coordinates used by the fourth-root reduction.

Definition code
import Definitions.Def_rsg_quartic_runtime_01
import Mathlib
import Definitions.Def_rsg_paper_structure
import Mathlib.LinearAlgebra.Pi
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.Finset.Card
import Mathlib.Tactic.Abel
import Definitions.Def_rsg_recognition_core
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected
import Mathlib.GroupTheory.PGroup
import Mathlib.GroupTheory.Nilpotent
import Mathlib.Combinatorics.SimpleGraph.Coloring.Vertex
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.LinearAlgebra.Isomorphisms
import Mathlib.Logic.Equiv.Defs
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Finset.Erase
import Mathlib.Logic.Function.Basic
import Mathlib.Data.Fintype.Sigma
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.LinearAlgebra.Dual.Defs
import Mathlib.LinearAlgebra.Basis.Prod
import Mathlib.LinearAlgebra.Dual.Basis
import Mathlib.Algebra.CharP.Two
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.Data.Set.Card
import Mathlib.FieldTheory.Finite.Trace
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Ring

section

set_option autoImplicit false
set_option maxHeartbeats 1200000

namespace RSGPaper.QuarticAffineDifference

open BooleanMonomials
open QuarticJointGuards

variable {A B : Type} [AddCommGroup A] [Module Bit A] [AddCommGroup B] [Module Bit B]

theorem at_origin (f : A → B) (x y : A) :
    QuarticJointGuards.delta x (QuarticJointGuards.delta y f) 0 =
      f (x+y)+f x+(f y+f 0) := by
  simp [QuarticJointGuards.delta]

theorem applying (ℓ : B →ₗ[Bit] Bit) (f : A → B) (a x : A) :
    QuarticJointGuards.delta a (ℓ ∘ f) x = ℓ (QuarticJointGuards.delta a f x) := by
  simp [QuarticJointGuards.delta,map_add]

def linearPart (f : A → Bit)
    (vanishes : ∀ x y, QuarticJointGuards.delta x (QuarticJointGuards.delta y f) 0 = 0) : A →ₗ[Bit] Bit where
  toFun x := f x+f 0
  map_add' x y := by
    have h := vanishes x y
    rw [at_origin] at h
    have also : f (x+y)+f 0 + (f x+f y) = 0 := by
      calc
        _ = f (x+y)+f x+(f y+f 0) := by abel
        _ = _ := h
    calc
      _ = f x+f y := add_right_cancel (also.trans (QuarticCayley.double _).symm)
      _ = (f x+f 0)+(f y+f 0) := by
        calc
          _ = (f x+f y)+(f 0+f 0) := by rw [QuarticCayley.double,add_zero]
          _ = _ := by abel
  map_smul' t x := by
    change f (t•x)+f 0 = t • (f x+f 0)
    have bit : ∀ c : Bit, c = 0 ∨ c = 1 := by decide
    rcases bit t with rfl | rfl <;> simp [QuarticCayley.double]

end RSGPaper.QuarticAffineDifference

end

section

set_option autoImplicit false
set_option maxHeartbeats 1450000

namespace RSGPaper.QuarticFirstCorrection

open BooleanMonomials
open CubicGauge
open QuarticDirectionSpan
open QuarticFirstPolar
open QuarticGuardRows

variable {m : ℕ}

def uAxis (i : Fin m) : Position m := (e i,0,0)
def vAxis (i : Fin m) : Position m := (0,e i,0)
def wAxis (m : ℕ) : Position m := (0,0,1)

theorem pairing_add_right (x y z : Position m) : pairing x (y+z) = pairing x y+pairing x z := by
  change dot x.1 (y.1+z.1)+dot x.2.1 (y.2.1+z.2.1)+x.2.2*(y.2.2+z.2.2) = _
  simp only [dot_right_add,mul_add,pairing]
  abel

end RSGPaper.QuarticFirstCorrection

end

section

set_option autoImplicit false
set_option maxHeartbeats 1350000

namespace RSGPaper.QuarticDerivatives

open RSGRecognition
open ColorRemovalRigidity

variable {d r : ℕ}

def secondSpan (f : Profile d r) : Submodule (ZMod 2) (Profile d r) :=
  Submodule.span _ (Set.range fun p : Pos d × Pos d => delta p.1 (delta p.2 f))

end RSGPaper.QuarticDerivatives

end

section

set_option autoImplicit false
set_option maxHeartbeats 1350000

namespace RSGPaper.QuarticNormalizeProfile

open RSGRecognition
open QuarticDerivatives
open BooleanMonomials
open QuarticDirectionSpan
open QuarticFirstPolar

def centered {A B : Type} [Add A] [Add B] (f : A → B) (c x : A) : B := f (x+c)+f c

def polarization {A B : Type} [Add A] [Add B] (f : A → B) (a b : A) : B :=
  f (a+b)+f a+f b

variable {k : ℕ}

def crossMap (M : Cube k →ₗ[Bit] Cube k) : Position k →ₗ[Bit] Position k where
  toFun p := (M p.2.1, M p.1, 0)
  map_add' p q := by
    change (M (p.2.1+q.2.1), M (p.1+q.1), (0 : Bit)) =
      (M p.2.1+M q.2.1,M p.1+M q.1,(0 : Bit)+0)
    rw [map_add,map_add,add_zero]
  map_smul' a p := by
    change (M (a•p.2.1),M (a•p.1),(0 : Bit)) = (a•M p.2.1,a•M p.1,a•(0 : Bit))
    rw [map_smul,map_smul,smul_zero]

theorem profile_polar (M : Cube k →ₗ[Bit] Cube k) (a b : Position k) :
    polarization (profile M) a b = polar a b := by
  change quadratic (a+b)+crossMap M (a+b)+(quadratic a+crossMap M a)+
    (quadratic b+crossMap M b) = _
  rw [map_add]
  calc
    _ = (quadratic (a+b)+quadratic a+quadratic b) +
        (crossMap M a+crossMap M a)+(crossMap M b+crossMap M b) := by abel
    _ = _ := by rw [QuarticCayley.double,QuarticCayley.double,add_zero,add_zero,polar_eq]

end RSGPaper.QuarticNormalizeProfile

end

section

set_option autoImplicit false
set_option maxHeartbeats 1500000

namespace RSGPaper.QuarticFirstGuardRows

open BooleanMonomials
open CubicGauge
open QuarticDirectionSpan
open QuarticFirstPolar
open QuarticFirstCorrection

variable {m : ℕ}

inductive Output (m : ℕ) where
  | u (i : Fin m)
  | v (i : Fin m)
  | w

def row (m : ℕ) : Output m → Position m →ₗ[Bit] Bit
  | .u i => (LinearMap.proj i).comp (LinearMap.fst _ _ _)
  | .v i => (LinearMap.proj i).comp ((LinearMap.fst _ _ _).comp (LinearMap.snd _ _ _))
  | .w => (LinearMap.snd _ _ _).comp (LinearMap.snd _ _ _)

def unitDirections (m : ℕ) : Set (Position m) :=
  Set.range uAxis ∪ Set.range vAxis ∪ {wAxis m}

end RSGPaper.QuarticFirstGuardRows

end

section

set_option autoImplicit false
set_option maxHeartbeats 1300000

noncomputable section

namespace RSGPaper.QuarticProductChart

open RSGRecognition

variable {I : Type} [Fintype I]

def addresses (width : I → ℕ) : (Σ i : I, Fin (width i)) ≃ Fin (∑ i, width i) :=
  Fintype.equivOfCardEq (by simp only [Fintype.card_sigma,Fintype.card_fin])

def flatten (width : I → ℕ) : ((i : I) → Pos (width i)) ≃ Pos (∑ i, width i) where
  toFun x j := let k := (addresses width).symm j; x k.1 k.2
  invFun z i j := z (addresses width ⟨i,j⟩)
  left_inv x := by
    funext i j
    change (let k := (addresses width).symm (addresses width ⟨i,j⟩); x k.1 k.2) = _
    rw [Equiv.symm_apply_apply]
  right_inv z := by
    funext j
    exact congrArg z ((addresses width).apply_symm_apply j)

abbrev Vertices (d r : I → ℕ) := (i : I) → Pos (d i) × Lab (r i)

def chart (d r : I → ℕ) : BinaryChart (Vertices d r) where
  d := ∑ i, d i
  r := ∑ i, r i
  coord := {
    toFun := fun x => (flatten d (fun i => (x i).1), flatten r (fun i => (x i).2))
    invFun := fun y i => ((flatten d).symm y.1 i,(flatten r).symm y.2 i)
    left_inv := by
      intro x
      funext i
      change ((flatten d).symm (flatten d (fun i => (x i).1)) i,
        (flatten r).symm (flatten r (fun i => (x i).2)) i) = x i
      rw [Equiv.symm_apply_apply,Equiv.symm_apply_apply]
    right_inv := by
      rintro ⟨a,b⟩
      change (flatten d ((flatten d).symm a),flatten r ((flatten r).symm b)) = (a,b)
      rw [Equiv.apply_symm_apply,Equiv.apply_symm_apply]
  }

end RSGPaper.QuarticProductChart

end

section

set_option autoImplicit false
set_option maxHeartbeats 1100000

namespace RSGPaper.QuarticGraphSteps

open RSGPaper
open RSGRecognition

abbrev Bit := ZMod 2
abbrev Channel := Fin 7
abbrev Factor := (Channel × Bool) ⊕ Bool

abbrev primary (j : Channel) (second : Bool) : Factor := .inl (j,second)
abbrev marker : Factor := .inr false
abbrev parity : Factor := .inr true

abbrev width (d : Channel → ℕ) : Factor → ℕ
  | .inl (j,_) => d j
  | .inr _ => 1

abbrev Positions (d : Channel → ℕ) := (i : Factor) → Pos (width d i)
abbrev Labels (r : Channel → ℕ) := (i : Factor) → Lab (width r i)
abbrev Vertex (d r : Channel → ℕ) := Positions d × Labels r

variable {d r : Channel → ℕ}

/-- The geometry of either primary copy changes only that copy. -/
def primaryGeometry (j : Channel) (second : Bool) (a : Pos (d j)) : Positions d :=
  Pi.single (primary j second) a

/-- A binary geometry changes only its own position. -/
def binaryGeometry (extra : Bool) : Positions d := Pi.single (.inr extra) 1

/-- A clause changes all seven first copies. -/
def clause (a : (j : Channel) → Pos (d j)) : Positions d
  | .inl (j,false) => a j
  | .inl (_,true) => 0
  | .inr _ => 0

/-- A comparison changes both copies of its channel and the marker. -/
def comparison (j : Channel) (a : Pos (d j)) : Positions d :=
  primaryGeometry j false a + primaryGeometry j true a + binaryGeometry false

/-- A guard changes one primary copy and the marker, with a parity adjustment. -/
def guard (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit) (j : Channel)
    (second : Bool) (a : Pos (d j)) : Positions d :=
  primaryGeometry j second a + binaryGeometry false + (high j a) • binaryGeometry true

@[simp] theorem primary_at (j : Channel) (copy : Bool) (a : Pos (d j)) :
    primaryGeometry j copy a (primary j copy) = a := Pi.single_eq_same _ _

theorem primary_away (j : Channel) (copy : Bool) (a : Pos (d j)) (i : Factor)
    (ne : i ≠ primary j copy) : primaryGeometry j copy a i = 0 := Pi.single_eq_of_ne ne _

@[simp] theorem binary_at (extra : Bool) :
    binaryGeometry (d := d) extra (.inr extra) = (1 : Pos 1) := Pi.single_eq_same _ _

theorem binary_away (extra : Bool) (i : Factor) (ne : i ≠ .inr extra) :
    binaryGeometry (d := d) extra i = 0 := Pi.single_eq_of_ne ne _

@[simp] theorem binary_at_primary (extra : Bool) (j : Channel) (copy : Bool) :
    binaryGeometry (d := d) extra (primary j copy) = 0 := binary_away _ _ (by simp)

@[simp] theorem primary_at_extra (j : Channel) (copy : Bool) (a : Pos (d j)) (extra : Bool) :
    primaryGeometry j copy a (.inr extra) = 0 := primary_away _ _ _ _ (by simp)

def character (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit) : Positions d →ₗ[Bit] Bit where
  toFun p := (∑ j, (high j (p (primary j false)) + high j (p (primary j true)))) +
    p marker (0 : Fin 1) + p parity (0 : Fin 1)
  map_add' a b := by
    simp only [Pi.add_apply,map_add]
    have sums : (∑ j, (high j (a (primary j false)) + high j (b (primary j false)) +
        (high j (a (primary j true)) + high j (b (primary j true))))) =
        (∑ j, (high j (a (primary j false)) + high j (a (primary j true)))) +
        (∑ j, (high j (b (primary j false)) + high j (b (primary j true)))) := by
      rw [← Finset.sum_add_distrib]
      exact Finset.sum_congr rfl (fun j _ => by abel)
    rw [sums]
    abel
  map_smul' c a := by
    have binary : ∀ c : Bit, c = 0 ∨ c = 1 := by decide
    rcases binary c with rfl | rfl <;> simp [map_zero]

theorem character_primary (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit)
    (j : Channel) (second : Bool) (a : Pos (d j)) :
    character high (primaryGeometry j second a) = high j a := by
  change (∑ k, (high k (primaryGeometry j second a (primary k false)) +
    high k (primaryGeometry j second a (primary k true)))) +
    primaryGeometry j second a marker (0 : Fin 1) +
    primaryGeometry j second a parity (0 : Fin 1) = _
  unfold primaryGeometry
  have marker_ne : marker ≠ primary j second := by simp [marker,primary]
  have parity_ne : parity ≠ primary j second := by simp [parity,primary]
  rw [Pi.single_eq_of_ne marker_ne,Pi.single_eq_of_ne parity_ne]
  simp only [Pi.zero_apply,add_zero]
  rw [Finset.sum_eq_single j]
  · cases second <;> simp [primary,Pi.single_eq_of_ne]
  · intro k _ ne
    have different (copy : Bool) : primary k copy ≠ primary j second := by
      intro eq
      exact ne (congrArg Prod.fst (Sum.inl.inj eq))
    rw [Pi.single_eq_of_ne (different false),Pi.single_eq_of_ne (different true)]
    simp only [map_zero,add_zero]
  · simp

theorem character_binary (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit) (extra : Bool) :
    character high (binaryGeometry extra) = 1 := by
  have different (j : Channel) (copy : Bool) : primary j copy ≠ (.inr extra : Factor) := by
    simp [primary]
  have zeros (j : Channel) (copy : Bool) : binaryGeometry (d := d) extra (primary j copy) = 0 :=
    Pi.single_eq_of_ne (different j copy) _
  change (∑ j, (high j (binaryGeometry extra (primary j false)) +
    high j (binaryGeometry extra (primary j true)))) +
    binaryGeometry (d := d) extra marker (0 : Fin 1) +
    binaryGeometry (d := d) extra parity (0 : Fin 1) = 1
  simp only [zeros,map_zero,add_zero,Finset.sum_const_zero,zero_add]
  cases extra <;> simp [binaryGeometry,marker,parity,Pi.single_eq_of_ne]

theorem character_clause (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit)
    (a : (j : Channel) → Pos (d j)) (high_one : ∀ j, high j (a j) = 1) :
    character high (clause a) = 1 := by
  change (∑ j, (high j (a j) + high j 0)) + (0 : Bit) + 0 = 1
  simp only [map_zero,high_one,add_zero,Finset.sum_const,Finset.card_univ,Fintype.card_fin]
  decide

theorem character_comparison (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit)
    (j : Channel) (a : Pos (d j)) : character high (comparison j a) = 1 := by
  simp only [comparison,map_add,character_primary,character_binary,QuarticCayley.double,zero_add]

theorem character_guard (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit)
    (j : Channel) (second : Bool) (a : Pos (d j)) : character high (guard high j second a) = 1 := by
  simp only [guard,map_add,character_primary,character_binary,map_smul,smul_eq_mul,mul_one]
  rw [add_right_comm,QuarticCayley.double,zero_add]

end RSGPaper.QuarticGraphSteps

end

section

set_option autoImplicit false
set_option maxHeartbeats 1200000

namespace RSGPaper.QuarticGraphColors

open RSGPaper
open RSGRecognition
open QuarticGraphSteps

variable {d r : Channel → ℕ}

/-- An edge color records its position step and the selected label rows. -/
inductive Step (d : Channel → ℕ) where
  | primary (channel : Channel) (second : Bool) (a : Pos (d channel))
  | binary (extra : Bool)
  | clause (a : (j : Channel) → Pos (d j))
  | comparison (channel : Channel) (a : Pos (d channel))
  | guard (channel : Channel) (second : Bool) (a : Pos (d channel))

structure Rules (d r : Channel → ℕ) where
  high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit
  geometry : (j : Channel) → Set (Pos (d j))
  geometry_high : ∀ j a, a ∈ geometry j → high j a = 1
  clauses : Set ((j : Channel) → Pos (d j))
  clauses_high : ∀ a ∈ clauses, ∀ j, high j (a j) = 1
  comparisonRows : (j : Channel) → Pos (d j) → List (Lab (r j) →ₗ[Bit] Bit)
  guardRows : (j : Channel) → Bool → Pos (d j) → List ((Lab (r j) →ₗ[Bit] Bit) × Bit)

def position (R : Rules d r) : Step d → Positions d
  | .primary j copy a => primaryGeometry j copy a
  | .binary extra => binaryGeometry extra
  | .clause a => clause a
  | .comparison j a => comparison j a
  | .guard j copy a => guard R.high j copy a

def Valid (R : Rules d r) : Step d → Prop
  | .primary j _ a => a ∈ R.geometry j
  | .binary _ => True
  | .clause a => a ∈ R.clauses
  | .comparison _ a => a ≠ 0
  | .guard _ _ a => a ≠ 0

def rows (R : Rules d r) : Step d → Labels r → List Bit
  | .primary _ _ _, _ => []
  | .binary _, _ => []
  | .clause _, _ => []
  | .comparison j a, z => (R.comparisonRows j a).map fun ℓ =>
      ℓ (z (primary j false) + z (primary j true))
  | .guard j copy a, z => (R.guardRows j copy a).map fun row =>
      row.1 (z (primary j copy)) + row.2 * z marker (0 : Fin 1)

def Supported (R : Rules d r) (s : Step d) (z : Labels r) : Prop :=
  ∀ i, position R s i = 0 → z i = 0

theorem step_crosses (R : Rules d r) (s : Step d) (valid : Valid R s) :
    character R.high (position R s) = 1 := by
  cases s with
  | primary j copy a => exact (character_primary R.high j copy a).trans (R.geometry_high j a valid)
  | binary extra => exact character_binary R.high extra
  | clause a => exact character_clause R.high a (R.clauses_high a valid)
  | comparison j a => exact character_comparison R.high j a
  | guard j copy a => exact character_guard R.high j copy a

theorem step_nonzero (R : Rules d r) (s : Step d) (valid : Valid R s) : position R s ≠ 0 := by
  intro zero
  have one := step_crosses R s valid
  rw [zero,map_zero] at one
  exact zero_ne_one one

end RSGPaper.QuarticGraphColors

end

section

set_option autoImplicit false
set_option maxHeartbeats 1700000

namespace RSGPaper.QuarticStepUniqueness

open RSGPaper
open RSGRecognition
open QuarticGraphSteps
open QuarticGraphColors

variable {d r : Channel → ℕ}

def activePrimaries (p : Positions d) : Finset (Channel × Bool) :=
  Finset.univ.filter fun i => p (primary i.1 i.2) ≠ 0

theorem active_primary (j : Channel) (copy : Bool) (a : Pos (d j)) (nz : a ≠ 0) :
    activePrimaries (primaryGeometry j copy a) = {(j,copy)} := by
  ext ⟨k,other⟩
  by_cases eq : (k,other) = (j,copy)
  · obtain ⟨rfl,rfl⟩ := Prod.mk.inj eq
    simp [activePrimaries,nz]
  · have ne : primary k other ≠ primary j copy := fun h => eq (Sum.inl.inj h)
    simp [activePrimaries,primary_away j copy a _ ne,eq]

theorem active_binary (extra : Bool) : activePrimaries (binaryGeometry (d := d) extra) = ∅ := by
  ext ⟨_,_⟩
  simp [activePrimaries]

theorem active_clause (a : (j : Channel) → Pos (d j)) (nz : ∀ j, a j ≠ 0) :
    activePrimaries (clause a) = Finset.univ.image (fun j : Channel => (j,false)) := by
  ext ⟨j,copy⟩
  simp only [activePrimaries,Finset.mem_filter,Finset.mem_univ,true_and]
  cases copy
  · change a j ≠ 0 ↔ (j,false) ∈ Finset.univ.image (fun k : Channel => (k,false))
    simp [nz j]
  · change (0 : Pos (d j)) ≠ 0 ↔ (j,true) ∈ Finset.univ.image (fun k : Channel => (k,false))
    simp

theorem active_comparison (j : Channel) (a : Pos (d j)) (nz : a ≠ 0) :
    activePrimaries (comparison j a) = {(j,false),(j,true)} := by
  ext ⟨k,copy⟩
  by_cases eq : k = j
  · subst k
    cases copy <;> simp [activePrimaries,comparison,Pi.add_apply,primary_away,nz]
  · cases copy <;> simp [activePrimaries,comparison,Pi.add_apply,primary_away,eq]

theorem active_guard (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit) (j : Channel)
    (copy : Bool) (a : Pos (d j)) (nz : a ≠ 0) :
    activePrimaries (guard high j copy a) = {(j,copy)} := by
  rw [← active_primary j copy a nz]
  ext ⟨k,other⟩
  simp [activePrimaries,QuarticGraphSteps.guard,Pi.add_apply,Pi.smul_apply]

theorem clause_primary_count (a : (j : Channel) → Pos (d j)) (nz : ∀ j, a j ≠ 0) :
    (activePrimaries (clause a)).card = 7 := by
  rw [active_clause a nz,Finset.card_image_of_injective _ (fun _ _ h => congrArg Prod.fst h)]
  simp

theorem guards_marker (high : (j : Channel) → Pos (d j) →ₗ[Bit] Bit) (j : Channel)
    (copy : Bool) (a : Pos (d j)) : guard high j copy a marker = (1 : Pos 1) := by
  simp [QuarticGraphSteps.guard,Pi.add_apply,Pi.smul_apply,binary_away (d := d) true marker (by decide)]

theorem high_nonzero {j : Channel} (high : Pos (d j) →ₗ[Bit] Bit) {a : Pos (d j)}
    (one : high a = 1) : a ≠ 0 := by
  intro zero
  rw [zero,map_zero] at one
  exact zero_ne_one one

def constructorOf (p : Positions d) : ℕ :=
  let n := (activePrimaries p).card
  if n = 0 then 0 else if n = 7 then 1 else if n = 2 then 2 else if p marker = 0 then 3 else 4

def Step.constructor : Step d → ℕ
  | .binary _ => 0
  | .clause _ => 1
  | .comparison _ _ => 2
  | .primary _ _ _ => 3
  | .guard _ _ _ => 4

theorem constructor_read (R : Rules d r) (s : Step d) (valid : Valid R s) :
    constructorOf (position R s) = Step.constructor s := by
  cases s with
  | primary j copy a =>
    have nz := high_nonzero (R.high j) (R.geometry_high j a valid)
    simp [constructorOf,position,Step.constructor,active_primary j copy a nz]
  | binary extra => simp [constructorOf,position,Step.constructor,active_binary]
  | clause a =>
    have nz (j : Channel) := high_nonzero (R.high j) (R.clauses_high a valid j)
    simp [constructorOf,position,Step.constructor,clause_primary_count a nz]
  | comparison j a =>
    have nz : a ≠ 0 := valid
    simp [constructorOf,position,Step.constructor,active_comparison j a nz]
  | guard j copy a =>
    have nz : a ≠ 0 := valid
    simp [constructorOf,position,Step.constructor,active_guard R.high j copy a nz,guards_marker]

theorem position_injective (R : Rules d r) (s t : Step d) (validS : Valid R s) (validT : Valid R t)
    (same : position R s = position R t) : s = t := by
  have kind := (constructor_read R s validS).symm.trans
    ((congrArg constructorOf same).trans (constructor_read R t validT))
  have active := congrArg activePrimaries same
  cases s <;> cases t <;> try { simp [Step.constructor] at kind }
  case primary.primary j copy a k other b =>
    change primaryGeometry j copy a = primaryGeometry k other b at same
    change activePrimaries (primaryGeometry j copy a) = activePrimaries (primaryGeometry k other b) at active
    rw [active_primary j copy a (high_nonzero (R.high j) (R.geometry_high j a validS)),
      active_primary k other b (high_nonzero (R.high k) (R.geometry_high k b validT))] at active
    obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Finset.singleton_injective active)
    have eq := congrFun same (primary j copy)
    simp only [primary_at] at eq
    rw [eq]
  case binary.binary extra other =>
    change binaryGeometry (d := d) extra = binaryGeometry (d := d) other at same
    cases extra <;> cases other <;> try rfl
    · have read := congrFun same marker
      simp [binary_away (d := d) true marker (by decide)] at read
    · have read := congrFun same marker
      simp [binary_away (d := d) true marker (by decide)] at read
  case clause.clause a b =>
    have eq : a = b := funext fun j => congrFun same (primary j false)
    rw [eq]
  case comparison.comparison j a k b =>
    change comparison j a = comparison k b at same
    change activePrimaries (comparison j a) = activePrimaries (comparison k b) at active
    rw [active_comparison j a validS,active_comparison k b validT] at active
    have mem : (j,false) ∈ ({(k,false),(k,true)} : Finset (Channel × Bool)) := by
      rw [← active]
      simp
    have eq : j = k := by simpa using mem
    subst k
    have read := congrFun same (primary j false)
    simp [comparison,Pi.add_apply,primary_away] at read
    rw [read]
  case guard.guard j copy a k other b =>
    change guard R.high j copy a = guard R.high k other b at same
    change activePrimaries (guard R.high j copy a) = activePrimaries (guard R.high k other b) at active
    rw [active_guard R.high j copy a validS,active_guard R.high k other b validT] at active
    obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Finset.singleton_injective active)
    have eq := congrFun same (primary j copy)
    simp [QuarticGraphSteps.guard,Pi.add_apply,Pi.smul_apply] at eq
    rw [eq]

end RSGPaper.QuarticStepUniqueness

end

section

set_option autoImplicit false
set_option maxHeartbeats 1300000

noncomputable section

namespace RSGPaper.QuarticPalette

open QuarticGraphSteps
open QuarticGraphColors
open QuarticStepUniqueness
open ColorRemovalGraph
open ColorRemovalAutomorphisms

variable {d r : Channel → ℕ}

abbrev Key (d : Channel → ℕ) := Positions d × List Bit

def Matches (R : Rules d r) (w : Vertex d r) (s : Step d) : Prop :=
  Valid R s ∧ position R s = w.1 ∧ Supported R s w.2

open Classical in
def rawColor (R : Rules d r) (w : Vertex d r) : Option (Key d) :=
  if h : ∃ s, Matches R w s then some (w.1,rows R h.choose w.2) else none

theorem raw_at (R : Rules d r) (w : Vertex d r) (s : Step d) (fits : Matches R w s) :
    rawColor R w = some (w.1,rows R s w.2) := by
  have available : ∃ t, Matches R w t := ⟨s,fits⟩
  have equal := position_injective R available.choose s available.choose_spec.1 fits.1
    (available.choose_spec.2.1.trans fits.2.1.symm)
  rw [rawColor,dif_pos available,equal]

theorem raw_exists (R : Rules d r) (w : Vertex d r) :
    rawColor R w ≠ none ↔ ∃ s, Matches R w s := by
  constructor
  · intro h
    by_contra missing
    exact h (by rw [rawColor,dif_neg missing])
  · rintro ⟨s,fits⟩
    rw [raw_at R w s fits]
    exact Option.some_ne_none _

def colors (R : Rules d r) : Finset (Option (Key d)) :=
  (Finset.univ.image (rawColor R)).erase none

def colorIndex (R : Rules d r) (w : Vertex d r) (nonempty : rawColor R w ≠ none) : ↥(colors R) :=
  ⟨rawColor R w, Finset.mem_erase.mpr ⟨nonempty,Finset.mem_image.mpr ⟨w,Finset.mem_univ _,rfl⟩⟩⟩

def classify (R : Rules d r) (w : Vertex d r) : Option (Fin (Fintype.card ↥(colors R))) :=
  if nonempty : rawColor R w ≠ none then some (Fintype.equivFin _ (colorIndex R w nonempty))
  else none

theorem classify_zero (R : Rules d r) : classify R 0 = none := by
  have empty : rawColor R (0 : Vertex d r) = none := by
    rw [rawColor,dif_neg]
    rintro ⟨s,valid,position_zero,_⟩
    exact step_nonzero R s valid position_zero
  simp [classify,empty]

def palette (R : Rules d r) : Palette (Vertex d r) (Fintype.card ↥(colors R)) :=
  QuarticCayley.palette (classify R) (classify_zero R)

end RSGPaper.QuarticPalette

end

section

set_option autoImplicit false
set_option maxHeartbeats 1500000

noncomputable section

namespace RSGPaper.QuarticPaletteGeometry

open RSGPaper
open RSGRecognition
open QuarticGraphSteps
open QuarticGraphColors
open QuarticPalette
open ColorRemovalGraph
open ColorRemovalAutomorphisms
open ColorRemovalAction
open QuarticStepUniqueness

variable {d r : Channel → ℕ}

abbrev Coordinates (d r : Channel → ℕ) := (i : Factor) → Pos (width d i) × Lab (width r i)

def assemble : Coordinates d r ≃ Vertex d r where
  toFun x := (fun i => (x i).1,fun i => (x i).2)
  invFun x := fun i => (x.1 i,x.2 i)
  left_inv x := funext fun i => Prod.eta _
  right_inv x := Prod.ext rfl rfl

end RSGPaper.QuarticPaletteGeometry

end

section

set_option autoImplicit false
set_option maxHeartbeats 1500000

noncomputable section

namespace RSGPaper.QuarticLabelAction

open RSGPaper
open RSGRecognition
open QuarticGraphSteps
open QuarticGraphColors
open QuarticPalette
open QuarticPaletteGeometry
open ColorRemovalAction

variable {d r : Channel → ℕ}

variable (R : Rules d r) (g : Equiv.Perm (Vertex d r)) (keeps : g ∈ colored (palette R))
variable (spans : ∀ j, Submodule.span Bit (R.geometry j) = ⊤)
variable (nonempty : ∀ j, (R.geometry j).Nonempty)

def comparisonForms (j : Channel) : Set (Lab (r j) →ₗ[Bit] Bit) :=
  {ℓ | ∃ a : Pos (d j), a ≠ 0 ∧ ℓ ∈ R.comparisonRows j a}

end RSGPaper.QuarticLabelAction

end

section

set_option autoImplicit false
set_option maxHeartbeats 1400000

noncomputable section

namespace RSGPaper.QuarticColoredChart

open RSGPaper
open RSGRecognition
open QuarticGraphSteps
open QuarticGraphColors
open QuarticPalette
open QuarticPaletteGeometry
open QuarticLabelAction
open ColorRemovalAction

variable {d r : Channel → ℕ}

variable (R : Rules d r) (g : Equiv.Perm (Vertex d r)) (keeps : g ∈ colored (palette R))
variable (spans : ∀ j, Submodule.span Bit (R.geometry j) = ⊤)
variable (nonempty : ∀ j, (R.geometry j).Nonempty)

def chart (d r : Channel → ℕ) : BinaryChart (Vertex d r) :=
  let product := QuarticProductChart.chart (width d) (width r)
  ⟨product.d,product.r,assemble.symm.trans product.coord⟩

end RSGPaper.QuarticColoredChart

end

section

set_option autoImplicit false
set_option maxHeartbeats 1700000

noncomputable section

namespace RSGPaper.QuarticPrimaryLayout

open RSGPaper
open RSGRecognition
open QuarticGraphSteps
open QuarticGraphColors
open QuarticLabelAction
open CubicGauge
open QuarticDirectionSpan
open QuarticFirstPolar
open QuarticFirstCorrection
open QuarticFirstGuardRows

abbrev PrimaryLabel (data m : ℕ) := BooleanMonomials.Cube data × Position m × Position m

structure Layout (d r data m : ℕ) where
  position : Pos d ≃ₗ[Bit] Position m
  label : Lab r ≃ₗ[Bit] PrimaryLabel data m
  dataInput : Fin data ↪ Fin m

variable {d r data m : ℕ}

def high (L : Layout d r data m) : Pos d →ₗ[Bit] Bit := (row m .w).comp L.position.toLinearMap

def geometrySteps (L : Layout d r data m) : Set (Pos d) := L.position ⁻¹' geometry

theorem step_high (L : Layout d r data m) (a : Pos d) (allowed : a ∈ geometrySteps L) : high L a = 1 :=
  allowed.1

def pairingRow (a : Position m) : Position m →ₗ[Bit] Bit where
  toFun := pairing a
  map_add' := pairing_add_right a
  map_smul' c x := by
    have bit : ∀ b : Bit, b = 0 ∨ b = 1 := by decide
    rcases bit c with rfl | rfl <;> simp [pairing,dot]

def q₁ (data m : ℕ) : PrimaryLabel data m →ₗ[Bit] Position m :=
  (LinearMap.fst _ _ _).comp (LinearMap.snd _ _ _)

def q₂ (data m : ℕ) : PrimaryLabel data m →ₗ[Bit] Position m :=
  (LinearMap.snd _ _ _).comp (LinearMap.snd _ _ _)

def dataRow (L : Layout d r data m) (i : Fin data) : Lab r →ₗ[Bit] Bit :=
  ((LinearMap.proj i).comp (LinearMap.fst _ _ _)).comp L.label.toLinearMap

def quadraticRow (L : Layout d r data m) (a : Position m) (which : Bool) : Lab r →ₗ[Bit] Bit :=
  ((pairingRow a).comp (if which then q₂ data m else q₁ data m)).comp L.label.toLinearMap

/-- Each comparison reads the two quadratic rows and the data row of a selected unit input. -/
def comparisonRows (L : Layout d r data m) (a : Pos d) : List (Lab r →ₗ[Bit] Bit) :=
  [quadraticRow L (L.position a) false,quadraticRow L (L.position a) true] ++
  (List.finRange data).filterMap (fun i => if L.position a = uAxis (L.dataInput i) then
    some (dataRow L i) else none)

section Channels

variable {D R T M : Channel → ℕ}

/-- The product rules with the actual dot-one geometry and comparison rows in each channel. -/
def rules (layout : (j : Channel) → Layout (D j) (R j) (T j) (M j))
    (clauses : Set ((j : Channel) → Pos (D j)))
    (clauseHigh : ∀ a ∈ clauses, ∀ j, high (layout j) (a j) = 1)
    (guards : (j : Channel) → Bool → Pos (D j) → List ((Lab (R j) →ₗ[Bit] Bit) × Bit)) : Rules D R where
  high j := high (layout j)
  geometry j := geometrySteps (layout j)
  geometry_high j := step_high (layout j)
  clauses := clauses
  clauses_high := clauseHigh
  comparisonRows j := comparisonRows (layout j)
  guardRows := guards

end Channels

end RSGPaper.QuarticPrimaryLayout

end

section

set_option autoImplicit false
set_option maxHeartbeats 1400000

namespace RSGPaper.QuarticChannelLayout

open RSGRecognition
open BooleanMonomials
open QuarticDirectionSpan
open QuarticPrimaryLayout

abbrev Group := Fin 4
abbrev Pair := {p : Group × Group // p.1 < p.2}
abbrev Slot (side : ℕ) := Group → Fin side

/-- Core coordinates, selectors, and the two auxiliary field copies of each slice. -/
abbrev DataIndex (side : ℕ) := (Group × Fin (side+1)) ⊕ Pair ⊕ (Pair × Bool × Fin (side+1))

def dataGroup {side : ℕ} : DataIndex side → Group
  | .inl (group,_) => group
  | .inr (.inl p) => p.val.1
  | .inr (.inr (p,_,_)) => p.val.2

def realCoord {side : ℕ} (group : Group) (coord : Fin side) : DataIndex side :=
  .inl (group,coord.castSucc)

def tagCoord (side : ℕ) (group : Group) : DataIndex side := .inl (group,Fin.last side)

def selector {side : ℕ} (p : Pair) : DataIndex side := .inr (.inl p)

def auxiliary {side : ℕ} (p : Pair) (copy : Bool) (j : Fin (side+1)) : DataIndex side :=
  .inr (.inr (p,copy,j))

def dataWidth (side : ℕ) : ℕ := 16*(side+1)+6

def polarityTags (side : ℕ) : Finset (DataIndex side) :=
  ((Finset.univ : Finset Group).filter fun g => g.val < 3).image (tagCoord side)

def literalSupport {side : ℕ} (slot : Slot side) (negative : Bool) : Finset (DataIndex side) :=
  (Finset.univ.image fun g => realCoord g (slot g)) ∪ if negative then polarityTags side else ∅

def splitCube (n m : ℕ) : Cube (n+m) ≃ₗ[Bit] Cube n × Cube m where
  toFun x := (fun i => x (i.castAdd m),fun j => x (j.natAdd n))
  invFun x := Fin.addCases x.1 x.2
  left_inv x := by
    funext i
    refine Fin.addCases ?_ ?_ i <;> intro j <;> simp
  right_inv x := by
    apply Prod.ext <;> funext i <;> simp
  map_add' _ _ := rfl
  map_smul' _ _ := rfl

def oneCube : Cube 1 ≃ₗ[Bit] Bit where
  toFun x := x 0
  invFun x := fun _ => x
  left_inv x := by
    funext i
    have eq : i = 0 := Subsingleton.elim _ _
    rw [eq]
  right_inv _ := rfl
  map_add' _ _ := rfl
  map_smul' _ _ := rfl

def positionWidth (m : ℕ) : ℕ := m+(m+1)

def positionEquiv (m : ℕ) : Cube (positionWidth m) ≃ₗ[Bit] Position m :=
  (splitCube m (m+1)).trans ((LinearEquiv.refl Bit (Cube m)).prodCongr
    ((splitCube m 1).trans ((LinearEquiv.refl Bit (Cube m)).prodCongr oneCube)))

def labelWidth (data m : ℕ) : ℕ := data+(positionWidth m+positionWidth m)

def labelEquiv (data m : ℕ) : Cube (labelWidth data m) ≃ₗ[Bit] PrimaryLabel data m :=
  (splitCube data (positionWidth m+positionWidth m)).trans ((LinearEquiv.refl Bit (Cube data)).prodCongr
    ((splitCube (positionWidth m) (positionWidth m)).trans ((positionEquiv m).prodCongr (positionEquiv m))))

abbrev fieldWidth (data : ℕ) : ℕ := data+(data+3)

abbrev nativeWidth (data : ℕ) : ℕ := fieldWidth data + (fieldWidth data + fieldWidth data)

abbrev firstWidth (side : ℕ) : ℕ := nativeWidth (dataWidth side)

def layout (side : ℕ) : Layout (positionWidth (firstWidth side))
    (labelWidth (dataWidth side) (firstWidth side)) (dataWidth side) (firstWidth side) where
  position := positionEquiv _
  label := labelEquiv _ _
  dataInput := ⟨fun i => ⟨i.val,i.isLt.trans_le (by unfold firstWidth nativeWidth fieldWidth; omega)⟩,
    fun _ _ eq => Fin.ext (congrArg (fun j : Fin (firstWidth side) => j.val) eq)⟩

end RSGPaper.QuarticChannelLayout

end

section

set_option autoImplicit false

namespace RSGPaper.QuarticField

variable {F : Type} [Field F]

def cubicPolar (a b : F) : F := a * b * (a + b)

theorem cubicPolar_is_polar [CharP F 2] (a b : F) :
    (a + b) ^ 3 + a ^ 3 + b ^ 3 = cubicPolar a b := by
  unfold cubicPolar
  have sum : (a + b) ^ 2 = a ^ 2 + b ^ 2 := by
    calc
      _ = a ^ 2 + b ^ 2 + (a * b + a * b) := by ring
      _ = _ := by rw [CharTwo.add_self_eq_zero, add_zero]
  rw [pow_succ, sum, add_mul]
  calc
    _ = a * b * (a + b) + (a ^ 3 + a ^ 3) + (b ^ 3 + b ^ 3) := by ring
    _ = _ := by simp only [CharTwo.add_self_eq_zero, add_zero]

section Trace

variable [Finite F] [Algebra (ZMod 2) F]

local notation "trace" => Algebra.trace (ZMod 2) F

end Trace

end RSGPaper.QuarticField

end

section

set_option autoImplicit false
set_option maxHeartbeats 1450000

namespace RSGPaper.QuarticSecondPolar

open QuarticField

variable {F : Type} [Field F] [CharP F 2] [Algebra (ZMod 2) F]

local notation "K" => ZMod 2

private theorem square_add (a b : F) : (a+b)^2 = a^2+b^2 := by
  calc
    _ = a^2+b^2+(a*b+a*b) := by ring
    _ = _ := by rw [CharTwo.add_self_eq_zero,add_zero]

private theorem expanded (a b : F) : cubicPolar a b = a^2*b+a*b^2 := by
  unfold cubicPolar
  ring

private theorem polar_swap (a b : F) : cubicPolar a b = cubicPolar b a := by
  unfold cubicPolar
  ring

private theorem polar_add (a b c : F) : cubicPolar (a+b) c = cubicPolar a c+cubicPolar b c := by
  rw [expanded,expanded a,expanded b,square_add]
  ring

private theorem scalar_cases (c : K) : c=0 ∨ c=1 := by revert c; decide

def fieldPolar : F →ₗ[K] F →ₗ[K] F where
  toFun a := {
    toFun := cubicPolar a
    map_add' := by
      intro b c
      rw [polar_swap a,polar_add,polar_swap b a,polar_swap c a]
    map_smul' := by
      intro c b
      rcases scalar_cases c with rfl | rfl <;> simp [cubicPolar]
  }
  map_add' a b := by
    apply DFunLike.ext
    intro c
    exact polar_add a b c
  map_smul' c a := by
    apply DFunLike.ext
    intro b
    rcases scalar_cases c with rfl | rfl <;> simp [cubicPolar]

def squarefreePart (linear : F →ₗ[K] F) (x : F) : F := x^3 + linear x

theorem squarefree_polar (linear : F →ₗ[K] F) (a b : F) :
    squarefreePart linear (a+b) + squarefreePart linear a + squarefreePart linear b =
      fieldPolar a b := by
  change ((a+b)^3+linear (a+b)) + (a^3+linear a) + (b^3+linear b) = cubicPolar a b
  rw [map_add,← cubicPolar_is_polar]
  calc
    _ = (a+b)^3+a^3+b^3+(linear a+linear a)+(linear b+linear b) := by abel
    _ = _ := by rw [CharTwo.add_self_eq_zero,CharTwo.add_self_eq_zero,add_zero,add_zero]

abbrev Dual (E : Type) [Field E] [Algebra K E] := Module.Dual K E

abbrev Position (E : Type) [Field E] [Algebra K E] := E × Dual E × E

abbrev Gradient (E : Type) [Field E] [Algebra K E] := Dual E × E × E

def secondProfile (linear : F →ₗ[K] F) (x : Position F) : Gradient F :=
  (x.2.1.comp (fieldPolar x.1),squarefreePart linear x.1 + x.2.2,0)

def secondPolar (a b : Position F) : Gradient F :=
  (a.2.1.comp (fieldPolar b.1) + b.2.1.comp (fieldPolar a.1),fieldPolar a.1 b.1,0)

theorem second_polar_correct (linear : F →ₗ[K] F) (a b : Position F) :
    secondProfile linear (a+b)+secondProfile linear a+secondProfile linear b = secondPolar a b := by
  rcases a with ⟨x,f,n⟩
  rcases b with ⟨y,g,m⟩
  apply Prod.ext
  · apply DFunLike.ext
    intro z
    change (f+g) (fieldPolar (x+y) z)+f (fieldPolar x z)+g (fieldPolar y z) =
      f (fieldPolar y z)+g (fieldPolar x z)
    simp only [map_add,LinearMap.add_apply]
    calc
      _ = f (fieldPolar y z)+g (fieldPolar x z)+
        (f (fieldPolar x z)+f (fieldPolar x z))+(g (fieldPolar y z)+g (fieldPolar y z)) := by abel
      _ = _ := by simp only [CharTwo.add_self_eq_zero,add_zero]
  · apply Prod.ext
    · change (squarefreePart linear (x+y)+(n+m))+(squarefreePart linear x+n)+
        (squarefreePart linear y+m) = fieldPolar x y
      calc
        _ = squarefreePart linear (x+y)+squarefreePart linear x+squarefreePart linear y+(n+n)+(m+m) := by abel
        _ = _ := by rw [CharTwo.add_self_eq_zero,CharTwo.add_self_eq_zero,add_zero,add_zero,squarefree_polar]
    · change (0 : F)+0+0 = 0
      simp

end RSGPaper.QuarticSecondPolar

end
Source
Sirawit Pongnakintr, Riemannian Symmetric Graphs, Hexagon v2 preprint, https://hexagonmath.org/2611.01261v2, Theorem 5.2 and Appendix A.5

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