doc-src/IsarRef/generic.tex
changeset 13048 8b2eb3b78cc3
parent 13042 d8a345d9e067
child 13411 181a293aa37a
equal deleted inserted replaced
13047:f27cc0a43feb 13048:8b2eb3b78cc3
     1 
     1 
     2 \chapter{Generic Tools and Packages}\label{ch:gen-tools}
     2 \chapter{Generic tools and packages}\label{ch:gen-tools}
     3 
     3 
     4 \section{Theory specification commands}
     4 \section{Theory specification commands}
     5 
     5 
     6 \subsection{Axiomatic type classes}\label{sec:axclass}
     6 \subsection{Axiomatic type classes}\label{sec:axclass}
     7 
     7 
    59 \subsection{Locales and local contexts}\label{sec:locale}
    59 \subsection{Locales and local contexts}\label{sec:locale}
    60 
    60 
    61 Locales are named local contexts, consisting of a list of declaration elements
    61 Locales are named local contexts, consisting of a list of declaration elements
    62 that are modeled after the Isar proof context commands (cf.\
    62 that are modeled after the Isar proof context commands (cf.\
    63 \S\ref{sec:proof-context}).
    63 \S\ref{sec:proof-context}).
       
    64 
    64 
    65 
    65 \subsubsection{Localized commands}
    66 \subsubsection{Localized commands}
    66 
    67 
    67 Existing locales may be augmented later on by adding new facts.  Note that the
    68 Existing locales may be augmented later on by adding new facts.  Note that the
    68 actual context definition may not be changed!  Several theory commands that
    69 actual context definition may not be changed!  Several theory commands that
   236   \quad \QED{} \\
   237   \quad \QED{} \\
   237   \quad \FIX{\vec x}~\ASSUMENAME^\ast~a\colon~\vec\phi \\
   238   \quad \FIX{\vec x}~\ASSUMENAME^\ast~a\colon~\vec\phi \\
   238 \end{matharray}
   239 \end{matharray}
   239 
   240 
   240 Typically, the soundness proof is relatively straight-forward, often just by
   241 Typically, the soundness proof is relatively straight-forward, often just by
   241 canonical automated tools such as ``$\BY{simp}$'' (see \S\ref{sec:simp}) or
   242 canonical automated tools such as ``$\BY{simp}$'' or ``$\BY{blast}$''.
   242 ``$\BY{blast}$'' (see \S\ref{sec:classical-auto}).  Accordingly, the
   243 Accordingly, the ``$that$'' reduction above is declared as simplification and
   243 ``$that$'' reduction above is declared as simplification and introduction
   244 introduction rule.
   244 rule.
       
   245 
   245 
   246 \medskip
   246 \medskip
   247 
   247 
   248 In a sense, $\OBTAINNAME$ represents at the level of Isar proofs what would be
   248 In a sense, $\OBTAINNAME$ represents at the level of Isar proofs what would be
   249 meta-logical existential quantifiers and conjunctions.  This concept has a
   249 meta-logical existential quantifiers and conjunctions.  This concept has a
   464   given meta-level definitions throughout a rule.
   464   given meta-level definitions throughout a rule.
   465 
   465 
   466 \item [$elim_format$] turns a destruction rule into elimination rule format,
   466 \item [$elim_format$] turns a destruction rule into elimination rule format,
   467   by resolving with the rule $\PROP A \Imp (\PROP A \Imp \PROP B) \Imp \PROP
   467   by resolving with the rule $\PROP A \Imp (\PROP A \Imp \PROP B) \Imp \PROP
   468   B$.
   468   B$.
   469 
   469   
   470   Note that the Classical Reasoner (\S\ref{sec:classical-att}) provides its
   470   Note that the Classical Reasoner (\S\ref{sec:classical}) provides its own
   471   own version of this operation.
   471   version of this operation.
   472 
   472 
   473 \item [$standard$] puts a theorem into the standard form of object-rules at
   473 \item [$standard$] puts a theorem into the standard form of object-rules at
   474   the outermost theory level.  Note that this operation violates the local
   474   the outermost theory level.  Note that this operation violates the local
   475   proof context (including active locales).
   475   proof context (including active locales).
   476 
   476 
   610 \end{descr}
   610 \end{descr}
   611 
   611 
   612 
   612 
   613 \subsection{The Simplifier}\label{sec:simplifier}
   613 \subsection{The Simplifier}\label{sec:simplifier}
   614 
   614 
   615 \subsubsection{Simplification methods}\label{sec:simp}
   615 \subsubsection{Simplification methods}
   616 
   616 
   617 \indexisarmeth{simp}\indexisarmeth{simp-all}
   617 \indexisarmeth{simp}\indexisarmeth{simp-all}
   618 \begin{matharray}{rcl}
   618 \begin{matharray}{rcl}
   619   simp & : & \isarmeth \\
   619   simp & : & \isarmeth \\
   620   simp_all & : & \isarmeth \\
   620   simp_all & : & \isarmeth \\
   735   opt: '(' (noasm | noasmsimp | noasmuse) ')'
   735   opt: '(' (noasm | noasmsimp | noasmuse) ')'
   736   ;
   736   ;
   737 \end{rail}
   737 \end{rail}
   738 
   738 
   739 \begin{descr}
   739 \begin{descr}
   740 
   740   
   741 \item [$simplified~\vec a$] causes a theorem to be simplified, either by
   741 \item [$simplified~\vec a$] causes a theorem to be simplified, either by
   742   exactly the specified rules $\vec a$, or the implicit Simplifier context if
   742   exactly the specified rules $\vec a$, or the implicit Simplifier context if
   743   no arguments are given.  The result is fully simplified by default,
   743   no arguments are given.  The result is fully simplified by default,
   744   including assumptions and conclusion; the options $no_asm$ etc.\ tune the
   744   including assumptions and conclusion; the options $no_asm$ etc.\ tune the
   745   Simplifier in the same way as the for the $simp$ method (see
   745   Simplifier in the same way as the for the $simp$ method.
   746   \S\ref{sec:simp}).
       
   747 
   746 
   748   Note that forward simplification restricts the simplifier to its most basic
   747   Note that forward simplification restricts the simplifier to its most basic
   749   operation of term rewriting; solver and looper tactics \cite{isabelle-ref}
   748   operation of term rewriting; solver and looper tactics \cite{isabelle-ref}
   750   are \emph{not} involved here.  The $simplified$ attribute should be only
   749   are \emph{not} involved here.  The $simplified$ attribute should be only
   751   rarely required under normal circumstances.
   750   rarely required under normal circumstances.
   752 
   751 
   753 \end{descr}
   752 \end{descr}
   754 
   753 
   755 
   754 
   756 \subsubsection{Low-level equational reasoning}\label{sec:basic-eq}
   755 \subsubsection{Low-level equational reasoning}
   757 
   756 
   758 \indexisarmeth{subst}\indexisarmeth{hypsubst}\indexisarmeth{split}
   757 \indexisarmeth{subst}\indexisarmeth{hypsubst}\indexisarmeth{split}
   759 \begin{matharray}{rcl}
   758 \begin{matharray}{rcl}
   760   subst^* & : & \isarmeth \\
   759   subst^* & : & \isarmeth \\
   761   hypsubst^* & : & \isarmeth \\
   760   hypsubst^* & : & \isarmeth \\
   785   variable.
   784   variable.
   786 
   785 
   787 \item [$split~\vec a$] performs single-step case splitting using rules $thms$.
   786 \item [$split~\vec a$] performs single-step case splitting using rules $thms$.
   788   By default, splitting is performed in the conclusion of a goal; the $asm$
   787   By default, splitting is performed in the conclusion of a goal; the $asm$
   789   option indicates to operate on assumptions instead.
   788   option indicates to operate on assumptions instead.
   790 
   789   
   791   Note that the $simp$ method already involves repeated application of split
   790   Note that the $simp$ method already involves repeated application of split
   792   rules as declared in the current context (see \S\ref{sec:simp}).
   791   rules as declared in the current context.
   793 \end{descr}
   792 \end{descr}
   794 
   793 
   795 
   794 
   796 \subsection{The Classical Reasoner}\label{sec:classical}
   795 \subsection{The Classical Reasoner}\label{sec:classical}
   797 
   796 
   798 \subsubsection{Basic methods}\label{sec:classical-basic}
   797 \subsubsection{Basic methods}
   799 
   798 
   800 \indexisarmeth{rule}\indexisarmeth{default}\indexisarmeth{contradiction}
   799 \indexisarmeth{rule}\indexisarmeth{default}\indexisarmeth{contradiction}
   801 \indexisarmeth{intro}\indexisarmeth{elim}
   800 \indexisarmeth{intro}\indexisarmeth{elim}
   802 \begin{matharray}{rcl}
   801 \begin{matharray}{rcl}
   803   rule & : & \isarmeth \\
   802   rule & : & \isarmeth \\
   833   decomposition of a proof problem, in contrast to common automated tools.
   832   decomposition of a proof problem, in contrast to common automated tools.
   834 
   833 
   835 \end{descr}
   834 \end{descr}
   836 
   835 
   837 
   836 
   838 \subsubsection{Automated methods}\label{sec:classical-auto}
   837 \subsubsection{Automated methods}
   839 
   838 
   840 \indexisarmeth{blast}\indexisarmeth{fast}\indexisarmeth{slow}
   839 \indexisarmeth{blast}\indexisarmeth{fast}\indexisarmeth{slow}
   841 \indexisarmeth{best}\indexisarmeth{safe}\indexisarmeth{clarify}
   840 \indexisarmeth{best}\indexisarmeth{safe}\indexisarmeth{clarify}
   842 \begin{matharray}{rcl}
   841 \begin{matharray}{rcl}
   843   blast & : & \isarmeth \\
   842   blast & : & \isarmeth \\
   906 \item [$auto$, $force$, $clarsimp$, $fastsimp$, $slowsimp$, and $bestsimp$]
   905 \item [$auto$, $force$, $clarsimp$, $fastsimp$, $slowsimp$, and $bestsimp$]
   907   provide access to Isabelle's combined simplification and classical reasoning
   906   provide access to Isabelle's combined simplification and classical reasoning
   908   tactics.  These correspond to \texttt{auto_tac}, \texttt{force_tac},
   907   tactics.  These correspond to \texttt{auto_tac}, \texttt{force_tac},
   909   \texttt{clarsimp_tac}, and Classical Reasoner tactics with the Simplifier
   908   \texttt{clarsimp_tac}, and Classical Reasoner tactics with the Simplifier
   910   added as wrapper, see \cite[\S11]{isabelle-ref} for more information.  The
   909   added as wrapper, see \cite[\S11]{isabelle-ref} for more information.  The
   911   modifier arguments correspond to those given in \S\ref{sec:simp} and
   910   modifier arguments correspond to those given in \S\ref{sec:simplifier} and
   912   \S\ref{sec:classical-auto}.  Just note that the ones related to the
   911   \S\ref{sec:classical}.  Just note that the ones related to the Simplifier
   913   Simplifier are prefixed by \railtterm{simp} here.
   912   are prefixed by \railtterm{simp} here.
   914 
   913 
   915   Facts provided by forward chaining are inserted into the goal before doing
   914   Facts provided by forward chaining are inserted into the goal before doing
   916   the search.  The ``!''~argument causes the full context of assumptions to be
   915   the search.  The ``!''~argument causes the full context of assumptions to be
   917   included as well.
   916   included as well.
   918 \end{descr}
   917 \end{descr}
   919 
   918 
   920 
   919 
   921 \subsubsection{Declaring rules}\label{sec:classical-mod}
   920 \subsubsection{Declaring rules}
   922 
   921 
   923 \indexisarcmd{print-claset}
   922 \indexisarcmd{print-claset}
   924 \indexisaratt{intro}\indexisaratt{elim}\indexisaratt{dest}
   923 \indexisaratt{intro}\indexisaratt{elim}\indexisaratt{dest}
   925 \indexisaratt{iff}\indexisaratt{rule}
   924 \indexisaratt{iff}\indexisaratt{rule}
   926 \begin{matharray}{rcl}
   925 \begin{matharray}{rcl}
   967   and omits the Simplifier declaration.
   966   and omits the Simplifier declaration.
   968 
   967 
   969 \end{descr}
   968 \end{descr}
   970 
   969 
   971 
   970 
   972 \subsubsection{Classical operations}\label{sec:classical-att}
   971 \subsubsection{Classical operations}
   973 
   972 
   974 \indexisaratt{elim-format}\indexisaratt{swapped}
   973 \indexisaratt{elim-format}\indexisaratt{swapped}
   975 
   974 
   976 \begin{matharray}{rcl}
   975 \begin{matharray}{rcl}
   977   elim_format & : & \isaratt \\
   976   elim_format & : & \isaratt \\
   992 \end{descr}
   991 \end{descr}
   993 
   992 
   994 
   993 
   995 \subsection{Proof by cases and induction}\label{sec:cases-induct}
   994 \subsection{Proof by cases and induction}\label{sec:cases-induct}
   996 
   995 
   997 \subsubsection{Rule contexts}\label{sec:rule-cases}
   996 \subsubsection{Rule contexts}
   998 
   997 
   999 \indexisarcmd{case}\indexisarcmd{print-cases}
   998 \indexisarcmd{case}\indexisarcmd{print-cases}
  1000 \indexisaratt{case-names}\indexisaratt{params}\indexisaratt{consumes}
   999 \indexisaratt{case-names}\indexisaratt{params}\indexisaratt{consumes}
  1001 \begin{matharray}{rcl}
  1000 \begin{matharray}{rcl}
  1002   \isarcmd{case} & : & \isartrans{proof(state)}{proof(state)} \\
  1001   \isarcmd{case} & : & \isartrans{proof(state)}{proof(state)} \\
  1104 
  1103 
  1105 The $cases$ and $induct$ methods provide a uniform interface to case analysis
  1104 The $cases$ and $induct$ methods provide a uniform interface to case analysis
  1106 and induction over datatypes, inductive sets, and recursive functions.  The
  1105 and induction over datatypes, inductive sets, and recursive functions.  The
  1107 corresponding rules may be specified and instantiated in a casual manner.
  1106 corresponding rules may be specified and instantiated in a casual manner.
  1108 Furthermore, these methods provide named local contexts that may be invoked
  1107 Furthermore, these methods provide named local contexts that may be invoked
  1109 via the $\CASENAME$ proof command within the subsequent proof text (cf.\
  1108 via the $\CASENAME$ proof command within the subsequent proof text.  This
  1110 \S\ref{sec:rule-cases}).  This accommodates compact proof texts even when
  1109 accommodates compact proof texts even when reasoning about large
  1111 reasoning about large specifications.
  1110 specifications.
  1112 
  1111 
  1113 \begin{rail}
  1112 \begin{rail}
  1114   'cases' spec
  1113   'cases' spec
  1115   ;
  1114   ;
  1116   'induct' spec
  1115   'induct' spec
  1173 
  1172 
  1174   The ``$(open)$'' option works the same way as for $cases$.
  1173   The ``$(open)$'' option works the same way as for $cases$.
  1175 
  1174 
  1176 \end{descr}
  1175 \end{descr}
  1177 
  1176 
  1178 Above methods produce named local contexts (cf.\ \S\ref{sec:rule-cases}), as
  1177 Above methods produce named local contexts, as determined by the instantiated
  1179 determined by the instantiated rule as specified in the text.  Beyond that,
  1178 rule as specified in the text.  Beyond that, the $induct$ method guesses
  1180 the $induct$ method guesses further instantiations from the goal specification
  1179 further instantiations from the goal specification itself.  Any persisting
  1181 itself.  Any persisting unresolved schematic variables of the resulting rule
  1180 unresolved schematic variables of the resulting rule will render the the
  1182 will render the the corresponding case invalid.  The term binding
  1181 corresponding case invalid.  The term binding $\Var{case}$\indexisarvar{case}
  1183 $\Var{case}$\indexisarvar{case} for the conclusion will be provided with each
  1182 for the conclusion will be provided with each case, provided that term is
  1184 case, provided that term is fully specified.
  1183 fully specified.
  1185 
  1184 
  1186 The $\isarkeyword{print_cases}$ command (\S\ref{sec:rule-cases}) prints all
  1185 The $\isarkeyword{print_cases}$ command prints all named cases present in the
  1187 named cases present in the current proof state.
  1186 current proof state.
  1188 
  1187 
  1189 \medskip
  1188 \medskip
  1190 
  1189 
  1191 It is important to note that there is a fundamental difference of the $cases$
  1190 It is important to note that there is a fundamental difference of the $cases$
  1192 and $induct$ methods in handling of non-atomic goal statements: $cases$ just
  1191 and $induct$ methods in handling of non-atomic goal statements: $cases$ just
  1240 \item [$cases$ and $induct$] (as attributes) augment the corresponding context
  1239 \item [$cases$ and $induct$] (as attributes) augment the corresponding context
  1241   of rules for reasoning about inductive sets and types, using the
  1240   of rules for reasoning about inductive sets and types, using the
  1242   corresponding methods of the same name.  Certain definitional packages of
  1241   corresponding methods of the same name.  Certain definitional packages of
  1243   object-logics usually declare emerging cases and induction rules as
  1242   object-logics usually declare emerging cases and induction rules as
  1244   expected, so users rarely need to intervene.
  1243   expected, so users rarely need to intervene.
  1245 
  1244   
  1246   Manual rule declarations usually include the the $case_names$ and $ps$
  1245   Manual rule declarations usually include the the $case_names$ and $ps$
  1247   attributes to adjust names of cases and parameters of a rule (see
  1246   attributes to adjust names of cases and parameters of a rule (see
  1248   \S\ref{sec:rule-cases}); the $consumes$ declaration is taken care of
  1247   \S\ref{sec:cases-induct}); the $consumes$ declaration is taken care of
  1249   automatically: $consumes~0$ is specified for ``type'' rules and $consumes~1$
  1248   automatically: $consumes~0$ is specified for ``type'' rules and $consumes~1$
  1250   for ``set'' rules.
  1249   for ``set'' rules.
  1251 
  1250 
  1252 \end{descr}
  1251 \end{descr}
  1253 
  1252