# Mealy 机

Mealy 机是一种有限状态机，其输出由当前状态和当前输入共同决定，因此机器在每一次状态转移时都能产生一个输出符号，而不只是在进入新状态时才产生输出。它是两种带输出的标准有限状态机之一，另一种是 Moore 机，其输出仅取决于当前状态<sup>[1](https://digisim.io/blog/mealy-vs-moore-state-machines-with-examples)</sup>。尽管纸面上差别不大，但在电路设计中却有实实在在的分量，它决定了一个输入能否在存储状态被改变之前就影响输出。<sup>[1](https://digisim.io/blog/mealy-vs-moore-state-machines-with-examples)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出函数 | 输出取决于当前状态和当前输入，\( \lambda: Q \times \Sigma \rightarrow \Gamma \)<sup>[2](https://www.dlsi.ua.es/~mlf/nnafmc/pbook/node13.html)</sup> |
| 形式化形式 | 六元组 \( M=(Q,\Sigma,\Gamma,\delta,\lambda,q_I) \)：状态集、输入字母表、输出字母表、转移函数、输出函数、初始状态<sup>[2](https://www.dlsi.ua.es/~mlf/nnafmc/pbook/node13.html)</sup> |
| 起源 | George H. Mealy，《时序电路综合的一种方法》，Bell System Technical Journal 34(5)，第 1045–1079 页，1955 年 9 月<sup>[3](https://onlinelibrary.wiley.com/doi/abs/10.1002/j.1538-7305.1955.tb03788.x)</sup> |
| 状态数 | 对于相同的行为，通常比等价的 Moore 机需要更少的状态<sup>[4](https://ecexplain.in/compare/mealy-vs-moore)</sup> |
| 输出时序 | 组合逻辑输出，可在同一时钟周期内响应，但输入有噪声时可能产生毛刺<sup>[5](https://ic.unicamp.br/en/~rodolfo/Cursos/mo801/2026s2/slides/M01A04-fsm-sv/)</sup> |
| 等价性 | 任何 Mealy 机都可转换为 Moore 机，反之亦然，但二者的时序特性不同<sup>[6](https://www.cl.cam.ac.uk/teaching/0708/DigElec/Digital_Electronics_pdf.pdf)</sup> |
| 作为转换器 | 在输入字母表上接受一个字符串，并在输出字母表上产生一个等长的字符串<sup>[2](https://www.dlsi.ua.es/~mlf/nnafmc/pbook/node13.html)</sup> |

## 形式化定义

作为有限状态机中的转换器或翻译器，Mealy 机在输入字母表上消费一个字符串，并在输出字母表上产生一个等长的字符串。形式化地，Mealy 机是一个六元组 \( M=(Q,\Sigma,\Gamma,\delta,\lambda,q_I) \)，其中 \( Q \) 是有限状态集，\( \Sigma \) 是有限输入字母表，\( \Gamma \) 是有限输出字母表，\( \delta: Q \times \Sigma \rightarrow Q \) 是下一状态函数，\( \lambda: Q \times \Sigma \rightarrow \Gamma \) 是输出函数，\( q_I \in Q \) 是初始状态<sup>[2](https://www.dlsi.ua.es/~mlf/nnafmc/pbook/node13.html)</sup>。处于状态 \( q_j \) 的机器读到符号 \( \sigma_k \) 时，转移到状态 \( \delta(q_j,\sigma_k) \) 并写出符号 \( \lambda(q_j,\sigma_k) \)<sup>[2](https://www.dlsi.ua.es/~mlf/nnafmc/pbook/node13.html)</sup>。

由于输出在每次转移时发出，每消费一个输入符号就产生一个输出符号。在状态图中，这画作以“输入/输出”对标记的转移弧，而 Moore 机则把输出标在每个状态圆圈内部<sup>[4](https://ecexplain.in/compare/mealy-vs-moore)</sup>。

一个小例子可以说明这种行为。给定状态集 \( Q=\{q_1,q_2\} \)、输入字母表 \(\{\mathtt{0},\mathtt{1}\}\) 和输出字母表 \(\{\mathtt{E},\mathtt{O}\}\)，可以构造一台机器：当截至该点所见 `1` 的个数为偶数时输出 `E`，为奇数时输出 `O`；输入 `11100101` 便得到 `OEOOOEEO`<sup>[2](https://www.dlsi.ua.es/~mlf/nnafmc/pbook/node13.html)</sup>。

## 起源

这种机器以 George H. Mealy 命名，他的论文《时序电路综合的一种方法》发表于 Bell System Technical Journal 第 34 卷第 5 期，第 1045–1079 页，1955 年 9 月；稿件于 1955 年 5 月 6 日收到<sup>[3](https://onlinelibrary.wiley.com/doi/abs/10.1002/j.1538-7305.1955.tb03788.x)</sup>。该文发展了时序电路综合的理论基础，特别参照了 D. A. Huffman 和 E. F. Moore 的工作，并提出了一种强调形式化程序而非更常见的直觉方法的综合方法<sup>[3](https://onlinelibrary.wiley.com/doi/abs/10.1002/j.1538-7305.1955.tb03788.x)</sup>。Mealy 和 E. F. Moore 在 1955–56 年分别发表的论文中将有限自动机理论推广到更强大的机器，这两种机器类型正是为纪念他们的工作而命名的<sup>[7](https://www-cs-faculty.stanford.edu/people/eroberts/courses/soco/projects/2004-05/automata-theory/basics.html)</sup>。

## Mealy 机与 Moore 机之比较

两种模型在规格说明上只差一行：Moore 机计算输出 = f(状态)，而 Mealy 机计算输出 = f(状态, 输入)<sup>[5](https://ic.unicamp.br/en/~rodolfo/Cursos/mo801/2026s2/slides/M01A04-fsm-sv/)</sup>。

**时序与毛刺。** Moore 输出直接来自时钟触发的触发器，因此具有有保证的时序特性且无毛刺；Mealy 输出则取决于输入的时序<sup>[6](https://www.cl.cam.ac.uk/teaching/0708/DigElec/Digital_Electronics_pdf.pdf)</sup>。在硬件层面，Mealy 输出是组合逻辑的，可以在同一周期内立即响应输入，但噪声输入可能产生带毛刺的输出<sup>[5](https://ic.unicamp.br/en/~rodolfo/Cursos/mo801/2026s2/slides/M01A04-fsm-sv/)</sup>。Moore 输出只在时钟边沿变化，增加了一个周期的延迟，但在边沿之间保持稳定<sup>[4](https://ecexplain.in/compare/mealy-vs-moore)</sup>。一种常见的补救办法是对 Mealy 输出进行寄存：在输出逻辑与状态机输出之间插入触发器，可避免长路径和不确定的时序，代价是额外增加一个时钟周期的延迟<sup>[8](https://www-vhdl-online.hrz.tu-chemnitz.de/courses/system_design/synthesis/finite_state_machines_and_vhdl/registered_output)</sup>。

**状态数与转换。** 对于相同的行为，Mealy 机通常比 Moore 机需要更少的状态<sup>[4](https://ecexplain.in/compare/mealy-vs-moore)</sup>。两种模型具有同等的表达能力：Mealy 机可以转换为 Moore 机，反之亦然，但它们的时序行为不会一致。<sup>[6](https://www.cl.cam.ac.uk/teaching/0708/DigElec/Digital_Electronics_pdf.pdf)</sup> 二者之间的选择应基于接口的周期级行为来做出，并且应当验证综合后的实现，而不是依赖关于速度、状态数或安全性的口号<sup>[1](https://digisim.io/blog/mealy-vs-moore-state-machines-with-examples)</sup>。

## 最小化

对于给定的函数 \( \Sigma^{*} \rightarrow \Gamma^{*} \)，可能存在许多等价的有限状态转换器，它们在内部状态数上各不相同，而找出最小机器——内部状态数最少的那一台——往往很重要<sup>[9](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_APP01_05.xhtml)</sup>。第一步是删除从初始状态不可达的状态；没有不可达状态的机器称为连通的。一台连通的 Mealy 机仍可能不是最小的，因为两个不同的状态可能起相同的作用<sup>[9](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_APP01_05.xhtml)</sup>。

标准的化简方法是划分细化。如果没有任何输入序列能将两个状态区分开，即每个输入序列从任一状态出发都产生相同的输出序列，则这两个状态等价<sup>[10](https://ptolemy.berkeley.edu/projects/embedded/eecsx44/lectures/Fall2014/wk2-lec2-fsm-minim.pdf)</sup>。算法开始时将所有状态放在一个等价类中，迭代地分裂那些存在某个输入将两个成员送到不同类或产生不同输出的类，直到没有块可以再分裂；由最终划分构造出的商机器就是与原机器等价的唯一最小机器<sup>[11](https://formal.org/model-theory/module/7)</sup>。关于精确最小化的研究仍在继续，包括基于 SAT 的不完全指定 Mealy 机的精确最小化<sup>[12](https://archives.ecrts.org/fileadmin/WebsitesArchiv/Workshops/WCET/wcet17/embedded.cs.uni-saarland.de/MeMin.html)</sup>。

## 局限性

作为有限状态自动机，Mealy 机的能力是有限的，正如有限接受器一样<sup>[13](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_APP01_07.xhtml)</sup>。一个基本的鸽巢原理结论是：对于任何 Mealy 机 \( M=(Q,\Sigma,\Gamma,\delta,\theta,q_0) \)，都存在一个状态 \( q_i \in Q \) 和一个非空字符串 \( w \in \Sigma^{+} \)，使得 \( \delta^{*}(q_i,w)=q_i \)，因为 \( |Q| \) 是有限的而 \( w \) 可以任意长<sup>[13](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_APP01_07.xhtml)</sup>。这类论证表明有些函数无法由任何 Mealy 机实现；教科书中的例子是函数 \( F: \{a\}^{*} \rightarrow \{a,b\}^{*} \)，定义为 \( F(a^{2n})=a^{n}b^{n} \) 和 \( F(a^{2n+1})=a^{n}b^{n+1} \)<sup>[13](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_APP01_07.xhtml)</sup>。

## 应用

**协议建模与测试。** 由于协议状态通过输入和输出数据包与环境交互，Mealy 机被认为比 Moore 机更适合对网络协议实现进行协议推断<sup>[14](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0188229)</sup>。在一致性测试中，假定规格说明是一台 Mealy 机，而实现是一个黑盒，其对给定输入序列的输出可被观察；测试套件是由有限个输入序列组成的集合，当实现产生的输出序列与规格说明相同时，该实现通过测试<sup>[15](https://drops.dagstuhl.de/storage/00lipics/lipics-vol348-concur2025/html/LIPIcs.CONCUR.2025.34/LIPIcs.CONCUR.2025.34.html)</sup>。

**主动自动机学习。** Angluin 的 L* 算法和最小充分教师框架最初是为确定性有限自动机提出的，现已被扩展用于学习反应式系统的 Mealy 机，其中成员查询被替换为输出查询，即询问给定输入序列所产生的输出序列<sup>[16](https://link.springer.com/article/10.1007/s10703-023-00425-y)</sup>。在一项关于低功耗蓝牙的案例研究中，对六台物理设备的 Mealy 机模型进行主动学习后发现，BLE 协议栈实现因设备而异，从而可以对黑盒设备的底层片上系统进行指纹识别<sup>[16](https://link.springer.com/article/10.1007/s10703-023-00425-y)</sup>。该模型的扩展包括带单个定时器的 Mealy 机，它可以描述许多实际应用的实时行为，并可通过归约为普通 Mealy 机学习而高效地学习<sup>[17](https://doi.org/10.1016%2Fj.ic.2023.105013)</sup>。

**模式匹配。** Mealy 机也用于文本处理：已有算法提出，可从任何正则表达式构造一台 Mealy 机，在只读取每个输入符号一次的情况下找出所有匹配，并且可以通过用正则语言形式化 Mealy 机，借助 DFA 最小化的变体来计算最小 Mealy 机<sup>[18](https://arxiv.org/abs/2206.04944)</sup>。

**推广。** 该模型已被扩展到经典设定之外。量子 Mealy 机作为量子推广被提出，并开发了用于检查同一机器中两个状态以及两台机器之间等价性的高效算法<sup>[19](https://arxiv.org/abs/1901.02173)</sup>，此外还存在针对符号 Mealy 自动机的主动学习算法，后者支持无限输入字母表和多个输出字符<sup>[20](https://arxiv.org/abs/2509.14694)</sup>。

## References

1. [Mealy vs Moore State Machines: With Examples, DigiSim.io](https://digisim.io/blog/mealy-vs-moore-state-machines-with-examples)
2. [Mealy machines, Networks with circles and arrows (DLSI, University of Alicante)](https://www.dlsi.ua.es/~mlf/nnafmc/pbook/node13.html)
3. [Mealy, G. H. (1955). A Method for Synthesizing Sequential Circuits. Bell System Technical Journal 34(5), 1045–1079, Wiley Online Library](https://onlinelibrary.wiley.com/doi/abs/10.1002/j.1538-7305.1955.tb03788.x)
4. [Mealy vs Moore State Machine, ECExplain](https://ecexplain.in/compare/mealy-vs-moore)
5. [A04 – FSMs in SystemVerilog, MO801/MC972, Unicamp](https://ic.unicamp.br/en/~rodolfo/Cursos/mo801/2026s2/slides/M01A04-fsm-sv/)
6. [Moore vs. Mealy Machines, Digital Electronics lecture notes, University of Cambridge](https://www.cl.cam.ac.uk/teaching/0708/DigElec/Digital_Electronics_pdf.pdf)
7. [Basics of Automata Theory, Stanford University](https://www-cs-faculty.stanford.edu/people/eroberts/courses/soco/projects/2004-05/automata-theory/basics.html)
8. [Registered output, Finite State Machines and VHDL, VHDL-Online, TU Chemnitz](https://www-vhdl-online.hrz.tu-chemnitz.de/courses/system_design/synthesis/finite_state_machines_and_vhdl/registered_output)
9. [A.5 Mealy Machine Minimization, in An Introduction to Formal Languages and Automata, 7th Edition, O'Reilly](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_APP01_05.xhtml)
10. [FSM Minimization, EECS 144/244 lecture notes, UC Berkeley](https://ptolemy.berkeley.edu/projects/embedded/eecsx44/lectures/Fall2014/wk2-lec2-fsm-minim.pdf)
11. [Module 7 – Bisimulation & Equivalence of Machines, Mathematical Foundations of Model Checking, formal.org](https://formal.org/model-theory/module/7)
12. [MeMin – SAT-based Exact Minimization of Incompletely Specified Mealy Machines](https://archives.ecrts.org/fileadmin/WebsitesArchiv/Workshops/WCET/wcet17/embedded.cs.uni-saarland.de/MeMin.html)
13. [A.7 Limitations of Finite-State Transducers, in An Introduction to Formal Languages and Automata, 7th Edition, O'Reilly](https://www.oreilly.com/library/view/an-introduction-to/9781284231618/xhtml/9781284231601_APP01_07.xhtml)
14. [A model-guided symbolic execution approach for network protocol implementations and vulnerability detection, PLOS One](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0188229)
15. [New Fault Domains for Conformance Testing of Finite State Machines, LIPIcs CONCUR 2025](https://drops.dagstuhl.de/storage/00lipics/lipics-vol348-concur2025/html/LIPIcs.CONCUR.2025.34/LIPIcs.CONCUR.2025.34.html)
16. [Fingerprinting and analysis of Bluetooth devices with automata learning, Formal Methods in System Design, Springer Nature](https://link.springer.com/article/10.1007/s10703-023-00425-y)
17. [Learning Mealy machines with one timer, Information and Computation](https://doi.org/10.1016%2Fj.ic.2023.105013)
18. [A Report on Achieving Complete Regular-Expression Matching using Mealy Machines, arXiv](https://arxiv.org/abs/2206.04944)
19. [Equivalence Checking of Quantum Finite-State Machines, arXiv](https://arxiv.org/abs/1901.02173)
20. [Active Learning of Symbolic Mealy Automata, arXiv](https://arxiv.org/abs/2509.14694)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Formal languages and automata theory › Finite automata and finite-state machines

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/mealy-machine

English original: https://www.edgepedia.org/mealy-machine
