Polynomial-time syntax validation for real-arithmetic formula words #
This adapts LeanCanny.ETR.Grammar.recognizeFormula from lean-canny at
970f28a5ecefc1327402ade16c068aa4b1b2c183 to the frontier formula encoding. The strict
formula-token decoder handles framing. The recursive-encoding checker verifies that the
constructor stream describes one tree, and term recognition at modulus one checks the comparison
payloads. Valid words encode formulas in the dimension given by their length.
The total view adapts LeanCanny.ETR.FormulaView at the same revision. It preserves the exact
bits of valid encodings and gives malformed words the semantics of falsity.
Its indexed token reader adapts the constructor and term-word access of
LeanCanny.ETR.FormulaBooleanCircuitSource to the frontier prefix token list.
Subtree spans locate the second operand with the native splitter for framed prefix tokens.
The child-index query returns the operands in their syntactic order.
The indexed gate operation adapts the local wire evaluation of
LeanCanny.ETR.FormulaBooleanCircuitCorrect at the same revision. It reads comparison signs
from a supplied term-word interpretation and connective operands from supplied wire values.
Comparison requests retain the exact term word and the required sign.
The Boolean part of gate evaluation has a polynomial-time certificate given the comparison
answer and access to the operand values.
Check that a raw bit word encodes one formula, including every comparison's term syntax.
A canonical formula encoding passes the syntax validator in any variable dimension.
Validation recognizes exactly the formula encodings, using the input length as a variable dimension large enough to contain every unary variable rank in the word.
Syntax validation runs in polynomial time uniformly in the raw bit word.
The formula view of a malformed word is falsity.
The bit-level normalization computes the exact encoding of the total formula view.
Formula word normalization is uniformly polynomial time.
Re-encoding the total formula view is uniformly polynomial time on raw bit words.
The prefix tokens of the total formula view, retaining the original comparison term words.
The executable token stream agrees with the typed formula view on every input.
Each token of a valid word occupies at least one bit. Malformed words have one falsity token, including for the empty input.
Recover the framed prefix token stream in polynomial time.
Read a prefix token by position. Positions beyond the stream return the falsity token.
Token lookup takes polynomial time in the raw word and binary index.
A serialized subtree starting at the given position is consumed exactly, leaving any following tokens out of the span.
Subtree span takes polynomial time with a binary index and an optional binary result. The index is capped by the number of tokens before converting it to unary for list dropping.
At a serialized subformula, the query returns precisely the starting positions of its immediate operands. A second operand starts just after the first operand's complete token stream.
Child indices are computable in polynomial time from a raw word and a binary index. The result is a framed list of up to two binary child positions.
Frame the raw term word and append one bit indicating strict inequality.
The tuple of the fields of encFormulaComparisonRequest.
The sign that makes the requested comparison true.
Read the comparison request at a binary index of the total formula view. Connectives, falsity and out-of-range positions have no request.
A comparison in the total formula view retains the canonical encoding of a term in the word's dimension.
A comparison request's term payload occupies strictly fewer bits than the original formula word. A malformed word has no comparison requests.
Extract the optional comparison request in polynomial time on the raw word and binary index. The term payload is copied unchanged.
Encoding the typed gate term recovers the executable reader's exact payload.
The typed gate terms have polynomial-time access under the raw formula word and binary
index encoding. This adapts the term access of LeanCanny.ETR.FormulaAtomPolynomials.termSource
to the frontier prefix token view.
The common length budget for gate terms, including the encoded constant zero in unused slots.
Compute the gate-term budget in binary from the raw formula word.
The term word at every gate fits within the common length budget.
The formula word gives a single degree and coefficient norm budget for all of its gate polynomials, including the zero padding at unused slots.
At an in-bounds gate, the residue is present exactly when a comparison term exists and
its polynomial has that residue. Coordinates missing from point are read as zero.
Comparison residue queries take polynomial time in the raw formula word, binary gate index and positive binary modulus, and framed binary coordinates.
For a positive modulus, the executable gate query returns the canonical residue of the indexed term polynomial at the zero-padded coordinates.
The total residue query is polynomial time in the raw formula word, binary gate index and positive binary modulus, and framed list of binary coordinate values.
Testing an indexed comparison is polynomial time in the formula word, binary gate index,
and supplied sign using encSign.
Read the comparison request of a serialized subformula, retaining its exact term word.
The Boolean gate reads its value function only at the two child lookup positions.
Comparison gates use the supplied answer.
Two supplied answers give the same gate value if they agree whenever the gate requests a comparison.
Evaluate the Boolean part of a gate in polynomial time from a raw word, binary position, comparison answer, and a certified reader of values at binary positions.
Evaluate one Boolean gate of the total formula view. Comparison gates ask for the sign
of their encoded term. Connectives read the supplied values at their child indices.
Falsity and positions outside the token stream return false.
Computing the comparison answer from the indexed request recovers the gate's value under the supplied term signs.
A gate at the start of an encoded subformula reads the exact term payload for a comparison, or combines the values at the starts of its immediate operands.