Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
lfa:2023:lab03 [2023/10/23 16:14] mihai.udubasa created |
lfa:2023:lab03 [2023/10/31 11:43] (current) alexandra.udrescu01 |
||
---|---|---|---|
Line 12: | Line 12: | ||
$ AB = ? $ | $ AB = ? $ | ||
\\ | \\ | ||
+ | |||
+ | |||
<hidden> | <hidden> | ||
Line 23: | Line 25: | ||
</hidden> | </hidden> | ||
+ | |||
+ | |||
**3.1.2.** | **3.1.2.** | ||
Line 31: | Line 35: | ||
\\ | \\ | ||
$ AB = ? $ \\ $ BA = ? $ | $ AB = ? $ \\ $ BA = ? $ | ||
+ | |||
<hidden> | <hidden> | ||
Line 63: | Line 68: | ||
$ B^* = ? $ | $ B^* = ? $ | ||
\\ | \\ | ||
+ | |||
<hidden> | <hidden> | ||
Line 83: | Line 89: | ||
\\ | \\ | ||
$ AB = ? $ \\ $ BA = ? $ | $ AB = ? $ \\ $ BA = ? $ | ||
+ | |||
<hidden> | <hidden> | ||
Line 94: | Line 101: | ||
</hidden> | </hidden> | ||
+ | |||
===== 3.2. Writing Regular Expressions ===== | ===== 3.2. Writing Regular Expressions ===== | ||
Line 99: | Line 107: | ||
**3.2.1.** Write a regular expression for the language of arithmetic expressions containing +, * and numbers. | **3.2.1.** Write a regular expression for the language of arithmetic expressions containing +, * and numbers. | ||
**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> | ||
Line 171: | Line 180: | ||
- | **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) | ||
Line 203: | Line 229: | ||
So, this ugly regex encodes BCD numbers that start with exactly 2 odd digits which are followed by 0 or more even digits. | So, this ugly regex encodes BCD numbers that start with exactly 2 odd digits which are followed by 0 or more even digits. | ||
</hidden> | </hidden> | ||
+ | */ | ||
===== 3.3 Regex Equivalence ===== | ===== 3.3 Regex Equivalence ===== |