slides/slides03.tex
changeset 445 e7d0157f0471
parent 348 31e89128ccd2
child 500 c502933be072
equal deleted inserted replaced
444:3056a4c071b0 445:e7d0157f0471
     9 \pgfplotsset{compat=1.11}
     9 \pgfplotsset{compat=1.11}
    10 
    10 
    11 \newcommand{\bl}[1]{\textcolor{blue}{#1}}  
    11 \newcommand{\bl}[1]{\textcolor{blue}{#1}}  
    12 
    12 
    13 % beamer stuff 
    13 % beamer stuff 
    14 \renewcommand{\slidecaption}{AFL 03, King's College London}
    14 \renewcommand{\slidecaption}{CFL 03, King's College London}
    15 
    15 
    16 \begin{document}
    16 \begin{document}
    17 
    17 
    18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    19 \begin{frame}[t]
    19 \begin{frame}[t]
    20 \frametitle{%
    20 \frametitle{%
    21   \begin{tabular}{@ {}c@ {}}
    21   \begin{tabular}{@ {}c@ {}}
    22   \\[-3mm]
    22   \\[-3mm]
    23   \LARGE Automata and \\[-2mm] 
    23   \LARGE Compilers and \\[-2mm] 
    24   \LARGE Formal Languages (3)\\[3mm] 
    24   \LARGE Formal Languages (3)\\[3mm] 
    25   \end{tabular}}
    25   \end{tabular}}
    26 
    26 
    27 \normalsize
    27 \normalsize
    28   \begin{center}
    28   \begin{center}
    32   Slides: & KEATS (also home work and coursework is there)\\
    32   Slides: & KEATS (also home work and coursework is there)\\
    33   \end{tabular}
    33   \end{tabular}
    34   \end{center}
    34   \end{center}
    35 
    35 
    36 \end{frame}
    36 \end{frame}
    37  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
    37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
    38 
       
    39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    40 \begin{frame}[c]
       
    41 \frametitle{Scala Book, Exams}
       
    42 
       
    43 \begin{itemize}
       
    44 \item www.inf.kcl.ac.uk/~urbanc/ProgInScala2ed.pdf
       
    45 \item homeworks (exam 80\%)
       
    46 \item coursework (20\%)
       
    47 \end{itemize}
       
    48 
       
    49 \end{frame}
       
    50 %%%%%%%%%%%
    38 
    51 
    39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    40 \begin{frame}[c]
    53 \begin{frame}[c]
    41 \frametitle{Regular Expressions}
    54 \frametitle{Regular Expressions}
    42 
    55 
    77 \begin{frame}[c]
    90 \begin{frame}[c]
    78 \frametitle{The Derivative of a Rexp}
    91 \frametitle{The Derivative of a Rexp}
    79 
    92 
    80 \begin{center}
    93 \begin{center}
    81 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {\hspace{-10mm}}l@ {}}
    94 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {\hspace{-10mm}}l@ {}}
    82   \bl{$der\, c\, (\varnothing)$}      & \bl{$\dn$} & \bl{$\varnothing$} & \\
    95   \bl{$der\, c\, (\ZERO)$}      & \bl{$\dn$} & \bl{$\ZERO$} & \\
    83   \bl{$der\, c\, (\epsilon)$}           & \bl{$\dn$} & \bl{$\varnothing$} & \\
    96   \bl{$der\, c\, (\ONE)$}           & \bl{$\dn$} & \bl{$\ZERO$} & \\
    84   \bl{$der\, c\, (d)$}                     & \bl{$\dn$} & \bl{if $c = d$ then $\epsilon$ else $\varnothing$} & \\
    97   \bl{$der\, c\, (d)$}                     & \bl{$\dn$} & \bl{if $c = d$ then $\ONE$ else $\ZERO$} & \\
    85   \bl{$der\, c\, (r_1 + r_2)$}        & \bl{$\dn$} & \bl{$der\, c\, r_1 + der\, c\, r_2$} & \\
    98   \bl{$der\, c\, (r_1 + r_2)$}        & \bl{$\dn$} & \bl{$der\, c\, r_1 + der\, c\, r_2$} & \\
    86   \bl{$der\, c\, (r_1 \cdot r_2)$}  & \bl{$\dn$}  & \bl{if $nullable (r_1)$}\\
    99   \bl{$der\, c\, (r_1 \cdot r_2)$}  & \bl{$\dn$}  & \bl{if $nullable (r_1)$}\\
    87   & & \bl{then $(der\,c\,r_1) \cdot r_2 + der\, c\, r_2$}\\ 
   100   & & \bl{then $(der\,c\,r_1) \cdot r_2 + der\, c\, r_2$}\\ 
    88   & & \bl{else $(der\, c\, r_1) \cdot r_2$}\\
   101   & & \bl{else $(der\, c\, r_1) \cdot r_2$}\\
    89   \bl{$der\, c\, (r^*)$}          & \bl{$\dn$} & \bl{$(der\,c\,r) \cdot (r^*)$} &\medskip\\
   102   \bl{$der\, c\, (r^*)$}          & \bl{$\dn$} & \bl{$(der\,c\,r) \cdot (r^*)$} &\medskip\\
   118 
   131 
   119 \begin{center}
   132 \begin{center}
   120 \bl{$nullable(r)$} \;if and only if\;  \bl{$[] \in L(r)$}
   133 \bl{$nullable(r)$} \;if and only if\;  \bl{$[] \in L(r)$}
   121 \end{center}
   134 \end{center}
   122 
   135 
   123 by induction on the regular expression.\bigskip\pause
   136 by induction on the regular expression \bl{$r$}.\bigskip\pause
   124 
   137 
   125 \begin{center}
   138 \begin{center}
   126 {\huge\bf\alert{Any Questions?}}
   139 {\huge\bf\alert{Any Questions?}}
   127 \end{center}
   140 \end{center}
   128 
   141 
   136 
   149 
   137 \begin{center}
   150 \begin{center}
   138 \bl{$L(der\,c\,r) = Der\,c\,(L(r))$}
   151 \bl{$L(der\,c\,r) = Der\,c\,(L(r))$}
   139 \end{center}
   152 \end{center}
   140 
   153 
   141 by induction on the regular expression.
   154 also by induction on the regular expression \bl{$r$}.
   142 \end{frame}
   155 \end{frame}
   143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   144 
   157 
   145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   146 \begin{frame}[c]
   159 \begin{frame}[c]
   147 \frametitle{Proofs about Rexps}
   160 \frametitle{Proofs about Rexps}
   148 
   161 
   149 \begin{itemize}
   162 \begin{itemize}
   150 \item \bl{$P$} holds for \bl{$\varnothing$}, \bl{$\epsilon$} and \bl{c}\bigskip
   163 \item \bl{$P$} holds for \bl{$\ZERO$}, \bl{$\ONE$} and \bl{c}\bigskip
   151 \item \bl{$P$} holds for \bl{$r_1 + r_2$} under the assumption that \bl{$P$} already
   164 \item \bl{$P$} holds for \bl{$r_1 + r_2$} under the assumption that \bl{$P$} already
   152 holds for \bl{$r_1$} and \bl{$r_2$}.\bigskip
   165 holds for \bl{$r_1$} and \bl{$r_2$}.\bigskip
   153 \item \bl{$P$} holds for \bl{$r_1 \cdot r_2$} under the assumption that \bl{$P$} already
   166 \item \bl{$P$} holds for \bl{$r_1 \cdot r_2$} under the assumption that \bl{$P$} already
   154 holds for \bl{$r_1$} and \bl{$r_2$}.\bigskip
   167 holds for \bl{$r_1$} and \bl{$r_2$}.\bigskip
   155 \item \bl{$P$} holds for \bl{$r^*$} under the assumption that \bl{$P$} already
   168 \item \bl{$P$} holds for \bl{$r^*$} under the assumption that \bl{$P$} already
   182 \begin{frame}[t]
   195 \begin{frame}[t]
   183 \frametitle{Regular Expressions}
   196 \frametitle{Regular Expressions}
   184 
   197 
   185 \begin{center}
   198 \begin{center}
   186    \begin{tabular}{@ {}rrl@ {\hspace{13mm}}l}
   199    \begin{tabular}{@ {}rrl@ {\hspace{13mm}}l}
   187   \bl{$r$} & \bl{$::=$}  & \bl{$\varnothing$}  & null\\
   200   \bl{$r$} & \bl{$::=$}  & \bl{$\ZERO$}  & null\\
   188          & \bl{$\mid$} & \bl{$\epsilon$}        & empty string / "" / $[]$\\
   201          & \bl{$\mid$} & \bl{$\ONE$}        & empty string / "" / $[]$\\
   189          & \bl{$\mid$} & \bl{$c$}                         & character\\
   202          & \bl{$\mid$} & \bl{$c$}                         & character\\
   190          & \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\
   203          & \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\
   191          & \bl{$\mid$} & \bl{$r_1 + r_2$}  & alternative / choice\\
   204          & \bl{$\mid$} & \bl{$r_1 + r_2$}  & alternative / choice\\
   192          & \bl{$\mid$} & \bl{$r^*$}                   & star (zero or more)\\
   205          & \bl{$\mid$} & \bl{$r^*$}                   & star (zero or more)\\
   193   \end{tabular}
   206   \end{tabular}
   471 \begin{frame}[c]
   484 \begin{frame}[c]
   472 \frametitle{Rexp to NFA}
   485 \frametitle{Rexp to NFA}
   473 
   486 
   474 \begin{center}
   487 \begin{center}
   475 \begin{tabular}[t]{l@{\hspace{10mm}}l}
   488 \begin{tabular}[t]{l@{\hspace{10mm}}l}
   476 \raisebox{1mm}{\bl{$\varnothing$}} & 
   489 \raisebox{1mm}{\bl{$\ZERO$}} & 
   477 \begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
   490 \begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
   478 \node[state, initial]  (q_0)  {$\mbox{}$};
   491 \node[state, initial]  (q_0)  {$\mbox{}$};
   479 \end{tikzpicture}\\\\
   492 \end{tikzpicture}\\\\
   480 \raisebox{1mm}{\bl{$\epsilon$}} & 
   493 \raisebox{1mm}{\bl{$\ONE$}} & 
   481 \begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
   494 \begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
   482 \node[state, initial, accepting]  (q_0)  {$\mbox{}$};
   495 \node[state, initial, accepting]  (q_0)  {$\mbox{}$};
   483 \end{tikzpicture}\\\\
   496 \end{tikzpicture}\\\\
   484 \raisebox{2mm}{\bl{$c$}} & 
   497 \raisebox{2mm}{\bl{$c$}} & 
   485 \begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
   498 \begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
   713 \frametitle{Removing Dead States}
   726 \frametitle{Removing Dead States}
   714 
   727 
   715 \footnotesize
   728 \footnotesize
   716 \begin{center}
   729 \begin{center}
   717 \begin{tabular}{ll}
   730 \begin{tabular}{ll}
   718 DFA: & NFA:\\
   731 DFA: & (original) NFA:\\
   719 \raisebox{10mm}{%
   732 \raisebox{10mm}{%
   720 \begin{tikzpicture}[scale=0.7,>=stealth',very thick,
   733 \begin{tikzpicture}[scale=0.7,>=stealth',very thick,
   721                     every state/.style={minimum size=0pt,
   734                     every state/.style={minimum size=0pt,
   722                     draw=blue!50,very thick,fill=blue!20}]
   735                     draw=blue!50,very thick,fill=blue!20}]
   723 \node[state,initial,accepting]  (q012)  {$\{0,1,2\}$};
   736 \node[state,initial,accepting]  (q012)  {$\{0,1,2\}$};
  1051             ;
  1064             ;
  1052 \end{tikzpicture}
  1065 \end{tikzpicture}
  1053 \end{center}\pause\bigskip
  1066 \end{center}\pause\bigskip
  1054 
  1067 
  1055 \onslide<2->{
  1068 \onslide<2->{
       
  1069 You know how to solve since school days, no?
  1056 \begin{center}
  1070 \begin{center}
  1057 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1071 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1058 \bl{$q_0$} & \bl{$=$} & \bl{$2\, q_0 + 3 \,q_1 +  4\, q_2$}\\
  1072 \bl{$q_0$} & \bl{$=$} & \bl{$2\, q_0 + 3 \,q_1 +  4\, q_2$}\\
  1059 \bl{$q_1$} & \bl{$=$} & \bl{$2 \,q_0 + 3\, q_1 + 1\, q_2$}\\
  1073 \bl{$q_1$} & \bl{$=$} & \bl{$2 \,q_0 + 3\, q_1 + 1\, q_2$}\\
  1060 \bl{$q_2$} & \bl{$=$} & \bl{$1\, q_0 + 5\, q_1 + 2\, q_2$}\\
  1074 \bl{$q_2$} & \bl{$=$} & \bl{$1\, q_0 + 5\, q_1 + 2\, q_2$}\\
  1086 \end{center}\bigskip
  1100 \end{center}\bigskip
  1087 
  1101 
  1088 \onslide<2->{
  1102 \onslide<2->{
  1089 \begin{center}
  1103 \begin{center}
  1090 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1104 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1091 \bl{$q_0$} & \bl{$=$} & \bl{$\epsilon + q_0\,b + q_1\,b +  q_2\,b$}\\
  1105 \bl{$q_0$} & \bl{$=$} & \bl{$\ONE + q_0\,b + q_1\,b +  q_2\,b$}\\
  1092 \bl{$q_1$} & \bl{$=$} & \bl{$q_0\,a$}\\
  1106 \bl{$q_1$} & \bl{$=$} & \bl{$q_0\,a$}\\
  1093 \bl{$q_2$} & \bl{$=$} & \bl{$q_1\,a + q_2\,a$}\\
  1107 \bl{$q_2$} & \bl{$=$} & \bl{$q_1\,a + q_2\,a$}\\
  1094 
  1108 
  1095 \end{tabular}
  1109 \end{tabular}
  1096 \end{center}
  1110 \end{center}
  1149 
  1163 
  1150 Given the function 
  1164 Given the function 
  1151 
  1165 
  1152 \begin{center}
  1166 \begin{center}
  1153 \bl{\begin{tabular}{r@{\hspace{1mm}}c@{\hspace{1mm}}l}
  1167 \bl{\begin{tabular}{r@{\hspace{1mm}}c@{\hspace{1mm}}l}
  1154 $rev(\varnothing)$   & $\dn$ & $\varnothing$\\
  1168 $rev(\ZERO)$   & $\dn$ & $\ZERO$\\
  1155 $rev(\epsilon)$         & $\dn$ & $\epsilon$\\
  1169 $rev(\ONE)$         & $\dn$ & $\ONE$\\
  1156 $rev(c)$                      & $\dn$ & $c$\\
  1170 $rev(c)$                      & $\dn$ & $c$\\
  1157 $rev(r_1 + r_2)$        & $\dn$ & $rev(r_1) + rev(r_2)$\\
  1171 $rev(r_1 + r_2)$        & $\dn$ & $rev(r_1) + rev(r_2)$\\
  1158 $rev(r_1 \cdot r_2)$  & $\dn$ & $rev(r_2) \cdot rev(r_1)$\\
  1172 $rev(r_1 \cdot r_2)$  & $\dn$ & $rev(r_2) \cdot rev(r_1)$\\
  1159 $rev(r^*)$                   & $\dn$ & $rev(r)^*$\\
  1173 $rev(r^*)$                   & $\dn$ & $rev(r)^*$\\
  1160 \end{tabular}}
  1174 \end{tabular}}