diff --git a/info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb b/info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb index 02e621953c89fab1646af6a4685d82831242d8bc..dfb3ac3027ae06856d0905a4f67ef3110d578c4e 100644 --- a/info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb +++ b/info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb @@ -4,7 +4,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Der Satz von Myhill und Nerode" + "# Der Satz von Myhill und Nerode\n", + "Wir betrachten die Myhill-Nerode-Äquivalenzrelation anhand der Sprache L = {a, b, aa, bb, aac, bbc, ccc}." ] }, { @@ -117,6 +118,38 @@ ":init" ] }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/markdown": [ + "$8$" + ], + "text/plain": [ + "8" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "index" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Da der $Index(L)=8<\\infty$ ist die gegebene Sprache regulär." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -128,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -144,7 +177,7 @@ "Delta(c)" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -155,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -164,7 +197,7 @@ "Executed operation: Delta(a)" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -175,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -184,7 +217,7 @@ "Executed operation: Delta(a)" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -195,7 +228,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -218,7 +251,7 @@ "<Animation function visualisation>" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -227,21 +260,108 @@ ":show" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Ein weiteres Beispiel ist die Sprache L={a^n | n>=0}.\n" + ] + }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Loaded machine: EquivalenceRelation2" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "MACHINE EquivalenceRelation2\n", + "SETS\n", + " Alphabet = {a,b,c}\n", + "CONSTANTS L, RL, maxsize, All, Classes, index\n", + "DEFINITIONS\n", + " class(x) == {y | x↦y : RL} ;\n", + " \n", + "PROPERTIES\n", + " L ⊆ seq(Alphabet) ∧\n", + " \n", + " // All = {z | z∈seq(Alphabet) ∧ size(z)≤maxsize} & /* Beschränkt auf endliche Folgen */\n", + " All = UNION(ii).(ii:0..maxsize| (1..ii) --> Alphabet) ∧\n", + "\n", + " RL = ({x,y| x∈All ∧ y∈All ∧ ∀z.(z∈All ⇒ ( x^z ∈ L ⇔ y^z ∈ L))}) ∧\n", + "\n", + " /*L = {x | x=a^n ∧ size(x)≤maxsize} Beschränkt auf endliche Folgen*/ \n", + " L = UNION(ii).(ii:0..maxsize| (1..ii) --> {a}) ∧ maxsize = 3 ∧\n", + "\n", + " Classes = ran( %x.(x∈All|class(x))) ∧ /* Menge der Äquivalenzklassen {class(x)|x∈All} */\n", + " index = card( Classes )\n", + "END" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Machine constants set up using operation 0: $setup_constants()" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + ":constants" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Machine initialised using operation 1: $initialise_machine()" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + ":init" + ] + }, + { + "cell_type": "code", + "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ - "$8$" + "$5$" ], "text/plain": [ - "8" + "5" ] }, - "execution_count": 8, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -254,15 +374,75 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Da der $Index(L)=8<\\infty$ ist die gegebene Sprache regulär." + "Auch diese Sprache ist offensichtlich regulär.\n", + "Hier könnte man davon ausgehen, dass dies aus der Beschränkung auf endliche Folgen folgt.\n", + "Denn je länger man die zugelassenen Folgen macht, desdo mehr Äquivalenzklassen gibt es.\n", + "Es gibt eine Äquivalenzklasse für jedes $a^m$ mit $0≤m≤n$ und eine für Wörter, die nicht in der Sprache liegen, also insgesamt $n+2$." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\renewcommand{\\emptyset}{\\mathord\\varnothing}\\{\\emptyset,\\{(1\\mapsto \\mathit{a})\\},\\{(1\\mapsto \\mathit{a}),(2\\mapsto \\mathit{a})\\},\\{(1\\mapsto \\mathit{a}),(2\\mapsto \\mathit{a}),(3\\mapsto \\mathit{a})\\}\\}$" + ], + "text/plain": [ + "{∅,{(1↦a)},{(1↦a),(2↦a)},{(1↦a),(2↦a),(3↦a)}}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "L" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$\n", + "\n", + "**Solution:**\n", + "* $\\mathit{x} = \\{(1\\mapsto \\mathit{a})\\}$\n", + "* $\\mathit{y} = \\{(1\\mapsto \\mathit{a}),(2\\mapsto \\mathit{a})\\}$\n", + "* $\\mathit{z} = \\{(1\\mapsto \\mathit{a}),(2\\mapsto \\mathit{a})\\}$" + ], + "text/plain": [ + "TRUE\n", + "\n", + "Solution:\n", + "\tx = {(1↦a)}\n", + "\ty = {(1↦a),(2↦a)}\n", + "\tz = {(1↦a),(2↦a)}" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x=[a] ∧ y=[a, a] ∧ ∃z.(z∈All ∧ not(x^z ∈ L ⇔ y^z ∈ L)) /*Gegenbeispiel für [a] ↦ [a,a] ∈ R_L*/" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Betrachtet man allerdings den unendlichen Fall, so fallen die Wörter $a^m$ alle in eine Klasse.\n", + "Dies gilt, da es kein \"Ende\" der Folgen mehr gibt und somit kein Gegenbeispiel wie oben." + ] } ], "metadata": {