handouts/notation.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 23 Nov 2015 16:45:07 +0000
changeset 384 4629448c1bd9
parent 332 4755ad4b457b
child 398 c8ce95067c1a
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass{article}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{../style}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage{../langs}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\begin{document}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
\section*{A Crash-Course on Notation}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    11
There are innumerable books available about automata and
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    12
formal languages. Unfortunately, they often use their own
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    13
notational conventions and their own symbols. This handout is
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    14
meant to clarify some of the notation I will use.
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    15
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
\subsubsection*{Characters and Strings}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    18
The most important concept in this module are strings. Strings
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    19
are composed of \defn{characters}. While characters are surely
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    20
a familiar concept, we will make one subtle distinction in
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    21
this module. If we want to refer to concrete characters, like
332
4755ad4b457b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
    22
\code{a}, \code{b}, \code{c} and so on, we use a typewriter font.
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    23
Accordingly if we want to refer to the concrete characters of
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    24
my email address we shall write
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
\begin{center}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
\pcode{christian.urban@kcl.ac.uk}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
\end{center}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    30
\noindent If we also need to explicitly indicate the ``space''
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
character, we write \VS{}\hspace{1mm}. For example
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
\begin{center}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
\tt{}hello\VS\hspace{0.5mm}world
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
\end{center}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    38
\noindent But often we do not care which particular characters
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    39
we use. In such cases we use the italic font and write $a$,
332
4755ad4b457b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
    40
$b$, $c$ and so on for characters. Therefore if we need a
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
representative string, we might write
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
\begin{equation}\label{abracadabra}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
abracadabra
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
\end{equation}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    47
\noindent In this string, we do not really care what the
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    48
characters stand for, except we do care about the fact that
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    49
for example the character $a$ is not equal to $b$ and so on.
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    51
An \defn{alphabet} is a (non-empty) finite set of characters.
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    52
Often the letter $\Sigma$ is used to refer to an alphabet. For
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    53
example the ASCII characters \pcode{a} to \pcode{z} form an
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    54
alphabet. The digits $0$ to $9$ are another alphabet. The
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    55
Greek letters $\alpha$ to $\omega$ also form an alphabet. If
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    56
nothing else is specified, we usually assume the alphabet
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    57
consists of just the lower-case letters $a$, $b$, \ldots, $z$.
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    58
Sometimes, however, we explicitly want to restrict strings to
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    59
contain only the letters $a$ and $b$, for example. In this
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    60
case we will state that the alphabet is the set $\{a, b\}$. 
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
\defn{Strings} are lists of characters. Unfortunately, there
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
are many ways how we can write down strings. In programming
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
languages, they are usually written as \dq{$hello$} where the
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    65
double quotes indicate that we are dealing with a string. But
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    66
since we regard strings as lists of characters we could also
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    67
write this string as
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
\[
332
4755ad4b457b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
    70
[\text{\it h, e, l, l, o}] \;\;\text{or simply}\;\; \textit{hello}
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
\noindent The important point is that we can always decompose
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
such strings. For example, we will often consider the first
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
character of a string, say $h$, and the ``rest'' of a string
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
say \dq{\textit{ello}} when making definitions about strings.
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    77
There are also some subtleties with the empty string,
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    78
sometimes written as \dq{} but also as the empty list of
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    79
characters $[\,]$.\footnote{In the literature you can also
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    80
often find that $\varepsilon$ or $\lambda$ is used to
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    81
represent the empty string.} 
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    82
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    83
Two strings, say $s_1$ and $s_2$, can be \defn{concatenated},
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    84
which we write as $s_1 @ s_2$. Suppose we are given two
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    85
strings \dq{\textit{foo}} and \dq{\textit{bar}}, then their
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    86
concatenation, writen \dq{\textit{foo}} $@$ \dq{\textit{bar}},
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    87
gives \dq{\textit{foobar}}. Often we will simplify our life
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    88
and just drop the double quotes whenever it is clear we are
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    89
talking about strings, writing as already in
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    90
\eqref{abracadabra} just \textit{foo}, \textit{bar},
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    91
\textit{foobar} or \textit{foo $@$ bar}.
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
Some simple properties of string concatenation hold. For
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
example the concatenation operation is \emph{associative},
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
meaning
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
\[(s_1 @ s_2) @ s_3 = s_1 @ (s_2 @ s_3)\]  
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
\noindent are always equal strings. The empty string behaves
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
like a unit element, therefore
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
\[s \,@\, [] = [] \,@\, s = s\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   104
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   105
Occasionally we will use the notation $a^n$ for strings, which 
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   106
stands for the string of $n$ repeated $a$s. So $a^{n}b^{n}$ is
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   107
a string that has as many $a$s as $b$s.
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   108
246
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   109
Note however that while for us strings are just lists of
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   110
characters, programming languages often differentiate between
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   111
the two concepts. In Scala, for example, there is the type of
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   112
\code{String} and the type of lists of characters,
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   113
\code{List[Char]}. They are not the same and we need to
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   114
explicitly coerce elements between the two types, for example
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
\begin{lstlisting}[numbers=none]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
scala> "abc".toList
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
res01: List[Char] = List(a, b, c)
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
\end{lstlisting}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
\subsubsection*{Sets and Languages}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   124
We will use the familiar operations $\cup$, $\cap$, $\subset$
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   125
and $\subseteq$ for sets. For the empty set we will either
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   126
write $\varnothing$ or $\{\,\}$. The set containing the
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   127
natural numbers $1$, $2$ and $3$, for example, we will write
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   128
with curly braces as
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
\{1, 2, 3\}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
\noindent The notation $\in$ means \emph{element of}, so $1
266
ae039d6ae3f2 fixed typo
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   135
\in \{1, 2, 3\}$ is true and $4 \in \{1, 2, 3\}$ is false.
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
Sets can potentially have infinitely many elements. For
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
example the set of all natural numbers $\{0, 1, 2, \ldots\}$
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
is infinite. This set is often also abbreviated as
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   139
$\mathbb{N}$. We can define sets by giving all elements, for
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   140
example $\{0, 1\}$, but also by \defn{set comprehensions}. For
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   141
example the set of all even natural numbers can be defined as
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
\{n\;|\;n\in\mathbb{N} \wedge n\;\text{is even}\}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
  
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
\noindent Though silly, but the set $\{0, 1, 2\}$ could also be
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
defined by the following set comprehension
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
\{n\;|\; n^2 < 9 \wedge n \in \mathbb{N}\}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
\noindent Notice that set comprehensions could be used
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
to define set union, intersection and difference:
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
\begin{eqnarray*}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
A \cup B & \dn & \{x\;|\; x \in A \vee x \in B\}\\
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
A \cap B & \dn & \{x\;|\; x \in A \wedge x \in B\}\\
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
A \backslash B & \dn & \{x\;|\; x \in A \wedge x \not\in B\} 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
\end{eqnarray*}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   163
\noindent In general set comprehensions are of the form
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   164
$\{a\;|\;P\}$ which stands for the set of all elements $a$
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   165
(from some set) for which some property $P$ holds.
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   166
 
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   167
For defining sets, we will also often use the notion of the
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   168
``big union''. An example is as follows:
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
\begin{equation}\label{bigunion}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
\bigcup_{0\le n}\; \{n^2, n^2 + 1\}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
\end{equation}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
\noindent which is the set of all squares and their immediate
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
successors, so
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
\{0, 1, 2, 4, 5, 9, 10, 16, 17, \ldots\}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
\noindent A big union is a sequence of unions which are 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
indexed typically by a natural number. So the big union in
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
\eqref{bigunion} could equally be written as
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
\{0, 1\} \cup \{1, 2\} \cup \{4, 5\} \cup \{9, 10\} \cup 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
\ldots
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
\noindent but using the big union notation is more concise.
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   192
An important notion in this module are \defn{languages}, which
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
are sets of strings. The main goal for us will be how to
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
(formally) specify languages and to find out whether a string
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   195
is in a language or not.\footnote{You might wish to ponder
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   196
whether this is in general a hard or easy problem, where
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   197
hardness is meant in terms of Turing decidable, for example.}
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   198
Note that the language containing the empty string $\{\dq{}\}$
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   199
is not equal to $\varnothing$, the empty language (or empty
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   200
set): The former contains one element, namely \dq{} (also
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   201
written $[\,]$), but the latter does not contain any
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   202
element.
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
For languages we define the operation of \defn{language
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   205
concatenation}, written like in the string case as $A @ B$:
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
\begin{equation}\label{langconc}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
A @ B \dn \{s_1 @ s_2\;|\; s_1\in A \wedge s_2\in B\}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
\end{equation}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
\noindent Be careful to understand the difference: the $@$
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
in $s_1 @ s_2$ is string concatenation, while $A @ B$ refers 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
to the concatenation of two languages (or sets of strings).
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
As an example suppose $A=\{ab, ac\}$ and $B=\{zzz, qq, r\}$,
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   215
then $A \,@\, B$ is the language
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
\{abzzz, abqq, abr, aczzz, acqq, acr\}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
\] 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
\noindent Recall the properties for string concatenation. For
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
language concatenation we have the following properties
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
\begin{center}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
\begin{tabular}{ll}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
associativity: & $(A @ B) @ C = A @ (B @ C)$\\
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
unit element:  & $A \,@\, \{[]\} = \{[]\} \,@\, A = A$\\
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
zero element:  & $A \,@\, \varnothing = \varnothing \,@\, A = 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
\varnothing$
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
\end{tabular}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
\end{center}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   233
\noindent Note the difference in the last two lines: the empty
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   234
set behaves like $0$ for multiplication and the set $\{[]\}$
242
35104ee14f87 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   235
like $1$ for multiplication ($n * 1 = n$ and $n * 0 = 0$).
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
Following the language concatenation, we can define a
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
\defn{language power} operation as follows:
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
\begin{eqnarray*}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
A^0     & \dn & \{[]\}\\
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
A^{n+1} & \dn & A \,@\, A^n
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
\end{eqnarray*}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   245
\noindent This definition is by recursion on natural numbers.
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
Note carefully that the zero-case is not defined as the empty
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
set, but the set containing the empty string. So no matter
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
what the set $A$ is, $A^0$ will always be $\{[]\}$. (There is
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
another hint about a connection between the $@$-operation and
242
35104ee14f87 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   250
multiplication: How is $x^n$ defined recursively and what is
35104ee14f87 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   251
$x^0$?)
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
242
35104ee14f87 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   253
Next we can define the \defn{star operation} for languages:
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
$A^*$ is the union of all powers of $A$, or short
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   256
\begin{equation}\label{star}
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
A^* \dn \bigcup_{0\le n}\; A^n
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   258
\end{equation}
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   260
\noindent This star operation is often also called
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   261
\emph{Kleene-star}. Unfolding the definition in \eqref{star}
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   262
gives
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
A^0 \cup A^1 \cup A^2 \cup A^3 \cup \ldots
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
\noindent
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
which is equal to 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
\[
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
\{[]\} \,\cup\, A \,\cup\, A @ A \,\cup\, A @ A @ A \,\cup\, \ldots
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   275
\noindent We can see that the empty string is always in $A^*$,
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
no matter what $A$ is. This is because $[] \in A^0$. To make
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   277
sure you understand these definitions, I leave you to answer
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
what $\{[]\}^*$ and $\varnothing^*$ are. 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
Recall that an alphabet is often referred to by the letter
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
$\Sigma$. We can now write for the set of all strings over
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
this alphabet $\Sigma^*$. In doing so we also include the 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
empty string as a possible string over $\Sigma$. So if
241
10f02605a46a polished
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   284
$\Sigma = \{a, b\}$, then $\Sigma^*$ is
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
\[
246
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   287
\{[], a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, \ldots\}
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
\]
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
246
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   290
\noindent or in other words all strings containing $a$s and
baf41b05210f updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
   291
$b$s only, plus the empty string.
239
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
\end{document}
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
%%% Local Variables: 
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
%%% mode: latex
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
%%% TeX-master: t
68d98140b90b added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
%%% End: