author | Christian Urban <christian.urban@kcl.ac.uk> |
Sun, 02 Oct 2022 08:42:01 +0100 | |
changeset 881 | 3b2f76950473 |
parent 880 | bc04fc576896 |
child 885 | 526aaee62a3e |
permissions | -rw-r--r-- |
22 | 1 |
\documentclass{article} |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
2 |
\usepackage{../style} |
22 | 3 |
|
4 |
\begin{document} |
|
5 |
||
6 |
\section*{Homework 2} |
|
7 |
||
347
22b5294daa2a
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
294
diff
changeset
|
8 |
\HEADER |
22b5294daa2a
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
294
diff
changeset
|
9 |
|
22 | 10 |
\begin{enumerate} |
499 | 11 |
\item What is the difference between \emph{basic} regular expressions |
12 |
and \emph{extended} regular expressions? |
|
13 |
||
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
14 |
\item What is the language recognised by the regular |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
15 |
expressions $(\ZERO^*)^*$. |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
132
diff
changeset
|
16 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
17 |
\item Review the first handout about sets of strings and read |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
18 |
the second handout. Assuming the alphabet is the set |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
19 |
$\{a, b\}$, decide which of the following equations are |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
20 |
true in general for arbitrary languages $A$, $B$ and |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
21 |
$C$: |
115
86c1c049eb3e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
104
diff
changeset
|
22 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
23 |
\begin{eqnarray} |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
24 |
(A \cup B) @ C & =^? & A @ C \cup B @ C\nonumber\\ |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
25 |
A^* \cup B^* & =^? & (A \cup B)^*\nonumber\\ |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
26 |
A^* @ A^* & =^? & A^*\nonumber\\ |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
27 |
(A \cap B)@ C & =^? & (A@C) \cap (B@C)\nonumber |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
28 |
\end{eqnarray} |
104
ffde837b1db1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
29 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
30 |
\noindent In case an equation is true, give an |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
31 |
explanation; otherwise give a counter-example. |
104
ffde837b1db1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
32 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
33 |
\item Given the regular expressions $r_1 = \ONE$ and $r_2 = |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
34 |
\ZERO$ and $r_3 = a$. How many strings can the regular |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
35 |
expressions $r_1^*$, $r_2^*$ and $r_3^*$ each match? |
104
ffde837b1db1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
36 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
37 |
\item Give regular expressions for (a) decimal numbers and for |
617 | 38 |
(b) binary numbers. Hint: Observe that the empty string |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
39 |
is not a number. Also observe that leading 0s are |
617 | 40 |
normally not written---for example the JSON format for numbers |
41 |
explicitly forbids this. |
|
22 | 42 |
|
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
132
diff
changeset
|
43 |
\item Decide whether the following two regular expressions are |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
44 |
equivalent $(\ONE + a)^* \equiv^? a^*$ and $(a \cdot |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
45 |
b)^* \cdot a \equiv^? a \cdot (b \cdot a)^*$. |
22 | 46 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
47 |
\item Given the regular expression $r = (a \cdot b + b)^*$. |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
48 |
Compute what the derivative of $r$ is with respect to |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
49 |
$a$, $b$ and $c$. Is $r$ nullable? |
22 | 50 |
|
881 | 51 |
\item Give an argument for why the following holds: |
52 |
if $r$ is nullable then $r^{\{n\}} \equiv r^{\{..n\}}$. |
|
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
132
diff
changeset
|
53 |
|
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
54 |
\item Define what is meant by the derivative of a regular |
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
55 |
expressions with respect to a character. (Hint: The |
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
56 |
derivative is defined recursively.) |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
57 |
|
768 | 58 |
\item Assume the set $Der$ is defined as |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
59 |
|
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
60 |
\begin{center} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
61 |
$Der\,c\,A \dn \{ s \;|\; c\!::\!s \in A\}$ |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
62 |
\end{center} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
63 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
64 |
What is the relation between $Der$ and the notion of |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
65 |
derivative of regular expressions? |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
66 |
|
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
67 |
\item Give a regular expression over the alphabet $\{a,b\}$ |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
68 |
recognising all strings that do not contain any |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
69 |
substring $bb$ and end in $a$. |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
258
diff
changeset
|
70 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
71 |
\item Do $(a + b)^* \cdot b^+$ and $(a^* \cdot b^+) + |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
72 |
(b^*\cdot b^+)$ define the same language? |
294
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
73 |
|
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
74 |
\item Define the function $zeroable$ by recursion over regular |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
75 |
expressions. This function should satisfy the property |
294
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
76 |
|
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
77 |
\[ |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
78 |
zeroable(r) \;\;\text{if and only if}\;\;L(r) = \{\}\qquad(*) |
294
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
79 |
\] |
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
80 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
81 |
The function $nullable$ for the not-regular expressions |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
82 |
can be defined by |
294
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
83 |
|
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
84 |
\[ |
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
85 |
nullable(\sim r) \dn \neg(nullable(r)) |
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
86 |
\] |
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
87 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
88 |
Unfortunately, a similar definition for $zeroable$ does |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
89 |
not satisfy the property in $(*)$: |
294
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
90 |
|
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
91 |
\[ |
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
92 |
zeroable(\sim r) \dn \neg(zeroable(r)) |
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
93 |
\] |
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
94 |
|
471 | 95 |
Find a counter example? |
294
c29853b672fb
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
96 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
97 |
\item Give a regular expressions that can recognise all |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
355
diff
changeset
|
98 |
strings from the language $\{a^n\;|\;\exists k.\; n = 3 k |
404
245d302791c7
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
401
diff
changeset
|
99 |
+ 1 \}$. |
245d302791c7
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
401
diff
changeset
|
100 |
|
245d302791c7
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
401
diff
changeset
|
101 |
\item Give a regular expression that can recognise an odd |
245d302791c7
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
401
diff
changeset
|
102 |
number of $a$s or an even number of $b$s. |
444
3056a4c071b0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
404
diff
changeset
|
103 |
|
3056a4c071b0
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
404
diff
changeset
|
104 |
\item \POSTSCRIPT |
404
245d302791c7
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
401
diff
changeset
|
105 |
\end{enumerate} |
22 | 106 |
|
107 |
\end{document} |
|
108 |
||
109 |
%%% Local Variables: |
|
110 |
%%% mode: latex |
|
111 |
%%% TeX-master: t |
|
112 |
%%% End: |