
diff -r e5453add7df6 -r fb4cd144a9e6 slides/slides05.tex
--- a/slides/slides05.tex	Tue Dec 03 01:22:16 2019 +0000
+++ b/slides/slides05.tex	Tue Dec 03 01:58:19 2019 +0000
@@ -1,9 +1,12 @@
+% !TEX program = xelatex
 \documentclass[dvipsnames,14pt,t,xelatex]{beamer}
 \usepackage{../slides}
 \usepackage{../graphics}
 \usepackage{../langs}
 %%\usepackage{../data}
-\usepackage[export]{adjustbox}
+%%\usepackage[export]{adjustbox}
+\usetikzlibrary{shapes,arrows,shadows}
+
 
 \hfuzz=220pt 
 
@@ -21,61 +24,6 @@
 % beamer stuff 
 \renewcommand{\slidecaption}{PEP (Scala) 05, King's College London}
 
-\begin{filecontents}{re3a.data}
-1 0.00003
-500001 0.22527
-1000001 0.62752
-1500001 0.88485
-2000001 1.39815
-2500001 1.68619
-3000001 1.94957
-3500001 2.15878
-4000001 2.59918
-4500001 5.90679
-5000001 13.11295
-5500001 19.15376
-6000001 40.16373
-\end{filecontents}
-\begin{filecontents}{re-python2.data}
-1 0.033
-5 0.036
-10 0.034
-15 0.036
-18 0.059
-19 0.084
-20 0.141
-21 0.248
-22 0.485
-23 0.878
-24 1.71
-25 3.40
-26 7.08
-27 14.12
-28 26.69
-\end{filecontents}
-
-\begin{filecontents}{re-java.data}
-5  0.00298
-10  0.00418
-15  0.00996
-16  0.01710
-17  0.03492
-18  0.03303
-19  0.05084
-20  0.10177
-21  0.19960
-22  0.41159
-23  0.82234
-24  1.70251
-25  3.36112
-26  6.63998
-27  13.35120
-28  29.81185
-\end{filecontents}
-
-%All O2 technical teams are working closely with one of our third party suppliers who has identified a global software issue in their system which has impacted data services.  
-
-
 \begin{document}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[t]
@@ -89,100 +37,245 @@
   \begin{center}
   \begin{tabular}{ll}
     Email:  & christian.urban at kcl.ac.uk\\
-    Office: & N\liningnums{7.07} (North Wing, Bush House)\\
-    Slides \& Code: & KEATS\medskip\\
-    Office Hours: &  Mondays 12:00 -- 14:00\\
+    Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\
+    Slides \& Code: & KEATS\\
+                    & \onslide<2>{\alert{PDF: A Crash-Course in Scala}}\bigskip\\
+    Office Hours: &  Thursdays 12:00 -- 14:00\\
+    Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\ 
   \end{tabular}
   \end{center}
 
-
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
 \begin{frame}[c]
-\frametitle{Marks for CW7 (Part 1 +  2)}
+\frametitle{Marks for Preliminary 8}
+
+Raw marks (265 submissions):\bigskip
 
-Raw marks (234 submissions):
+\begin{itemize}
+\item 4\%: \hspace{4mm}211
+\item 3\%: \hspace{4mm}11
+\item 2\%: \hspace{4mm}14
+\item 1\%: \hspace{4mm}8
+\item 0\%: \hspace{4mm}21
+\end{itemize}\bigskip\bigskip  
+
+\footnotesize
+(plagiarism/collusion interviews ongoing again!)
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+
+\begin{frame}[c]
+\frametitle{Plan for Today}
 
 \begin{itemize}
-\item 6\%: \hspace{4mm}192 students
-\item 5\%: \hspace{4mm}16
-\item 4\%: \hspace{4mm}7
-\item 3\%: \hspace{4mm}2
-\item 2\%: \hspace{4mm}6
-\item 1\%: \hspace{4mm}1
-\item 0\%: \hspace{4mm}9 
-\end{itemize}  
+\item Being Lazy
+\item Polymorphic Types
+\item Immutable OOP
+\item Making Fun about Scala
+\end{itemize}
+
 \end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+\begin{frame}[c,fragile]
+\frametitle{How To calcululate 100 Mio Collatz Series?} 
+
+\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=1mm]
+(1L to 100_000_000).map(collatz).max
+\end{lstlisting}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+\begin{frame}[c,fragile]
+\frametitle{Polyorphic Types} 
+
+To be avoided:\bigskip\bigskip
+\small
+
+\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-6mm]
+def length_string_list(lst: List[String]): Int = 
+ lst match {
+   case Nil => 0
+   case x::xs => 1 + length_string_list(xs)
+ }
 
 
+def length_int_list(lst: List[Int]): Int = 
+ lst match {
+   case Nil => 0
+   case x::xs => 1 + length_int_list(xs)
+ }
+\end{lstlisting}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+\begin{frame}[c,fragile]
+\frametitle{Polyorphic Types} 
+
+\small
+
+\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-6mm]
+def length[A](lst: List[A]): Int = lst match {
+  case Nil => 0
+  case x::xs => 1 + length(xs)
+}
+
+length(List("1", "2", "3", "4"))
+length(List(1, 2, 3, 4))
+
+
+def map[A, B](lst: List[A], f: A => B): List[B] = 
+ lst match {
+   case Nil => Nil
+   case x::xs => f(x)::map(xs, f) 
+ }
+\end{lstlisting}
+\end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c,fragile]
-\small
+\begin{frame}[c]
+\frametitle{DFAs}  
+
+\begin{center}
+\begin{tikzpicture}[>=stealth',very thick,auto,
+  every state/.style={minimum size=0pt,inner sep=2pt,
+    draw=blue!50,very thick,fill=blue!20},]
   
-\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm]
-def get_csv_url(url: String) : List[String] = {
-  val csv = Try(Source.fromURL(url)).getOrElse(null)
-   if (csv == null){
-     List()
-   }
-   else {
-     ....
-   }
-}
-\end{lstlisting}
+\only<1,3->{\node[state,initial] (Q_0)  {$\mbox{Q}_0$};}
+\only<2>{\node[state,initial,fill=red] (Q_0)  {$\mbox{Q}_0$};}  
+\only<1,2,4->{\node[state] (Q_1) [right=of Q_0] {$\mbox{Q}_1$};}
+\only<3>{\node[state,fill=red] (Q_1) [right=of Q_0] {$\mbox{Q}_1$};}
+\only<-3,5->{\node[state] (Q_2) [below right=of Q_0] {$\mbox{Q}_2$};}
+\only<4>{\node[state,fill=red] (Q_2) [below right=of Q_0] {$\mbox{Q}_2$};}
+\only<-4,6->{\node[state] (Q_3) [right=of Q_2] {$\mbox{Q}_3$};}
+\only<5>{\node[state,fill=red] (Q_3) [right=of Q_2] {$\mbox{Q}_3$};}
+\only<-5>{\node[state, accepting] (Q_4) [right=of Q_1] {$\mbox{Q}_4$};}
+\only<6->{\node[state, accepting,fill=red] (Q_4) [right=of Q_1] {$\mbox{Q}_4$};}
+
+\path[->] (Q_0) edge node [above]  {\alert{$a$}} (Q_1);
+\path[->] (Q_1) edge node [above]  {\alert{$a$}} (Q_4);
+\path[->] (Q_4) edge [loop right] node  {\alert{$a, b$}} ();
+\path[->] (Q_3) edge node [right]  {\alert{$a$}} (Q_4);
+\path[->] (Q_2) edge node [above]  {\alert{$a$}} (Q_3);
+\path[->] (Q_1) edge node [right]  {\alert{$b$}} (Q_2);
+\path[->] (Q_0) edge node [above]  {\alert{$b$}} (Q_2);
+\path[->] (Q_2) edge [loop left] node  {\alert{$b$}} ();
+\path[->] (Q_3) edge [bend left=95, looseness=1.3] node [below]  {\alert{$b$}} (Q_0);
+\end{tikzpicture}
+\end{center}
 
-\pause
-\bigskip
-\rule{11cm}{0.3mm}
-\bigskip
+\begin{textblock}{9}(4,12)
+\LARGE{}
+\only<3->{\boldmath\alert{$a$}}%
+\only<4->{\boldmath\alert{$b$}}%
+\only<5->{\boldmath\alert{$a$}}%
+\only<6->{\boldmath\alert{$a$}}%
+\only<7->{\boldmath\alert{$a\quad\Rightarrow \textbf{yes}$}}% 
+\end{textblock}
+  
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[t]
+\frametitle{DFAs}
 
-\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm]
-def get_csv_url(url: String) : List[String] = {
-  Try(Source.fromURL(url)....).getOrElse(Nil)
-\end{lstlisting}
+A \alert{\bf deterministic finite automaton} (DFA) consists of
+5 things:
 
+\begin{itemize}
+\item an alphabet \bl{$\varSigma$}  
+\item a set of states \bl{$\mbox{Qs}$}
+\item one of these states is the start state \bl{$\mbox{Q}_0$}
+\item some states are accepting states \bl{$F$}, and
+\item there is transition function \bl{$\delta$}\bigskip 
+
+\small
+which takes a state  and a character as arguments and produces a 
+new state; this function might not be everywhere defined 
+\end{itemize}
+
+\begin{center}
+\bl{$A(\varSigma, \mbox{Qs}, \mbox{Q}_0, F, \delta)$}
+\end{center}
 
 \end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{NFAs}  
 
+\begin{center}
+\begin{tikzpicture}[>=stealth',very thick, auto,
+    every state/.style={minimum size=0pt,inner sep=3pt,
+      draw=blue!50,very thick,fill=blue!20},scale=2]
+\node[state,initial]  (Q_0)  {$\mbox{Q}_0$};
+\node[state] (Q_1) [right=of Q_0] {$\mbox{Q}_1$};
+\node[state, accepting] (Q_2) [right=of Q_1] {$\mbox{Q}_2$};
+\path[->] (Q_0) edge [loop above] node  {\alert{$b$}} ();
+\path[<-] (Q_0) edge node [below]  {\alert{$b$}} (Q_1);
+\path[->] (Q_0) edge [bend left] node [above]  {\alert{$a$}} (Q_1);
+\path[->] (Q_0) edge [bend right=45,looseness=1.3] node [below]  {\alert{$a$}} (Q_2);
+\path[->] (Q_1) edge [loop above] node  {\alert{$a,b$}} ();
+\path[->] (Q_1) edge node  [above] {\alert{$a$}} (Q_2);
+\end{tikzpicture}
+\end{center}
 
-
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c,fragile]
-\small
-  
-\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm]
-def get_csv_url(url: String) : List[String] = {
-    try {
-        val csvFile = Source.fromURL(url)
-        ....
-    } catch {
-        case unknown : Throwable => List()
-    }
-}
-\end{lstlisting}
+\tikzstyle{sensor}=[draw, fill=blue!20, text width=3.8em, line width=1mm,
+    text centered, minimum height=2em,drop shadow]
+\tikzstyle{ann} = [above, text width=4em, text centered]
+\tikzstyle{sc} = [sensor, text width=7em, fill=red!20, 
+    minimum height=6em, rounded corners, drop shadow,line width=1mm]
+
+\begin{frame}[fragile,c]
+\frametitle{Compilers 6CCS3CFL}
 
-
-\bigskip
-\rule{11cm}{0.3mm}
-\bigskip
+\begin{tikzpicture}
+    % Validation Layer is the same except that there are a set of nodes and links which are added
+   
+    \path (0,0) node (IR) [sc] {\textbf{WHILE Language}\\ compiler};
+    \path (IR.west)+(-2.2,1.7) node (sou1) [sensor] {Fact};
+    \path (IR.west)+(-2.2,0.5) node (sou2)[sensor] {Fib};
+    \path (IR.west)+(-2.2,-0.7) node (sou4)[sensor] {Primes}; 
+    \only<2>{\path (IR.west)+(-2.2,-1.9) node (sou3)[sensor] {BrainF**k};}    
 
-\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm]
-def get_csv_url(url: String) : List[String] = {
-  Try(Source.fromURL(url)....).getOrElse(Nil)
-\end{lstlisting}
+    \path [draw,->,line width=1mm] (sou1.east) -- node [above] {} (IR.160);
+    \path [draw,->,line width=1mm] (sou2.east) -- node [above] {} (IR.180);
+    \only<2>{\path [draw,->,line width=1mm] (sou3.east) -- node [above] {} (IR.200);}
+    \path [draw,->,line width=1mm] (sou4.east) -- node [above] {} (IR.190);
+
+    \path (IR.east)+(2.2, 0.8) node (tar2)[sensor] {JVM};
+    \path (IR.east)+(2.2,-0.8) node (tar3)[sensor] {LLVM{\small(x86)}}; 
 
+    \path [draw,<-,line width=1mm] (tar2.west) -- node [above] {} (IR.5);
+    \path [draw,<-,line width=1mm] (tar3.west) -- node [above] {} (IR.-5);
 
+    
+\end{tikzpicture}
 \end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   \begin{frame}[c]
@@ -294,62 +387,6 @@
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
-\begin{frame}[c]
-  \frametitle{CW9 : Regexes}
-  
-\begin{center}
-  Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip
-  
-\begin{tabular}[t]{@{\hspace{-8mm}}c@{\hspace{-4mm}}c@{}}
-\raisebox{6mm}{\begin{tikzpicture}
-\begin{axis}[
-    xlabel={$n$},
-    x label style={at={(1.05,0.0)}},
-    ylabel={time in secs},
-    enlargelimits=false,
-    xtick={0,5,...,30},
-    xmax=33,
-    ymax=35,
-    ytick={0,5,...,30},
-    scaled ticks=false,
-    axis lines=left,
-    width=5.5cm,
-    height=5cm, 
-    legend entries={Python,  Java 8},  
-    legend pos=north west,
-    legend cell align=left]
-\addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};  
-\addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
-\end{axis}
-\end{tikzpicture}}
-  &
-\onslide<1>{\begin{tikzpicture}
-  \begin{axis}[
-    xlabel={$n$},
-    x label style={at={(1.05,0.0)}},
-    ylabel={time in secs},
-    enlargelimits=false,
-    ymax=35,
-    ytick={0,5,...,30},
-    axis lines=left,
-    %%scaled ticks=false,
-    width=5.5cm, 
-    height=5cm]
-%%\addplot[green,mark=square*,mark options={fill=white}] table {re2a.data};    
-\addplot[red,mark=square*,mark options={fill=white}] table {re3a.data};
-\end{axis}
-\end{tikzpicture}}
-\end{tabular}
-\end{center}
-
-
-\small
-\hfill Kuklewicz: most POSIX matchers are buggy\\
-\footnotesize
-\hfill \url{http://www.haskell.org/haskellwiki/Regex_Posix}
-\end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
 \begin{frame}[c]
@@ -357,7 +394,7 @@
 
 \begin{itemize}
 \item Martin Odersky (EPFL)\ldots he is currently throwing out everything
-  and starts again with the dotty compiler for Scala\medskip
+  and starts again with the dotty compiler for Scala 3.0\medskip
 
 \item Elm (\url{http://elm-lang.org})\ldots web applications with style\medskip   
 
@@ -425,27 +462,6 @@
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
-
-\begin{frame}[c]
-\frametitle{Marks for CW6 (Part 1 + 2)}
-
-Raw marks:
-
-\begin{itemize}
-\item 6\%: 154 students
-\item 5\%: 66
-\item 4\%: 18
-\item 3\%: 13
-\item 2\%: 2
-\item 1\%: 1
-\item 0\%: 21 
-\end{itemize}  
-\end{frame}
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
 \end{document}
 
 




