From 5b8e374f712423fabf39c3bdbc63e0104688887c Mon Sep 17 00:00:00 2001 From: Michael Leuschel <leuschel@uni-duesseldorf.de> Date: Thu, 16 Apr 2020 18:32:25 +0200 Subject: [PATCH] add first material about set theory --- info4/kapitel-0/Logik.ipynb | 2 +- info4/kapitel-0/Mengentheorie.ipynb | 587 ++++++++++++++++++++++++++++ 2 files changed, 588 insertions(+), 1 deletion(-) diff --git a/info4/kapitel-0/Logik.ipynb b/info4/kapitel-0/Logik.ipynb index 7e97521..2984425 100644 --- a/info4/kapitel-0/Logik.ipynb +++ b/info4/kapitel-0/Logik.ipynb @@ -639,7 +639,7 @@ "\n", "Die Bedeutung dieser Junktoren kann man in folgender Wahrheitstabelle zusammenfassen:\n", "\n", - "\n", + "<img src=\"./img/wahrheitstabelle.png\" width=\"600\">\n", "\n", "Wie berechnet man damit den Wahrheitswert einer Formel wie $(p \\vee (\\neg p \\wedge q)$?\n", "\n", diff --git a/info4/kapitel-0/Mengentheorie.ipynb b/info4/kapitel-0/Mengentheorie.ipynb index 96025b7..9676745 100644 --- a/info4/kapitel-0/Mengentheorie.ipynb +++ b/info4/kapitel-0/Mengentheorie.ipynb @@ -12,6 +12,593 @@ "\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Mengen\n", + " \n", + "\n", + "Fundamentale Idee der Mengentheorie: \n", + "* _\"The ability to regard any collection of objects as a single entity (i.e., as a set).\"_ (Keith Devlin. Joy of Sets.)\n", + "\n", + "In der Regel gibt es eine Domäne an \"Objekten\" aus denen man Mengen bauen kann.\n", + "Was genau diese Objekte sind interessiert uns in der Mengentheorie nicht.\n", + "\n", + "Fundamental sind diese beiden Symbole:\n", + "* wenn $a$ ein Objekt ist und $x$ eine Menge, dann \n", + " * ist $a \\in x$ wahr, wenn $a$ ein Element von $x$ ist\n", + " * ist $a \\not\\in x$ wahr, wenn $a$ **kein** Element von $x$ ist.\n", + "\n", + "\n", + "$\\in$ und $\\not\\in$ sind Prädikate, verbunden durch die Eigenschaft:\n", + "* $\\forall(a,x).(a\\not\\in x \\Leftrightarrow \\neg(a \\in x))$\n", + "\n", + "\n", + "Eine besondere Menge ist die leere Menge $\\emptyset$.\n", + "Sie hat keine Elemente:\n", + " * $z = \\emptyset \\Leftrightarrow \\forall(a).(a\\not\\in z)$\n", + "\n", + "Zwei Mengen $x$ und $y$ sind gleich gdw wenn sie die gleichen Elemente haben:\n", + " * $\\forall(x,y).(x=y \\Leftrightarrow \\forall(a).(a\\in x \\Leftrightarrow a \\in y))$" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{FALSE}$" + ], + "text/plain": [ + "FALSE" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "∅ = {1}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{FALSE}$" + ], + "text/plain": [ + "FALSE" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{1} = {1,2}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$" + ], + "text/plain": [ + "TRUE" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{1,2} = {1,2}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Notationen für Mengen: endliche Enumeration\n", + " \n", + "* explizite Auflistung aller Elemente $\\{a_1,\\ldots,a_n\\}$\n", + "* die Reihenfolge spielt keine Rolle:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$" + ], + "text/plain": [ + "TRUE" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{2,5,3} = {2,3,5}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Dies ist im Unterschied zu Tupeln und Listen, die oft mit runden und eckigen Klammern geschriben werden:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{FALSE}$" + ], + "text/plain": [ + "FALSE" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2,5,3) = (2,3,5)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$" + ], + "text/plain": [ + "TRUE" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[2,5,3] = [2,5,3]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Elemente können in der Enumeration mehrfach auftauchen:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$" + ], + "text/plain": [ + "TRUE" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{2,5,3,2,5} = {2,3,5}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Vereinigung, Schnitt, Differenz\n", + "\n", + "Drei wichtige Operationen auf Mengen sind wie folgt.\n", + "\n", + "Vereinigung von Mengen $\\cup$ :\n", + " * $z = x\\cup y \\Leftrightarrow \\forall(a).(a\\in z \\Leftrightarrow (a\\in x \\vee a \\in y))$\n", + "\n", + "Schnitt von Mengen $\\cap$:\n", + "* $z = x\\cap y \\Leftrightarrow \\forall(a).(a\\in z \\Leftrightarrow (a\\in x \\wedge a \\in y))$\n", + "\n", + "Differenz von Mengen $\\setminus$:\n", + "* $z = x \\setminus y \\Leftrightarrow \\forall(a).(a\\in z \\Leftrightarrow (a\\in x \\wedge a \\not\\in y))$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{2,3,5,7\\}$" + ], + "text/plain": [ + "{2,3,5,7}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{2,3,5} ∪ {5,7}" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{5\\}$" + ], + "text/plain": [ + "{5}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{2,3,5}∩{5,7}" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{2,3\\}$" + ], + "text/plain": [ + "{2,3}" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{2,3,5}−{5,7}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Notationen für Mengen: per Prädikat\n", + " \n", + "Definition der Elemente durch ein Prädikat $\\{a \\mid P(a)\\}$:\n", + "* $z = \\{a \\mid P(a)\\} \\Leftrightarrow \\forall(a).(a\\in z \\equiv P(a))$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{2,3,5\\}$" + ], + "text/plain": [ + "{2,3,5}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{a | a>1 & a<6 & a≠4}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Man kann damit auch unendliche Mengen darstellen:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{\\mathit{a}\\mid \\mathit{a} > 10\\}$" + ], + "text/plain": [ + "{a∣a > 10}" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{a | a>10}" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{2\\}$" + ], + "text/plain": [ + "{2}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{a | a mod 2 = 0} ∩ {2,3,5}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Man kann damit auch die drei Mengenoperationen definieren:\n", + "\n", + "* $x \\cup y = \\{a \\mid a\\in x \\vee a\\in y\\}$\n", + "* $x \\cap y = \\{a \\mid a\\in x \\wedge a\\in y\\}$\n", + "* $x \\setminus y = \\{a \\mid a\\in x \\wedge a\\not\\in y\\}$" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$\n", + "\n", + "**Solution:**\n", + "* $\\mathit{xy} = \\{2,3,5\\}$\n", + "* $\\mathit{x} = \\{2,3\\}$\n", + "* $\\mathit{y} = \\{2,5\\}$" + ], + "text/plain": [ + "TRUE\n", + "\n", + "Solution:\n", + "\txy = {2,3,5}\n", + "\tx = {2,3}\n", + "\ty = {2,5}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = {2,3} & y = {2,5} & xy = {a| a∈x ∨ a∈y}" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$\n", + "\n", + "**Solution:**\n", + "* $\\mathit{xy} = \\{2\\}$\n", + "* $\\mathit{x} = \\{2,3\\}$\n", + "* $\\mathit{y} = \\{2,5\\}$" + ], + "text/plain": [ + "TRUE\n", + "\n", + "Solution:\n", + "\txy = {2}\n", + "\tx = {2,3}\n", + "\ty = {2,5}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = {2,3} & y = {2,5} & xy = {a| a∈x ∧ a∈y}" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$\n", + "\n", + "**Solution:**\n", + "* $\\mathit{xy} = \\{3\\}$\n", + "* $\\mathit{x} = \\{2,3\\}$\n", + "* $\\mathit{y} = \\{2,5\\}$" + ], + "text/plain": [ + "TRUE\n", + "\n", + "Solution:\n", + "\txy = {3}\n", + "\tx = {2,3}\n", + "\ty = {2,5}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = {2,3} & y = {2,5} & xy = {a| a∈x ∧ a∉y}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Als Kürzel führen wir auch die Notation $a..b$ für $\\{x \\mid x \\geq a \\wedge x \\leq b\\}$ ein." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{1,2,3,4,5,6,7,8,9,10\\}$" + ], + "text/plain": [ + "{1,2,3,4,5,6,7,8,9,10}" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1..10" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Ein Theorem\n", + "\n", + "Für alle Mengen $x$, $y$, $z$ gilt:\n", + "* $x \\cup (y \\cap z) = (x\\cup y) \\cap (x\\cup z)$\n", + "\n", + "<img src=\"./img/Venn.pdf\" width=\"300\">" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{2,3,44,55\\}$" + ], + "text/plain": [ + "{2,3,44,55}" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{2,3,55}∪({2,44,77}∩{2,44,66})" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\{2,3,44,55\\}$" + ], + "text/plain": [ + "{2,3,44,55}" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "({2,3,55}∪{2,44,77})∩({2,3,55}∪{2,44,66})" + ] + }, { "cell_type": "code", "execution_count": null, -- GitLab