43 |
45 |
44 \noindent In case an equation is true, give an |
46 \noindent In case an equation is true, give an |
45 explanation; otherwise give a counter-example. |
47 explanation; otherwise give a counter-example. |
46 |
48 |
47 \solution{1 + 3 are equal; 2 + 4 are not. Interesting is 4 where |
49 \solution{1 + 3 are equal; 2 + 4 are not. Interesting is 4 where |
48 $A = \{[a]\}$, $B = \{[]\}$ and $C = \{[a], []\}$} |
50 $A = \{[a]\}$, $B = \{[]\}$ and $C = \{[a], []\}$\medskip |
|
51 |
|
52 For equations like 3 it is always a god idea to prove the |
|
53 two inclusions |
|
54 |
|
55 \[ |
|
56 A^* \subseteq A^* @ A^* \qquad |
|
57 A^* @ A^* \subseteq A^* |
|
58 \] |
|
59 |
|
60 This means for every string $s$ we have to show |
|
61 |
|
62 \[ |
|
63 s \in A^* \;\textit{implies}\; s \in A^* @ A^* \qquad |
|
64 s \in A^* @ A^* \;\textit{implies}\; s \in A^* |
|
65 \] |
|
66 |
|
67 The first one is easy because $[] \in A^*$ and therefore |
|
68 $s @ [] \in A^* @ A^*$. |
|
69 |
|
70 The second one says that $s$ must be of the form $s = s_1 @ s_2$ with |
|
71 $s_1 \in A^*$ and $s_2 \in A^*$. We have to show that |
|
72 $s_1 @ s_2 \in A^*$. |
|
73 |
|
74 If $s_1 \in A^*$ then there exists an $n$ such that $s_1 \in A^n$, and |
|
75 if $s_2 \in A^*$ then there exists an $m$ such that $s_2 \in A^m$.\bigskip |
|
76 |
|
77 |
|
78 Aside: We are going to show that |
|
79 |
|
80 \[ |
|
81 A^n \,@\, A^m = A^{n+m} |
|
82 \] |
|
83 |
|
84 We prove that by induction on $n$. |
|
85 |
|
86 Case $n = 0$: $A^0 \,@\, A^m = A^{0+m}$ holds because $A^0 = \{[]\}$ |
|
87 and $\{[]\} \,@\, A^m = A ^ m$ and $0 + m = m$.\medskip |
|
88 |
|
89 Case $n + 1$: The induction hypothesis is |
|
90 |
|
91 \[ A^n \,@\, A^m = A^{n+m} |
|
92 \] |
|
93 |
|
94 We need to prove |
|
95 |
|
96 \[ |
|
97 A^{n+1} \,@\, A^m = A^{(n+1)+m} |
|
98 \] |
|
99 |
|
100 The left-hand side is $(A \,@\, A^n) \,@\, A^m$ by the definition of |
|
101 the power operation. We can rearrange that |
|
102 to $A \,@\, (A^n \,@\, A^m)$. \footnote{Because for all languages $A$, $B$, $C$ we have $(A @ B) @ C = A @ (B @ C)$.} |
|
103 |
|
104 By the induction hypothesis we know that $A^n \,@\, A^m = A^{n+m}$. |
|
105 |
|
106 So we have $A \,@\, (A^{n+m})$. But this is $A^{(n+m)+1}$ again if we |
|
107 apply the definition of the power operator. If we |
|
108 rearrange that we get $A^{(n+1)+m}$ and are done with |
|
109 what we need to prove for the power law.\bigskip |
|
110 |
|
111 Picking up where we left, we know that $s_1 \in A^n$ and $s_2 \in A^m$. This now implies that $s_1 @ s_2\in A^n @ A^m$. By the power law this means |
|
112 $s_1 @ s_2\in A^{n+m}$. But this also means $s_1 @ s_2\in A^*$. |
|
113 } |
49 |
114 |
50 \item Given the regular expressions $r_1 = \ONE$ and $r_2 = |
115 \item Given the regular expressions $r_1 = \ONE$ and $r_2 = |
51 \ZERO$ and $r_3 = a$. How many strings can the regular |
116 \ZERO$ and $r_3 = a$. How many strings can the regular |
52 expressions $r_1^*$, $r_2^*$ and $r_3^*$ each match? |
117 expressions $r_1^*$, $r_2^*$ and $r_3^*$ each match? |
53 |
118 |
98 |
163 |
99 \item Give a regular expression over the alphabet $\{a,b\}$ |
164 \item Give a regular expression over the alphabet $\{a,b\}$ |
100 recognising all strings that do not contain any |
165 recognising all strings that do not contain any |
101 substring $bb$ and end in $a$. |
166 substring $bb$ and end in $a$. |
102 |
167 |
103 |
168 \solution{$((ba)^* \cdot (a)^*)^*\,\cdot\,a$} |
104 |
169 |
105 \item Do $(a + b)^* \cdot b^+$ and $(a^* \cdot b^+) + |
170 \item Do $(a + b)^* \cdot b^+$ and $(a^* \cdot b^+) + |
106 (b^*\cdot b^+)$ define the same language? |
171 (b^*\cdot b^+)$ define the same language? |
107 |
172 |
108 \solution{No, the first one can match for example abababababbbbb} |
173 \solution{No, the first one can match for example abababababbbbb |
|
174 while the second can only match for example aaaaaabbbbb or bbbbbbb} |
109 |
175 |
110 \item Define the function $zeroable$ by recursion over regular |
176 \item Define the function $zeroable$ by recursion over regular |
111 expressions. This function should satisfy the property |
177 expressions. This function should satisfy the property |
112 |
178 |
113 \[ |
179 \[ |
126 |
192 |
127 \[ |
193 \[ |
128 zeroable(\sim r) \dn \neg(zeroable(r)) |
194 zeroable(\sim r) \dn \neg(zeroable(r)) |
129 \] |
195 \] |
130 |
196 |
131 Find a counter example? |
197 Find a counter example? |
|
198 |
|
199 |
|
200 \solution{ |
|
201 Here the idea is that nullable for NOT can be defined as |
|
202 |
|
203 \[nullable(\sim r) \dn \neg(nullable(r))\] |
|
204 |
|
205 This will satisfy the property |
|
206 $nullable(r) \;\;\text{if and only if}\;\;[] \in L(r)$. (Remember how |
|
207 $L(\sim r)$ is defined).\bigskip |
|
208 |
|
209 But you cannot define |
|
210 |
|
211 \[zeroable(\sim r) \dn \neg(zeroable(r))\] |
|
212 |
|
213 because if $r$ for example is $\ONE$ then $\sim \ONE$ can match |
|
214 some strings (all non-empty strings). So $zeroable$ should be false. But if we follow |
|
215 the above definition we would obtain $\neg(zeroable(\ONE))$. According |
|
216 to the definition of $zeroable$ for $\ONE$ this would be false, |
|
217 but if we now negate false, we get actually true. So the above |
|
218 definition would not satisfy the property |
|
219 |
|
220 \[ |
|
221 zeroable(r) \;\;\text{if and only if}\;\;L(r) = \{\} |
|
222 \] |
|
223 } |
132 |
224 |
133 \item Give a regular expressions that can recognise all |
225 \item Give a regular expressions that can recognise all |
134 strings from the language $\{a^n\;|\;\exists k.\; n = 3 k |
226 strings from the language $\{a^n\;|\;\exists k.\; n = 3 k |
135 + 1 \}$. |
227 + 1 \}$. |
136 |
228 |
137 \solution{$a(aaa)^*$} |
229 \solution{$a(aaa)^*$} |
138 |
230 |
139 \item Give a regular expression that can recognise an odd |
231 \item Give a regular expression that can recognise an odd |
140 number of $a$s or an even number of $b$s. |
232 number of $a$s or an even number of $b$s. |
|
233 |
|
234 \solution{ |
|
235 If the a's and b's are meant to be separate, then this is easy |
|
236 |
|
237 \[a(aa)^* + (bb)^*\] |
|
238 |
|
239 If the letters are mixed, then this is difficult |
|
240 |
|
241 \[(aa|bb|(ab|ba)\cdot (aa|bb)^* \cdot (ba|ab))^* \cdot (b|(ab|ba)(bb|aa)^* \cdot a) |
|
242 \] |
|
243 |
|
244 (copied from somewhere ;o) |
|
245 |
|
246 The idea behind it is essentially the DFA |
|
247 |
|
248 \begin{center} |
|
249 \begin{tikzpicture}[scale=1,>=stealth',very thick, |
|
250 every state/.style={minimum size=0pt, |
|
251 draw=blue!50,very thick,fill=blue!20}] |
|
252 \node[state,initial] (q0) at (0,2) {$q_0$}; |
|
253 \node[state,accepting] (q1) at (2,2) {$q_1$}; |
|
254 \node[state] (q2) at (0,0) {$q_2$}; |
|
255 \node[state] (q3) at (2,0) {$q_3$}; |
|
256 |
|
257 \path[->] (q0) edge[bend left] node[above] {$a$} (q1) |
|
258 (q1) edge[bend left] node[above] {$a$} (q0) |
|
259 (q2) edge[bend left] node[above] {$a$} (q3) |
|
260 (q3) edge[bend left] node[above] {$a$} (q2) |
|
261 (q0) edge[bend left] node[right] {$b$} (q2) |
|
262 (q2) edge[bend left] node[left] {$b$} (q0) |
|
263 (q1) edge[bend left] node[right] {$b$} (q3) |
|
264 (q3) edge[bend left] node[left] {$b$} (q1); |
|
265 \end{tikzpicture} |
|
266 \end{center} |
|
267 } |
141 |
268 |
142 \item \POSTSCRIPT |
269 \item \POSTSCRIPT |
143 \end{enumerate} |
270 \end{enumerate} |
144 |
271 |
145 \end{document} |
272 \end{document} |