Canonical postfix encoding of Boolean formulas #
This module exposes the machine-facing input format for the uniform Barrington generator. Formula nodes become a postfix stream of six three-bit token kinds; variable tokens carry a terminated-unary index, and a terminated-unary token count frames the complete stream.
The stack decoder is iterative, exact decoding is a left inverse, canonical serialization is injective, and the code-length equation records every bit.
Main results #
FormulaCode.run?_tokens-- postfix execution reconstructs a formula on any stack.FormulaCode.decode?_encode-- whole-formula round trip.FormulaCode.encode_injective-- canonical codes are unambiguous.FormulaCode.length_encode-- exact serialized length.
The declared token cost is its exact encoded length.
Running a formula's postfix tokens pushes exactly that formula.
Building from a formula's postfix stream recovers the formula.
The postfix stream has one token per formula node.
Fixed-count token decoding consumes exactly the supplied encoded stream.
Prefix decoding preserves a caller-supplied suffix.
Exact decoding is a left inverse of canonical serialization.
Canonical formula serialization is injective.
Exact formula-code length: one framed token count followed by every token.