doc-src/ind-defs.tex
changeset 2219 5687d7dec139
parent 2137 afc15c2fd5b5
child 2974 bb55cab416af
equal deleted inserted replaced
2218:36bb751913c6 2219:5687d7dec139
   134 definitions and proved the characteristic theorems.  Similar is Melham's
   134 definitions and proved the characteristic theorems.  Similar is Melham's
   135 recursive type package for the Cambridge \textsc{hol} system~\cite{melham89}.
   135 recursive type package for the Cambridge \textsc{hol} system~\cite{melham89}.
   136 Such data structures are called \defn{datatypes}
   136 Such data structures are called \defn{datatypes}
   137 below, by analogy with datatype declarations in Standard~\textsc{ml}\@.
   137 below, by analogy with datatype declarations in Standard~\textsc{ml}\@.
   138 Some logics take datatypes as primitive; consider Boyer and Moore's shell
   138 Some logics take datatypes as primitive; consider Boyer and Moore's shell
   139 principle~\cite{bm79} and the Coq type theory~\cite{paulin92}.
   139 principle~\cite{bm79} and the Coq type theory~\cite{paulin-tlca}.
   140 
   140 
   141 A datatype is but one example of an \defn{inductive definition}.  This
   141 A datatype is but one example of an \defn{inductive definition}.  This
   142 specifies the least set closed under given rules~\cite{aczel77}.  The
   142 specifies the least set closed under given rules~\cite{aczel77}.  The
   143 collection of theorems in a logic is inductively defined.  A structural
   143 collection of theorems in a logic is inductively defined.  A structural
   144 operational semantics~\cite{hennessy90} is an inductive definition of a
   144 operational semantics~\cite{hennessy90} is an inductive definition of a
   145 reduction or evaluation relation on programs.  A few theorem provers
   145 reduction or evaluation relation on programs.  A few theorem provers
   146 provide commands for formalizing inductive definitions; these include
   146 provide commands for formalizing inductive definitions; these include
   147 Coq~\cite{paulin92} and again the \textsc{hol} system~\cite{camilleri92}.
   147 Coq~\cite{paulin-tlca} and again the \textsc{hol} system~\cite{camilleri92}.
   148 
   148 
   149 The dual notion is that of a \defn{coinductive definition}.  This specifies
   149 The dual notion is that of a \defn{coinductive definition}.  This specifies
   150 the greatest set closed under given rules.  Important examples include
   150 the greatest set closed under given rules.  Important examples include
   151 using bisimulation relations to formalize equivalence of
   151 using bisimulation relations to formalize equivalence of
   152 processes~\cite{milner89} or lazy functional programs~\cite{abramsky90}.
   152 processes~\cite{milner89} or lazy functional programs~\cite{abramsky90}.
   244 
   244 
   245 The definition may involve arbitrary parameters $\vec{p}=p_1$,
   245 The definition may involve arbitrary parameters $\vec{p}=p_1$,
   246 \ldots,~$p_k$.  Each recursive set then has the form $R_i(\vec{p})$.  The
   246 \ldots,~$p_k$.  Each recursive set then has the form $R_i(\vec{p})$.  The
   247 parameters must be identical every time they occur within a definition.  This
   247 parameters must be identical every time they occur within a definition.  This
   248 would appear to be a serious restriction compared with other systems such as
   248 would appear to be a serious restriction compared with other systems such as
   249 Coq~\cite{paulin92}.  For instance, we cannot define the lists of
   249 Coq~\cite{paulin-tlca}.  For instance, we cannot define the lists of
   250 $n$ elements as the set $\listn(A,n)$ using rules where the parameter~$n$
   250 $n$ elements as the set $\listn(A,n)$ using rules where the parameter~$n$
   251 varies.  Section~\ref{listn-sec} describes how to express this set using the
   251 varies.  Section~\ref{listn-sec} describes how to express this set using the
   252 inductive definition package.
   252 inductive definition package.
   253 
   253 
   254 To avoid clutter below, the recursive sets are shown as simply $R_i$
   254 To avoid clutter below, the recursive sets are shown as simply $R_i$
   547 rule is {\tt Fin.induct}.
   547 rule is {\tt Fin.induct}.
   548 
   548 
   549 
   549 
   550 \subsection{Lists of $n$ elements}\label{listn-sec}
   550 \subsection{Lists of $n$ elements}\label{listn-sec}
   551 This has become a standard example of an inductive definition.  Following
   551 This has become a standard example of an inductive definition.  Following
   552 Paulin-Mohring~\cite{paulin92}, we could attempt to define a new datatype
   552 Paulin-Mohring~\cite{paulin-tlca}, we could attempt to define a new datatype
   553 $\listn(A,n)$, for lists of length~$n$, as an $n$-indexed family of sets.
   553 $\listn(A,n)$, for lists of length~$n$, as an $n$-indexed family of sets.
   554 But her introduction rules
   554 But her introduction rules
   555 \[ \hbox{\tt Niln}\in\listn(A,0)  \qquad
   555 \[ \hbox{\tt Niln}\in\listn(A,0)  \qquad
   556    \infer{\hbox{\tt Consn}(n,a,l)\in\listn(A,\succ(n))}
   556    \infer{\hbox{\tt Consn}(n,a,l)\in\listn(A,\succ(n))}
   557          {n\in\nat & a\in A & l\in\listn(A,n)}
   557          {n\in\nat & a\in A & l\in\listn(A,n)}
   733 no infinite decreasing chains~\cite{aczel77}.  Formally, $\acc(\prec)$ is
   733 no infinite decreasing chains~\cite{aczel77}.  Formally, $\acc(\prec)$ is
   734 inductively defined to be the least set that contains $a$ if it contains
   734 inductively defined to be the least set that contains $a$ if it contains
   735 all $\prec$-predecessors of~$a$, for $a\in D$.  Thus we need an
   735 all $\prec$-predecessors of~$a$, for $a\in D$.  Thus we need an
   736 introduction rule of the form 
   736 introduction rule of the form 
   737 \[ \infer{a\in\acc(\prec)}{\forall y.y\prec a\imp y\in\acc(\prec)} \]
   737 \[ \infer{a\in\acc(\prec)}{\forall y.y\prec a\imp y\in\acc(\prec)} \]
   738 Paulin-Mohring treats this example in Coq~\cite{paulin92}, but it causes
   738 Paulin-Mohring treats this example in Coq~\cite{paulin-tlca}, but it causes
   739 difficulties for other systems.  Its premise is not acceptable to the
   739 difficulties for other systems.  Its premise is not acceptable to the
   740 inductive definition package of the Cambridge \textsc{hol}
   740 inductive definition package of the Cambridge \textsc{hol}
   741 system~\cite{camilleri92}.  It is also unacceptable to the Isabelle package
   741 system~\cite{camilleri92}.  It is also unacceptable to the Isabelle package
   742 (recall \S\ref{intro-sec}), but fortunately can be transformed into the
   742 (recall \S\ref{intro-sec}), but fortunately can be transformed into the
   743 acceptable form $t\in M(R)$.
   743 acceptable form $t\in M(R)$.
  1210 complex; earlier versions of Martin-L\"of's type theory could (using
  1210 complex; earlier versions of Martin-L\"of's type theory could (using
  1211 wellordering types) express datatype definitions, but the version underlying
  1211 wellordering types) express datatype definitions, but the version underlying
  1212 \textsc{alf} requires new rules for each definition~\cite{dybjer91}.  With Coq
  1212 \textsc{alf} requires new rules for each definition~\cite{dybjer91}.  With Coq
  1213 the situation is subtler still; its underlying Calculus of Constructions can
  1213 the situation is subtler still; its underlying Calculus of Constructions can
  1214 express inductive definitions~\cite{huet88}, but cannot quite handle datatype
  1214 express inductive definitions~\cite{huet88}, but cannot quite handle datatype
  1215 definitions~\cite{paulin92}.  It seems that researchers tried hard to
  1215 definitions~\cite{paulin-tlca}.  It seems that researchers tried hard to
  1216 circumvent these problems before finally extending the Calculus with rule
  1216 circumvent these problems before finally extending the Calculus with rule
  1217 schemes for strictly positive operators.  Recently Gim{\'e}nez has extended
  1217 schemes for strictly positive operators.  Recently Gim{\'e}nez has extended
  1218 the Calculus of Constructions with inductive and coinductive
  1218 the Calculus of Constructions with inductive and coinductive
  1219 types~\cite{gimenez-codifying}, with mechanized support in Coq.
  1219 types~\cite{gimenez-codifying}, with mechanized support in Coq.
  1220 
  1220 
  1412   monos      {\it monotonicity theorems}
  1412   monos      {\it monotonicity theorems}
  1413   con_defs   {\it constructor definitions}
  1413   con_defs   {\it constructor definitions}
  1414   type_intrs {\it introduction rules for type-checking}
  1414   type_intrs {\it introduction rules for type-checking}
  1415   type_elims {\it elimination rules for type-checking}
  1415   type_elims {\it elimination rules for type-checking}
  1416 \end{ttbox}
  1416 \end{ttbox}
  1417 A coinductive definition is identical save that it starts with the keyword
  1417 A coinductive definition is identical, but starts with the keyword
  1418 {\tt coinductive}.  
  1418 {\tt coinductive}.  
  1419 
  1419 
  1420 The {\tt monos}, {\tt con\_defs}, {\tt type\_intrs} and {\tt type\_elims}
  1420 The {\tt monos}, {\tt con\_defs}, {\tt type\_intrs} and {\tt type\_elims}
  1421 sections are optional.  If present, each is specified as a string, which
  1421 sections are optional.  If present, each is specified as a string, which
  1422 must be a valid \textsc{ml} expression of type {\tt thm list}.  It is simply
  1422 must be a valid \textsc{ml} expression of type {\tt thm list}.  It is simply
  1547   definition involves the set parameters $A_1$, \ldots, $A_k$.  Then
  1547   definition involves the set parameters $A_1$, \ldots, $A_k$.  Then
  1548   $\univ(A_1\un\cdots\un A_k)$ is used for a datatype definition and
  1548   $\univ(A_1\un\cdots\un A_k)$ is used for a datatype definition and
  1549   $\quniv(A_1\un\cdots\un A_k)$ is used for a codatatype definition.
  1549   $\quniv(A_1\un\cdots\un A_k)$ is used for a codatatype definition.
  1550 
  1550 
  1551   These choices should work for all finitely-branching (co)datatype
  1551   These choices should work for all finitely-branching (co)datatype
  1552   definitions.  For examples of infinitely-branching datatype
  1552   definitions.  For examples of infinitely-branching datatypes, 
  1553   definitions, see the file {\tt ZF/ex/Brouwer.thy}.
  1553   see file {\tt ZF/ex/Brouwer.thy}.
  1554 
  1554 
  1555 \item[\it datatype declaration] has the form
  1555 \item[\it datatype declaration] has the form
  1556 \begin{quote}
  1556 \begin{quote}
  1557  {\it string\/} {\tt =} {\it constructor} {\tt|} {\it constructor} {\tt|}
  1557  {\it string\/} {\tt =} {\it constructor} {\tt|} {\it constructor} {\tt|}
  1558  \ldots 
  1558  \ldots