Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2022:lab05-mindfa [2022/11/04 13:58] alexandra.udrescu01 |
lfa:2022:lab05-mindfa [2022/11/12 20:49] (current) alexandra.udrescu01 |
||
---|---|---|---|
Line 3: | Line 3: | ||
Consider the following DFAs: | Consider the following DFAs: | ||
- | **DFA 1**: {{ :lfa:2022:lfa2022_lab5_ex2_4_cerinta.png?350 |}} | + | ^ **DFA 1** ^ **DFA 2** ^ |
- | + | |{{ :lfa:2022:lfa2022_lab5_ex2_4_cerinta.png?350 |}} | {{ :lfa:screenshot_2021-11-03_at_11.25.00.png?400 |}} | | |
- | **DFA 2**: {{ :lfa:screenshot_2021-11-03_at_11.25.00.png?400 |}} | + | |
<note important>The first DFA is the solution to exercise 4.3.4 from Lab4.</note> | <note important>The first DFA is the solution to exercise 4.3.4 from Lab4.</note> | ||
Line 13: | Line 12: | ||
5.1.1. Identify a pair of states which are **indistinguishable**. (Solve the exercise for the 2 given DFAs.) | 5.1.1. Identify a pair of states which are **indistinguishable**. (Solve the exercise for the 2 given DFAs.) | ||
- | <hidden> | + | |
+ | <hidden DFA 1> | ||
+ | <note tip> | ||
** DFA 1** | ** DFA 1** | ||
Line 19: | Line 20: | ||
Looking at the DFA we can see that states 2 and 5 both go to state 6 on "1" and to 3 on "0". | Looking at the DFA we can see that states 2 and 5 both go to state 6 on "1" and to 3 on "0". | ||
+ | </note> | ||
</hidden> | </hidden> | ||
- | <hidden> | + | <hidden DFA 2> |
+ | <note tip> | ||
** DFA 2** | ** DFA 2** | ||
Line 28: | Line 30: | ||
Looking at the DFA we can see that states 1 and 2 both go to state 2 on "a" and to 5 on "b". | Looking at the DFA we can see that states 1 and 2 both go to state 2 on "a" and to 5 on "b". | ||
+ | </note> | ||
</hidden> | </hidden> | ||
+ | |||
5.1.2. Identify a pair of final or non-final states which are **distinguishable**. The pair must be distinguished by a word different from the empty word. (Solve the exercise for the 2 given DFAs.) | 5.1.2. Identify a pair of final or non-final states which are **distinguishable**. The pair must be distinguished by a word different from the empty word. (Solve the exercise for the 2 given DFAs.) | ||
- | <hidden> | ||
- | ** DFA 1** | ||
- | States 4 and 5 are distinguishable because we can accept "1" from 4, but not from 5. | + | <hidden DFA 1> |
+ | <note tip>** DFA 1** | ||
+ | |||
+ | States 4 and 5 are distinguishable because we can accept "1" from 4, but not from 5.</note> | ||
</hidden> | </hidden> | ||
- | <hidden> | + | <hidden DFA 2> |
- | ** DFA 2** | + | <note tip>** DFA 2** |
- | States 0 and 5 are distinguishable because from 0 we can accept word "b", but not from 5. | + | States 0 and 5 are distinguishable because from 0 we can accept word "b", but not from 5.</note> |
</hidden> | </hidden> | ||
+ | |||
5.1.3. Compute the table of indistinguishable states for the DFA. (Solve the exercise for the 2 given DFAs.) | 5.1.3. Compute the table of indistinguishable states for the DFA. (Solve the exercise for the 2 given DFAs.) | ||
- | <hidden> | + | |
+ | <hidden DFA 1><note tip> | ||
** DFA 1 ** | ** DFA 1 ** | ||
Line 70: | Line 77: | ||
Predecessors for (6, 2): | Predecessors for (6, 2): | ||
* 0: - | * 0: - | ||
- | * 1: (2, 1), (5, 1) => mark them on the table | + | * 1: (2, 1), (5, 1) => mark them |
Line 83: | Line 90: | ||
Predecessors for (6, 5): | Predecessors for (6, 5): | ||
* 0: - | * 0: - | ||
- | * 1: (2, 3), (5, 3), (2, 4), (5, 4) => mark them on the table | + | * 1: (2, 3), (5, 3), (2, 4), (5, 4) => mark them |
Predecessors for (2, 1): | Predecessors for (2, 1): | ||
Line 115: | Line 122: | ||
=> The partitions are: {2, 5} and {1, 3, 4} | => The partitions are: {2, 5} and {1, 3, 4} | ||
+ | </note> | ||
</hidden> | </hidden> | ||
- | <hidden> | + | <hidden DFA 2> |
+ | <note tip> | ||
** DFA 2 ** | ** DFA 2 ** | ||
Line 142: | Line 150: | ||
Predecessors for (5, 4): | Predecessors for (5, 4): | ||
* a: - | * a: - | ||
- | * b: (3, 4), (3, 1), (3, 2), (3, 5) => mark them on the table | + | * b: (3, 4), (3, 1), (3, 2), (3, 5) => mark them |
Predecessors for (5, 1): | Predecessors for (5, 1): | ||
* a: - | * a: - | ||
- | * b: (5, 0) => mark it on the table | + | * b: (5, 0) => mark it |
Predecessors for (3, 1): | Predecessors for (3, 1): | ||
Line 177: | Line 185: | ||
Predecessors for (0, 5): | Predecessors for (0, 5): | ||
- | * a: (3, 5) => mark it on the table | + | * a: (3, 5) => mark it |
* b: - | * b: - | ||
Line 189: | Line 197: | ||
=> The partitions are: {0, 3} and {1, 2, 4} | => The partitions are: {0, 3} and {1, 2, 4} | ||
+ | </note> | ||
</hidden> | </hidden> | ||
+ | |||
+ | |||
===== 5.2. Minimisation ====== | ===== 5.2. Minimisation ====== | ||
5.2.1. Minimise the DFA. (Solve the exercise for the 2 given DFAs.) | 5.2.1. Minimise the DFA. (Solve the exercise for the 2 given DFAs.) | ||
- | <hidden> | + | |
+ | <hidden DFA 1> | ||
** DFA 1 ** | ** DFA 1 ** | ||
Line 201: | Line 212: | ||
</hidden> | </hidden> | ||
- | <hidden> | + | <hidden DFA 2> |
** DFA 2 ** | ** DFA 2 ** | ||
{{ :lfa:2022:lfa2022_lab5_dfa2_min.png?400 |}} | {{ :lfa:2022:lfa2022_lab5_dfa2_min.png?400 |}} | ||
</hidden> | </hidden> | ||
+ | |||
5.2.2. How can we algorithmically determine if two minimal DFAs accept the same language? | 5.2.2. How can we algorithmically determine if two minimal DFAs accept the same language? | ||
+ | |||
+ | |||
<hidden><note tip> | <hidden><note tip> | ||
* assume the states are labeled as integers starting with 0, and that 0 is the unique initial state of both DFAs (this can be easily obtained from any previous transformation). | * assume the states are labeled as integers starting with 0, and that 0 is the unique initial state of both DFAs (this can be easily obtained from any previous transformation). | ||
Line 218: | Line 232: | ||
Another more elegant approach is to use state equivalence. We can treat two (not necessarily minimal) DFAs as one and the same, and compute the (in)distinguishability table over all states, in a single go. Finally, the DFAs accept the same language iff their initial states are indistinguishable. | Another more elegant approach is to use state equivalence. We can treat two (not necessarily minimal) DFAs as one and the same, and compute the (in)distinguishability table over all states, in a single go. Finally, the DFAs accept the same language iff their initial states are indistinguishable. | ||
</note></hidden> | </note></hidden> | ||
+ | |||
5.2.3. Determine if the following regexes are **equivalent**: $math[(1\cup\epsilon)(00^*1)^*0^*] and $math[(10\cup 0)^*(01 \cup 1)^*(0 \cup \epsilon)] | 5.2.3. Determine if the following regexes are **equivalent**: $math[(1\cup\epsilon)(00^*1)^*0^*] and $math[(10\cup 0)^*(01 \cup 1)^*(0 \cup \epsilon)] | ||
+ | |||
<hidden> | <hidden> | ||
- | The two languages are not equivalent because of word "110" which is accepted by the second regex, but rejected by the first regex. | + | <note tip>The two languages are not equivalent because of word "110" which is accepted by the second regex, but rejected by the first regex.</note> |
</hidden> | </hidden> | ||
- | 5.2.4. Remeber exercise 3.3.4 from Lab3. Show that the two regexes are equivalent: $ E1 = ((ab^*a)^+b)^* $ and $ E2 = (a(b\mid aa)^*ab)^* $ | + | |
+ | 5.2.4. Remember exercise 3.3.4 from Lab3. Show that the two regexes are equivalent: $ E1 = ((ab^*a)^+b)^* $ and $ E2 = (a(b\mid aa)^*ab)^* $ | ||
+ | |||
+ | |||
+ | <hidden> | ||
+ | <note tip> | ||
+ | There are several methods to do this. | ||
+ | |||
+ | 1. The first way will be presented in the next seminar. Using closure properties we will prove both the following properties: | ||
+ | * L(E1) ∩ L(E2) = ∅ | ||
+ | * L(complement(E1)) ∩ L(complement(E2)) = ∅ | ||
+ | |||
+ | 2. Check that the initial state of minDfa(E1) is indistinguishable from the initial state of minDfa(E2). | ||
+ | |||
+ | We will solve 2, but we will assume we have already computed minDfa for the 2 regular expressions and got the following DFAs as result: | ||
+ | |||
+ | |||
+ | {{ :lfa:2022:lfa2022_lab5_ex2_4.png?500 |}} | ||
+ | |||
+ | |||
+ | **Obs**: We can tell they are the same by looking at them but the computer needs an algorithm to check this equivalence. | ||
+ | |||
+ | ^ ^0 ^1 ^2 ^3 ^4 ^5 | ||
+ | |**0** | -| -| -| -| -| - | ||
+ | |**1** | X| -| -| -| -| - | ||
+ | |**2** | X| X| -| -| -| - | ||
+ | |**3** | | X| X| -| -| - | ||
+ | |**4** | X| | X| X| -| - | ||
+ | |**5** | X| X| | X| X| - | ||
+ | |||
+ | Initially marked pairs of (final, non-final) states: | ||
+ | * (0, 1) | ||
+ | * (0, 2) | ||
+ | * (0, 4) | ||
+ | * (0, 5) | ||
+ | * (3, 1) | ||
+ | * (3, 2) | ||
+ | * (3, 4) | ||
+ | * (3, 5) | ||
+ | |||
+ | Predecessors for (0, 1): | ||
+ | * a: - | ||
+ | * b: - | ||
+ | |||
+ | Predecessors for (0, 2): | ||
+ | * a: - | ||
+ | * b: (1, 2) => mark it | ||
+ | |||
+ | Predecessors for (0, 4): | ||
+ | * a: - | ||
+ | * b: - | ||
+ | |||
+ | Predecessors for (0, 5): | ||
+ | * a: - | ||
+ | * b: (1, 5) => mark it | ||
+ | |||
+ | Predecessors for (2, 1): | ||
+ | * a: (1, 2), (0, 2) => already marked | ||
+ | * b: - | ||
+ | |||
+ | Predecessors for (3, 1): | ||
+ | * a: - | ||
+ | * b: - | ||
+ | |||
+ | Predecessors for (5, 1): | ||
+ | * a: (3, 2), (4, 2) => mark them | ||
+ | * b: - | ||
+ | |||
+ | Predecessors for (3, 2): | ||
+ | * a: - | ||
+ | * b: (4, 2) => already marked | ||
+ | |||
+ | Predecessors for (4, 2): | ||
+ | * a: (5, 1), (5, 0) => already marked | ||
+ | * b: - | ||
+ | |||
+ | Predecessors for (4, 3): | ||
+ | * a: - | ||
+ | * b: - | ||
+ | |||
+ | Predecessors for (5, 3): | ||
+ | * a: - | ||
+ | * b: (5, 4) => mark it | ||
+ | |||
+ | Predecessors for (5, 4): | ||
+ | * a: (3, 5), (4, 5) => already marked | ||
+ | * b: - | ||
+ | |||
+ | So, we get 3 sets of indistinguishable states: {0, 3}, {1, 4} and {2, 5}. | ||
+ | |||
+ | Because states 0 and 3, which are initial states in the 2 DFAs, we can conclude that the 2 DFAs accept the same language. | ||
+ | |||
+ | </note></hidden> | ||
5.2.5. (extra) Apply the **Brzozowski** minimisation algorithm on DFA 1. | 5.2.5. (extra) Apply the **Brzozowski** minimisation algorithm on DFA 1. | ||
- | <note tip>Brzozowski minimisation: **minDfa(A) = toDfa(reverse(toDfa(reverse(A))))**</note> | + | |
+ | |||
+ | <note important>Brzozowski minimisation: **minDfa(A) = toDfa(reverse(toDfa(reverse(A))))**</note> | ||
<hidden> | <hidden> | ||
+ | <note tip> | ||
Step 1: ** Reverse(A) ** | Step 1: ** Reverse(A) ** | ||
* reverse transitions | * reverse transitions | ||
Line 240: | Line 353: | ||
* we can also not include the sink state in the reversal of the DFA | * we can also not include the sink state in the reversal of the DFA | ||
* the set of initial states is: {1, 2, 3, 4, 5} | * the set of initial states is: {1, 2, 3, 4, 5} | ||
+ | </note> | ||
{{ :lfa:2022:lfa2022_lab5_bmin_step1.png?400 |}} | {{ :lfa:2022:lfa2022_lab5_bmin_step1.png?400 |}} | ||
+ | <note tip> | ||
Step 2: **toDfa(Reverse(A))** | Step 2: **toDfa(Reverse(A))** | ||
+ | * rename the subsets as follows: {1,2,3,4,5} -> 1 and {1,3,4} -> 2 | ||
+ | </note> | ||
{{ :lfa:2022:lfa2022_lab5_bmin_step2.png?400 |}} | {{ :lfa:2022:lfa2022_lab5_bmin_step2.png?400 |}} | ||
- | * rename the subsets as follows: {1,2,3,4,5} -> 1 and {1,3,4} -> 2 | ||
+ | <note tip> | ||
Step 3: **Reverse(toDfa(Reverse(A)))** | Step 3: **Reverse(toDfa(Reverse(A)))** | ||
* we can ignore the sink state | * we can ignore the sink state | ||
* as previously, we remember a set of initial states: {1,2} | * as previously, we remember a set of initial states: {1,2} | ||
+ | </note> | ||
{{ :lfa:2022:lfa2022_lab5_bmin_step3.png?400 |}} | {{ :lfa:2022:lfa2022_lab5_bmin_step3.png?400 |}} | ||
+ | <note tip> | ||
Step 4: **toDfa(Reverse(toDfa(Reverse(A))))** | Step 4: **toDfa(Reverse(toDfa(Reverse(A))))** | ||
- | * This is minDfa(A) | + | * this is minDfa(A) |
+ | </note> | ||
{{ :lfa:2022:lfa2022_lab5_bmin_step4.png?400 |}} | {{ :lfa:2022:lfa2022_lab5_bmin_step4.png?400 |}} | ||
</hidden> | </hidden> | ||
+ | |||
+ | |||
===== Conclusion ===== | ===== Conclusion ===== | ||
Line 270: | Line 392: | ||
* DFA -> minDfa | * DFA -> minDfa | ||
- | We advise you to use this conversion when solving the project. | + | **To get a better performance, include minDfa conversion in your project.** |
</note> | </note> | ||