Literal Atomic Prefix Parser
Abstract
The literal two-letter tree code has an executable recursive parser with exact suffix boundaries, injective code, prefix-free image, and complete decoding.
Source is the existing FreeMagma Bool of finite nonempty ordered binary trees. The true leaf is alpha and the false leaf is beta. A leaf b is encoded as [true,b], while a branch is encoded as false followed by the concatenation of the left and right codes. The parser uses predecessor fuel for both recursive children and passes the actual remainder returned by the left parse to the right parse. Its public fuel is the input length, and decode accepts only an empty final remainder.
Definition 1.1 (Literal Tree Code).
Formalization. D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.code (✓ std3).
Source. Repository-derived.
Commentary.
The two Boolean letters are used directly. Internal nodes begin with false, so the two child codes are parsed without a delimiter or integer encoding.
Definition 1.2 (Fuelled Suffix Parser).
Formalization. D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.parse (✓ std3).
Source. Repository-derived.
Commentary.
Parsing returns either failure or a source tree together with the exact unconsumed suffix. The local recurrence below uses recursion-depth fuel: both child calls receive n, and the right child receives the actual left remainder r. The clauses exhaust the input shapes and recursive outcomes. The public parser derives its fuel from the input length.
Definition 1.3 (Complete Decoder).
Formalization. D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.decode (✓ std3).
Source. Repository-derived.
Commentary.
Here emptyRemainder denotes the mathematical operation defined by the following three cases. Decoding succeeds exactly when the parser consumes the whole input, and then returns the parsed source.
Theorem 1.4 (Exact Parsing and Prefix-Free Coding).
Proof. Machine-checked in Lean as D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.result (✓ std3). ∎
Source. Repository-derived.
Commentary.
The first conjunct is the successful-consumption equivalence for every input, tree, and suffix. Its proof keeps the stronger local induction invariant that any successful fuelled parse consumes exactly one codeword, and the uniform sufficient-fuel invariant that every codeword followed by an arbitrary suffix parses with that suffix unchanged.
The same parser law gives injectivity by applying a local Encoding roundtrip, and gives prefix freedom by parsing one complete codeword in two ways. Full decoding is equivalent to being exactly a codeword; malformed inputs and nonempty suffixes are rejected.
References
- Truth anchor:
D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.code - Truth anchor:
D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.decode - Truth anchor:
D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.parse - Truth anchor:
D5/S3/Arith/FibonacciAtomic/AtomicPrefixParser.result - Dependency: D5/S0/Computability/Coding/PrefixFreeCode
- Dependency: D5/S3/Arith/FibonacciAtomic/GenealogicalFiberTransport