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
361420e9
Commit
361420e9
authored
4 years ago
by
Chris
Browse files
Options
Downloads
Patches
Plain Diff
Neues Notebook zur Myhill-Nerode Äquivalenzrelation
parent
78d3da7f
Branches
Branches containing commit
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
+283
-0
283 additions, 0 deletions
info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb
with
283 additions
and
0 deletions
info4/kapitel-2/Der Satz von Myhill und Nerode.ipynb
0 → 100644
+
283
−
0
View file @
361420e9
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Der Satz von Myhill und Nerode"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Loaded machine: EquivalenceRelation"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"MACHINE EquivalenceRelation\n",
"/* Ein Modell der Myhill-Nerode Äquivalenzrelation R_L,\n",
" der entsprechenden Äquivalenzklassen und dem Index der Sprache.*/\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",
" ANIMATION_FUNCTION1 == {r,c,i |r=1 ∧ c∈ dom(word) ∧ i=word(c)};\n",
" ANIMATION_FUNCTION2 == {r,c,i |r=2 ∧ c=1 ∧ i=z};\n",
" ANIMATION_FUNCTION3 == {(1, 0, \"Wort:\"), (2, 0, \"Äquivalenzklasse:\")};\n",
" \n",
"PROPERTIES\n",
" L ⊆ seq(Alphabet) ∧\n",
" \n",
" // All = {z | z∈seq(Alphabet) ∧ size(z)<=maxsz} & /* 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 = {[a],[b],[a,a],[b,b],[a,a,c],[b,b,c],[c,c,c]} ∧ maxsize = 3 ∧\n",
"\n",
" Classes = ran( %x.(x∈All|class(x))) ∧ /* Menge der Äquivalenzklassen {class(x)|x∈All} */\n",
" index = card( Classes ) \n",
"\n",
"ASSERTIONS\n",
" /* Test ob wir eine Äquivalenzrelation haben: */\n",
" ∀x.(x∈All ⇒ x↦x ∈ RL); /* Reflexivität */\n",
" ∀(x,y).(x↦y ∈ RL ⇒ y↦x ∈ RL); /* Symetrie */\n",
" ∀(x,y,z).(x↦y ∈ RL ∧ y↦z ∈ RL ⇒ x↦z ∈ RL); /* Transitivität */\n",
"\n",
" /* Einige Beispiele : */\n",
" [a,a] ↦ [b,b] ∈ RL;\n",
" [a,a] ↦ [c,c] ∉ RL;\n",
" [b,b,c] ↦ [c,c,c] ∈ RL;\n",
" class([a,a]) = {[a,a],[b,b]};\n",
" class([c,c,c]) = {[a,a,c],[b,b,c],[c,c,c]}\n",
"\n",
"/* Der durch die Äquivalenzklassen induzierte DFA: */\n",
"VARIABLES z, word\n",
"INVARIANT z ⊆ All ∧ word ∈ seq(Alphabet)\n",
"INITIALISATION z := class([]); word := []\n",
"OPERATIONS\n",
" Delta(terminal) = PRE terminal∈Alphabet THEN\n",
" ANY x WHERE x∈z ∧ ∀x2.(x2∈z ⇒ size(x2)≥size(x)) THEN\n",
" z := class(x^[terminal]);\n",
" word := word^[terminal]\n",
" END\n",
" END;\n",
" Final = SELECT z ∩ L ≠ {} THEN skip END\n",
"END"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Machine constants set up using operation 0: $setup_constants()"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":constants"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Machine initialised using operation 1: $initialise_machine()"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":init"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Durch die Äquivalenzklassen wird ein Minimalautomat induziert.\n",
"Die Menge der Zustände ist gleich der Menge der Äquivalenzklassen.\n",
"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",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Machine: EquivalenceRelation\n",
"Sets: Alphabet\n",
"Constants: L, RL, maxsize, All, Classes, index\n",
"Variables: z, word\n",
"Operations: \n",
"Delta(a)\n",
"Delta(b)\n",
"Delta(c)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":browse"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Executed operation: Delta(a)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":exec Delta terminal=a"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Executed operation: Delta(a)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":exec Delta terminal=a"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"<table style=\"font-family:monospace\"><tbody>\n",
"<tr>\n",
"<td style=\"padding:10px\">Wort:</td>\n",
"<td style=\"padding:10px\">a</td>\n",
"<td style=\"padding:10px\">a</td>\n",
"</tr>\n",
"<tr>\n",
"<td style=\"padding:10px\">Äquivalenzklasse:</td>\n",
"<td style=\"padding:10px\">{{(1|->a),(2|->a)},{(1|->b),(2|->b)}}</td>\n",
"<td style=\"padding:0px\"></td>\n",
"</tr>\n",
"</tbody></table>"
],
"text/plain": [
"<Animation function visualisation>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":show"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$8$"
],
"text/plain": [
"8"
]
},
"execution_count": 8,
"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": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "ProB 2",
"language": "prob",
"name": "prob2"
},
"language_info": {
"codemirror_mode": "prob2_jupyter_repl",
"file_extension": ".prob",
"mimetype": "text/x-prob2-jupyter-repl",
"name": "prob"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% Cell type:markdown id: tags:
# Der Satz von Myhill und Nerode
%% 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: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: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:code id: tags:
```
prob
```
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