Mercurial > 14ss.theoinf
annotate notes/tex/grammars.tex @ 20:02e25244ae1f
fix error in cyk
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Wed, 14 May 2014 21:58:31 +0200 |
parents | d9096d761fab |
children | 6a3cdddedcf7 |
rev | line source |
---|---|
1 | 1 \defineUnit{grammatik}{% |
2 \begin{frame} | |
3 \frametitle{Grammatiken} | |
4 \setbeamercovered{dynamic} | |
5 | |
3 | 6 \begin{definition}[Grammatik] |
7 Eine \structure{(Phrasenstruktur-)Grammatik} $G = (V, \Sigma, P, S)$ ist ein 4-Tupel: | |
1 | 8 \begin{description} |
9 \item[V] endlich viele \alert{Nichtterminale} (Variablen) | |
10 \item[$\Sigma$] ein Alphabet von \alert{Terminalen} | |
3 | 11 \item[P] endlich viele \alert{Produktionen} $\subseteq \left( V \cup \Sigma \right)^* \times \left( V \cup \Sigma \right)^*$ |
12 \item[S] ein \alert{Startsymbol} (Axiom) | |
1 | 13 \end{description} |
3 | 14 Ist $(l, r) \in P$, so schreibt man \structure{$l \rightarrow r$}. |
1 | 15 \end{definition} |
16 | |
3 | 17 \vfill |
18 | |
19 \begin{example}[] | |
1 | 20 $\Sigma = \left\{ 0, 1 \right\}$. Grammatik für alle Wörter ungerader Länge, bei denen alle Nullen vor der ersten Eins stehen und weniger Nullen als Einsen vorhanden sind. |
3 | 21 \visible<2>{ |
22 \begin{align} | |
23 S \rightarrow 0S1 \mid S11 \mid 1 | |
24 \end{align} | |
25 } | |
1 | 26 \end{example} |
27 \end{frame} | |
28 } | |
29 | |
30 \defineUnit{ableitung}{% | |
31 \begin{frame} | |
32 \frametitle{Ableitungsrelation} | |
33 \setbeamercovered{dynamic} | |
34 | |
35 \begin{definition}[Ableitungsrelation] | |
3 | 36 Eine Grammatik $G$ induziert eine \structure{Ableitungsrelation} $\rightarrow_G$ auf Wörtern über $V \cup \Sigma$. Seien $x, y$ solche Wörter und |
37 \begin{align} | |
38 z &= x\alert{\alpha}y\\ | |
39 z^\prime &= x\alert{\beta}y\\ | |
40 \intertext{Dann ist} | |
41 z &\rightarrow_G z^\prime | |
42 \end{align} | |
43 gdw. es eine Regel $\alert{\alpha \rightarrow \beta}$ in $P$ gibt. | |
1 | 44 \end{definition} |
45 | |
3 | 46 \vfill |
47 | |
48 \begin{example}[] | |
1 | 49 Mit den Produktionen $S \rightarrow 0S1 \mid S11 \mid 1$: |
50 \begin{align*} | |
51 S &\rightarrow_G 0S1 \rightarrow_G 00S11 \rightarrow_G 00S1111 \rightarrow_G 0011111 \\ | |
3 | 52 \intertext{Es gilt also} |
53 S &\rightarrow_G^* 0011111 | |
1 | 54 \end{align*} |
55 \end{example} | |
56 \end{frame} | |
57 } | |
58 | |
3 | 59 \defineUnit{sprachtypen}{% |
60 \begin{frame} | |
61 \frametitle{Sprachtypen} | |
62 | |
63 Sei $G = (V, \Sigma, P, S)$ eine Grammatik und $\alpha \rightarrow \beta \in P$ beliebig. | |
64 \begin{definition}[Monotonie] | |
65 $G$ heißt \structure{(längen-)monoton}, wenn für $\alpha \neq S$ gilt | |
66 \begin{align} | |
67 \alert{\abs{\alpha} \leq \abs{\beta}} | |
68 \end{align} | |
69 und falls $S \to \epsilon \in P$, dann kommt $S$ nie auf der rechten Seite vor. | |
70 \end{definition} | |
71 | |
72 \vfill | |
73 | |
74 \begin{definition}[Chomsky-Typen] | |
75 Seien $A \in V$, $\gamma, \delta \in (V \cup \Sigma)^*$ und $\beta^\prime \in (V \cup \Sigma)^+$.\\ | |
76 Damit $G$ vom \structure{Typ k} ist, muss für $\alpha$ und $\beta$ gelten | |
77 \begin{center} | |
78 \tabulinesep=4pt | |
79 \begin{tabu} to .8\textwidth{X[1,c,m]|[.5pt]X[2,c,m]X[2,c,m]} | |
80 & $\alpha$ & $\beta$\\\tabucline[.5pt]{-} | |
81 \structure{Typ 0} & beliebig & beliebig\\ | |
82 \structure{Typ 1} & $= \alert{\gamma} A \alert{\delta}$ & $= \alert{\gamma} \beta^\prime \alert{\delta}$\\ | |
83 \structure{Typ 2} & $\in V$ & beliebig\\ | |
84 \structure{Typ 3} & $\in V$ & $\in \Sigma^+ \cup \Sigma^*V$\\ | |
85 \end{tabu} | |
86 \end{center} | |
87 Ab Typ 1 muss $G$ auch \alert{monoton} sein. | |
88 \end{definition} | |
89 \end{frame} | |
90 } | |
91 | |
1 | 92 \defineUnit{cfl}{% |
93 \begin{frame}[c] | |
94 \frametitle{Kontextfreie Sprache} | |
95 \setbeamercovered{dynamic} | |
96 | |
97 \begin{definition}[Kontextfreie Sprache] | |
98 Eine kontextfreie Grammatik $G = (V, \Sigma, P, S)$ \alert{erzeugt} die Sprache | |
99 \[ | |
100 L(G) := \left\{ w \in \Sigma^* \mid S \rightarrow_G^* w \right\} | |
101 \] | |
102 Eine Sprache $L \subseteq \Sigma^*$ heißt \alert{kontextfrei} gdw es eine kontextfreie Grammatik $G$ gibt mit $L = L(G)$. | |
103 \end{definition} | |
19 | 104 \end{frame} |
1 | 105 } |
106 | |
107 \defineUnit{induktivesprachdefinition}{% | |
108 \begin{frame} | |
109 \frametitle{Induktive Sprachdefinition} | |
110 \setbeamercovered{dynamic} | |
111 | |
112 \begin{block}{Induktive Sprachdefinition} | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
113 Die \alert{induktive Definition} zu einer Grammatik $G$ ergibt sich direkt aus ihren Produktionen. Dabei werden kleinere Worte zu größeren Worten \alert{zusammengesetzt}, die Definition erfolgt \structure{bottom-up}. |
1 | 114 \end{block} |
115 | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
116 \vfill |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
117 |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
118 \begin{example} |
1 | 119 Mit den Produktionen $S \rightarrow 0S1 \mid S11 \mid 1$: |
120 | |
121 \begin{align*} | |
122 1 &\in L_G(S) \\ | |
123 u \in L_G(S) \quad \Longrightarrow \quad 0\alert{u}1 &\in L_G(S) \\ | |
124 u \in L_G(S) \quad \Longrightarrow \quad \alert{u}11 &\in L_G(S) | |
125 \end{align*} | |
126 | |
127 Also z.B: | |
128 | |
129 \[ | |
130 1 \in L_G(S) \Longrightarrow 0\alert{1}0 \in L_G(S) \Longrightarrow \alert{010}11 \in L_G(S) | |
131 \] | |
132 \end{example} | |
133 \end{frame} | |
134 } | |
135 | |
10
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
136 \defineUnit{eindeutigkeit}{% |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
137 \begin{frame} |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
138 \frametitle{Eindeutigkeit} |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
139 |
11
de844d67518b
fix powersets; wording
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
10
diff
changeset
|
140 \begin{definition}[kontextfreie Linksableitung] |
10
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
141 Eine Ableitung |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
142 \begin{align} |
11
de844d67518b
fix powersets; wording
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
10
diff
changeset
|
143 S \to^* \structure{x}\alert{A}z \to \structure{x}\alert{\beta}z \to^* w |
10
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
144 \end{align} |
11
de844d67518b
fix powersets; wording
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
10
diff
changeset
|
145 heißt (kontextfreie) \structure{Linksableitung}, wenn für jede Anwendung jeder Produktion $\alert{A \to \beta}$ gilt, dass in \structure{$x$} kein Nichtterminal vorkommt. |
10
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
146 \end{definition} |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
147 |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
148 \vfill |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
149 |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
150 \begin{definition}[Eindeutigkeit] |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
151 \begin{itemize} |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
152 \item Eine Grammatik heißt \structure{eindeutig}, wenn es für jedes Wort genau eine Linksableitung gibt. |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
153 \item Eine Sprache heißt \structure{eindeutig}, wenn es für sie eine eindeutige Grammatik gibt. |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
154 \end{itemize} |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
155 \end{definition} |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
156 \end{frame} |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
157 } |
e1b3b7b99d28
second notes and sheet
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
3
diff
changeset
|
158 |
1 | 159 \defineUnit{cnf}{% |
160 \begin{frame} | |
161 \frametitle{CNF} | |
162 \setbeamercovered{dynamic} | |
163 | |
164 \begin{definition}[Chomsky-Normalform] | |
16
a08f6e33cfb0
fourth sheet and notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
165 Eine kontextfreie Grammatik ist in \structure{Chomsky-Normalform} (CNF) genau dann wenn alle Produktionen die Form |
1 | 166 \[ |
167 A \rightarrow \alert{a} \quad \text{oder} \quad A \rightarrow \alert{BC} | |
168 \] | |
169 haben. | |
170 \end{definition} | |
171 | |
172 \vfill | |
173 | |
174 \begin{theorem} | |
19 | 175 Zu \alert{jeder} CFG $G$ existiert eine CFG $G'$ in Chomsky-Normalform mit |
1 | 176 \[ |
177 L(G') = L(G) \alert{\setminus \left\{ \epsilon \right\}} | |
178 \] | |
179 \end{theorem} | |
180 \end{frame} | |
181 } | |
182 | |
183 \defineUnit{cnfkonstruktion}{% | |
184 \begin{frame} | |
185 \frametitle{CNF Konstruktion} | |
186 \setbeamercovered{dynamic} | |
187 | |
16
a08f6e33cfb0
fourth sheet and notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
188 \begin{block}{CNF Konstruktion} |
1 | 189 Sei $G = (V, \Sigma, P, S)$ eine CFG. |
190 \begin{enumerate} | |
191 \item<1,2-> Eliminiere \alert{$\epsilon$-Produktionen} | |
192 \item<1,3-> Eliminiere \alert{Kettenproduktionen} | |
193 \item<1,4-> \alert{Ersetze Terminale} durch Nichtterminale | |
194 \item<1,5-> \alert{Verkürze Ketten} von Nichtterminalen der Länge $\geq 3$ | |
195 \end{enumerate} | |
196 \end{block} | |
197 | |
198 \vspace{1em} | |
199 | |
200 \only<2> { | |
201 Sind \alert{$B \rightarrow \epsilon$} und \alert{$A \rightarrow \alpha B \beta$} in $P$, dann füge \alert{$A \rightarrow \alpha \beta$} hinzu. Entferne danach alle $\epsilon$-Produktionen. | |
202 \begin{align*} | |
203 S &\rightarrow Ab, \quad A \rightarrow aAA \mid \epsilon \\ | |
204 \intertext{wird zu:} | |
205 S &\rightarrow \alert{Ab \mid b} \\ | |
206 A &\rightarrow \alert{aAA \mid aA \mid a} | |
207 \end{align*} | |
208 } | |
209 | |
210 \only<3> { | |
211 Sind \alert{$A \rightarrow B$} und \alert{$B \rightarrow \alpha$} in $P$, dann füge \alert{$A \rightarrow \alpha$} hinzu. Entferne danach alle Kettenproduktionen und unerreichbaren Symbole. | |
212 \begin{align*} | |
213 S &\rightarrow A, \quad A \rightarrow a \mid B, \quad B \rightarrow bS \\ | |
214 \intertext{wird zu:} | |
215 A &\rightarrow \alert{a \mid bS} \\ | |
216 S &\rightarrow \alert{a \mid bS} | |
217 \end{align*} | |
218 } | |
219 | |
220 \only<4> { | |
221 Ersetze jedes \alert{$a \in \Sigma$} in einer rechten Seite \alert{länger als $1$} durch ein neues Nichtterminal. | |
222 \begin{align*} | |
223 S &\rightarrow aa \mid Bb \mid b, \quad B \rightarrow \ldots \\ | |
224 \intertext{wird zu:} | |
225 S &\rightarrow \alert{X_aX_a \mid BX_b \mid b} \\ | |
226 X_a &\rightarrow \alert{a}, \quad X_b \rightarrow \alert{b} | |
227 \end{align*} | |
228 } | |
229 | |
230 \only<5> { | |
231 Ersetze jede Produktion der Form $A \rightarrow B_1B_2\ldots B_k$ durch neue Nichtterminale mit Produktionen der Länge $2$. | |
232 \begin{align*} | |
233 S &\rightarrow X_aX_bBX_a, \quad X_a \rightarrow a, \quad X_b \rightarrow b, \quad B \rightarrow \ldots \\ | |
234 \intertext{wird zu:} | |
235 S &\rightarrow \alert{X_aT_1} \\ | |
236 T_1 &\rightarrow \alert{X_bT_2}, \quad T_2 \rightarrow \alert{BX_a} \\ | |
237 \end{align*} | |
238 } | |
239 \end{frame} | |
240 } | |
241 | |
242 \defineUnit{nuetzlichessymbol}{% | |
243 \begin{frame} | |
244 \frametitle{Eigenschaften von Symbolen} | |
245 \setbeamercovered{dynamic} | |
246 | |
247 \begin{definition} | |
248 Sei $G = (V, \Sigma, P, S)$ eine CFG. \\ | |
249 Ein Symbol $X \in V \cup \Sigma$ ist | |
250 \begin{description} | |
251 \item[nützlich] es gibt $S \rightarrow_G^* w \in \Sigma^*$ in der X \alert{vorkommt} | |
252 \item[erzeugend] es gibt $\alert{X} \rightarrow_G^* w \in \Sigma^*$ | |
253 \item[erreichbar] es gibt $S \rightarrow_G^* \alpha \alert{X} \beta$ | |
254 \end{description} | |
255 \end{definition} | |
256 | |
257 \vfill | |
258 | |
259 \begin{theorem} | |
260 Nützliche Symbole \alert{sind} erzeugend und erreichbar. Aber \alert{nicht} notwendigerweise umgekehrt. | |
261 \[ | |
262 S \rightarrow AB \mid a, \quad A \rightarrow b | |
263 \] | |
264 \end{theorem} | |
265 \end{frame} | |
266 } | |
267 | |
268 \defineUnit{cfpl}{% | |
269 \begin{frame} | |
270 \frametitle{Pumping Lemma für CFLs} | |
271 \setbeamercovered{dynamic} | |
272 | |
273 \begin{theorem}[Pumping Lemma für kontextfreie Sprachen] | |
16
a08f6e33cfb0
fourth sheet and notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
274 Sei $L \subseteq \Sigma^*$ kontextfrei.\\ |
a08f6e33cfb0
fourth sheet and notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
275 Dann gibt es ein $n > 0$, so dass sich \alert{jedes} $z \in L$ mit $|z| \geq n$ so in \alert{$z = uvwxy$} zerlegen lässt, dass |
1 | 276 \begin{itemize} |
277 \item $vx \alert{\neq \epsilon}$ | |
278 \item $|vwx| \alert{\leq n}$ | |
279 \item $\forall i \alert{\geq 0}. uv^iwx^iy \in L$ | |
280 \end{itemize} | |
281 \end{theorem} | |
282 | |
283 \vfill | |
284 | |
17
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
285 \vspace{1.5em} |
1 | 286 \begin{center} |
287 \begin{columns} | |
288 \begin{column}{.4\textwidth} | |
289 \begin{tikzpicture} | |
290 \coordinate (outer) at (2, 2.4); | |
291 \coordinate (middle) at (2.2, 1.2); | |
292 \coordinate (inner) at (2.2, 0.6); | |
293 % outer | |
294 \draw[fill=tumred!40] (0, 0) -- (1.2, 0) -- (middle) -- (3.2, 0) -- (4, 0) -- (outer) node[above] {$S$} -- (0, 0); | |
295 % middle | |
296 \draw[fill=tumgreen!40] (1.2, 0) -- (1.7, 0) -- (inner) -- (2.7, 0) -- (3.2, 0) -- (middle) -- (1.2, 0); | |
297 % inner | |
298 \draw[fill=tumblue!40] (1.7, 0) -- (inner) -- (2.7, 0) -- (1.7, 0); | |
299 | |
300 % path | |
301 \draw[dashed, thick] (outer) -- (middle) -- (inner); | |
302 \draw[fill] (outer) circle (1pt); | |
303 \draw[fill] (middle) circle (1pt); | |
304 \draw[fill] (inner) circle (1pt); | |
305 | |
306 % nodes | |
307 \node[below] at (0.6, 0) {$u$}; | |
308 \node[below] at (1.45, 0) {$v$}; | |
309 \node[below] at (2.2, 0) {$w$}; | |
310 \node[below] at (2.95, 0) {$x$}; | |
311 \node[below] at (3.6, 0) {$y$}; | |
17
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
312 |
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
313 \node[right] at (middle) {$A$}; |
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
314 \node[right] at (inner) {$A$}; |
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
315 |
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
316 \node at (2, 3.4) {$S \to^* uAy \to^* uvAxy \to^* uvwxy$}; |
1 | 317 \end{tikzpicture} |
318 \end{column} | |
319 \begin{column}{.4\textwidth} | |
320 \begin{tikzpicture} | |
321 \coordinate (outer) at (2, 2.4); | |
322 \coordinate (middle) at (2.2, 1.2); | |
323 \coordinate (inner) at (2.2, 0.6); | |
324 % outer | |
325 \draw[fill=tumred!40] (0, 0) -- (1.2, 0) -- (middle) -- (3.2, 0) -- (4, 0) -- (outer) node[above] {$S$} -- (0, 0); | |
326 % inner | |
327 \draw[fill=tumblue!40] (1.7, 0.6) -- (middle) -- (2.7, 0.6) -- (1.7, 0.6); | |
328 | |
329 % path | |
330 \draw[dashed, thick] (outer) -- (middle); | |
331 \draw[fill] (outer) circle (1pt); | |
332 \draw[fill] (middle) circle (1pt); | |
333 | |
334 % nodes | |
335 \node[below] at (0.6, 0) {$u$}; | |
336 \node[below] at (2.2, 0) {$w$}; | |
337 \node[below] at (3.6, 0) {$y$}; | |
17
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
338 |
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
339 \node[right] at (middle) {$A$}; |
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
340 |
0f7daeda8363
wording; add explicit productions to cf-pumping lemma
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
16
diff
changeset
|
341 \node at (2, 3.4) {$S \to^* uAy \to^* uwy$}; |
1 | 342 \end{tikzpicture} |
343 \end{column} | |
344 \end{columns} | |
345 \end{center} | |
346 \end{frame} | |
347 } | |
348 | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
349 \defineUnit{ogden}{% |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
350 \begin{frame} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
351 \frametitle{Ogden Lemma für kontextfreie Sprachen} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
352 \setbeamercovered{dynamic} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
353 |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
354 \begin{theorem}[Ogden Lemma für kontextfreie Sprachen] |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
355 Sei $L \subseteq \Sigma^*$ kontextfrei.\\ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
356 Dann gibt es ein $n > 0$, so dass für \alert{jedes} $z \in L$ mit $|z| \geq n$ gilt:\\ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
357 Für \alert{jede} Markierung $M$ von \alert{mindestens $n$} Buchstaben in $z$ gibt es eine Zerlegung $z = uvwxy$ mit |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
358 \begin{itemize} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
359 \item $|vx|_M \alert{\geq 1}$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
360 \item $|vwx|_M \alert{\leq n}$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
361 \item $\forall i \alert{\geq 0}. uv^iwx^iy \in L$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
362 \end{itemize} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
363 \end{theorem} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
364 |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
365 \hfill |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
366 |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
367 \begin{example}[Markierung] |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
368 Sei $w = abaabaaa$ ein Wort. Dann ist |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
369 \begin{align} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
370 w = a\structure{ba}a\structure{b}aaa |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
371 \end{align} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
372 eine Markierung mit $|w|_M = 3$. |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
373 \end{example} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
374 \end{frame} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
375 } |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
376 |
1 | 377 \defineUnit{cyk}{% |
378 \begin{frame} | |
379 \frametitle{CYK} | |
380 \setbeamercovered{dynamic} | |
381 | |
382 \begin{definition}[Cocke-Younger-Kasami-Algorithmus] | |
16
a08f6e33cfb0
fourth sheet and notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
383 Der \structure{CYK-Algorithmus} entscheidet das Wortproblem für kontextfreie Grammatiken in Chomsky-Normalform in $\Oh(n^3)$. \\ |
1 | 384 Gegeben eine \alert{Grammatik} $G = (V, \Sigma, P, S)$ in CNF und ein \alert{Wort} $w = a_1 \ldots a_n \in \Sigma^*$. |
385 Mit \[ V_{ij} := \left\{ A \in V \mid A \rightarrow_G^* \alert{a_i \ldots a_j} \right\}\] | |
386 ist \[ w \in L(G) \Leftrightarrow S \in V_{\alert{1n}} \] | |
387 \end{definition} | |
388 | |
389 \begin{align*} | |
390 V_{ii} &= \left\{ A \in V \mid (A \rightarrow a_i) \in P \right\} \\ | |
391 V_{ij} &= \left\{ A \in V \mid \exists k, B \in V_{ik}, C \in V_{k+1,j} \;.\; (A \rightarrow BC) \in P \right\} | |
392 \end{align*} | |
19 | 393 \end{frame} |
1 | 394 } |
395 | |
396 \defineUnit{cykbeispiel}{% | |
397 \begin{frame} | |
398 \frametitle{CYK} | |
399 \setbeamercovered{dynamic} | |
400 | |
16
a08f6e33cfb0
fourth sheet and notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
401 \begin{block}{CYK-Algorithmus} |
1 | 402 Kombiniere \alert{Teilwörter} zum ganzen Wort, wenn möglich. |
403 \begin{enumerate} | |
404 \item Initialisiere mit den \alert{$V_{ii}$}. | |
405 \item<3-5> Befülle die Tabelle von unten nach oben. | |
406 \end{enumerate} | |
407 \end{block} | |
408 | |
409 \[ S \rightarrow AB \mid BC, \quad A \rightarrow BA \mid a, \quad B \rightarrow CC \mid b, \quad C \rightarrow AB \mid a \] | |
16
a08f6e33cfb0
fourth sheet and notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
410 \vspace{2em} |
1 | 411 \begin{center} |
412 \extrarowsep=5pt | |
413 \begin{tabu}to .8\textwidth{r|X[c]|X[c]|X[c]|X[c]|} | |
414 \tabucline{2-2} | |
415 4 & \alt<-4>{}{$S,\ldots$} \\ \tabucline{2-3} | |
416 3 & \alt<-3>{}{$\emptyset$} & \alt<-3>{}{$S, A, C$} \\ \tabucline{2-4} | |
20 | 417 2 & \alt<-2>{}{$A,S$} & \alt<-2>{}{$B$} & \alt<-2>{}{$B$} \\ \tabucline{2-5} |
1 | 418 1 & \alt<-1>{}{$B$} & \alt<1>{}{$A,C$} & \alt<1>{}{$A,C$} & \alt<1>{}{$A,C$} \\ \tabucline{2-5} |
419 \multicolumn{1}{r}{} & \multicolumn{1}{c}{\alert{b}} & \multicolumn{1}{c}{\alert{a}} & \multicolumn{1}{c}{\alert{a}} & \multicolumn{1}{c}{\alert{a}} \\ | |
420 \end{tabu} | |
421 \end{center} | |
422 \end{frame} | |
423 } | |
424 | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
425 \defineUnit{greibach}{% |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
426 \begin{frame} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
427 \frametitle{Greibach Normalform} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
428 |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
429 Stuff. |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
430 \end{frame} |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
431 } |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
432 |
1 | 433 \defineUnit{pda}{% |
434 \begin{frame} | |
435 \frametitle{Kellerautomaten} | |
436 \setbeamercovered{dynamic} | |
437 | |
438 \begin{definition}[Kellerautomat] | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
439 Ein \structure{PDA} (Push-Down-Automaton) ist ein Tupel $P = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)$ aus einer/einem |
1 | 440 \begin{itemize} |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
441 \item endlichen Menge von \structure{Zuständen} $Q$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
442 \item endlichen \structure{Eingabealphabet} $\Sigma$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
443 \item endlichen \structure{Kelleralphabet} $\Gamma$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
444 \item \structure{Übergangsfunktion} $\delta : Q \times \left( \Sigma \cup \{\epsilon\} \right) \times \Gamma \to P(Q \times \Gamma^*)$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
445 \item \structure{Startzustand} $q_0 \in Q$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
446 \item \structure{Kellerinitialisierung} $Z_0 \in \Gamma$ |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
447 \item Menge von \structure{Endzuständen} $F \subseteq Q$ |
1 | 448 \end{itemize} |
449 \end{definition} | |
450 | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
451 \vfill |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
452 |
1 | 453 \begin{center} |
454 \begin{tikzpicture}[automaton, node distance=4cm] | |
455 \node[state] (q0) {$q_i$}; | |
456 \node[state] (q1) [right of = q0] {$q_j$}; | |
457 | |
458 \draw[every edge] (q0) edge node {$a, X/\gamma$} (q1); | |
459 \end{tikzpicture} | |
460 \end{center} | |
461 \end{frame} | |
462 } | |
463 | |
464 \defineUnit{pdaakzeptanz}{% | |
465 \begin{frame} | |
466 \frametitle{Kellerautomaten} | |
467 \setbeamercovered{dynamic} | |
468 | |
469 \begin{definition}[Kellerautomat] | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
470 Ein \structure{PDA} (Push-Down-Automaton) ist ein Tupel $P = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)$ aus einer/einem |
1 | 471 \begin{itemize} |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
472 \item \structure{Übergangsfunktion} $\delta : Q \times \left( \Sigma \cup \{\epsilon\} \right) \times \Gamma \to P(Q \times \Gamma^*)$ |
1 | 473 \end{itemize} |
474 \end{definition} | |
475 | |
476 \vfill | |
477 | |
478 \begin{definition}[Akzeptanz] | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
479 Ein PDA $P$ akzeptiert $w \in \Sigma^*$ \structure{mit Endzustand} gdw |
1 | 480 \[ \exists \alert{f \in F}, \gamma \in \Gamma^*.(q_0, w, Z_0) \rightarrow_P^* (\alert{f}, \epsilon, \gamma) \] |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
481 Ein PDA $P$ akzeptiert $w \in \Sigma^*$ \structure{mit leerem Keller} gdw |
1 | 482 \[ \exists q \in Q.(q_0, w, Z_0) \rightarrow_P^* (q, \epsilon, \alert{\epsilon}) \] |
483 \end{definition} | |
484 \end{frame} | |
485 } | |
486 | |
487 \defineUnit{pdabeispiel}{% | |
488 \begin{frame} | |
489 \frametitle{Kellerautomaten} | |
490 \setbeamercovered{dynamic} | |
491 | |
492 \begin{definition}[Kellerautomat] | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
493 Ein \structure{PDA} (Push-Down-Automaton) ist ein Tupel $P = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)$ aus einer/einem |
1 | 494 \begin{itemize} |
495 | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
496 \item \structure{Übergangsfunktion} $\delta : Q \times \left( \Sigma \cup \{\epsilon\} \right) \times \Gamma \to P(Q \times \Gamma^*)$ |
1 | 497 \end{itemize} |
498 \end{definition} | |
499 | |
500 \vfill | |
501 | |
502 \begin{example}[] | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
503 PDA akzeptierend \alert{mit leerem Keller} zu $L = \left\{ a^nb^n \mid n \in \N_0 \right\}$. |
1 | 504 |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
505 \bigskip |
1 | 506 \centering |
507 \begin{tikzpicture}[automaton] | |
508 | |
509 \node[state, initial] (q0) {$q_0$}; | |
510 \node[state] (q1) [right of = q0] {$q_1$}; | |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
511 \node[state] (q2) [right of = q1] {$q_2$}; |
1 | 512 |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
513 \draw[->] (q0) edge [loop above] node {$\epsilon, Z_0/\epsilon$}; |
1 | 514 |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
515 \draw[->] (q0) edge node {$a, Z_0/AZ_0$} (q1); |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
516 \draw[->] (q1) edge node {$\epsilon, A/A$} (q2); |
1 | 517 |
18
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
518 \draw[->] (q1) edge [loop above] node {$a, */A*$} (q1); |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
519 |
1359f5a6aa60
first half of fifth notes
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
17
diff
changeset
|
520 \draw[->] (q2) edge [loop above] node {$b, */\epsilon$} (q2); |
1 | 521 \end{tikzpicture} |
522 \end{example} | |
523 \end{frame} | |
524 } | |
525 | |
526 \defineUnit{kontextfreiesprachen}{% | |
527 \begin{frame} | |
528 \frametitle{Kontextfreie Sprachen} | |
529 \setbeamercovered{dynamic} | |
530 | |
531 \begin{center} | |
532 \begin{tikzpicture}[node distance=3cm] | |
533 \node (CFG) {CFG}; | |
534 \node (CNF) [right of = CFG] {CNF}; | |
535 \node (PDAe) [right of = CNF] {PDA$_\epsilon$}; | |
536 \node (PDAf) [right of = PDAe] {PDA$_F$}; | |
537 | |
538 \draw [every edge, <->] (CFG) -- (CNF); | |
539 \draw [every edge, <->] (CNF) -- (PDAe); | |
540 \draw [every edge, <->] (PDAe) -- (PDAf); | |
541 \end{tikzpicture} | |
542 \end{center} | |
543 | |
544 \vfill | |
545 | |
546 \begin{itemize} | |
547 \item \alert{Abschlusseigenschaften} | |
548 \end{itemize} | |
549 \begin{table} | |
550 \begin{tabu}to \textwidth{X[c]|ccccc} | |
551 & Schnitt & Vereinigung & Komplement & Produkt & Stern \\ \tabucline{} | |
552 REG & ja & ja & ja & ja & ja\\ | |
19 | 553 CFL & nein & ja & nein & ja & ja |
1 | 554 \end{tabu} |
555 \end{table} | |
556 | |
557 \begin{itemize} | |
558 \item \alert{Entscheidbarkeit} | |
559 \end{itemize} | |
560 \begin{table} | |
561 \begin{tabu}to \textwidth{X[c]|cccc} | |
562 & Wortproblem & Leerheit & Äquivalenz & Schnittproblem\\ \tabucline{} | |
563 DFA & $\Oh(n)$ & ja & ja & ja \\ | |
564 CFG & $\Oh(n^3)$ & ja & nein & nein | |
565 \end{tabu} | |
566 \end{table} | |
567 \end{frame} | |
568 } |