hws/hw02.tex
author cu
Wed, 01 Nov 2017 11:44:23 +0000
changeset 530 cec95ad3a837
parent 499 dfd0f41f8668
child 617 f7de0915fff2
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
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    38
      (b) binary numbers. (Hint: Observe that the empty string
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
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    40
      normally not written.)
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
258
1e4da6d2490c updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 132
diff changeset
    42
\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
    43
      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
    44
      b)^* \cdot a \equiv^? a \cdot (b \cdot a)^*$.
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    46
\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
    47
      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
    48
      $a$, $b$ and $c$. Is $r$ nullable?
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
\item Prove that for all regular expressions $r$ we have
258
1e4da6d2490c updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 132
diff changeset
    51
      
1e4da6d2490c updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 132
diff changeset
    52
\begin{center} 
1e4da6d2490c updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 132
diff changeset
    53
  $\textit{nullable}(r) \quad \text{if and only if} 
1e4da6d2490c updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 132
diff changeset
    54
  \quad [] \in L(r)$ 
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    57
      Write down clearly in each case what you need to prove
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    58
      and what are the assumptions. 
258
1e4da6d2490c updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 132
diff changeset
    59
  
355
a259eec25156 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 347
diff changeset
    60
\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
    61
      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
    62
      derivative is defined recursively.)
267
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    63
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    64
\item Assume the set $Der$ is defined as
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
  \begin{center}
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    67
    $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
    68
  \end{center}
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
      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
    71
      derivative of regular expressions?
267
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    72
a1544b804d1e updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    73
\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
    74
      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
    75
      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
    76
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    77
\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
    78
      (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
    79
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    80
\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
    81
      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
    82
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    83
  \[
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    84
  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
    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
      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
    88
      can be defined by 
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
  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
    92
  \]
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    93
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    94
      Unfortunately, a similar definition for $zeroable$ does
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
    95
      not satisfy the property in $(*)$:
294
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    96
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    97
  \[
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
    98
  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
    99
  \]
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
   100
471
9476086849ad updated
Christian Urban <urbanc@in.tum.de>
parents: 444
diff changeset
   101
      Find a counter example?
294
c29853b672fb updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 292
diff changeset
   102
401
5d85dc9779b1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 355
diff changeset
   103
\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
   104
      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
   105
      + 1 \}$. 
245d302791c7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 401
diff changeset
   106
      
245d302791c7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 401
diff changeset
   107
\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
   108
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
   109
3056a4c071b0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 404
diff changeset
   110
\item \POSTSCRIPT  
404
245d302791c7 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 401
diff changeset
   111
\end{enumerate}
22
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
%%% Local Variables: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
%%% End: