--- a/slides/slides07.tex Mon Nov 11 13:48:34 2013 +0000
+++ b/slides/slides07.tex Mon Nov 11 15:26:20 2013 +0000
@@ -76,152 +76,6 @@
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
-
-% The data files, written on the first run.
-\begin{filecontents}{re-python.data}
-1 0.029
-5 0.029
-10 0.029
-15 0.032
-16 0.042
-17 0.042
-18 0.055
-19 0.084
-20 0.136
-21 0.248
-22 0.464
-23 0.899
-24 1.773
-25 3.505
-26 6.993
-27 14.503
-28 29.307
-#29 58.886
-\end{filecontents}
-
-\begin{filecontents}{re-ruby.data}
-1 0.00006
-2 0.00003
-3 0.00001
-4 0.00001
-5 0.00001
-6 0.00002
-7 0.00002
-8 0.00004
-9 0.00007
-10 0.00013
-11 0.00026
-12 0.00055
-13 0.00106
-14 0.00196
-15 0.00378
-16 0.00764
-17 0.01606
-18 0.03094
-19 0.06508
-20 0.12420
-21 0.25393
-22 0.51449
-23 1.02174
-24 2.05998
-25 4.22514
-26 8.42479
-27 16.88678
-28 34.79653
-\end{filecontents}
-
-\begin{filecontents}{re1.data}
-1 0.00179
-2 0.00011
-3 0.00014
-4 0.00026
-5 0.00050
-6 0.00095
-7 0.00190
-8 0.00287
-9 0.00779
-10 0.01399
-11 0.01894
-12 0.03666
-13 0.07994
-14 0.08944
-15 0.02377
-16 0.07392
-17 0.22798
-18 0.65310
-19 2.11360
-20 6.31606
-21 21.46013
-\end{filecontents}
-
-\begin{filecontents}{re2.data}
-1 0.00240
-2 0.00013
-3 0.00020
-4 0.00030
-5 0.00049
-6 0.00083
-7 0.00146
-8 0.00228
-9 0.00351
-10 0.00640
-11 0.01217
-12 0.02565
-13 0.01382
-14 0.02423
-15 0.05065
-16 0.06522
-17 0.02140
-18 0.05176
-19 0.18254
-20 0.51898
-21 1.39631
-22 2.69501
-23 8.07952
-\end{filecontents}
-
-\begin{filecontents}{re-internal.data}
-1 0.00069
-301 0.00700
-601 0.00297
-901 0.00470
-1201 0.01301
-1501 0.01175
-1801 0.01761
-2101 0.01787
-2401 0.02717
-2701 0.03932
-3001 0.03470
-3301 0.04349
-3601 0.05411
-3901 0.06181
-4201 0.07119
-4501 0.08578
-\end{filecontents}
-
-\begin{filecontents}{re3.data}
-1 0.001605
-501 0.131066
-1001 0.057885
-1501 0.136875
-2001 0.176238
-2501 0.254363
-3001 0.37262
-3501 0.500946
-4001 0.638384
-4501 0.816605
-5001 1.00491
-5501 1.232505
-6001 1.525672
-6501 1.757502
-7001 2.092784
-7501 2.429224
-8001 2.803037
-8501 3.463045
-9001 3.609
-9501 4.081504
-10001 4.54569
-\end{filecontents}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -262,18 +116,13 @@
\item a start symbol (which must be a nonterminal)
\item a set of rules
\begin{center}
-\bl{$A \rightarrow \text{rhs}$}
+\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$}
\end{center}
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause
-We can also allow rules
-\begin{center}
-\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$}
-\end{center}
\end{itemize}
-
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -281,17 +130,21 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}A CFG Derivation\end{tabular}}
+\frametitle{\begin{tabular}{c}Hierarchie of Languages\end{tabular}}
-\begin{enumerate}
-\item Begin with a string with only the start symbol \bl{$S$}\bigskip
-\item Replace any non-terminal \bl{$X$} in the string by the
-right-hand side of some production \bl{$X \rightarrow \text{rhs}$}\bigskip
-\item Repeat 2 until there are no non-terminals
-\end{enumerate}
+Recall that languages are sets of strings.
\begin{center}
-\bl{$S \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots $}
+\begin{tikzpicture}
+[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}]
+
+\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages};
+\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages};
+\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages};
+\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages};
+\draw (0,-1.4) node [rect] {regular languages};
+\end{tikzpicture}
+
\end{center}
\end{frame}}
@@ -299,45 +152,87 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Numbers\end{tabular}}
+
+A grammar for numbers:
+
+\begin{center}
+\bl{\begin{tabular}{lcl}
+$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
+\end{tabular}}
+\end{center}
+
+Unfortunately left-recursive (and ambiguous).\medskip\\
+A problem for \alert{recursive descent parsers} (e.g.~parser combinators).
+\bigskip\pause
+
+A non-left-recursive grammar for numbers
+
+\begin{center}
+\bl{\begin{tabular}{lcl}
+$N$ & $\rightarrow$ & $0 \cdot N \;|\;1 \cdot N \;|\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
+\end{tabular}}
+\end{center}
+
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Language of a CFG\end{tabular}}
+\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
-Let \bl{$G$} be a context-free grammar with start symbol \bl{$S$}.
-Then the language \bl{$L(G)$} is:
+All rules must be of the form
\begin{center}
-\bl{$\{c_1\ldots c_n \;|\; \forall i.\; c_i \in T \wedge S \rightarrow^* c_1\ldots c_n \}$}
-\end{center}\pause
+\bl{$A \rightarrow a$}
+\end{center}
+
+or
-\begin{itemize}
-\item Terminals are so-called because there are no rules for replacing them
-\item Once generated, terminals are ``permanent''
-\item Terminals ought to be tokens of the language (at least in this course)
-\end{itemize}
+\begin{center}
+\bl{$A \rightarrow B\cdot C$}
+\end{center}
+
+
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
+\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
+
\begin{center}
-\bl{\begin{tabular}{lcl}
-$E$ & $\rightarrow$ & $num\_token$ \\
-$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\
-$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\
-$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\
-$E$ & $\rightarrow$ & $( \cdot E \cdot )$
+\bl{\begin{tabular}{@ {}lcl}
+$S$ & $\rightarrow$ & $N\cdot P$ \\
+$P$ & $\rightarrow$ & $V\cdot N$ \\
+$N$ & $\rightarrow$ & $N\cdot N$ \\
+$N$ & $\rightarrow$ & $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
+$V$ & $\rightarrow$ & $\texttt{trains}$
\end{tabular}}
-\end{center}\pause\bigskip
+\end{center}
-A CFG is \alert{left-recursive} if it has a nonterminal \bl{$E$} such
-that \bl{$E \rightarrow^+ E\cdot \ldots$}
+\bl{\texttt{Jeff trains geometry students}}
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
+
+
+\begin{itemize}
+\item runtime is \bl{$O(n^3)$}\bigskip
+\item grammars need to be transferred into CNF
+\end{itemize}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -427,6 +322,26 @@
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}A CFG Derivation\end{tabular}}
+
+\begin{enumerate}
+\item Begin with a string with only the start symbol \bl{$S$}\bigskip
+\item Replace any non-terminal \bl{$X$} in the string by the
+right-hand side of some production \bl{$X \rightarrow \text{rhs}$}\bigskip
+\item Repeat 2 until there are no non-terminals
+\end{enumerate}
+
+\begin{center}
+\bl{$S \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots $}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
\end{document}
%%% Local Variables: