Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== 3. Regular Expressions ====== ===== 3.1. Natural Language / DFA $ \rightarrow $ Regex conversion ===== For each of the exercises from DFA Seminary 1 write a regex describing the same language. **3.1.1.** $ L=\{w \in \{0,1\}^* \text{ | w contains an odd number of ones} \} $ {{:lfa:2022:lfa2022_lab2_ex1.png?400|}} <hidden 3.1.1.> $math[0^*10^*(10^*10^*)^*] </hidden> **3.1.2.** The language of binary words which contain **exactly** two ones {{:lfa:2022:lfa2022_lab2_ex2.png?550|}} <hidden 3.1.2.> $math[0^*10^*10^*] </hidden> **3.1.3.** The language of binary words which encode odd numbers (the last digit is least significative) {{:lfa:2022:lfa2022_lab2_ex3.png?300|}} <hidden 3.1.3.> $math[(0 \cup 1)^*1] </hidden> **3.1.4.** The set of all binary strings having the substring 00101 {{:lfa:2022:ex_8_dfa.png?400|}} <hidden 3.1.4.> $math[(0 \cup 1)^*00101(0 \cup 1)^*] </hidden> ===== 3.2. Formation rules (concatenation, reunion, Kleene star) ===== **3.2.1.** $math[A=\{ 0^{2k} \mid k \geq 1 \}] $ B = \{0, \epsilon \}$ \\ $ AB = ? $ \\ <hidden> A = {00, 0000, 00000000 ...} AB = {00, 00**0**, 0000, 0000**0**, ...} <- this is the cartesian product between the sets(languages) A and B, where the elements of A come first. * where the words in the language that have an even length are obtained by combining a word from A with the word ε from B * and those with an odd length are obtained by combining a word from A with the word 0 from B </hidden> **3.2.2.** $math[A = \{ 0^n 1^n \mid n \geq 1 \}] \\ $ B = \{ 1^n \mid n \geq 1 \} $ \\ $ AB = ? $ \\ $ BA = ? $ <hidden> 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). The notation of n in the definition of B is completely **unrelated** to the n used to define A. So, B is the language of words made of sequences of ones, having the length of at least 1, so basically B = L(11*). A = {01, 0011, 000111, 00001111 ...} B = {1, 11, 111 ...} AB = {01**1**, 0011**1**, 00001111**1**, ..., 01**11**, 0011**11**, 000111**11**, 00001111**11**, ... } BA = {**1**01, **1**0011, **1**000111, ..., **11**01, **11**0011, ..., **111**01, **111**0011 ...} </hidden> **3.2.3** $math[A = \{ 0^n 1^n 0^m \mid m \geq n \geq 1 \}] \\ $ B = \{ 0^n \mid n \geq 1 \} $ \\ $ AB = ? $ \\ $ BA = ? $ <hidden> $math[AB = \{ 0^n 1^n 0^{m+k} \mid m \geq n \geq 1, k \geq 1 \}]. Deci $math[AB = A]. Note that the n in the definition of language A **is different** from the n in in the definition of B, they are **independent** when used in defining different sets/languages. However, when n is used several times in the definition of one language, such as the 2 times it appears in language A, it is **the same** value. $math[BA = \{ 0^{(n+k)} 1^n 0^m \mid m \geq n \geq 1, k \geq 1 \}]. Equivalently: $math[BA = \{0^x 1^y 0^z \mid x \geq y\geq 1 \text{ and } z \geq y \geq 1 \}] </hidden> **3.2.4.** $ A = ∅ $ \\ $ B = \{ 1^n \mid n \geq 1 \} $ \\ $ AB = ? $ \\ $ A^* = ? $ \\ $ B^* = ? $ \\ <hidden> AB = ∅ (because A is empty, so the cartesian product leads to an empty set) 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 ... So basically B = L( ($1^n$)* ) </hidden>