Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2023:lab03 [2023/10/23 16:17] mihai.udubasa |
lfa:2023:lab03 [2023/10/31 11:43] (current) alexandra.udrescu01 |
||
---|---|---|---|
Line 14: | Line 14: | ||
- | /* | + | |
<hidden> | <hidden> | ||
Line 25: | Line 25: | ||
</hidden> | </hidden> | ||
- | */ | + | |
Line 36: | Line 36: | ||
$ AB = ? $ \\ $ BA = ? $ | $ AB = ? $ \\ $ BA = ? $ | ||
- | /* | + | |
<hidden> | <hidden> | ||
Line 54: | Line 54: | ||
</hidden> | </hidden> | ||
- | */ | + | |
**3.1.3.** | **3.1.3.** | ||
Line 69: | Line 69: | ||
\\ | \\ | ||
- | /* | + | |
<hidden> | <hidden> | ||
Line 80: | Line 80: | ||
</hidden> | </hidden> | ||
- | */ | + | |
**3.1.4** | **3.1.4** | ||
Line 90: | Line 90: | ||
$ AB = ? $ \\ $ BA = ? $ | $ AB = ? $ \\ $ BA = ? $ | ||
- | /* | + | |
<hidden> | <hidden> | ||
Line 101: | Line 101: | ||
</hidden> | </hidden> | ||
- | */ | + | |
===== 3.2. Writing Regular Expressions ===== | ===== 3.2. Writing Regular Expressions ===== | ||
Line 108: | Line 108: | ||
**Hint:** you can abbreviate $ 0 \cup 1 \cup ... \cup 9 $ by $ [0-9] $ | **Hint:** you can abbreviate $ 0 \cup 1 \cup ... \cup 9 $ by $ [0-9] $ | ||
- | /* | + | |
<hidden> | <hidden> | ||
We start by defining the regex for a number: | We start by defining the regex for a number: | ||
Line 126: | Line 126: | ||
</hidden> | </hidden> | ||
- | */ | + | |
**3.2.2.** Write a regular expression for $ L = \{ \omega \text{ in } \text{{0,1}} ^* \text{ | EVERY sequence of two or more consecutive zeros appears before ANY sequence of two or more consecutive ones} \} $ | **3.2.2.** Write a regular expression for $ L = \{ \omega \text{ in } \text{{0,1}} ^* \text{ | EVERY sequence of two or more consecutive zeros appears before ANY sequence of two or more consecutive ones} \} $ | ||
- | /* | + | |
<hidden> | <hidden> | ||
Line 142: | Line 142: | ||
</hidden> | </hidden> | ||
- | */ | + | |
**3.2.3.** Write a DFA for $ L(( 10 \cup 0) ^* ( 1 \cup \epsilon )) $ | **3.2.3.** Write a DFA for $ L(( 10 \cup 0) ^* ( 1 \cup \epsilon )) $ | ||
- | /* | + | |
<hidden> | <hidden> | ||
{{:lfa:2022:lfa2022_lab_3.2.3.png?300|}} | {{:lfa:2022:lfa2022_lab_3.2.3.png?300|}} | ||
</hidden> | </hidden> | ||
- | */ | + | |
**3.2.4.** Write a regular expression which generates the accepted language of A. Then try to find the most simple and easy to understand way to write it. | **3.2.4.** Write a regular expression which generates the accepted language of A. Then try to find the most simple and easy to understand way to write it. | ||
Line 156: | Line 156: | ||
{{:lfa:graf1.png?400|}} | {{:lfa:graf1.png?400|}} | ||
- | /* | + | |
<hidden> | <hidden> | ||
Line 178: | Line 178: | ||
</hidden> | </hidden> | ||
- | */ | ||
- | **3.2.5.** Describe as precisely as possible the language generated by $math[((0(1 \cup 0)(1 \cup 0)) \cup 100)1((0(1 \cup 0)(1 \cup 0)) \cup 100)1(((0(1 \cup 0)(1 \cup 0)) \cup 100)0)*] | + | |
+ | **3.2.5.** | ||
+ | Find a regular expression for the set of all binary strings with the property that none of its prefixes has two more 0's than 1's nor two more 1's than 0's. | ||
+ | |||
+ | |||
+ | |||
+ | <hidden> | ||
+ | |||
+ | We the given property implies that the word is composed of repeated sequences of '10' and '01' (so elements at odd positions are different from their left neighbour), possibly followed by a final 1 or 0: | ||
+ | |||
+ | After any prefix of even length with an equal number of 0's and 1's (including $\epsilon$), you can either finish the word, add a single character and then finish the word (both of these keeping the rule true) or add at least 2 characters. In the last case, if the characters are equal the prefix ending at these two characters breaks the rule. | ||
+ | |||
+ | $(01\cup10)^*(0\cup1\cup\epsilon)$ | ||
+ | |||
+ | </hidden> | ||
+ | |||
+ | |||
+ | /* this is the old exercise | ||
+ | Describe as precisely as possible the language generated by $math[((0(1 \cup 0)(1 \cup 0)) \cup 100)1((0(1 \cup 0)(1 \cup 0)) \cup 100)1(((0(1 \cup 0)(1 \cup 0)) \cup 100)0)*] | ||
(hint: BCD) | (hint: BCD) | ||
- | /* | + | |
<hidden> | <hidden> | ||
Line 224: | Line 241: | ||
$ E2 = (a|\epsilon)(b|\epsilon) $ | $ E2 = (a|\epsilon)(b|\epsilon) $ | ||
- | /* | + | |
<hidden><note important> | <hidden><note important> | ||
We can observe that E2 accepts ε, while E1 does not so they are not equivalent. | We can observe that E2 accepts ε, while E1 does not so they are not equivalent. | ||
Line 230: | Line 247: | ||
Another approach is to compute the language of each expression (since they are finite) and check if they are equivalent. | Another approach is to compute the language of each expression (since they are finite) and check if they are equivalent. | ||
</note></hidden> | </note></hidden> | ||
- | */ | + | |
** 3.3.2 ** | ** 3.3.2 ** | ||
Line 238: | Line 255: | ||
$ E2 = ab(b|c|d|e)|acd|ace $ | $ E2 = ab(b|c|d|e)|acd|ace $ | ||
- | /* | + | |
<hidden><note important> | <hidden><note important> | ||
Since both E1 and E2 have a finite language, we could just compute the language and check if they are equivalent. | Since both E1 and E2 have a finite language, we could just compute the language and check if they are equivalent. | ||
Language is L = {abb, abc, abd, abe, acd, ace}, therefore they are equivalent. | Language is L = {abb, abc, abd, abe, acd, ace}, therefore they are equivalent. | ||
</note></hidden> | </note></hidden> | ||
- | */ | + | |
** 3.3.3 ** | ** 3.3.3 ** | ||
Line 251: | Line 268: | ||
$ E2 = (a\mid ba)^*(b\mid ba)^* $ | $ E2 = (a\mid ba)^*(b\mid ba)^* $ | ||
- | /* | + | |
<hidden><note important> | <hidden><note important> | ||
Both E1 and E2 have an infinite language, so comparing them is not an option. | Both E1 and E2 have an infinite language, so comparing them is not an option. | ||
Line 259: | Line 276: | ||
Fun fact: E1 was proposed by a student as a solution for 3.2.2 last year, while E2 is the actual solution. | Fun fact: E1 was proposed by a student as a solution for 3.2.2 last year, while E2 is the actual solution. | ||
</note></hidden> | </note></hidden> | ||
- | */ | + | |
** 3.3.4 ** | ** 3.3.4 ** | ||
Line 267: | Line 284: | ||
$ E2 = (a(b\mid aa)^*ab)^* $ | $ E2 = (a(b\mid aa)^*ab)^* $ | ||
- | /* | + | |
<hidden><note important> | <hidden><note important> | ||
Both E1 and E2 have an infinite language, so comparing them is not an option. | Both E1 and E2 have an infinite language, so comparing them is not an option. | ||
Line 280: | Line 297: | ||
se. | se. | ||
</note></hidden> | </note></hidden> | ||
- | */ | + | |
==== Conclusion ==== | ==== Conclusion ==== |