Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax765601.MealyMachine

Mealy machines

concepts/Lax765601/MealyMachine.lean · lax-765601

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    In the paper

    Definition

    A Mealy machine is a deterministic finite automaton whose transitions are labelled by output letters, and which has no accepting states, since its purpose is to produce an output string rather than to accept or reject. Formally (Definition A.1.1 of Transducers), it consists of an input alphabet AA, an output alphabet BB, a state space QQ, an initial state q0Qq_0 \in Q and a transition function

    δ:Q×AQ×B.\delta : Q \times A \to Q \times B.

    Its semantics is the function f:ABf : A^* \to B^* obtained by running the underlying automaton on the input string and labelling each position by the output letter of the corresponding transition; it is a letter-to-letter function, the output having the same length as the input. A function is computed by a Mealy machine if it is the semantics of a Mealy machine with a finite state space.

    The state transformation of an input letter aa is the map QQQ \to Q describing how reading aa updates the state, the output being ignored; the underlying pre-automaton of the machine is the family of these maps, i.e. a deterministic automaton without initial and accepting states (Section A.2).

    Lean source view on GitHub

    1import Mathlib.Data.Finite.Defs
    2
    3/-!
    4---
    5title: Mealy machines
    6type: definition
    7---
    8A *Mealy machine* is a deterministic finite automaton whose transitions are
    9labelled by output letters, and which has no accepting states, since its purpose
    10is to produce an output string rather than to accept or reject. Formally
    11(Definition A.1.1 of *Transducers*), it consists of an input alphabet AA, an
    12output alphabet BB, a state space QQ, an initial state q0Qq_0 \in Q and a
    13transition function
    14δ:Q×AQ×B.\delta : Q \times A \to Q \times B.
    15Its semantics is the function f:ABf : A^* \to B^* obtained by running the
    16underlying automaton on the input string and labelling each position by the
    17output letter of the corresponding transition; it is a *letter-to-letter*
    18function, the output having the same length as the input. A function is
    19*computed by a Mealy machine* if it is the semantics of a Mealy machine with a
    20finite state space.
    21
    22The *state transformation* of an input letter aa is the map QQQ \to Q describing
    23how reading aa updates the state, the output being ignored; the underlying
    24*pre-automaton* of the machine is the family of these maps, i.e. a deterministic
    25automaton without initial and accepting states (Section A.2).
    26
    27# Formalization notes
    28
    29`Mealy A B Q` carries the initial state and the transition function; the three
    30alphabets are the type parameters. Finiteness of the state space is not part of
    31the structure — it is where it belongs, in `IsMealy`, which asks for *some*
    32finite state space `Q` and some machine over it. Alphabets are arbitrary types;
    33the finiteness the book assumes globally is a hypothesis of the statements that
    34need it.
    35
    36`run` is the output produced from a given state, defined by recursion on the
    37input string, and `eval` is the run from the initial state. Nothing else is
    38derivable from these and is omitted; the dfa obtained by forgetting outputs is
    39`transFun`.
    40-/
    41
    42namespace Lax765601.MealyMachine
    43
    44/-- A Mealy machine with input alphabet `A`, output alphabet `B` and state space
    45`Q`: an initial state and a transition function `Q × A → Q × B`. -/
    46structure Mealy (A B Q : Type) where
    47 /-- The initial state. -/
    48 init : Q
    49 /-- The transition function: a source state and an input letter determine a
    50 target state and an output letter. -/
    51 step : Q → A → Q × B
    52
    53namespace Mealy
    54
    55variable {A B Q : Type}
    56
    57/-- The output produced by the machine on an input string, when started in a
    58given state. -/
    59def run (M : Mealy A B Q) : Q → List A → List B
    60 | _, [] => []
    61 | q, a :: w => (M.step q a).2 :: M.run (M.step q a).1 w
    62
    63/-- The semantics of a Mealy machine: the output produced from the initial state.
    64-/
    65def eval (M : Mealy A B Q) (w : List A) : List B := M.run M.init w
    66
    67/-- The state transformation of an input letter: how reading the letter updates
    68the state. -/
    69def letterTrans (M : Mealy A B Q) (a : A) : Q → Q := fun q => (M.step q a).1
    70
    71/-- The underlying pre-automaton: the transition function with the output letters
    72forgotten. -/
    73def transFun (M : Mealy A B Q) : Q → A → Q := fun q a => (M.step q a).1
    74
    75end Mealy
    76
    77/-- A string-to-string function is computed by a Mealy machine if it is the
    78semantics of a Mealy machine with a finite state space. -/
    79def IsMealy {A B : Type} (f : List A → List B) : Prop :=
    80 ∃ (Q : Type) (_ : Finite Q) (M : Mealy A B Q), M.eval = f
    81
    82end Lax765601.MealyMachine
    83

    Formalization notes

    MealyABQMealy A B Q carries the initial state and the transition function; the three alphabets are the type parameters. Finiteness of the state space is not part of the structure — it is where it belongs, in IsMealyIsMealy, which asks for some finite state space QQ and some machine over it. Alphabets are arbitrary types; the finiteness the book assumes globally is a hypothesis of the statements that need it.

    runrun is the output produced from a given state, defined by recursion on the input string, and evaleval is the run from the initial state. Nothing else is derivable from these and is omitted; the dfa obtained by forgetting outputs is transFuntransFun.

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…