Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prob-teaching-notebooks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
prob-teaching-notebooks
Commits
cf0e32dc
Commit
cf0e32dc
authored
4 years ago
by
Chris
Browse files
Options
Downloads
Patches
Plain Diff
Erweiterung des Notebooks um ein zweites Beispiel
parent
361420e9
No related branches found
No related tags found
1 merge request
!1
Master
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb
+197
-17
197 additions, 17 deletions
info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb
with
197 additions
and
17 deletions
info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb
+
197
−
17
View file @
cf0e32dc
...
...
@@ -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":
null
,
"execution_count":
13
,
"metadata": {},
"outputs": [],
"source": []
"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": 14,
"metadata": {},
"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": {
...
...
%% Cell type:markdown id: tags:
# Der Satz von Myhill und Nerode
Wir betrachten die Myhill-Nerode-Äquivalenzrelation anhand der Sprache L = {a, b, aa, bb, aac, bbc, ccc}.
%% Cell type:code id: tags:
```
prob
MACHINE EquivalenceRelation
/* Ein Modell der Myhill-Nerode Äquivalenzrelation R_L,
der entsprechenden Äquivalenzklassen und dem Index der Sprache.*/
SETS
Alphabet = {a,b,c}
CONSTANTS L, RL, maxsize, All, Classes, index
DEFINITIONS
class(x) == {y | x↦y : RL} ;
ANIMATION_FUNCTION1 == {r,c,i |r=1 ∧ c∈ dom(word) ∧ i=word(c)};
ANIMATION_FUNCTION2 == {r,c,i |r=2 ∧ c=1 ∧ i=z};
ANIMATION_FUNCTION3 == {(1, 0, "Wort:"), (2, 0, "Äquivalenzklasse:")};
PROPERTIES
L ⊆ seq(Alphabet) ∧
// All = {z | z∈seq(Alphabet) ∧ size(z)<=maxsz} & /* beschränkt auf endliche Folgen */
All = UNION(ii).(ii:0..maxsize| (1..ii) --> Alphabet) ∧
RL = ({x,y| x∈All ∧ y∈All ∧ ∀z.(z∈All ⇒ ( x^z ∈ L ⇔ y^z ∈ L))}) ∧
L = {[a],[b],[a,a],[b,b],[a,a,c],[b,b,c],[c,c,c]} ∧ maxsize = 3 ∧
Classes = ran( %x.(x∈All|class(x))) ∧ /* Menge der Äquivalenzklassen {class(x)|x∈All} */
index = card( Classes )
ASSERTIONS
/* Test ob wir eine Äquivalenzrelation haben: */
∀x.(x∈All ⇒ x↦x ∈ RL); /* Reflexivität */
∀(x,y).(x↦y ∈ RL ⇒ y↦x ∈ RL); /* Symetrie */
∀(x,y,z).(x↦y ∈ RL ∧ y↦z ∈ RL ⇒ x↦z ∈ RL); /* Transitivität */
/* Einige Beispiele : */
[a,a] ↦ [b,b] ∈ RL;
[a,a] ↦ [c,c] ∉ RL;
[b,b,c] ↦ [c,c,c] ∈ RL;
class([a,a]) = {[a,a],[b,b]};
class([c,c,c]) = {[a,a,c],[b,b,c],[c,c,c]}
/* Der durch die Äquivalenzklassen induzierte DFA: */
VARIABLES z, word
INVARIANT z ⊆ All ∧ word ∈ seq(Alphabet)
INITIALISATION z := class([]); word := []
OPERATIONS
Delta(terminal) = PRE terminal∈Alphabet THEN
ANY x WHERE x∈z ∧ ∀x2.(x2∈z ⇒ size(x2)≥size(x)) THEN
z := class(x^[terminal]);
word := word^[terminal]
END
END;
Final = SELECT z ∩ L ≠ {} THEN skip END
END
```
%% Output
Loaded machine: EquivalenceRelation
%% Cell type:code id: tags:
```
prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
```
prob
:init
```
%% Output
Machine initialised using operation 1: $initialise_machine()
%% Cell type:code id: tags:
```
prob
index
```
%% Output
$8$
8
%% Cell type:markdown id: tags:
Da der $Index(L)=8<
\i
nfty$ ist die gegebene Sprache regulär.
%% Cell type:markdown id: tags:
Durch die Äquivalenzklassen wird ein Minimalautomat induziert.
Die Menge der Zustände ist gleich der Menge der Äquivalenzklassen.
Und nach dem Einlesen eines Wortes $w∈Σ^
*
$ landet man in dem Zustand, der der Äquivalenzklasse von $w$ bezüglich $R_L$ entspricht.
%% Cell type:code id: tags:
```
prob
:browse
```
%% Output
Machine: EquivalenceRelation
Sets: Alphabet
Constants: L, RL, maxsize, All, Classes, index
Variables: z, word
Operations:
Delta(a)
Delta(b)
Delta(c)
%% Cell type:code id: tags:
```
prob
:exec Delta terminal=a
```
%% Output
Executed operation: Delta(a)
%% Cell type:code id: tags:
```
prob
:exec Delta terminal=a
```
%% Output
Executed operation: Delta(a)
%% Cell type:code id: tags:
```
prob
:show
```
%% Output
<table style="font-family:monospace"><tbody>
<tr>
<td style="padding:10px">Wort:</td>
<td style="padding:10px">a</td>
<td style="padding:10px">a</td>
</tr>
<tr>
<td style="padding:10px">Äquivalenzklasse:</td>
<td style="padding:10px">{{(1|->a),(2|->a)},{(1|->b),(2|->b)}}</td>
<td style="padding:0px"></td>
</tr>
</tbody></table>
<Animation function visualisation>
%% Cell type:markdown id: tags:
Ein weiteres Beispiel ist die Sprache L={a^n | n>=0}.
%% Cell type:code id: tags:
```
prob
MACHINE EquivalenceRelation2
SETS
Alphabet = {a,b,c}
CONSTANTS L, RL, maxsize, All, Classes, index
DEFINITIONS
class(x) == {y | x↦y : RL} ;
PROPERTIES
L ⊆ seq(Alphabet) ∧
// All = {z | z∈seq(Alphabet) ∧ size(z)≤maxsize} & /* Beschränkt auf endliche Folgen */
All = UNION(ii).(ii:0..maxsize| (1..ii) --> Alphabet) ∧
RL = ({x,y| x∈All ∧ y∈All ∧ ∀z.(z∈All ⇒ ( x^z ∈ L ⇔ y^z ∈ L))}) ∧
/*L = {x | x=a^n ∧ size(x)≤maxsize} Beschränkt auf endliche Folgen*/
L = UNION(ii).(ii:0..maxsize| (1..ii) --> {a}) ∧ maxsize = 3 ∧
Classes = ran( %x.(x∈All|class(x))) ∧ /* Menge der Äquivalenzklassen {class(x)|x∈All} */
index = card( Classes )
END
```
%% Output
Loaded machine: EquivalenceRelation2
%% Cell type:code id: tags:
```
prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
```
prob
:init
```
%% Output
Machine initialised using operation 1: $initialise_machine()
%% Cell type:code id: tags:
```
prob
index
```
%% Output
$
8
$
8
$
5
$
5
%% Cell type:markdown id: tags:
Da der $Index(L)=8<
\i
nfty$ ist die gegebene Sprache regulär.
Auch diese Sprache ist offensichtlich regulär.
Hier könnte man davon ausgehen, dass dies aus der Beschränkung auf endliche Folgen folgt.
Denn je länger man die zugelassenen Folgen macht, desdo mehr Äquivalenzklassen gibt es.
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 id: tags:
```
prob
L
```
%% Output
$\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})\}\}$
{∅,{(1↦a)},{(1↦a),(2↦a)},{(1↦a),(2↦a),(3↦a)}}
%% Cell type:code id: tags:
```
prob
x=[a] ∧ y=[a, a] ∧ ∃z.(z∈All ∧ not(x^z ∈ L ⇔ y^z ∈ L)) /*Gegenbeispiel für [a] ↦ [a,a] ∈ R_L*/
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{x} = \{(1\mapsto \mathit{a})\}$
* $\mathit{y} = \{(1\mapsto \mathit{a}),(2\mapsto \mathit{a})\}$
* $\mathit{z} = \{(1\mapsto \mathit{a}),(2\mapsto \mathit{a})\}$
TRUE
Solution:
x = {(1↦a)}
y = {(1↦a),(2↦a)}
z = {(1↦a),(2↦a)}
%% Cell type:markdown id: tags:
Betrachtet man allerdings den unendlichen Fall, so fallen die Wörter $a^m$ alle in eine Klasse.
Dies gilt, da es kein "Ende" der Folgen mehr gibt und somit kein Gegenbeispiel wie oben.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment