609 The key definition in the Myhill-Nerode Theorem is the |
609 The key definition in the Myhill-Nerode Theorem is the |
610 \emph{Myhill-Nerode Relation}, which states that w.r.t.~a language two |
610 \emph{Myhill-Nerode Relation}, which states that w.r.t.~a language two |
611 strings are related, provided there is no distinguishing extension in this |
611 strings are related, provided there is no distinguishing extension in this |
612 language. This can be defined as a ternary relation. |
612 language. This can be defined as a ternary relation. |
613 |
613 |
614 \begin{dfntn}[(Myhill-Nerode Relation)]\label{myhillneroderel} |
614 \begin{dfntn}[Myhill-Nerode Relation]\label{myhillneroderel} |
615 Given a language @{text A}, two strings @{text x} and |
615 Given a language @{text A}, two strings @{text x} and |
616 @{text y} are Myhill-Nerode related provided |
616 @{text y} are Myhill-Nerode related provided |
617 \begin{center} |
617 \begin{center} |
618 @{thm str_eq_def'} |
618 @{thm str_eq_def'} |
619 \end{center} |
619 \end{center} |
1188 \noindent |
1188 \noindent |
1189 The proof will be by induction on the structure of @{text r}. It turns out |
1189 The proof will be by induction on the structure of @{text r}. It turns out |
1190 the base cases are straightforward. |
1190 the base cases are straightforward. |
1191 |
1191 |
1192 |
1192 |
1193 \begin{proof}[(Base Cases)] |
1193 \begin{proof}[Base Cases] |
1194 The cases for @{const ZERO}, @{const ONE} and @{const ATOM} are routine, because |
1194 The cases for @{const ZERO}, @{const ONE} and @{const ATOM} are routine, because |
1195 we can easily establish that |
1195 we can easily establish that |
1196 |
1196 |
1197 \begin{center} |
1197 \begin{center} |
1198 \begin{tabular}{l} |
1198 \begin{tabular}{l} |
1273 @{term "\<approx>(lang r)"}, which implies that @{term "UNIV // \<approx>(lang r)"} must |
1273 @{term "\<approx>(lang r)"}, which implies that @{term "UNIV // \<approx>(lang r)"} must |
1274 also be finite. We formally define the notion of a \emph{tagging-relation} |
1274 also be finite. We formally define the notion of a \emph{tagging-relation} |
1275 as follows. |
1275 as follows. |
1276 |
1276 |
1277 |
1277 |
1278 \begin{dfntn}[(Tagging-Relation)] Given a tagging-function @{text tag}, then two strings @{text x} |
1278 \begin{dfntn}[Tagging-Relation] Given a tagging-function @{text tag}, then two strings @{text x} |
1279 and @{text y} are \emph{tag-related} provided |
1279 and @{text y} are \emph{tag-related} provided |
1280 \begin{center} |
1280 \begin{center} |
1281 @{text "x \<^raw:$\threesim$>\<^bsub>tag\<^esub> y \<equiv> tag x = tag y"}\;. |
1281 @{text "x \<^raw:$\threesim$>\<^bsub>tag\<^esub> y \<equiv> tag x = tag y"}\;. |
1282 \end{center} |
1282 \end{center} |
1283 \end{dfntn} |
1283 \end{dfntn} |
1351 is that we need to establish that @{term "=(tag_Plus A B)="} refines @{term "\<approx>(A \<union> B)"}. |
1351 is that we need to establish that @{term "=(tag_Plus A B)="} refines @{term "\<approx>(A \<union> B)"}. |
1352 This amounts to showing @{term "x \<approx>A y"} or @{term "x \<approx>B y"} under the assumption |
1352 This amounts to showing @{term "x \<approx>A y"} or @{term "x \<approx>B y"} under the assumption |
1353 @{term "x"}~@{term "=(tag_Plus A B)="}~@{term y}. As we shall see, this definition will |
1353 @{term "x"}~@{term "=(tag_Plus A B)="}~@{term y}. As we shall see, this definition will |
1354 provide us with just the right assumptions in order to get the proof through. |
1354 provide us with just the right assumptions in order to get the proof through. |
1355 |
1355 |
1356 \begin{proof}[(@{const "PLUS"}-Case)] |
1356 \begin{proof}[@{const "PLUS"}-Case] |
1357 We can show in general, if @{term "finite (UNIV // \<approx>A)"} and @{term "finite |
1357 We can show in general, if @{term "finite (UNIV // \<approx>A)"} and @{term "finite |
1358 (UNIV // \<approx>B)"} then @{term "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"} |
1358 (UNIV // \<approx>B)"} then @{term "finite ((UNIV // \<approx>A) \<times> (UNIV // \<approx>B))"} |
1359 holds. The range of @{term "tag_Plus A B"} is a subset of this product |
1359 holds. The range of @{term "tag_Plus A B"} is a subset of this product |
1360 set---so finite. For the refinement proof-obligation, we know that @{term |
1360 set---so finite. For the refinement proof-obligation, we know that @{term |
1361 "(\<approx>A `` {x}, \<approx>B `` {x}) = (\<approx>A `` {y}, \<approx>B `` {y})"} holds by assumption. Then |
1361 "(\<approx>A `` {x}, \<approx>B `` {x}) = (\<approx>A `` {y}, \<approx>B `` {y})"} holds by assumption. Then |
1475 Note that we have to make the assumption for all suffixes @{text "x\<^isub>s"}, since we do |
1475 Note that we have to make the assumption for all suffixes @{text "x\<^isub>s"}, since we do |
1476 not know anything about how the string @{term x} is partitioned. |
1476 not know anything about how the string @{term x} is partitioned. |
1477 With this definition in place, let us prove the @{const "Times"}-case. |
1477 With this definition in place, let us prove the @{const "Times"}-case. |
1478 |
1478 |
1479 |
1479 |
1480 \begin{proof}[(@{const TIMES}-Case)] |
1480 \begin{proof}[@{const TIMES}-Case] |
1481 If @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"} |
1481 If @{term "finite (UNIV // \<approx>A)"} and @{term "finite (UNIV // \<approx>B)"} |
1482 then @{term "finite ((UNIV // \<approx>A) \<times> (Pow (UNIV // \<approx>B)))"} holds. The range of |
1482 then @{term "finite ((UNIV // \<approx>A) \<times> (Pow (UNIV // \<approx>B)))"} holds. The range of |
1483 @{term "tag_Times A B"} is a subset of this product set, and therefore finite. |
1483 @{term "tag_Times A B"} is a subset of this product set, and therefore finite. |
1484 For the refinement of @{term "\<approx>(A \<cdot> B)"} and @{text "\<^raw:$\threesim$>\<^bsub>\<times>tag A B\<^esub>"}, |
1484 For the refinement of @{term "\<approx>(A \<cdot> B)"} and @{text "\<^raw:$\threesim$>\<^bsub>\<times>tag A B\<^esub>"}, |
1485 we have by Lemma \ref{refinement} |
1485 we have by Lemma \ref{refinement} |
1600 \begin{center} |
1600 \begin{center} |
1601 @{thm (lhs) tag_Star_def[where ?A="A", THEN meta_eq_app]}~@{text "\<equiv>"}~ |
1601 @{thm (lhs) tag_Star_def[where ?A="A", THEN meta_eq_app]}~@{text "\<equiv>"}~ |
1602 @{text "{\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>A\<^esub> | x\<^isub>p < x \<and> x\<^isub>p \<in> A\<^isup>\<star> \<and> (x\<^isub>p, x\<^isub>s) \<in> Partitions x}"} |
1602 @{text "{\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>A\<^esub> | x\<^isub>p < x \<and> x\<^isub>p \<in> A\<^isup>\<star> \<and> (x\<^isub>p, x\<^isub>s) \<in> Partitions x}"} |
1603 \end{center} |
1603 \end{center} |
1604 |
1604 |
1605 \begin{proof}[(@{const Star}-Case)] |
1605 \begin{proof}[@{const Star}-Case] |
1606 If @{term "finite (UNIV // \<approx>A)"} |
1606 If @{term "finite (UNIV // \<approx>A)"} |
1607 then @{term "finite (Pow (UNIV // \<approx>A))"} holds. The range of |
1607 then @{term "finite (Pow (UNIV // \<approx>A))"} holds. The range of |
1608 @{term "tag_Star A"} is a subset of this set, and therefore finite. |
1608 @{term "tag_Star A"} is a subset of this set, and therefore finite. |
1609 Again we have to show under the assumption @{term "x"}~@{term "=(tag_Star A)="}~@{term y} |
1609 Again we have to show under the assumption @{term "x"}~@{term "=(tag_Star A)="}~@{term y} |
1610 that @{term "x @ z \<in> A\<star>"} implies @{term "y @ z \<in> A\<star>"}. |
1610 that @{term "x @ z \<in> A\<star>"} implies @{term "y @ z \<in> A\<star>"}. |
2273 |
2273 |
2274 Finally we like to show that the Myhill-Nerode Theorem is also convenient for establishing |
2274 Finally we like to show that the Myhill-Nerode Theorem is also convenient for establishing |
2275 the non-regularity of languages. For this we use the following version of the Continuation |
2275 the non-regularity of languages. For this we use the following version of the Continuation |
2276 Lemma (see for example~\cite{Rosenberg06}). |
2276 Lemma (see for example~\cite{Rosenberg06}). |
2277 |
2277 |
2278 \begin{lmm}[(Continuation Lemma)] |
2278 \begin{lmm}[Continuation Lemma] |
2279 If a language @{text A} is regular and a set of strings @{text B} is infinite, |
2279 If a language @{text A} is regular and a set of strings @{text B} is infinite, |
2280 then there exist two distinct strings @{text x} and @{text y} in @{text B} |
2280 then there exist two distinct strings @{text x} and @{text y} in @{text B} |
2281 such that @{term "x \<approx>A y"}. |
2281 such that @{term "x \<approx>A y"}. |
2282 \end{lmm} |
2282 \end{lmm} |
2283 |
2283 |
2298 \end{lmm} |
2298 \end{lmm} |
2299 |
2299 |
2300 \begin{proof} |
2300 \begin{proof} |
2301 After unfolding the definition of @{text "B"}, we need to establish that given @{term "i \<noteq> j"}, |
2301 After unfolding the definition of @{text "B"}, we need to establish that given @{term "i \<noteq> j"}, |
2302 the strings @{text "a\<^sup>i"} and @{text "a\<^sup>j"} are not Myhill-Nerode related by @{text "A"}. |
2302 the strings @{text "a\<^sup>i"} and @{text "a\<^sup>j"} are not Myhill-Nerode related by @{text "A"}. |
2303 That means we have to show that \mbox{@{text "\<forall>z. a\<^sup>i @ z \<in> A = a\<^sup>j @ z \<in> A"}} leads to |
2303 That means we have to show that @{text "\<forall>z. a\<^sup>i @ z \<in> A = a\<^sup>j @ z \<in> A"} leads to |
2304 a contradiction. Let us take @{text "b\<^sup>i"} for @{text "z"}. Then we know @{text "a\<^sup>i @ b\<^sup>i \<in> A"}. |
2304 a contradiction. Let us take @{text "b\<^sup>i"} for @{text "z"}. Then we know @{text "a\<^sup>i @ b\<^sup>i \<in> A"}. |
2305 But since @{term "i \<noteq> j"}, @{text "a\<^sup>j @ b\<^sup>i \<notin> A"}. Therefore @{text "a\<^sup>i"} and @{text "a\<^sup>j"} |
2305 But since @{term "i \<noteq> j"}, @{text "a\<^sup>j @ b\<^sup>i \<notin> A"}. Therefore @{text "a\<^sup>i"} and @{text "a\<^sup>j"} |
2306 cannot be Myhill-Nerode related by @{text "A"}, and we are done. |
2306 cannot be Myhill-Nerode related by @{text "A"}, and we are done. |
2307 \end{proof} |
2307 \end{proof} |
2308 |
2308 |
2321 \noindent |
2321 \noindent |
2322 In this paper we took the view that a regular language is one where there |
2322 In this paper we took the view that a regular language is one where there |
2323 exists a regular expression that matches all of its strings. Regular |
2323 exists a regular expression that matches all of its strings. Regular |
2324 expressions can conveniently be defined as a datatype in theorem |
2324 expressions can conveniently be defined as a datatype in theorem |
2325 provers. For us it was therefore interesting to find out how far we can push |
2325 provers. For us it was therefore interesting to find out how far we can push |
2326 this point of view. We have established in Isabelle/HOL both directions |
2326 this point of view. But this question whether formal language theory can |
|
2327 be done without automata crops up also in non-theorem prover contexts. For |
|
2328 example, Gasarch asked in the Computational Complexity blog by \citeN{GasarchBlog} |
|
2329 whether the complementation of |
|
2330 regular-expression languages can be proved without using automata. He concluded |
|
2331 |
|
2332 \begin{quote} |
|
2333 {\it \ldots it can't be done} |
|
2334 \end{quote} |
|
2335 |
|
2336 \noindent |
|
2337 and even pondered |
|
2338 |
|
2339 \begin{quote} |
|
2340 {\it \ldots [b]ut is there a rigorous way to even state that?} |
|
2341 \end{quote} |
|
2342 |
|
2343 \noindent |
|
2344 We have established in Isabelle/HOL both directions |
2327 of the Myhill-Nerode Theorem. |
2345 of the Myhill-Nerode Theorem. |
2328 % |
2346 % |
2329 \begin{thrm}[(Myhill-Nerode Theorem)]\mbox{}\\ |
2347 \begin{thrm}[Myhill-Nerode Theorem]\mbox{}\\ |
2330 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
2348 A language @{text A} is regular if and only if @{thm (rhs) Myhill_Nerode}. |
2331 \end{thrm} |
2349 \end{thrm} |
2332 |
2350 |
2333 \noindent |
2351 \noindent |
2334 Having formalised this theorem means we pushed our point of view quite |
2352 Having formalised this theorem means we pushed our point of view quite |
2335 far. Using this theorem we can obviously prove when a language is \emph{not} |
2353 far. Using this theorem we can obviously prove when a language is \emph{not} |
2336 regular---by establishing that it has infinitely many equivalence classes |
2354 regular---by establishing that it has infinitely many equivalence classes |
2337 generated by the Myhill-Nerode Relation (this is usually the purpose of the |
2355 generated by the Myhill-Nerode Relation (this is usually the purpose of the |
2338 Pumping Lemma). We can also use it to establish the standard |
2356 Pumping Lemma). We can also use it to establish the standard |
2339 textbook results about closure properties of regular languages. Interesting |
2357 textbook results about closure properties of regular languages. The case of |
2340 is the case of closure under complement, because it seems difficult to |
2358 closure under complement follows easily from the Myhill-Nerode Theorem. |
2341 construct a regular expression for the complement language by direct |
2359 So our answer to Gasarch is ``{\it it can be done!''} |
2342 means. However the existence of such a regular expression can be easily |
|
2343 proved using the Myhill-Nerode Theorem. |
|
2344 |
2360 |
2345 %Our insistence on regular expressions for proving the Myhill-Nerode Theorem |
2361 %Our insistence on regular expressions for proving the Myhill-Nerode Theorem |
2346 %arose from the problem of defining formally the regularity of a language. |
2362 %arose from the problem of defining formally the regularity of a language. |
2347 %In order to guarantee consistency, |
2363 %In order to guarantee consistency, |
2348 %formalisations in HOL can only extend the logic with definitions that introduce a new concept in |
2364 %formalisations in HOL can only extend the logic with definitions that introduce a new concept in |
2375 %regular expressions poses no problem at all for HOL. We showed in this |
2391 %regular expressions poses no problem at all for HOL. We showed in this |
2376 %paper that they can be used for establishing the central result in regular |
2392 %paper that they can be used for establishing the central result in regular |
2377 %language theory---the Myhill-Nerode Theorem. |
2393 %language theory---the Myhill-Nerode Theorem. |
2378 |
2394 |
2379 While regular expressions are convenient, they have some limitations. One is |
2395 While regular expressions are convenient, they have some limitations. One is |
|
2396 that there are some regular expressions for which the smallest regular |
|
2397 expression for the complement language has a doubly-exponential blowup in size |
|
2398 as shown by \citeN{Gelade12}. |
|
2399 Another is |
2380 that there seems to be no method of calculating a minimal regular expression |
2400 that there seems to be no method of calculating a minimal regular expression |
2381 (for example in terms of length) for a regular language, like there is for |
2401 (for example in terms of length) for a regular language, like there is for |
2382 automata. On the other hand, efficient regular expression matching, without |
2402 automata. On the other hand, efficient regular expression matching, without |
2383 using automata, poses no problem as shown by \citeN{OwensReppyTuron09}. For an |
2403 using automata, poses no problem as shown by \citeN{OwensReppyTuron09}. For an |
2384 implementation of a simple regular expression matcher, whose correctness has |
2404 implementation of a simple regular expression matcher, whose correctness has |