Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lfa:2023:lab02 [2024/10/05 00:52]
stefan.sterea
lfa:2023:lab02 [2024/10/06 21:30] (current)
stefan.sterea old revision restored (2023/10/31 11:44)
Line 4: Line 4:
  
 <​note>​ <​note>​
-  * Double-circle ​= final state +  * Blue = final state 
-  * Hanging arrow entering state initial ​state+  * Orange ​non-final ​state
   * Sink state = a state that is not final; once reached, there is no transition that leaves it, thus the DFA will reject; there is a transition that loops in this state for each possible character   * Sink state = a state that is not final; once reached, there is no transition that leaves it, thus the DFA will reject; there is a transition that loops in this state for each possible character
 </​note>​ </​note>​
Line 15: Line 15:
  
  
-/*<​hidden>​+<​hidden>​
 {{:​lfa:​2022:​lfa2022_lab2_ex1.png?​400|}} {{:​lfa:​2022:​lfa2022_lab2_ex1.png?​400|}}
   * State 0 = currently counted an even number of 1s [initial state]   * State 0 = currently counted an even number of 1s [initial state]
Line 23: Line 23:
       * If we were on state 0, it means we counted until the previous step an even number of ones. Now we have an odd number of ones, so we need to move to state 1.       * If we were on state 0, it means we counted until the previous step an even number of ones. Now we have an odd number of ones, so we need to move to state 1.
       * If we were on state 1, it means we counted until the previous step an odd number of ones. Now we have an even number of ones, so we need to move to state 0.       * If we were on state 1, it means we counted until the previous step an odd number of ones. Now we have an even number of ones, so we need to move to state 0.
-</​hidden>​*/+</​hidden>​
  
  
Line 29: Line 29:
  
  
-/*<​hidden>​+<​hidden>​
 {{:​lfa:​2022:​lfa2022_lab2_ex2.png?​550|}} {{:​lfa:​2022:​lfa2022_lab2_ex2.png?​550|}}
   * State 0: no ones have been found yet [initial state]   * State 0: no ones have been found yet [initial state]
Line 35: Line 35:
   * State 2: 2 ones have been found so far [final state]   * State 2: 2 ones have been found so far [final state]
   * State 3: more than 2 ones have been found so far [sink state]   * State 3: more than 2 ones have been found so far [sink state]
-</​hidden>​*/+</​hidden>​
  
  
Line 41: Line 41:
  
  
-/*<​hidden>​+<​hidden>​
 {{:​lfa:​2022:​lfa2022_lab2_ex3.png?​300|}} {{:​lfa:​2022:​lfa2022_lab2_ex3.png?​300|}}
   * We pass through the word, marking the parity of the last character that we have read.   * We pass through the word, marking the parity of the last character that we have read.
-</​hidden>​*/+</​hidden>​
  
  
Line 70: Line 70:
  
  
-/*<​hidden>​+<​hidden>​
 {{:​lfa:​2022:​lfa2022_lab2_ex5.png?​600|}} {{:​lfa:​2022:​lfa2022_lab2_ex5.png?​600|}}
   * Note: Checking for months with 30 or 31 days can be done with a slightly bigger DFA.   * Note: Checking for months with 30 or 31 days can be done with a slightly bigger DFA.
   * Note: Even checking for bisect years (29 Feb) can still be done with a DFA, but it's too big to do as a seminar example.   * Note: Even checking for bisect years (29 Feb) can still be done with a DFA, but it's too big to do as a seminar example.
-</​hidden>​*/+</​hidden>​
  
  
Line 91: Line 91:
  
  
-/*<​hidden>​+<​hidden>​
 {{:​lfa:​2022:​ex_8_dfa.png?​400|}} {{:​lfa:​2022:​ex_8_dfa.png?​400|}}
   * Every state corresponds to a certain current configuration (eg. state **B** translates to a sequence of **0**; **C** to a seq of **00**; **D** -> **001** and so on)   * Every state corresponds to a certain current configuration (eg. state **B** translates to a sequence of **0**; **C** to a seq of **00**; **D** -> **001** and so on)
   * Analyze how each incoming character changes the current available sequence. For example, if we are in state **E** and we read character **1** we reach a final state, but if we read **0** we go back to state **C** since the available seq will be **00** ​   * Analyze how each incoming character changes the current available sequence. For example, if we are in state **E** and we read character **1** we reach a final state, but if we read **0** we go back to state **C** since the available seq will be **00** ​
-</​hidden>​*/+</​hidden>​
  
  
-=== Describe the language of the following ​DFA and simulate them on the given inputs: === +=== Describe the language of the following ​DFAs and simulate them on the given inputs: ===
- +
-All states are final+
  
 **2.1.8.** w<​sub>​1</​sub>​ = 10011110, w<​sub>​2</​sub>​ = 00110010 **2.1.8.** w<​sub>​1</​sub>​ = 10011110, w<​sub>​2</​sub>​ = 00110010
Line 106: Line 104:
 {{:​lfa:​2022:​lfa2022_lab2_ex8.png?​400|}} {{:​lfa:​2022:​lfa2022_lab2_ex8.png?​400|}}
  
-/*<​hidden>​+<​hidden>​
   * The language of binary words where there are no sequences in which the same character repeats 3 or more times.   * The language of binary words where there are no sequences in which the same character repeats 3 or more times.
   * regex: $math[(11 \cup 1 \cup \epsilon) ( (00 \cup 0) 1 (1 \cup \epsilon) )^* (00 \cup 0 \cup \epsilon)]   * regex: $math[(11 \cup 1 \cup \epsilon) ( (00 \cup 0) 1 (1 \cup \epsilon) )^* (00 \cup 0 \cup \epsilon)]
   * (0, **10011110**) |--<​sub>​A</​sub>​ (11, 0011110) |--<​sub>​A</​sub>​ (01, 011110) |--<​sub>​A</​sub>​ (02, 11110) |--<​sub>​A</​sub>​ (11, 1110) |--<​sub>​A</​sub>​ (12, 110) [There is no transition, so we go to a sink state which is not figured on the drawing.] |--<​sub>​A</​sub>​ (sink, 10) |--<​sub>​A</​sub>​ (sink, 0) |--<​sub>​A</​sub>​ (sink, $math[\epsilon]) ​ The sink state is not a final state, so this word is **rejected**.   * (0, **10011110**) |--<​sub>​A</​sub>​ (11, 0011110) |--<​sub>​A</​sub>​ (01, 011110) |--<​sub>​A</​sub>​ (02, 11110) |--<​sub>​A</​sub>​ (11, 1110) |--<​sub>​A</​sub>​ (12, 110) [There is no transition, so we go to a sink state which is not figured on the drawing.] |--<​sub>​A</​sub>​ (sink, 10) |--<​sub>​A</​sub>​ (sink, 0) |--<​sub>​A</​sub>​ (sink, $math[\epsilon]) ​ The sink state is not a final state, so this word is **rejected**.
   * (0, **00110010**) |--<​sub>​A</​sub>​ (01, 0110010) |--<​sub>​A</​sub>​ (02, 110010) |--<​sub>​A</​sub>​ (11, 10010) |--<​sub>​A</​sub>​ (12, 0010) |--<​sub>​A</​sub>​ (01, 010) |--<​sub>​A</​sub>​ (02, 10) |--<​sub>​A</​sub>​ (11, 0) |--<​sub>​A</​sub>​ (01, $math[\epsilon]) The word is **accepted** by the DFA because we reached a final state (blue).   * (0, **00110010**) |--<​sub>​A</​sub>​ (01, 0110010) |--<​sub>​A</​sub>​ (02, 110010) |--<​sub>​A</​sub>​ (11, 10010) |--<​sub>​A</​sub>​ (12, 0010) |--<​sub>​A</​sub>​ (01, 010) |--<​sub>​A</​sub>​ (02, 10) |--<​sub>​A</​sub>​ (11, 0) |--<​sub>​A</​sub>​ (01, $math[\epsilon]) The word is **accepted** by the DFA because we reached a final state (blue).
-</​hidden>​*/+</​hidden>​
  
-===== 2.2. Describing the language of DFAs =====+===== 2.2. Regex practice ​=====
  
-Describe in natural speak the language accepted by these DFAs. Make sure your description is fit to the DFA and not too broad (covers all words accepted and no other word).+For each of the exercises from DFA practice write a regex describing the same language.
  
  
-**2.2.1**+<​hidden ​2.2.1.> 
 +$math[0^*10^*(10^*10^*)^*
 +</​hidden>​
  
-{{:​lfa:​2024:​lab1-2_2_1.png?​400|}} 
  
-**2.2.2**+<​hidden ​2.2.2.> 
 +$math[0^*10^*10^*
 +</​hidden>​
  
-{{:​lfa:​2024:​lab1-2_2_2.png?​300|}} 
  
-**2.2.3**+<​hidden ​2.2.3.> 
 +$math[(0 \cup 1)^*1] 
 +</​hidden>​
  
-{{:​lfa:​2024:​lab1-2_2_3.png?​500|}} 
  
-**2.2.4**+<hidden 2.2.4.>​ 
 +creating the regex directly is not easy, but the pattern can be derived by studying the dfa, and trying to '​replace'​ states with more complex transitions. For a step-by-step description of the method, wait until the lecture/lab about the dfa to regex transformation algorithm 
 + 
 + 
 +$math[((1(01^*0)^*1)\cup0)^*] 
 + 
 +</​hidden>​ 
 + 
 + 
 +<​hidden ​2.2.5.> 
 +$(0[1-9])\cup((1\cup2)[0-9])\cup(3(0\cup1))/​((0[1-9])\cup(1(0\cup1\cup2))/​[0-9][0-9][0-9][0-9])$ 
 +</​hidden>​ 
 + 
 +<hidden 2.2.6.>​ 
 +This language is a good example of a language which is significantly easier to describe using a dfa rather than a regex. The regex is very hard to build intuitively and is very long. For a way to algorithmically build this regex from the dfa built during the first part, wait until the lab/lecture about the dfa->​regex transformation. 
 +</​hidden>​ 
 + 
 +<hidden 2.2.7> 
 +$math[(0 \cup 1)^*00101(0 \cup 1)^*
 +</​hidden>​
  
-{{:​lfa:​2024:​lab1-2_2_4.png?​300|}}