计算理论:有限自动机
Finite Automata
Finite automata is a formal system with only a finite amount of information
- Information represented by its state
- State changes in response to inputs
- Rules that tell how the state changes in response to inputs are called transitions
Acceptance:对一个输入的序列(input string),从起始状态开始按照 transition 的规则转换状态,该输入被接受
Language of an Automata: The set of strings accepted by an automata
不同的终止状态集合会带来不同的 language
Deterministic Finite Automata
Definition
A DFA is represented formally by a 5-tuple,
- a finite set of states
- a finite set of input symbols
- a transition function
- an initial state
- a set of states
distinguished as final states,
transition function takes two arguments: a state and an input symbol
更为严谨的定义需要 transition function
DFA 也可以以图的形式表示
- 节点=状态
- 边=transition function
- 无源边 start 指向初始状态
- 接收状态用 double circles 表示
或者以 transition table 的形式表示
- 行为状态
- 列为输入
- 起始状态用箭头标注
- 接收状态用 * 标注
Extend transition function: 接受一个 state 和一个 string 作为输入,递归定义如下
Basis.
Induction.
Language of DFA
各种各样的 Automata 都定义语言,对于 DFA
Regular language: a language is regular if it is the language accepted by some DFA
A Nonregular Language:
Proof.
使用反证法,假设存在一个 DFA 接受该语言,该 DFA 有
则必然存在从起始状态到接收状态的路径
考虑前
则该 DFA 同样可接受
Q.E.D.
Nondeterministic Finite Automata
Nondeterminism
NFA 的 transition 结果可以是一个状态的集合
An NFA is represented formally by a 5-tuple,
- a finite set of states
- a finite set of input symbols
- a transition function
- an initial state
- a set of states
distinguished as final states,
对于 NFA ,
Basis.
Induction.
对于 NFA
即只要存在一条运行路径结束于接收状态即可认为接受该 string
NFA with -transitions
允许状态间根据
定义 Closure of states:
= set of states you can reach from state following only arcs labeled - Basis.
- Induction. 如果
且有一条从 到 的边标号为 ,则
- Basis.
在
Basis.
Induction.
Equivalence of DFA, NFA
DFA to NFA
A DFA can be turned into an NFA that accepts the same language:
If
NFA to DFA: subset construction
从 NFA 构造 DFA 可使用 subset construction
对于 NFA
是 的 power set,如果 那么 ,但实践中一般很多状态都是不可达的,可达状态的数量大约和 在同一数量级 是满足 的 的集合 的定义如下,对于任意
Critical Point: DFA 的状态为 NFA 状态的集合
证明其正确性只需证明对字符串
Proof.
对
Basis.
Induction. 令
令
根据 NFA transition function 的定义,有
而根据上述证明的构造有
同样的,根据 DFA transition function 的定义,有
则
故
得证
Q.E.D.
由上述双向的等价可得
Equivalence of DFA, -NFA
DFA to -NFA
Obviously, every DFA is an
-NFA to DFA
可从一个
对于一个
Proof.
是 的 power set,且任意 满足 ,换言之, 是一个 -closed set 是满足 的 的集合 的定义为,对于任意
证明其正确性只需证明对任意字符串
根据
Q.E.D.