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:2022:lab03-dfa-regexp [2022/10/27 14:21]
pdmatei [3.3 Regex Equivalence]
lfa:2022:lab03-dfa-regexp [2022/10/28 22:42] (current)
alexandra.udrescu01
Line 12: Line 12:
 $ AB = ? $ $ AB = ? $
 \\ \\
-/*+
 <​hidden>​ <​hidden>​
  
Line 23: Line 23:
  
 </​hidden>​ </​hidden>​
-*/+
 **3.1.2.** **3.1.2.**
  
Line 31: Line 31:
 \\ \\
 $ AB = ? $ \\ $ BA = ? $ $ AB = ? $ \\ $ BA = ? $
-/*+
 <​hidden>​ <​hidden>​
  
Line 49: Line 49:
  
 </​hidden>​ </​hidden>​
-*/+
  
 **3.1.3.** **3.1.3.**
Line 63: Line 63:
 $ B^* = ? $ $ B^* = ? $
 \\ \\
-/*+
 <​hidden>​ <​hidden>​
  
Line 70: Line 70:
 A* = {ε} (epsilon is always part of Kleene star) A* = {ε} (epsilon is always part of Kleene star)
  
-B*= {ε} (epsilon is always part of Kleene star) U {1^n} U {(1^(2n)} U {1^(3n)} U ... +B*= {ε} (epsilon is always part of Kleene star) U {1^n $} U {1^{2n} $} U {1^{3n} $} U ... 
-So basically B = L( (1^n)* )+So basically B = L( ($1^n$)* )
  
 </​hidden>​ </​hidden>​
-*/+
  
 **3.1.4** **3.1.4**
Line 83: Line 83:
 \\ \\
 $ AB = ? $ \\ $ BA = ? $ $ AB = ? $ \\ $ BA = ? $
-/*+
 <​hidden>​ <​hidden>​
  
Line 94: Line 94:
  
 </​hidden>​ </​hidden>​
-*/+
 ===== 3.2. Writing Regular Expressions ===== ===== 3.2. Writing Regular Expressions =====
  
 **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>​
 We start by defining the regex for a number: We start by defining the regex for a number:
Line 117: Line 117:
  
 </​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 133: Line 133:
  
 </​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 147: Line 147:
 {{:​lfa:​graf1.png?​400|}} {{:​lfa:​graf1.png?​400|}}
  
-/*+
 <​hidden>​ <​hidden>​
  
Line 153: Line 153:
 Let's see what words are accepted: Let's see what words are accepted:
   * ab*ab (when we don't loop on state 1)   * ab*ab (when we don't loop on state 1)
-  * ab*(<a way to leave state 2 and return back to it>)*ab => ab*(aab*)ab+  * ab*(<a way to leave state 2 and return back to it>)*ab => ab*(aab*)*ab
   * anything that repeats the previous expression several times   * anything that repeats the previous expression several times
   * ε (the initial state is also a final state)   * ε (the initial state is also a final state)
   * from the previous 2 observations => we can use Kleene star   * from the previous 2 observations => we can use Kleene star
  So, the regex is:  So, the regex is:
-> ( ab*(aab*)ab )*+> ( ab*(aab*)*ab )*
  
 <​note>​ <​note>​
Line 169: Line 169:
  
 </​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.** 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)*] ​
Line 175: Line 175:
 (hint: BCD) (hint: BCD)
  
-/*+
 <​hidden>​ <​hidden>​
  
Line 201: Line 201:
 0000, 0010, 0100, 0110, 1000. 0000, 0010, 0100, 0110, 1000.
  
-So, this ugly regex encodes BCD numbers that start with exactly 2 odd digits which are followed by 0 or more eve +So, this ugly regex encodes BCD numbers that start with exactly 2 odd digits which are followed by 0 or more even digits.
-digits.+
 </​hidden>​ </​hidden>​
-*/+
  
 ===== 3.3 Regex Equivalence ===== ===== 3.3 Regex Equivalence =====
Line 216: Line 215:
 $ 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 222: Line 221:
 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 230: Line 229:
 $ 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 **
  
-$ E1 = (a|b)*aa*| {ε} $+$ E1 = (a\mid b)^*aa^\mid \epsilon ​$
 \\ \\
-$ E2 = (a|ba)*(b|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 251: Line 250:
 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 **
 +
 $ E1 = ((ab^*a)^+b)^* $ $ E1 = ((ab^*a)^+b)^* $
 \\ \\
-$ E2 = (a(b|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 271: Line 271:
 se. se.
 </​note></​hidden>​ </​note></​hidden>​
-*/+
  
 ==== Conclusion ==== ==== Conclusion ====