20
|
1 |
\documentclass{article}
|
|
2 |
\usepackage{charter}
|
|
3 |
\usepackage{hyperref}
|
|
4 |
\usepackage{amssymb}
|
|
5 |
\usepackage{amsmath}
|
|
6 |
|
|
7 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
|
|
8 |
\begin{document}
|
|
9 |
|
|
10 |
\section*{Proof}
|
|
11 |
|
|
12 |
Recall the definitions for regular expressions and the language associated with a regular expression:
|
|
13 |
|
|
14 |
\begin{center}
|
|
15 |
\begin{tabular}{c}
|
|
16 |
\begin{tabular}[t]{rcl}
|
|
17 |
$r$ & $::=$ & $\varnothing$ \\
|
|
18 |
& $\mid$ & $\epsilon$ \\
|
|
19 |
& $\mid$ & $c$ \\
|
|
20 |
& $\mid$ & $r_1 \cdot r_2$ \\
|
|
21 |
& $\mid$ & $r_1 + r_2$ \\
|
|
22 |
& $\mid$ & $r^*$ \\
|
|
23 |
\end{tabular}\hspace{10mm}
|
|
24 |
\begin{tabular}[t]{r@{\hspace{1mm}}c@{\hspace{1mm}}l}
|
|
25 |
$L(\varnothing)$ & $\dn$ & $\varnothing$ \\
|
|
26 |
$L(\epsilon)$ & $\dn$ & $\{\texttt{""}\}$ \\
|
|
27 |
$L(c)$ & $\dn$ & $\{\texttt{"}c\texttt{"}\}$ \\
|
|
28 |
$L(r_1 \cdot r_2)$ & $\dn$ & $L(r_1) \,@\, L(r_2)$ \\
|
|
29 |
$L(r_1 + r_2)$ & $\dn$ & $L(r_1) \cup L(r_2)$ \\
|
|
30 |
$L(r^*)$ & $\dn$ & $\bigcup_{n\ge 0} L(r)^n$ \\
|
|
31 |
\end{tabular}
|
|
32 |
\end{tabular}
|
|
33 |
\end{center}
|
|
34 |
|
|
35 |
\noindent
|
|
36 |
We also defined the notion of a derivative of a regular expression (the derivative with respect to a character):
|
|
37 |
|
|
38 |
\begin{center}
|
|
39 |
\begin{tabular}{lcl}
|
|
40 |
$der\, c\, (\varnothing)$ & $\dn$ & $\varnothing$ \\
|
|
41 |
$der\, c\, (\epsilon)$ & $\dn$ & $\varnothing$ \\
|
|
42 |
$der\, c\, (d)$ & $\dn$ & if $c = d$ then $\epsilon$ else $\varnothing$\\
|
|
43 |
$der\, c\, (r_1 + r_2)$ & $\dn$ & $(der\, c\, r_1) + (der\, c\, r_2)$ \\
|
|
44 |
$der\, c\, (r_1 \cdot r_2)$ & $\dn$ & if $nullable(r_1)$\\
|
|
45 |
& & then $((der\, c\, r_1) \cdot r_2) + (der\, c\, r_2)$\\
|
|
46 |
& & else $(der\, c\, r_1) \cdot r_2$\\
|
|
47 |
$der\, c\, (r^*)$ & $\dn$ & $(der\, c\, r) \cdot (r^*)$\\
|
|
48 |
\end{tabular}
|
|
49 |
\end{center}
|
|
50 |
|
|
51 |
\noindent
|
|
52 |
With our definition of regular expressions comes an induction principle. Given a property $P$ over
|
|
53 |
regular expressions. We can establish that $\forall r.\; P(r)$ holds, provided we can show the following:
|
|
54 |
|
|
55 |
\begin{enumerate}
|
|
56 |
\item $P(\varnothing)$, $P(\epsilon)$ and $P(c)$ all hold,
|
|
57 |
\item $P(r_1 + r_2)$ holds under the induction hypotheses that
|
|
58 |
$P(r_1)$ and $P(r_2)$ hold,
|
|
59 |
\item $P(r_1 \cdot r_2)$ holds under the induction hypotheses that
|
|
60 |
$P(r_1)$ and $P(r_2)$ hold, and
|
|
61 |
\item $P(r^*)$ holds under the induction hypothesis that $P(r)$ holds.
|
|
62 |
\end{enumerate}
|
|
63 |
|
|
64 |
\noindent
|
|
65 |
Let us try out an induction proof. Recall the definition
|
|
66 |
|
|
67 |
\begin{center}
|
|
68 |
$Der\, c\, A \dn \{ s\;\mid\; c\!::\!s \in A\}$
|
|
69 |
\end{center}
|
|
70 |
|
|
71 |
\noindent
|
|
72 |
whereby $A$ is a set of strings. We like to prove
|
|
73 |
|
|
74 |
\begin{center}
|
|
75 |
\begin{tabular}{l}
|
|
76 |
$P(r) \dn $ \hspace{4mm} $L(der\,c\,r) = Der\,c\,(L(r))$
|
|
77 |
\end{tabular}
|
|
78 |
\end{center}
|
|
79 |
|
|
80 |
\noindent
|
|
81 |
by induction over the regular expression $r$.
|
|
82 |
|
|
83 |
|
|
84 |
\newpage
|
|
85 |
\noindent
|
|
86 |
{\bf Proof}
|
|
87 |
|
|
88 |
\noindent
|
|
89 |
According to 1.~above we need to prove $P(\varnothing)$, $P(\epsilon)$ and $P(d)$. Lets do this in turn.
|
|
90 |
|
|
91 |
\begin{itemize}
|
|
92 |
\item First Case: $P(\varnothing)$ is $L(der\,c\,\varnothing) = Der\,c\,(L(\varnothing))$ (a). We have $der\,c\,\varnothing = \varnothing$
|
|
93 |
and $L(\varnothing) = \varnothing$. We also have $Der\,c\,\varnothing = \varnothing$. Hence we have $\varnothing = \varnothing$ in (a).
|
|
94 |
|
|
95 |
\item Second Case: $P(\epsilon)$ is $L(der\,c\,\epsilon) = Der\,c\,(L(\epsilon))$ (b). We have $der\,c\,\epsilon = \varnothing$,
|
|
96 |
$L(\varnothing) = \varnothing$ and $L(\epsilon) = \{\texttt{""}\}$. We also have $Der\,c\,\{\texttt{""}\} = \varnothing$. Hence we have
|
|
97 |
$\varnothing = \varnothing$ in (b).
|
|
98 |
|
|
99 |
\item Third Case: $P(d)$ is $L(der\,c\,d) = Der\,c\,(L(d))$ (c). We need to treat the cases $d = c$ and $d \not= c$.
|
|
100 |
|
|
101 |
$d = c$: We have $der\,c\,c = \epsilon$ and $L(\epsilon) = \{\texttt{""}\}$.
|
|
102 |
We also have $L(c) = \{\texttt{"}c\texttt{"}\}$ and $Der\,c\,\{\texttt{"}c\texttt{"}\} = \{\texttt{""}\}$. Hence we have
|
|
103 |
$\{\texttt{""}\} = \{\texttt{""}\}$ in (c).
|
|
104 |
|
|
105 |
$d \not=c$: We have $der\,c\,d = \varnothing$.
|
|
106 |
We also have $Der\,c\,\{\texttt{"}d\texttt{"}\} = \varnothing$. Hence we have
|
|
107 |
$\varnothing = \varnothing$ in (c).
|
|
108 |
|
|
109 |
\item Fourth Case: $P(r_1 + r_2)$ is $L(der\,c\,(r_1 + r_2)) = Der\,c\,(L(r_1 + r_2))$ (d). This is what we have to show.
|
|
110 |
We can assume already:
|
|
111 |
|
|
112 |
\begin{center}
|
|
113 |
\begin{tabular}{ll}
|
|
114 |
$P(r_1)$: & $L(der\,c\,r_1) = Der\,c\,(L(r_1))$ (I)\\
|
|
115 |
$P(r_2)$: & $L(der\,c\,r_2) = Der\,c\,(L(r_2))$ (II)
|
|
116 |
\end{tabular}
|
|
117 |
\end{center}
|
|
118 |
|
|
119 |
We have that $der\,c\,(r_1 + r_2) = (der\,c\,r_1) + (der\,c\,r_2)$ and also $L((der\,c\,r_1) + (der\,c\,r_2)) = L(der\,c\,r_1) \cup L(der\,c\,r_2)$.
|
|
120 |
By (I) and (II) we know that the left-hand side is $Der\,c\,(L(r_1)) \cup Der\,c\,(L(r_2))$. You need to ponder a bit, but you should see
|
|
121 |
that
|
|
122 |
|
|
123 |
\begin{center}
|
|
124 |
$Der\,c(A \cup B) = (Der\,c\,A) \cup (Der\,c\,B)$
|
|
125 |
\end{center}
|
|
126 |
|
|
127 |
holds for every set of strings $A$ and $B$. That means the right-hand side of (d) is also $Der\,c\,(L(r_1)) \cup Der\,c\,(L(r_2))$,
|
|
128 |
because $L(r_1 + r_2) = L(r_1) \cup L(r_2)$. And we are done with the fourth case.
|
|
129 |
|
21
|
130 |
\item Fifth Case: $P(r_1 \cdot r_2)$ is $L(der\,c\,(r_1 \cdot r_2)) = Der\,c\,(L(r_1 \cdot r_2))$ (e). We can assume already:
|
|
131 |
|
|
132 |
\begin{center}
|
|
133 |
\begin{tabular}{ll}
|
|
134 |
$P(r_1)$: & $L(der\,c\,r_1) = Der\,c\,(L(r_1))$ (I)\\
|
|
135 |
$P(r_2)$: & $L(der\,c\,r_2) = Der\,c\,(L(r_2))$ (II)
|
|
136 |
\end{tabular}
|
|
137 |
\end{center}
|
|
138 |
|
|
139 |
Let us first consider the case where $nullable(r_1)$ holds. Then
|
|
140 |
|
|
141 |
\[
|
|
142 |
der\,c\,(r_1 \cdot r_2) = ((der\,c\,r_1) \cdot r_2) + (der\,c\,r_2).
|
|
143 |
\]
|
|
144 |
|
|
145 |
The corresponding language of the right-hand side is
|
|
146 |
|
|
147 |
\[
|
|
148 |
(L(der\,c\,r_1) \,@\, L(r_2)) \cup L(der\,c\,r_2).
|
|
149 |
\]
|
|
150 |
|
|
151 |
By the induction hypotheses (I) and (II), this is equal to
|
|
152 |
|
|
153 |
\[
|
|
154 |
(Der\,c\,(L(r_1)) \,@\, L(r_2)) \cup (Der\,c\,(L(r_2)).\;\;(**)
|
|
155 |
\]
|
|
156 |
|
|
157 |
We also know that $L(r_1 \cdot r_2) = L(r_1) \,@\,L(r_2)$. We have to know what
|
|
158 |
$Der\,c\,(L(r_1) \,@\,L(r_2))$ is.
|
|
159 |
|
|
160 |
Let us analyse what
|
|
161 |
$Der\,c\,(A \,@\, B)$ is for arbitrary sets of strings $A$ and $B$. If $A$ does \emph{not}
|
|
162 |
contain the empty string, then every string in $A\,@\,B$ is of the form $s_1 \,@\, s_2$ where
|
|
163 |
$s_1 \in A$ and $s_2 \in B$. So if $s_1$ starts with $c$ then we just have to remove it. Consequently,
|
|
164 |
$Der\,c\,(A \,@\, B) = (Der\,c\,(A)) \,@\, B$. This case does not apply here though, because we already
|
|
165 |
proved that if $r_1$ is nullable, then $L(r_1)$ contains the empty string. In this case, every string
|
|
166 |
in $A\,@\,B$ is either of the form $s_1 \,@\, s_2$, with $s_1 \in A$ and $s_2 \in B$, or
|
|
167 |
$s_3$ with $s_3 \in B$. This means $Der\,c\,(A \,@\, B) = ((Der\,c\,(A)) \,@\, B) \cup Der\,c\,B$.
|
|
168 |
But this proves that (**) is $Der\,c\,(L(r_1) \,@\, L(r_2))$.
|
|
169 |
|
|
170 |
Similarly in the case where $r_1$ is \emph{not} nullable.
|
20
|
171 |
|
|
172 |
\item Sixth Case:
|
|
173 |
\end{itemize}
|
|
174 |
|
|
175 |
\end{document}
|
|
176 |
|
|
177 |
%%% Local Variables:
|
|
178 |
%%% mode: latex
|
|
179 |
%%% TeX-master: t
|
|
180 |
%%% End:
|