Documentation

CslibFrontier.Computability.Catalytic.VertexEquality

Constant-frame two-stage catalytic vertex equality #

In CslibFrontier.Computability.Catalytic.Comparison, eqTest compares two ℓ-digit vectors over ZMod (2 ^ k) in eight single-endpoint visits while restoring a borrowed register and accumulator, provided the caller retains the initial k-bit accumulator across the forward call (or starts it at zero). When n-bit identifiers (n = O(B)) are chunked into q₁ ≈ log₂ B-bit digits, that accumulator has k₁ = Θ(log B) bits; keeping k₁ clean local bits in every suspended recursive frame is too large at constant slack d = O(1).

In Lemma 9.9 and Lemma 11.9 of [OAI26e], short log₂ B-bit keys are instead compared with only constant local frame data across four single-endpoint excursions by toggling a shared B-bit table (Cslib.Catalytic.keyTest over ZMod 2). Any excursion that returns to the caller and restores the shared catalytic memory, with return value independent of the incoming catalytic contents, composes across repeated and nested visits.

This module combines two deterministic sum-of-squares stages (addSqDist) with keyTest into an exact, deterministic, salt-free 64-excursion equality procedure for n-bit natural identifiers:

  1. Stage 1 (4 visits per signed call). Split x, y < 2 ^ n into ℓ₁ = ⌈n / q₁⌉ chunks of q₁ = max 1 ⌊log₂ B⌋ bits (natChunkVec). addSqDist (±1) shifts a shared k₁-bit accumulator z₁ over ZMod (2 ^ k₁) (k₁ = 2 · q₁ + ⌊log₂ ℓ₁⌋ + 1) by ± ∑ᵢ (xᵢ - yᵢ)² while restoring its borrowed ℓ₁-word register. Because ℓ₁ · (2 ^ q₁ - 1)² < 2 ^ k₁, the shifted value z₁' equals z₁ iff x = y.
  2. Stage 2 (16 visits per signed call). Alternate Stage 1 (+1) and Stage 1 (-1) four times so z₁ alternates z₁, z₁', z₁, z₁' without storing z₁ locally. Feed those four k₁-bit values, split into ℓ₂ = ⌈k₁ / q₂⌉ chunks of q₂ = max 1 ⌊q₁ / 2⌋ bits, into an inner addSqDist (±1) over ZMod (2 ^ k₂). When n ≤ C_N · B, ℓ₂ ≤ ⌊log₂ (C_N + 1)⌋ + 11 is bounded by a constant independent of B, so k₂ ≤ 2 · q₂ + O(1) ≤ log₂ B + O(1) and 2 ^ k₂ = O(B).
  3. Stage 3 (64 visits total). Alternate Stage 2 (+1) and Stage 2 (-1) four times so the inner accumulator alternates z₂, z₂', z₂, z₂', and apply keyTest 1 on a shared table W : ZMod (2 ^ k₂) → ZMod 2, adding 1 into a single local ZMod 2 bit iff x = y and restoring all three catalytic components (T₁, T₂, W).

Across all 64 excursions the caller retains only the phase in Fin 64 and one result bit in ZMod 2 (7 local bits total, card_vertexLocalFrame), while the shared restored catalytic state VertexCatState B n occupies vertexCatBits B n ≤ vertexCatLinearConst C_N * (B + 1) bits whenever n ≤ C_N * B (card_vertexCatState, vertexCatBits_le).

Like Catalytic.Comparison, this module formalizes the stepwise single-endpoint excursion contract, nested-excursion restoration invariance, and exact state-cardinality bit budgets; it is not a native Turing-machine space certificate.

Main definitions #

Main results #

References #

Stepwise single-endpoint excursion procedures #

structure Cslib.Catalytic.ExcursionProc (m : ℕ) (α : Type u_1) (S : Type u_2) :
Type (max u_1 u_2)

A deterministic m-visit single-endpoint comparison procedure on values of type α with state S. At phase p : Fin m, side p = false visits the left endpoint x and side p = true visits the right endpoint y; step p v s updates the state from the single visited value v alone.

  • side : Fin m → Bool

    Endpoint selector at phase p: false visits x, true visits y.

  • step : Fin m → α → S → S

    State update at phase p given the visited endpoint value.

def Cslib.Catalytic.ExcursionProc.run {m : ℕ} {α : Type u_1} {S : Type u_2} (P : ExcursionProc m α S) (x y : α) (s₀ : S) :
S

Direct execution on fixed endpoints x and y across phases 0, …, m - 1.

def Cslib.Catalytic.ExcursionProc.runExcursions {m : ℕ} {α : Type u_1} {Cat : Type u_2} {Loc : Type u_3} (P : ExcursionProc m α (Cat × Loc)) (visit : Bool → Cat → α × Cat) (cat₀ : Cat) (loc₀ : Loc) :
Cat × Loc

Execution through an endpoint-excursion callback visit : Bool → Cat → α × Cat sharing catalytic state Cat while holding only (p : Fin m, st.2 : Loc) in the caller's local frame across each excursion.

theorem Cslib.Catalytic.ExcursionProc.runExcursions_eq_run {m : ℕ} {α : Type u_1} {Cat : Type u_2} {Loc : Type u_3} (P : ExcursionProc m α (Cat × Loc)) {visit : Bool → Cat → α × Cat} {x y : α} (hvisit : ∀ (b : Bool) (cat : Cat), visit b cat = (bif b then y else x, cat)) (cat₀ : Cat) (loc₀ : Loc) :
P.runExcursions visit cat₀ loc₀ = P.run x y (cat₀, loc₀)

Excursion invariance (Lemma 9.9 nested-excursion contract): if visit false returns x, visit true returns y, and both restore any incoming catalytic state cat (even when visit internally invokes nested restoring procedures on cat), then runExcursions equals run x y.

def Cslib.Catalytic.ExcursionProc.mapState {m : ℕ} {α : Type u_1} {S₁ : Type u_2} {S₂ : Type u_3} (e : S₁ ≃ S₂) (P : ExcursionProc m α S₁) :
ExcursionProc m α S₂

Transport an excursion procedure along an equivalence of states e : S₁ ≃ S₂.

@[simp]
theorem Cslib.Catalytic.ExcursionProc.run_mapState {m : ℕ} {α : Type u_1} {S₁ : Type u_2} {S₂ : Type u_3} (e : S₁ ≃ S₂) (P : ExcursionProc m α S₁) (x y : α) (s : S₂) :
(mapState e P).run x y s = e (P.run x y (e.symm s))
def Cslib.Catalytic.ExcursionProc.liftFst {m : ℕ} {α : Type u_1} {S : Type u_2} (Θ : Type u_3) (P : ExcursionProc m α S) :
ExcursionProc m α (S × Θ)

Lift a procedure on S to S × Θ, acting on the first component and leaving Θ untouched.

@[simp]
theorem Cslib.Catalytic.ExcursionProc.run_liftFst {m : ℕ} {α : Type u_1} {S : Type u_2} {Θ : Type u_3} (P : ExcursionProc m α S) (x y : α) (s : S) (θ : Θ) :
(liftFst Θ P).run x y (s, θ) = (P.run x y s, θ)
def Cslib.Catalytic.ExcursionProc.precomp {n : ℕ} {α : Type u_1} {S : Type u_2} (f : S → S) (P : ExcursionProc (n + 1) α S) :
ExcursionProc (n + 1) α S

Precompose a pure state transformation f : S → S onto phase 0 of a nonempty procedure, adding no extra endpoint visits.

@[simp]
theorem Cslib.Catalytic.ExcursionProc.run_precomp {n : ℕ} {α : Type u_1} {S : Type u_2} (f : S → S) (P : ExcursionProc (n + 1) α S) (x y : α) (s : S) :
(precomp f P).run x y s = P.run x y (f s)
def Cslib.Catalytic.ExcursionProc.append {m₁ m₂ : ℕ} {α : Type u_1} {S : Type u_2} (P : ExcursionProc m₁ α S) (Q : ExcursionProc m₂ α S) :
ExcursionProc (m₁ + m₂) α S

Concatenate an m₁-visit procedure followed by an m₂-visit procedure.

@[simp]
theorem Cslib.Catalytic.ExcursionProc.run_append {m₁ m₂ : ℕ} {α : Type u_1} {S : Type u_2} (P : ExcursionProc m₁ α S) (Q : ExcursionProc m₂ α S) (x y : α) (s : S) :
(P.append Q).run x y s = Q.run x y (P.run x y s)
def Cslib.Catalytic.ExcursionProc.liftAlternating {n : ℕ} {α : Type u_1} {β : Type u_2} {S : Type u_3} {Θ : Type u_4} (P_fwd P_inv : ExcursionProc (n + 1) α S) (π : S → β) (Q : ExcursionProc 4 β Θ) :
ExcursionProc (n + 1 + (n + 1) + (n + 1 + (n + 1))) α (S × Θ)

Lift a 4-visit alternating procedure Q : ExcursionProc 4 β Θ (visiting a, b, a, b) along a forward procedure P_fwd and its inverse P_inv on S, reading a = π s in the unshifted state and b = π (P_fwd.run x y s) in the shifted state across four blocks.

theorem Cslib.Catalytic.ExcursionProc.run_liftAlternating {n : ℕ} {α : Type u_1} {β : Type u_2} {S : Type u_3} {Θ : Type u_4} (P_fwd P_inv : ExcursionProc (n + 1) α S) (π : S → β) (Q : ExcursionProc 4 β Θ) (hside : Q.side = ![false, true, false, true]) {x y : α} {s : S} (hinv : P_inv.run x y (P_fwd.run x y s) = s) (θ : Θ) :
(P_fwd.liftAlternating P_inv π Q).run x y (s, θ) = (s, Q.run (π s) (π (P_fwd.run x y s)) θ)

Four-block forward/inverse lifting: when P_inv undoes P_fwd on (x, y) and Q alternates ![false, true, false, true], liftAlternating restores s and executes Q on the unshifted readout π s and shifted readout π (P_fwd.run x y s).

addSqDist and keyTest as 4-visit excursion procedures #

def Cslib.Catalytic.sqDistProc {α : Type u_1} {R : Type u_2} {ι : Type u_3} [CommRing R] [DecidableEq ι] {ℓ : ℕ} (c : R) (r : ι) (enc : α → Fin ℓ → R) :
ExcursionProc 4 α ((ι → Fin ℓ → R) × R)

Cslib.Catalytic.addSqDist packaged as a 4-visit single-endpoint ExcursionProc, encoding each visited endpoint by enc : α → Fin ℓ → R.

@[simp]
theorem Cslib.Catalytic.run_sqDistProc {α : Type u_1} {R : Type u_2} {ι : Type u_3} [CommRing R] [DecidableEq ι] {ℓ : ℕ} (c : R) (r : ι) (enc : α → Fin ℓ → R) (x y : α) (T : (ι → Fin ℓ → R) × R) :
(sqDistProc c r enc).run x y T = addSqDist c r (enc x) (enc y) T
def Cslib.Catalytic.keyTestProc {α : Type u_1} {κ : Type u_2} {M : Type u_3} [DecidableEq κ] [AddCommGroup M] (c : M) (enc : α → κ) :
ExcursionProc 4 α ((κ → M) × M)

Cslib.Catalytic.keyTest packaged as a 4-visit single-endpoint ExcursionProc.

@[simp]
theorem Cslib.Catalytic.run_keyTestProc {α : Type u_1} {κ : Type u_2} {M : Type u_3} [DecidableEq κ] [AddCommGroup M] (c : M) (enc : α → κ) (x y : α) (V : κ → M) (s : M) :
(keyTestProc c enc).run x y (V, s) = keyTest c (enc x) (enc y) V s

Fixed-length binary-chunk encoding of natural numbers #

def Cslib.Catalytic.natChunkVec (q ℓ x : ℕ) (i : Fin ℓ) :

Extract ℓ base-2 ^ q chunks of a natural number x, least-significant chunk first.

theorem Cslib.Catalytic.natChunkVec_lt (q ℓ x : ℕ) (i : Fin ℓ) :
natChunkVec q ℓ x i < 2 ^ q
theorem Cslib.Catalytic.natChunkVec_eq_iff {q ℓ x y : ℕ} (hx : x < 2 ^ (ℓ * q)) (hy : y < 2 ^ (ℓ * q)) :
natChunkVec q ℓ x = natChunkVec q ℓ y ↔ x = y

Two-stage bit-width parameterization and 64-excursion vertex equality #

Outer chunk bit-width q₁ = max 1 ⌊log₂ B⌋.

Number of outer chunks ℓ₁ = ⌈n / q₁⌉ covering an n-bit identifier.

Bit-width k₁ of the Stage-1 sum-of-squares accumulator over ZMod (2 ^ k₁).

Inner chunk bit-width q₂ = max 1 ⌊q₁ / 2⌋.

Number of inner chunks ℓ₂ = ⌈k₁ / q₂⌉ covering the k₁-bit Stage-1 accumulator.

Bit-width k₂ of the Stage-2 sum-of-squares accumulator (and log₂ of the Stage-3 table).

@[reducible, inline]

Stage-1 catalytic register and accumulator state ((ℓ₁ + 1) · k₁ bits).

@[reducible, inline]

Stage-2 catalytic register and accumulator state ((ℓ₂ + 1) · k₂ bits).

@[reducible, inline]

Stage-3 catalytic ZMod 2 key table (2 ^ k₂ bits).

@[reducible, inline]

Full shared catalytic memory (T₁, T₂, W) restored by vertexEqProc and catalyticVertexEq.

@[reducible, inline]

Caller-local frame retained across each of the 64 excursions: a phase in Fin 64 and one accumulator bit in ZMod 2 (7 bits total, independent of B and n).

Stage-1 4-visit procedure adding c₁ times the outer chunk squared distance to T₁.2.

Stage-2 16-visit procedure lifting the inner chunk squared distance along stageOneSqDistProc and its inverse.

State reassociation separating the shared catalyst VertexCatState B n from the 1-bit local accumulator ZMod 2.

The 64-excursion catalytic vertex-equality procedure. On endpoints x, y < 2 ^ n, it restores any incoming catalytic state cat : VertexCatState B n and adds 1 : ZMod 2 into the local result bit iff x = y.

Boolean catalytic vertex equality via single-endpoint excursions. Initializes the local result bit to 0 : ZMod 2, runs the 64 excursions through visit, and returns the equality decision together with the restored catalytic state.

Exactness and exact restoration #

theorem Cslib.Catalytic.run_vertexEqProc_chunk (B n x y : ℕ) (cat : VertexCatState B n) (s₀ : ZMod 2) :

Unconditional restoration and chunk-equality characterization of vertexEqProc: for all B n x y : ℕ (without any range bound on x or y), vertexEqProc restores cat and adds 1 to s₀ iff x and y agree on their first outerDigits B n base-2 ^ outerChunkBits B chunks.

theorem Cslib.Catalytic.run_vertexEqProc {B n x y : ℕ} (hx : x < 2 ^ n) (hy : y < 2 ^ n) (cat : VertexCatState B n) (s₀ : ZMod 2) :
(vertexEqProc B n).run x y (cat, s₀) = (cat, s₀ + if x = y then 1 else 0)

Direct correctness and restoration of vertexEqProc: for all B n : ℕ, all x, y < 2 ^ n, and any initial catalytic contents cat and local bit s₀ : ZMod 2, vertexEqProc restores cat and adds if x = y then 1 else 0 to s₀.

theorem Cslib.Catalytic.runExcursions_vertexEqProc {B n x y : ℕ} (hx : x < 2 ^ n) (hy : y < 2 ^ n) {visit : Bool → VertexCatState B n → ℕ × VertexCatState B n} (hvisit : ∀ (b : Bool) (cat : VertexCatState B n), visit b cat = (bif b then y else x, cat)) (cat : VertexCatState B n) (s₀ : ZMod 2) :
(vertexEqProc B n).runExcursions visit cat s₀ = (cat, s₀ + if x = y then 1 else 0)

Excursion correctness and restoration of vertexEqProc: under any restoring, catalyst-independent excursion callback visit for x, y < 2 ^ n, runExcursions restores cat and adds if x = y then 1 else 0 to s₀.

theorem Cslib.Catalytic.catalyticVertexEq_eq {B n x y : ℕ} (hx : x < 2 ^ n) (hy : y < 2 ^ n) {visit : Bool → VertexCatState B n → ℕ × VertexCatState B n} (hvisit : ∀ (b : Bool) (cat : VertexCatState B n), visit b cat = (bif b then y else x, cat)) (cat₀ : VertexCatState B n) :
catalyticVertexEq B n visit cat₀ = (decide (x = y), cat₀)

Exactness and restoration of catalyticVertexEq: for all B n : ℕ, all x, y < 2 ^ n, every restoring catalyst-independent callback visit, and arbitrary initial catalytic state cat₀, catalyticVertexEq returns (decide (x = y), cat₀). In particular, it satisfies the same restoring catalyst-independent contract for outer callers.

Explicit local-frame and catalytic bit-budget accounting #

Total bit count of the shared catalytic state VertexCatState B n.

Explicit closed-form linear coefficient bounding vertexCatBits B n by vertexCatLinearConst C_N * (B + 1) whenever n ≤ C_N * B.

Constant local frame (7 bits). The caller's local frame across all 64 excursions has cardinality 2 ^ 7, independent of B and n.

Exact catalytic bit count. The shared catalytic state VertexCatState B n has cardinality 2 ^ vertexCatBits B n.

theorem Cslib.Catalytic.innerDigits_le {B n C_N : ℕ} (hn : n ≤ C_N * B) :
innerDigits B n ≤ Nat.log 2 (C_N + 1) + 11

Constant Stage-2 chunk count. When n ≤ C_N * B, the number of inner chunks innerDigits B n is bounded by Nat.log 2 (C_N + 1) + 11, independently of B.

theorem Cslib.Catalytic.vertexCatBits_le {B n C_N : ℕ} (hn : n ≤ C_N * B) :

O(B) catalytic bit budget. Whenever n ≤ C_N * B, the total number of shared catalytic bits satisfies vertexCatBits B n ≤ vertexCatLinearConst C_N * (B + 1).