Skip to content
Snippets Groups Projects
Commit 92a368fd authored by Chris's avatar Chris
Browse files

Neue Maschiene zur Visualisierung der Chomsky-Hierarchie

parent 6fbbb250
No related branches found
No related tags found
1 merge request!1Master
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Grammatiken und Chomsky-Hierarchie ## Grammatiken und Chomsky-Hierarchie
Dieses Notebook begleitet Teil 2 der Vorlesung 3 und führt am Ende die Chomsky-Hierarchie ein Dieses Notebook begleitet Teil 2 der Vorlesung 3 und führt am Ende die Chomsky-Hierarchie ein
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Eine __Grammatik__ ist ein Quadrupel Eine __Grammatik__ ist ein Quadrupel
$G = (\Sigma , N, S, P)$, wobei $G = (\Sigma , N, S, P)$, wobei
* $\Sigma$ ein Alphabet (von so genannten __Terminalsymbolen__) ist, * $\Sigma$ ein Alphabet (von so genannten __Terminalsymbolen__) ist,
* $N$ eine endliche Menge (von so genannten __Nichtterminalen__) mit * $N$ eine endliche Menge (von so genannten __Nichtterminalen__) mit
$\Sigma \cap N = \emptyset$, $\Sigma \cap N = \emptyset$,
* $S \in N$ das __Startsymbol__ und * $S \in N$ das __Startsymbol__ und
* $P \subseteq (N \cup \Sigma)^+ \times (N \cup \Sigma)^{\ast}$ die * $P \subseteq (N \cup \Sigma)^+ \times (N \cup \Sigma)^{\ast}$ die
endliche Menge der __Produktionen__ (Regeln). endliche Menge der __Produktionen__ (Regeln).
Diese mathematische Definition setzen wir im Notebook folgendermaßen um. Diese mathematische Definition setzen wir im Notebook folgendermaßen um.
Wir verwenden eine B Maschine um eine neue Basismenge an Symbolen (ΣN) einführen zu können. Wir verwenden eine B Maschine um eine neue Basismenge an Symbolen (ΣN) einführen zu können.
Hier steht ```seq1(T)``` für die nicht leeren Folgen über T, also $T^+$ in der Notation des Skripts. Hier steht ```seq1(T)``` für die nicht leeren Folgen über T, also $T^+$ in der Notation des Skripts.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
::load ::load
MACHINE Grammatik MACHINE Grammatik
SETS ΣN = {a,b,c, S} SETS ΣN = {a,b,c, S}
CONSTANTS Σ, N, P CONSTANTS Σ, N, P
PROPERTIES PROPERTIES
Σ = {a,b,c} ∧ Σ = {a,b,c} ∧
Σ ∩ N = {} ∧ Σ ∩ N = {} ∧
Σ ∪ N = ΣN ∧ Σ ∪ N = ΣN ∧
S ∈ N ∧ S ∈ N ∧
P ⊆ seq1(ΣN) × seq(ΣN) ∧ P ⊆ seq1(ΣN) × seq(ΣN) ∧
// Die Beispiel Grammatik G1 von den Folien // Die Beispiel Grammatik G1 von den Folien
P = { [S] ↦ [], P = { [S] ↦ [],
[S] ↦ [a,S,b] [S] ↦ [a,S,b]
} }
DEFINITIONS SET_PREF_PP_SEQUENCES == TRUE DEFINITIONS SET_PREF_PP_SEQUENCES == TRUE
END END
``` ```
%% Output %% Output
Loaded machine: Grammatik Loaded machine: Grammatik
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:constants :constants
``` ```
%% Output %% Output
Machine constants set up using operation 0: $setup_constants() Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
[S] ↦ RHS ∈ P [S] ↦ RHS ∈ P
``` ```
%% Output %% Output
$\mathit{TRUE}$ $\mathit{TRUE}$
**Solution:** **Solution:**
* $\mathit{RHS} = []$ * $\mathit{RHS} = []$
TRUE TRUE
Solution: Solution:
RHS = [] RHS = []
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Mit dem relationalen Bild können wir alle Regeln mit der Folge S auf der rechten Seite finden: Mit dem relationalen Bild können wir alle Regeln mit der Folge S auf der rechten Seite finden:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
P[{ [S] }] P[{ [S] }]
``` ```
%% Output %% Output
$\{[],[a,\mathit{S},b]\}$ $\{[],[a,\mathit{S},b]\}$
{[],[a,S,b]} {[],[a,S,b]}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Definiere die __unmittelbare Ableitungsrelation__ bzgl. $G$ so Definiere die __unmittelbare Ableitungsrelation__ bzgl. $G$ so
* $u \vdash_{G} v \Longleftrightarrow u = xpz, v = xqz$, * $u \vdash_{G} v \Longleftrightarrow u = xpz, v = xqz$,
wobei $x,z \in (N \cup \Sigma)^{\ast}$ und $p \rightarrow q$ eine Regel in $P$ wobei $x,z \in (N \cup \Sigma)^{\ast}$ und $p \rightarrow q$ eine Regel in $P$
ist. ist.
Im Notebook können wir dies so umsetzen, können aber leider nicht das Symbol $\vdash_G$ verwenden. Im Notebook können wir dies so umsetzen, können aber leider nicht das Symbol $\vdash_G$ verwenden.
Aus $u \vdash_{G} v$ wird $u \mapsto v \in abl$. Aus $u \vdash_{G} v$ wird $u \mapsto v \in abl$.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
::load ::load
MACHINE Grammatik MACHINE Grammatik
SETS ΣN = {a,b,c, S} SETS ΣN = {a,b,c, S}
CONSTANTS Σ, N, P CONSTANTS Σ, N, P
ABSTRACT_CONSTANTS abl ABSTRACT_CONSTANTS abl
PROPERTIES PROPERTIES
Σ = {a,b,c} ∧ Σ = {a,b,c} ∧
Σ ∩ N = {} ∧ Σ ∩ N = {} ∧
Σ ∪ N = ΣN ∧ Σ ∪ N = ΣN ∧
S ∈ N ∧ S ∈ N ∧
P ⊆ seq1(ΣN) × seq(ΣN) ∧ P ⊆ seq1(ΣN) × seq(ΣN) ∧
// Die Beispiel Grammatik G1 von den Folien // Die Beispiel Grammatik G1 von den Folien
P = { [S] ↦ [], P = { [S] ↦ [],
[S] ↦ [a,S,b] [S] ↦ [a,S,b]
} }
abl = {u,v | ∃(x,z,p,q).( p↦q ∈ P ∧ u = x^p^z ∧ v = x^q^z )} abl = {u,v | ∃(x,z,p,q).( p↦q ∈ P ∧ u = x^p^z ∧ v = x^q^z )}
DEFINITIONS SET_PREF_PP_SEQUENCES == TRUE DEFINITIONS SET_PREF_PP_SEQUENCES == TRUE
END END
``` ```
%% Output %% Output
Loaded machine: Grammatik Loaded machine: Grammatik
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:constants :constants
``` ```
%% Output %% Output
Machine constants set up using operation 0: $setup_constants() Machine constants set up using operation 0: $setup_constants()
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Da diese Relation ```abl``` unendlich ist wird diese im Notebook symbolisch gehalten. Wir können aber prüfen ob Paare an Folgen in der Relation sind: Da diese Relation ```abl``` unendlich ist wird diese im Notebook symbolisch gehalten. Wir können aber prüfen ob Paare an Folgen in der Relation sind:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
abl abl
``` ```
%% Output %% Output
$\newcommand{\qdot}{\mathord{\mkern1mu\cdot\mkern1mu}}/*@symbolic*/ \{\mathit{u},\mathit{v}\mid\exists(\mathit{x},\mathit{z},\mathit{p},\mathit{q})\qdot(\mathit{p} \mapsto \mathit{q} \in \{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\} \land \mathit{u} = \mathit{x} ⌒ \mathit{p} ⌒ \mathit{z} \land \mathit{v} = \mathit{x} ⌒ \mathit{q} ⌒ \mathit{z})\}$ $\newcommand{\qdot}{\mathord{\mkern1mu\cdot\mkern1mu}}/*@symbolic*/ \{\mathit{u},\mathit{v}\mid\exists(\mathit{x},\mathit{z},\mathit{p},\mathit{q})\qdot(\mathit{p} \mapsto \mathit{q} \in \{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\} \land \mathit{u} = \mathit{x} ⌒ \mathit{p} ⌒ \mathit{z} \land \mathit{v} = \mathit{x} ⌒ \mathit{q} ⌒ \mathit{z})\}$
/*@symbolic*/ {u,v∣∃(x,z,p,q)·(p ↦ q ∈ {([S]↦[]),([S]↦[a,S,b])} ∧ u = x ⌒ p ⌒ z ∧ v = x ⌒ q ⌒ z)} /*@symbolic*/ {u,v∣∃(x,z,p,q)·(p ↦ q ∈ {([S]↦[]),([S]↦[a,S,b])} ∧ u = x ⌒ p ⌒ z ∧ v = x ⌒ q ⌒ z)}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
[a,S,b,S] ↦ [a,S,b,a,S,b] ∈ abl [a,S,b,S] ↦ [a,S,b,a,S,b] ∈ abl
``` ```
%% Output %% Output
$\mathit{TRUE}$ $\mathit{TRUE}$
TRUE TRUE
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
[S] ↦ [a,b] ∈ abl [S] ↦ [a,b] ∈ abl
``` ```
%% Output %% Output
$\mathit{FALSE}$ $\mathit{FALSE}$
FALSE FALSE
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
[S] ↦ x ∈ abl [S] ↦ x ∈ abl
``` ```
%% Output %% Output
$\mathit{TRUE}$ $\mathit{TRUE}$
**Solution:** **Solution:**
* $\mathit{x} = []$ * $\mathit{x} = []$
TRUE TRUE
Solution: Solution:
x = [] x = []
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Mit dem relationalen Abbild können wir die Menge aller Umschreibungen berrechnen: Mit dem relationalen Abbild können wir die Menge aller Umschreibungen berrechnen:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
abl[ { [S] } ] abl[ { [S] } ]
``` ```
%% Output %% Output
$\{[],[a,\mathit{S},b]\}$ $\{[],[a,\mathit{S},b]\}$
{[],[a,S,b]} {[],[a,S,b]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
abl[ {[a,S,b,S]} ] abl[ {[a,S,b,S]} ]
``` ```
%% Output %% Output
$\{[a,\mathit{b},S],[a,\mathit{S},b],[a,\mathit{S},\mathit{b},\mathit{a},\mathit{S},b],[a,\mathit{a},\mathit{S},\mathit{b},\mathit{b},S]\}$ $\{[a,\mathit{b},S],[a,\mathit{S},b],[a,\mathit{S},\mathit{b},\mathit{a},\mathit{S},b],[a,\mathit{a},\mathit{S},\mathit{b},\mathit{b},S]\}$
{[a,b,S],[a,S,b],[a,S,b,a,S,b],[a,a,S,b,b,S]} {[a,b,S],[a,S,b],[a,S,b,a,S,b],[a,a,S,b,b,S]}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Durch mehrfache Anwendung bekommen wir die Ergebnisse von immer längeren Ableitungen: Durch mehrfache Anwendung bekommen wir die Ergebnisse von immer längeren Ableitungen:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
abl[ abl[ {[S]} ] ] abl[ abl[ {[S]} ] ]
``` ```
%% Output %% Output
$\{[a,b],[a,\mathit{a},\mathit{S},\mathit{b},b]\}$ $\{[a,b],[a,\mathit{a},\mathit{S},\mathit{b},b]\}$
{[a,b],[a,a,S,b,b]} {[a,b],[a,a,S,b,b]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
abl[ abl[ abl[ {[S]} ] ] ] abl[ abl[ abl[ {[S]} ] ] ]
``` ```
%% Output %% Output
$\{[a,\mathit{a},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b]\}$ $\{[a,\mathit{a},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b]\}$
{[a,a,b,b],[a,a,a,S,b,b,b]} {[a,a,b,b],[a,a,a,S,b,b,b]}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Durch $n$-malige Anwendung von $\vdash_{G}$ erhalten wir Durch $n$-malige Anwendung von $\vdash_{G}$ erhalten wir
$\vdash_{G}^{n}$. Das heiß t: $\vdash_{G}^{n}$. Das heiß t:
* $u \vdash_{G}^{n} v \Longleftrightarrow u = x_0 \vdash_{G} x_1 * $u \vdash_{G}^{n} v \Longleftrightarrow u = x_0 \vdash_{G} x_1
\vdash_{G} \cdots \vdash_{G} x_n = v$ \vdash_{G} \cdots \vdash_{G} x_n = v$
Im Notebook kann man für die n-malige Anwendung einer binären Relation den Operator ```iterate``` verwenden: Im Notebook kann man für die n-malige Anwendung einer binären Relation den Operator ```iterate``` verwenden:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
[S] ↦ [a,b] ∈ iterate(abl,2) [S] ↦ [a,b] ∈ iterate(abl,2)
``` ```
%% Output %% Output
$\mathit{TRUE}$ $\mathit{TRUE}$
TRUE TRUE
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Die Menge $\{w \mid S \vdash_{G}^{n} w\}$ kann direkt mit dem relationalen Bild berechnet werden. Zum Beispiel für n = 0,1,2,3,4: Die Menge $\{w \mid S \vdash_{G}^{n} w\}$ kann direkt mit dem relationalen Bild berechnet werden. Zum Beispiel für n = 0,1,2,3,4:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
iterate(abl,0)[ {[S]} ] iterate(abl,0)[ {[S]} ]
``` ```
%% Output %% Output
$\{[S]\}$ $\{[S]\}$
{[S]} {[S]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
iterate(abl,1)[ {[S]} ] iterate(abl,1)[ {[S]} ]
``` ```
%% Output %% Output
$\{[],[a,\mathit{S},b]\}$ $\{[],[a,\mathit{S},b]\}$
{[],[a,S,b]} {[],[a,S,b]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
iterate(abl,2)[ {[S]} ] iterate(abl,2)[ {[S]} ]
``` ```
%% Output %% Output
$\{[a,b],[a,\mathit{a},\mathit{S},\mathit{b},b]\}$ $\{[a,b],[a,\mathit{a},\mathit{S},\mathit{b},b]\}$
{[a,b],[a,a,S,b,b]} {[a,b],[a,a,S,b,b]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
iterate(abl,3)[ {[S]} ] iterate(abl,3)[ {[S]} ]
``` ```
%% Output %% Output
$\{[a,\mathit{a},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b]\}$ $\{[a,\mathit{a},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b]\}$
{[a,a,b,b],[a,a,a,S,b,b,b]} {[a,a,b,b],[a,a,a,S,b,b,b]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
iterate(abl,4)[ {[S]} ] iterate(abl,4)[ {[S]} ]
``` ```
%% Output %% Output
$\{[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},\mathit{b},b]\}$ $\{[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},\mathit{b},b]\}$
{[a,a,a,b,b,b],[a,a,a,a,S,b,b,b,b]} {[a,a,a,b,b,b],[a,a,a,a,S,b,b,b,b]}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Die von der Grammatik $G$ erzeugte Sprache ist Die von der Grammatik $G$ erzeugte Sprache ist
definiert als definiert als
$L(G) = \{w \in \Sigma^* \mid S \vdash_{G}^{\ast} w\}.$ $L(G) = \{w \in \Sigma^* \mid S \vdash_{G}^{\ast} w\}.$
Bis zur Länge 4 gibt es folgende abgeleitenen Wörter über $\Sigma \cup N$ Bis zur Länge 4 gibt es folgende abgeleitenen Wörter über $\Sigma \cup N$
(auch Satzformen genannt): (auch Satzformen genannt):
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ]) UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ])
``` ```
%% Output %% Output
$\{[],[a,b],[S],[a,\mathit{a},\mathit{b},b],[a,\mathit{S},b],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{S},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},\mathit{b},b]\}$ $\{[],[a,b],[S],[a,\mathit{a},\mathit{b},b],[a,\mathit{S},b],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{S},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},\mathit{b},b]\}$
{[],[a,b],[S],[a,a,b,b],[a,S,b],[a,a,a,b,b,b],[a,a,S,b,b],[a,a,a,S,b,b,b],[a,a,a,a,S,b,b,b,b]} {[],[a,b],[S],[a,a,b,b],[a,S,b],[a,a,a,b,b,b],[a,a,S,b,b],[a,a,a,S,b,b,b],[a,a,a,a,S,b,b,b,b]}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Wenn wir mit $\Sigma^*$ schneiden bekommen wir Wörter der von der Grammatik generierten Sprache: Wenn wir mit $\Sigma^*$ schneiden bekommen wir Wörter der von der Grammatik generierten Sprache:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ]) ∩ seq(Σ) UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ]) ∩ seq(Σ)
``` ```
%% Output %% Output
$\{[],[a,b],[a,\mathit{a},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b]\}$ $\{[],[a,b],[a,\mathit{a},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b]\}$
{[],[a,b],[a,a,b,b],[a,a,a,b,b,b]} {[],[a,b],[a,a,b,b],[a,a,a,b,b,b]}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Wir können die Ableitungsrelationen für alle Satzformen bis zu einer gegebenen Tiefe auch grafisch darstellen. Wir können die Ableitungsrelationen für alle Satzformen bis zu einer gegebenen Tiefe auch grafisch darstellen.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:let SF UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ]) :let SF UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ])
``` ```
%% Output %% Output
$\{[],[a,b],[S],[a,\mathit{a},\mathit{b},b],[a,\mathit{S},b],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{S},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},\mathit{b},b]\}$ $\{[],[a,b],[S],[a,\mathit{a},\mathit{b},b],[a,\mathit{S},b],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{S},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},b],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{b},\mathit{b},\mathit{b},b]\}$
{[],[a,b],[S],[a,a,b,b],[a,S,b],[a,a,a,b,b,b],[a,a,S,b,b],[a,a,a,S,b,b,b],[a,a,a,a,S,b,b,b,b]} {[],[a,b],[S],[a,a,b,b],[a,S,b],[a,a,a,b,b,b],[a,a,S,b,b],[a,a,a,S,b,b,b],[a,a,a,a,S,b,b,b,b]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:pref DOT_DECOMPOSE_NODES=FALSE :pref DOT_DECOMPOSE_NODES=FALSE
``` ```
%% Output %% Output
Preference changed: DOT_DECOMPOSE_NODES = FALSE Preference changed: DOT_DECOMPOSE_NODES = FALSE
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:dot expr_as_graph ("abl",SF <| abl |> SF) :dot expr_as_graph ("abl",SF <| abl |> SF)
``` ```
%% Output %% Output
<Dot visualization: expr_as_graph [SFSF={[],[a,b],[S],[a,a,b,b],[a,S,b],[a,a,a,b,b,b],[a,a,S,b,b],[a,a,a,S,b,b,b],[a,a,a,a,S,b,b,b,b]}("abl",SF<|abl|>SF)]> <Dot visualization: expr_as_graph [SFSF={[],[a,b],[S],[a,a,b,b],[a,S,b],[a,a,a,b,b,b],[a,a,S,b,b],[a,a,a,S,b,b,b],[a,a,a,a,S,b,b,b,b]}("abl",SF<|abl|>SF)]>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Die Grammatik G2 können wir wie folgt umsetzen: Die Grammatik G2 können wir wie folgt umsetzen:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
::load ::load
MACHINE Grammatik2 MACHINE Grammatik2
SETS ΣN = {a,b,c, S, B,C} SETS ΣN = {a,b,c, S, B,C}
CONSTANTS Σ, N, P CONSTANTS Σ, N, P
ABSTRACT_CONSTANTS abl ABSTRACT_CONSTANTS abl
PROPERTIES PROPERTIES
Σ = {a,b,c} ∧ Σ = {a,b,c} ∧
Σ ∩ N = {} ∧ Σ ∩ N = {} ∧
Σ ∪ N = ΣN ∧ Σ ∪ N = ΣN ∧
S ∈ N ∧ S ∈ N ∧
P ⊆ seq1(ΣN) × seq(ΣN) ∧ P ⊆ seq1(ΣN) × seq(ΣN) ∧
// Die Beispiel Grammatik G2 von den Folien // Die Beispiel Grammatik G2 von den Folien
P = { [S] ↦ [a,B,C], P = { [S] ↦ [a,B,C],
[S] ↦ [a,S,B,C], [S] ↦ [a,S,B,C],
[C,B] ↦ [B,C], [C,B] ↦ [B,C],
[a,B] ↦ [a,b], [a,B] ↦ [a,b],
[b,B] ↦ [b,b], [b,B] ↦ [b,b],
[b,C] ↦ [b,c], [b,C] ↦ [b,c],
[c,C] ↦ [c,c] [c,C] ↦ [c,c]
} }
abl = {u,v | ∃(x,z,p,q).( p↦q ∈ P ∧ u = x^p^z ∧ v = x^q^z )} abl = {u,v | ∃(x,z,p,q).( p↦q ∈ P ∧ u = x^p^z ∧ v = x^q^z )}
DEFINITIONS SET_PREF_PP_SEQUENCES == TRUE DEFINITIONS SET_PREF_PP_SEQUENCES == TRUE
END END
``` ```
%% Output %% Output
Loaded machine: Grammatik2 Loaded machine: Grammatik2
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:constants :constants
``` ```
%% Output %% Output
Machine constants set up using operation 0: $setup_constants() Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:let SF UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ]) :let SF UNION(i).(i:0..4|iterate(abl,i)[ {[S]} ])
``` ```
%% Output %% Output
$\{[S],[a,\mathit{b},c],[a,\mathit{b},C],[a,\mathit{S},\mathit{B},C],[a,\mathit{B},C],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{B},C],[a,\mathit{a},\mathit{b},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{b},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{S},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{B},\mathit{C},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{B},\mathit{B},\mathit{C},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{B},\mathit{C},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{a},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C]\}$ $\{[S],[a,\mathit{b},c],[a,\mathit{b},C],[a,\mathit{S},\mathit{B},C],[a,\mathit{B},C],[a,\mathit{a},\mathit{b},\mathit{c},\mathit{B},C],[a,\mathit{a},\mathit{b},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{b},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{S},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{B},\mathit{C},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{B},\mathit{B},\mathit{C},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{b},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{B},\mathit{C},\mathit{B},\mathit{B},\mathit{C},C],[a,\mathit{a},\mathit{a},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C],[a,\mathit{a},\mathit{a},\mathit{a},\mathit{S},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},\mathit{C},\mathit{B},C]\}$
{[S],[a,b,c],[a,b,C],[a,S,B,C],[a,B,C],[a,a,b,c,B,C],[a,a,b,C,B,C],[a,a,b,B,C,C],[a,a,B,C,B,C],[a,a,B,B,C,C],[a,a,S,B,C,B,C],[a,a,S,B,B,C,C],[a,a,a,S,B,C,B,B,C,C],[a,a,a,S,B,B,C,C,B,C],[a,a,a,S,B,C,B,C,B,C],[a,a,a,B,B,C,C,B,C],[a,a,a,b,C,B,C,B,C],[a,a,a,B,C,B,B,C,C],[a,a,a,B,C,B,C,B,C],[a,a,a,a,B,C,B,C,B,C,B,C],[a,a,a,a,S,B,C,B,C,B,C,B,C]} {[S],[a,b,c],[a,b,C],[a,S,B,C],[a,B,C],[a,a,b,c,B,C],[a,a,b,C,B,C],[a,a,b,B,C,C],[a,a,B,C,B,C],[a,a,B,B,C,C],[a,a,S,B,C,B,C],[a,a,S,B,B,C,C],[a,a,a,S,B,C,B,B,C,C],[a,a,a,S,B,B,C,C,B,C],[a,a,a,S,B,C,B,C,B,C],[a,a,a,B,B,C,C,B,C],[a,a,a,b,C,B,C,B,C],[a,a,a,B,C,B,B,C,C],[a,a,a,B,C,B,C,B,C],[a,a,a,a,B,C,B,C,B,C,B,C],[a,a,a,a,S,B,C,B,C,B,C,B,C]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
SF ∩ seq(Σ) SF ∩ seq(Σ)
``` ```
%% Output %% Output
$\{[a,\mathit{b},c]\}$ $\{[a,\mathit{b},c]\}$
{[a,b,c]} {[a,b,c]}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:pref DOT_DECOMPOSE_NODES=FALSE :pref DOT_DECOMPOSE_NODES=FALSE
``` ```
%% Output %% Output
Preference changed: DOT_DECOMPOSE_NODES = FALSE Preference changed: DOT_DECOMPOSE_NODES = FALSE
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:dot expr_as_graph ("abl",SF <| abl |> SF) :dot expr_as_graph ("abl",SF <| abl |> SF)
``` ```
%% Output %% Output
<Dot visualization: expr_as_graph [SFSF={[S],[a,b,c],[a,b,C],[a,S,B,C],[a,B,C],[a,a,b,c,B,C],[a,a,b,C,B,C],[a,a,b,B,C,C],[a,a,B,C,B,C],[a,a,B,B,C,C],[a,a,S,B,C,B,C],[a,a,S,B,B,C,C],[a,a,a,S,B,C,B,B,C,C],[a,a,a,S,B,B,C,C,B,C],[a,a,a,S,B,C,B,C,B,C],[a,a,a,B,B,C,C,B,C],[a,a,a,b,C,B,C,B,C],[a,a,a,B,C,B,B,C,C],[a,a,a,B,C,B,C,B,C],[a,a,a,a,B,C,B,C,B,C,B,C],[a,a,a,a,S,B,C,B,C,B,C,B,C]}("abl",SF<|abl|>SF)]> <Dot visualization: expr_as_graph [SFSF={[S],[a,b,c],[a,b,C],[a,S,B,C],[a,B,C],[a,a,b,c,B,C],[a,a,b,C,B,C],[a,a,b,B,C,C],[a,a,B,C,B,C],[a,a,B,B,C,C],[a,a,S,B,C,B,C],[a,a,S,B,B,C,C],[a,a,a,S,B,C,B,B,C,C],[a,a,a,S,B,B,C,C,B,C],[a,a,a,S,B,C,B,C,B,C],[a,a,a,B,B,C,C,B,C],[a,a,a,b,C,B,C,B,C],[a,a,a,B,C,B,B,C,C],[a,a,a,B,C,B,C,B,C],[a,a,a,a,B,C,B,C,B,C,B,C],[a,a,a,a,S,B,C,B,C,B,C,B,C]}("abl",SF<|abl|>SF)]>
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:unlet SF :unlet SF
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Bis zur Ebene 8 sieht der Graph der Ableitungsrelation so aus: Bis zur Ebene 8 sieht der Graph der Ableitungsrelation so aus:
<img src="img/GrammatikUnicode2.svg" width="700"> <img src="img/GrammatikUnicode2.svg" width="700">
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Chomsky-Hierarchie ## Chomsky-Hierarchie
Die Chomsky-Hierarchie klassifiziert Grammatiken nach folgenden Kriterien: Die Chomsky-Hierarchie klassifiziert Grammatiken nach folgenden Kriterien:
Sei $G = (\Sigma , N, S, P)$ eine Grammatik. Sei $G = (\Sigma , N, S, P)$ eine Grammatik.
* $G$ ist eine __Typ-0-Grammatik__, falls $P$ keinerlei * $G$ ist eine __Typ-0-Grammatik__, falls $P$ keinerlei
Einschränkungen unterliegt. Einschränkungen unterliegt.
* $G$ ist eine __Typ-1-Grammatik__ (bzw. __kontextsensitiv__ bzw. _nichtverkürzend_ oder __monoton__), falls für alle Regeln $p \rightarrow q$ in * $G$ ist eine __Typ-1-Grammatik__ (bzw. __kontextsensitiv__ bzw. _nichtverkürzend_ oder __monoton__), falls für alle Regeln $p \rightarrow q$ in
$P$ gilt: $|p| \leq |q|$. $P$ gilt: $|p| \leq |q|$.
* Eine Typ-1-Grammatik $G$ ist __vom Typ 2__ (bzw. __kontextfrei__), falls für alle Regeln $p \rightarrow q$ in $P$ gilt: $p \in N$. * Eine Typ-1-Grammatik $G$ ist __vom Typ 2__ (bzw. __kontextfrei__), falls für alle Regeln $p \rightarrow q$ in $P$ gilt: $p \in N$.
* Eine Typ-2-Grammatik $G$ ist __vom Typ 3__ (bzw. __regulär__ bzw. __rechtslinear__), falls für * Eine Typ-2-Grammatik $G$ ist __vom Typ 3__ (bzw. __regulär__ bzw. __rechtslinear__), falls für
alle Regeln $p \rightarrow q$ in $P$ gilt: $p \in N$ und $q \in \Sigma \cup \Sigma N$. alle Regeln $p \rightarrow q$ in $P$ gilt: $p \in N$ und $q \in \Sigma \cup \Sigma N$.
Eine Sprache $A \subseteq \Sigma^*$ ist genau dann vom Typ $i \in Eine Sprache $A \subseteq \Sigma^*$ ist genau dann vom Typ $i \in
\{0,1,2,3\}$, wenn es eine Typ-$i$-Grammatik $G$ gibt mit $L(G) = A$. \{0,1,2,3\}$, wenn es eine Typ-$i$-Grammatik $G$ gibt mit $L(G) = A$.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
P P
``` ```
%% Output
$\{([a,B]\mapsto [a,b]),([b,B]\mapsto [b,b]),([b,C]\mapsto [b,c]),([c,C]\mapsto [c,c]),([S]\mapsto [a,\mathit{S},\mathit{B},C]),([S]\mapsto [a,\mathit{B},C]),([C,B]\mapsto [B,C])\}$
{([a,B]↦[a,b]),([b,B]↦[b,b]),([b,C]↦[b,c]),([c,C]↦[c,c]),([S]↦[a,S,B,C]),([S]↦[a,B,C]),([C,B]↦[B,C])}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Jede Grammatik ist vom Typ-0. Jede Grammatik ist vom Typ-0.
Die Grammatik $G_2$ ist nicht-verkürzend, also vom Typ 1: Die Grammatik $G_2$ ist nicht-verkürzend, also vom Typ 1:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
∀(p,q).( p↦q ∈ P ⇒ size(p) ≤ size(q)) ∀(p,q).( p↦q ∈ P ⇒ size(p) ≤ size(q))
``` ```
%% Output %% Output
$\mathit{TRUE}$ $\mathit{TRUE}$
TRUE TRUE
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
P P
``` ```
%% Output %% Output
$\{([a,B]\mapsto [a,b]),([b,B]\mapsto [b,b]),([b,C]\mapsto [b,c]),([c,C]\mapsto [c,c]),([S]\mapsto [a,\mathit{S},\mathit{B},C]),([S]\mapsto [a,\mathit{B},C]),([C,B]\mapsto [B,C])\}$ $\{([a,B]\mapsto [a,b]),([b,B]\mapsto [b,b]),([b,C]\mapsto [b,c]),([c,C]\mapsto [c,c]),([S]\mapsto [a,\mathit{S},\mathit{B},C]),([S]\mapsto [a,\mathit{B},C]),([C,B]\mapsto [B,C])\}$
{([a,B]↦[a,b]),([b,B]↦[b,b]),([b,C]↦[b,c]),([c,C]↦[c,c]),([S]↦[a,S,B,C]),([S]↦[a,B,C]),([C,B]↦[B,C])} {([a,B]↦[a,b]),([b,B]↦[b,b]),([b,C]↦[b,c]),([c,C]↦[c,c]),([S]↦[a,S,B,C]),([S]↦[a,B,C]),([C,B]↦[B,C])}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Die Grammatik $G_2$ ist aber nicht vom Typ 2: Die Grammatik $G_2$ ist aber nicht vom Typ 2:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
∀(p,q).( p↦q ∈ P ⇒ size(p)=1 & p∈seq(N)) ∀(p,q).( p↦q ∈ P ⇒ size(p)=1 & p∈seq(N))
``` ```
%% Output %% Output
$\mathit{FALSE}$ $\mathit{FALSE}$
FALSE FALSE
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Anmerkung: im Skript wird nicht zwischen einem Nicht-Terminal Symbol und einer Folge der Länge 1 bestehend aus einem Nicht-Terminal unterschieden. Anmerkung: im Skript wird nicht zwischen einem Nicht-Terminal Symbol und einer Folge der Länge 1 bestehend aus einem Nicht-Terminal unterschieden.
Deshalb steht im Skript $p\in N$. Im Notebook sind $p$ und die Folge bestehend aus einem $p$ (geschrieben als [p]) von einem unterschiedlichen Typ. Die wortwörtliche Übersetzung von $p\in N$ führt zu einem Typfehler. Deshalb steht im Skript $p\in N$. Im Notebook sind $p$ und die Folge bestehend aus einem $p$ (geschrieben als [p]) von einem unterschiedlichen Typ. Die wortwörtliche Übersetzung von $p\in N$ führt zu einem Typfehler.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
∀(p,q).( p↦q ∈ P ⇒ p ∈ N) ∀(p,q).( p↦q ∈ P ⇒ p ∈ N)
``` ```
%% Output %% Output
:eval: Computation not completed: Type mismatch: Expected POW(seq(ΣN)), but was POW(ΣN) in 'N' :eval: Computation not completed: Type mismatch: Expected POW(seq(ΣN)), but was POW(ΣN) in 'N'
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Die Grammatik $G_2$ ist also vom Typ 1 aber nicht vom Typ 2 oder 3. Die Grammatik $G_2$ ist also vom Typ 1 aber nicht vom Typ 2 oder 3.
Wie sieht es mit der Grammatik $G_1$ aus? Wie sieht es mit der Grammatik $G_1$ aus?
Diese erfüllt die Typ-2 Bedingung: Diese erfüllt die Typ-2 Bedingung:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:let P1 { [S] ↦ [], [S] ↦ [a,S,b] } :let P1 { [S] ↦ [], [S] ↦ [a,S,b] }
``` ```
%% Output %% Output
$\{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\}$ $\{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\}$
{([S]↦[]),([S]↦[a,S,b])} {([S]↦[]),([S]↦[a,S,b])}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
∀(p,q).( p↦q ∈ P1 ⇒ size(p)=1 & p∈seq(N)) ∀(p,q).( p↦q ∈ P1 ⇒ size(p)=1 & p∈seq(N))
``` ```
%% Output %% Output
$\mathit{TRUE}$ $\mathit{TRUE}$
**Solution:** **Solution:**
* $\mathit{P1} = \{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\}$ * $\mathit{P1} = \{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\}$
TRUE TRUE
Solution: Solution:
P1 = {([S]↦[]),([S]↦[a,S,b])} P1 = {([S]↦[]),([S]↦[a,S,b])}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Die Grammatik $G_1$ erfüllt aber nicht die Typ 1 Bedingung, da die erste Regel verkürzend ist: Die Grammatik $G_1$ erfüllt aber nicht die Typ 1 Bedingung, da die erste Regel verkürzend ist:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
∀(p,q).( p↦q ∈ P1 ⇒ size(p) ≤ size(q)) ∀(p,q).( p↦q ∈ P1 ⇒ size(p) ≤ size(q))
``` ```
%% Output %% Output
$\mathit{FALSE}$ $\mathit{FALSE}$
FALSE FALSE
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
p↦q ∈ P1 ∧ size(p) > size(q) /* Gegenbeispiel */ p↦q ∈ P1 ∧ size(p) > size(q) /* Gegenbeispiel */
``` ```
%% Output %% Output
$\mathit{TRUE}$ $\mathit{TRUE}$
**Solution:** **Solution:**
* $\mathit{p} = [S]$ * $\mathit{p} = [S]$
* $\mathit{q} = []$ * $\mathit{q} = []$
* $\mathit{P1} = \{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\}$ * $\mathit{P1} = \{([S]\mapsto []),([S]\mapsto [a,\mathit{S},b])\}$
TRUE TRUE
Solution: Solution:
p = [S] p = [S]
q = [] q = []
P1 = {([S]↦[]),([S]↦[a,S,b])} P1 = {([S]↦[]),([S]↦[a,S,b])}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Die Grammatik $G_1$ ist also vom Typ-0. Die Grammatik $G_1$ ist also vom Typ-0.
Wir werden aber in der nächsten Woche eine Sonderregelung für das leere Wort erlauben, damit auch Grammatiken vom Typ 1,2 oder 3 das leere Wort in ihrer Sprache generieren können. Wir werden aber in der nächsten Woche eine Sonderregelung für das leere Wort erlauben, damit auch Grammatiken vom Typ 1,2 oder 3 das leere Wort in ihrer Sprache generieren können.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Chomsky-Hierarchie ### Chomsky-Hierarchie
Die __Chomsky-Hierarchie__ besteht aus den vier Sprachklassen: Die __Chomsky-Hierarchie__ besteht aus den vier Sprachklassen:
* $\mathfrak{L}_i = \{L(G) \Longleftrightarrow \mbox{$G$ ist Typ-$i$-Grammatik} \}$, * $\mathfrak{L}_i = \{L(G) \Longleftrightarrow \mbox{$G$ ist Typ-$i$-Grammatik} \}$,
wobei $i \in \{0,1,2,3\}$. wobei $i \in \{0,1,2,3\}$.
Übliche Bezeichnungen: Übliche Bezeichnungen:
* $\mathfrak{L}_0$ ist die Klasse aller Sprachen, die durch eine * $\mathfrak{L}_0$ ist die Klasse aller Sprachen, die durch eine
Grammatik erzeugt werden können; Grammatik erzeugt werden können;
* $\mathfrak{L}_1 = CS$ ist die __Klasse der kontextsensitiven Sprachen__; * $\mathfrak{L}_1 = CS$ ist die __Klasse der kontextsensitiven Sprachen__;
* $\mathfrak{L}_2 = CF$ ist die __Klasse der kontextfreien Sprachen__; * $\mathfrak{L}_2 = CF$ ist die __Klasse der kontextfreien Sprachen__;
* $\mathfrak{L}_3 = REG$ ist die __Klasse der regulären Sprachen__. * $\mathfrak{L}_3 = REG$ ist die __Klasse der regulären Sprachen__.
* $REG \subseteq CF \subseteq CS \subseteq \mathfrak{L}_0.$ * $REG \subseteq CF \subseteq CS \subseteq \mathfrak{L}_0.$
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
::load
MACHINE Chomsky
SETS ΣN = {a, b, c, S, A, B, C}
CONSTANTS Σ, N, P0, P1, P2, P3, P4, Grammatiken
PROPERTIES
Σ = {a, b, c} ∧
N = {S, A, B, C} ∧
Σ ∩ N = {} ∧
Σ ∪ N = ΣN ∧
//L0 = {x∈{a, b}^* | x enthält gleich viele as und bs}
//Ohne Sonderrregelung für lambda ist L0 von Typ 0.
P0 = {([S] ↦ [a, b]), ([S] ↦ [S, S]), ([S] ↦ []), ([a, b] ↦ [b, a]), ([b, a] ↦ [a, b])} ∧
//L1 = {a^mb^mc^m | m≥1}
P1 = {([S] ↦ [S, S]), ([S] ↦ [A, B, C]), ([B, A] ↦ [A, B]), ([C, A] ↦ [A, C]), ([C, B] ↦ [B, C]),
([A] ↦ [a]), ([a, B] ↦ [a, b]), ([b, B] ↦ [b, b]), ([b, C] ↦ [b, c]), ([c, C] ↦ [c, c])} ∧
//L2 = {x∈{a, b}^+ | x enthält gleich viele as und bs}
P2 = {([S] ↦ [A, B]), ([S] ↦ [B, A]),
([A] ↦ [A, A, B]), ([A] ↦ [A, B, A]), ([A] ↦ [B, A, A]), ([A] ↦ [a]),
([B] ↦ [B, B, A]), ([B] ↦ [B, A, B]), ([B] ↦ [A, B, B]), ([B] ↦ [b])} ∧
//L3 = L4 = {a, b, c}
P3 = {([S] ↦ [a]), ([S] ↦ [b]), ([S] ↦ [c])} ∧
P4 = {([S] ↦ [A, A]), ([A, A] ↦ [a]), ([S] ↦ [b]), ([S] ↦ [c])} ∧
Grammatiken = [P0, P1, P2, P3, P4]
DEFINITIONS
SET_PREF_PP_SEQUENCES == TRUE;
L0(R) == TRUE; //Jede Grammatik ist vom Typ 0
L1(R) == IF ∀(p,q).( p↦q ∈ R ⇒ size(p) ≤ size(q)) THEN L0(R) ELSE FALSE END;
L2(R) == IF ∀(p,q).( p↦q ∈ R ⇒ size(p)=1 & p∈seq(N)) THEN L1(R) ELSE FALSE END;
L3(R) == IF ∀(p,q).( p↦q ∈ R ⇒ size(q)>0 & size(q) ≤ 2 & first(q)∈Σ & (size(q)≤1 or first(tail(q))∈N)) THEN L2(R) ELSE FALSE END;
"LibraryStrings.def";
ANIMATION_FUNCTION_DEFAULT == {(0,0,"P"), (1,0,"P0"), (2,0,"P1"), (3,0,"P2"), (4,0,"P3"), (5,0,"P4")};
ANIMATION_FUNCTION1 == {c,r,i| r=1 ∧ c∈dom(Grammatiken) ∧ i=TO_STRING(L0(Grammatiken(c)))} ∪ {(0,1,"L0(P)")};
ANIMATION_FUNCTION2 == {c,r,i| r=2 ∧ c∈dom(Grammatiken) ∧ i=TO_STRING(L1(Grammatiken(c)))} ∪ {(0,2,"L1(P)")};
ANIMATION_FUNCTION3 == {c,r,i| r=3 ∧ c∈dom(Grammatiken) ∧ i=TO_STRING(L2(Grammatiken(c)))} ∪ {(0,3,"L2(P)")};
ANIMATION_FUNCTION4 == {c,r,i| r=4 ∧ c∈dom(Grammatiken) ∧ i=TO_STRING(L3(Grammatiken(c)))} ∪ {(0,4,"L3(P)")};
END
```
%% Output
Loaded machine: Chomsky
%% 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
:show
```
%% Output
<table style="font-family:monospace"><tbody>
<tr>
<td style="padding:10px">P</td>
<td style="padding:10px">L0(P)</td>
<td style="padding:10px">L1(P)</td>
<td style="padding:10px">L2(P)</td>
<td style="padding:10px">L3(P)</td>
</tr>
<tr>
<td style="padding:10px">P0</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">FALSE</td>
<td style="padding:10px">FALSE</td>
<td style="padding:10px">FALSE</td>
</tr>
<tr>
<td style="padding:10px">P1</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">FALSE</td>
<td style="padding:10px">FALSE</td>
</tr>
<tr>
<td style="padding:10px">P2</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">FALSE</td>
</tr>
<tr>
<td style="padding:10px">P3</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">TRUE</td>
</tr>
<tr>
<td style="padding:10px">P4</td>
<td style="padding:10px">TRUE</td>
<td style="padding:10px">FALSE</td>
<td style="padding:10px">FALSE</td>
<td style="padding:10px">FALSE</td>
</tr>
</tbody></table>
<Animation function visualisation>
%% Cell type:markdown id: tags:
Die obige Tabelle zeigt, in welche Sprachklasse die entsprechenden Grammatiken fallen. Dabei ist zu beachten, dass L3 = L4 ist, aber P3 und P4 unterschiedliche Typen haben. Die Sprache fällt allerdings immer in die größte Spracheklasse zu der es eine Grammatik gibt, die diese Sprache erzeugt. Also gilt $L4 ∈ \mathfrak{L}_3 = REG$. Daher reicht die Angabe einer Grammatik nicht aus, um zu zeigen dass eine Sprache höchstens in einer der Klassen liegt. Um dies zu zeigen gibt es verschiedene Methoden, wie z.B. das Pumping-Lemma oder die Myhill-Nerode Relation.
%% 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