1 \documentstyle[12pt,a4,proof,lcp,alltt,amssymbols]{article} |
1 \documentstyle[12pt,a4,proof,lcp,alltt,amssymbols]{article} |
|
2 \hyphenation{data-type} |
2 %CADE version should use 11pt and the Springer style |
3 %CADE version should use 11pt and the Springer style |
3 \newif\ifCADE |
4 \newif\ifCADE |
4 \CADEfalse |
5 \CADEfalse |
5 |
6 |
6 \title{A Fixedpoint Approach to Implementing (Co)Inductive |
7 \title{A Fixedpoint Approach to Implementing (Co)Inductive |
95 \newcommand\qsplit{{\tt qsplit}} |
96 \newcommand\qsplit{{\tt qsplit}} |
96 \newcommand\qcase{{\tt qcase}} |
97 \newcommand\qcase{{\tt qcase}} |
97 \newcommand\Con{{\tt Con}} |
98 \newcommand\Con{{\tt Con}} |
98 \newcommand\data{{\tt data}} |
99 \newcommand\data{{\tt data}} |
99 |
100 |
100 \sloppy |
|
101 \binperiod %%%treat . like a binary operator |
101 \binperiod %%%treat . like a binary operator |
102 |
102 |
103 \begin{document} |
103 \begin{document} |
104 \pagestyle{empty} |
104 \pagestyle{empty} |
105 \begin{titlepage} |
105 \begin{titlepage} |
106 \maketitle |
106 \maketitle |
107 \begin{abstract} |
107 \begin{abstract} |
108 Several theorem provers provide commands for formalizing recursive |
108 Several theorem provers provide commands for formalizing recursive |
109 datatypes and/or inductively defined sets. This paper presents a new |
109 data\-types or inductively defined sets. This paper presents a new |
110 approach, based on fixedpoint definitions. It is unusually general: |
110 approach, based on fixedpoint definitions. It is unusually general: it |
111 it admits all monotone inductive definitions. It is conceptually simple, |
111 admits all provably monotone inductive definitions. It is conceptually |
112 which has allowed the easy implementation of mutual recursion and other |
112 simple, which has allowed the easy implementation of mutual recursion and |
113 conveniences. It also handles coinductive definitions: simply replace |
113 other conveniences. It also handles coinductive definitions: simply |
114 the least fixedpoint by a greatest fixedpoint. This represents the first |
114 replace the least fixedpoint by a greatest fixedpoint. This represents |
115 automated support for coinductive definitions. |
115 the first automated support for coinductive definitions. |
116 |
116 |
117 The method has been implemented in Isabelle's formalization of ZF set |
117 The method has been implemented in Isabelle's formalization of ZF set |
118 theory. It should |
118 theory. It should be applicable to any logic in which the Knaster-Tarski |
119 be applicable to any logic in which the Knaster-Tarski Theorem can be |
119 Theorem can be proved. The paper briefly describes a method of |
120 proved. The paper briefly describes a method of formalizing |
120 formalizing non-well-founded data structures in standard ZF set theory. |
121 non-well-founded data structures in standard ZF set theory. |
|
122 |
121 |
123 Examples include lists of $n$ elements, the accessible part of a relation |
122 Examples include lists of $n$ elements, the accessible part of a relation |
124 and the set of primitive recursive functions. One example of a |
123 and the set of primitive recursive functions. One example of a |
125 coinductive definition is bisimulations for lazy lists. \ifCADE\else |
124 coinductive definition is bisimulations for lazy lists. \ifCADE\else |
126 Recursive datatypes are examined in detail, as well as one example of a |
125 Recursive datatypes are examined in detail, as well as one example of a |
227 that $\lfp$ must be the least fixedpoint, and $\gfp$ the greatest. |
226 that $\lfp$ must be the least fixedpoint, and $\gfp$ the greatest. |
228 |
227 |
229 This fixedpoint theory is simple. The Knaster-Tarski theorem is easy to |
228 This fixedpoint theory is simple. The Knaster-Tarski theorem is easy to |
230 prove. Showing monotonicity of~$h$ is trivial, in typical cases. We must |
229 prove. Showing monotonicity of~$h$ is trivial, in typical cases. We must |
231 also exhibit a bounding set~$D$ for~$h$. Sometimes this is trivial, as |
230 also exhibit a bounding set~$D$ for~$h$. Sometimes this is trivial, as |
232 when a set of ``theorems'' is (co)inductively defined over some previously |
231 when a set of `theorems' is (co)inductively defined over some previously |
233 existing set of ``formulae.'' But defining the bounding set for |
232 existing set of `formulae.' But defining the bounding set for |
234 (co)datatype definitions requires some effort; see~\S\ref{univ-sec} below. |
233 (co)datatype definitions requires some effort; see~\S\ref{univ-sec} below. |
235 |
234 |
236 |
235 |
237 \section{Elements of an inductive or coinductive definition}\label{basic-sec} |
236 \section{Elements of an inductive or coinductive definition}\label{basic-sec} |
238 Consider a (co)inductive definition of the sets $R_1$, \ldots,~$R_n$, in |
237 Consider a (co)inductive definition of the sets $R_1$, \ldots,~$R_n$, in |
532 involves mostly introduction rules. When the package returns, we can refer |
531 involves mostly introduction rules. When the package returns, we can refer |
533 to the $\Fin(A)$ introduction rules as {\tt Fin.intrs}, the induction rule |
532 to the $\Fin(A)$ introduction rules as {\tt Fin.intrs}, the induction rule |
534 as {\tt Fin.induct}, and so forth. |
533 as {\tt Fin.induct}, and so forth. |
535 |
534 |
536 \subsection{Lists of $n$ elements}\label{listn-sec} |
535 \subsection{Lists of $n$ elements}\label{listn-sec} |
537 This has become a standard example in the |
536 This has become a standard example of an inductive definition. Following |
538 literature. Following Paulin-Mohring~\cite{paulin92}, we could attempt to |
537 Paulin-Mohring~\cite{paulin92}, we could attempt to define a new datatype |
539 define a new datatype $\listn(A,n)$, for lists of length~$n$, as an $n$-indexed |
538 $\listn(A,n)$, for lists of length~$n$, as an $n$-indexed family of sets. |
540 family of sets. But her introduction rules |
539 But her introduction rules |
541 \[ {\tt Niln}\in\listn(A,0) \qquad |
540 \[ {\tt Niln}\in\listn(A,0) \qquad |
542 \infer{{\tt Consn}(n,a,l)\in\listn(A,\succ(n))} |
541 \infer{{\tt Consn}(n,a,l)\in\listn(A,\succ(n))} |
543 {n\in\nat & a\in A & l\in\listn(A,n)} |
542 {n\in\nat & a\in A & l\in\listn(A,n)} |
544 \] |
543 \] |
545 are not acceptable to the inductive definition package: |
544 are not acceptable to the inductive definition package: |
626 x = \pair{\succ(n),\Cons(a,l)} \\ |
625 x = \pair{\succ(n),\Cons(a,l)} \\ |
627 a\in A \\ |
626 a\in A \\ |
628 \pair{n,l}\in\listn(A) |
627 \pair{n,l}\in\listn(A) |
629 \end{array} \right]_{a,l,n}}} |
628 \end{array} \right]_{a,l,n}}} |
630 \] |
629 \] |
631 The ML function {\tt ListN.mk\_cases} generates simplified instances of this |
630 The ML function {\tt ListN.mk\_cases} generates simplified instances of |
632 rule. It works by freeness reasoning on the list constructors: $\Cons$ is |
631 this rule. It works by freeness reasoning on the list constructors: |
633 injective and $\Cons(a,l)\not=\Nil$. If $x$ is $\pair{i,\Nil}$ or |
632 $\Cons(a,l)$ is injective in its two arguments and differs from~$\Nil$. If |
634 $\pair{i,\Cons(a,l)}$ then {\tt ListN.mk\_cases} deduces the corresponding |
633 $x$ is $\pair{i,\Nil}$ or $\pair{i,\Cons(a,l)}$ then {\tt ListN.mk\_cases} |
635 form of~$i$. For example, |
634 deduces the corresponding form of~$i$. For example, |
636 \begin{ttbox} |
635 \begin{ttbox} |
637 ListN.mk_cases List.con_defs "<i,Cons(a,l)> : listn(A)" |
636 ListN.mk_cases List.con_defs "<i,Cons(a,l)> : listn(A)" |
638 \end{ttbox} |
637 \end{ttbox} |
639 yields a rule with only two premises: |
638 yields a rule with only two premises: |
640 \[ \infer{Q}{\pair{i, \Cons(a,l)}\in\listn(A) & |
639 \[ \infer{Q}{\pair{i, \Cons(a,l)}\in\listn(A) & |
945 is an alternative to adopting Aczel's Anti-Foundation |
944 is an alternative to adopting Aczel's Anti-Foundation |
946 Axiom~\cite{aczel88}. |
945 Axiom~\cite{aczel88}. |
947 |
946 |
948 \subsection{The case analysis operator} |
947 \subsection{The case analysis operator} |
949 The (co)datatype package automatically defines a case analysis operator, |
948 The (co)datatype package automatically defines a case analysis operator, |
950 called {\tt$R$\_case}. A mutually recursive definition still has only |
949 called {\tt$R$\_case}. A mutually recursive definition still has only one |
951 one operator, called {\tt$R_1$\_\ldots\_$R_n$\_case}. The case operator is |
950 operator, whose name combines those of the recursive sets: it is called |
952 analogous to those for products and sums. |
951 {\tt$R_1$\_\ldots\_$R_n$\_case}. The case operator is analogous to those |
|
952 for products and sums. |
953 |
953 |
954 Datatype definitions employ standard products and sums, whose operators are |
954 Datatype definitions employ standard products and sums, whose operators are |
955 $\split$ and $\case$ and satisfy the equations |
955 $\split$ and $\case$ and satisfy the equations |
956 \begin{eqnarray*} |
956 \begin{eqnarray*} |
957 \split(f,\pair{x,y}) & = & f(x,y) \\ |
957 \split(f,\pair{x,y}) & = & f(x,y) \\ |
1517 equivalences or elimination rules. |
1517 equivalences or elimination rules. |
1518 \end{description} |
1518 \end{description} |
1519 |
1519 |
1520 The result structure also inherits everything from the underlying |
1520 The result structure also inherits everything from the underlying |
1521 (co)inductive definition, such as the introduction rules, elimination rule, |
1521 (co)inductive definition, such as the introduction rules, elimination rule, |
1522 and induction/coinduction rule. |
1522 and (co)induction rule. |
1523 |
1523 |
1524 |
1524 |
1525 \begin{figure} |
1525 \begin{figure} |
1526 \begin{ttbox} |
1526 \begin{ttbox} |
1527 sig |
1527 sig |
1574 $\quniv(A)$ contains~$A$ and is closed under the variant Cartesian products |
1574 $\quniv(A)$ contains~$A$ and is closed under the variant Cartesian products |
1575 and disjoint sums; the appropriate domain is |
1575 and disjoint sums; the appropriate domain is |
1576 $\quniv(A_1\un\cdots\un A_k)$. |
1576 $\quniv(A_1\un\cdots\un A_k)$. |
1577 |
1577 |
1578 The {\tt sintrs} specify the introduction rules, which govern the recursive |
1578 The {\tt sintrs} specify the introduction rules, which govern the recursive |
1579 structure of the datatype. Introduction rules may involve monotone operators |
1579 structure of the datatype. Introduction rules may involve monotone |
1580 and side-conditions to express things that go beyond the usual notion of |
1580 operators and side-conditions to express things that go beyond the usual |
1581 datatype. The theorem lists {\tt monos}, {\tt type\_intrs} and {\tt |
1581 notion of datatype. The theorem lists {\tt monos}, {\tt type\_intrs} and |
1582 type\_elims} should contain precisely what is needed for the underlying |
1582 {\tt type\_elims} should contain precisely what is needed for the |
1583 (co)inductive definition. Isabelle/ZF defines theorem lists that can be |
1583 underlying (co)inductive definition. Isabelle/ZF defines lists of |
1584 defined for the latter two components: |
1584 type-checking rules that can be supplied for the latter two components: |
1585 \begin{itemize} |
1585 \begin{itemize} |
1586 \item {\tt datatype\_intrs} and {\tt datatype\_elims} are type-checking rules |
1586 \item {\tt datatype\_intrs} and {\tt datatype\_elims} are rules |
1587 for $\univ(A)$. |
1587 for $\univ(A)$. |
1588 \item {\tt co\_datatype\_intrs} and {\tt co\_datatype\_elims} are type-checking |
1588 \item {\tt co\_datatype\_intrs} and {\tt co\_datatype\_elims} are |
1589 rules for $\quniv(A)$. |
1589 rules for $\quniv(A)$. |
1590 \end{itemize} |
1590 \end{itemize} |
1591 In typical definitions, these theorem lists need not be supplemented with |
1591 In typical definitions, these theorem lists need not be supplemented with |
1592 other theorems. |
1592 other theorems. |
1593 |
1593 |