87 \end{lstlisting} |
87 \end{lstlisting} |
88 |
88 |
89 \noindent |
89 \noindent |
90 However, we do not want to do this kind of explicit coercion in our |
90 However, we do not want to do this kind of explicit coercion in our |
91 pencil-and-paper, everyday arguments. So in our (mathematical) |
91 pencil-and-paper, everyday arguments. So in our (mathematical) |
92 definitions we regard strings as lists of characters, we will also |
92 definitions we regard strings as lists of characters and we will also |
93 write \dq{$hello$} as |
93 write \dq{$hello$} as list |
94 |
94 |
95 \[ |
95 \[ |
96 [\text{\it h, e, l, l, o}] \qquad\text{or simply}\qquad \textit{hello} |
96 [\text{\it h, e, l, l, o}] \qquad\text{or simply}\qquad \textit{hello} |
97 \] |
97 \] |
98 |
98 |
112 Suppose we are given two strings \dq{\textit{foo}} and |
112 Suppose we are given two strings \dq{\textit{foo}} and |
113 \dq{\textit{bar}}, then their concatenation, written |
113 \dq{\textit{bar}}, then their concatenation, written |
114 \dq{\textit{foo}} $@$ \dq{\textit{bar}}, gives |
114 \dq{\textit{foo}} $@$ \dq{\textit{bar}}, gives |
115 \dq{\textit{foobar}}. But as said above, we will often |
115 \dq{\textit{foobar}}. But as said above, we will often |
116 simplify our life and just drop the double quotes whenever it |
116 simplify our life and just drop the double quotes whenever it |
117 is clear we are talking about strings, So we will often just |
117 is clear we are talking about strings. So we will often just |
118 write \textit{foo}, \textit{bar}, \textit{foobar} or |
118 write \textit{foo}, \textit{bar}, \textit{foobar} or |
119 \textit{foo $@$ bar}. |
119 \textit{foo $@$ bar}. |
120 |
120 |
121 Occasionally we will use the notation $a^n$ for strings, which stands |
121 Occasionally we will use the notation $a^n$ for strings, which stands |
122 for the string of $n$ repeated $a$s. So $a^{n}b^{n}$ is a string that |
122 for the string of $n$ repeated $a$s. So $a^{n}b^{n}$ is a string that |
151 Also sets can potentially have infinitely many elements, whereas lists |
151 Also sets can potentially have infinitely many elements, whereas lists |
152 cannot. For example |
152 cannot. For example |
153 the set of all natural numbers $\{0, 1, 2, \ldots\}$ is infinite. This |
153 the set of all natural numbers $\{0, 1, 2, \ldots\}$ is infinite. This |
154 set is often also abbreviated as $\mathbb{N}$. Lists can be very large, but they cannot contain infinitely many elements. |
154 set is often also abbreviated as $\mathbb{N}$. Lists can be very large, but they cannot contain infinitely many elements. |
155 |
155 |
156 We can define sets by giving all elements, for example $\{0, 1\}$ for |
156 We can define sets by giving all their elements, for example $\{0, 1\}$ for |
157 the set containing just $0$ and $1$, but also by \defn{set |
157 the set containing just $0$ and $1$. But often we need to use \defn{set |
158 comprehensions}. For example the set of all even natural numbers can |
158 comprehensions} to define sets. For example the set of all \emph{even} |
159 be defined as |
159 natural numbers can be defined as |
160 |
160 |
161 \[ |
161 \[ |
162 \{n\;|\;n\in\mathbb{N} \wedge n\;\text{is even}\} |
162 \{n\;|\;n\in\mathbb{N} \wedge n\;\text{is even}\} |
163 \] |
163 \] |
164 |
164 |
165 \noindent Though silly, but the set $\{0, 1, 2\}$ could also be |
165 \noindent Set comprehensions consist of a ``base set'' (in this case |
|
166 all the natural numbers) and a predicate (here eveness). |
|
167 |
|
168 Though silly, but the set $\{0, 1, 2\}$ could also be |
166 defined by the following set comprehension |
169 defined by the following set comprehension |
167 |
170 |
168 \[ |
171 \[ |
169 \{n\;|\; n^2 < 9 \wedge n \in \mathbb{N}\} |
172 \{n\;|\; n \in \mathbb{N} \wedge n^2 < 9\} |
170 \] |
173 \] |
171 |
174 |
172 \noindent Can you see why this defines the set $\{0, 1, 2\}$? Notice |
175 \noindent Can you see why this defines the set $\{0, 1, 2\}$? Notice |
173 that set comprehensions could be used to define set union, |
176 that set comprehensions are quite powerful constructions. For example they |
174 intersection and difference: |
177 could be used to define set union, |
|
178 set intersection and set difference: |
175 |
179 |
176 \begin{eqnarray*} |
180 \begin{eqnarray*} |
177 A \cup B & \dn & \{x\;|\; x \in A \vee x \in B\}\\ |
181 A \cup B & \dn & \{x\;|\; x \in A \vee x \in B\}\\ |
178 A \cap B & \dn & \{x\;|\; x \in A \wedge x \in B\}\\ |
182 A \cap B & \dn & \{x\;|\; x \in A \wedge x \in B\}\\ |
179 A \backslash B & \dn & \{x\;|\; x \in A \wedge x \not\in B\} |
183 A \backslash B & \dn & \{x\;|\; x \in A \wedge x \not\in B\} |
206 \ldots |
210 \ldots |
207 \] |
211 \] |
208 |
212 |
209 \noindent but using the big union notation is more concise. |
213 \noindent but using the big union notation is more concise. |
210 |
214 |
211 As an aside: While this stuff about sets might all look trivial or even needlessly |
215 As an aside: While this stuff about sets might all look trivial or |
212 pedantic, \emph{Nature} is never simple. If you want to be amazed how |
216 even needlessly pedantic, \emph{Nature} is never simple. If you want |
213 complicated sets can get, watch out for the last lecture just before |
217 to be amazed how complicated sets can get, watch out for the last |
214 Christmas where I want to convince you of the fact that some sets are |
218 lecture just before Christmas where I want to convince you of the fact |
215 more infinite than others. Yes, you read correctly, there can be sets |
219 that some sets are more infinite than other sets. Yes, you read |
216 that are ``more infinite'' then others. If you think this is obvious: |
220 correctly, there can be sets that are ``more infinite'' than |
217 say you have the infinite set $\mathbb{N}\backslash\{0\} = \{1, 2, 3, 4, \ldots\}$ which is all |
221 others. If you think this is obvious: say you have the infinite set |
218 the natural numbers except $0$, and then compare it to the set |
222 $\mathbb{N}\backslash\{0\} = \{1, 2, 3, 4, \ldots\}$ which is all the |
219 $\{0, 1, 2, 3, 4, \ldots\}$ which contains the $0$. If you think, |
223 natural numbers except $0$, and then compare it to the set |
220 the second must be more infinite\ldots{} well, then think again. Because the two |
224 $\{0, 1, 2, 3, 4, \ldots\}$ which contains the $0$ and all other |
221 infinite sets |
225 numbers. If you think, the second must be more infinite\ldots{} well, |
|
226 then think again. Because the two infinite sets |
222 |
227 |
223 \begin{center} |
228 \begin{center} |
224 $\{1, 2, 3, 4, \ldots\}$ and |
229 $\{1, 2, 3, 4, \ldots\}$ and |
225 $\{0, 1, 2, 3, 4, \ldots\}$ |
230 $\{0, 1, 2, 3, 4, \ldots\}$ |
226 \end{center} |
231 \end{center} |
227 |
232 |
228 \noindent |
233 \noindent |
229 contain actually the same number of elements. Does this make sense? |
234 contain actually the same amount of elements. Does this make sense? |
230 Though this might all look strange this about infinite sets will be a |
235 Though this might all look strange, infinite sets will be a |
231 topic that is very relevant to the material of this module. It tells |
236 topic that is very relevant to the material of this module. It tells |
232 us what we can compute with a computer (actually algorithm) and what |
237 us what we can compute with a computer (actually algorithm) and what |
233 we cannot. But during the first 9 lectures we can go by without this |
238 we cannot. But during the first 9 lectures we can go by without this |
234 ``weird'' stuff. |
239 ``weird'' stuff. End of aside.\smallskip |
235 |
240 |
236 Another important notion in this module are \defn{languages}, which |
241 Another important notion in this module are \defn{languages}, which |
237 are sets of strings. One of the main goals for us will be how to |
242 are sets of strings. One of the main goals for us will be how to |
238 (formally) specify languages and to find out whether a string |
243 (formally) specify languages and to find out whether a string |
239 is in a language or not.\footnote{You might wish to ponder |
244 is in a language or not.\footnote{You might wish to ponder |