MELJUN CORTES Automata Theory (Automata6)
-
Upload
meljun-cortes -
Category
Technology
-
view
57 -
download
1
Transcript of MELJUN CORTES Automata Theory (Automata6)
![Page 1: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/1.jpg)
CSC 3130: Automata theory and formal languages
DFA minimization algorithm
MELJUN P. CORTES, MBA,MPA,BSCS,ACSMELJUN P. CORTES, MBA,MPA,BSCS,ACS
MELJUN CORTESMELJUN CORTES
![Page 2: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/2.jpg)
Example
• Construct a DFA over alphabet {0, 1} that accepts those strings that end in 111
• This is big, isn’t there a smaller DFA for this?
0
1
…
…
……
q
q
q
q
q
q
q
q
q
q
q
0
1
0
1
0
1
1
1
1
1
0
![Page 3: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/3.jpg)
Smaller DFA
• Yes, we can do it with 4 states:
– The state remembers the number of consecutive 1s at the end of the string (up to 3)
• Can we do it with 3 states?
1q q q q
1 1 1
0
00
0
![Page 4: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/4.jpg)
Even smaller DFA?
• Suppose we had a 3 state DFA M for L
• We do not know what this M looks like
… but let’s imagine what happens when:
• By the pigeonhole principle, on two of these inputs M ends in the same state
Minputs:
, 1, 11, 111
![Page 5: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/5.jpg)
Pigeonhole principle
• Here, balls are inputs, bins are states:
Suppose you are tossing m balls into n bins, and m > n. Then two balls end up in the same bin.
If you have a DFA with n states and you run it on m inputs, and m > n, then two inputs end up in same state.
![Page 6: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/6.jpg)
A smaller DFA?
Minputs:
, 1, 11, 111
• What goes wrong if…– M ends up in same state on input 1 and input
111?
– M ends up in same state on input and input 11?
![Page 7: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/7.jpg)
A smaller DFA
• Suppose M ends up in the same state after reading inputs x = 1i and y = 1j, where 0 ≤ i < j ≤ 3
• Then after reading the continuation z = 13 – j
– The state of yz should be accepting (yz = 111)– The state of xz should be rejecting (xz = , 1, or 11)
… but they are both in the same state!
Minputs:
, 1, 11, 1111i, 1j
![Page 8: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/8.jpg)
No smaller DFA!
• Conclusion
• So, this DFA is minimal
– In fact, it is the unique minimal DFA for L
There is no DFA with 3 states for L
1q q q q
1 1 1
0
00
0
![Page 9: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/9.jpg)
DFA minimization
• There is an algorithm to start with any DFA and reduce it to the smallest possible DFA
• The algorithm attempts to identify classes of equivalent states
• These are states that can be merged together without affecting the answer of the computation
![Page 10: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/10.jpg)
Examples of equivalent states
q0, q1 equivalent
q
q
q
q
0
1
0
1
0, 1
0, 1
q
q
q
q
1
0, 1
0, 1
0, 1
0
q0, q1 equivalent
q2, q3 also equivalent
![Page 11: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/11.jpg)
Equivalent and distinguishable states • Two states q, q’ are equivalent if
– Here, (q, w) is the state that the machine is in if it starts at q and reads the string w
• q, q’ are distinguishable if they are not equivalent:
^
For every string w, the states (q, w) and (q’, w) are either both accepting or both rejecting
^ ^
For some string w, one of the states (q, w), (q’, w) is accepting and the other is rejecting
![Page 12: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/12.jpg)
Examples of distinguishable states
q0, q1 equivalent
q3 distinguishable from q0, q1, q2
q3 is accepting, others are rejecting
q
q
q
q
0
1
0
1
0, 1
0, 1
(q0, q2) and (q1, q2) distinguishablethey behave differently on input 0
q0
q
q
0
1
0, 1
0, 1
![Page 13: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/13.jpg)
DFA minimization algorithm
• Find all pairs of distinguishable states as follows:
For any pair of states q, q’: If q is accepting and q’ is rejecting Mark (q, q’) as distinguishable
Repeat until nothing is marked: For any pair of states (q, q’): For every alphabet symbol a: If ((q, a), (q’, a)) are marked as distinguishable Mark (q, q’) as distinguishable
For any pair of states (q, q’): If (q, q’) is not marked as distinguishable Merge q and q’ into a single state
![Page 14: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/14.jpg)
Example of DFA minimization
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
q
q
q
q
q
q
qq q q qq
![Page 15: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/15.jpg)
Example of DFA minimization
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
x x x x x x
q
q
q
q
q
q
qq q q qq
q11 is distinguishable from all other states
![Page 16: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/16.jpg)
Example of DFA minimization
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
x
x
x
x
x
xx x x x
q
q
q
q
q
q
qq q q qq
q1 is distinguishable from q, q0, q00, q10
On transition 1, they go to distinguishable states
![Page 17: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/17.jpg)
Example of DFA minimization
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
x
x
x
x
x
x
x
xx
x
xxx x
q
q
q
q
q
q
qq q q qq
q01 is distinguishable from q, q0, q00, q10
On transition 1, they go to distinguishable states
![Page 18: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/18.jpg)
Example of DFA minimization
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
AxAxAx
xAxAx
xBxx
xAx
xx x
q
q
q
q
q
q
qq q q qq
Merge states not marked distinguishable q, q0, q00, q10 are equivalent → group A q1, q01 are equivalent → group B q11 cannot be merged → group C
A
BC
![Page 19: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/19.jpg)
Example of DFA minimization
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
AxAxAx
xAxAx
xBxx
xAx
xx x
q
q
q
q
q
q
qq q q qq
1q q qC
11
0
00
minimized DFA:
A
BC
![Page 20: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/20.jpg)
Why does DFA minimization work?
• We need to convince ourselves of three properties:
• Consistency– The new DFA M’ is well-defined
• Correctness – The new DFA M’ is equivalent to the original DFA
• Minimality – The new DFA M’ is the smallest DFA possible for L
M M’
![Page 21: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/21.jpg)
Main claim
• Proof outline:– First, we assume q, q’ are marked
distinguishable, and show they must be distinguishable
– Then, we assume q, q’ are not marked distinguishable, and show they must be equivalent
Any two states q and q’ in M are distinguishable if and only if the algorithm marks them as distinguishable
![Page 22: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/22.jpg)
Proof of part 1
• First, suppose q, q’ are marked as distinguishable
• Could it be that they are equivalent?– No, because recall how the algorithm works:
q
q’
w1
w1
w2
w2
wk
wk
wk-1
wk-1
…
…
xxxx
![Page 23: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/23.jpg)
Proof idea for part 2
• Now suppose q, q’ are not marked as distinguishable
• Could it be that they are distinguishable? Suppose so
• Then for some string w, (q, w) accepts, but (q’, w) rejects
• Working backwards, the algorithm will mark q and q’ as distinguishable at some point
^ ^
![Page 24: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/24.jpg)
Proof of part 2
q
q’
w1
w1
w1
w1
wk
wk
wk-1
wk-1
…
…
For any pair of states q, q’: If q is accepting and q’ is rejecting Mark (q, q’) as distinguishable
![Page 25: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/25.jpg)
Proof of part 2
q
q’
w1
w1
w2
w2
wk
wk
wk-1
wk-1
…
…
x
Repeat until nothing is marked: For any pair of states (q, q’): For every alphabet symbol a: If ((q, a), (q’, a)) are marked as distinguishable Mark (q, q’) as distinguishable
xxx
![Page 26: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/26.jpg)
Why does DFA minimization work?
• We need to convince ourselves of three properties:
• Consistency– The new DFA M’ is well-defined
• Correctness – The new DFA M’ is equivalent to the original DFA
• Minimality – The new DFA M’ is the smallest DFA possible for L
M M’
![Page 27: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/27.jpg)
Consistency of transitions
• Why are the transitions between the merged states consistent?
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
A
BC
![Page 28: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/28.jpg)
Proof of consistency
• Suppose there were two inconsistent transitions in M’ labeled a out of merged state qA
Aq3
q7
q1
Bq5
q2
Cq6
a
a
![Page 29: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/29.jpg)
Proof of consistency
• States q5 and q6 must be distinguishable because they were not merged together
Aq3
q7
q1
Bq5
q2
q6
a
a
![Page 30: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/30.jpg)
Proof of consistency
• Then, q3 and q7 must also be distinguishable, and this is impossible
Aq3
q7
q1
Bq5
q2
Cq6
a
a
w
w
![Page 31: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/31.jpg)
Consistency of states
• Why are the merged states either all accepting or all rejecting?
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
A
BC
![Page 32: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/32.jpg)
Consistency of states
• Because merged states are not distinguishable, so they are mutually equivalent
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
A
BC
![Page 33: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/33.jpg)
Correctness
• Each state of M’ corresponds to a class of mutually equivalent states in M
0
1
q
q
q
q
q
q
q
0
1
0
1
1
0
01
1
0
0
1
A
BC
![Page 34: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/34.jpg)
Proof of correctness
• Claim: After reading input w,
• Proof: True in start state, and stays true after, because transitions are consistent
• At the end, M accepts w in state qi if and only if M’ on input w lands in the state qA that represents qi
– qA must be accepting by consistency of states
M’ is in state qA if and only if M is in one of the states represented by A
![Page 35: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/35.jpg)
Proof of minimality
• Now suppose there is some smaller M’’ for L
• By the pigeonhole principle, there is a state q’’ of M’’ such that
All pairs of states in M’ are distinguishable
M’ M’’q
q’
v
v’
q’’
v, v’
![Page 36: MELJUN CORTES Automata Theory (Automata6)](https://reader036.fdocuments.us/reader036/viewer/2022062515/55c5c850bb61eb4b748b4628/html5/thumbnails/36.jpg)
Proof of minimality
• Since q and q’ are distinguishable, for some w…
• But in M’’, (q’’, w) cannot both accept and reject!
• So, M’’ cannot be smaller than M’
All pairs of states in M’ are distinguishable
M’ M’’q
q’
v
v’
q’’
v, v’
w
w?
w