Mealy machines #
A Mealy machine [Mea55] is a deterministic transducer which reads its input left to
right and emits exactly one output symbol per input symbol, so the function it computes
is length-preserving by construction. Output coordinate i of the run is the output
at the state reached after the length-i input prefix (Mealy.getElem?_run),
so the output is prefix-determined at every coordinate.
Note that this definition allows for machines with infinite states; a Fintype
instance must be supplied for the finite-state class IsMealyComputable.
Main definitions #
Mealy σ α β: transducer with statesσ, input alphabetα, output alphabetβMealy.run,Mealy.runRight: the left-to-right and right-to-left passesMealy.comp: the cascade connection, computing the composite functionMealy.ofFn: the single-state machine applying a fixed symbol map letter-wiseMealy.ofFlag: the one-bit machine tracking whether an earlier symbol satisfiespMealy.map: transport along an equivalence on statesIsMealyComputable f:fis computed by some finite-stateMealyDFA.comapMealy: pulls an acceptor back along a transducer
Main theorems #
Mealy.getElem?_run: output coordinateiis the output at the state reached after the length-iinput prefixMealy.getElem?_ofFlag_run,Mealy.getElem?_ofFlag_runRight: each coordinate of a flag machine sees the flag over its strict prefix (its strict suffix, for the right-to-left pass)isMealyComputable_iff: the universe-polymorphic characterizationIsMealyComputable.comp: closure under compositionIsMealyComputable.isRegular_preimage: Mealy-computable maps pull back regular languages
Implementation notes #
The functions computed by Mealy machines are the sequential functions of algebraic
automata theory [Hol82]. SubsequentialTransducer generalizes to word-block
outputs and a state-final output [Moh97]; Mealy.toSubsequentialTransducer
exhibits a Mealy machine as the singleton-output, empty-flush case.
[UPSTREAM] candidate: Mathlib.Computability.Mealy.
The Myhill–Nerode characterization of the Mealy-computable functions by their
residuals is in Core/Computability/MyhillNerode.lean.
TODO #
- Mealy machine homomorphisms [Hol82], with
mapat an equivalence as the isomorphism case. - The right-scan mirror via reverse conjugation.
- Moore machines (state-determined output) and the Mealy–Moore equivalence: same
states one way,
σ × βstates the other, so the computable classes coincide. - The graph view: the zipped graph of a Mealy-computable map is a regular language
over
α × β(the synchronous rational relations). Residuals of the map correspond to left quotients of the graph, so this would deriveisMealyComputable_iff_residualfrom the language Myhill–Nerode theorem.
A Mealy machine is a set of states (σ), a starting state (initial), a
transition function (step) and an output function (output); it is letter-to-letter,
emitting exactly one output symbol per input symbol.
- initial : σ
Starting state.
- step : σ → α → σ
Transition function.
- output : σ → α → β
Output function: the symbol emitted on reading an input symbol in a state.
Instances For
Equations
- instInhabitedMealy = { default := { initial := default, step := fun (x : σ) (x_1 : α) => default, output := fun (x : σ) (x_1 : α) => default } }
T.stateAfter s x is the state reached from s after consuming the input x.
Equations
- T.stateAfter s = List.foldl T.step s
Instances For
The right-to-left pass emits the head output at the state reached over the entire reversed tail: the right scan reads the future.
Output coordinate i of the run is the output at the state reached after the
first i input symbols.
Output coordinate i of T.run is the output at the state reached after the
first i input symbols.
Composition #
T₂.comp T₁ feeds the outputs of T₁ to T₂ — the cascade connection of
[Hol82] — computing T₂.run ∘ T₁.run.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Letter-wise machines #
The single-state machine applying h to every symbol.
Equations
- Mealy.ofFn h = { initial := (), step := fun (x : Unit) (x_1 : α) => (), output := fun (x : Unit) => h }
Instances For
Flag machines #
The Mealy machine whose state is the monotone flag "a symbol satisfying p has
occurred".
Equations
- Mealy.ofFlag p out = { initial := false, step := fun (b : Bool) (a : α) => b || p a, output := out }
Instances For
Each coordinate of a flag machine run right-to-left sees the flag over its strict suffix.
Transport along state equivalences #
The Mealy-computable class #
The class of functions computed by a finite-state Mealy machine.
Equations
- IsMealyComputable f = ∃ (σ : Type) (x : Fintype σ) (T : Mealy σ α β), T.run = f
Instances For
The universe-polymorphic form of IsMealyComputable.
Mealy-computable functions are closed under composition (Mealy.comp).
Pulling back acceptors #
M.comapMealy T pulls the acceptor M back along the transducer T: the product
machine runs T and feeds its output symbols to M, so it accepts x if and only if
M accepts T.run x.
Equations
- M.comapMealy T = { step := fun (p : σ × τ) (a : α) => (T.step p.1 a, M.step p.2 (T.output p.1 a)), start := (T.initial, M.start), accept := {p : σ × τ | p.2 ∈ M.accept} }
Instances For
Mealy-computable maps pull back regular languages (DFA.comapMealy).
Causality #
A sequential machine's output coordinate i depends only on the input prefix
Set.Iic i.
A Mealy-computable map's output coordinate i depends only on the input prefix
Set.Iic i.