Binary postfix encodings of finite tree-automaton transition tables
DefinitionBinaryTreeAutomata_PostfixTablesautomatacomputational-complexity
A leaf supplies a state. An internal node carries a finite table whose row is indexed by the right child and whose column is indexed by the left child. Evaluation requires both indices to be valid. The postfix encoding puts both subtrees before that entire table and uses eight three-bit tokens. State numbers are written in unary, with a delimiter.
Definition code
import Mathlib
namespace BinaryTreeAutomata
/-- A binary expression with an explicit finite transition table at each branch.
The outer table index is the right child's state and the inner index is the left child's state. -/
inductive TableTree where
| leaf (state : ℕ)
| branch (left right : TableTree) (table : List (List ℕ))
deriving Repr, DecidableEq
/-- Bottom-up evaluation. A run exists when every accessed table entry is present. -/
inductive TableTree.Evaluates : TableTree → ℕ → Prop where
| leaf (q : ℕ) : Evaluates (.leaf q) q
| branch {l r : TableTree} {i j q : ℕ} {row : List ℕ} {table : List (List ℕ)} :
Evaluates l i → Evaluates r j → table[j]? = some row → row[i]? = some q →
Evaluates (.branch l r table) q
namespace TableTree
inductive Token | leaf | branch | mark | cellEnd | rowEnd | blockEnd | row | cell
deriving DecidableEq, Repr
/-- Every instruction symbol has a fixed three-bit code. -/
def Token.bits : Token → List Bool
| .leaf => [false,false,false]
| .branch => [false,false,true]
| .mark => [false,true,false]
| .cellEnd => [false,true,true]
| .rowEnd => [true,false,false]
| .blockEnd => [true,false,true]
| .row => [true,true,false]
| .cell => [true,true,true]
def cellTokens (q : ℕ) : List Token := .cell :: (List.replicate q .mark ++ [.cellEnd])
def rowTokens (r : List ℕ) : List Token := .row :: (r.flatMap cellTokens ++ [.rowEnd])
/-- Both child expressions precede the transition table. The code lists every table entry. -/
def tokens : TableTree → List Token
| .leaf q => .leaf :: (List.replicate q .mark ++ [.blockEnd])
| .branch l r tab => l.tokens ++ r.tokens ++ (.branch :: (tab.flatMap rowTokens ++ [.blockEnd]))
def encode (t : TableTree) : List Bool := t.tokens.flatMap Token.bits
/-- The stack representation of one state. -/
def stateWord (q : ℕ) : List Bool := List.replicate q true ++ [false]
end TableTree
end BinaryTreeAutomata
Source
Finite bottom-up tree automata on binary terms. Encoding for the auxiliary evaluator of Chakraborty, Ordyniak and Siebertz, arXiv:2610.41974, Theorem 2.8.