Skip to content
Snippets Groups Projects
Commit 3c4c7517 authored by Michael Leuschel's avatar Michael Leuschel
Browse files

fix typo

parent a231c472
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
## Formale Sprachen
Dieses Notebook begleitet Vorlesung 3 und erläutert die grundlegenden Definitionen der formalen Sprachen.
%% Cell type:code id: tags:
``` prob
::load
MACHINE Alphabet
SETS Σ = {a,b,c}
END
```
%% Output
Loaded machine: Alphabet
%% Cell type:markdown id: tags:
Ein Wort ist eine endliche Folge von Elementen aus dem Alphabet.
Im Skript schreiben wir $w \in \Sigma^{*}$; hier im Notebook schreiben wir
$w \in seq(\Sigma)$.
Im Skript schreiben wir Wörter in dem wir die Symbole aus $\Sigma$ hintereinander setzten: $abc$. Im Notebook schreiben wir $[a,b,c]$ für die Folge mit den drei Symbolen $a$, $b$ und $c$.
Also aus $abc \in \Sigma^*$ wird dies:
%% Cell type:code id: tags:
``` prob
[a,b,c] ∈ seq(Σ)
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
[a,a,b,c] ∈ seq(Σ)
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
Die Länge eines Wortes $w$ ist die Anzahl der Symbole in $w$. Im Skript schreiben wir $\|w\|$, im Notebook benutzen wir ```size(w)```:
Die Länge eines Wortes $w$ ist die Anzahl der Symbole in $w$. Im Skript schreiben wir $|w|$, im Notebook benutzen wir ```size(w)```:
%% Cell type:code id: tags:
``` prob
size([a,b,c])
```
%% Output
$3$
3
%% Cell type:code id: tags:
``` prob
size([a,a,b,c])
```
%% Output
$4$
4
%% Cell type:markdown id: tags:
Das leere Wort ist das eindeutig bestimmte Wort der Laenge 0:
%% Cell type:code id: tags:
``` prob
ε ∈ seq(Σ) ∧ size(ε) = 0
```
%% Output
$\renewcommand{\emptyset}{\mathord\varnothing}\mathit{TRUE}$
**Solution:**
* $ε = \emptyset$
TRUE
Solution:
ε = ∅
%% Cell type:markdown id: tags:
Leider ist in der B Sprache das Symbol λ schon vergeben (zur Definition von Funktionen). Deshalb müssen wir in einer weiteren Abweichung vom Skript Epsilon verwenden.
Eine formale Sprache ist eine jede Teilmenge von $\Sigma^*$.
%% Cell type:code id: tags:
``` prob
Sprachen = {L | L ⊆ seq(Σ)}
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{Sprachen} = \{\mathit{L}\mid \mathit{L} \subseteq \mathit{seq}(Σ)\}$
TRUE
Solution:
Sprachen = {L∣L ⊆ seq(Σ)}
%% Cell type:markdown id: tags:
In folgender B Maschine werden wir ein paar Sprachen und Wörter definieren:
%% Cell type:code id: tags:
``` prob
::load
MACHINE Alphabet
SETS Σ = {a,b,c}
CONSTANTS ε, Sprachen, w₁, w₂, L₁, L₂
PROPERTIES
ε ∈ seq(Σ) ∧ size(ε) = 0 ∧
Sprachen = {L | L ⊆ seq(Σ)}∧
w₁ = [a,a,b,c] ∧
w₂ = [c,c] ∧
L₁ = {w₁,w₂} ∧
L₂ = {w₂, [a,a,a] }
END
```
%% Output
Loaded machine: Alphabet
%% Cell type:code id: tags:
``` prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
``` prob
w₁
```
%% Output
$\{(1\mapsto \mathit{a}),(2\mapsto \mathit{a}),(3\mapsto \mathit{b}),(4\mapsto \mathit{c})\}$
{(1↦a),(2↦a),(3↦b),(4↦c)}
%% Cell type:markdown id: tags:
Man sieht hier, dass die Folge aabc, mathematisch gesehen eine totale Funktion von 1..4 nach $\Sigma$ ist. Wir können aber den "Pretty-Printer" beeinflussen und Folgen anders ausgeben:
%% Cell type:code id: tags:
``` prob
:pref PP_SEQUENCES=TRUE
```
%% Output
Preference changed: PP_SEQUENCES = TRUE
%% Cell type:code id: tags:
``` prob
w₁
```
%% Output
$[a,\mathit{a},\mathit{b},c]$
[a,a,b,c]
%% Cell type:markdown id: tags:
Hier wird die Schreibweise von B für Folgen verwendet. Diese kann man auch so im Notebook eingeben.
%% Cell type:code id: tags:
``` prob
w₂
```
%% Output
$[c,c]$
[c,c]
%% Cell type:code id: tags:
``` prob
L₁
```
%% Output
$\{[c,c],[a,\mathit{a},\mathit{b},c]\}$
{[c,c],[a,a,b,c]}
%% Cell type:markdown id: tags:
Die Leere Sprache ist die Sprache die keine Wörter enthält, sie ist unterschiedlich von der Sprache die nur das leere Wort beinhaltet:
%% Cell type:code id: tags:
``` prob
LeereSprache = ∅ ∧ LeereSprache ≠ {ε}
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{LeereSprache} = []$
TRUE
Solution:
LeereSprache = []
%% Cell type:markdown id: tags:
Die Kardinalität einer Sprache L ist die Anzahl der Wörter von L.
%% Cell type:code id: tags:
``` prob
card(L₁)
```
%% Output
$2$
2
%% Cell type:code id: tags:
``` prob
card( {ε} )
```
%% Output
$1$
1
%% Cell type:code id: tags:
``` prob
card( ∅ )
```
%% Output
$0$
0
%% Cell type:markdown id: tags:
Die Mengeoperatoren (Vereinigung, Schnitt, Differenz) kann man auch auf Sprachen anwenden:
%% Cell type:code id: tags:
``` prob
L₁
```
%% Output
$\{[c,c],[a,\mathit{a},\mathit{b},c]\}$
{[c,c],[a,a,b,c]}
%% Cell type:code id: tags:
``` prob
L₂
```
%% Output
$\{[c,c],[a,\mathit{a},a]\}$
{[c,c],[a,a,a]}
%% Cell type:code id: tags:
``` prob
L₁ ∪ L₂
```
%% Output
$\{[c,c],[a,\mathit{a},a],[a,\mathit{a},\mathit{b},c]\}$
{[c,c],[a,a,a],[a,a,b,c]}
%% Cell type:code id: tags:
``` prob
{x| x∈seq(Σ) ∧ (x∈L₁ ∨ x∈L₂)}
```
%% Output
$\{[c,c],[a,\mathit{a},a],[a,\mathit{a},\mathit{b},c]\}$
{[c,c],[a,a,a],[a,a,b,c]}
%% Cell type:code id: tags:
``` prob
L₁ ∩ L₂
```
%% Output
$\{[c,c]\}$
{[c,c]}
%% Cell type:code id: tags:
``` prob
{x| x∈seq(Σ) ∧ (x∈L₁ ∧ x∈L₂)}
```
%% Output
$\{[c,c]\}$
{[c,c]}
%% Cell type:code id: tags:
``` prob
L₁ \ L₂
```
%% Output
$\{[a,\mathit{a},\mathit{b},c]\}$
{[a,a,b,c]}
%% Cell type:code id: tags:
``` prob
L₂ \ L₁
```
%% Output
$\{[a,\mathit{a},a]\}$
{[a,a,a]}
%% Cell type:code id: tags:
``` prob
Komplement = seq(Σ) \ L₁ ∧
[a,a,b,c] ∉ Komplement ∧
[a,a,c,c] ∈ Komplement
```
%% Output
$\mathit{TRUE}$
**Solution:**
* $\mathit{Komplement} = (\mathit{seq}(Σ) - \{[c,c],[a,\mathit{a},\mathit{b},c]\})$
TRUE
Solution:
Komplement = (seq(Σ) − {[c,c],[a,a,b,c]})
%% Cell type:markdown id: tags:
Konkatenation von Wörtern wird in B mit ^ geschrieben:
%% Cell type:code id: tags:
``` prob
w₁
```
%% Output
$[a,\mathit{a},\mathit{b},c]$
[a,a,b,c]
%% Cell type:code id: tags:
``` prob
w₁^w₁
```
%% Output
$[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c]$
[a,a,b,c,a,a,b,c]
%% Cell type:code id: tags:
``` prob
w₁^ε
```
%% Output
$[a,\mathit{a},\mathit{b},c]$
[a,a,b,c]
%% Cell type:code id: tags:
``` prob
ε^w₁
```
%% Output
$[a,\mathit{a},\mathit{b},c]$
[a,a,b,c]
%% Cell type:markdown id: tags:
Die Verkettung von Sprachen:
%% Cell type:code id: tags:
``` prob
L₁
```
%% Output
$\{[c,c],[a,\mathit{a},\mathit{b},c]\}$
{[c,c],[a,a,b,c]}
%% Cell type:code id: tags:
``` prob
L₂
```
%% Output
$\{[c,c],[a,\mathit{a},a]\}$
{[c,c],[a,a,a]}
%% Cell type:code id: tags:
``` prob
{w | ∃(a,b).(a∈L₁ ∧ b∈L₂ ∧ w = a^b)}
```
%% Output
$\{[c,\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{a},\mathit{a},a],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},a]\}$
{[c,c,c,c],[c,c,a,a,a],[a,a,b,c,c,c],[a,a,b,c,a,a,a]}
%% Cell type:markdown id: tags:
Man kann eine Sprache auch mit sich selber verketten.
Dies ist die Sprache $L_1^2$:
%% Cell type:code id: tags:
``` prob
:let L1_2 {w | ∃(a,b).(a∈L₁ ∧ b∈L₁ ∧ w = a^b)}
```
%% Output
$\{[c,\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c]\}$
{[c,c,c,c],[c,c,a,a,b,c],[a,a,b,c,c,c],[a,a,b,c,a,a,b,c]}
%% Cell type:markdown id: tags:
Man kann eine Sprache auch mehrfach mit sich selber verketten.
Dies sind die Sprachen $L_1^3$ und $L_1^4$:
%% Cell type:code id: tags:
``` prob
:let L1_3 {w | ∃(a,b).(a∈L₁ ∧ b∈L1_2 ∧ w = a^b)}
```
%% Output
$\{[c,\mathit{c},\mathit{c},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c]\}$
{[c,c,c,c,c,c],[c,c,a,a,b,c,c,c],[a,a,b,c,c,c,c,c],[c,c,c,c,a,a,b,c],[a,a,b,c,a,a,b,c,c,c],[c,c,a,a,b,c,a,a,b,c],[a,a,b,c,c,c,a,a,b,c],[a,a,b,c,a,a,b,c,a,a,b,c]}
%% Cell type:code id: tags:
``` prob
:let L1_4 {w | ∃(a,b).(a∈L₁ ∧ b∈L1_3 ∧ w = a^b)}
```
%% Output
$\{[c,\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{c},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[c,\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[c,\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[c,\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{c},c],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},\mathit{c},\mathit{a},\mathit{a},\mathit{b},c]\}$
{[c,c,c,c,c,c,c,c],[c,c,c,c,a,a,b,c,c,c],[c,c,a,a,b,c,c,c,c,c],[a,a,b,c,c,c,c,c,c,c],[c,c,c,c,c,c,a,a,b,c],[a,a,b,c,a,a,b,c,c,c,c,c],[c,c,c,c,a,a,b,c,a,a,b,c],[c,c,a,a,b,c,c,c,a,a,b,c],[c,c,a,a,b,c,a,a,b,c,c,c],[a,a,b,c,c,c,c,c,a,a,b,c],[a,a,b,c,c,c,a,a,b,c,c,c],[c,c,a,a,b,c,a,a,b,c,a,a,b,c],[a,a,b,c,c,c,a,a,b,c,a,a,b,c],[a,a,b,c,a,a,b,c,c,c,a,a,b,c],[a,a,b,c,a,a,b,c,a,a,b,c,c,c],[a,a,b,c,a,a,b,c,a,a,b,c,a,a,b,c]}
%% Cell type:code id: tags:
``` prob
:unlet L1_2
```
%% Cell type:code id: tags:
``` prob
:unlet L1_3
```
%% Cell type:code id: tags:
``` prob
:unlet L1_4
```
%% Cell type:markdown id: tags:
Die Spiegelung eines Wortes kann im Notebook mit dem ```rev``` Operator verwirklicht werden:
%% Cell type:code id: tags:
``` prob
rev(w₁)
```
%% Output
$[c,\mathit{b},\mathit{a},a]$
[c,b,a,a]
%% Cell type:markdown id: tags:
Eine Sprache wird gespiegelt indem jedes Wort gespiegelt wird:
%% Cell type:code id: tags:
``` prob
{ws|∃w.(w∈L₁ ∧ ws=rev(w))}
```
%% Output
$\{[a,\mathit{b},\mathit{a},c],[c,\mathit{b},\mathit{a},a]\}$
{[a,b,a,c],[c,b,a,a]}
%% Cell type:markdown id: tags:
Die Teilwort und Präfix Relationen definieren wir in folgender B Maschine:
%% Cell type:code id: tags:
``` prob
::load
MACHINE Alphabet
SETS Sigma = {a,b,c}
CONSTANTS ε, Sprachen, w₁, w₂, L₁, L₂
ABSTRACT_CONSTANTS
teilwort, präfix
PROPERTIES
ε ∈ seq(Sigma) ∧ size(ε) = 0 ∧
Sprachen = {L | L ⊆ seq(Sigma)}∧
w₁ = [a,a,b,c] ∧
w₂ = [c,a,b,a] ∧
L₁ = {w₁,w₂} ∧
L₂ = {w₂, [a,a,a] } ∧
teilwort = {ut,vt | ut∈seq(Sigma) & vt∈seq(Sigma) ∧ ∃(vt1,vt2).(vt1^ut^vt2 = vt)} ∧
präfix = {up,vp | up∈seq(Sigma) & vp∈seq(Sigma) ∧ ∃(wp).(up^wp = vp)}
DEFINITIONS SET_PREF_PP_SEQUENCES == TRUE
END
```
%% Output
Loaded machine: Alphabet
%% Cell type:code id: tags:
``` prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
``` prob
[a,a] ↦ [c,b,a,a,b] ∈ teilwort
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
[a,a,a] ↦ [c,b,a,a,b] ∈ teilwort
```
%% Output
$\mathit{FALSE}$
FALSE
%% Cell type:code id: tags:
``` prob
[c] ↦ [c,b,a,a,b] ∈ präfix
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
Man kann den Verkettungs Operator mehrfach anwenden:
%% Cell type:code id: tags:
``` prob
{x| x ↦ [c,b,a,a,b] ∈ präfix}
```
%% Output
$\{[],[c],[c,b],[c,\mathit{b},a],[c,\mathit{b},\mathit{a},a],[c,\mathit{b},\mathit{a},\mathit{a},b]\}$
{[],[c],[c,b],[c,b,a],[c,b,a,a],[c,b,a,a,b]}
%% Cell type:code id: tags:
``` prob
{x| x ↦ [c,b,a,a,b] ∈ teilwort}
```
%% Output
$\{[],[a],[a,a],[a,b],[b],[b,a],[c],[c,b],[a,\mathit{a},b],[b,\mathit{a},a],[b,\mathit{a},\mathit{a},b],[c,\mathit{b},a],[c,\mathit{b},\mathit{a},a],[c,\mathit{b},\mathit{a},\mathit{a},b]\}$
{[],[a],[a,a],[a,b],[b],[b,a],[c],[c,b],[a,a,b],[b,a,a],[b,a,a,b],[c,b,a],[c,b,a,a],[c,b,a,a,b]}
%% Cell type:code id: tags:
``` prob
:let TW {x| x ↦ [a,b,c] ∈ teilwort}
```
%% Output
$\{[],[a],[a,b],[b],[b,c],[c],[a,\mathit{b},c]\}$
{[],[a],[a,b],[b],[b,c],[c],[a,b,c]}
%% Cell type:code id: tags:
``` prob
:pref DOT_DECOMPOSE_NODES=FALSE
```
%% Output
Preference changed: DOT_DECOMPOSE_NODES = FALSE
%% Cell type:code id: tags:
``` prob
:dot expr_as_graph ("tw",{x,y | x |-> y : teilwort & y : TW })
```
%% Output
<Dot visualization: expr_as_graph [TWTW={[],[a],[a,b],[b],[b,c],[c],[a,b,c]}("tw",{x,y|(x,y):teilwort & y:TW})]>
%% Cell type:code id: tags:
``` prob
:dot expr_as_graph ("präfix",{x,y | x |-> y : präfix & y : TW })
```
%% Output
<Dot visualization: expr_as_graph [TWTW={[],[a],[a,b],[b],[b,c],[c],[a,b,c]}("präfix",{x,y|(x,y):präfix & y:TW})]>
%% Cell type:code id: tags:
``` prob
:unlet TW
```
%% Cell type:code id: tags:
``` prob
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment