Explicit finite-state bottom-up automata on binary terms
DefinitionBinaryTreeAutomata_ExplicitAutomataautomatacomputational-complexity
A finite deterministic automaton has an explicit list covering its states, leaf and binary-operation transitions, and an acceptance test. The transition tables list row-major state indices. The input encoding places both child codes before the full table, followed at the root by one final acceptance lookup.
Definition code
import Mathlib
import Definitions.Def_BinaryTreeAutomata_PostfixTables
namespace BinaryTreeAutomata
/-- Ranked terms with independently labelled leaves and binary operation nodes. -/
inductive Term (Leaf Op : Type) where
| leaf (a : Leaf)
| node (b : Op) (l r : Term Leaf Op)
deriving Repr
def Term.nodes {L B : Type} : Term L B → ℕ
| .leaf _ => 1
| .node _ l r => l.nodes + r.nodes + 1
def Term.mapLeaves {L K B : Type} (f : L → K) : Term L B → Term K B
| .leaf a => .leaf (f a)
| .node b l r => .node b (l.mapLeaves f) (r.mapLeaves f)
/-- A deterministic bottom-up tree automaton and an explicit enumeration of its states. -/
structure Automaton (Leaf Op : Type) where
State : Type
decState : DecidableEq State
states : List State
complete : ∀ q, q ∈ states
atLeaf : Leaf → State
atNode : Op → State → State → State
accept : State → Bool
attribute [instance] Automaton.decState
namespace Automaton
variable {L B : Type}
def eval (A : Automaton L B) : Term L B → A.State
| .leaf a => A.atLeaf a
| .node b l r => A.atNode b (A.eval l) (A.eval r)
def transitionTable (A : Automaton L B) (b : B) : List (List ℕ) :=
A.states.map fun y => A.states.map fun x => A.states.idxOf (A.atNode b x y)
def tables (A : Automaton L B) : Term L B → TableTree
| .leaf a => .leaf (A.states.idxOf (A.atLeaf a))
| .node b l r => .branch (A.tables l) (A.tables r) (A.transitionTable b)
/-- The last unary lookup converts the root state to its acceptance bit. -/
def acceptingTables (A : Automaton L B) (t : Term L B) : TableTree :=
.branch (A.tables t) (.leaf 0) [A.states.map fun x => (A.accept x).toNat]
end Automaton
end BinaryTreeAutomata
Source
Auxiliary constructions for Chakraborty, Ordyniak and Siebertz, Model Checking for Metric Extensions of Monadic Second-Order Logic, arXiv:2610.41974, Theorem 2.8, pp. 16-17.