Automata and regular languages
導入済み
5:58
計算理論とコンパイラ
This course asks what machines can decide, and how text becomes meaning. The first three units are theory: automata and regular languages, context-free…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| deterministic finite automaton/dɪˌtɜːmɪˈnɪstɪk ˈfaɪnaɪt ɔːˈtɒmətn/ | 決定有限自動機 |
| pumping lemma/ˈpʌmpɪŋ ˈlemə/ | ポンピング法則 |
| Regular languages/ˈreɡjʊlə ˈlæŋɡwɪdʒɪz/ | languages that a finite automaton or a regular expression can describe |
| nondeterministic finite automaton/ˌnɒndɪˌtɜːmɪˈnɪstɪk ˈfaɪnaɪt ɔːˈtɒmətn/ | a finite automaton that may have several possible moves, or none, for a symbol |
| subset construction/ˈsʌbset kənˈstrʌkʃn/ | turning an NFA into an equivalent DFA whose states are sets of NFA states |
| closed/kləʊzd/ | of a class of languages: applying an operation such as union or complement to members always gives another member |
| product construction/ˈprɒdʌkt kənˈstrʌkʃn/ | building one automaton whose states are pairs of states of two automata, so it runs both at once |
| accepting state |
表で動く機械
- 決定性有限オートマトン(DFA)は、状態の集合と遷移表からなります。記号を1つ読み、次の状態に移り、入力の終わりで受理するか拒否するかを決めます。
- この講座のDFAは、$\{a, b\}$上の文字列のうち、$ab$で終わるものを受理します。

The course DFA on input aba ends in state —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
q0-a-q1, q1-b-q2, q2-a-q1: ends q1, rejected (q2 accepts, not q1).
ポンピングの限界
- ポンピング補題:受理される十分に長い文字列は、$|xy| \le p$かつ$|y| \ge 1$となるように$xyz$と分割でき、すべての$xy^iz$も受理されます。したがって、$L = \{a^n b^n\}$は正則ではありません。$y$(すべて$a$)を繰り返すと、個数が一致しなくなります。
- 正則言語は、数を無限に数えることはできません。有限の記憶が限界です。
The pumping lemma shows a^n b^n is not regular because —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
y lies in the a-block; pumping changes the count of a without b.
A DFA with enough states can recognise $\{a^n b^n : n \ge 0\}$.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The pumping lemma breaks it: pumping $y$ inside the first $p$ letters adds $a$s only, giving a string with more $a$s than $b$s. A finite machine cannot count without bound.
動きを正確にたどる
aababはq0→q1(a)、q1→q1(a)、q1→q2(b)、q2→q1(a)、q1→q2(b)と進み、受理されます。abaはq0、q1、q2、q1と進み、パターンの途中で終わるため拒否されます。- 正規表現
ab|baを表す非決定性有限オートマトン(NFA)は、どちらの分岐を進むかを推測します。そこから作られたDFAは両方の可能性を同時に追跡するため、状態の数が大幅に増えることがあります。
The trace of aabab in the ends-in-ab DFA is —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
a:q1, a:q1, b:q2, a:q1, b:q2 - accept.
NFAからDFAへ
- $(a|b)^*ab$のNFAには3つの状態があります。$q_0$は$a$と$b$で自己ループし、$q_0 \xrightarrow{a} q_1$、$q_1 \xrightarrow{b} q_2$です。
- 部分集合構成法では、DFAの各状態をNFAの状態の集合にします。$\{q_0\} \xrightarrow{a} \{q_0, q_1\} \xrightarrow{b} \{q_0, q_2\}$は受理状態です。到達できる部分集合は$3$個だけです。
- 最悪の場合、$n$個の状態を持つNFAには$2^n$個の状態を持つDFAが必要です。「末尾から3番目の記号が$a$である」という条件には、NFAでは$4$個、DFAでは$8$個の状態が必要です。NFAはコンパクトに書けます。DFAは記号ごとに表を1回参照するだけなので、高速に動作します。
At most how many states can the subset construction produce from a 5-state NFA?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Each DFA state is a subset of the 5 NFA states: 2^5 = 32.
In the DFA for $(a|b)^*ab$, which subset is reached after reading ab?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
a takes {q0} to {q0, q1}; b then takes it to {q0, q2}, which contains the accepting q2.
2つの機械を1つとして動かす
- 正則言語は、和集合、共通部分、補集合の演算に対して閉じています。共通部分を求める直積構成では、2つのDFAを同時に動かします。状態はそれぞれの機械から1つずつ取った状態の組なので、3状態のDFAと4状態のDFAからは$3 \times 4 = \mathbf{12}$個の状態ができます。
- 両方が受理するときに受理するのが共通部分、どちらかが受理するときに受理するのが和集合です。補集合を求めるには、完全なDFAの受理状態と非受理状態を入れ替えます。
Product construction for the intersection of a 3-state DFA and a 4-state DFA: number of states?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
One state per pair: $3 \times 4$.
The complement of a regular language is regular.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Swap accepting and non-accepting states of a complete DFA.
例題:3で割り切れる2進数
- 状態を、それまでに読んだ数を3で割った余りとします。ビット$b$を読むと余り$r$は$(2r + b) \bmod 3$になるので、3つの状態で十分です。余りが0の状態を受理状態にします。
- 110(6)の場合:0 → 1 → $(2 + 1) \bmod 3 = 0$ → $0$となり、受理されます。101(5)の場合:0 → 1 → 2 → $(4 + 1) \bmod 3 = \mathbf{2}$となり、拒否されます。DFAは、残りの入力を処理するために必要な情報だけを記憶します。
The divisible-by-3 DFA reads the binary string 101. Which remainder state does it end in?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
$0 \to 1 \to 2 \to (2 \cdot 2 + 1) \bmod 3 = 2$.
点を落としやすいところ
- ポンピング補題を使って正則性を証明する。 ポンピング補題で示せるのは、言語が正則でないことだけです。
- 文字列の途中で判定する。 受理か拒否かは入力の終わりでのみ判定します。
abaはq2を通りますが、q1で終わります。 - DFAがNFAと同じくらい小さいと思い込む。 部分集合構成法では、$k$個の状態を持つNFAに対して、最大$2^k$個の状態が必要になることがあります。
まとめ
- DFAは1回の遷移で1つの記号を読み、最後の状態によって受理するかどうかを決めます。
- ポンピング補題は、$\{a^n b^n\}$が正則でないことを示します。有限オートマトンは数を無限に数えることができません。
- 部分集合構成法により、どのNFAもDFAに変換できます。そのDFAの状態は最悪の場合$2^n$個になります。
| NFA | DFA | |
|---|---|---|
| 1つの記号による遷移先 | 複数の状態のうち任意の状態 | 必ず1つの状態 |
| 大きさ | 小さく、書きやすい | 最大$2^n$個の状態 |
| 動作 | 状態の集合を追跡する | 記号ごとに表を1回参照する |
何が問題でしたか?この内容はサイトの運営チームだけが確認します。