doc-src/Logics/HOL.tex
changeset 4834 dd89afb55272
parent 4803 8428d4699d58
child 4877 7a046198610e
equal deleted inserted replaced
4833:2e53109d4bc8 4834:dd89afb55272
   412 
   412 
   413 %\tdx{if_True}         (if True then x else y) = x
   413 %\tdx{if_True}         (if True then x else y) = x
   414 %\tdx{if_False}        (if False then x else y) = y
   414 %\tdx{if_False}        (if False then x else y) = y
   415 \tdx{if_P}            P ==> (if P then x else y) = x
   415 \tdx{if_P}            P ==> (if P then x else y) = x
   416 \tdx{if_not_P}        ~ P ==> (if P then x else y) = y
   416 \tdx{if_not_P}        ~ P ==> (if P then x else y) = y
   417 \tdx{expand_if}       P(if Q then x else y) = ((Q --> P x) & (~Q --> P y))
   417 \tdx{split_if}        P(if Q then x else y) = ((Q --> P x) & (~Q --> P y))
   418 \subcaption{Conditionals}
   418 \subcaption{Conditionals}
   419 \end{ttbox}
   419 \end{ttbox}
   420 \caption{More derived rules} \label{hol-lemmas2}
   420 \caption{More derived rules} \label{hol-lemmas2}
   421 \end{figure}
   421 \end{figure}
   422 
   422 
   754 All the other axioms are definitions.  They include the empty set, bounded
   754 All the other axioms are definitions.  They include the empty set, bounded
   755 quantifiers, unions, intersections, complements and the subset relation.
   755 quantifiers, unions, intersections, complements and the subset relation.
   756 They also include straightforward constructions on functions: image~({\tt``})
   756 They also include straightforward constructions on functions: image~({\tt``})
   757 and \texttt{range}.
   757 and \texttt{range}.
   758 
   758 
   759 %The predicate \cdx{inj_onto} is used for simulating type definitions.
   759 %The predicate \cdx{inj_on} is used for simulating type definitions.
   760 %The statement ${\tt inj_onto}~f~A$ asserts that $f$ is injective on the
   760 %The statement ${\tt inj_on}~f~A$ asserts that $f$ is injective on the
   761 %set~$A$, which specifies a subset of its domain type.  In a type
   761 %set~$A$, which specifies a subset of its domain type.  In a type
   762 %definition, $f$ is the abstraction function and $A$ is the set of valid
   762 %definition, $f$ is the abstraction function and $A$ is the set of valid
   763 %representations; we should not expect $f$ to be injective outside of~$A$.
   763 %representations; we should not expect $f$ to be injective outside of~$A$.
   764 
   764 
   765 %\begin{figure} \underscoreon
   765 %\begin{figure} \underscoreon
   776 %
   776 %
   777 %\tdx{injI}       [| !! x y. f x = f y ==> x=y |] ==> inj f
   777 %\tdx{injI}       [| !! x y. f x = f y ==> x=y |] ==> inj f
   778 %\tdx{inj_inverseI}              (!!x. g(f x) = x) ==> inj f
   778 %\tdx{inj_inverseI}              (!!x. g(f x) = x) ==> inj f
   779 %\tdx{injD}       [| inj f; f x = f y |] ==> x=y
   779 %\tdx{injD}       [| inj f; f x = f y |] ==> x=y
   780 %
   780 %
   781 %\tdx{inj_ontoI}  (!!x y. [| f x=f y; x:A; y:A |] ==> x=y) ==> inj_onto f A
   781 %\tdx{inj_onI}  (!!x y. [| f x=f y; x:A; y:A |] ==> x=y) ==> inj_on f A
   782 %\tdx{inj_ontoD}  [| inj_onto f A;  f x=f y;  x:A;  y:A |] ==> x=y
   782 %\tdx{inj_onD}  [| inj_on f A;  f x=f y;  x:A;  y:A |] ==> x=y
   783 %
   783 %
   784 %\tdx{inj_onto_inverseI}
   784 %\tdx{inj_on_inverseI}
   785 %    (!!x. x:A ==> g(f x) = x) ==> inj_onto f A
   785 %    (!!x. x:A ==> g(f x) = x) ==> inj_on f A
   786 %\tdx{inj_onto_contraD}
   786 %\tdx{inj_on_contraD}
   787 %    [| inj_onto f A;  x~=y;  x:A;  y:A |] ==> ~ f x=f y
   787 %    [| inj_on f A;  x~=y;  x:A;  y:A |] ==> ~ f x=f y
   788 %\end{ttbox}
   788 %\end{ttbox}
   789 %\caption{Derived rules involving functions} \label{hol-fun}
   789 %\caption{Derived rules involving functions} \label{hol-fun}
   790 %\end{figure}
   790 %\end{figure}
   791 
   791 
   792 
   792 
   869 \begin{center}
   869 \begin{center}
   870 \begin{tabular}{rrr}
   870 \begin{tabular}{rrr}
   871   \it name      &\it meta-type  & \it description \\ 
   871   \it name      &\it meta-type  & \it description \\ 
   872   \cdx{inj}~~\cdx{surj}& $(\alpha\To\beta )\To bool$
   872   \cdx{inj}~~\cdx{surj}& $(\alpha\To\beta )\To bool$
   873         & injective/surjective \\
   873         & injective/surjective \\
   874   \cdx{inj_onto}        & $[\alpha\To\beta ,\alpha\,set]\To bool$
   874   \cdx{inj_on}        & $[\alpha\To\beta ,\alpha\,set]\To bool$
   875         & injective over subset\\
   875         & injective over subset\\
   876   \cdx{inv} & $(\alpha\To\beta)\To(\beta\To\alpha)$ & inverse function
   876   \cdx{inv} & $(\alpha\To\beta)\To(\beta\To\alpha)$ & inverse function
   877 \end{tabular}
   877 \end{tabular}
   878 \end{center}
   878 \end{center}
   879 
   879 
   880 \underscoreon
   880 \underscoreon
   881 \begin{ttbox}
   881 \begin{ttbox}
   882 \tdx{inj_def}           inj f        == ! x y. f x=f y --> x=y
   882 \tdx{inj_def}         inj f      == ! x y. f x=f y --> x=y
   883 \tdx{surj_def}          surj f       == ! y. ? x. y=f x
   883 \tdx{surj_def}        surj f     == ! y. ? x. y=f x
   884 \tdx{inj_onto_def}      inj_onto f A == !x:A. !y:A. f x=f y --> x=y
   884 \tdx{inj_on_def}      inj_on f A == !x:A. !y:A. f x=f y --> x=y
   885 \tdx{inv_def}           inv f        == (\%y. @x. f(x)=y)
   885 \tdx{inv_def}         inv f      == (\%y. @x. f(x)=y)
   886 \end{ttbox}
   886 \end{ttbox}
   887 \caption{Theory \thydx{Fun}} \label{fig:HOL:Fun}
   887 \caption{Theory \thydx{Fun}} \label{fig:HOL:Fun}
   888 \end{figure}
   888 \end{figure}
   889 
   889 
   890 \subsection{Properties of functions}\nopagebreak
   890 \subsection{Properties of functions}\nopagebreak
   944 
   944 
   945 \subsubsection{Case splitting}
   945 \subsubsection{Case splitting}
   946 \label{subsec:HOL:case:splitting}
   946 \label{subsec:HOL:case:splitting}
   947 
   947 
   948 \HOL{} also provides convenient means for case splitting during
   948 \HOL{} also provides convenient means for case splitting during
   949   rewriting. Goals containing a subterm of the form {\tt if}~$b$~{\tt
   949 rewriting. Goals containing a subterm of the form {\tt if}~$b$~{\tt
   950 then\dots else\dots} often require a case distinction on $b$. This is
   950 then\dots else\dots} often require a case distinction on $b$. This is
   951 expressed by the theorem \tdx{expand_if}:
   951 expressed by the theorem \tdx{split_if}:
   952 $$
   952 $$
   953 \Var{P}(\mbox{\tt if}~\Var{b}~{\tt then}~\Var{x}~\mbox{\tt else}~\Var{y})~=~
   953 \Var{P}(\mbox{\tt if}~\Var{b}~{\tt then}~\Var{x}~\mbox{\tt else}~\Var{y})~=~
   954 ((\Var{b} \to \Var{P}(\Var{x})) \land (\neg \Var{b} \to \Var{P}(\Var{y})))
   954 ((\Var{b} \to \Var{P}(\Var{x})) \land (\neg \Var{b} \to \Var{P}(\Var{y})))
   955 \eqno{(*)}
   955 \eqno{(*)}
   956 $$
   956 $$
   961 \]
   961 \]
   962 Because $(*)$ is too general as a rewrite rule for the simplifier (the
   962 Because $(*)$ is too general as a rewrite rule for the simplifier (the
   963 left-hand side is not a higher-order pattern in the sense of
   963 left-hand side is not a higher-order pattern in the sense of
   964 \iflabelundefined{chap:simplification}{the {\em Reference Manual\/}}%
   964 \iflabelundefined{chap:simplification}{the {\em Reference Manual\/}}%
   965 {Chap.\ts\ref{chap:simplification}}), there is a special infix function 
   965 {Chap.\ts\ref{chap:simplification}}), there is a special infix function 
   966 \ttindexbold{addsplits} (analogous to \texttt{addsimps}) of type
   966 \ttindexbold{addsplits} of type \texttt{simpset * thm list -> simpset}
   967 \texttt{simpset * thm list -> simpset} that adds rules such as $(*)$ to a
   967 (analogous to \texttt{addsimps}) that adds rules such as $(*)$ to a
   968 simpset, as in
   968 simpset, as in
   969 \begin{ttbox}
   969 \begin{ttbox}
   970 by(simp_tac (!simpset addsplits [expand_if]) 1);
   970 by(simp_tac (!simpset addsplits [split_if]) 1);
   971 \end{ttbox}
   971 \end{ttbox}
   972 The effect is that after each round of simplification, one occurrence of
   972 The effect is that after each round of simplification, one occurrence of
   973 \texttt{if} is split acording to \texttt{expand_if}, until all occurences of
   973 \texttt{if} is split acording to \texttt{split_if}, until all occurences of
   974 \texttt{if} have been eliminated.
   974 \texttt{if} have been eliminated.
       
   975 
       
   976 It turns out that using \texttt{split_if} is almost always the right thing to
       
   977 do. Hence \texttt{split_if} is already included in the default simpset. If
       
   978 you want to delete it from a simpset, use \ttindexbold{delsplits}, which is
       
   979 the inverse of \texttt{addsplits}:
       
   980 \begin{ttbox}
       
   981 by(simp_tac (!simpset delsplits [split_if]) 1);
       
   982 \end{ttbox}
   975 
   983 
   976 In general, \texttt{addsplits} accepts rules of the form
   984 In general, \texttt{addsplits} accepts rules of the form
   977 \[
   985 \[
   978 \Var{P}(c~\Var{x@1}~\dots~\Var{x@n})~=~ rhs
   986 \Var{P}(c~\Var{x@1}~\dots~\Var{x@n})~=~ rhs
   979 \]
   987 \]
   980 where $c$ is a constant and $rhs$ is arbitrary. Note that $(*)$ is of the
   988 where $c$ is a constant and $rhs$ is arbitrary. Note that $(*)$ is of the
   981 right form because internally the left-hand side is
   989 right form because internally the left-hand side is
   982 $\Var{P}(\mathtt{If}~\Var{b}~\Var{x}~~\Var{y})$. Important further examples
   990 $\Var{P}(\mathtt{If}~\Var{b}~\Var{x}~~\Var{y})$. Important further examples
   983 are splitting rules for \texttt{case} expressions (see~\S\ref{subsec:list}
   991 are splitting rules for \texttt{case} expressions (see~\S\ref{subsec:list}
   984 and~\S\ref{subsec:datatype:basics}).
   992 and~\S\ref{subsec:datatype:basics}).
       
   993 
       
   994 Analogous to \texttt{Addsimps} and \texttt{Delsimps}, there are also
       
   995 imperative versions of \texttt{addsplits} and \texttt{delsplits}
       
   996 \begin{ttbox}
       
   997 \ttindexbold{Addsplits}: thm list -> unit
       
   998 \ttindexbold{Delsplits}: thm list -> unit
       
   999 \end{ttbox}
       
  1000 for adding splitting rules to, and deleting them from the current simpset.
   985 
  1001 
   986 \subsection{Classical reasoning}
  1002 \subsection{Classical reasoning}
   987 
  1003 
   988 \HOL\ derives classical introduction rules for $\disj$ and~$\exists$, as
  1004 \HOL\ derives classical introduction rules for $\disj$ and~$\exists$, as
   989 well as classical elimination rules for~$\imp$ and~$\bimp$, and the swap
  1005 well as classical elimination rules for~$\imp$ and~$\bimp$, and the swap
  1035 \tdx{fst_conv}     fst (a,b) = a
  1051 \tdx{fst_conv}     fst (a,b) = a
  1036 \tdx{snd_conv}     snd (a,b) = b
  1052 \tdx{snd_conv}     snd (a,b) = b
  1037 \tdx{surjective_pairing}  p = (fst p,snd p)
  1053 \tdx{surjective_pairing}  p = (fst p,snd p)
  1038 
  1054 
  1039 \tdx{split}        split c (a,b) = c a b
  1055 \tdx{split}        split c (a,b) = c a b
  1040 \tdx{expand_split} R(split c p) = (! x y. p = (x,y) --> R(c x y))
  1056 \tdx{split_split}  R(split c p) = (! x y. p = (x,y) --> R(c x y))
  1041 
  1057 
  1042 \tdx{SigmaI}    [| a:A;  b:B a |] ==> (a,b) : Sigma A B
  1058 \tdx{SigmaI}    [| a:A;  b:B a |] ==> (a,b) : Sigma A B
  1043 \tdx{SigmaE}    [| c:Sigma A B; !!x y.[| x:A; y:B x; c=(x,y) |] ==> P |] ==> P
  1059 \tdx{SigmaE}    [| c:Sigma A B; !!x y.[| x:A; y:B x; c=(x,y) |] ==> P |] ==> P
  1044 \end{ttbox}
  1060 \end{ttbox}
  1045 \caption{Type $\alpha\times\beta$}\label{hol-prod}
  1061 \caption{Type $\alpha\times\beta$}\label{hol-prod}
  1134 
  1150 
  1135 \tdx{sum_case_Inl}   sum_case f g (Inl x) = f x
  1151 \tdx{sum_case_Inl}   sum_case f g (Inl x) = f x
  1136 \tdx{sum_case_Inr}   sum_case f g (Inr x) = g x
  1152 \tdx{sum_case_Inr}   sum_case f g (Inr x) = g x
  1137 
  1153 
  1138 \tdx{surjective_sum} sum_case (\%x. f(Inl x)) (\%y. f(Inr y)) s = f s
  1154 \tdx{surjective_sum} sum_case (\%x. f(Inl x)) (\%y. f(Inr y)) s = f s
  1139 \tdx{expand_sum_case} R(sum_case f g s) = ((! x. s = Inl(x) --> R(f(x))) &
  1155 \tdx{split_sum_case} R(sum_case f g s) = ((! x. s = Inl(x) --> R(f(x))) &
  1140                                      (! y. s = Inr(y) --> R(g(y))))
  1156                                      (! y. s = Inr(y) --> R(g(y))))
  1141 \end{ttbox}
  1157 \end{ttbox}
  1142 \caption{Type $\alpha+\beta$}\label{hol-sum}
  1158 \caption{Type $\alpha+\beta$}\label{hol-sum}
  1143 \end{figure}
  1159 \end{figure}
  1144 
  1160 
  1407 ((e = \texttt{[]} \to P(a)) \land
  1423 ((e = \texttt{[]} \to P(a)) \land
  1408  (\forall x~ xs. e = x\texttt{\#}xs \to P(f~x~xs)))
  1424  (\forall x~ xs. e = x\texttt{\#}xs \to P(f~x~xs)))
  1409 \end{array}
  1425 \end{array}
  1410 \]
  1426 \]
  1411 which can be fed to \ttindex{addsplits} just like
  1427 which can be fed to \ttindex{addsplits} just like
  1412 \texttt{expand_if} (see~\S\ref{subsec:HOL:case:splitting}).
  1428 \texttt{split_if} (see~\S\ref{subsec:HOL:case:splitting}).
  1413 
  1429 
  1414 {\tt List} provides a basic library of list processing functions defined by
  1430 {\tt List} provides a basic library of list processing functions defined by
  1415 primitive recursion (see~\S\ref{sec:HOL:primrec}).  The recursion equations
  1431 primitive recursion (see~\S\ref{sec:HOL:primrec}).  The recursion equations
  1416 are shown in Fig.\ts\ref{fig:HOL:list-simps}.
  1432 are shown in Fig.\ts\ref{fig:HOL:list-simps}.
  1417 
  1433