hws/hw07.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 17 Nov 2013 18:16:20 +0000
changeset 194 90796ee3c17a
parent 183 b17eff695c7f
child 292 7ed2a25dd115
permissions -rw-r--r--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass{article}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\usepackage{charter}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
\usepackage{hyperref}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
\usepackage{amssymb}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
\usepackage{amsmath}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
\usepackage{tikz}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\usetikzlibrary{automata}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
\section*{Homework 7}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
\begin{enumerate}
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    16
\item Suppose the context-sensitive grammar
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
\begin{center}
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    19
\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    20
$S$ & $\rightarrow$ &  $bSAA\;|\; \epsilon$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    21
$A$ & $\rightarrow$ & $a$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    22
$bA$ & $\rightarrow$ & $Ab$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    23
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    24
\end{center}
183
b17eff695c7f added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    25
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    26
where $S$ is the starting symbol of the grammar. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    27
Give a derivation  of the string $"\!aaabaaabb"$. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    28
What can you say about the number of as and bs in the
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    29
strings recognised by this grammar.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    30
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
\item Consider the following grammar 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
\begin{tabular}{l}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
$S \rightarrow N\cdot P$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
$P \rightarrow V\cdot N$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
$N \rightarrow N\cdot N$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
$N \rightarrow A \cdot N$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
$N \rightarrow \texttt{student} \;|\; \texttt{trainer} \;|\; \texttt{team} \;|\; \texttt{trains}$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
$V \rightarrow \texttt{trains} \;|\; \texttt{team}$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
$A \rightarrow \texttt{The} \;|\; \texttt{the}$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
\end{tabular}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
where $S$ is the start symbol and $S$, $P$, $N$, $V$ and $A$ are non-terminals.
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
Using the CYK-algorithm, check whether or not the following string can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
by the grammar:
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
\texttt{The trainer trains the student team}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    54
\item Transform the grammar
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
60
68d664c204d2 updated
Christian Urban <urbanc@in.tum.de>
parents: 59
diff changeset
    56
\begin{center}
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    57
\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    58
$A$ & $\rightarrow$ & $0A1 \;|\; BB$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    59
$B$ & $\rightarrow$ & $\epsilon \;|\; 2B$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    60
\end{tabular}
60
68d664c204d2 updated
Christian Urban <urbanc@in.tum.de>
parents: 59
diff changeset
    61
\end{center}
194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    62
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    63
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    64
into Chomsky normal form.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    67
%\item {\bf (Optional)} The task is to match strings where the letters are in alphabetical order---for example, 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    68
%\texttt{abcfjz} would pass, but \texttt{acb} would not. Whitespace should be ignored---for example
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    69
%\texttt{ab c d} should pass. The point is to try to get the regular expression as short as possible!
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    70
%See:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    71
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    72
%\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    73
%\url{http://callumacrae.github.com/regex-tuesday/challenge11.html}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    74
%\end{center}
59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
\end{enumerate}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
%%% Local Variables: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
%%% End: