Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:dfa [2018/07/23 12:21] pdmatei |
lfa:dfa [2020/10/19 15:36] (current) pdmatei |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Deterministic automata ====== | ====== Deterministic automata ====== | ||
- | |||
- | ===== Motivation ===== | ||
- | |||
- | In the last lecture, we have shown that, for **each** regular expression $math[e], we can construct an NFA $math[M], such that $math[L(e) = L(M)]. | ||
- | |||
- | While NFAs are a computational instrument for establishing acceptance, they **are not an ideal one**. Nondeterminism is difficult to translate per. se. in a programming language. | ||
- | |||
- | Suppose we enforce the following restriction on the **transition relation** $math[\Delta]: | ||
- | * $math[\Delta : K \times \Sigma \rightarrow K], | ||
- | * the function $math[\Delta] is **total** (i.e. it is defined for all possible values in its input). | ||
- | |||
- | Thus: | ||
- | * each transition must occur on a **symbol**, | ||
- | * exactly **one** transition is possible for each state-symbol combination | ||
$def[DFA] | $def[DFA] | ||
- | A **Deterministic Finite Automata** is an NFA, where $math[\Delta : K \times \Sigma \rightarrow K] is a **total** function. In what follows, we write $math[\delta] instead of $math[\Delta] to refer to the transition function of a DFA. | + | A **Deterministic Finite Automata** is a tuple $math[(K,\Sigma,\delta,q_0,F)], where $math[K] is a set of states, $math[\Sigma] is the alphabet, $math[\Delta : K \times \Sigma \rightarrow K] is a **total** transition function. |
$end | $end | ||
Line 33: | Line 19: | ||
We say a word $math[w] is **accepted** by a DFA $math[M] iff $math[(q_0,w)\vdash_M^*(q,\epsilon)] and $math[q\in F] ($math[q] is a final state). | We say a word $math[w] is **accepted** by a DFA $math[M] iff $math[(q_0,w)\vdash_M^*(q,\epsilon)] and $math[q\in F] ($math[q] is a final state). | ||
$end | $end | ||
- | |||
- | Example(s) | ||
===== NFA to DFA transformation ===== | ===== NFA to DFA transformation ===== | ||
- | Let $math[M=(K,\Sig | + | Let $math[M=(K,\Sigma, \Delta, q_0, F)] be an NFA. We assume $math[M] **does not contain transitions on words of length larger than 1**. If $math[(q,w,q')\in\Delta] for some $math[w=c_1\ldots c_n] of size 2 or more, we construct intermediary states $math[q^1, \ldots, q^{n+1}] as well as transitions $math[(q^1,c_1,q^2), \ldots (q^n,c_n,q^{n+1})], where $math[q=q^1] and $math[q'=q^n] |
- | ma, \Delta, q_0, F)] be an NFA. We assume $math[M] **does not contain transitions on words of length larger than 1**. If $math[(q,w,q')\in\Delta] for some $math[w=c_1\ldots c_n] of size 2 or more, we construct intermediary states $math[q^1, \ldots, q^{n+1}] as well as transitions $math[(q^1,c_1,q^2), \ldots (q^n,c_n,q^{n+1})], where $math[q=q^1] and $math[q'=q^n] | + | |
We denote by $math[E_M(q) = \{p\in K\mid (q,\epsilon)\vdash^*_M (p,\epsilon)\}], the **$math[\epsilon]-closure** of state $math[q]. In effect $math[E_M(q)] contains **all states reachable from $math[q] via $math[\epsilon]-transitions**. When the automaton $math[M] is understood from the context, we omit the subscript and simply write $math[E(q)]. | We denote by $math[E_M(q) = \{p\in K\mid (q,\epsilon)\vdash^*_M (p,\epsilon)\}], the **$math[\epsilon]-closure** of state $math[q]. In effect $math[E_M(q)] contains **all states reachable from $math[q] via $math[\epsilon]-transitions**. When the automaton $math[M] is understood from the context, we omit the subscript and simply write $math[E(q)]. | ||
Line 55: | Line 38: | ||
$prop[1] | $prop[1] | ||
- | For all $math[q,p], $math[(q,w)\vdash^*_M (p,\epsilon)] iff $math[(E(q),w)\vdash^*_{M'}(P,\epsilon)] with $math[p\in P]. | + | For all $math[q,p\in K], $math[(q,w)\vdash^*_M (p,\epsilon)] iff $math[(E(q),w)\vdash^*_{M'}(P,\epsilon)], for some $math[P] such that $math[p\in P]. |
$end | $end | ||
Line 81: | Line 64: | ||
The proof is by **induction** over the length of the word $math[w]. | The proof is by **induction** over the length of the word $math[w]. | ||
- | ** Basis case: $math[w=\epsilon]** | + | ** Basis step**: $math[\mid w\mid=0] that is $math[w=\epsilon] |
* //direction $math[\implies]:// | * //direction $math[\implies]:// | ||
- Suppose $math[(q,\epsilon) \vdash^*_M(p,\epsilon)]. | - Suppose $math[(q,\epsilon) \vdash^*_M(p,\epsilon)]. | ||
- | - Since $math[\vdash^*_{M'}] is **reflexive**, we have $math[(E(q),\epsilon)\vdash^*_{M'}(E(q),\epsilon)] | ||
- From the definition of $math[E] and 1., we have that $math[p\in E(q)]. | - From the definition of $math[E] and 1., we have that $math[p\in E(q)]. | ||
- | - From 2. and 3. we have $math[E(q),\epsilon)\vdash^*_{M'}(P,\epsilon)] with $math[p\in P]. | + | - Since $math[\vdash^*_{M'}] is **reflexive**, we have $math[(E(q),\epsilon)\vdash^*_{M'}(E(q),\epsilon)]. |
+ | - Therefore, we have $math[E(q),\epsilon)\vdash^*_{M'}(P,\epsilon)] with $math[p\in P]: $math[P] is actually $math[E(q)]. | ||
* //direction $math[\impliedby]:// | * //direction $math[\impliedby]:// | ||
Line 93: | Line 76: | ||
- By the definition of $math[E], we have that $math[(q,\epsilon)\vdash^*_{M}(p,\epsilon)] for any $math[p\in E(q)]. | - By the definition of $math[E], we have that $math[(q,\epsilon)\vdash^*_{M}(p,\epsilon)] for any $math[p\in E(q)]. | ||
- | ** Induction step: $math[w'=wa]** (hence $math[a] is the last symbol of $math[w']). | + | ** Induction hypothesis**: suppose that the claim is true for all strings w such that $math[\mid w\mid\leq k] for $math[k\geq0] |
+ | |||
+ | ** Induction step**: we prove for any string $math[w] of length $math[k+1]; let $math[w'=wa] (hence $math[a] is the last symbol of $math[w']). | ||
* //direction $math[\implies]:// | * //direction $math[\implies]:// | ||
- Suppose $math[(q,wa)\vdash^*_{M} (p,\epsilon)]. | - Suppose $math[(q,wa)\vdash^*_{M} (p,\epsilon)]. | ||
- | - By the definition of $math[\vdash^*], we have: $math[(q,wa)\vdash^*_{M} (r_1,a) \vdash_{M} (r_2,\epsilon)\vdash^*_{M} (p,epsilon)]. In words, there is a path from $math[q] which takes us to $math[r_1] by consuming $math[w], then to $math[r_2] via a **one-step** transition, then to $math[p] in zero or more $math[\epsilon]-transitions. Notice that $math[p] may be equal to $math[r_2], which is taken into account since $math[\vdash^*_{M}] is reflexive. | + | - By the definition of $math[\vdash^*], we have: $math[(q,w)\vdash^*_{M} (r_1,a) \vdash_{M} (r_2,\epsilon)\vdash^*_{M} (p,\epsilon)]. In other words, there is a //path// from $math[q] which takes us to $math[r_1] by consuming $math[w], then to $math[r_2] via a **one-step** transition, then to $math[p] in zero or more $math[\epsilon]-transitions. Notice that $math[p] may be equal to $math[r_2], which is taken into account since $math[\vdash^*_{M}] is reflexive. |
- By the construction of $math[\vdash^*_{M}], we also have $math[(q,w)\vdash^*_{M}(r_1,\epsilon)] | - By the construction of $math[\vdash^*_{M}], we also have $math[(q,w)\vdash^*_{M}(r_1,\epsilon)] | ||
- From 3. by **induction hypothesis**, we have $math[(E(q),w)\vdash^*_{M'}(R_1,\epsilon)] with $math[r_1 \in R_1] | - From 3. by **induction hypothesis**, we have $math[(E(q),w)\vdash^*_{M'}(R_1,\epsilon)] with $math[r_1 \in R_1] | ||
- By construction of $math[\vdash^*_{M'}], we have $math[(E(q),wa)\vdash^*_{M'}(R_1,a)] | - By construction of $math[\vdash^*_{M'}], we have $math[(E(q),wa)\vdash^*_{M'}(R_1,a)] | ||
- | - Since $math[(r_1,a) \vdash_{M} (r_2,\epsilon)], by the definition of $math[\delta], we have $math[(R_1,a)\vdash_{M'}(R_2,\epsilon)] and $math[E(r_2)\subseteq R_2]. Also, $math[r_2\in E(r_2)]. | + | - Since $math[(r_1,a) \vdash_{M} (r_2,\epsilon)], by the definition of $math[\delta], we have $math[E(R_2) \subseteq \delta(R_1,a)]. |
- | - By the definition of $math[E] (and $math[(r_2,\epsilon)\vdash^*_{M} (p,epsilon)]), also $math[p \in E(r_2)]. | + | - Since $math[(r_2,\epsilon) \vdash_{M} (p,\epsilon)] it follows that $math[p \in E(r_2)], and therefore $math[p \in \delta(R_1,a)]. |
- In effect, from 5. and 7. we have shown that $math[(E(q),wa)\vdash^*_{M'}(R_1,a)\vdash_{M'}(R_2,\epsilon)] with $math[p\in R_2], which concludes our proof. | - In effect, from 5. and 7. we have shown that $math[(E(q),wa)\vdash^*_{M'}(R_1,a)\vdash_{M'}(R_2,\epsilon)] with $math[p\in R_2], which concludes our proof. | ||