author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sat, 06 Sep 2014 15:28:59 +0100 | |
changeset 239 | 68d98140b90b |
child 241 | 10f02605a46a |
permissions | -rw-r--r-- |
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 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
\subsubsection*{Characters and Strings} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
In this module we will often use \defn{characters}. While they |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
are surely familiar, we will make one subtle distinction. If |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
we want to refer to concrete characters, like \code{a}, |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
\code{b} and so on, we use a typewriter font. So if we want to |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
refer to the concrete characters of my email address we shall |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
write |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
\begin{center} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
\pcode{christian.urban@kcl.ac.uk} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
\end{center} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
\noindent If we need to explicitly indicate the ``space'' |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
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
|
26 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
\begin{center} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
\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
|
29 |
\end{center} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
\noindent But often we do not care |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
about which characters we use. In such cases we us the italic |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
font and write $a$, $b$ and so on. So if we need a |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
representative string, we might write |
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 |
\begin{equation}\label{abracadabra} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
abracadabra |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
\end{equation} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
\noindent We do not really care what the characters stand for, |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
except we do care about is that for example the character $a$ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
is not equal to $b$. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
An \defn{alphabet} is a finite set of characters. Often the |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
letter $\Sigma$ is used to refer to an alphabet. For example |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
the ASCII characters \pcode{a} to \pcode{z} form an alphabet. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
The digits $0$ to $9$ are another alphabet. If nothing else is |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
specified, we usually assume the alphabet consists of just the |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
lower-case letters $a$, $b$, \ldots, $z$. Sometimes, however, |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
we explicitly restrict strings to contain, for example, only |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
the letters $a$ and $b$. In this case we say the alphabet is |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
the set $\{a, b\}$. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
\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
|
56 |
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
|
57 |
languages, they are usually written as \dq{$hello$} where the |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
double quotes indicate that we dealing with a string. But |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
since, strings are lists of characters we could also write |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
this string as |
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 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
[\text{\it h, e, l, l, o}] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
\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
|
67 |
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
|
68 |
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
|
69 |
say \dq{\textit{ello}} when making definitions about strings. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
There are some subtleties with the empty string, sometimes |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
written as \dq{} but also as the empty list of characters |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
$[\,]$. Two strings, for example $s_1$ and $s_2$, can be |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
\emph{concatenated}, which we write as $s_1 @ s_2$. Suppose we |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
are given two strings \dq{\textit{foo}} and \dq{\textit{bar}}, |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
then their concatenation, writen |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
\dq{\textit{foo}} $@$ \dq{\textit{bar}}, gives |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
\dq{\textit{foobar}}. Often we will simplify our life and just |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
drop the double quotes whenever it is clear we are talking |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
about strings, writing as already in \eqref{abracadabra} just |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
\textit{foo}, \textit{bar}, \textit{foobar} or \textit{foo $@$ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
bar}. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
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
|
84 |
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
|
85 |
meaning |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
86 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
\[(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
|
88 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
\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
|
90 |
like a unit element, therefore |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
\[s \,@\, [] = [] \,@\, s = s\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
While for us strings are just lists of characters, programming |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
languages often differentiate between the two concepts. In |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
Scala, for example, there is the type of \code{String} and the |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
type of lists of characters, \code{List[Char]}. They are not |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
the same and we need to explicitly coerce elements between the |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
two types, for example |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
100 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
\begin{lstlisting}[numbers=none] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
scala> "abc".toList |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
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
|
104 |
\end{lstlisting} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
107 |
\subsubsection*{Sets and Languages} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
We will use the familiar operations $\cup$ and $\cap$ for |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
sets. For the empty set we will either write $\varnothing$ or |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
$\{\,\}$. The set containing, for example, the natural numbers |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
$1$, $2$ and $3$ we will write as |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
\{1, 2, 3\} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
\noindent The notation $\in$ means \emph{element of}, so $1 |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
\in \{1, 2, 3\}$ is true and $3 \in \{1, 2, 3\}$ is false. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
is infinite. This set is often also abbreviated as |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
$\mathbb{N}$. We can define sets by giving all elements, like |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
$\{0, 1\}$, but also by \defn{set comprehensions}. For example |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
the set of all even natural numbers can be defined as |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
\{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
|
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 |
\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
|
132 |
defined by the following set comprehension |
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 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
\{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
|
136 |
\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
138 |
\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
|
139 |
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
|
140 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
141 |
\begin{eqnarray*} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
\end{eqnarray*} |
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 For defining sets, we will also often use the notion |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
of the ``big union''. An example is as follows: |
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 |
\begin{equation}\label{bigunion} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
\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
|
152 |
\end{equation} |
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 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
|
155 |
successors, so |
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 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
158 |
\{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
|
159 |
\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
\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
|
162 |
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
|
163 |
\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
|
164 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
165 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
\{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
|
167 |
\ldots |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
168 |
\] |
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 |
\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
|
171 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
172 |
An important notion in this module are \defn{Languages}, which |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
173 |
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
|
174 |
(formally) specify languages and to find out whether a string |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
is in a language or not. Note that the language containing the |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
176 |
empty string $\{\dq{}\}$ is not equal to the empty language |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
(or empty set): The former contains one element, namely \dq{} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
(also written $[\,]$), but the latter does not contain any. |
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 |
For languages we define the operation of \defn{language |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
182 |
concatenation}, written $A @ B$: |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
183 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
184 |
\begin{equation}\label{langconc} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
185 |
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
|
186 |
\end{equation} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
187 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
188 |
\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
|
189 |
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
|
190 |
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
|
191 |
As an example suppose $A=\{ab, ac\}$ and $B=\{zzz, qq, r\}$, |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
192 |
then $A \,@\, B$ is |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
193 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
194 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
195 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
\{abzzz, abqq, abr, aczzz, acqq, acr\} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
198 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
\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
|
200 |
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
|
201 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
202 |
\begin{center} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
\begin{tabular}{ll} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
204 |
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
|
205 |
unit element: & $A \,@\, \{[]\} = \{[]\} \,@\, A = A$\\ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
206 |
zero element: & $A \,@\, \varnothing = \varnothing \,@\, A = |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
207 |
\varnothing$ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
\end{tabular} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
209 |
\end{center} |
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 Note the difference: the empty set behaves like $0$ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
212 |
for multiplication and the set $\{[]\}$ like $1$ for |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
213 |
multiplication. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
214 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
215 |
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
|
216 |
\defn{language power} operation as follows: |
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 |
\begin{eqnarray*} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
A^0 & \dn & \{[]\}\\ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
220 |
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
|
221 |
\end{eqnarray*} |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
223 |
\noindent This definition is by induction on natural numbers. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
another hint about a connection between the $@$-operation and |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
228 |
multiplication: How is $x^n$ defined and what is $x^0$?) |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
229 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
230 |
Next we can define the \defn{star operation} for languages: |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
$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
|
232 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
233 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
234 |
A^* \dn \bigcup_{0\le n}\; A^n |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
235 |
\] |
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 |
\noindent |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
238 |
Unfolding this definition |
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 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
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
|
242 |
\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
243 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
\noindent |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
245 |
which is equal to |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
246 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
247 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
248 |
\{[]\} \,\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
|
249 |
\] |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
250 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
251 |
\noindent we can see that the empty string is always in $A^*$, |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
252 |
no matter what $A$ is. This is because $[] \in A^0$. To make |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
253 |
sure you understand these definition, I leave you to answer |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
what $\{[]\}^*$ and $\varnothing^*$ are. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
256 |
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
|
257 |
$\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
|
258 |
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
|
259 |
empty string as a possible string over $\Sigma$. So if |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
260 |
$\Sigma = \{a, b\}$ then $\Sigma^*$ is |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
261 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
262 |
\[ |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
263 |
\{[], a, b, ab, ba, aaa, aab, aba, abb, baa, bab, \ldots\} |
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 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
266 |
\noindent or in other words all strings containing $a$s and |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
267 |
$b$s only. |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
268 |
|
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
269 |
\end{document} |
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 |
%%% Local Variables: |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
272 |
%%% mode: latex |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
273 |
%%% TeX-master: t |
68d98140b90b
added notation handout
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
274 |
%%% End: |