247 \noindent |
247 \noindent |
248 changes the type---the disjoint union is not a set, but a set of |
248 changes the type---the disjoint union is not a set, but a set of |
249 pairs. Using this definition for disjoint union means we do not have a |
249 pairs. Using this definition for disjoint union means we do not have a |
250 single type for automata. As a result we will not be able to define a regular |
250 single type for automata. As a result we will not be able to define a regular |
251 language as one for which there exists an automaton that recognises all its |
251 language as one for which there exists an automaton that recognises all its |
252 strings. This is because we cannot make a definition in HOL that is polymorphic in |
252 strings (Definition~\ref{baddef}). This is because we cannot make a definition in HOL that is polymorphic in |
253 the state type and there is no type quantification available in HOL (unlike |
253 the state type and there is no type quantification available in HOL (unlike |
254 in Coq, for example).\footnote{Slind already pointed out this problem in an email |
254 in Coq, for example).\footnote{Slind already pointed out this problem in an email |
255 to the HOL4 mailing list on 21st April 2005.} |
255 to the HOL4 mailing list on 21st April 2005.} |
256 |
256 |
257 An alternative, which provides us with a single type for automata, is to give every |
257 An alternative, which provides us with a single type for automata, is to give every |
303 lexing. Berghofer and Reiter \cite{BerghoferReiter09} formalise automata |
303 lexing. Berghofer and Reiter \cite{BerghoferReiter09} formalise automata |
304 working over bit strings in the context of Presburger arithmetic. The only |
304 working over bit strings in the context of Presburger arithmetic. The only |
305 larger formalisations of automata theory are carried out in Nuprl |
305 larger formalisations of automata theory are carried out in Nuprl |
306 \cite{Constable00} and in Coq \cite{Filliatre97}. |
306 \cite{Constable00} and in Coq \cite{Filliatre97}. |
307 |
307 |
308 Also one might consider automata theory as a well-worn stock subject where |
308 Also one might consider automata theory and regular languages as a well-worn |
309 everything is crystal clear. However, paper proofs about automata often |
309 stock subject where everything is crystal clear. However, paper proofs about |
310 involve subtle side-conditions which are easily overlooked, but which make |
310 automata often involve subtle side-conditions which are easily overlooked, |
311 formal reasoning rather painful. For example Kozen's proof of the |
311 but which make formal reasoning rather painful. For example Kozen's proof of |
312 Myhill-Nerode theorem requires that automata do not have inaccessible |
312 the Myhill-Nerode theorem requires that automata do not have inaccessible |
313 states \cite{Kozen97}. Another subtle side-condition is completeness of |
313 states \cite{Kozen97}. Another subtle side-condition is completeness of |
314 automata, that is automata need to have total transition functions and at most one |
314 automata, that is automata need to have total transition functions and at |
315 `sink' state from which there is no connection to a final state (Brzozowski |
315 most one `sink' state from which there is no connection to a final state |
316 mentions this side-condition in the context of state complexity |
316 (Brzozowski mentions this side-condition in the context of state complexity |
317 of automata \cite{Brzozowski10}). Such side-conditions mean that if we define a regular |
317 of automata \cite{Brzozowski10}). Such side-conditions mean that if we |
318 language as one for which there exists \emph{a} finite automaton that |
318 define a regular language as one for which there exists \emph{a} finite |
319 recognises all its strings (see Def.~\ref{baddef}), then we need a lemma which |
319 automaton that recognises all its strings (see Def.~\ref{baddef}), then we |
320 ensures that another equivalent one can be found satisfying the |
320 need a lemma which ensures that another equivalent one can be found |
321 side-condition. Unfortunately, such `little' and `obvious' lemmas make |
321 satisfying the side-condition. Unfortunately, such `little' and `obvious' |
322 a formalisation of automata theory a hair-pulling experience. |
322 lemmas make a formalisation of automata theory a hair-pulling experience. |
323 |
323 |
324 |
324 |
325 In this paper, we will not attempt to formalise automata theory in |
325 In this paper, we will not attempt to formalise automata theory in |
326 Isabelle/HOL nor will we attempt to formalise automata proofs from the |
326 Isabelle/HOL nor will we attempt to formalise automata proofs from the |
327 literature, but take a different approach to regular languages than is |
327 literature, but take a different approach to regular languages than is |
359 folklore. For the other part, we give two proofs: one direct proof using |
359 folklore. For the other part, we give two proofs: one direct proof using |
360 certain tagging-functions, and another indirect proof using Antimirov's |
360 certain tagging-functions, and another indirect proof using Antimirov's |
361 partial derivatives \cite{Antimirov95}. Again to our best knowledge, the |
361 partial derivatives \cite{Antimirov95}. Again to our best knowledge, the |
362 tagging-functions have not been used before to establish the Myhill-Nerode |
362 tagging-functions have not been used before to establish the Myhill-Nerode |
363 theorem. Derivatives of regular expressions have been used recently quite |
363 theorem. Derivatives of regular expressions have been used recently quite |
364 widely in the literature; partial derivatives, in contrast, attracted much |
364 widely in the literature; partial derivatives, in contrast, attract much |
365 less attention. However, partial derivatives are more suitable in the |
365 less attention. However, partial derivatives are more suitable in the |
366 context of the Myhill-Nerode theorem, since it is easier to establish |
366 context of the Myhill-Nerode theorem, since it is easier to establish |
367 formally their finiteness result. We have not found any proof that uses |
367 formally their finiteness result. We are not aware of any proof that uses |
368 either of them in order to prove the Myhill-Nerode theorem. |
368 either of them for proving the Myhill-Nerode theorem. |
369 *} |
369 *} |
370 |
370 |
371 section {* Preliminaries *} |
371 section {* Preliminaries *} |
372 |
372 |
373 text {* |
373 text {* |
410 \end{prpstn} |
410 \end{prpstn} |
411 |
411 |
412 \noindent |
412 \noindent |
413 In @{text "(ii)"} we use the notation @{term "length s"} for the length of a |
413 In @{text "(ii)"} we use the notation @{term "length s"} for the length of a |
414 string; this property states that if \mbox{@{term "[] \<notin> A"}} then the lengths of |
414 string; this property states that if \mbox{@{term "[] \<notin> A"}} then the lengths of |
415 the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}. We omit |
415 the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}. |
|
416 Property @{text "(iv)"} states that a non-empty string in @{term "A\<star>"} can |
|
417 always be split up into a non-empty prefix belonging to @{text "A"} and the |
|
418 rest being in @{term "A\<star>"}. We omit |
416 the proofs for these properties, but invite the reader to consult our |
419 the proofs for these properties, but invite the reader to consult our |
417 formalisation.\footnote{Available at \url{http://www4.in.tum.de/~urbanc/regexp.html}} |
420 formalisation.\footnote{Available at \url{http://www4.in.tum.de/~urbanc/regexp.html}} |
418 |
421 |
419 The notation in Isabelle/HOL for the quotient of a language @{text A} |
422 The notation in Isabelle/HOL for the quotient of a language @{text A} |
420 according to an equivalence relation @{term REL} is @{term "A // REL"}. We |
423 according to an equivalence relation @{term REL} is @{term "A // REL"}. We |
509 \mbox{@{thm (lhs) folds_alt_simp} @{text "= \<Union> (\<calL> ` rs)"}} |
512 \mbox{@{thm (lhs) folds_alt_simp} @{text "= \<Union> (\<calL> ` rs)"}} |
510 \end{equation} |
513 \end{equation} |
511 |
514 |
512 \noindent |
515 \noindent |
513 holds, whereby @{text "\<calL> ` rs"} stands for the |
516 holds, whereby @{text "\<calL> ` rs"} stands for the |
514 image of the set @{text rs} under function @{text "\<calL>"}. |
517 image of the set @{text rs} under function @{text "\<calL>"} defined as |
|
518 |
|
519 \begin{center} |
|
520 @{term "lang ` rs \<equiv> {lang r | r. r \<in> rs}"} |
|
521 \end{center} |
|
522 |
|
523 \noindent |
|
524 In what follows we shall use this convenient short-hand notation for images of sets |
|
525 also with other functions. |
515 *} |
526 *} |
516 |
527 |
517 |
528 |
518 section {* The Myhill-Nerode Theorem, First Part *} |
529 section {* The Myhill-Nerode Theorem, First Part *} |
519 |
530 |
1145 @{term UNIV} & @{term "UNIV // (\<approx>(lang r))"} & @{term "UNIV // R"} |
1156 @{term UNIV} & @{term "UNIV // (\<approx>(lang r))"} & @{term "UNIV // R"} |
1146 \end{tabular}} |
1157 \end{tabular}} |
1147 \end{equation} |
1158 \end{equation} |
1148 |
1159 |
1149 \noindent |
1160 \noindent |
1150 The relation @{term "\<approx>(lang r)"} partitions the set of all strings into some |
1161 The relation @{term "\<approx>(lang r)"} partitions the set of all strings, @{term UNIV}, into some |
1151 equivalence classes. To show that there are only finitely many of them, it |
1162 equivalence classes. To show that there are only finitely many of them, it |
1152 suffices to show in each induction step that another relation, say @{text |
1163 suffices to show in each induction step that another relation, say @{text |
1153 R}, has finitely many equivalence classes and refines @{term "\<approx>(lang r)"}. |
1164 R}, has finitely many equivalence classes and refines @{term "\<approx>(lang r)"}. |
1154 |
1165 |
1155 \begin{dfntn} |
1166 \begin{dfntn} |
1270 The @{const TIMES}-case is slightly more complicated. We first prove the |
1281 The @{const TIMES}-case is slightly more complicated. We first prove the |
1271 following lemma, which will aid the proof about refinement. |
1282 following lemma, which will aid the proof about refinement. |
1272 |
1283 |
1273 \begin{lmm}\label{refinement} |
1284 \begin{lmm}\label{refinement} |
1274 The relation @{text "\<^raw:$\threesim$>\<^bsub>tag\<^esub>"} refines @{term "\<approx>A"}, provided for |
1285 The relation @{text "\<^raw:$\threesim$>\<^bsub>tag\<^esub>"} refines @{term "\<approx>A"}, provided for |
1275 all strings @{text x}, @{text y} and @{text z} we have \mbox{@{text "x \<^raw:$\threesim$>\<^bsub>tag\<^esub> y"}} |
1286 all strings @{text x}, @{text y} and @{text z} we have that \mbox{@{text "x \<^raw:$\threesim$>\<^bsub>tag\<^esub> y"}} |
1276 and @{term "x @ z \<in> A"} imply @{text "y @ z \<in> A"}. |
1287 and @{term "x @ z \<in> A"} imply @{text "y @ z \<in> A"}. |
1277 \end{lmm} |
1288 \end{lmm} |
1278 |
1289 |
1279 |
1290 |
1280 \noindent |
1291 \noindent |
1281 We therefore can analyse how the strings @{text "x @ z"} are in the language |
1292 We therefore can analyse how the strings @{text "x @ z"} are in the language |
1282 @{text A} and then construct an appropriate tagging-function to infer that |
1293 @{text A} and then construct an appropriate tagging-function to infer that |
1283 @{term "y @ z"} are also in @{text A}. For this we sill need the notion of |
1294 @{term "y @ z"} are also in @{text A}. For this we will use the notion of |
1284 the set of all possible \emph{partitions} of a string |
1295 the set of all possible \emph{partitions} of a string: |
1285 |
1296 |
1286 \begin{equation} |
1297 \begin{equation} |
1287 @{thm Partitions_def} |
1298 @{thm Partitions_def} |
1288 \end{equation} |
1299 \end{equation} |
1289 |
1300 |
1290 \noindent |
1301 \noindent |
1291 If we know that @{text "(x\<^isub>p, x\<^isub>s) \<in> Partitions x"}, we will |
1302 If we know that @{text "(x\<^isub>p, x\<^isub>s) \<in> Partitions x"}, we will |
1292 refer to @{text "x\<^isub>p"} as the \emph{prefix} of the string @{text x}, |
1303 refer to @{text "x\<^isub>p"} as the \emph{prefix} of the string @{text x}, |
1293 respectively to @{text "x\<^isub>s"} as the \emph{suffix}. |
1304 and respectively to @{text "x\<^isub>s"} as the \emph{suffix}. |
1294 |
1305 |
1295 |
1306 |
1296 Now assuming @{term "x @ z \<in> A \<cdot> B"} there are only two possible ways of how to `split' |
1307 Now assuming @{term "x @ z \<in> A \<cdot> B"} there are only two possible ways of how to `split' |
1297 this string to be in @{term "A \<cdot> B"}: |
1308 this string to be in @{term "A \<cdot> B"}: |
1298 % |
1309 % |
1529 \begin{center} |
1540 \begin{center} |
1530 @{text "\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>A\<^esub> \<in> {\<lbrakk>y\<^isub>s\<rbrakk>\<^bsub>\<approx>A\<^esub> | y\<^bsub>p\<^esub> < y \<and> y\<^bsub>p\<^esub> \<in> A\<^isup>\<star> \<and> (y\<^bsub>p\<^esub>, y\<^isub>s) \<in> Partitions y}"} |
1541 @{text "\<lbrakk>x\<^isub>s\<rbrakk>\<^bsub>\<approx>A\<^esub> \<in> {\<lbrakk>y\<^isub>s\<rbrakk>\<^bsub>\<approx>A\<^esub> | y\<^bsub>p\<^esub> < y \<and> y\<^bsub>p\<^esub> \<in> A\<^isup>\<star> \<and> (y\<^bsub>p\<^esub>, y\<^isub>s) \<in> Partitions y}"} |
1531 \end{center} |
1542 \end{center} |
1532 |
1543 |
1533 \noindent |
1544 \noindent |
1534 From this we know there exist partitions @{text "y\<^isub>p"} and @{text |
1545 From this we know there exist a partition @{text "y\<^isub>p"} and @{text |
1535 "y\<^isub>s"} with @{term "y\<^isub>p \<in> A\<star>"} and also @{term "x\<^isub>s \<approx>A |
1546 "y\<^isub>s"} with @{term "y\<^isub>p \<in> A\<star>"} and also @{term "x\<^isub>s \<approx>A |
1536 y\<^isub>s"}. Unfolding the Myhill-Nerode relation we know @{term |
1547 y\<^isub>s"}. Unfolding the Myhill-Nerode relation we know @{term |
1537 "y\<^isub>s @ z\<^isub>a \<in> A"}. We also know that @{term "z\<^isub>b \<in> A\<star>"}. |
1548 "y\<^isub>s @ z\<^isub>a \<in> A"}. We also know that @{term "z\<^isub>b \<in> A\<star>"}. |
1538 Therefore @{term "y\<^isub>p @ (y\<^isub>s @ z\<^isub>a) @ z\<^isub>b \<in> |
1549 Therefore @{term "y\<^isub>p @ (y\<^isub>s @ z\<^isub>a) @ z\<^isub>b \<in> |
1539 A\<star>"}, which means @{term "y @ z \<in> A\<star>"}. As the last step we have to set |
1550 A\<star>"}, which means @{term "y @ z \<in> A\<star>"}. The last step is to set |
1540 @{text "A"} to @{term "lang r"} and thus complete the proof. |
1551 @{text "A"} to @{term "lang r"} and thus complete the proof. |
1541 \end{proof} |
1552 \end{proof} |
1542 *} |
1553 *} |
1543 |
1554 |
1544 section {* Second Part proved using Partial Derivatives *} |
1555 section {* Second Part proved using Partial Derivatives *} |
1548 As we have seen in the previous section, in order to establish |
1559 As we have seen in the previous section, in order to establish |
1549 the second direction of the Myhill-Nerode theorem, we need to find |
1560 the second direction of the Myhill-Nerode theorem, we need to find |
1550 a more refined relation than @{term "\<approx>(lang r)"} for which we can |
1561 a more refined relation than @{term "\<approx>(lang r)"} for which we can |
1551 show that there are only finitely many equivalence classes. So far we |
1562 show that there are only finitely many equivalence classes. So far we |
1552 showed this by induction on @{text "r"}. However, there is also |
1563 showed this by induction on @{text "r"}. However, there is also |
1553 an indirect method to come up with such a refined relation based on |
1564 an indirect method to come up with such a refined relation by using |
1554 derivatives of regular expressions \cite{Brzozowski64}. |
1565 derivatives of regular expressions \cite{Brzozowski64}. |
1555 |
1566 |
1556 Assume the following two definitions for a \emph{left-quotient} of a language, |
1567 Assume the following two definitions for a \emph{left-quotient} of a language, |
1557 which we write as @{term "Der c A"} and @{term "Ders s A"} where @{text c} |
1568 which we write as @{term "Der c A"} and @{term "Ders s A"} where @{text c} |
1558 is a character and @{text s} a string: |
1569 is a character and @{text s} a string: |
1563 @{thm (lhs) Ders_def} & @{text "\<equiv>"} & @{thm (rhs) Ders_def}\\ |
1574 @{thm (lhs) Ders_def} & @{text "\<equiv>"} & @{thm (rhs) Ders_def}\\ |
1564 \end{tabular} |
1575 \end{tabular} |
1565 \end{center} |
1576 \end{center} |
1566 |
1577 |
1567 \noindent |
1578 \noindent |
1568 In order to aid readability, we shall also make use of the following abbreviation: |
1579 In order to aid readability, we shall also make use of the following abbreviation |
1569 |
1580 |
1570 \begin{center} |
1581 \begin{center} |
1571 @{abbrev "Derss s A"} |
1582 @{abbrev "Derss s As"} |
1572 \end{center} |
1583 \end{center} |
1573 |
1584 |
1574 |
1585 \noindent |
1575 \noindent |
1586 where we apply the left-quotient to a set of languages and then combine the results. |
1576 Clearly we have the following relation between the Myhill-Nerode relation |
1587 Clearly we have the following relation between the Myhill-Nerode relation |
1577 (Def.~\ref{myhillneroderel}) and left-quotients |
1588 (Def.~\ref{myhillneroderel}) and left-quotients |
1578 |
1589 |
1579 \begin{equation}\label{mhders} |
1590 \begin{equation}\label{mhders} |
1580 @{term "x \<approx>A y"} \hspace{4mm}\text{if and only if}\hspace{4mm} @{term "Ders x A = Ders y A"} |
1591 @{term "x \<approx>A y"} \hspace{4mm}\text{if and only if}\hspace{4mm} @{term "Ders x A = Ders y A"} |
1581 \end{equation} |
1592 \end{equation} |
1582 |
1593 |
1583 \noindent |
1594 \noindent |
1584 It is straightforward to establish the following properties for left-quotients: |
1595 It is also straightforward to establish the following properties for left-quotients: |
1585 |
1596 |
1586 \begin{equation} |
1597 \begin{equation} |
1587 \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{2mm}}l} |
1598 \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{2mm}}l} |
1588 @{thm (lhs) Der_simps(1)} & $=$ & @{thm (rhs) Der_simps(1)}\\ |
1599 @{thm (lhs) Der_simps(1)} & $=$ & @{thm (rhs) Der_simps(1)}\\ |
1589 @{thm (lhs) Der_simps(2)} & $=$ & @{thm (rhs) Der_simps(2)}\\ |
1600 @{thm (lhs) Der_simps(2)} & $=$ & @{thm (rhs) Der_simps(2)}\\ |
1598 \end{tabular}} |
1609 \end{tabular}} |
1599 \end{equation} |
1610 \end{equation} |
1600 |
1611 |
1601 \noindent |
1612 \noindent |
1602 where @{text "\<Delta>"} is a function that tests whether the empty string |
1613 where @{text "\<Delta>"} is a function that tests whether the empty string |
1603 is in the language and returns @{term "{[]}"} or @{term "{}"}, respectively. |
1614 is in the language and returns @{term "{[]}"} or @{term "{}"}, accordingly. |
1604 The only interesting case above is the last one where we use Prop.~\ref{langprops} |
1615 The only interesting case above is the last one where we use Prop.~\ref{langprops}@{text "(i)"} |
1605 in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can |
1616 in order to infer that @{term "Der c (A\<star>) = Der c (A \<cdot> A\<star>)"}. We can |
1606 then complete the proof by observing that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}. |
1617 then complete the proof by observing that @{term "Delta A \<cdot> Der c (A\<star>) \<subseteq> (Der c A) \<cdot> A\<star>"}. |
1607 |
1618 |
1608 Brzozowski observed that the left-quotients for languages of regular |
1619 Brzozowski observed that the left-quotients for languages of regular |
1609 expressions can be calculated directly via the notion of \emph{derivatives |
1620 expressions can be calculated directly via the notion of \emph{derivatives |
1627 @{thm (lhs) ders.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) ders.simps(2)}\\ |
1638 @{thm (lhs) ders.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) ders.simps(2)}\\ |
1628 \end{tabular} |
1639 \end{tabular} |
1629 \end{center} |
1640 \end{center} |
1630 |
1641 |
1631 \noindent |
1642 \noindent |
1632 The last two clauses extend derivatives for characters to strings (list of |
1643 The last two clauses extend derivatives from characters to strings---i.e.~list of |
1633 characters). The list-cons operator is written \mbox{@{text "_ :: _"}}. The |
1644 characters. The list-cons operator is written \mbox{@{text "_ :: _"}}. The |
1634 function @{term "nullable r"} needed in the @{const Times}-case tests |
1645 function @{term "nullable r"} needed in the @{const Times}-case tests |
1635 whether a regular expression can recognise the empty string: |
1646 whether a regular expression can recognise the empty string: |
1636 |
1647 |
1637 \begin{center} |
1648 \begin{center} |
1638 \begin{tabular}{c@ {\hspace{10mm}}c} |
1649 \begin{tabular}{c@ {\hspace{10mm}}c} |
1665 |
1676 |
1666 \noindent |
1677 \noindent |
1667 The importance in the context of the Myhill-Nerode theorem is that |
1678 The importance in the context of the Myhill-Nerode theorem is that |
1668 we can use \eqref{mhders} and \eqref{Dersders} in order to |
1679 we can use \eqref{mhders} and \eqref{Dersders} in order to |
1669 establish that @{term "x \<approx>(lang r) y"} is equivalent to |
1680 establish that @{term "x \<approx>(lang r) y"} is equivalent to |
1670 @{term "lang (ders x r) = lang (ders y r)"}. From this we obtain |
1681 @{term "lang (ders x r) = lang (ders y r)"}. Hence |
1671 |
1682 |
1672 \begin{equation} |
1683 \begin{equation} |
1673 @{term "x \<approx>(lang r) y"}\hspace{4mm}\mbox{provided}\hspace{4mm}@{term "ders x r = ders y r"} |
1684 @{term "x \<approx>(lang r) y"}\hspace{4mm}\mbox{provided}\hspace{4mm}@{term "ders x r = ders y r"} |
1674 \end{equation} |
1685 \end{equation} |
1675 |
1686 |
1676 |
1687 |
1677 \noindent |
1688 \noindent |
1678 which means the right-hand side (seen as relation) refines the |
1689 which means the right-hand side (seen as relation) refines the |
1679 Myhill-Nerode relation. Consequently, we can use |
1690 Myhill-Nerode relation. Consequently, we can use |
1680 @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} as a potential tagging-relation |
1691 @{text "\<^raw:$\threesim$>\<^bsub>(\<lambda>x. ders x r)\<^esub>"} as a tagging-relation |
1681 for the regular expression @{text r}. However, in |
1692 for the regular expression @{text r}. However, in |
1682 order to be useful in the Myhill-Nerode theorem, we also have to show that |
1693 order to be useful for teh second part of the Myhill-Nerode theorem, we also have to show that |
1683 for the corresponding language there are only finitely many derivatives---ensuring |
1694 for the corresponding language there are only finitely many derivatives---thus ensuring |
1684 that there are only finitely many equivalence classes. Unfortunately, this |
1695 that there are only finitely many equivalence classes. Unfortunately, this |
1685 is not true in general. Sakarovitch gives an example where a regular |
1696 is not true in general. Sakarovitch gives an example where a regular |
1686 expression has infinitely many derivatives w.r.t.~a language |
1697 expression has infinitely many derivatives w.r.t.~a language |
1687 \cite[Page~141]{Sakarovitch09}. What Brzozowski \cite{Brzozowski64} proved |
1698 \cite[Page~141]{Sakarovitch09}. What Brzozowski \cite{Brzozowski64} proved |
1688 is that for every language there \emph{are} only finitely `dissimilar' |
1699 is that for every language there \emph{are} only finitely `dissimilar' |
1698 \end{tabular}} |
1709 \end{tabular}} |
1699 \end{equation} |
1710 \end{equation} |
1700 |
1711 |
1701 \noindent |
1712 \noindent |
1702 Carrying this idea through, we must not consider the set of all derivatives, |
1713 Carrying this idea through, we must not consider the set of all derivatives, |
1703 but the ones modulo @{text "ACI"}. In principle, this can be formally |
1714 but the ones modulo @{text "ACI"}. In principle, this can be done formally, |
1704 defined, but it is very painful in a theorem prover (since there is no |
1715 but it is very painful in a theorem prover (since there is no |
1705 direct characterisation of the set of dissimlar derivatives). |
1716 direct characterisation of the set of dissimlar derivatives). |
1706 |
1717 |
1707 |
1718 |
1708 Fortunately, there is a much simpler approach using \emph{partial |
1719 Fortunately, there is a much simpler approach using \emph{partial |
1709 derivatives}. They were introduced by Antimirov \cite{Antimirov95} and can be defined |
1720 derivatives}. They were introduced by Antimirov \cite{Antimirov95} and can be defined |
1740 \noindent |
1751 \noindent |
1741 in order to `sequence' a regular expression with a set of regular |
1752 in order to `sequence' a regular expression with a set of regular |
1742 expressions. Note that in the last clause we first build the set of partial |
1753 expressions. Note that in the last clause we first build the set of partial |
1743 derivatives w.r.t~the character @{text c}, then build the image of this set under the |
1754 derivatives w.r.t~the character @{text c}, then build the image of this set under the |
1744 function @{term "pders s"} and finally `union up' all resulting sets. It will be |
1755 function @{term "pders s"} and finally `union up' all resulting sets. It will be |
1745 convenient to introduce the following abbreviation |
1756 convenient to introduce for this the following abbreviation |
1746 |
1757 |
1747 \begin{center} |
1758 \begin{center} |
1748 @{abbrev "pderss s A"} |
1759 @{abbrev "pderss s A"} |
1749 \end{center} |
1760 \end{center} |
1750 |
1761 |
1761 taking the partial derivatives of the |
1772 taking the partial derivatives of the |
1762 regular expressions in \eqref{ACI} gives us in each case |
1773 regular expressions in \eqref{ACI} gives us in each case |
1763 equal sets. Antimirov \cite{Antimirov95} showed a similar result to |
1774 equal sets. Antimirov \cite{Antimirov95} showed a similar result to |
1764 \eqref{Dersders} for partial derivatives: |
1775 \eqref{Dersders} for partial derivatives: |
1765 |
1776 |
1766 \begin{equation} |
1777 \begin{equation}\label{Derspders} |
1767 \mbox{\begin{tabular}{lc} |
1778 \mbox{\begin{tabular}{lc} |
1768 @{text "(i)"} & @{thm Der_pder}\\ |
1779 @{text "(i)"} & @{thm Der_pder}\\ |
1769 @{text "(ii)"} & @{thm Ders_pders} |
1780 @{text "(ii)"} & @{thm Ders_pders} |
1770 \end{tabular}} |
1781 \end{tabular}} |
1771 \end{equation} |
1782 \end{equation} |
1785 |
1796 |
1786 \begin{center} |
1797 \begin{center} |
1787 \begin{tabular}{r@ {\hspace{1.5mm}}c@ {\hspace{1.5mm}}ll} |
1798 \begin{tabular}{r@ {\hspace{1.5mm}}c@ {\hspace{1.5mm}}ll} |
1788 @{term "Ders (c # s) (lang r)"} |
1799 @{term "Ders (c # s) (lang r)"} |
1789 & @{text "="} & @{term "Ders s (Der c (lang r))"} & by def.\\ |
1800 & @{text "="} & @{term "Ders s (Der c (lang r))"} & by def.\\ |
1790 & @{text "="} & @{term "Ders s (\<Union> lang ` (pder c r))"} & by @{text "(i)"}\\ |
1801 & @{text "="} & @{term "Ders s (\<Union> lang ` (pder c r))"} & by @{text "("}\ref{Derspders}@{text ".i)"}\\ |
1791 & @{text "="} & @{term "\<Union> (Ders s) ` (lang ` (pder c r))"} & by def.~of @{text "Ders"}\\ |
1802 & @{text "="} & @{term "\<Union> (Ders s) ` (lang ` (pder c r))"} & by def.~of @{text "Ders"}\\ |
1792 & @{text "="} & @{term "\<Union> lang ` (\<Union> pders s ` (pder c r))"} & by IH\\ |
1803 & @{text "="} & @{term "\<Union> lang ` (\<Union> pders s ` (pder c r))"} & by IH\\ |
1793 & @{text "="} & @{term "\<Union> lang ` (pders (c # s) r)"} & by def.\\ |
1804 & @{text "="} & @{term "\<Union> lang ` (pders (c # s) r)"} & by def.\\ |
1794 \end{tabular} |
1805 \end{tabular} |
1795 \end{center} |
1806 \end{center} |
1796 |
1807 |
1797 \noindent |
1808 \noindent |
1798 In order to apply the induction hypothesis in the fourth step, we need the generalisation |
1809 Note that in order to apply the induction hypothesis in the fourth equation, we |
1799 over all regular expressions @{text r}. The case for the empty string is routine and omitted. |
1810 need the generalisation over all regular expressions @{text r}. The case for |
|
1811 the empty string is routine and omitted. |
1800 \end{proof} |
1812 \end{proof} |
1801 |
1813 |
1802 Antimirov also proved that for every language and regular expression there are only finitely |
1814 \noindent |
1803 many partial derivatives. |
1815 Taking \eqref{Dersders} and \eqref{Derspders} together gives the relationship |
|
1816 between languages of derivatives and partial derivatives |
|
1817 |
|
1818 \begin{equation} |
|
1819 \mbox{\begin{tabular}{lc} |
|
1820 @{text "(i)"} & @{thm der_pder[symmetric]}\\ |
|
1821 @{text "(ii)"} & @{thm ders_pders[symmetric]} |
|
1822 \end{tabular}} |
|
1823 \end{equation} |
|
1824 |
|
1825 \noindent |
|
1826 These two properties confirm the observation made earlier |
|
1827 that by using sets, partial derivatives have the @{text "ACI"}-identidies |
|
1828 of derivatives already built in. |
|
1829 |
|
1830 Antimirov also proved that for every language and regular expression |
|
1831 there are only finitely many partial derivatives. |
1804 *} |
1832 *} |
1805 |
1833 |
1806 section {* Closure Properties *} |
1834 section {* Closure Properties *} |
1807 |
1835 |
1808 text {* |
1836 text {* |