Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2023:lab02 [2023/10/17 09:30] mihai.udubasa |
lfa:2023:lab02 [2024/10/06 21:30] (current) stefan.sterea old revision restored (2023/10/31 11:44) |
||
---|---|---|---|
Line 14: | Line 14: | ||
**2.1.1.** $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of ones} \} $ | **2.1.1.** $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of ones} \} $ | ||
- | /* | + | |
<hidden> | <hidden> | ||
{{:lfa:2022:lfa2022_lab2_ex1.png?400|}} | {{:lfa:2022:lfa2022_lab2_ex1.png?400|}} | ||
Line 24: | Line 24: | ||
* 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> | ||
- | */ | + | |
**2.1.2.** The language of binary words which contain **exactly** two ones | **2.1.2.** The language of binary words which contain **exactly** two ones | ||
- | /* | + | |
<hidden> | <hidden> | ||
{{:lfa:2022:lfa2022_lab2_ex2.png?550|}} | {{:lfa:2022:lfa2022_lab2_ex2.png?550|}} | ||
Line 36: | Line 36: | ||
* 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> | ||
- | */ | + | |
**2.1.3.** The language of binary words which encode odd numbers (the last digit is least significative) | **2.1.3.** The language of binary words which encode odd numbers (the last digit is least significative) | ||
- | /* | + | |
<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> | ||
- | */ | + | |
**2.1.4.** (hard) The language of words which encode numbers divisible by 3 | **2.1.4.** (hard) The language of words which encode numbers divisible by 3 | ||
- | /* | + | |
<hidden> | <hidden> | ||
{{:lfa:2022:lfa2022_lab2_ex4.png?400|}} | {{:lfa:2022:lfa2022_lab2_ex4.png?400|}} | ||
Line 64: | Line 64: | ||
* 3k + 2 --(*2)--> 3k + 1 --(+1)--> 3k + 2 | * 3k + 2 --(*2)--> 3k + 1 --(+1)--> 3k + 2 | ||
</hidden> | </hidden> | ||
- | */ | + | |
**2.1.5.** The language of words that encode a calendar date (DD/MM/YYYY) | **2.1.5.** The language of words that encode a calendar date (DD/MM/YYYY) | ||
(do not overthink about the actual number of days in a month) | (do not overthink about the actual number of days in a month) | ||
- | /* | + | |
<hidden> | <hidden> | ||
{{:lfa:2022:lfa2022_lab2_ex5.png?600|}} | {{:lfa:2022:lfa2022_lab2_ex5.png?600|}} | ||
Line 75: | Line 75: | ||
* 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> | ||
- | */ | + | |
**2.1.6.** (HARD) $ L=\{w \in \{0,1,2,3\}^* \text{ | w follows the rule that every zero is immediately followed by a sequence of at least 2 consecutive threes and every one is immediately followed by a sequence of at most 2 consecutive twos} \} $ | **2.1.6.** (HARD) $ L=\{w \in \{0,1,2,3\}^* \text{ | w follows the rule that every zero is immediately followed by a sequence of at least 2 consecutive threes and every one is immediately followed by a sequence of at most 2 consecutive twos} \} $ | ||
- | /* | + | |
<hidden> | <hidden> | ||
{{:lfa:2022:lfa2022_lab2_ex6_v2.png?400|}} | {{:lfa:2022:lfa2022_lab2_ex6_v2.png?400|}} | ||
- | /* | ||
- | {{:lfa:2022:lfa2022_lab2_ex6.png?400|}} - this is wrong, some transitions are missing*/ | ||
* injuraturile redirectati-le catre AU :)) (si MP) | * injuraturile redirectati-le catre AU :)) (si MP) | ||
* All missing transitions lead to a sink state (where there is a transition that loops in that state for any character) | * All missing transitions lead to a sink state (where there is a transition that loops in that state for any character) | ||
</hidden> | </hidden> | ||
- | */ | + | |
+ | |||
+ | **2.1.7.** The set of all binary strings having the substring 00101 | ||
+ | |||
+ | |||
+ | <hidden> | ||
+ | {{: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) | ||
+ | * 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> | ||
=== Describe the language of the following DFAs and simulate them on the given inputs: === | === Describe the language of the following DFAs and simulate them on the given inputs: === | ||
- | **2.1.7.** w<sub>1</sub> = 10011110, w<sub>2</sub> = 00110010 | + | **2.1.8.** w<sub>1</sub> = 10011110, w<sub>2</sub> = 00110010 |
{{: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. | ||
Line 102: | Line 110: | ||
* (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. Regex practice ===== | ===== 2.2. Regex practice ===== | ||
For each of the exercises from DFA practice write a regex describing the same language. | For each of the exercises from DFA practice write a regex describing the same language. | ||
- | /* | + | |
<hidden 2.2.1.> | <hidden 2.2.1.> | ||
$math[0^*10^*(10^*10^*)^*] | $math[0^*10^*(10^*10^*)^*] | ||
Line 140: | Line 148: | ||
</hidden> | </hidden> | ||
- | */ | + | <hidden 2.2.7> |
+ | $math[(0 \cup 1)^*00101(0 \cup 1)^*] | ||
+ | </hidden> |