doc-src/Logics/CHOL.tex
changeset 1162 7be0684950a3
parent 1113 dd7284573601
child 1163 c080ff36d24e
equal deleted inserted replaced
1161:1831ba01c90c 1162:7be0684950a3
     1 %% $Id$
     1 %% $Id$
     2 \chapter{Higher-Order Logic}
     2 \chapter{Higher-Order Logic}
     3 \index{higher-order logic|(}
     3 \index{higher-order logic|(}
     4 \index{CHOL system@{\sc chol} system}
     4 \index{HOL system@{\sc chol} system}
     5 
     5 
     6 The theory~\thydx{CHOL} implements higher-order logic with curried
     6 The theory~\thydx{HOL} implements higher-order logic.  It is based on
     7 function application.  It is based on Gordon's~{\sc hol}
     7 Gordon's~{\sc hol} system~\cite{mgordon-hol}, which itself is based on
     8 system~\cite{mgordon-hol}, which itself is based on Church's original
     8 Church's original paper~\cite{church40}.  Andrews's book~\cite{andrews86} is a
     9 paper~\cite{church40}.  Andrews's book~\cite{andrews86} is a full
     9 full description of higher-order logic.  Experience with the {\sc hol} system
    10 description of higher-order logic.  Experience with the {\sc hol}
    10 has demonstrated that higher-order logic is useful for hardware verification;
    11 system has demonstrated that higher-order logic is useful for hardware
    11 beyond this, it is widely applicable in many areas of mathematics.  It is
    12 verification; beyond this, it is widely applicable in many areas of
    12 weaker than {\ZF} set theory but for most applications this does not matter.
    13 mathematics.  It is weaker than {\ZF} set theory but for most
    13 If you prefer {\ML} to Lisp, you will probably prefer \HOL\ to~{\ZF}.
    14 applications this does not matter.  If you prefer {\ML} to Lisp, you
    14 
    15 will probably prefer \CHOL\ to~{\ZF}.
    15 The syntax of Isabelle's \HOL\ has recently been changed to look more like the
    16 
    16 traditional syntax of higher-order logic.  Function application is now
    17 \CHOL\ is a modified version of Isabelle's \HOL\ and uses curried function
    17 curried.  To apply the function~$f$ to the arguments~$a$ and~$b$ in \HOL, you
    18 application. Therefore the expression $f(a,b)$ (which in \HOL\ means
    18 must write $f\,a\,b$.  Note that $f(a,b)$ means ``$f$ applied to the pair
    19 ``f applied to the two arguments $a$ and $b$'') means ``f applied to
    19 $(a,b)$'' in \HOL.  We write ordered pairs as $(a,b)$, not $\langle
    20 the pair $(a,b)$'' in \CHOL. N.B. that ordered pairs in \HOL\ are written as
    20 a,b\rangle$ as in {\ZF} and earlier versions of \HOL.  Early releases of
    21 $<a,b>$ while in \CHOL\ the syntax $(a,b)$ is used.  Previous
    21 Isabelle included still another version of~\HOL, with explicit type inference
    22 releases of Isabelle also included a different version of~\HOL, with
    22 rules~\cite{paulson-COLOG}.  This version no longer exists, but \thydx{ZF}
    23 explicit type inference rules~\cite{paulson-COLOG}.  This version no
    23 supports a similar style of reasoning.
    24 longer exists, but \thydx{ZF} supports a similar style of reasoning.
    24 
    25 
    25 \HOL\ has a distinct feel, compared with {\ZF} and {\CTT}.  It
    26 \CHOL\ has a distinct feel, compared with {\ZF} and {\CTT}.  It
       
    27 identifies object-level types with meta-level types, taking advantage of
    26 identifies object-level types with meta-level types, taking advantage of
    28 Isabelle's built-in type checker.  It identifies object-level functions
    27 Isabelle's built-in type checker.  It identifies object-level functions
    29 with meta-level functions, so it uses Isabelle's operations for abstraction
    28 with meta-level functions, so it uses Isabelle's operations for abstraction
    30 and application.  There is no `apply' operator: function applications are
    29 and application.  There is no `apply' operator: function applications are
    31 written as simply~$f~a$ rather than $f{\tt`}a$.
    30 written as simply~$f~a$ rather than $f{\tt`}a$.
    32 
    31 
    33 These identifications allow Isabelle to support \CHOL\ particularly nicely,
    32 These identifications allow Isabelle to support \HOL\ particularly nicely,
    34 but they also mean that \CHOL\ requires more sophistication from the user
    33 but they also mean that \HOL\ requires more sophistication from the user
    35 --- in particular, an understanding of Isabelle's type system.  Beginners
    34 --- in particular, an understanding of Isabelle's type system.  Beginners
    36 should work with {\tt show_types} set to {\tt true}.  Gain experience by
    35 should work with {\tt show_types} set to {\tt true}.  Gain experience by
    37 working in first-order logic before attempting to use higher-order logic.
    36 working in first-order logic before attempting to use higher-order logic.
    38 This chapter assumes familiarity with~{\FOL{}}.
    37 This chapter assumes familiarity with~{\FOL{}}.
    39 
    38 
   120          & | & "EX~~" id~id^* " . " formula \\
   119          & | & "EX~~" id~id^* " . " formula \\
   121          & | & "?!~~" id~id^* " . " formula 
   120          & | & "?!~~" id~id^* " . " formula 
   122          & | & "EX!~" id~id^* " . " formula
   121          & | & "EX!~" id~id^* " . " formula
   123   \end{array}
   122   \end{array}
   124 \]
   123 \]
   125 \caption{Full grammar for \CHOL} \label{chol-grammar}
   124 \caption{Full grammar for \HOL} \label{chol-grammar}
   126 \end{figure} 
   125 \end{figure} 
   127 
   126 
   128 
   127 
   129 \section{Syntax}
   128 \section{Syntax}
   130 The type class of higher-order terms is called~\cldx{term}.  Type variables
   129 The type class of higher-order terms is called~\cldx{term}.  Type variables
   145 binders), while Fig.\ts\ref{chol-grammar} presents the grammar of
   144 binders), while Fig.\ts\ref{chol-grammar} presents the grammar of
   146 higher-order logic.  Note that $a$\verb|~=|$b$ is translated to
   145 higher-order logic.  Note that $a$\verb|~=|$b$ is translated to
   147 $\neg(a=b)$.
   146 $\neg(a=b)$.
   148 
   147 
   149 \begin{warn}
   148 \begin{warn}
   150   \CHOL\ has no if-and-only-if connective; logical equivalence is expressed
   149   \HOL\ has no if-and-only-if connective; logical equivalence is expressed
   151   using equality.  But equality has a high priority, as befitting a
   150   using equality.  But equality has a high priority, as befitting a
   152   relation, while if-and-only-if typically has the lowest priority.  Thus,
   151   relation, while if-and-only-if typically has the lowest priority.  Thus,
   153   $\neg\neg P=P$ abbreviates $\neg\neg (P=P)$ and not $(\neg\neg P)=P$.
   152   $\neg\neg P=P$ abbreviates $\neg\neg (P=P)$ and not $(\neg\neg P)=P$.
   154   When using $=$ to mean logical equivalence, enclose both operands in
   153   When using $=$ to mean logical equivalence, enclose both operands in
   155   parentheses.
   154   parentheses.
   156 \end{warn}
   155 \end{warn}
   157 
   156 
   158 \subsection{Types}\label{CHOL-types}
   157 \subsection{Types}\label{HOL-types}
   159 The type of formulae, \tydx{bool}, belongs to class \cldx{term}; thus,
   158 The type of formulae, \tydx{bool}, belongs to class \cldx{term}; thus,
   160 formulae are terms.  The built-in type~\tydx{fun}, which constructs function
   159 formulae are terms.  The built-in type~\tydx{fun}, which constructs function
   161 types, is overloaded with arity {\tt(term,term)term}.  Thus, $\sigma\To\tau$
   160 types, is overloaded with arity {\tt(term,term)term}.  Thus, $\sigma\To\tau$
   162 belongs to class~{\tt term} if $\sigma$ and~$\tau$ do, allowing quantification
   161 belongs to class~{\tt term} if $\sigma$ and~$\tau$ do, allowing quantification
   163 over functions.
   162 over functions.
   164 
   163 
   165 Types in \CHOL\ must be non-empty; otherwise the quantifier rules would be
   164 Types in \HOL\ must be non-empty; otherwise the quantifier rules would be
   166 unsound.  I have commented on this elsewhere~\cite[\S7]{paulson-COLOG}.
   165 unsound.  I have commented on this elsewhere~\cite[\S7]{paulson-COLOG}.
   167 
   166 
   168 \index{type definitions}
   167 \index{type definitions}
   169 Gordon's {\sc hol} system supports {\bf type definitions}.  A type is
   168 Gordon's {\sc hol} system supports {\bf type definitions}.  A type is
   170 defined by exhibiting an existing type~$\sigma$, a predicate~$P::\sigma\To
   169 defined by exhibiting an existing type~$\sigma$, a predicate~$P::\sigma\To
   183 Isabelle cannot enforce this.
   182 Isabelle cannot enforce this.
   184 
   183 
   185 
   184 
   186 \subsection{Binders}
   185 \subsection{Binders}
   187 Hilbert's {\bf description} operator~$\epsilon x.P[x]$ stands for some~$a$
   186 Hilbert's {\bf description} operator~$\epsilon x.P[x]$ stands for some~$a$
   188 satisfying~$P[a]$, if such exists.  Since all terms in \CHOL\ denote
   187 satisfying~$P[a]$, if such exists.  Since all terms in \HOL\ denote
   189 something, a description is always meaningful, but we do not know its value
   188 something, a description is always meaningful, but we do not know its value
   190 unless $P[x]$ defines it uniquely.  We may write descriptions as
   189 unless $P[x]$ defines it uniquely.  We may write descriptions as
   191 \cdx{Eps}($P$) or use the syntax
   190 \cdx{Eps}($P$) or use the syntax
   192 \hbox{\tt \at $x$.$P[x]$}.
   191 \hbox{\tt \at $x$.$P[x]$}.
   193 
   192 
   197 of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
   196 of~$\exists$ and~$\forall$.  An Isabelle binder, it admits nested
   198 quantifications.  For instance, $\exists!x y.P~x~y$ abbreviates
   197 quantifications.  For instance, $\exists!x y.P~x~y$ abbreviates
   199 $\exists!x. \exists!y.P~x~y$; note that this does not mean that there
   198 $\exists!x. \exists!y.P~x~y$; note that this does not mean that there
   200 exists a unique pair $(x,y)$ satisfying~$P~x~y$.
   199 exists a unique pair $(x,y)$ satisfying~$P~x~y$.
   201 
   200 
   202 \index{*"! symbol}\index{*"? symbol}\index{CHOL system@{\sc hol} system}
   201 \index{*"! symbol}\index{*"? symbol}\index{HOL system@{\sc hol} system}
   203 Quantifiers have two notations.  As in Gordon's {\sc hol} system, \CHOL\
   202 Quantifiers have two notations.  As in Gordon's {\sc hol} system, \HOL\
   204 uses~{\tt!}\ and~{\tt?}\ to stand for $\forall$ and $\exists$.  The
   203 uses~{\tt!}\ and~{\tt?}\ to stand for $\forall$ and $\exists$.  The
   205 existential quantifier must be followed by a space; thus {\tt?x} is an
   204 existential quantifier must be followed by a space; thus {\tt?x} is an
   206 unknown, while \verb'? x.f x=y' is a quantification.  Isabelle's usual
   205 unknown, while \verb'? x.f x=y' is a quantification.  Isabelle's usual
   207 notation for quantifiers, \sdx{ALL} and \sdx{EX}, is also
   206 notation for quantifiers, \sdx{ALL} and \sdx{EX}, is also
   208 available.  Both notations are accepted for input.  The {\ML} reference
   207 available.  Both notations are accepted for input.  The {\ML} reference
   217 Local abbreviations can be introduced by a {\tt let} construct whose
   216 Local abbreviations can be introduced by a {\tt let} construct whose
   218 syntax appears in Fig.\ts\ref{chol-grammar}.  Internally it is translated into
   217 syntax appears in Fig.\ts\ref{chol-grammar}.  Internally it is translated into
   219 the constant~\cdx{Let}.  It can be expanded by rewriting with its
   218 the constant~\cdx{Let}.  It can be expanded by rewriting with its
   220 definition, \tdx{Let_def}.
   219 definition, \tdx{Let_def}.
   221 
   220 
   222 \CHOL\ also defines the basic syntax
   221 \HOL\ also defines the basic syntax
   223 \[\dquotes"case"~e~"of"~c@1~"=>"~e@1~"|" \dots "|"~c@n~"=>"~e@n\] 
   222 \[\dquotes"case"~e~"of"~c@1~"=>"~e@1~"|" \dots "|"~c@n~"=>"~e@n\] 
   224 as a uniform means of expressing {\tt case} constructs.  Therefore {\tt
   223 as a uniform means of expressing {\tt case} constructs.  Therefore {\tt
   225   case} and \sdx{of} are reserved words.  However, so far this is mere
   224   case} and \sdx{of} are reserved words.  However, so far this is mere
   226 syntax and has no logical meaning.  By declaring translations, you can
   225 syntax and has no logical meaning.  By declaring translations, you can
   227 cause instances of the {\tt case} construct to denote applications of
   226 cause instances of the {\tt case} construct to denote applications of
   238 \tdx{mp}             [| P-->Q;  P |] ==> Q
   237 \tdx{mp}             [| P-->Q;  P |] ==> Q
   239 \tdx{iff}            (P-->Q) --> (Q-->P) --> (P=Q)
   238 \tdx{iff}            (P-->Q) --> (Q-->P) --> (P=Q)
   240 \tdx{selectI}        P(x::'a) ==> P(@x.P x)
   239 \tdx{selectI}        P(x::'a) ==> P(@x.P x)
   241 \tdx{True_or_False}  (P=True) | (P=False)
   240 \tdx{True_or_False}  (P=True) | (P=False)
   242 \end{ttbox}
   241 \end{ttbox}
   243 \caption{The {\tt CHOL} rules} \label{chol-rules}
   242 \caption{The {\tt HOL} rules} \label{chol-rules}
   244 \end{figure}
   243 \end{figure}
   245 
   244 
   246 
   245 
   247 \begin{figure}\hfuzz=4pt%suppress "Overfull \hbox" message
   246 \begin{figure}\hfuzz=4pt%suppress "Overfull \hbox" message
   248 \begin{ttbox}\makeatother
   247 \begin{ttbox}\makeatother
   258 \tdx{Inv_def}    Inv      == (\%(f::'a=>'b) y. @x. f x=y)
   257 \tdx{Inv_def}    Inv      == (\%(f::'a=>'b) y. @x. f x=y)
   259 \tdx{o_def}      op o     == (\%(f::'b=>'c) g (x::'a). f(g x))
   258 \tdx{o_def}      op o     == (\%(f::'b=>'c) g (x::'a). f(g x))
   260 \tdx{if_def}     If P x y == (\%P x y.@z::'a.(P=True --> z=x) & (P=False --> z=y))
   259 \tdx{if_def}     If P x y == (\%P x y.@z::'a.(P=True --> z=x) & (P=False --> z=y))
   261 \tdx{Let_def}    Let s f  == f s
   260 \tdx{Let_def}    Let s f  == f s
   262 \end{ttbox}
   261 \end{ttbox}
   263 \caption{The {\tt CHOL} definitions} \label{chol-defs}
   262 \caption{The {\tt HOL} definitions} \label{chol-defs}
   264 \end{figure}
   263 \end{figure}
   265 
   264 
   266 
   265 
   267 \section{Rules of inference}
   266 \section{Rules of inference}
   268 Figure~\ref{chol-rules} shows the inference rules of~\CHOL{}, with
   267 Figure~\ref{chol-rules} shows the inference rules of~\HOL{}, with
   269 their~{\ML} names.  Some of the rules deserve additional comments:
   268 their~{\ML} names.  Some of the rules deserve additional comments:
   270 \begin{ttdescription}
   269 \begin{ttdescription}
   271 \item[\tdx{ext}] expresses extensionality of functions.
   270 \item[\tdx{ext}] expresses extensionality of functions.
   272 \item[\tdx{iff}] asserts that logically equivalent formulae are
   271 \item[\tdx{iff}] asserts that logically equivalent formulae are
   273   equal.
   272   equal.
   277 \item[\tdx{True_or_False}] makes the logic classical.\footnote{In
   276 \item[\tdx{True_or_False}] makes the logic classical.\footnote{In
   278     fact, the $\epsilon$-operator already makes the logic classical, as
   277     fact, the $\epsilon$-operator already makes the logic classical, as
   279     shown by Diaconescu; see Paulson~\cite{paulson-COLOG} for details.}
   278     shown by Diaconescu; see Paulson~\cite{paulson-COLOG} for details.}
   280 \end{ttdescription}
   279 \end{ttdescription}
   281 
   280 
   282 \CHOL{} follows standard practice in higher-order logic: only a few
   281 \HOL{} follows standard practice in higher-order logic: only a few
   283 connectives are taken as primitive, with the remainder defined obscurely
   282 connectives are taken as primitive, with the remainder defined obscurely
   284 (Fig.\ts\ref{chol-defs}).  Gordon's {\sc hol} system expresses the
   283 (Fig.\ts\ref{chol-defs}).  Gordon's {\sc hol} system expresses the
   285 corresponding definitions \cite[page~270]{mgordon-hol} using
   284 corresponding definitions \cite[page~270]{mgordon-hol} using
   286 object-equality~({\tt=}), which is possible because equality in
   285 object-equality~({\tt=}), which is possible because equality in
   287 higher-order logic may equate formulae and even functions over formulae.
   286 higher-order logic may equate formulae and even functions over formulae.
   288 But theory~\CHOL{}, like all other Isabelle theories, uses
   287 But theory~\HOL{}, like all other Isabelle theories, uses
   289 meta-equality~({\tt==}) for definitions.
   288 meta-equality~({\tt==}) for definitions.
   290 
   289 
   291 Some of the rules mention type variables; for example, {\tt refl}
   290 Some of the rules mention type variables; for example, {\tt refl}
   292 mentions the type variable~{\tt'a}.  This allows you to instantiate
   291 mentions the type variable~{\tt'a}.  This allows you to instantiate
   293 type variables explicitly by calling {\tt res_inst_tac}.  By default,
   292 type variables explicitly by calling {\tt res_inst_tac}.  By default,
   348 \tdx{eqTrueI}     P ==> P=True 
   347 \tdx{eqTrueI}     P ==> P=True 
   349 \tdx{eqTrueE}     P=True ==> P 
   348 \tdx{eqTrueE}     P=True ==> P 
   350 \subcaption{Logical equivalence}
   349 \subcaption{Logical equivalence}
   351 
   350 
   352 \end{ttbox}
   351 \end{ttbox}
   353 \caption{Derived rules for \CHOL} \label{chol-lemmas1}
   352 \caption{Derived rules for \HOL} \label{chol-lemmas1}
   354 \end{figure}
   353 \end{figure}
   355 
   354 
   356 
   355 
   357 \begin{figure}
   356 \begin{figure}
   358 \begin{ttbox}\makeatother
   357 \begin{ttbox}\makeatother
   538 may be defined by absolute comprehension.
   537 may be defined by absolute comprehension.
   539 \item
   538 \item
   540 Although sets may contain other sets as elements, the containing set must
   539 Although sets may contain other sets as elements, the containing set must
   541 have a more complex type.
   540 have a more complex type.
   542 \end{itemize}
   541 \end{itemize}
   543 Finite unions and intersections have the same behaviour in \CHOL\ as they
   542 Finite unions and intersections have the same behaviour in \HOL\ as they
   544 do in~{\ZF}.  In \CHOL\ the intersection of the empty set is well-defined,
   543 do in~{\ZF}.  In \HOL\ the intersection of the empty set is well-defined,
   545 denoting the universal set for the given type.
   544 denoting the universal set for the given type.
   546 
   545 
   547 
   546 
   548 \subsection{Syntax of set theory}\index{*set type}
   547 \subsection{Syntax of set theory}\index{*set type}
   549 \CHOL's set theory is called \thydx{Set}.  The type $\alpha\,set$ is
   548 \HOL's set theory is called \thydx{Set}.  The type $\alpha\,set$ is
   550 essentially the same as $\alpha\To bool$.  The new type is defined for
   549 essentially the same as $\alpha\To bool$.  The new type is defined for
   551 clarity and to avoid complications involving function types in unification.
   550 clarity and to avoid complications involving function types in unification.
   552 Since Isabelle does not support type definitions (as mentioned in
   551 Since Isabelle does not support type definitions (as mentioned in
   553 \S\ref{CHOL-types}), the isomorphisms between the two types are declared
   552 \S\ref{HOL-types}), the isomorphisms between the two types are declared
   554 explicitly.  Here they are natural: {\tt Collect} maps $\alpha\To bool$ to
   553 explicitly.  Here they are natural: {\tt Collect} maps $\alpha\To bool$ to
   555 $\alpha\,set$, while \hbox{\tt op :} maps in the other direction (ignoring
   554 $\alpha\,set$, while \hbox{\tt op :} maps in the other direction (ignoring
   556 argument order).
   555 argument order).
   557 
   556 
   558 Figure~\ref{chol-set-syntax} lists the constants, infixes, and syntax
   557 Figure~\ref{chol-set-syntax} lists the constants, infixes, and syntax
   821 such as \tdx{subsetCE}, \tdx{bexCI} and \tdx{UnCI},
   820 such as \tdx{subsetCE}, \tdx{bexCI} and \tdx{UnCI},
   822 are designed for classical reasoning; the rules \tdx{subsetD},
   821 are designed for classical reasoning; the rules \tdx{subsetD},
   823 \tdx{bexI}, \tdx{Un1} and~\tdx{Un2} are not
   822 \tdx{bexI}, \tdx{Un1} and~\tdx{Un2} are not
   824 strictly necessary but yield more natural proofs.  Similarly,
   823 strictly necessary but yield more natural proofs.  Similarly,
   825 \tdx{equalityCE} supports classical reasoning about extensionality,
   824 \tdx{equalityCE} supports classical reasoning about extensionality,
   826 after the fashion of \tdx{iffCE}.  See the file {\tt CHOL/Set.ML} for
   825 after the fashion of \tdx{iffCE}.  See the file {\tt HOL/Set.ML} for
   827 proofs pertaining to set theory.
   826 proofs pertaining to set theory.
   828 
   827 
   829 Figure~\ref{chol-fun} presents derived inference rules involving functions.
   828 Figure~\ref{chol-fun} presents derived inference rules involving functions.
   830 They also include rules for \cdx{Inv}, which is defined in theory~{\tt
   829 They also include rules for \cdx{Inv}, which is defined in theory~{\tt
   831   CHOL}; note that ${\tt Inv}~f$ applies the Axiom of Choice to yield an
   830   HOL}; note that ${\tt Inv}~f$ applies the Axiom of Choice to yield an
   832 inverse of~$f$.  They also include natural deduction rules for the image
   831 inverse of~$f$.  They also include natural deduction rules for the image
   833 and range operators, and for the predicates {\tt inj} and {\tt inj_onto}.
   832 and range operators, and for the predicates {\tt inj} and {\tt inj_onto}.
   834 Reasoning about function composition (the operator~\sdx{o}) and the
   833 Reasoning about function composition (the operator~\sdx{o}) and the
   835 predicate~\cdx{surj} is done simply by expanding the definitions.  See
   834 predicate~\cdx{surj} is done simply by expanding the definitions.  See
   836 the file {\tt CHOL/fun.ML} for a complete listing of the derived rules.
   835 the file {\tt HOL/fun.ML} for a complete listing of the derived rules.
   837 
   836 
   838 Figure~\ref{chol-subset} presents lattice properties of the subset relation.
   837 Figure~\ref{chol-subset} presents lattice properties of the subset relation.
   839 Unions form least upper bounds; non-empty intersections form greatest lower
   838 Unions form least upper bounds; non-empty intersections form greatest lower
   840 bounds.  Reasoning directly about subsets often yields clearer proofs than
   839 bounds.  Reasoning directly about subsets often yields clearer proofs than
   841 reasoning about the membership relation.  See the file {\tt CHOL/subset.ML}.
   840 reasoning about the membership relation.  See the file {\tt HOL/subset.ML}.
   842 
   841 
   843 Figure~\ref{chol-equalities} presents many common set equalities.  They
   842 Figure~\ref{chol-equalities} presents many common set equalities.  They
   844 include commutative, associative and distributive laws involving unions,
   843 include commutative, associative and distributive laws involving unions,
   845 intersections and complements.  The proofs are mostly trivial, using the
   844 intersections and complements.  The proofs are mostly trivial, using the
   846 classical reasoner; see file {\tt CHOL/equalities.ML}.
   845 classical reasoner; see file {\tt HOL/equalities.ML}.
   847 
   846 
   848 
   847 
   849 \begin{figure}
   848 \begin{figure}
   850 \begin{constants}
   849 \begin{constants}
   851   \it symbol    & \it meta-type &           & \it description \\ 
   850   \it symbol    & \it meta-type &           & \it description \\ 
   909 \caption{Type $\alpha+\beta$}\label{chol-sum}
   908 \caption{Type $\alpha+\beta$}\label{chol-sum}
   910 \end{figure}
   909 \end{figure}
   911 
   910 
   912 
   911 
   913 \section{Generic packages and classical reasoning}
   912 \section{Generic packages and classical reasoning}
   914 \CHOL\ instantiates most of Isabelle's generic packages;
   913 \HOL\ instantiates most of Isabelle's generic packages;
   915 see {\tt CHOL/ROOT.ML} for details.
   914 see {\tt HOL/ROOT.ML} for details.
   916 \begin{itemize}
   915 \begin{itemize}
   917 \item 
   916 \item 
   918 Because it includes a general substitution rule, \CHOL\ instantiates the
   917 Because it includes a general substitution rule, \HOL\ instantiates the
   919 tactic {\tt hyp_subst_tac}, which substitutes for an equality
   918 tactic {\tt hyp_subst_tac}, which substitutes for an equality
   920 throughout a subgoal and its hypotheses.
   919 throughout a subgoal and its hypotheses.
   921 \item 
   920 \item 
   922 It instantiates the simplifier, defining~\ttindexbold{HOL_ss} as the
   921 It instantiates the simplifier, defining~\ttindexbold{HOL_ss} as the
   923 simplification set for higher-order logic.  Equality~($=$), which also
   922 simplification set for higher-order logic.  Equality~($=$), which also
   924 expresses logical equivalence, may be used for rewriting.  See the file
   923 expresses logical equivalence, may be used for rewriting.  See the file
   925 {\tt CHOL/simpdata.ML} for a complete listing of the simplification
   924 {\tt HOL/simpdata.ML} for a complete listing of the simplification
   926 rules. 
   925 rules. 
   927 \item 
   926 \item 
   928 It instantiates the classical reasoner, as described below. 
   927 It instantiates the classical reasoner, as described below. 
   929 \end{itemize}
   928 \end{itemize}
   930 \CHOL\ derives classical introduction rules for $\disj$ and~$\exists$, as
   929 \HOL\ derives classical introduction rules for $\disj$ and~$\exists$, as
   931 well as classical elimination rules for~$\imp$ and~$\bimp$, and the swap
   930 well as classical elimination rules for~$\imp$ and~$\bimp$, and the swap
   932 rule; recall Fig.\ts\ref{chol-lemmas2} above.
   931 rule; recall Fig.\ts\ref{chol-lemmas2} above.
   933 
   932 
   934 The classical reasoner is set up as the structure
   933 The classical reasoner is set up as the structure
   935 {\tt Classical}.  This structure is open, so {\ML} identifiers such
   934 {\tt Classical}.  This structure is open, so {\ML} identifiers such
  1085 Type~\tydx{nat} is postulated to belong to class~\cldx{ord}, which
  1084 Type~\tydx{nat} is postulated to belong to class~\cldx{ord}, which
  1086 overloads $<$ and $\leq$ on the natural numbers.  As of this writing,
  1085 overloads $<$ and $\leq$ on the natural numbers.  As of this writing,
  1087 Isabelle provides no means of verifying that such overloading is sensible;
  1086 Isabelle provides no means of verifying that such overloading is sensible;
  1088 there is no means of specifying the operators' properties and verifying
  1087 there is no means of specifying the operators' properties and verifying
  1089 that instances of the operators satisfy those properties.  To be safe, the
  1088 that instances of the operators satisfy those properties.  To be safe, the
  1090 \CHOL\ theory includes no polymorphic axioms asserting general properties of
  1089 \HOL\ theory includes no polymorphic axioms asserting general properties of
  1091 $<$ and~$\leq$.
  1090 $<$ and~$\leq$.
  1092 
  1091 
  1093 Theory \thydx{Arith} develops arithmetic on the natural numbers.  It
  1092 Theory \thydx{Arith} develops arithmetic on the natural numbers.  It
  1094 defines addition, multiplication, subtraction, division, and remainder.
  1093 defines addition, multiplication, subtraction, division, and remainder.
  1095 Many of their properties are proved: commutative, associative and
  1094 Many of their properties are proved: commutative, associative and
  1159 \end{figure}
  1158 \end{figure}
  1160 
  1159 
  1161 \begin{figure}
  1160 \begin{figure}
  1162 \begin{ttbox}\makeatother
  1161 \begin{ttbox}\makeatother
  1163 \tdx{list_rec_Nil}    list_rec [] c h = c  
  1162 \tdx{list_rec_Nil}    list_rec [] c h = c  
  1164 \tdx{list_rec_Cons}   list_rec a#l c h = h a l (list_rec l c h)
  1163 \tdx{list_rec_Cons}   list_rec (a#l) c h = h a l (list_rec l c h)
  1165 
  1164 
  1166 \tdx{list_case_Nil}   list_case c h [] = c 
  1165 \tdx{list_case_Nil}   list_case c h [] = c 
  1167 \tdx{list_case_Cons}  list_case c h x#xs = h x xs
  1166 \tdx{list_case_Cons}  list_case c h (x#xs) = h x xs
  1168 
  1167 
  1169 \tdx{map_Nil}         map f [] = []
  1168 \tdx{map_Nil}         map f [] = []
  1170 \tdx{map_Cons}        map f x \# xs = f x \# map f xs
  1169 \tdx{map_Cons}        map f (x#xs) = f x # map f xs
  1171 
  1170 
  1172 \tdx{null_Nil}        null [] = True
  1171 \tdx{null_Nil}        null [] = True
  1173 \tdx{null_Cons}       null x#xs = False
  1172 \tdx{null_Cons}       null (x#xs) = False
  1174 
  1173 
  1175 \tdx{hd_Cons}         hd x#xs = x
  1174 \tdx{hd_Cons}         hd (x#xs) = x
  1176 \tdx{tl_Cons}         tl x#xs = xs
  1175 \tdx{tl_Cons}         tl (x#xs) = xs
  1177 
  1176 
  1178 \tdx{ttl_Nil}         ttl [] = []
  1177 \tdx{ttl_Nil}         ttl [] = []
  1179 \tdx{ttl_Cons}        ttl x#xs = xs
  1178 \tdx{ttl_Cons}        ttl (x#xs) = xs
  1180 
  1179 
  1181 \tdx{append_Nil}      [] @ ys = ys
  1180 \tdx{append_Nil}      [] @ ys = ys
  1182 \tdx{append_Cons}     (x#xs) \at ys = x # xs \at ys
  1181 \tdx{append_Cons}     (x#xs) \at ys = x # xs \at ys
  1183 
  1182 
  1184 \tdx{mem_Nil}         x mem [] = False
  1183 \tdx{mem_Nil}         x mem [] = False
  1185 \tdx{mem_Cons}        x mem (y#ys) = if y=x then True else x mem ys
  1184 \tdx{mem_Cons}        x mem (y#ys) = if y=x then True else x mem ys
  1186 
  1185 
  1187 \tdx{filter_Nil}      filter P [] = []
  1186 \tdx{filter_Nil}      filter P [] = []
  1188 \tdx{filter_Cons}     filter P x#xs = if P x then x#filter P xs else filter P xs
  1187 \tdx{filter_Cons}     filter P (x#xs) = if P x then x#filter P xs else filter P xs
  1189 
  1188 
  1190 \tdx{list_all_Nil}    list_all P [] = True
  1189 \tdx{list_all_Nil}    list_all P [] = True
  1191 \tdx{list_all_Cons}   list_all P x#xs = (P x & list_all P xs)
  1190 \tdx{list_all_Cons}   list_all P (x#xs) = (P x & list_all P xs)
  1192 \end{ttbox}
  1191 \end{ttbox}
  1193 \caption{Rewrite rules for lists} \label{chol-list-simps}
  1192 \caption{Rewrite rules for lists} \label{chol-list-simps}
  1194 \end{figure}
  1193 \end{figure}
  1195 
  1194 
  1196 
  1195 
  1197 \subsection{The type constructor for lists, {\tt list}}
  1196 \subsection{The type constructor for lists, {\tt list}}
  1198 \index{*list type}
  1197 \index{*list type}
  1199 
  1198 
  1200 \CHOL's definition of lists is an example of an experimental method for
  1199 \HOL's definition of lists is an example of an experimental method for
  1201 handling recursive data types.  Figure~\ref{chol-list} presents the theory
  1200 handling recursive data types.  Figure~\ref{chol-list} presents the theory
  1202 \thydx{List}: the basic list operations with their types and properties.
  1201 \thydx{List}: the basic list operations with their types and properties.
  1203 
  1202 
  1204 The \sdx{case} construct is defined by the following translation:
  1203 The \sdx{case} construct is defined by the following translation:
  1205 {\dquotes
  1204 {\dquotes
  1372 \subsection{Examples}
  1371 \subsection{Examples}
  1373 
  1372 
  1374 \subsubsection{The datatype $\alpha~list$}
  1373 \subsubsection{The datatype $\alpha~list$}
  1375 
  1374 
  1376 We want to define the type $\alpha~list$.\footnote{Of course there is a list
  1375 We want to define the type $\alpha~list$.\footnote{Of course there is a list
  1377   type in CHOL already. This is only an example.} To do this we have to build
  1376   type in HOL already. This is only an example.} To do this we have to build
  1378 a new theory that contains the type definition. We start from {\tt CHOL}.
  1377 a new theory that contains the type definition. We start from {\tt HOL}.
  1379 \begin{ttbox}
  1378 \begin{ttbox}
  1380 MyList = CHOL +
  1379 MyList = HOL +
  1381   datatype 'a list = Nil | Cons 'a ('a list)
  1380   datatype 'a list = Nil | Cons 'a ('a list)
  1382 end
  1381 end
  1383 \end{ttbox}
  1382 \end{ttbox}
  1384 After loading the theory (\verb$use_thy "MyList"$), we can prove
  1383 After loading the theory (\verb$use_thy "MyList"$), we can prove
  1385 $Cons~x~xs\neq xs$.  First we build a suitable simpset for the simplifier:
  1384 $Cons~x~xs\neq xs$.  First we build a suitable simpset for the simplifier:
  1429 In this example we define the type $\alpha~list$ again but this time we want
  1428 In this example we define the type $\alpha~list$ again but this time we want
  1430 to write {\tt []} instead of {\tt Nil} and we want to use the infix operator
  1429 to write {\tt []} instead of {\tt Nil} and we want to use the infix operator
  1431 \verb|#| instead of {\tt Cons}. To do this we simply add mixfix annotations
  1430 \verb|#| instead of {\tt Cons}. To do this we simply add mixfix annotations
  1432 after the constructor declarations as follows:
  1431 after the constructor declarations as follows:
  1433 \begin{ttbox}
  1432 \begin{ttbox}
  1434 MyList = CHOL +
  1433 MyList = HOL +
  1435   datatype 'a list = "[]" ("[]") 
  1434   datatype 'a list = "[]" ("[]") 
  1436                    | "#" 'a ('a list) (infixr 70)
  1435                    | "#" 'a ('a list) (infixr 70)
  1437 end
  1436 end
  1438 \end{ttbox}
  1437 \end{ttbox}
  1439 Now the theorem in the previous example can be written \verb|x#xs ~= xs|. The
  1438 Now the theorem in the previous example can be written \verb|x#xs ~= xs|. The
  1471 \begin{ttbox}
  1470 \begin{ttbox}
  1472 Append = MyList +
  1471 Append = MyList +
  1473 consts app :: "['a list,'a list] => 'a list"
  1472 consts app :: "['a list,'a list] => 'a list"
  1474 rules 
  1473 rules 
  1475    app_Nil   "app [] ys = ys"
  1474    app_Nil   "app [] ys = ys"
  1476    app_Cons  "app x#xs ys = x#app xs ys"
  1475    app_Cons  "app (x#xs) ys = x#app xs ys"
  1477 end
  1476 end
  1478 \end{ttbox}
  1477 \end{ttbox}
  1479 this carries with it the danger of accidentally asserting an inconsistency,
  1478 this carries with it the danger of accidentally asserting an inconsistency,
  1480 as in \verb$app [] ys = us$. Therefore primitive recursive functions on
  1479 as in \verb$app [] ys = us$. Therefore primitive recursive functions on
  1481 datatypes can be defined with a special syntax:
  1480 datatypes can be defined with a special syntax:
  1482 \begin{ttbox}
  1481 \begin{ttbox}
  1483 Append = MyList +
  1482 Append = MyList +
  1484 consts app :: "'['a list,'a list] => 'a list"
  1483 consts app :: "'['a list,'a list] => 'a list"
  1485 primrec app MyList.list
  1484 primrec app MyList.list
  1486    app_Nil   "app [] ys = ys"
  1485    app_Nil   "app [] ys = ys"
  1487    app_Cons  "app x#xs ys = x#app xs ys"
  1486    app_Cons  "app (x#xs) ys = x#app xs ys"
  1488 end
  1487 end
  1489 \end{ttbox}
  1488 \end{ttbox}
  1490 The system will now check that the two rules \verb$app_Nil$ and
  1489 The system will now check that the two rules \verb$app_Nil$ and
  1491 \verb$app_Cons$ do indeed form a primitive recursive definition, thus
  1490 \verb$app_Cons$ do indeed form a primitive recursive definition, thus
  1492 ensuring that consistency is maintained. For example
  1491 ensuring that consistency is maintained. For example
  1588 substructure of the main theory structure.
  1587 substructure of the main theory structure.
  1589 
  1588 
  1590 This package is derived from the ZF one, described in a
  1589 This package is derived from the ZF one, described in a
  1591 separate paper,\footnote{It appeared in CADE~\cite{paulson-CADE} and a
  1590 separate paper,\footnote{It appeared in CADE~\cite{paulson-CADE} and a
  1592   longer version is distributed with Isabelle.} which you should refer to
  1591   longer version is distributed with Isabelle.} which you should refer to
  1593 in case of difficulties.  The package is simpler than ZF's, thanks to CHOL's
  1592 in case of difficulties.  The package is simpler than ZF's, thanks to HOL's
  1594 automatic type-checking.  The type of the (co)inductive determines the
  1593 automatic type-checking.  The type of the (co)inductive determines the
  1595 domain of the fixedpoint definition, and the package does not use inference
  1594 domain of the fixedpoint definition, and the package does not use inference
  1596 rules for type-checking.
  1595 rules for type-checking.
  1597 
  1596 
  1598 
  1597 
  1726   intrs
  1725   intrs
  1727      pred "pred a r: Pow(acc r) ==> a: acc r"
  1726      pred "pred a r: Pow(acc r) ==> a: acc r"
  1728   monos   "[Pow_mono]"
  1727   monos   "[Pow_mono]"
  1729 end
  1728 end
  1730 \end{ttbox}
  1729 \end{ttbox}
  1731 The CHOL distribution contains many other inductive definitions, such as the
  1730 The HOL distribution contains many other inductive definitions, such as the
  1732 theory {\tt CHOL/ex/PropLog.thy} and the directory {\tt CHOL/IMP}.  The
  1731 theory {\tt HOL/ex/PropLog.thy} and the directory {\tt HOL/IMP}.  The
  1733 theory {\tt CHOL/ex/LList.thy} contains coinductive definitions.
  1732 theory {\tt HOL/ex/LList.thy} contains coinductive definitions.
  1734 
  1733 
  1735 \index{*coinductive|)} \index{*inductive|)} \underscoreoff
  1734 \index{*coinductive|)} \index{*inductive|)} \underscoreoff
  1736 
  1735 
  1737 
  1736 
  1738 \section{The examples directories}
  1737 \section{The examples directories}
  1739 Directory {\tt CHOL/Subst} contains Martin Coen's mechanisation of a theory of
  1738 Directory {\tt HOL/Subst} contains Martin Coen's mechanisation of a theory of
  1740 substitutions and unifiers.  It is based on Paulson's previous
  1739 substitutions and unifiers.  It is based on Paulson's previous
  1741 mechanisation in {\LCF}~\cite{paulson85} of Manna and Waldinger's
  1740 mechanisation in {\LCF}~\cite{paulson85} of Manna and Waldinger's
  1742 theory~\cite{mw81}. 
  1741 theory~\cite{mw81}. 
  1743 
  1742 
  1744 Directory {\tt CHOL/IMP} contains a mechanised version of a semantic
  1743 Directory {\tt HOL/IMP} contains a mechanised version of a semantic
  1745 equivalence proof taken from Winskel~\cite{winskel93}.  It formalises the
  1744 equivalence proof taken from Winskel~\cite{winskel93}.  It formalises the
  1746 denotational and operational semantics of a simple while-language, then
  1745 denotational and operational semantics of a simple while-language, then
  1747 proves the two equivalent.  It contains several datatype and inductive
  1746 proves the two equivalent.  It contains several datatype and inductive
  1748 definitions, and demonstrates their use.
  1747 definitions, and demonstrates their use.
  1749 
  1748 
  1750 Directory {\tt CHOL/ex} contains other examples and experimental proofs in
  1749 Directory {\tt HOL/ex} contains other examples and experimental proofs in
  1751 {\CHOL}.  Here is an overview of the more interesting files.
  1750 {\HOL}.  Here is an overview of the more interesting files.
  1752 \begin{itemize}
  1751 \begin{itemize}
  1753 \item File {\tt cla.ML} demonstrates the classical reasoner on over sixty
  1752 \item File {\tt cla.ML} demonstrates the classical reasoner on over sixty
  1754   predicate calculus theorems, ranging from simple tautologies to
  1753   predicate calculus theorems, ranging from simple tautologies to
  1755   moderately difficult problems involving equality and quantifiers.
  1754   moderately difficult problems involving equality and quantifiers.
  1756 
  1755 
  1809 %
  1808 %
  1810 Viewing types as sets, $\alpha\To bool$ represents the powerset
  1809 Viewing types as sets, $\alpha\To bool$ represents the powerset
  1811 of~$\alpha$.  This version states that for every function from $\alpha$ to
  1810 of~$\alpha$.  This version states that for every function from $\alpha$ to
  1812 its powerset, some subset is outside its range.  
  1811 its powerset, some subset is outside its range.  
  1813 
  1812 
  1814 The Isabelle proof uses \CHOL's set theory, with the type $\alpha\,set$ and
  1813 The Isabelle proof uses \HOL's set theory, with the type $\alpha\,set$ and
  1815 the operator \cdx{range}.  The set~$S$ is given as an unknown instead of a
  1814 the operator \cdx{range}.  The set~$S$ is given as an unknown instead of a
  1816 quantified variable so that we may inspect the subset found by the proof.
  1815 quantified variable so that we may inspect the subset found by the proof.
  1817 \begin{ttbox}
  1816 \begin{ttbox}
  1818 goal Set.thy "~ ?S : range(f :: 'a=>'a set)";
  1817 goal Set.thy "~ ?S : range(f :: 'a=>'a set)";
  1819 {\out Level 0}
  1818 {\out Level 0}
  1876 {\out ~ \{x. ~ x : f x\} : range f}
  1875 {\out ~ \{x. ~ x : f x\} : range f}
  1877 {\out No subgoals!}
  1876 {\out No subgoals!}
  1878 \end{ttbox}
  1877 \end{ttbox}
  1879 How much creativity is required?  As it happens, Isabelle can prove this
  1878 How much creativity is required?  As it happens, Isabelle can prove this
  1880 theorem automatically.  The classical set \ttindex{set_cs} contains rules
  1879 theorem automatically.  The classical set \ttindex{set_cs} contains rules
  1881 for most of the constructs of \CHOL's set theory.  We must augment it with
  1880 for most of the constructs of \HOL's set theory.  We must augment it with
  1882 \tdx{equalityCE} to break up set equalities, and then apply best-first
  1881 \tdx{equalityCE} to break up set equalities, and then apply best-first
  1883 search.  Depth-first search would diverge, but best-first search
  1882 search.  Depth-first search would diverge, but best-first search
  1884 successfully navigates through the large search space.
  1883 successfully navigates through the large search space.
  1885 \index{search!best-first}
  1884 \index{search!best-first}
  1886 \begin{ttbox}
  1885 \begin{ttbox}