24 pow ("_\<^bsup>_\<^esup>" [100, 100] 100) and |
24 pow ("_\<^bsup>_\<^esup>" [100, 100] 100) and |
25 Suc ("_+1" [100] 100) and |
25 Suc ("_+1" [100] 100) and |
26 quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and |
26 quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and |
27 REL ("\<approx>") and |
27 REL ("\<approx>") and |
28 UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and |
28 UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and |
29 L ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and |
29 L_rexp ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and |
30 Lam ("\<lambda>'(_')" [100] 100) and |
30 Lam ("\<lambda>'(_')" [100] 100) and |
31 Trn ("'(_, _')" [100, 100] 100) and |
31 Trn ("'(_, _')" [100, 100] 100) and |
32 EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and |
32 EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and |
33 transition ("_ \<^raw:\ensuremath{\stackrel{\text{>_\<^raw:}}{\Longmapsto}}> _" [100, 100, 100] 100) and |
33 transition ("_ \<^raw:\ensuremath{\stackrel{\text{>_\<^raw:}}{\Longmapsto}}> _" [100, 100, 100] 100) and |
34 Setalt ("\<^raw:\ensuremath{\bigplus}>_" [1000] 999) and |
34 Setalt ("\<^raw:\ensuremath{\bigplus}>_" [1000] 999) and |
39 tag_str_ALT ("tag\<^isub>A\<^isub>L\<^isub>T _ _ _" [100, 100, 100] 100) and |
39 tag_str_ALT ("tag\<^isub>A\<^isub>L\<^isub>T _ _ _" [100, 100, 100] 100) and |
40 tag_str_SEQ ("tag\<^isub>S\<^isub>E\<^isub>Q _ _" [100, 100] 100) and |
40 tag_str_SEQ ("tag\<^isub>S\<^isub>E\<^isub>Q _ _" [100, 100] 100) and |
41 tag_str_SEQ ("tag\<^isub>S\<^isub>E\<^isub>Q _ _ _" [100, 100, 100] 100) and |
41 tag_str_SEQ ("tag\<^isub>S\<^isub>E\<^isub>Q _ _ _" [100, 100, 100] 100) and |
42 tag_str_STAR ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _" [100] 100) and |
42 tag_str_STAR ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _" [100] 100) and |
43 tag_str_STAR ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _ _" [100, 100] 100) |
43 tag_str_STAR ("tag\<^isub>S\<^isub>T\<^isub>A\<^isub>R _ _" [100, 100] 100) |
|
44 |
44 lemma meta_eq_app: |
45 lemma meta_eq_app: |
45 shows "f \<equiv> \<lambda>x. g x \<Longrightarrow> f x \<equiv> g x" |
46 shows "f \<equiv> \<lambda>x. g x \<Longrightarrow> f x \<equiv> g x" |
46 by auto |
47 by auto |
47 |
48 |
|
49 (* THEOREMS *) |
|
50 |
|
51 notation (Rule output) |
|
52 "==>" ("\<^raw:\mbox{}\inferrule{\mbox{>_\<^raw:}}>\<^raw:{\mbox{>_\<^raw:}}>") |
|
53 |
|
54 syntax (Rule output) |
|
55 "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop" |
|
56 ("\<^raw:\mbox{}\inferrule{>_\<^raw:}>\<^raw:{\mbox{>_\<^raw:}}>") |
|
57 |
|
58 "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" |
|
59 ("\<^raw:\mbox{>_\<^raw:}\\>/ _") |
|
60 |
|
61 "_asm" :: "prop \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}>") |
|
62 |
|
63 notation (Axiom output) |
|
64 "Trueprop" ("\<^raw:\mbox{}\inferrule{\mbox{}}{\mbox{>_\<^raw:}}>") |
|
65 |
|
66 notation (IfThen output) |
|
67 "==>" ("\<^raw:{\normalsize{}>If\<^raw:\,}> _/ \<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
68 syntax (IfThen output) |
|
69 "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop" |
|
70 ("\<^raw:{\normalsize{}>If\<^raw:\,}> _ /\<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
71 "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}> /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _") |
|
72 "_asm" :: "prop \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}>") |
|
73 |
|
74 notation (IfThenNoBox output) |
|
75 "==>" ("\<^raw:{\normalsize{}>If\<^raw:\,}> _/ \<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
76 syntax (IfThenNoBox output) |
|
77 "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop" |
|
78 ("\<^raw:{\normalsize{}>If\<^raw:\,}> _ /\<^raw:{\normalsize \,>then\<^raw:\,}>/ _.") |
|
79 "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("_ /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _") |
|
80 "_asm" :: "prop \<Rightarrow> asms" ("_") |
|
81 |
|
82 |
48 (*>*) |
83 (*>*) |
49 |
84 |
50 |
85 |
51 section {* Introduction *} |
86 section {* Introduction *} |
52 |
87 |
53 text {* |
88 text {* |
|
89 \noindent |
54 Regular languages are an important and well-understood subject in Computer |
90 Regular languages are an important and well-understood subject in Computer |
55 Science, with many beautiful theorems and many useful algorithms. There is a |
91 Science, with many beautiful theorems and many useful algorithms. There is a |
56 wide range of textbooks on this subject, many of which are aimed at students |
92 wide range of textbooks on this subject, many of which are aimed at students |
57 and contain very detailed `pencil-and-paper' proofs |
93 and contain very detailed `pencil-and-paper' proofs |
58 (e.g.~\cite{Kozen97}). It seems natural to exercise theorem provers by |
94 (e.g.~\cite{Kozen97}). It seems natural to exercise theorem provers by |
74 In case of graphs and matrices, this means we have to build our own |
110 In case of graphs and matrices, this means we have to build our own |
75 reasoning infrastructure for them, as neither Isabelle/HOL nor HOL4 nor |
111 reasoning infrastructure for them, as neither Isabelle/HOL nor HOL4 nor |
76 HOLlight support them with libraries. Even worse, reasoning about graphs and |
112 HOLlight support them with libraries. Even worse, reasoning about graphs and |
77 matrices can be a real hassle in HOL-based theorem provers. Consider for |
113 matrices can be a real hassle in HOL-based theorem provers. Consider for |
78 example the operation of sequencing two automata, say $A_1$ and $A_2$, by |
114 example the operation of sequencing two automata, say $A_1$ and $A_2$, by |
79 connecting the accepting states of $A_1$ to the initial state of $A_2$:\\[-5.5mm] |
115 connecting the accepting states of $A_1$ to the initial state of $A_2$: |
80 % |
116 % |
81 \begin{center} |
117 \begin{center} |
82 \begin{tabular}{ccc} |
118 \begin{tabular}{ccc} |
83 \begin{tikzpicture}[scale=0.8] |
119 \begin{tikzpicture}[scale=0.8] |
84 %\draw[step=2mm] (-1,-1) grid (1,1); |
120 %\draw[step=2mm] (-1,-1) grid (1,1); |
204 Isabelle/HOL, but take a different approach to regular |
240 Isabelle/HOL, but take a different approach to regular |
205 languages. Instead of defining a regular language as one where there exists |
241 languages. Instead of defining a regular language as one where there exists |
206 an automaton that recognises all strings of the language, we define a |
242 an automaton that recognises all strings of the language, we define a |
207 regular language as: |
243 regular language as: |
208 |
244 |
209 \begin{definition} |
245 \begin{dfntn} |
210 A language @{text A} is \emph{regular}, provided there is a regular expression that matches all |
246 A language @{text A} is \emph{regular}, provided there is a regular expression that matches all |
211 strings of @{text "A"}. |
247 strings of @{text "A"}. |
212 \end{definition} |
248 \end{dfntn} |
213 |
249 |
214 \noindent |
250 \noindent |
215 The reason is that regular expressions, unlike graphs, matrices and functions, can |
251 The reason is that regular expressions, unlike graphs, matrices and functions, can |
216 be easily defined as inductive datatype. Consequently a corresponding reasoning |
252 be easily defined as inductive datatype. Consequently a corresponding reasoning |
217 infrastructure comes for free. This has recently been exploited in HOL4 with a formalisation |
253 infrastructure comes for free. This has recently been exploited in HOL4 with a formalisation |
239 text {* |
275 text {* |
240 Strings in Isabelle/HOL are lists of characters with the \emph{empty string} |
276 Strings in Isabelle/HOL are lists of characters with the \emph{empty string} |
241 being represented by the empty list, written @{term "[]"}. \emph{Languages} |
277 being represented by the empty list, written @{term "[]"}. \emph{Languages} |
242 are sets of strings. The language containing all strings is written in |
278 are sets of strings. The language containing all strings is written in |
243 Isabelle/HOL as @{term "UNIV::string set"}. The concatenation of two languages |
279 Isabelle/HOL as @{term "UNIV::string set"}. The concatenation of two languages |
244 is written @{term "A ;; B"} and a language raised to the power @{text n} is written |
280 is written @{term "A \<cdot> B"} and a language raised to the power @{text n} is written |
245 @{term "A \<up> n"}. They are defined as usual |
281 @{term "A \<up> n"}. They are defined as usual |
246 |
282 |
247 \begin{center} |
283 \begin{center} |
248 @{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]} |
284 @{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]} |
249 \hspace{7mm} |
285 \hspace{7mm} |
255 \noindent |
291 \noindent |
256 where @{text "@"} is the list-append operation. The Kleene-star of a language @{text A} |
292 where @{text "@"} is the list-append operation. The Kleene-star of a language @{text A} |
257 is defined as the union over all powers, namely @{thm Star_def}. In the paper |
293 is defined as the union over all powers, namely @{thm Star_def}. In the paper |
258 we will make use of the following properties of these constructions. |
294 we will make use of the following properties of these constructions. |
259 |
295 |
260 \begin{proposition}\label{langprops}\mbox{}\\ |
296 \begin{prpstn}\label{langprops}\mbox{}\\ |
261 \begin{tabular}{@ {}ll} |
297 \begin{tabular}{@ {}ll} |
262 (i) & @{thm star_cases} \\ |
298 (i) & @{thm star_cases} \\ |
263 (ii) & @{thm[mode=IfThen] pow_length}\\ |
299 (ii) & @{thm[mode=IfThen] pow_length}\\ |
264 (iii) & @{thm seq_Union_left} \\ |
300 (iii) & @{thm seq_Union_left} \\ |
265 \end{tabular} |
301 \end{tabular} |
266 \end{proposition} |
302 \end{prpstn} |
267 |
303 |
268 \noindent |
304 \noindent |
269 In @{text "(ii)"} we use the notation @{term "length s"} for the length of a |
305 In @{text "(ii)"} we use the notation @{term "length s"} for the length of a |
270 string; this property states that if \mbox{@{term "[] \<notin> A"}} then the lengths of |
306 string; this property states that if \mbox{@{term "[] \<notin> A"}} then the lengths of |
271 the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}. We omit |
307 the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}. We omit |
278 as \mbox{@{text "{y | y \<approx> x}"}}. |
314 as \mbox{@{text "{y | y \<approx> x}"}}. |
279 |
315 |
280 |
316 |
281 Central to our proof will be the solution of equational systems |
317 Central to our proof will be the solution of equational systems |
282 involving equivalence classes of languages. For this we will use Arden's Lemma \cite{Brzozowski64}, |
318 involving equivalence classes of languages. For this we will use Arden's Lemma \cite{Brzozowski64}, |
283 which solves equations of the form @{term "X = A ;; X \<union> B"} provided |
319 which solves equations of the form @{term "X = A \<cdot> X \<union> B"} provided |
284 @{term "[] \<notin> A"}. However we will need the following `reverse' |
320 @{term "[] \<notin> A"}. However we will need the following `reverse' |
285 version of Arden's Lemma (`reverse' in the sense of changing the order of @{term "A ;; X"} to |
321 version of Arden's Lemma (`reverse' in the sense of changing the order of @{term "A \<cdot> X"} to |
286 \mbox{@{term "X ;; A"}}). |
322 \mbox{@{term "X \<cdot> A"}}). |
287 |
323 |
288 \begin{lemma}[Reverse Arden's Lemma]\label{arden}\mbox{}\\ |
324 \begin{lmm}[Reverse Arden's Lemma]\label{arden}\mbox{}\\ |
289 If @{thm (prem 1) arden} then |
325 If @{thm (prem 1) arden} then |
290 @{thm (lhs) arden} if and only if |
326 @{thm (lhs) arden} if and only if |
291 @{thm (rhs) arden}. |
327 @{thm (rhs) arden}. |
292 \end{lemma} |
328 \end{lmm} |
293 |
329 |
294 \begin{proof} |
330 \begin{proof} |
295 For the right-to-left direction we assume @{thm (rhs) arden} and show |
331 For the right-to-left direction we assume @{thm (rhs) arden} and show |
296 that @{thm (lhs) arden} holds. From Prop.~\ref{langprops}@{text "(i)"} |
332 that @{thm (lhs) arden} holds. From Prop.~\ref{langprops}@{text "(i)"} |
297 we have @{term "A\<star> = {[]} \<union> A ;; A\<star>"}, |
333 we have @{term "A\<star> = {[]} \<union> A \<cdot> A\<star>"}, |
298 which is equal to @{term "A\<star> = {[]} \<union> A\<star> ;; A"}. Adding @{text B} to both |
334 which is equal to @{term "A\<star> = {[]} \<union> A\<star> \<cdot> A"}. Adding @{text B} to both |
299 sides gives @{term "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)"}, whose right-hand side |
335 sides gives @{term "B \<cdot> A\<star> = B \<cdot> ({[]} \<union> A\<star> \<cdot> A)"}, whose right-hand side |
300 is equal to @{term "(B ;; A\<star>) ;; A \<union> B"}. This completes this direction. |
336 is equal to @{term "(B \<cdot> A\<star>) \<cdot> A \<union> B"}. This completes this direction. |
301 |
337 |
302 For the other direction we assume @{thm (lhs) arden}. By a simple induction |
338 For the other direction we assume @{thm (lhs) arden}. By a simple induction |
303 on @{text n}, we can establish the property |
339 on @{text n}, we can establish the property |
304 |
340 |
305 \begin{center} |
341 \begin{center} |
306 @{text "(*)"}\hspace{5mm} @{thm (concl) arden_helper} |
342 @{text "(*)"}\hspace{5mm} @{thm (concl) arden_helper} |
307 \end{center} |
343 \end{center} |
308 |
344 |
309 \noindent |
345 \noindent |
310 Using this property we can show that @{term "B ;; (A \<up> n) \<subseteq> X"} holds for |
346 Using this property we can show that @{term "B \<cdot> (A \<up> n) \<subseteq> X"} holds for |
311 all @{text n}. From this we can infer @{term "B ;; A\<star> \<subseteq> X"} using the definition |
347 all @{text n}. From this we can infer @{term "B \<cdot> A\<star> \<subseteq> X"} using the definition |
312 of @{text "\<star>"}. |
348 of @{text "\<star>"}. |
313 For the inclusion in the other direction we assume a string @{text s} |
349 For the inclusion in the other direction we assume a string @{text s} |
314 with length @{text k} is an element in @{text X}. Since @{thm (prem 1) arden} |
350 with length @{text k} is an element in @{text X}. Since @{thm (prem 1) arden} |
315 we know by Prop.~\ref{langprops}@{text "(ii)"} that |
351 we know by Prop.~\ref{langprops}@{text "(ii)"} that |
316 @{term "s \<notin> X ;; (A \<up> Suc k)"} since its length is only @{text k} |
352 @{term "s \<notin> X \<cdot> (A \<up> Suc k)"} since its length is only @{text k} |
317 (the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). |
353 (the strings in @{term "X \<cdot> (A \<up> Suc k)"} are all longer). |
318 From @{text "(*)"} it follows then that |
354 From @{text "(*)"} it follows then that |
319 @{term s} must be an element in @{term "(\<Union>m\<in>{0..k}. B ;; (A \<up> m))"}. This in turn |
355 @{term s} must be an element in @{term "(\<Union>m\<in>{0..k}. B \<cdot> (A \<up> m))"}. This in turn |
320 implies that @{term s} is in @{term "(\<Union>n. B ;; (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} |
356 implies that @{term s} is in @{term "(\<Union>n. B \<cdot> (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} |
321 this is equal to @{term "B ;; A\<star>"}, as we needed to show.\qed |
357 this is equal to @{term "B \<cdot> A\<star>"}, as we needed to show.\qed |
322 \end{proof} |
358 \end{proof} |
323 |
359 |
324 \noindent |
360 \noindent |
325 Regular expressions are defined as the inductive datatype |
361 Regular expressions are defined as the inductive datatype |
326 |
362 |
379 The key definition in the Myhill-Nerode theorem is the |
415 The key definition in the Myhill-Nerode theorem is the |
380 \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two |
416 \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two |
381 strings are related, provided there is no distinguishing extension in this |
417 strings are related, provided there is no distinguishing extension in this |
382 language. This can be defined as a tertiary relation. |
418 language. This can be defined as a tertiary relation. |
383 |
419 |
384 \begin{definition}[Myhill-Nerode Relation] Given a language @{text A}, two strings @{text x} and |
420 \begin{dfntn}[Myhill-Nerode Relation] Given a language @{text A}, two strings @{text x} and |
385 @{text y} are Myhill-Nerode related provided |
421 @{text y} are Myhill-Nerode related provided |
386 \begin{center} |
422 \begin{center} |
387 @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]} |
423 @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]} |
388 \end{center} |
424 \end{center} |
389 \end{definition} |
425 \end{dfntn} |
390 |
426 |
391 \noindent |
427 \noindent |
392 It is easy to see that @{term "\<approx>A"} is an equivalence relation, which |
428 It is easy to see that @{term "\<approx>A"} is an equivalence relation, which |
393 partitions the set of all strings, @{text "UNIV"}, into a set of disjoint |
429 partitions the set of all strings, @{text "UNIV"}, into a set of disjoint |
394 equivalence classes. To illustrate this quotient construction, let us give a simple |
430 equivalence classes. To illustrate this quotient construction, let us give a simple |
405 |
441 |
406 One direction of the Myhill-Nerode theorem establishes |
442 One direction of the Myhill-Nerode theorem establishes |
407 that if there are finitely many equivalence classes, like in the example above, then |
443 that if there are finitely many equivalence classes, like in the example above, then |
408 the language is regular. In our setting we therefore have to show: |
444 the language is regular. In our setting we therefore have to show: |
409 |
445 |
410 \begin{theorem}\label{myhillnerodeone} |
446 \begin{thrm}\label{myhillnerodeone} |
411 @{thm[mode=IfThen] Myhill_Nerode1} |
447 @{thm[mode=IfThen] Myhill_Nerode1} |
412 \end{theorem} |
448 \end{thrm} |
413 |
449 |
414 \noindent |
450 \noindent |
415 To prove this theorem, we first define the set @{term "finals A"} as those equivalence |
451 To prove this theorem, we first define the set @{term "finals A"} as those equivalence |
416 classes from @{term "UNIV // \<approx>A"} that contain strings of @{text A}, namely |
452 classes from @{term "UNIV // \<approx>A"} that contain strings of @{text A}, namely |
417 % |
453 % |
494 Overloading the function @{text \<calL>} for the two kinds of terms in the |
530 Overloading the function @{text \<calL>} for the two kinds of terms in the |
495 equational system, we have |
531 equational system, we have |
496 |
532 |
497 \begin{center} |
533 \begin{center} |
498 @{text "\<calL>(Y, r) \<equiv>"} % |
534 @{text "\<calL>(Y, r) \<equiv>"} % |
499 @{thm (rhs) L_rhs_trm.simps(2)[where X="Y" and r="r", THEN eq_reflection]}\hspace{10mm} |
535 @{thm (rhs) L_trm.simps(2)[where X="Y" and r="r", THEN eq_reflection]}\hspace{10mm} |
500 @{thm L_rhs_trm.simps(1)[where r="r", THEN eq_reflection]} |
536 @{thm L_trm.simps(1)[where r="r", THEN eq_reflection]} |
501 \end{center} |
537 \end{center} |
502 |
538 |
503 \noindent |
539 \noindent |
504 and we can prove for @{text "X\<^isub>2\<^isub>.\<^isub>.\<^isub>n"} that the following equations |
540 and we can prove for @{text "X\<^isub>2\<^isub>.\<^isub>.\<^isub>n"} that the following equations |
505 % |
541 % |
542 \noindent |
578 \noindent |
543 Because we use sets of terms |
579 Because we use sets of terms |
544 for representing the right-hand sides of equations, we can |
580 for representing the right-hand sides of equations, we can |
545 prove \eqref{inv1} and \eqref{inv2} more concisely as |
581 prove \eqref{inv1} and \eqref{inv2} more concisely as |
546 % |
582 % |
547 \begin{lemma}\label{inv} |
583 \begin{lmm}\label{inv} |
548 If @{thm (prem 1) test} then @{text "X = \<Union> \<calL> ` rhs"}. |
584 If @{thm (prem 1) test} then @{text "X = \<Union> \<calL> ` rhs"}. |
549 \end{lemma} |
585 \end{lmm} |
550 |
586 |
551 \noindent |
587 \noindent |
552 Our proof of Thm.~\ref{myhillnerodeone} will proceed by transforming the |
588 Our proof of Thm.~\ref{myhillnerodeone} will proceed by transforming the |
553 initial equational system into one in \emph{solved form} maintaining the invariant |
589 initial equational system into one in \emph{solved form} maintaining the invariant |
554 in Lem.~\ref{inv}. From the solved form we will be able to read |
590 in Lem.~\ref{inv}. From the solved form we will be able to read |
595 \end{center} |
631 \end{center} |
596 |
632 |
597 \noindent |
633 \noindent |
598 This allows us to prove a version of Arden's Lemma on the level of equations. |
634 This allows us to prove a version of Arden's Lemma on the level of equations. |
599 |
635 |
600 \begin{lemma}\label{ardenable} |
636 \begin{lmm}\label{ardenable} |
601 Given an equation @{text "X = rhs"}. |
637 Given an equation @{text "X = rhs"}. |
602 If @{text "X = \<Union>\<calL> ` rhs"}, |
638 If @{text "X = \<Union>\<calL> ` rhs"}, |
603 @{thm (prem 2) Arden_keeps_eq}, and |
639 @{thm (prem 2) Arden_keeps_eq}, and |
604 @{thm (prem 3) Arden_keeps_eq}, then |
640 @{thm (prem 3) Arden_keeps_eq}, then |
605 @{text "X = \<Union>\<calL> ` (Arden X rhs)"}. |
641 @{text "X = \<Union>\<calL> ` (Arden X rhs)"}. |
606 \end{lemma} |
642 \end{lmm} |
607 |
643 |
608 \noindent |
644 \noindent |
609 Our @{text ardenable} condition is slightly stronger than needed for applying Arden's Lemma, |
645 Our @{text ardenable} condition is slightly stronger than needed for applying Arden's Lemma, |
610 but we can still ensure that it holds troughout our algorithm of transforming equations |
646 but we can still ensure that it holds troughout our algorithm of transforming equations |
611 into solved form. The \emph{substitution-operation} takes an equation |
647 into solved form. The \emph{substitution-operation} takes an equation |
784 \end{proof} |
820 \end{proof} |
785 |
821 |
786 \noindent |
822 \noindent |
787 We also need the fact that @{text Iter} decreases the termination measure. |
823 We also need the fact that @{text Iter} decreases the termination measure. |
788 |
824 |
789 \begin{lemma}\label{itertwo} |
825 \begin{lmm}\label{itertwo} |
790 @{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]} |
826 @{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]} |
791 \end{lemma} |
827 \end{lmm} |
792 |
828 |
793 \begin{proof} |
829 \begin{proof} |
794 By assumption we know that @{text "ES"} is finite and has more than one element. |
830 By assumption we know that @{text "ES"} is finite and has more than one element. |
795 Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with |
831 Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with |
796 @{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distinctness property we can infer |
832 @{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distinctness property we can infer |
801 |
837 |
802 \noindent |
838 \noindent |
803 This brings us to our property we want to establish for @{text Solve}. |
839 This brings us to our property we want to establish for @{text Solve}. |
804 |
840 |
805 |
841 |
806 \begin{lemma} |
842 \begin{lmm} |
807 If @{thm (prem 1) Solve} and @{thm (prem 2) Solve} then there exists |
843 If @{thm (prem 1) Solve} and @{thm (prem 2) Solve} then there exists |
808 a @{text rhs} such that @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} |
844 a @{text rhs} such that @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} |
809 and @{term "invariant {(X, rhs)}"}. |
845 and @{term "invariant {(X, rhs)}"}. |
810 \end{lemma} |
846 \end{lmm} |
811 |
847 |
812 \begin{proof} |
848 \begin{proof} |
813 In order to prove this lemma using \eqref{whileprinciple}, we have to use a slightly |
849 In order to prove this lemma using \eqref{whileprinciple}, we have to use a slightly |
814 stronger invariant since Lem.~\ref{iterone} and \ref{itertwo} have the precondition |
850 stronger invariant since Lem.~\ref{iterone} and \ref{itertwo} have the precondition |
815 that @{term "(X, rhs) \<in> ES"} for some @{text rhs}. This precondition is needed |
851 that @{term "(X, rhs) \<in> ES"} for some @{text rhs}. This precondition is needed |
833 |
869 |
834 \noindent |
870 \noindent |
835 With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"} |
871 With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"} |
836 there exists a regular expression. |
872 there exists a regular expression. |
837 |
873 |
838 \begin{lemma}\label{every_eqcl_has_reg} |
874 \begin{lmm}\label{every_eqcl_has_reg} |
839 @{thm[mode=IfThen] every_eqcl_has_reg} |
875 @{thm[mode=IfThen] every_eqcl_has_reg} |
840 \end{lemma} |
876 \end{lmm} |
841 |
877 |
842 \begin{proof} |
878 \begin{proof} |
843 By the preceding lemma, we know that there exists a @{text "rhs"} such |
879 By the preceding lemma, we know that there exists a @{text "rhs"} such |
844 that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"}, |
880 that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"}, |
845 and that the invariant holds for this equation. That means we |
881 and that the invariant holds for this equation. That means we |
917 will show that the tagging-relations are more refined than @{term "\<approx>(L r)"}, which |
953 will show that the tagging-relations are more refined than @{term "\<approx>(L r)"}, which |
918 implies that @{term "UNIV // \<approx>(L r)"} must also be finite (a relation @{text "R\<^isub>1"} |
954 implies that @{term "UNIV // \<approx>(L r)"} must also be finite (a relation @{text "R\<^isub>1"} |
919 is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}). |
955 is said to \emph{refine} @{text "R\<^isub>2"} provided @{text "R\<^isub>1 \<subseteq> R\<^isub>2"}). |
920 We formally define the notion of a \emph{tagging-relation} as follows. |
956 We formally define the notion of a \emph{tagging-relation} as follows. |
921 |
957 |
922 \begin{definition}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x} |
958 \begin{dfntn}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x} |
923 and @{text y} are \emph{tag-related} provided |
959 and @{text y} are \emph{tag-related} provided |
924 \begin{center} |
960 \begin{center} |
925 @{text "x =tag= y \<equiv> tag x = tag y"}\;. |
961 @{text "x =tag= y \<equiv> tag x = tag y"}\;. |
926 \end{center} |
962 \end{center} |
927 \end{definition} |
963 \end{dfntn} |
928 |
964 |
929 |
965 |
930 In order to establish finiteness of a set @{text A}, we shall use the following powerful |
966 In order to establish finiteness of a set @{text A}, we shall use the following powerful |
931 principle from Isabelle/HOL's library. |
967 principle from Isabelle/HOL's library. |
932 % |
968 % |
937 \noindent |
973 \noindent |
938 It states that if an image of a set under an injective function @{text f} (injective over this set) |
974 It states that if an image of a set under an injective function @{text f} (injective over this set) |
939 is finite, then the set @{text A} itself must be finite. We can use it to establish the following |
975 is finite, then the set @{text A} itself must be finite. We can use it to establish the following |
940 two lemmas. |
976 two lemmas. |
941 |
977 |
942 \begin{lemma}\label{finone} |
978 \begin{lmm}\label{finone} |
943 @{thm[mode=IfThen] finite_eq_tag_rel} |
979 @{thm[mode=IfThen] finite_eq_tag_rel} |
944 \end{lemma} |
980 \end{lmm} |
945 |
981 |
946 \begin{proof} |
982 \begin{proof} |
947 We set in \eqref{finiteimageD}, @{text f} to be @{text "X \<mapsto> tag ` X"}. We have |
983 We set in \eqref{finiteimageD}, @{text f} to be @{text "X \<mapsto> tag ` X"}. We have |
948 @{text "range f"} to be a subset of @{term "Pow (range tag)"}, which we know must be |
984 @{text "range f"} to be a subset of @{term "Pow (range tag)"}, which we know must be |
949 finite by assumption. Now @{term "f (UNIV // =tag=)"} is a subset of @{text "range f"}, |
985 finite by assumption. Now @{term "f (UNIV // =tag=)"} is a subset of @{text "range f"}, |
953 @{text "tag x = tag y"}. Since @{text x} and @{text y} are tag-related, this in |
989 @{text "tag x = tag y"}. Since @{text x} and @{text y} are tag-related, this in |
954 turn means that the equivalence classes @{text X} |
990 turn means that the equivalence classes @{text X} |
955 and @{text Y} must be equal.\qed |
991 and @{text Y} must be equal.\qed |
956 \end{proof} |
992 \end{proof} |
957 |
993 |
958 \begin{lemma}\label{fintwo} |
994 \begin{lmm}\label{fintwo} |
959 Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, whereby |
995 Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, whereby |
960 @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}. |
996 @{text "R\<^isub>1"} refines @{text "R\<^isub>2"}. |
961 If @{thm (prem 1) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]} |
997 If @{thm (prem 1) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]} |
962 then @{thm (concl) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}. |
998 then @{thm (concl) refined_partition_finite[where ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}. |
963 \end{lemma} |
999 \end{lmm} |
964 |
1000 |
965 \begin{proof} |
1001 \begin{proof} |
966 We prove this lemma again using \eqref{finiteimageD}. This time we set @{text f} to |
1002 We prove this lemma again using \eqref{finiteimageD}. This time we set @{text f} to |
967 be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that |
1003 be @{text "X \<mapsto>"}~@{term "{R\<^isub>1 `` {x} | x. x \<in> X}"}. It is easy to see that |
968 @{term "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{term "Pow (UNIV // R\<^isub>1)"}, |
1004 @{term "finite (f ` (UNIV // R\<^isub>2))"} because it is a subset of @{term "Pow (UNIV // R\<^isub>1)"}, |
1026 The pattern in \eqref{pattern} is repeated for the other two cases. Unfortunately, |
1062 The pattern in \eqref{pattern} is repeated for the other two cases. Unfortunately, |
1027 they are slightly more complicated. In the @{const SEQ}-case we essentially have |
1063 they are slightly more complicated. In the @{const SEQ}-case we essentially have |
1028 to be able to infer that |
1064 to be able to infer that |
1029 % |
1065 % |
1030 \begin{center} |
1066 \begin{center} |
1031 @{text "\<dots>"}@{term "x @ z \<in> A ;; B \<longrightarrow> y @ z \<in> A ;; B"} |
1067 @{text "\<dots>"}@{term "x @ z \<in> A \<cdot> B \<longrightarrow> y @ z \<in> A \<cdot> B"} |
1032 \end{center} |
1068 \end{center} |
1033 % |
1069 % |
1034 \noindent |
1070 \noindent |
1035 using the information given by the appropriate tagging-function. The complication |
1071 using the information given by the appropriate tagging-function. The complication |
1036 is to find out what the possible splits of @{text "x @ z"} are to be in @{term "A ;; B"} |
1072 is to find out what the possible splits of @{text "x @ z"} are to be in @{term "A \<cdot> B"} |
1037 (this was easy in case of @{term "A \<union> B"}). To deal with this complication we define the |
1073 (this was easy in case of @{term "A \<union> B"}). To deal with this complication we define the |
1038 notions of \emph{string prefixes} |
1074 notions of \emph{string prefixes} |
1039 % |
1075 % |
1040 \begin{center} |
1076 \begin{center} |
1041 @{text "x \<le> y \<equiv> \<exists>z. y = x @ z"}\hspace{10mm} |
1077 @{text "x \<le> y \<equiv> \<exists>z. y = x @ z"}\hspace{10mm} |
1073 (z.north west) -- ($(z.north east)+(0em,0em)$) |
1109 (z.north west) -- ($(z.north east)+(0em,0em)$) |
1074 node[midway, above=0.5em]{@{text z}}; |
1110 node[midway, above=0.5em]{@{text z}}; |
1075 |
1111 |
1076 \draw[decoration={brace,transform={yscale=3}},decorate] |
1112 \draw[decoration={brace,transform={yscale=3}},decorate] |
1077 ($(xa.north west)+(0em,3ex)$) -- ($(z.north east)+(0em,3ex)$) |
1113 ($(xa.north west)+(0em,3ex)$) -- ($(z.north east)+(0em,3ex)$) |
1078 node[midway, above=0.8em]{@{term "x @ z \<in> A ;; B"}}; |
1114 node[midway, above=0.8em]{@{term "x @ z \<in> A \<cdot> B"}}; |
1079 |
1115 |
1080 \draw[decoration={brace,transform={yscale=3}},decorate] |
1116 \draw[decoration={brace,transform={yscale=3}},decorate] |
1081 ($(z.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$) |
1117 ($(z.south east)+(0em,0ex)$) -- ($(xxa.south west)+(0em,0ex)$) |
1082 node[midway, below=0.5em]{@{term "(x - x') @ z \<in> B"}}; |
1118 node[midway, below=0.5em]{@{term "(x - x') @ z \<in> B"}}; |
1083 |
1119 |
1100 ($(za.north west)+(0em,0ex)$) -- ($(zza.north east)+(0em,0ex)$) |
1136 ($(za.north west)+(0em,0ex)$) -- ($(zza.north east)+(0em,0ex)$) |
1101 node[midway, above=0.5em]{@{text z}}; |
1137 node[midway, above=0.5em]{@{text z}}; |
1102 |
1138 |
1103 \draw[decoration={brace,transform={yscale=3}},decorate] |
1139 \draw[decoration={brace,transform={yscale=3}},decorate] |
1104 ($(x.north west)+(0em,3ex)$) -- ($(zza.north east)+(0em,3ex)$) |
1140 ($(x.north west)+(0em,3ex)$) -- ($(zza.north east)+(0em,3ex)$) |
1105 node[midway, above=0.8em]{@{term "x @ z \<in> A ;; B"}}; |
1141 node[midway, above=0.8em]{@{term "x @ z \<in> A \<cdot> B"}}; |
1106 |
1142 |
1107 \draw[decoration={brace,transform={yscale=3}},decorate] |
1143 \draw[decoration={brace,transform={yscale=3}},decorate] |
1108 ($(za.south east)+(0em,0ex)$) -- ($(x.south west)+(0em,0ex)$) |
1144 ($(za.south east)+(0em,0ex)$) -- ($(x.south west)+(0em,0ex)$) |
1109 node[midway, below=0.5em]{@{text "x @ z' \<in> A"}}; |
1145 node[midway, below=0.5em]{@{text "x @ z' \<in> A"}}; |
1110 |
1146 |
1134 then @{term "finite ((UNIV // \<approx>A) \<times> (Pow (UNIV // \<approx>B)))"} holds. The range of |
1170 then @{term "finite ((UNIV // \<approx>A) \<times> (Pow (UNIV // \<approx>B)))"} holds. The range of |
1135 @{term "tag_str_SEQ A B"} is a subset of this product set, and therefore finite. |
1171 @{term "tag_str_SEQ A B"} is a subset of this product set, and therefore finite. |
1136 We have to show injectivity of this tagging-function as |
1172 We have to show injectivity of this tagging-function as |
1137 % |
1173 % |
1138 \begin{center} |
1174 \begin{center} |
1139 @{term "\<forall>z. tag_str_SEQ A B x = tag_str_SEQ A B y \<and> x @ z \<in> A ;; B \<longrightarrow> y @ z \<in> A ;; B"} |
1175 @{term "\<forall>z. tag_str_SEQ A B x = tag_str_SEQ A B y \<and> x @ z \<in> A \<cdot> B \<longrightarrow> y @ z \<in> A \<cdot> B"} |
1140 \end{center} |
1176 \end{center} |
1141 % |
1177 % |
1142 \noindent |
1178 \noindent |
1143 There are two cases to be considered (see pictures above). First, there exists |
1179 There are two cases to be considered (see pictures above). First, there exists |
1144 a @{text "x'"} such that |
1180 a @{text "x'"} such that |
1159 That means there must be a @{text "y'"} such that @{text "y' \<in> A"} and |
1195 That means there must be a @{text "y'"} such that @{text "y' \<in> A"} and |
1160 @{term "\<approx>B `` {x - x'} = \<approx>B `` {y - y'}"}. This equality means that |
1196 @{term "\<approx>B `` {x - x'} = \<approx>B `` {y - y'}"}. This equality means that |
1161 @{term "(x - x') \<approx>B (y - y')"} holds. Unfolding the Myhill-Nerode |
1197 @{term "(x - x') \<approx>B (y - y')"} holds. Unfolding the Myhill-Nerode |
1162 relation and together with the fact that @{text "(x - x') @ z \<in> B"}, we |
1198 relation and together with the fact that @{text "(x - x') @ z \<in> B"}, we |
1163 have @{text "(y - y') @ z \<in> B"}. We already know @{text "y' \<in> A"}, therefore |
1199 have @{text "(y - y') @ z \<in> B"}. We already know @{text "y' \<in> A"}, therefore |
1164 @{term "y @ z \<in> A ;; B"}, as needed in this case. |
1200 @{term "y @ z \<in> A \<cdot> B"}, as needed in this case. |
1165 |
1201 |
1166 Second, there exists a @{text "z'"} such that @{term "x @ z' \<in> A"} and @{text "z - z' \<in> B"}. |
1202 Second, there exists a @{text "z'"} such that @{term "x @ z' \<in> A"} and @{text "z - z' \<in> B"}. |
1167 By the assumption about @{term "tag_str_SEQ A B"} we have |
1203 By the assumption about @{term "tag_str_SEQ A B"} we have |
1168 @{term "\<approx>A `` {x} = \<approx>A `` {y}"} and thus @{term "x \<approx>A y"}. Which means by the Myhill-Nerode |
1204 @{term "\<approx>A `` {x} = \<approx>A `` {y}"} and thus @{term "x \<approx>A y"}. Which means by the Myhill-Nerode |
1169 relation that @{term "y @ z' \<in> A"} holds. Using @{text "z - z' \<in> B"}, we can conclude also in this case |
1205 relation that @{term "y @ z' \<in> A"} holds. Using @{text "z - z' \<in> B"}, we can conclude also in this case |
1170 with @{term "y @ z \<in> A ;; B"}. We again can complete the @{const SEQ}-case |
1206 with @{term "y @ z \<in> A \<cdot> B"}. We again can complete the @{const SEQ}-case |
1171 by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed |
1207 by setting @{text A} to @{term "L r\<^isub>1"} and @{text B} to @{term "L r\<^isub>2"}.\qed |
1172 \end{proof} |
1208 \end{proof} |
1173 |
1209 |
1174 \noindent |
1210 \noindent |
1175 The case for @{const STAR} is similar to @{const SEQ}, but poses a few extra challenges. When |
1211 The case for @{const STAR} is similar to @{const SEQ}, but poses a few extra challenges. When |
1307 expressions can conveniently be defined as a datatype in HOL-based theorem |
1343 expressions can conveniently be defined as a datatype in HOL-based theorem |
1308 provers. For us it was therefore interesting to find out how far we can push |
1344 provers. For us it was therefore interesting to find out how far we can push |
1309 this point of view. We have established in Isabelle/HOL both directions |
1345 this point of view. We have established in Isabelle/HOL both directions |
1310 of the Myhill-Nerode theorem. |
1346 of the Myhill-Nerode theorem. |
1311 % |
1347 % |
1312 \begin{theorem}[The Myhill-Nerode Theorem]\mbox{}\\ |
1348 \begin{thrm}[The Myhill-Nerode Theorem]\mbox{}\\ |
1313 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
1349 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
1314 \end{theorem} |
1350 \end{thrm} |
1315 % |
1351 % |
1316 \noindent |
1352 \noindent |
1317 Having formalised this theorem means we |
1353 Having formalised this theorem means we |
1318 pushed our point of view quite far. Using this theorem we can obviously prove when a language |
1354 pushed our point of view quite far. Using this theorem we can obviously prove when a language |
1319 is \emph{not} regular---by establishing that it has infinitely many |
1355 is \emph{not} regular---by establishing that it has infinitely many |