handouts/ho03.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 27 Aug 2014 16:11:32 +0100
changeset 230 0fd668d7b619
parent 217 cd6066f1056a
child 251 5b5a68df6d16
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
140
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{hyperref}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage{amssymb}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
\usepackage{amsmath}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\usepackage[T1]{fontenc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\usepackage{listings}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\usepackage{xcolor}
142
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
     8
\usepackage{tikz}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
     9
\usetikzlibrary{arrows}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    10
\usetikzlibrary{automata}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    11
\usetikzlibrary{shapes}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    12
\usetikzlibrary{shadows}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    13
\usetikzlibrary{positioning}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    14
\usetikzlibrary{calc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    15
\usetikzlibrary{fit}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    16
\usetikzlibrary{backgrounds}
217
cd6066f1056a updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 144
diff changeset
    17
\usepackage{../langs}
140
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
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}%
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
141
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 140
diff changeset
    24
\section*{Handout 3}
140
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
142
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    26
Let us have a closer look at automata and their relation to regular expressions. This will help us to understand
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    27
why the regular expression matchers in Python and Ruby are so slow with certain regular expressions. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    28
143
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    29
A \emph{deterministic finite automaton} (DFA), say $A$, is defined by  a four-tuple written $A(Q, q_0, F, \delta)$ where
142
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    31
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    32
\item $Q$ is a set of states,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    33
\item $q_0 \in Q$ is the start state,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    34
\item $F \subseteq Q$ are the accepting states, and
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    35
\item $\delta$ is the transition function.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    36
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    37
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    38
\noindent
143
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    39
The transition function determines how to ``transition'' from one state to the next state with respect to a character.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    40
We have the assumption that these functions do not need to be defined everywhere: so it can be the case that
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    41
given a character there is no next state, in which case we need to raise a kind of ``raise an exception''.  A typical 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    42
example of a DFA is
142
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    43
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    44
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    45
\begin{tikzpicture}[>=stealth',very thick,auto,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    46
                             every state/.style={minimum size=0pt,inner sep=2pt,draw=blue!50,very thick,fill=blue!20},]
143
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    47
\node[state,initial]  (q_0)  {$q_0$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    48
\node[state] (q_1) [right=of q_0] {$q_1$};
142
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    49
\node[state] (q_2) [below right=of q_0] {$q_2$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    50
\node[state] (q_3) [right=of q_2] {$q_3$};
143
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    51
\node[state, accepting] (q_4) [right=of q_1] {$q_4$};
142
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    52
\path[->] (q_0) edge node [above]  {$a$} (q_1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    53
\path[->] (q_1) edge node [above]  {$a$} (q_4);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    54
\path[->] (q_4) edge [loop right] node  {$a, b$} ();
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    55
\path[->] (q_3) edge node [right]  {$a$} (q_4);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    56
\path[->] (q_2) edge node [above]  {$a$} (q_3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    57
\path[->] (q_1) edge node [right]  {$b$} (q_2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    58
\path[->] (q_0) edge node [above]  {$b$} (q_2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    59
\path[->] (q_2) edge [loop left] node  {$b$} ();
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    60
\path[->] (q_3) edge [bend left=95, looseness=1.3] node [below]  {$b$} (q_0);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    61
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 141
diff changeset
    62
\end{center}
140
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
143
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    64
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    65
The accepting state $q_4$ is indicated with double circles. It is possible that a DFA has no
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    66
accepting states at all, or that the starting state is also an accepting state.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    67
In the case above the transition function is defined everywhere and can be given as a table
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    68
as follows:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    70
\[
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    71
\begin{array}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    72
(q_0, a) &\rightarrow& q_1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    73
(q_0, b) &\rightarrow& q_2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    74
(q_1, a) &\rightarrow& q_4\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    75
(q_1, b) &\rightarrow& q_2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    76
(q_2, a) &\rightarrow& q_3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    77
(q_2, b) &\rightarrow& q_2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    78
(q_3, a) &\rightarrow& q_4\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    79
(q_3, b) &\rightarrow& q_0\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    80
(q_4, a) &\rightarrow& q_4\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    81
(q_4, b) &\rightarrow& q_4\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    82
\end{array}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    83
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    84
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    85
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    86
We need to define the notion of what language is accepted by an automaton. For this we 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    87
lift the transition function $\delta$ from characters to strings as follows:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    88
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    89
\[
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    90
\begin{array}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    91
\hat{\delta}(q, "")        & \dn & q\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    92
\hat{\delta}(q, c\!::\!s) & \dn & \hat{\delta}(\delta(q, c), s)\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    93
\end{array}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    94
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    95
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    96
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    97
Given a string this means we start in the starting state and take the first character of the string,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    98
follow to the next sate, then take the second character and so on. Once the string is exhausted
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
    99
and we end up in an accepting state, then this string is accepted. Otherwise it is not accepted. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   100
So $s$ in the \emph{language accepted by the automaton} $A(Q, q_0, F, \delta)$ iff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   101
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   102
\[
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   103
\hat{\delta}(q_0, s) \in F 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   104
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   105
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   106
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   107
While with DFA it will always clear that given a character what the next state is, it will be useful to relax 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   108
this restriction. The resulting construction is called a \emph{non-deterministic finite automaton} (NFA) given
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   109
as a four-tuple $A(Q, q_0, F, \rho)$ where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   110
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   111
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   112
\item $Q$ is a finite set of states
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   113
\item $q_0$ is a start state
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   114
\item $F$ are some accepting states with $F \subseteq Q$, and
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   115
\item $\rho$ is a transition relation.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   116
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   117
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   118
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   119
Two typical examples of NFAs are
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   120
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   121
\begin{tabular}[t]{c@{\hspace{9mm}}c}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   122
\begin{tikzpicture}[scale=0.7,>=stealth',very thick,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   123
                             every state/.style={minimum size=0pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   124
\node[state,initial]  (q_0)  {$q_0$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   125
\node[state] (q_1) [above=of q_0] {$q_1$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   126
\node[state, accepting] (q_2) [below=of q_0] {$q_2$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   127
\path[->] (q_0) edge node [left]  {$\epsilon$} (q_1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   128
\path[->] (q_0) edge node [left]  {$\epsilon$} (q_2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   129
\path[->] (q_0) edge [loop right] node  {$a$} ();
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   130
\path[->] (q_1) edge [loop above] node  {$a$} ();
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   131
\path[->] (q_2) edge [loop below] node  {$b$} ();
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   132
\end{tikzpicture} &
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   133
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   134
\raisebox{20mm}{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   135
\begin{tikzpicture}[scale=0.7,>=stealth',very thick,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   136
                             every state/.style={minimum size=0pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   137
\node[state,initial]  (r_1)  {$r_1$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   138
\node[state] (r_2) [above=of r_1] {$r_2$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   139
\node[state, accepting] (r_3) [right=of r_1] {$r_3$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   140
\path[->] (r_1) edge node [below]  {$b$} (r_3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   141
\path[->] (r_2) edge [bend left] node [above]  {$a$} (r_3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   142
\path[->] (r_1) edge [bend left] node  [left] {$\epsilon$} (r_2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   143
\path[->] (r_2) edge [bend left] node  [right] {$a$} (r_1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   144
\end{tikzpicture}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   145
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   146
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   147
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   148
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   149
There are a number of points you should note. Every DFA is a NFA, but not vice versa.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   150
The $\rho$ in NFAs is a transition \emph{relation} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   151
(DFAs have a transition function). The difference between a function and a relation is that a function 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   152
has always a single output, while a relation gives, roughly speaking, several outputs. Look
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   153
at the NFA on the right-hand side above: if you are currently in the state $r_2$ and you read a
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   154
character $a$, then you can transition to $r_1$ \emph{or} $r_3$. Which route you take is not
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   155
determined. This means if we need to decide whether a string is accepted by a NFA, we might have 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   156
to explore all possibilities. Also there is a special transition in NFAs which is called \emph{epsilon-transition}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   157
or \emph{silent transition}. This transition means you do not have to ``consume'' no part of
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   158
the input string, but ``silently'' change to a different state.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   159
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   160
The reason for introducing NFAs is that there is a relatively simple (recursive) translation of regular expressions into
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   161
NFAs. Consider the simple regular expressions $\varnothing$, $\epsilon$ and $c$. They can be translated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   162
as follows:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   163
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   164
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   165
\begin{tabular}[t]{l@{\hspace{10mm}}l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   166
\raisebox{1mm}{$\varnothing$} & 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   167
\begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   168
\node[state, initial]  (q_0)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   169
\end{tikzpicture}\\\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   170
\raisebox{1mm}{$\epsilon$} & 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   171
\begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   172
\node[state, initial, accepting]  (q_0)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   173
\end{tikzpicture}\\\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   174
\raisebox{2mm}{$c$} & 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   175
\begin{tikzpicture}[scale=0.7,>=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   176
\node[state, initial]  (q_0)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   177
\node[state, accepting]  (q_1)  [right=of q_0] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   178
\path[->] (q_0) edge node [below]  {$c$} (q_1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   179
\end{tikzpicture}\\\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   180
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   181
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   182
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   183
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   184
The case for the sequence regular expression $r_1 \cdot r_2$ is as follows: We are given by recursion
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   185
two automata representing $r_1$ and $r_2$ respectively. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   186
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   187
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   188
\begin{tikzpicture}[node distance=3mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   189
                             >=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   190
\node[state, initial]  (q_0)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   191
\node (r_1)  [right=of q_0] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   192
\node[state, accepting]  (t_1)  [right=of r_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   193
\node[state, accepting]  (t_2)  [above=of t_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   194
\node[state, accepting]  (t_3)  [below=of t_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   195
\node[state, initial]  (a_0)  [right=2.5cm of t_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   196
\node (b_1)  [right=of a_0] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   197
\node[state, accepting]  (c_1)  [right=of b_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   198
\node[state, accepting]  (c_2)  [above=of c_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   199
\node[state, accepting]  (c_3)  [below=of c_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   200
\begin{pgfonlayer}{background}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   201
\node (1) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (q_0) (r_1) (t_1) (t_2) (t_3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   202
\node (2) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (a_0) (b_1) (c_1) (c_2) (c_3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   203
\node [yshift=2mm] at (1.north) {$r_1$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   204
\node [yshift=2mm] at (2.north) {$r_2$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   205
\end{pgfonlayer}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   206
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   207
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   209
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   210
The first automaton has some accepting states. We obtain an automaton for $r_1\cdot r_2$ by connecting
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   211
these accepting states with $\epsilon$-transitions to the starting state of the second automaton. By doing 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   212
so we make them non-accepting like so:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   213
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   214
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   215
\begin{tikzpicture}[node distance=3mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   216
                             >=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   217
\node[state, initial]  (q_0)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   218
\node (r_1)  [right=of q_0] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   219
\node[state]  (t_1)  [right=of r_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   220
\node[state]  (t_2)  [above=of t_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   221
\node[state]  (t_3)  [below=of t_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   222
\node[state]  (a_0)  [right=2.5cm of t_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   223
\node (b_1)  [right=of a_0] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   224
\node[state, accepting]  (c_1)  [right=of b_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   225
\node[state, accepting]  (c_2)  [above=of c_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   226
\node[state, accepting]  (c_3)  [below=of c_1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   227
\path[->] (t_1) edge node [above, pos=0.3]  {$\epsilon$} (a_0);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   228
\path[->] (t_2) edge node [above]  {$\epsilon$} (a_0);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   229
\path[->] (t_3) edge node [below]  {$\epsilon$} (a_0);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   230
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   231
\begin{pgfonlayer}{background}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   232
\node (3) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (q_0) (c_1) (c_2) (c_3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   233
\node [yshift=2mm] at (3.north) {$r_1\cdot r_2$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   234
\end{pgfonlayer}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   235
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   236
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   237
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   238
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   239
The case for the choice regular expression $r_1 + r_2$ is slightly different: We are given by recursion
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   240
two automata representing $r_1$ and $r_2$ respectively. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   241
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   242
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   243
\begin{tikzpicture}[node distance=3mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   244
                             >=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   245
\node at (0,0)  (1)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   246
\node[state, initial]  (2)  [above right=16mm of 1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   247
\node[state, initial]  (3)  [below right=16mm of 1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   248
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   249
\node (a)  [right=of 2] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   250
\node[state, accepting]  (a1)  [right=of a] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   251
\node[state, accepting]  (a2)  [above=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   252
\node[state, accepting]  (a3)  [below=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   253
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   254
\node (b)  [right=of 3] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   255
\node[state, accepting]  (b1)  [right=of b] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   256
\node[state, accepting]  (b2)  [above=of b1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   257
\node[state, accepting]  (b3)  [below=of b1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   258
\begin{pgfonlayer}{background}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   259
\node (1) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (2) (a1) (a2) (a3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   260
\node (2) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (3) (b1) (b2) (b3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   261
\node [yshift=3mm] at (1.north) {$r_1$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   262
\node [yshift=3mm] at (2.north) {$r_2$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   263
\end{pgfonlayer}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   264
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   265
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   266
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   267
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   268
Each automaton has a single start state and potentially several accepting states. We obtain a
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   269
NFA for the regular expression $r_1 + r_2$ by introducing a new starting state and connecting it
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   270
with an $\epsilon$-transition to the two starting states above, like so
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   271
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   272
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   273
\hspace{2cm}\begin{tikzpicture}[node distance=3mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   274
                             >=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   275
\node at (0,0) [state, initial]  (1)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   276
\node[state]  (2)  [above right=16mm of 1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   277
\node[state]  (3)  [below right=16mm of 1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   278
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   279
\node (a)  [right=of 2] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   280
\node[state, accepting]  (a1)  [right=of a] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   281
\node[state, accepting]  (a2)  [above=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   282
\node[state, accepting]  (a3)  [below=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   283
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   284
\node (b)  [right=of 3] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   285
\node[state, accepting]  (b1)  [right=of b] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   286
\node[state, accepting]  (b2)  [above=of b1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   287
\node[state, accepting]  (b3)  [below=of b1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   288
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   289
\path[->] (1) edge node [above]  {$\epsilon$} (2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   290
\path[->] (1) edge node [below]  {$\epsilon$} (3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   291
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   292
\begin{pgfonlayer}{background}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   293
\node (3) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (1) (a2) (a3) (b2) (b3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   294
\node [yshift=3mm] at (3.north) {$r_1+ r_2$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   295
\end{pgfonlayer}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   296
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   297
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   298
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   299
\noindent 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   300
Finally for the $*$-case we have an automaton for $r$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   301
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   302
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   303
\begin{tikzpicture}[node distance=3mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   304
                             >=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   305
\node at (0,0)  (1)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   306
\node[state, initial]  (2)  [right=16mm of 1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   307
\node (a)  [right=of 2] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   308
\node[state, accepting]  (a1)  [right=of a] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   309
\node[state, accepting]  (a2)  [above=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   310
\node[state, accepting]  (a3)  [below=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   311
\begin{pgfonlayer}{background}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   312
\node (1) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (2) (a1) (a2) (a3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   313
\node [yshift=3mm] at (1.north) {$r$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   314
\end{pgfonlayer}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   315
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   316
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   317
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   318
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   319
and connect its accepting states to a new starting state via $\epsilon$-transitions. This new
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   320
starting state is also an accepting state, because $r^*$ can also recognise the empty string.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   321
This gives the following automaton for $r^*$:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   322
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   323
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   324
\begin{tikzpicture}[node distance=3mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   325
                             >=stealth',very thick, every state/.style={minimum size=3pt,draw=blue!50,very thick,fill=blue!20},]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   326
\node at (0,0) [state, initial,accepting]  (1)  {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   327
\node[state]  (2)  [right=16mm of 1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   328
\node (a)  [right=of 2] {$\ldots$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   329
\node[state]  (a1)  [right=of a] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   330
\node[state]  (a2)  [above=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   331
\node[state]  (a3)  [below=of a1] {$\mbox{}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   332
\path[->] (1) edge node [above]  {$\epsilon$} (2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   333
\path[->] (a1) edge [bend left=45] node [above]  {$\epsilon$} (1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   334
\path[->] (a2) edge [bend right] node [below]  {$\epsilon$} (1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   335
\path[->] (a3) edge [bend left=45] node [below]  {$\epsilon$} (1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   336
\begin{pgfonlayer}{background}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   337
\node (2) [rounded corners, inner sep=1mm, thick, draw=black!60, fill=black!20, fit= (1) (a2) (a3)] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   338
\node [yshift=3mm] at (2.north) {$r^*$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   339
\end{pgfonlayer}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   340
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   341
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   342
144
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 143
diff changeset
   343
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 143
diff changeset
   344
This construction of a NFA from a regular expression was invented by Ken Thompson in 1968.
143
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 142
diff changeset
   345
140
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
%%% End: