Encodings and instruction counts for uniform matching
DefinitionBackreferenceMatching_AlgorithmsPatterns are encoded as prefix syntax trees, and input words are lists of alphabet symbols. Variable names are numbered by first occurrence. A decision program reads the actual input and must halt with exactly one output bit indicating whether the word matches.
The machine has logarithmic-width words and a finite instruction set. The normalizer must write the complete list of ordinary expressions it produces, preserve the language on every word, and satisfy independent size bounds for the branches and their components.
import Definitions.Def_BackreferenceMatching_Languages
import Definitions.Def_EdgeSublinearMWIS_Main_NativeWordRAM
namespace BackreferenceMatching
abbrev Program := Lax808846.Ram.Program
variable {q : ℕ}
def wordCode (w : Word q) : List ℕ := w.map Fin.val
def regCode : Reg q → List ℕ
| .zero => [0]
| .epsilon => [1]
| .char a => [2, a.val]
| .plus e f => 3 :: (regCode e ++ regCode f)
| .comp e f => 4 :: (regCode e ++ regCode f)
| .star e => 5 :: regCode e
def exprCodeWith (xs : List ℕ) : Expr q → List ℕ
| .zero => [0]
| .eps => [1]
| .letter a => [2, a.val]
| .alt e f => 3 :: (exprCodeWith xs e ++ exprCodeWith xs f)
| .seq e f => 4 :: (exprCodeWith xs e ++ exprCodeWith xs f)
| .star e => 5 :: exprCodeWith xs e
| .capture x e => 6 :: xs.idxOf x :: exprCodeWith xs e
| .read x => [7, xs.idxOf x]
def exprCode (e : Expr q) : List ℕ := exprCodeWith e.variables.eraseDups e
def Branch.code (p : Branch q) : List ℕ :=
regCode p.first ++ regCode p.copy ++ regCode p.middle ++ regCode p.last
def NormalForm.code (u : NormalForm q) : List ℕ :=
regCode u.regular ++ (u.branches.length :: u.branches.flatMap Branch.code)
def regexInput (e : Expr q) (w : Word q) : List ℕ := exprCode e ++ wordCode w
def repetitionInput (x y z : Reg q) (α : ℕ) (w : Word q) : List ℕ :=
List.replicate α 1 ++ [0] ++ regCode x ++ regCode y ++ regCode z ++ wordCode w
def logFactor (n : ℕ) : ℕ := 1 + Nat.log2 (n + 2)
def wordBits (a scale : ℕ) : ℕ := (a + 1) * logFactor scale
def CorrectBit (claim : Prop) (out : List ℕ) : Prop :=
(out = [1] ∧ claim) ∨ (out = [0] ∧ ¬ claim)
def DecidesWithin (p : Program) (a q : ℕ) (input : List ℕ) (claim : Prop)
(budget : ℕ) : Prop :=
∃ t out, Lax808846.Ram.RunsTo (wordBits a (input.length + q + 8)) p input out t ∧
t ≤ budget ∧ CorrectBit claim out
def NormalSize (c s : ℕ) (u : NormalForm q) : Prop :=
u.branches.length ≤ c * s^2 ∧ regSize u.regular ≤ c * s^2 ∧
∀ p ∈ u.branches, regSize p.first ≤ c * s^2 ∧ regSize p.copy ≤ c * s ∧
regSize p.middle ≤ c * s^2 ∧ regSize p.last ≤ c * s
def NormalizesWithin (p : Program) (a c : ℕ) (e : Expr q) : Prop :=
∃ (u : NormalForm q) (t : ℕ),
Lax808846.Ram.RunsTo (wordBits a ((exprCode e).length + q + 8)) p
(exprCode e) u.code t ∧ t ≤ c * e.size^4 ∧ NormalSize c e.size u ∧
∀ w, Matches e w ↔ u.accepts w
end BackreferenceMatchingRead-back
What the Lean code literally says, in plain math · GPT-6
Encoding expressions
For an alphabet of size , a word is encoded by its letter values. Ordinary and extended expressions use prefix tags for empty language, empty word, letter, union, concatenation and star. A letter tag precedes its value and operator tags precede their operands in order. Capture uses , a name index and the body. Read uses and a name index. A name's index in a supplied list is its first zero-based position or the list length if absent. An expression uses its distinct names in first-occurrence order.
Inputs and outputs
Matching input appends the word to the expression code. For regular expressions and exponent , repetition input concatenates ones, one zero, the codes of , and the word. A branch concatenates its first, copy, middle and last regular codes. A normal form concatenates its regular code, its branch count and its branch codes in list order.
Decisions on a word RAM
For natural , put and . Given a finite RAM program , natural-number list , proposition and budget , the decision predicate means halts on at width within instructions, with full output when holds and otherwise. Memory starts at zero and output starts empty. At width , data cells and addresses use bits. Input supports sequential and indexed reads. A fetched halt or exhausted read costs one instruction. Falling outside the program costs zero to terminate.
Normalization
For natural , the size condition bounds the branch count and regular size each by , and every branch's first, copy, middle and last sizes respectively by . To normalize an expression of nodes, the program must halt on its code at width within instructions, outputting exactly a normal form's code. The form must satisfy these bounds and accept precisely the words matched from the all-empty valuation.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.