-
Notifications
You must be signed in to change notification settings - Fork 0
/
lec12.tex
121 lines (103 loc) · 3.65 KB
/
lec12.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
\section{Context-free Languages}
\label{sec:context-free_lang}
% ==================================================
Let
\[
R = \set{ \varphi(E) \mid \text{$E$ is a regular expression over $\set{0,1}$} }
\]
where
\[
E \in \set{0,1,(,),\varnothing,*,+,\cdot}^*,
\]
such that
$\varphi(E)$ maps each symbol in $E$ to a binary string.
Is $R$, then, a regular language?
\begin{proof}
To prove that $R$ is not regular, we need to find a nonregular language $L$ so
$
L \reducable R
.$
Let
\[
L = \set{ 0^n 1^n \mid n \ge 0}
,\]
build the FST that translates from $L$ to $E$,
\centgraph[6cm]{mp/fst-2}
The FST translates all the 0's at the left hand side to 010 which is the ``$($'' symbol and
all but the first the 1's at the right hand side to 011 which is the ``$)$'' symbol.
The first 1 is translated to $100\,011$ which is two symbols ``$\varnothing)$''.
In summary the FST translates all strings in $L$ to $((\cdots(\varnothing)\cdots))$,
which certainly is a regular expression.
Thus proved that $R$ can be nonregular.
\end{proof}
\begin{example}[Is a regex regular?]
$
\forall \varphi(E) \in R,
$
is $L(E)$ regular?
Yes. This question differs from the earlier one since the earlier question was about
$R$, the set of \emph{all} regexes. Language of every regex is a regular language, yet
that of the set of all regexes is not.
\end{example}
Clearly, a regex cannot express the language
\[
L = \set{ 0^n 1^n \mid n \ge 0 }
,\]
thus we need a more powerful method of describing languages.
\subsection{Context-Free Grammars}
% --------------------------------------------------
Context-free grammars is a method of describing languages which, particularly, can
describe certain features that have a recursive structure.
\begin{example}[A context-free grammar]
\label{exa:context-free_grammar:G_L}
Below is an example of context-free grammar that describes
\[
L = \set{ 0^n 1^n \mid n \ge 0 }
\]
in \autoref{sec:context-free_lang}, which we call $G_L$,
\begin{align*}
G_L \colon & S \mapsto \varepsilon \\
& S \mapsto 0S1
.\end{align*}
The two \emph{rules} means that the \emph{variable} $S$ generates either an empty
string ($\varepsilon$) or a string $0S1$.
\end{example}
\begin{example}[How $G_L$ describes $L$]
Consider the grammar $G_L$ given in \autoref{exa:context-free_grammar:G_L},
how exactly does it describe language $L$?
For example, how does $S$ generate string $0011 \in L$?
\[
S \mapsto 0S1 \mapsto 00S11 \mapsto 00\varepsilon11 = 0011 \in L
\]
As the above example, $00S11$ can be further expanded to more 0's and 1's, while the
number of 0's and 1's are always equal and the sequence of 0's and 1's won't mess up.
In other words,
a string $0^n 1^n$ can be generated by $S$ via
expanding $S$ to $0S1$ $n$ times, which generates $0^n S 1^n$, and expand $S$ to
$\varepsilon$ at last leaving the string $0^n \varepsilon 1^n = 0^n 1^n$.
\end{example}
\[
L(G) = \set{ w \mid S \mapsto \cdots \mapsto w \in \Sigma^* }
\]
% \begin{align*}
% G_R \colon &S \mapsto \varnothing \\
% &S \mapsto 0 \\
% &S \mapsto 1 \\
% &S \mapsto (S) \\
% &S \mapsto S \cdot S \\
% &S \mapsto S + S \\
% &S \mapsto S^*
% \end{align*}
%
% With string ``$0+0\cdot0$,'' the expression can be treated as
% %%% tree
% but also
% %%% tree
% Thus we would like to adopt a set of grammar so the
%
% \begin{align*}
% S \mapsto T \mid T + S \\
% T \mapsto F \mid F \cdot T \\
% F \mapsto F^* \mid 0 \mid 1 \mid (S) \mid \varnothing
% \end{align*}
%