hws/hw09.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 13 Sep 2014 04:30:25 +0100
changeset 242 35104ee14f87
parent 208 bd5a8a6b3871
child 292 7ed2a25dd115
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}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{charter}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage{hyperref}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
\usepackage{amssymb}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\usepackage{amsmath}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\usepackage{tikz}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\usetikzlibrary{automata}
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
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
\section*{Homework 9}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
\begin{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
\item Describe what is meant by \emph{eliminating tail recursion}, when such an 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
optimization can be applied and why it is a benefit?
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
\item It is true (I confirmed it) that
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
if $\varnothing$ does not occur in $r$ \;\;then\;\;$L(r) \not= \{\}$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
holds, or equivalently
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
$L(r) = \{\}$ \;\;implies\;\; $\varnothing$ occurs in $r$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
\end{center}
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
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
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
    34
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
    35
the following function:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
$occurs(\varnothing)$      & $\dn$ & $true$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
$occurs(\epsilon)$           & $\dn$ &  $f\!alse$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
$occurs (c)$                    & $\dn$ &  $f\!alse$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
$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
    43
$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
    44
$occurs (r^*)$                & $\dn$ & $occurs(r)$ \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
Now you can prove 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
$L(r) = \{\}$ \;\;implies\;\; $occurs(r)$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
The interesting cases are $r_1 + r_2$ and $r^*$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
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
    58
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
    59
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
    60
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
    61
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
$occurs(\sim r)$      & $\dn$ & $occurs(r)$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
\end{center}  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
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
    70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
$L(r) = \{\}$ \;\;implies\;\; $occurs(r)$.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
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
    77
property.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
%%% End: