Differences
This shows you the differences between two versions of the page.
lfa:2023:lab07 [2023/11/21 09:13] mihai.udubasa created |
lfa:2023:lab07 [2023/12/04 15:03] (current) alexandra.udrescu01 |
||
---|---|---|---|
Line 3: | Line 3: | ||
**7.1.1.** Identify **different strategies** to verify that two regular expressions generate the same language. State them as algorithmic procedures. | **7.1.1.** Identify **different strategies** to verify that two regular expressions generate the same language. State them as algorithmic procedures. | ||
- | /* | ||
<hidden> All strategies require building DFAs from the regexes. | <hidden> All strategies require building DFAs from the regexes. | ||
- You can use an existing minimisation algorithm to find the minimal DFAs. Then, label each state from each DFA from 0 to |K|. Fix an ordering of the symbols of the alphabet. Sort the transitions by symbol. Make a textual representation of each DFA which includes the number of states and the sorted transition function. If the textual representations of the two DFAs are identical then they accept the same language. | - You can use an existing minimisation algorithm to find the minimal DFAs. Then, label each state from each DFA from 0 to |K|. Fix an ordering of the symbols of the alphabet. Sort the transitions by symbol. Make a textual representation of each DFA which includes the number of states and the sorted transition function. If the textual representations of the two DFAs are identical then they accept the same language. | ||
Line 9: | Line 8: | ||
- Check $math[L(A_1) \subseteq L(A_2)] and $math[L(A_2) \subseteq L(A_1)]. The condition $math[L(A) \subseteq L(B)] can be restated as $math[L(A) \cap complement(L(B)) = \emptyset]. Build the complement DFA for B, and use the product construction with A. Check if the resulting DFA has any final state accessible from the initial one. | - Check $math[L(A_1) \subseteq L(A_2)] and $math[L(A_2) \subseteq L(A_1)]. The condition $math[L(A) \subseteq L(B)] can be restated as $math[L(A) \cap complement(L(B)) = \emptyset]. Build the complement DFA for B, and use the product construction with A. Check if the resulting DFA has any final state accessible from the initial one. | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.1.2.** Write a regex for the complement of $math[L((10 \cup 0)^*(1 \cup \epsilon))]. | **7.1.2.** Write a regex for the complement of $math[L((10 \cup 0)^*(1 \cup \epsilon))]. | ||
- | /* | + | |
<hidden> | <hidden> | ||
Build the DFA for that regex and then build the complement of that DFA. Transform it into a regex. | Build the DFA for that regex and then build the complement of that DFA. Transform it into a regex. | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.1.3.** Suppose $math[A] is a DFA. Write another DFA which accepts only those words $math[w] such that both $math[w \in L(A)] and $math[reverse(w) \in L(A)]. | **7.1.3.** Suppose $math[A] is a DFA. Write another DFA which accepts only those words $math[w] such that both $math[w \in L(A)] and $math[reverse(w) \in L(A)]. | ||
- | /* | + | |
<hidden> | <hidden> | ||
Build the DFA $math[A^R] which accepts $math[reverse(L(A))]. Build the product construction between $math[A] and $math[A^R]. | Build the DFA $math[A^R] which accepts $math[reverse(L(A))]. Build the product construction between $math[A] and $math[A^R]. | ||
</hidden> | </hidden> | ||
- | */ | + | |
===== Quotients ===== | ===== Quotients ===== | ||
Line 33: | Line 32: | ||
**7.2.1.** Let $ L = L((aaa \cup ba)^*(ab)^* )$. What is the language $ L/a $ ? | **7.2.1.** Let $ L = L((aaa \cup ba)^*(ab)^* )$. What is the language $ L/a $ ? | ||
- | /* | + | |
<hidden> | <hidden> | ||
$math[L/a = L((aaa \cup ba)^*(aa \cup b))] | $math[L/a = L((aaa \cup ba)^*(aa \cup b))] | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.2.2.** Let $ L = L(a^*)$. What is the language $ L/a $ ? | **7.2.2.** Let $ L = L(a^*)$. What is the language $ L/a $ ? | ||
- | /* | + | |
<hidden> | <hidden> | ||
$math[L/a = L(a^*)] | $math[L/a = L(a^*)] | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.2.3.** Prove that if $ L $ is a regular language, then $ L/c$ is a regular language $ \forall c \in \Sigma$. | **7.2.3.** Prove that if $ L $ is a regular language, then $ L/c$ is a regular language $ \forall c \in \Sigma$. | ||
- | /* | + | |
<hidden> | <hidden> | ||
Let $math[A] be a DFA which accepts $math[L]. We build a new DFA $math[A/c] which accepts $math[L/c]. This new DFA has the same number of states, initial state, same transitions and same alphabet. The set of final states is different though: $math[F/c = \{q' \in K | \exists q \in F. \delta(q',c) = q\}]. In other words, the final states of $math[A/c] are those states which are $math[c-]predecessors of some final state of $math[A]. Note that some $math[q'] may be equal to $math[q], and it may also be the case that no such predecessors exist. | Let $math[A] be a DFA which accepts $math[L]. We build a new DFA $math[A/c] which accepts $math[L/c]. This new DFA has the same number of states, initial state, same transitions and same alphabet. The set of final states is different though: $math[F/c = \{q' \in K | \exists q \in F. \delta(q',c) = q\}]. In other words, the final states of $math[A/c] are those states which are $math[c-]predecessors of some final state of $math[A]. Note that some $math[q'] may be equal to $math[q], and it may also be the case that no such predecessors exist. | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.2.4.** Let $ L \subseteq \Sigma^* $ be a language and $ c \in \Sigma $ a symbol. Then $ c / L = \{ w \in \Sigma^* | cw \in L \} $. Prove that if $ L $ is a regular language, then $ a / L $ is a regular language,$ \forall a \in \Sigma$. | **7.2.4.** Let $ L \subseteq \Sigma^* $ be a language and $ c \in \Sigma $ a symbol. Then $ c / L = \{ w \in \Sigma^* | cw \in L \} $. Prove that if $ L $ is a regular language, then $ a / L $ is a regular language,$ \forall a \in \Sigma$. | ||
- | /* | + | |
<hidden> | <hidden> | ||
The easiest way is to rely on other closure properties: $math[c/L = reverse(reverse(L)/c)] | The easiest way is to rely on other closure properties: $math[c/L = reverse(reverse(L)/c)] | ||
</hidden> | </hidden> | ||
- | */ | + | |
===== Suffixes and prefixes ===== | ===== Suffixes and prefixes ===== | ||
Line 67: | Line 66: | ||
**7.3.1.** Prove that $ \text{suffix}(L) = \{ w \in \Sigma^* | \exists x \in \Sigma^*, \: \text{such that} \: xw \in L \} $ is a closure property. | **7.3.1.** Prove that $ \text{suffix}(L) = \{ w \in \Sigma^* | \exists x \in \Sigma^*, \: \text{such that} \: xw \in L \} $ is a closure property. | ||
- | /* | + | |
<hidden> | <hidden> | ||
Suppose $math[A] is the accepting DFA of L. We build a new NFA from A by adding $math[\epsilon-]transitions from the initial state to all other states of A (obs: if the initial state of A had transitions that entered it, then, in the new NFA, create another initial state that has an $math[\epsilon-]transition to the former initial state). Thus, we can nondeterministically //skip// any prefix $math[x] of any accepted word from $math[L]. This new DFA accepts $math[\text{suffix(L)}] | Suppose $math[A] is the accepting DFA of L. We build a new NFA from A by adding $math[\epsilon-]transitions from the initial state to all other states of A (obs: if the initial state of A had transitions that entered it, then, in the new NFA, create another initial state that has an $math[\epsilon-]transition to the former initial state). Thus, we can nondeterministically //skip// any prefix $math[x] of any accepted word from $math[L]. This new DFA accepts $math[\text{suffix(L)}] | ||
</hidden> | </hidden> | ||
- | */ | + | |
===== Other transformations ===== | ===== Other transformations ===== | ||
Line 80: | Line 79: | ||
**7.4.1.** Describe $math[min(L)] without mathematical notation. | **7.4.1.** Describe $math[min(L)] without mathematical notation. | ||
- | /* | + | |
<hidden> | <hidden> | ||
$math[min(L)] is the set of words from $math[L] that have no proper ($math[\neq \epsilon]) prefix in $math[L]. | $math[min(L)] is the set of words from $math[L] that have no proper ($math[\neq \epsilon]) prefix in $math[L]. | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.4.2.** What is the language $ min(L(a^*)) $ ? | **7.4.2.** What is the language $ min(L(a^*)) $ ? | ||
- | /* | + | |
<hidden> | <hidden> | ||
$math[min(L(a^*)) = \{\epsilon\}] | $math[min(L(a^*)) = \{\epsilon\}] | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.4.3.** What is the language $ min(L(a^*b)) $ ? | **7.4.3.** What is the language $ min(L(a^*b)) $ ? | ||
- | /* | + | |
<hidden> | <hidden> | ||
No word from $math[L(a^*b)] has a prefix in this same language, hence the answer is $math[L(a^*b)]. | No word from $math[L(a^*b)] has a prefix in this same language, hence the answer is $math[L(a^*b)]. | ||
</hidden> | </hidden> | ||
- | */ | + | |
**7.4.4.** Prove that $ min $ has the closure property with respect to the regular languages. | **7.4.4.** Prove that $ min $ has the closure property with respect to the regular languages. | ||
- | /* | + | |
<hidden> | <hidden> | ||
Let $math[A] be the accepting DFA of L. If a word $math[w=xy \in L] has a proper prefix $math[x] in $math[L], then $math[(q_0,xy) \vdash^* (q_1,x) \vdash^* (q_2,\epsilon)] where $math[q_1,q_2] are final states. We need to //break-off// those paths leading from one final state (such as $math[q_1]) to another. | Let $math[A] be the accepting DFA of L. If a word $math[w=xy \in L] has a proper prefix $math[x] in $math[L], then $math[(q_0,xy) \vdash^* (q_1,x) \vdash^* (q_2,\epsilon)] where $math[q_1,q_2] are final states. We need to //break-off// those paths leading from one final state (such as $math[q_1]) to another. | ||
Line 110: | Line 109: | ||
We construct a new DFA which accepts $math[min(L)]. We build a new sink state. We change all outgoing transitions of all final states such that they now //go// to the sink state. In this way, once a final state was visited once, no other final state can be visited while accepting any word $math[w]. This means $math[w] has no accepting proper prefix. | We construct a new DFA which accepts $math[min(L)]. We build a new sink state. We change all outgoing transitions of all final states such that they now //go// to the sink state. In this way, once a final state was visited once, no other final state can be visited while accepting any word $math[w]. This means $math[w] has no accepting proper prefix. | ||
</hidden> | </hidden> | ||
- | */ | + | |
** 7.4.5.** Let $math[L] be a regular language and $math[R = \{xy \mid yx \in L\}]. Both $math[x] and $math[y] can be empty strings. Show that $math[R] is regular. | ** 7.4.5.** Let $math[L] be a regular language and $math[R = \{xy \mid yx \in L\}]. Both $math[x] and $math[y] can be empty strings. Show that $math[R] is regular. | ||
- | /* | + | |
<hidden> | <hidden> | ||
The language $math[R] contains all those words formed by taking any suffix $math[x] of a word from $math[L] an appending its respective prefix $math[y] to it. | The language $math[R] contains all those words formed by taking any suffix $math[x] of a word from $math[L] an appending its respective prefix $math[y] to it. | ||
Line 127: | Line 126: | ||
{{ :lfa:2022:screenshot_2022-11-18_at_14.15.39.png?600 |}} | {{ :lfa:2022:screenshot_2022-11-18_at_14.15.39.png?600 |}} | ||
</hidden> | </hidden> | ||
- | */ | + | |