Lecture Notes 07:
Finite Automata and Nondeterminism
Outline
This class we'll discuss:
- Recap: Finite Automata
- FA properties
- Nondeterminism
- NFAs Formal Definition
- NFA computation (tree)
Recap: FAs
Example Finite Automaton:
Activity 0 [2 minutes]:
What is the Language that this FA accepts?
Useful Properties
These are some properties that can help you deduce, generalize, or analyze FSMs with respect to their RegEx and Regular Languages.
Complement
IF a Language \(L_1\) is recognizable by an FA \( M_1\),
is language \( (L_1)^{c} \) also recognizable by some FA?
Or in other words,
\[\exists M_2 \quad | \quad L(M_2) = L(M_1)^{c} \]
Example: {w|w doesn’t contain either 00 or 11 as a substring}
If the property in question is "
Containing either 00 or 11 as a substring", then the Complement is:
the set of words that
do have the property, or:
Complement: {w|w contains either 00 or 11 as a substring}
Intersection
Activity 4 [2 minutes]:
How would you prove this (by construction)?
(Wait; then Click)
- run both machines “in parallel”
- accept if (and only if) both reach an accepting state
Example: word \( w = 0111 \)
Intersection: General Rule
The set of possible states
\( Q_3 = \{ AD, BD, CD, AE, BE, CE \}\)
Look at the rule for the transition function:
\[
\delta_3 ( (q_1, q_2), a ) = (\delta_1(q_1,a), \delta_2(q_2,a)) \\
\]
That means:
\( \mathbf{ \delta_3 ( (q_1, q_2), a ) }\) : the transition for \(M_3\) starting at the combo state: \(q_1q_2\) and input symbol \(a\).
the combo state resulting from the output of \(M_1\) when starting at state \(q_1\) and input symbol \(a\),
and the state resulting from the output of \(M_2\) when starting at state \(q_2\) and input symbol \(a\)
or \( \mathbf{ \delta_1(q_1,a), \delta_2(q_2,a)) }\)
The set of starting states \( q_{03} = (q_1,q_2) \)
Which is the combination state of the starting states of each of the machines: \(q_1\) from \(M_1\) and \(q_2\) from \(M_2\).
The set of Accepting states \( F_3 = (q_1,q_2) \)
Where
each one is the combination state of states where
both are accepting states in each of the machines:
\(C\) from \(M_1\)
AND \(E\) from \(M_2\).
Notice that for the example word
\( w = 0111 \) , the sequence of states is:
\( AD \xrightarrow{0} BD \xrightarrow{1} CE \xrightarrow{1} CD \xrightarrow{1} CE \) (Accept)
Union
Union: General Rule
NOW, the set of Accepting states \( F_3 = (q_1,q_2) \)
Where
each one is the combination state of states where
either are accepting states in each of the machines:
\(C\) from \(M_1\)
OR \(E\) from \(M_2\).
Set Difference
\[ L_3 = L_1 - L_2 \]
Activity 1 [2 minutes]:
Concatenation
Activity 2 [2 minutes]:
How would you prove this (by construction)?
(Wait; then Click)
- Let’s say we have two FAs \(M_1\) and \(M_2\), both with the same \(\Sigma\)
- Want to build another FA \(M_3\) with \( L(M_3)=L(M_1) \circ L(M_2) \texttt{, which is } \{ 𝑥_1 𝑥_2 | 𝑥_1 \in 𝐿(𝑀_1) \texttt{ and } 𝑥_2 \in 𝐿(𝑀_2) \} \)
- Just need to attach the accepting states of \(M_1\) to the start state of \(M_2\)
- Caution: since we don’t know when we’re done with the L(\(M_1\)) part of the string; could go through accepting states of \(M_1\) several times!
Example: word \( w = 000 \)
Notice that for the example word
\( w = 000 \) , the sequence of states might be:
\( A \xrightarrow{0}\) "invisible reject state" (Reject)
or
\( A \rightarrow B \xrightarrow{0} C \xrightarrow{0} C \xrightarrow{0} C\) (Accept)
How to combine them?
We seem to need to be able to “guess” when to shift to the second machine.
And we can't do that yet.
Another example of the logic and the issue:
- Say we have: \(M_1\): all strings with an odd number of 1's
- And \(M_2\): all strings with alternating 0s and 1s
- Is \(L(M_3) = L(M_1) \circ L(M_2)\) FA-recognizable?
- Say we have the string \(101001101010101\)
- is this recognizable if we split the string into \(x_1\) and \(x_2\)
- such that \(M_1\) recognizes \(x_1\), and
- such that \(M_2\) recognizes \(x_2\)
- What happens if \(x_1 = 101001101\) and \(x_2 = 010101\)?
- What happens if \(x_1 = 1010011\) and \(x_2 = 01010101\)?
Kleene Star
- Start with FA \(M_1\)
- Build another FA \(M_2\), with \(L(M_2) = L(M_1 )^∗\)
- Same problem as with concatenation: we need to guess...
Nondeterminism
Let's check a small video fragment from MinutePhysics.
The part we are interested in is the fact that there is a way to:
Let multiple parallel options happen at the same time!
As long as any of them succeeds, all "timelines" collapse and the word is accepted.
Think of it as having the option of "cloning yourself" into multiple word checkers... each checking one possible path.
We "split" or "clone" each time we:
- see an \(\epsilon\) (or free jump without consuming a symbol), or
- each time we see multiple paths for the same symbol.
Example
Notice that for the example word
\( w = 011 \) , the sequence of states is:
\( D \xrightarrow{0} D \xrightarrow{1} E \dots \) and then we have a split!!
- One path continues with: \( D \xrightarrow{0} D \xrightarrow{1} E \mathbf{ \xrightarrow{1} D }\) (Rejected) ...
- Another path continues with: \( D \xrightarrow{0} D \xrightarrow{1} E \mathbf{ \xrightarrow{1} E } \) (Accepted) ...
- Yet another path continues with: \( D \xrightarrow{0} D \xrightarrow{1} E \mathbf{ \xrightarrow{\epsilon} D \xrightarrow{1} E } \) (Accepted)
- The last path continues with: \( D \xrightarrow{0} D \xrightarrow{1} E \mathbf{ \xrightarrow{\epsilon} D \xrightarrow{1} E \xrightarrow{\epsilon} D} \) (Rejected)
NFAs Formal Definition
Activity 3 [2 minutes]:
Why would this be useful at all?
Remember Union?
With an NFA:
So how do NFA's
Compute?
NFA computation (tree)
We can visualize what happens with the computation of a string with an NFA by building a NFA computation Tree.
This is like "unrolling an FA as we walk it into paths", except with two extra rules:
- You add a possible path into a "next" state for every outgoing symbol option, and
- You add a possible path into a "next" state any states we might get to through an arrow labeled with \(\epsilon\)
An Example:
Activity 4 [2 minutes]:
Does the above example Accept or Reject string: \( 0 \; 1 \)?
Activity 5 [2 minutes]:
Build the computation tree for the Union example for the string \( 1 \; 0 \)
The example is repeated here for your convenience (you're welcome)
"Walk" the NFA and add a path for every possible choice (given the symbol read)
(Wait; then Click)
Remember Concatenation?
The problem was we could not "guess" at which part of the string one Machine should accept (reject) and the next begin processing.
With an NFA:
Activity 6 [2 minutes]:
Build the computation tree for the Concatenation example above, given the string:
\( 1 \quad 1 \quad 1 \quad 0 \)
Next class: Are NFAs stronger than DFAs?
Homework
[Due for everyone]
Remember: Problem Set 2 (Moodle) [Due Friday 02/11] Start Early!
[Optional]
TODO