Bimachines #
A Bimachine ([Sch61]; [Eil74]) reads its input in both
directions: a left automaton scans →, a right automaton scans ←, and output i is
output (lState (x.take i)) (x i) (rState (x.drop (i+1))). Word-output bimachines
compute exactly the rational functions ([EM65]; they are the transducers of
[Sch76]'s semi-monomial representations, see [Sak09]); the
letter-to-letter machines here compute the total length-preserving ones.
Main definitions #
Bimachine L R α β: machine with left statesL, right statesR, alphabetsα,βBimachine.run: the computed functionIsBimachineComputable f:fis computed by some finite bimachine
Main theorems #
Bimachine.getElem?_run: outputiisoutput (lState (x.take i)) (x i) (rState (x.drop (i+1)))
Implementation notes #
Only the left state is threaded through the run (Bimachine.runFrom); the recursion
reads each tail's right state on the spot. The class existentials pin state types at
Type 0; the universe-polymorphic isBimachineComputable_iff recovers generality.
The identification of
IsBimachineComputable with the total rational functions preserving the empty word is
classical and not formalized here; ElgotMezei.lean proves the composition half.
[UPSTREAM] candidate: Mathlib.Computability.Bimachine.
A bimachine is a left automaton scanning left to right, a right automaton scanning right to left, and a cell output reading both context states and the current symbol.
- lInit : L
Starting state of the left automaton.
- lStep : L → α → L
Transition of the left automaton, scanning left to right.
- rInit : R
Starting state of the right automaton.
- rStep : R → α → R
Transition of the right automaton, scanning right to left.
- output : L → α → R → List β
The word emitted from the two context states and the current input symbol.
Instances For
B.lStateAfter l pre is the left state reached from l after scanning pre.
Equations
- B.lStateAfter l = List.foldl B.lStep l
Instances For
Left state after scanning a prefix left-to-right from the start state.
Equations
- B.lState = B.lStateAfter B.lInit
Instances For
Letter-to-letter bimachines #
A cell of a general bimachine emits a word, so the run is a concatenation and output positions need not track input positions. A letter-to-letter bimachine emits exactly one symbol per cell ([Sak09] §IV.6); the function it computes is then length-preserving, and the positional description below holds.
A witness that B is letter-to-letter: every cell emits exactly one symbol, named
by cell.
- cell : L → α → R → β
The single symbol emitted at a cell.
Every cell emits exactly that one symbol.
Instances For
B is letter-to-letter when it admits a LetterToLetter witness.
Equations
- B.IsLetterToLetter = Nonempty B.LetterToLetter
Instances For
The run of a letter-to-letter bimachine has the length of its input.
Output coordinate i reads the left state after the length-i prefix and the
right state of the strict suffix.
Output i is cell (lState (x.take i)) (x i) (rState (x.drop (i+1))).
Transport along state equivalences #
Transport a bimachine along equivalences on the two state spaces.
Equations
- One or more equations did not get rendered due to their size.
Instances For
map as an equivalence of bimachines.
Equations
- Bimachine.reindex eL eR = { toFun := Bimachine.map eL eR, invFun := Bimachine.map eL.symm eR.symm, left_inv := ⋯, right_inv := ⋯ }
Instances For
Cells agree exactly when the underlying word-valued outputs do.
Letter-to-letter-ness transports along state reindexing.
Equations
Instances For
Flag bimachines #
The recurring two-sided-trigger shape: each side's automaton is the one-bit "some symbol
on my side satisfies p" flag, so lState/rState compute List.any and the cell sees
exactly the two flags. The conjunctive witness conjBM below is an instance.
The bimachine whose side states are "a symbol satisfying pL/pR occurred on my
side" flags.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A flag bimachine is letter-to-letter, with out as its cell.
Equations
- Bimachine.ofFlags_letterToLetter pL pR out = { cell := out, output_eq := ⋯ }
Instances For
Output i of a flag bimachine sees the input symbol and the two window-any
flags.
Sequential machines as bimachines #
The bimachine view computes the same string function.
The bimachine-computable class #
Computability by a finite bimachine — classically, the total rational functions preserving the empty word.
Equations
- IsBimachineComputable f = ∃ (L : Type) (x : Fintype L) (R : Type) (x : Fintype R) (B : Bimachine L R α β), B.run = f
Instances For
f is bimachine-computable if and only if it is computed by a finite bimachine
with state types in any universes.
Computability by a finite letter-to-letter bimachine: the total length-preserving rational functions.
Equations
- IsLengthPreservingBimachineComputable f = ∃ (L : Type) (x : Fintype L) (R : Type) (x : Fintype R) (B : Bimachine L R α β), B.IsLetterToLetter ∧ B.run = f
Instances For
f is computed by a finite letter-to-letter bimachine iff it is computed by one with
state types in any universes.
A length-preserving bimachine-computable function is bimachine-computable.
Functions computed by letter-to-letter bimachines are length-preserving.
A Mealy-computable function is bimachine-computable (Mealy.toBimachine).