ICS312 Set 29 Deterministic Finite Automata Nondeterministic Finite Automata.
Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite...
-
Upload
lynne-hamilton -
Category
Documents
-
view
215 -
download
1
Transcript of Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite...
![Page 1: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/1.jpg)
CS322Week 14 - Wednesday
![Page 2: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/2.jpg)
Last time
What did we talk about last time? Regular expressions Introduction to finite state automata
![Page 3: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/3.jpg)
Questions?
![Page 4: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/4.jpg)
Logical warmup
Each of the following equations is made of matches and written using Roman numerals
Unfortunately, each equation is wrong Move a single match stick in each
equation to correct the error VI = IV – III (12 matches) XIV – V = XX (14 matches) X = VIII – II (12 matches) VII = I (7 matches but bizarre)
![Page 5: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/5.jpg)
Back to FSA's
![Page 6: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/6.jpg)
FSA example
Consider this FSA again:
Which state will be reached on the following inputs:i. 01ii. 0011iii. 0101100iv. 10101
s0 s1 s2
1
1
001
0
![Page 7: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/7.jpg)
Eventual-state function
Let A be a FSA with a set of states S, set of input symbols I, and next-state function N: S x I S
Let I* be the set of all strings over I The eventual-state function N*: S x I* S is the
following N*(s,w) = the state that A goes to if the symbols of w are
input to A in sequence, starting with A in state s All of this is just a notational convenience so that we
have a way of talking about the state that a string will transition an FSA to
We say that w is accepted by A iff N*(s0, w) is an accepting state of A
The language of A, L(A) = { w I* | w is accepted by A }
![Page 8: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/8.jpg)
Designing automata
Design a finite-state automaton that accepts the set of all strings of 0's and 1's such that the number of 1's in the string is divisible by 3
Make a regular expression for this language
Design a finite-state automaton that accepts the set of all strings of 0's and 1's that contain exactly one 1
Make a regular expression for this language
![Page 9: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/9.jpg)
FSA = regular expressions Kleene's Theorem shows that Finite-
State Automata are equivalent to regular expressions
That is, for every finite-state automaton there is some equivalent regular expression, and vice versa
We won't prove it, but it should be intuitively clear because there are algorithms for building FSA's from regular expressions and vice versa
![Page 10: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/10.jpg)
Irregular
Languages that can be expressed as an FSA or a regular expression are called regular
Some languages are not regular For example, the language consisting of
strings akbk, meaning all strings that have a positive number of a's followed by the same number of b's, is not regular
Prove it (by contradiction) Hint: We use the pigeonhole principle to
show that more than one sequence of ap and aq must end up the in the same state
![Page 11: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/11.jpg)
Simplifying FSA'sStudent Lecture
![Page 12: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/12.jpg)
Simplifying FSA's
![Page 13: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/13.jpg)
Comparison
List strings accepted by the FSA A List strings accepted by the FSA B
s0 s1
s2
1
0
0
1
0
s3
1
1
0
A
s1
1
0 01
s0
B
![Page 14: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/14.jpg)
*-equivalence
Two states of a finite-state automaton are *-equivalent if any string accepted by the automaton when it starts from one state is accepted when starting from the other
Given an automaton A with eventual-state function N*, we can formally say: States s and t in A are*-equivalent iff N*(s,w)
and N*(t,w) are both accepting states or both not
It turns out that *-equivalence defines an equivalence relation
![Page 15: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/15.jpg)
k-equivalence
*-equivalence is hard to demonstrate directly
Instead, we'll focus on equivalence after k or fewer inputs
Given an automaton A with eventual-state function N*, we can formally say: States s and t in A are k-equivalent iff
N*(s,w) and N*(t,w) are both accepting states or both not, for all strings w of length k or less
![Page 16: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/16.jpg)
Facts about k-equivalence For k ≥ 0, k-equivalence is an equivalence
relation For k ≥ 0, the k-equivalence classes partition
the set of all states of the automaton into a union of mutually disjoint subsets
For k ≥ 1, if two states are k-equivalent, they are also (k-1)-equivalent
For k ≥ 1, each k-equivalence class is a subset of a (k-1)-equivalence class
Any two states that are k-equivalent for all integers k ≥ 0 are *-equivalent
![Page 17: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/17.jpg)
k-equivalence theorems
Let A be an FSA with next-state function N Given any states s and t in A:
1. s is 0-equivalent to t iff either s and t are both accepting states or they are both nonaccepting states
2. For every integer k ≥ 1, s is k-equivalent to t iff s and t are (k-1)-equivalent and for any input symbol m, N(s,m) and N(t,m) are also (k-1)-equivalent
These theorems essentially allow us to create a recursive definition for testing k-equivalence
![Page 18: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/18.jpg)
k-equivalence examples
Find the 0-equivalence classes, the 1-equivalence classes, and the 2-equivalence classes for the following FSA:
s1 s2
s3
01
1
s4
0
0
s0
11
00
1
![Page 19: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/19.jpg)
Finding the *-equivalence classes
Keep finding k-equivalence classes for larger and larger values of k
If you ever find that the set of k-equivalence classes is equal to the set of (k+1)-equivalence classes, that is the set of *-equivalence classes
This is known as a fixed point in mathematics
![Page 20: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/20.jpg)
The quotient automaton
We can build a new FSA from the *-equivalence classes
Recall that [s] means the equivalence class of s This FSA is called the quotient automaton A', and is
defined from an FSA A with states S, input symbols I, and next-state function N as follows:1. The set of states S' of A' is the set of *-equivalent classes
of states of A2. The set of input symbols I' of A' equals I3. The initial state of A' is [s0] where so is the initial state of A
4. The accepting states of A' are the states of the form [s] where s is an accepting state of A
5. The next-state function N': S' x I S' is:For all states [s] in S' and input symbols m, N'([s], m) = [N(s,m)]
![Page 21: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/21.jpg)
Constructing a quotient automaton
Let A be an FSA with states S, input symbols I, and next-state function N
To build A':1. Find the set of 0-equivalence classes of S2. For each integer k ≥ 1, find the k-equivalence
classes of S until the k-equivalence classes are the same as the (k-1)-equivalence classes
3. Build a quotient automaton whose states are the equivalence classes given above with transition function N'([s],m) = [N(s,m)] for any input symbol m
![Page 22: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/22.jpg)
Quotient automaton example
Find the quotient automaton for the following FSA
s1 s2
s3
01
1
s4
0
0
s0
11
00
1
![Page 23: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/23.jpg)
Equivalent automata
Two automata A1 and A2 are equivalent iff L(A1) = L(A2)
Proving the languages accepted by two automata can be difficult
However, the quotient automata for both A1 and A2 will be the same (except for labeling) if A1 is equivalent to A2
![Page 24: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/24.jpg)
Proving equivalence
Prove that the following two automata are equivalent by finding their quotient automata
s0
s2
s1
0
1
1
s3
0
01
1
0
s0
'
s1
'
s2
'
0, 1
0
1
s3
'
0
0
1
1
![Page 25: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/25.jpg)
Upcoming
![Page 26: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/26.jpg)
Next time…
Context free languages
![Page 27: Week 14 - Wednesday. What did we talk about last time? Regular expressions Introduction to finite state automata.](https://reader030.fdocuments.us/reader030/viewer/2022032414/56649ef95503460f94c0b401/html5/thumbnails/27.jpg)
Reminders
Keep reading Chapter 12 Finish Assignment 10
Due Friday before midnight