hws/hw09.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 28 Oct 2014 12:24:11 +0000
changeset 292 7ed2a25dd115
parent 208 bd5a8a6b3871
child 314 7dd5797a5ffa
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass{article}
292
7ed2a25dd115 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
     2
\usepackage{../style}
7ed2a25dd115 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
     3
\usepackage{../graphics}
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\section*{Homework 9}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
\begin{enumerate}
292
7ed2a25dd115 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    10
\item Describe what is meant by \emph{eliminating tail
7ed2a25dd115 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    11
      recursion}, when such an optimization can be applied and
7ed2a25dd115 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    12
      why it is a benefit?
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
\item It is true (I confirmed it) that
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
292
7ed2a25dd115 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    16
\begin{center} if $\varnothing$ does not occur in $r$
7ed2a25dd115 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 208
diff changeset
    17
\;\;then\;\;$L(r) \not= \{\}$ 
208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
holds, or equivalently
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
$L(r) = \{\}$ \;\;implies\;\; $\varnothing$ occurs in $r$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
You can prove either version by induction on $r$. The best way to
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
make more formal what is meant by `$\varnothing$ occurs in $r$', you can define
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
the following function:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
$occurs(\varnothing)$      & $\dn$ & $true$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
$occurs(\epsilon)$           & $\dn$ &  $f\!alse$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
$occurs (c)$                    & $\dn$ &  $f\!alse$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
$occurs (r_1 + r_2)$       & $\dn$ &  $occurs(r_1) \vee occurs(r_2)$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
$occurs (r_1 \cdot r_2)$ & $\dn$ &  $occurs(r_1) \vee occurs(r_2)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
$occurs (r^*)$                & $\dn$ & $occurs(r)$ \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
Now you can prove 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
$L(r) = \{\}$ \;\;implies\;\; $occurs(r)$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
The interesting cases are $r_1 + r_2$ and $r^*$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
The other direction is not true, that is if $occurs(r)$ then $L(r) = \{\}$. A counter example
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
is $\varnothing + a$: although $\varnothing$ occurs in this regular expression, the corresponding
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
language is not empty. The obvious extension to include the not-regular expression, $\sim r$,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
also leads to an incorrect statement. Suppose we add the clause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
$occurs(\sim r)$      & $\dn$ & $occurs(r)$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
\end{center}  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
to the definition above, then it will not be true that
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
$L(r) = \{\}$ \;\;implies\;\; $occurs(r)$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
Assume the alphabet contains just $a$ and $b$, find a counter example to this
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
property.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
%%% End: