Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== 5. Minimal DFAs ====== Consider the following DFA (blue states are final): {{ :lfa:screenshot_2021-11-03_at_11.25.00.png?400 |}} ===== 5.1. Equivalence between states ===== 5.1.1. Identify a pair of states which are **indistinguishable**. 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. 5.1.3. Compute the table of indistinguishable states for the DFA. ===== 5.2. Minimisation ====== 5.2.1. Minimise the DFA. 5.2.2. How can we algorithmically determine if two minimal DFAs accept the same language? <hidden><note tip> Without loss of generality, assume the states are labeled with numbers starting from 0 and 0 is their initial state. Give an ordering to the symbols of the alphabet and perform a DFS on the two DFAs simultaneously, relabeling the states as you discover them with the lowest label number available. Always choose transitions according to the given order of the alphabet. At the end, check whether their transition tables are identical and they have the same final states. 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> 5.2.3. 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.4. (**Optional**) Determine if the following regexes are **equivalent**: $ (1\cup\epsilon)(00^*1)^*0^* $ and $ (10\cup 0)^*(01 \cup 1)^*(0 \cup \epsilon) $ 5.2.5. Consider the following sequence of DFAs $ D_n $ which all accept the language $ L(a^+b^*) $. {{:lfa:2024:lab6-2_5_d0.png?300 |}} {{:lfa:2024:lab6-2_5_d1.png?450|}} {{:lfa:2024:lab6-2_5_d2.png?450|}} ...and so on <hidden Formal definition of the sequence above> <note> \begin{align*} &D_n = (K_n, \Sigma, \delta_n, q_0, F_n) & &n \geq 0 \\ &K_n = \{S, X\} \cup \{A_i, B_i\}_{i=0}^n \\ &\Sigma = \{a, b\} \hspace{3em} q_0 = S & &F_n = \{A_i, B_i\}_{i=0}^n \\ \end{align*} \begin{align*} \delta_n(S, a) &= A_n & \delta_n(A_0, a) &= A_0 & \delta_n(A_i, a) &= A_{i-1} & &i \geq 1 \\ \delta_n(S, b) &= X & \delta_n(A_0, b) &= B_n & \delta_n(A_i, b) &= B_n & &i \geq 1 \\ \delta_n(X, a) &= X & \delta_n(B_0, a) &= X & \delta_n(B_i, a) &= X & &i \geq 1 \\ \delta_n(X, b) &= X & \delta_n(B_0, b) &= B_0 & \delta_n(B_i, b) &= B_{i-1} & &i \geq 1 \end{align*} </note> </hidden> Use Hopcroft's algorithm to minimise the first few DFAs in the sequence. Count the number of steps performed and the number of splits. Determine the time complexity of the algorithm. {{:lfa:2024:lab6-hopcroft.png?500|}} 5.2.6. (**Extra**) Apply the **Brzozowski** minimisation algorithm on DFA 1. <note important>Brzozowski minimisation: **minDfa(A) = toDfa(reverse(toDfa(reverse(A))))**</note> <hidden> <note tip> Step 1: ** Reverse(A) ** * reverse transitions * the initial state becomes final in Reverse(A) * the final state becomes initial in Reverse(A), but here we have more final states: * normally, to compute Reverse(A) we should add a new initial state in Reverse(A); the final states in A become non-final in Reverse(A); then add $\varepsilon$ - transitions from the new initial state of Reverse(A) to the former final states of A * for Brzozowski's minimization algorithm however, we will not add this new initial state and, instead, we will start the subset construction in Step 2 from the set of final states that were in A, that now become "multiple" initial states in Reverse(A) * 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} </note> {{ :lfa:2022:lfa2022_lab5_bmin_step1.png?400 |}} <note tip> 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 |}} <note tip> Step 3: **Reverse(toDfa(Reverse(A)))** * we can ignore the sink state * as previously, we remember a set of initial states: {1,2} </note> {{ :lfa:2022:lfa2022_lab5_bmin_step3.png?400 |}} <note tip> Step 4: **toDfa(Reverse(toDfa(Reverse(A))))** * this is minDfa(A) </note> {{ :lfa:2022:lfa2022_lab5_bmin_step4.png?400 |}} </hidden> ===== Conclusion ===== <note important> Now we can do a complete transformation of a regex into a minimal DFA. * Regex -> NFA (Thomson's algorithm) * NFA -> DFA (Subset Construction) * DFA -> minDfa </note>