doc-src/Ref/thm.tex
changeset 4317 7264fa2ff2ec
parent 4276 a770eae2cdb0
child 4376 407f786d3059
equal deleted inserted replaced
4316:86ac9153e660 4317:7264fa2ff2ec
   133 
   133 
   134 
   134 
   135 \subsection{Instantiating a theorem}
   135 \subsection{Instantiating a theorem}
   136 \index{instantiation}
   136 \index{instantiation}
   137 \begin{ttbox}
   137 \begin{ttbox}
   138 read_instantiate    :            (string * string) list -> thm -> thm
   138 read_instantiate    :                (string * string) list -> thm -> thm
   139 read_instantiate_sg : Sign.sg -> (string * string) list -> thm -> thm
   139 read_instantiate_sg :     Sign.sg -> (string * string) list -> thm -> thm
   140 cterm_instantiate   :              (cterm * cterm) list -> thm -> thm
   140 cterm_instantiate   :                  (cterm * cterm) list -> thm -> thm
       
   141 instantiate'        : ctyp option list -> cterm option list -> thm -> thm
   141 \end{ttbox}
   142 \end{ttbox}
   142 These meta-rules instantiate type and term unknowns in a theorem.  They are
   143 These meta-rules instantiate type and term unknowns in a theorem.  They are
   143 occasionally useful.  They can prevent difficulties with higher-order
   144 occasionally useful.  They can prevent difficulties with higher-order
   144 unification, and define specialized versions of rules.
   145 unification, and define specialized versions of rules.
   145 \begin{ttdescription}
   146 \begin{ttdescription}
   164     sign_of} to get a theory's signature.
   165     sign_of} to get a theory's signature.
   165 
   166 
   166 \item[\ttindexbold{cterm_instantiate} {\it ctpairs} {\it thm}] 
   167 \item[\ttindexbold{cterm_instantiate} {\it ctpairs} {\it thm}] 
   167 is similar to {\tt read_instantiate}, but the instantiations are provided
   168 is similar to {\tt read_instantiate}, but the instantiations are provided
   168 as pairs of certified terms, not as strings to be read.
   169 as pairs of certified terms, not as strings to be read.
       
   170 
       
   171 \item[\ttindexbold{instantiate'} {\it ctyps} {\it cterms} {\it thm}]
       
   172   instantiates {\it thm} according to the positional arguments {\it
       
   173     ctyps} and {\it cterms}.  Counting from left to right, schematic
       
   174   variables $?x$ are either replaced by $t$ for any argument
       
   175   \texttt{Some\(\;t\)}, or left unchanged in case of \texttt{None} or
       
   176   if the end of the argument list is encountered.  Types are
       
   177   instantiated before terms.
       
   178 
   169 \end{ttdescription}
   179 \end{ttdescription}
   170 
   180 
   171 
   181 
   172 \subsection{Miscellaneous forward rules}\label{MiscellaneousForwardRules}
   182 \subsection{Miscellaneous forward rules}\label{MiscellaneousForwardRules}
   173 \index{theorems!standardizing}
   183 \index{theorems!standardizing}
   206 
   216 
   207 \subsection{Taking a theorem apart}
   217 \subsection{Taking a theorem apart}
   208 \index{theorems!taking apart}
   218 \index{theorems!taking apart}
   209 \index{flex-flex constraints}
   219 \index{flex-flex constraints}
   210 \begin{ttbox} 
   220 \begin{ttbox} 
       
   221 cprop_of      : thm -> cterm
   211 concl_of      : thm -> term
   222 concl_of      : thm -> term
   212 prems_of      : thm -> term list
   223 prems_of      : thm -> term list
       
   224 cprems_of     : thm -> cterm list
   213 nprems_of     : thm -> int
   225 nprems_of     : thm -> int
   214 tpairs_of     : thm -> (term*term)list
   226 tpairs_of     : thm -> (term * term) list
   215 stamps_of_thy : thm -> string ref list
   227 sign_of_thm   : thm -> Sign.sg
   216 theory_of_thm : thm -> theory
   228 theory_of_thm : thm -> theory
   217 dest_state    : thm*int -> (term*term)list*term list*term*term
   229 dest_state    : thm * int -> (term * term) list * term list * term * term
   218 rep_thm       : thm -> {\ttlbrace}prop: term, hyps: term list, der: deriv, 
   230 rep_thm       : thm -> {\ttlbrace}sign_ref: Sign.sg_ref, der: deriv, maxidx: int,
   219                         maxidx: int, sign: Sign.sg, shyps: sort list\ttrbrace
   231                         shyps: sort list, hyps: term list, prop: term\ttrbrace
   220 \end{ttbox}
   232 crep_thm      : thm -> {\ttlbrace}sign_ref: Sign.sg_ref, der: deriv, maxidx: int,
   221 \begin{ttdescription}
   233                         shyps: sort list, hyps: cterm list, prop: cterm\ttrbrace
   222 \item[\ttindexbold{concl_of} $thm$] 
   234 \end{ttbox}
   223 returns the conclusion of $thm$ as a term.
   235 \begin{ttdescription}
   224 
   236 \item[\ttindexbold{cprop_of} $thm$] returns the statement of $thm$ as
   225 \item[\ttindexbold{prems_of} $thm$] 
   237   a certified term.
   226 returns the premises of $thm$ as a list of terms.
   238   
       
   239 \item[\ttindexbold{concl_of} $thm$] returns the conclusion of $thm$ as
       
   240   a term.
       
   241   
       
   242 \item[\ttindexbold{prems_of} $thm$] returns the premises of $thm$ as a
       
   243   list of terms.
       
   244   
       
   245 \item[\ttindexbold{cprems_of} $thm$] returns the premises of $thm$ as
       
   246   a list of certified terms.
   227 
   247 
   228 \item[\ttindexbold{nprems_of} $thm$] 
   248 \item[\ttindexbold{nprems_of} $thm$] 
   229 returns the number of premises in $thm$, and is equivalent to {\tt
   249 returns the number of premises in $thm$, and is equivalent to {\tt
   230   length(prems_of~$thm$)}.
   250   length~(prems_of~$thm$)}.
   231 
   251 
   232 \item[\ttindexbold{tpairs_of} $thm$] 
   252 \item[\ttindexbold{tpairs_of} $thm$] returns the flex-flex constraints
   233 returns the flex-flex constraints of $thm$.
   253   of $thm$.
   234 
   254   
   235 \item[\ttindexbold{stamps_of_thm} $thm$] 
   255 \item[\ttindexbold{sign_of_thm} $thm$] returns the signature
   236 returns the \rmindex{stamps} of the signature associated with~$thm$.
   256   associated with $thm$.
   237 
   257   
   238 \item[\ttindexbold{theory_of_thm} $thm$]
   258 \item[\ttindexbold{theory_of_thm} $thm$] returns the theory associated
   239 returns the theory associated with $thm$.
   259   with $thm$.  Note that this does a lookup in Isabelle's global
       
   260   database of loaded theories.
   240 
   261 
   241 \item[\ttindexbold{dest_state} $(thm,i)$] 
   262 \item[\ttindexbold{dest_state} $(thm,i)$] 
   242 decomposes $thm$ as a tuple containing a list of flex-flex constraints, a
   263 decomposes $thm$ as a tuple containing a list of flex-flex constraints, a
   243 list of the subgoals~1 to~$i-1$, subgoal~$i$, and the rest of the theorem
   264 list of the subgoals~1 to~$i-1$, subgoal~$i$, and the rest of the theorem
   244 (this will be an implication if there are more than $i$ subgoals).
   265 (this will be an implication if there are more than $i$ subgoals).
   245 
   266 
   246 \item[\ttindexbold{rep_thm} $thm$] decomposes $thm$ as a record containing the
   267 \item[\ttindexbold{rep_thm} $thm$] decomposes $thm$ as a record
   247   statement of~$thm$ ({\tt prop}), its list of meta-assumptions ({\tt hyps}),
   268   containing the statement of~$thm$ ({\tt prop}), its list of
   248   its derivation ({\tt der}), a bound on the maximum subscript of its
   269   meta-assumptions ({\tt hyps}), its derivation ({\tt der}), a bound
   249   unknowns ({\tt maxidx}), and its signature ({\tt sign}).  The {\tt shyps}
   270   on the maximum subscript of its unknowns ({\tt maxidx}), and a
   250   field is discussed below.
   271   reference to its signature ({\tt sign_ref}).  The {\tt shyps} field
       
   272   is discussed below.
       
   273   
       
   274 \item[\ttindexbold{crep_thm} $thm$] like \texttt{rep_thm}, but returns
       
   275   the hypotheses and statement as certified terms.
       
   276 
   251 \end{ttdescription}
   277 \end{ttdescription}
   252 
   278 
   253 
   279 
   254 \subsection{*Sort hypotheses} 
   280 \subsection{*Sort hypotheses} 
   255 \index{sort hypotheses}
   281 \index{sort hypotheses}
   265 Isabelle's type variables are decorated with sorts, constraining them to
   291 Isabelle's type variables are decorated with sorts, constraining them to
   266 certain ranges of types.  This has little impact when sorts only serve for
   292 certain ranges of types.  This has little impact when sorts only serve for
   267 syntactic classification of types --- for example, FOL distinguishes between
   293 syntactic classification of types --- for example, FOL distinguishes between
   268 terms and other types.  But when type classes are introduced through axioms,
   294 terms and other types.  But when type classes are introduced through axioms,
   269 this may result in some sorts becoming {\em empty\/}: where one cannot exhibit
   295 this may result in some sorts becoming {\em empty\/}: where one cannot exhibit
   270 a type belonging to it because certain axioms are unsatisfiable.
   296 a type belonging to it because certain sets of axioms are unsatisfiable.
   271 
   297 
   272 If a theorem contains a type variable that is constrained by an empty
   298 If a theorem contains a type variable that is constrained by an empty
   273 sort, then that theorem has no instances.  It is basically an instance
   299 sort, then that theorem has no instances.  It is basically an instance
   274 of {\em ex falso quodlibet}.  But what if it is used to prove another
   300 of {\em ex falso quodlibet}.  But what if it is used to prove another
   275 theorem that no longer involves that sort?  The latter theorem holds
   301 theorem that no longer involves that sort?  The latter theorem holds
   299 \end{ttbox}
   325 \end{ttbox}
   300 Tracing the search may be useful when higher-order unification behaves
   326 Tracing the search may be useful when higher-order unification behaves
   301 unexpectedly.  Letting {\tt res_inst_tac} circumvent the problem is easier,
   327 unexpectedly.  Letting {\tt res_inst_tac} circumvent the problem is easier,
   302 though.
   328 though.
   303 \begin{ttdescription}
   329 \begin{ttdescription}
   304 \item[Unify.trace_simp := true;] 
   330 \item[set Unify.trace_simp;] 
   305 causes tracing of the simplification phase.
   331 causes tracing of the simplification phase.
   306 
   332 
   307 \item[Unify.trace_types := true;] 
   333 \item[set Unify.trace_types;] 
   308 generates warnings of incompleteness, when unification is not considering
   334 generates warnings of incompleteness, when unification is not considering
   309 all possible instantiations of type unknowns.
   335 all possible instantiations of type unknowns.
   310 
   336 
   311 \item[Unify.trace_bound := $n$;] 
   337 \item[Unify.trace_bound := $n$;] 
   312 causes unification to print tracing information once it reaches depth~$n$.
   338 causes unification to print tracing information once it reaches depth~$n$.
   313 Use $n=0$ for full tracing.  At the default value of~10, tracing
   339 Use $n=0$ for full tracing.  At the default value of~10, tracing
   314 information is almost never printed.
   340 information is almost never printed.
   315 
   341 
   316 \item[Unify.search_bound := $n$;] 
   342 \item[Unify.search_bound := $n$;] causes unification to limit its
   317 causes unification to limit its search to depth~$n$.  Because of this
   343   search to depth~$n$.  Because of this bound, higher-order
   318 bound, higher-order unification cannot return an infinite sequence, though
   344   unification cannot return an infinite sequence, though it can return
   319 it can return a very long one.  The search rarely approaches the default
   345   a very long one.  The search rarely approaches the default value
   320 value of~20.  If the search is cut off, unification prints {\tt
   346   of~20.  If the search is cut off, unification prints a warning
   321 ***Unification bound exceeded}.
   347   \texttt{Unification bound exceeded}.
   322 \end{ttdescription}
   348 \end{ttdescription}
   323 
   349 
   324 
   350 
   325 \section{Primitive meta-level inference rules}
   351 \section{*Primitive meta-level inference rules}
   326 \index{meta-rules|(}
   352 \index{meta-rules|(}
   327 These implement the meta-logic in {\sc lcf} style, as functions from theorems
   353 These implement the meta-logic in the style of the {\sc lcf} system,
   328 to theorems.  They are, rarely, useful for deriving results in the pure
   354 as functions from theorems to theorems.  They are, rarely, useful for
   329 theory.  Mainly, they are included for completeness, and most users should
   355 deriving results in the pure theory.  Mainly, they are included for
   330 not bother with them.  The meta-rules raise exception \xdx{THM} to signal
   356 completeness, and most users should not bother with them.  The
   331 malformed premises, incompatible signatures and similar errors.
   357 meta-rules raise exception \xdx{THM} to signal malformed premises,
       
   358 incompatible signatures and similar errors.
   332 
   359 
   333 \index{meta-assumptions}
   360 \index{meta-assumptions}
   334 The meta-logic uses natural deduction.  Each theorem may depend on
   361 The meta-logic uses natural deduction.  Each theorem may depend on
   335 meta-level assumptions.  Certain rules, such as $({\Imp}I)$,
   362 meta-level assumptions.  Certain rules, such as $({\Imp}I)$,
   336 discharge assumptions; in most other rules, the conclusion depends on all
   363 discharge assumptions; in most other rules, the conclusion depends on all
   692 \index{proof objects|(} Isabelle can record the full meta-level proof of each
   719 \index{proof objects|(} Isabelle can record the full meta-level proof of each
   693 theorem.  The proof object contains all logical inferences in detail, while
   720 theorem.  The proof object contains all logical inferences in detail, while
   694 omitting bookkeeping steps that have no logical meaning to an outside
   721 omitting bookkeeping steps that have no logical meaning to an outside
   695 observer.  Rewriting steps are recorded in similar detail as the output of
   722 observer.  Rewriting steps are recorded in similar detail as the output of
   696 simplifier tracing.  The proof object can be inspected by a separate
   723 simplifier tracing.  The proof object can be inspected by a separate
   697 proof-checker, or used to generate human-readable proof digests.
   724 proof-checker, for example.
   698 
   725 
   699 Full proof objects are large.  They multiply storage requirements by about
   726 Full proof objects are large.  They multiply storage requirements by about
   700 seven; attempts to build large logics (such as {\sc zf} and {\sc hol}) may
   727 seven; attempts to build large logics (such as {\sc zf} and {\sc hol}) may
   701 fail.  Isabelle normally builds minimal proof objects, which include only uses
   728 fail.  Isabelle normally builds minimal proof objects, which include only uses
   702 of oracles.  You can also request an intermediate level of detail, containing
   729 of oracles.  You can also request an intermediate level of detail, containing
   725 %
   752 %
   726 Each theorem's derivation is stored as the {\tt der} field of its internal
   753 Each theorem's derivation is stored as the {\tt der} field of its internal
   727 record: 
   754 record: 
   728 \begin{ttbox} 
   755 \begin{ttbox} 
   729 #der (rep_thm conjI);
   756 #der (rep_thm conjI);
   730 {\out Join (Theorem "conjI", [Join (MinProof,[])]) : deriv}
   757 {\out Join (Theorem "HOL.conjI", [Join (MinProof,[])]) : deriv}
   731 \end{ttbox}
   758 \end{ttbox}
   732 This proof object identifies a labelled theorem, {\tt conjI}, whose underlying
   759 This proof object identifies a labelled theorem, {\tt conjI} of theory
   733 proof has not been recorded; all we have is {\tt MinProof}.
   760 \texttt{HOL}, whose underlying proof has not been recorded; all we
       
   761 have is {\tt MinProof}.
   734 
   762 
   735 Nontrivial proof objects are unreadably large and complex.  Isabelle provides
   763 Nontrivial proof objects are unreadably large and complex.  Isabelle provides
   736 several functions to help you inspect them informally.  These functions omit
   764 several functions to help you inspect them informally.  These functions omit
   737 the more obscure inferences and attempt to restructure the others into natural
   765 the more obscure inferences and attempt to restructure the others into natural
   738 formats, linear or tree-structured.
   766 formats, linear or tree-structured.