hws/hw02.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 21 Oct 2020 09:24:32 +0100
changeset 785 faa4489267d5
parent 770 c563cf946497
child 880 bc04fc576896
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     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
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
\section*{Homework 2}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     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
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
\begin{enumerate}
499
dfd0f41f8668 updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    11
\item What is the difference between \emph{basic} regular expressions  
dfd0f41f8668 updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    12
      and \emph{extended} regular expressions?
dfd0f41f8668 updated
Christian Urban <urbanc@in.tum.de>
parents: 471
diff changeset
    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
f7de0915fff2 updated
Christian Urban <urbanc@in.tum.de>
parents: 499
diff changeset
    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
f7de0915fff2 updated
Christian Urban <urbanc@in.tum.de>
parents: 499
diff changeset
    40
      normally not written---for example the JSON format for numbers
f7de0915fff2 updated
Christian Urban <urbanc@in.tum.de>
parents: 499
diff changeset
    41
      explicitly forbids this.
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    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
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    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
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
770
c563cf946497 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 768
diff changeset
    51
\item (Moved to HW3)
258
1e4da6d2490c updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 132
diff changeset
    52
  
355
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 347
diff changeset
    53
\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
    54
      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
    55
      derivative is defined recursively.)
267
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    56
768
34f77b976b88 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 617
diff changeset
    57
\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
    58
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    59
  \begin{center}
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    60
    $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
    61
  \end{center}
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    62
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    63
      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
    64
      derivative of regular expressions?
267
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    65
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    66
\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
    67
      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
    68
      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
    69
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    70
\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
    71
      (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
    72
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    73
\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
    74
      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
    75
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    76
  \[
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    77
  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
    78
  \]
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    79
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    80
      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
    81
      can be defined by 
294
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    82
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
  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
    85
  \]
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    86
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    87
      Unfortunately, a similar definition for $zeroable$ does
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    88
      not satisfy the property in $(*)$:
294
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    89
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
  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
    92
  \]
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    93
471
9476086849ad updated
Christian Urban <urbanc@in.tum.de>
parents: 444
diff changeset
    94
      Find a counter example?
294
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    95
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    96
\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
    97
      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
    98
      + 1 \}$. 
245d302791c7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 401
diff changeset
    99
      
245d302791c7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 401
diff changeset
   100
\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
   101
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
   102
3056a4c071b0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 404
diff changeset
   103
\item \POSTSCRIPT  
404
245d302791c7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 401
diff changeset
   104
\end{enumerate}
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
%%% Local Variables: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
%%% End: