Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2024:lab03 [2024/10/20 12:54] cata_chiru |
lfa:2024:lab03 [2024/10/22 08:13] (current) cata_chiru |
||
---|---|---|---|
Line 50: | Line 50: | ||
\\ | \\ | ||
- | <hidden> | + | <hidden 3.2.1> |
A = {00, 0000, 00000000 ...} | A = {00, 0000, 00000000 ...} | ||
Line 69: | Line 69: | ||
$ AB = ? $ \\ $ BA = ? $ | $ AB = ? $ \\ $ BA = ? $ | ||
- | <hidden> | + | <hidden 3.2.2> |
A is the language in which the words start with zero and end with one and the number of one is equal to the number of zeros (the same value for n is used). | A is the language in which the words start with zero and end with one and the number of one is equal to the number of zeros (the same value for n is used). | ||
Line 94: | Line 94: | ||
- | <hidden> | + | <hidden 3.2.3> |
$math[AB = \{ 0^n 1^n 0^{m+k} \mid m \geq n \geq 1, k \geq 1 \}]. Deci $math[AB = A]. | $math[AB = \{ 0^n 1^n 0^{m+k} \mid m \geq n \geq 1, k \geq 1 \}]. Deci $math[AB = A]. | ||
Line 116: | Line 116: | ||
- | <hidden> | + | <hidden 3.2.4> |
AB = ∅ (because A is empty, so the cartesian product leads to an empty set) | AB = ∅ (because A is empty, so the cartesian product leads to an empty set) | ||
Line 126: | Line 126: | ||
</hidden> | </hidden> | ||
+ | |||
+ | |||
+ | ===== 3.3 Regex Equivalence ===== | ||
+ | |||
+ | Are the following regex pair equivalent? | ||
+ | |||
+ | ** 3.3.1 ** | ||
+ | |||
+ | $ E1 = ab|a|b $ | ||
+ | \\ | ||
+ | $ E2 = (a|\epsilon)(b|\epsilon) $ | ||
+ | |||
+ | |||
+ | <hidden 3.3.1><note important> | ||
+ | We can observe that E2 accepts ε, while E1 does not so they are not equivalent. | ||
+ | \\ | ||
+ | Another approach is to compute the language of each expression (since they are finite) and check if they are equivalent. | ||
+ | </note></hidden> | ||
+ | |||
+ | |||
+ | ** 3.3.2 ** | ||
+ | |||
+ | $ E1 = a(b|c)(d|e)|abb|abc $ | ||
+ | \\ | ||
+ | $ E2 = ab(b|c|d|e)|acd|ace $ | ||
+ | |||
+ | |||
+ | <hidden 3.3.2><note important> | ||
+ | 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. | ||
+ | </note></hidden> | ||
+ | |||
** 3.3.3 ** | ** 3.3.3 ** | ||
Line 134: | Line 166: | ||
- | <hidden><note important> | + | <hidden 3.3.3><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. | ||
We can see that for example E2 accepts b, while E1 does not accept it, so the expressions are not equivalent. | We can see that for example E2 accepts b, while E1 does not accept it, so the expressions are not equivalent. | ||
- | 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.4.1 some year ago, while E2 is the actual solution. |
</note></hidden> | </note></hidden> | ||
Line 150: | Line 182: | ||
- | <hidden><note important> | + | <hidden 3.3.4><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 162: | Line 194: | ||
se. | se. | ||
</note></hidden> | </note></hidden> | ||
- | |||
Line 171: | Line 202: | ||
- | <hidden> | + | <hidden 3.4.0> |
We start by defining the regex for a number: | We start by defining the regex for a number: | ||
Line 193: | Line 224: | ||
- | <hidden> | + | <hidden 3.4.1> |
> (1 U ε) ( 0 0* (1 U ε) )* (0 U ε) ( 1 1* (0 U ε) )* | > (1 U ε) ( 0 0* (1 U ε) )* (0 U ε) ( 1 1* (0 U ε) )* | ||
Line 209: | Line 240: | ||
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. | 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> | + | <hidden 3.4.2> |
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: | 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: | ||
Line 219: | Line 250: | ||
</hidden> | </hidden> | ||
- | **3.4.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.4.3.** 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. |
{{:lfa:graf1.png?400|}} | {{:lfa:graf1.png?400|}} | ||
- | <hidden> | + | <hidden 3.4.3> |
Looking at the DFA we can tell state 3 is a sink state. We can simplify the DFA's drawing by not looking at/ignoring it. | Looking at the DFA we can tell state 3 is a sink state. We can simplify the DFA's drawing by not looking at/ignoring it. | ||
Line 248: | Line 279: | ||
==== Conclusion ==== | ==== Conclusion ==== | ||
- | <hidden><note important> | + | <hidden Conclusion ><note important> |
What have we learned today? | What have we learned today? | ||