doc-src/Logics/HOL.tex
changeset 3315 16d603a560d8
parent 3287 078be5581967
child 3487 62a6a08471e4
equal deleted inserted replaced
3314:ddb36bc2f014 3315:16d603a560d8
  1578   \List{P~x@{r@{m1}}; \dots; P~x@{r@{ml@m}}} &
  1578   \List{P~x@{r@{m1}}; \dots; P~x@{r@{ml@m}}} &
  1579   \Imp & P \, (C@m~x@1~\dots~x@{k@m})
  1579   \Imp & P \, (C@m~x@1~\dots~x@{k@m})
  1580 \end{array}}
  1580 \end{array}}
  1581 \]
  1581 \]
  1582 where $\{r@{j1},\dots,r@{jl@j}\} = \{i \in \{1,\dots k@j\} ~\mid~ \tau@{ji}
  1582 where $\{r@{j1},\dots,r@{jl@j}\} = \{i \in \{1,\dots k@j\} ~\mid~ \tau@{ji}
  1583 = (\alpha@1,\dots,\alpha@n)t \}$, i.e.\ the property $P$ can be assumed for
  1583 = (\alpha@1,\dots,\alpha@n)t \} =: Rec@j$, i.e.\ the property $P$ can be
  1584 all arguments of the recursive type.
  1584 assumed for all arguments of the recursive type.
  1585 
  1585 
  1586 \medskip The type also comes with an \ML-like \sdx{case}-construct:
  1586 For convenience, the following additional constructions are predefined for
       
  1587 each datatype.
       
  1588 
       
  1589 \subsubsection{\sdx{case}}
       
  1590 
       
  1591 The type comes with an \ML-like \texttt{case}-construct:
  1587 \[
  1592 \[
  1588 \begin{array}{rrcl}
  1593 \begin{array}{rrcl}
  1589 \mbox{\tt case}~e~\mbox{\tt of} & C@1~x@{11}~\dots~x@{1k@1} & \To & e@1 \\
  1594 \mbox{\tt case}~e~\mbox{\tt of} & C@1~x@{11}~\dots~x@{1k@1} & \To & e@1 \\
  1590                            \vdots \\
  1595                            \vdots \\
  1591                            \mid & C@m~x@{m1}~\dots~x@{mk@m} & \To & e@m
  1596                            \mid & C@m~x@{m1}~\dots~x@{mk@m} & \To & e@m
  1597 In contrast to \ML, {\em all} constructors must be present, their order is
  1602 In contrast to \ML, {\em all} constructors must be present, their order is
  1598 fixed, and nested patterns are not supported (with the exception of tuples).
  1603 fixed, and nested patterns are not supported (with the exception of tuples).
  1599 Violating this restriction results in strange error messages.
  1604 Violating this restriction results in strange error messages.
  1600 \end{warn}
  1605 \end{warn}
  1601 
  1606 
       
  1607 \subsubsection{\cdx{size}}
       
  1608 
       
  1609 Theory \texttt{Arith} declares an overloaded function \texttt{size} of type
       
  1610 $\alpha\To nat$. Each datatype defines a particular instance of \texttt{size}
       
  1611 according to the following scheme:
       
  1612 \[
       
  1613 size(C@j~x@{j1}~\dots~x@{jk@1}) =
       
  1614 \left\{
       
  1615 \begin{array}{ll}
       
  1616 0 & \mbox{if $Rec@j = \emptyset$} \\
       
  1617 size(x@{r@{j1}}) + \cdots + size(x@{r@{jl@j}}) + 1 &
       
  1618  \mbox{if $Rec@j = \{r@{j1},\dots,r@{jl@j}\}$}
       
  1619 \end{array}
       
  1620 \right.
       
  1621 \]
       
  1622 where $Rec@j$ is defined above. Viewing datatypes as generalized trees, the
       
  1623 size of a leaf is 0 and the size of a node is the sum of the sizes of its
       
  1624 subtrees $+1$.
  1602 
  1625 
  1603 \subsection{Defining datatypes}
  1626 \subsection{Defining datatypes}
  1604 
  1627 
  1605 A datatype is defined in a theory definition file using the keyword
  1628 A datatype is defined in a theory definition file using the keyword
  1606 {\tt datatype}. The definition following this must conform to the
  1629 {\tt datatype}. The definition following this must conform to the
  1621 \caption{Syntax of datatype declarations}
  1644 \caption{Syntax of datatype declarations}
  1622 \label{datatype-grammar}
  1645 \label{datatype-grammar}
  1623 \end{figure}
  1646 \end{figure}
  1624 
  1647 
  1625 \begin{warn}
  1648 \begin{warn}
  1626   If there are 7 or more constructors, the {\it t\_ord} scheme is used
  1649   Every theory containing a datatype declaration must be based, directly or
  1627   for distinctness theorems.  In this case the theory {\tt Arith} must
  1650   indirectly, on the theory {\tt Arith}, if necessary by including it
  1628   be contained in the current theory, if necessary by including it
       
  1629   explicitly as a parent.
  1651   explicitly as a parent.
  1630 \end{warn}
  1652 \end{warn}
  1631 
  1653 
  1632 Most of the theorems about the datatype become part of the default simpset
  1654 Most of the theorems about the datatype become part of the default simpset
  1633 and you never need to see them again because the simplifier applies them
  1655 and you never need to see them again because the simplifier applies them
  1639 \end{ttdescription}
  1661 \end{ttdescription}
  1640 In some cases, induction is overkill and a case distinction over all
  1662 In some cases, induction is overkill and a case distinction over all
  1641 constructors of the datatype suffices:
  1663 constructors of the datatype suffices:
  1642 \begin{ttdescription}
  1664 \begin{ttdescription}
  1643 \item[\ttindexbold{exhaust_tac} {\tt"}$u${\tt"} $i$]
  1665 \item[\ttindexbold{exhaust_tac} {\tt"}$u${\tt"} $i$]
  1644  performs an exhaustive case analysis for an arbitrary term $u$ whose type
  1666  performs an exhaustive case analysis for the term $u$ whose type
  1645  must be a datatyp or type {\tt nat}. If the datatype has $n$ constructors
  1667  must be a datatyp or type {\tt nat}. If the datatype has $n$ constructors
  1646  $C@1$, \dots $C@n$, subgoal $i$ is replaced by $n$ new subgoals which
  1668  $C@1$, \dots $C@n$, subgoal $i$ is replaced by $n$ new subgoals which
  1647  contain the additional assumption $u = C@j~x@1~\dots~x@{k@j}$ for
  1669  contain the additional assumption $u = C@j~x@1~\dots~x@{k@j}$ for
  1648  $j=1,\dots,n$.
  1670  $j=1,\dots,n$.
  1649 
       
  1650 Note that in contrast to induction, exhaustion is possible even if $u$
       
  1651 mentions identifiers that occur in the assumptions of the subgoal.
       
  1652 \end{ttdescription}
  1671 \end{ttdescription}
       
  1672 \begin{warn}
       
  1673   Induction is only allowed on a free variable that should not occur among
       
  1674   the premises of the subgoal. Exhaustion is works for arbitrary terms.
       
  1675 \end{warn}
       
  1676 \bigskip
       
  1677 
  1653 
  1678 
  1654 For the technically minded, we give a more detailed description.
  1679 For the technically minded, we give a more detailed description.
  1655 Reading the theory file produces a structure which, in addition to the
  1680 Reading the theory file produces an \ML\ structure which, in addition to the
  1656 usual components, contains a structure named $t$ for each datatype $t$
  1681 usual components, contains a structure named $t$ for each datatype $t$
  1657 defined in the file. Each structure $t$ contains the following
  1682 defined in the file. Each structure $t$ contains the following
  1658 elements:
  1683 elements:
  1659 \begin{ttbox}
  1684 \begin{ttbox}
  1660 val distinct : thm list
  1685 val distinct : thm list
  1897 definitions.  They may be intermixed with other declarations; in
  1922 definitions.  They may be intermixed with other declarations; in
  1898 particular, the (co)inductive sets {\bf must} be declared separately as
  1923 particular, the (co)inductive sets {\bf must} be declared separately as
  1899 constants, and may have mixfix syntax or be subject to syntax translations.
  1924 constants, and may have mixfix syntax or be subject to syntax translations.
  1900 
  1925 
  1901 Each (co)inductive definition adds definitions to the theory and also
  1926 Each (co)inductive definition adds definitions to the theory and also
  1902 proves some theorems.  Each definition creates an ML structure, which is a
  1927 proves some theorems.  Each definition creates an \ML\ structure, which is a
  1903 substructure of the main theory structure.
  1928 substructure of the main theory structure.
  1904 
  1929 
  1905 This package is derived from the \ZF\ one, described in a separate
  1930 This package is derived from the \ZF\ one, described in a separate
  1906 paper,\footnote{It appeared in CADE~\cite{paulson-CADE}, a longer
  1931 paper,\footnote{It appeared in CADE~\cite{paulson-CADE}, a longer
  1907   version is distributed with Isabelle.} which you should refer to in
  1932   version is distributed with Isabelle.} which you should refer to in