Documentation

ComplexityTheory.Foundations.FormulaEncoding.Stream

Postfix Boolean-formula streams #

Boolean formulas compile to a flat postfix token stream. A small stack machine reconstructs the tree without a recursive bit-level parser, and the stream has exactly one token for every formula node.

Execute a postfix token stream from an initial formula stack. Evaluation stops with none as soon as a token cannot consume the required operands.

Equations
Instances For

    Reconstruct exactly one formula from a complete token stream. Empty streams, stack underflow, and leftover formulas are all rejected.

    Equations
    Instances For
      theorem ComplexityTheory.BooleanFormulaCode.run?_append (first second : List Token) (stack : List BooleanFormula) :
      run? (first ++ second) stack = (run? first stack).bind (run? second)

      Running concatenated streams is sequential stack execution. This composition law lets structural proofs reason about each formula subtree independently.

      @[simp]
      theorem ComplexityTheory.BooleanFormulaCode.run?_tokens (formula : BooleanFormula) (stack : List BooleanFormula) :
      run? (tokens formula) stack = some (formula :: stack)

      Executing a formula's postfix tokens pushes exactly that formula onto any existing stack. This is the central semantic invariant of the stream format.

      @[simp]

      Building from a formula's canonical token stream recovers that formula.

      @[simp]

      The postfix stream contains exactly one token per formula-tree node. Token count and syntactic formula size therefore coincide.