doc-src/IsarRef/ML_Tactic.thy
changeset 48985 5386df44a037
parent 48984 f51d4a302962
child 48986 037d32448e29
equal deleted inserted replaced
48984:f51d4a302962 48985:5386df44a037
     1 theory ML_Tactic
       
     2 imports Base Main
       
     3 begin
       
     4 
       
     5 chapter {* ML tactic expressions *}
       
     6 
       
     7 text {*
       
     8   Isar Proof methods closely resemble traditional tactics, when used
       
     9   in unstructured sequences of @{command "apply"} commands.
       
    10   Isabelle/Isar provides emulations for all major ML tactics of
       
    11   classic Isabelle --- mostly for the sake of easy porting of existing
       
    12   developments, as actual Isar proof texts would demand much less
       
    13   diversity of proof methods.
       
    14 
       
    15   Unlike tactic expressions in ML, Isar proof methods provide proper
       
    16   concrete syntax for additional arguments, options, modifiers etc.
       
    17   Thus a typical method text is usually more concise than the
       
    18   corresponding ML tactic.  Furthermore, the Isar versions of classic
       
    19   Isabelle tactics often cover several variant forms by a single
       
    20   method with separate options to tune the behavior.  For example,
       
    21   method @{method simp} replaces all of @{ML simp_tac}~/ @{ML
       
    22   asm_simp_tac}~/ @{ML full_simp_tac}~/ @{ML asm_full_simp_tac}, there
       
    23   is also concrete syntax for augmenting the Simplifier context (the
       
    24   current ``simpset'') in a convenient way.
       
    25 *}
       
    26 
       
    27 
       
    28 section {* Resolution tactics *}
       
    29 
       
    30 text {*
       
    31   Classic Isabelle provides several variant forms of tactics for
       
    32   single-step rule applications (based on higher-order resolution).
       
    33   The space of resolution tactics has the following main dimensions.
       
    34 
       
    35   \begin{enumerate}
       
    36 
       
    37   \item The ``mode'' of resolution: intro, elim, destruct, or forward
       
    38   (e.g.\ @{ML resolve_tac}, @{ML eresolve_tac}, @{ML dresolve_tac},
       
    39   @{ML forward_tac}).
       
    40 
       
    41   \item Optional explicit instantiation (e.g.\ @{ML resolve_tac} vs.\
       
    42   @{ML res_inst_tac}).
       
    43 
       
    44   \item Abbreviations for singleton arguments (e.g.\ @{ML resolve_tac}
       
    45   vs.\ @{ML rtac}).
       
    46 
       
    47   \end{enumerate}
       
    48 
       
    49   Basically, the set of Isar tactic emulations @{method rule_tac},
       
    50   @{method erule_tac}, @{method drule_tac}, @{method frule_tac} (see
       
    51   \secref{sec:tactics}) would be sufficient to cover the four modes,
       
    52   either with or without instantiation, and either with single or
       
    53   multiple arguments.  Although it is more convenient in most cases to
       
    54   use the plain @{method_ref (Pure) rule} method, or any of its
       
    55   ``improper'' variants @{method erule}, @{method drule}, @{method
       
    56   frule}.  Note that explicit goal addressing is only supported by the
       
    57   actual @{method rule_tac} version.
       
    58 
       
    59   With this in mind, plain resolution tactics correspond to Isar
       
    60   methods as follows.
       
    61 
       
    62   \medskip
       
    63   \begin{tabular}{lll}
       
    64     @{ML rtac}~@{text "a 1"} & & @{text "rule a"} \\
       
    65     @{ML resolve_tac}~@{text "[a\<^sub>1, \<dots>] 1"} & & @{text "rule a\<^sub>1 \<dots>"} \\
       
    66     @{ML res_inst_tac}~@{text "ctxt [(x\<^sub>1, t\<^sub>1), \<dots>] a 1"} & &
       
    67     @{text "rule_tac x\<^sub>1 = t\<^sub>1 \<AND> \<dots> \<IN> a"} \\[0.5ex]
       
    68     @{ML rtac}~@{text "a i"} & & @{text "rule_tac [i] a"} \\
       
    69     @{ML resolve_tac}~@{text "[a\<^sub>1, \<dots>] i"} & & @{text "rule_tac [i] a\<^sub>1 \<dots>"} \\
       
    70     @{ML res_inst_tac}~@{text "ctxt [(x\<^sub>1, t\<^sub>1), \<dots>] a i"} & &
       
    71     @{text "rule_tac [i] x\<^sub>1 = t\<^sub>1 \<AND> \<dots> \<IN> a"} \\
       
    72   \end{tabular}
       
    73   \medskip
       
    74 
       
    75   Note that explicit goal addressing may be usually avoided by
       
    76   changing the order of subgoals with @{command "defer"} or @{command
       
    77   "prefer"} (see \secref{sec:tactic-commands}).
       
    78 *}
       
    79 
       
    80 
       
    81 section {* Simplifier tactics *}
       
    82 
       
    83 text {*
       
    84   The main Simplifier tactics @{ML simp_tac} and variants (cf.\
       
    85   \cite{isabelle-ref}) are all covered by the @{method simp} and
       
    86   @{method simp_all} methods (see \secref{sec:simplifier}).  Note that
       
    87   there is no individual goal addressing available, simplification
       
    88   acts either on the first goal (@{method simp}) or all goals
       
    89   (@{method simp_all}).
       
    90 
       
    91   \medskip
       
    92   \begin{tabular}{lll}
       
    93     @{ML asm_full_simp_tac}~@{text "@{simpset} 1"} & & @{method simp} \\
       
    94     @{ML ALLGOALS}~(@{ML asm_full_simp_tac}~@{text "@{simpset}"}) & & @{method simp_all} \\[0.5ex]
       
    95     @{ML simp_tac}~@{text "@{simpset} 1"} & & @{method simp}~@{text "(no_asm)"} \\
       
    96     @{ML asm_simp_tac}~@{text "@{simpset} 1"} & & @{method simp}~@{text "(no_asm_simp)"} \\
       
    97     @{ML full_simp_tac}~@{text "@{simpset} 1"} & & @{method simp}~@{text "(no_asm_use)"} \\
       
    98     @{ML asm_lr_simp_tac}~@{text "@{simpset} 1"} & & @{method simp}~@{text "(asm_lr)"} \\
       
    99   \end{tabular}
       
   100   \medskip
       
   101 *}
       
   102 
       
   103 
       
   104 section {* Classical Reasoner tactics *}
       
   105 
       
   106 text {* The Classical Reasoner provides a rather large number of
       
   107   variations of automated tactics, such as @{ML blast_tac}, @{ML
       
   108   fast_tac}, @{ML clarify_tac} etc.  The corresponding Isar methods
       
   109   usually share the same base name, such as @{method blast}, @{method
       
   110   fast}, @{method clarify} etc.\ (see \secref{sec:classical}).  *}
       
   111 
       
   112 
       
   113 section {* Miscellaneous tactics *}
       
   114 
       
   115 text {*
       
   116   There are a few additional tactics defined in various theories of
       
   117   Isabelle/HOL, some of these also in Isabelle/FOL or Isabelle/ZF.
       
   118   The most common ones of these may be ported to Isar as follows.
       
   119 
       
   120   \medskip
       
   121   \begin{tabular}{lll}
       
   122     @{ML stac}~@{text "a 1"} & & @{text "subst a"} \\
       
   123     @{ML hyp_subst_tac}~@{text 1} & & @{text hypsubst} \\
       
   124     @{ML strip_tac}~@{text 1} & @{text "\<approx>"} & @{text "intro strip"} \\
       
   125     @{ML split_all_tac}~@{text 1} & & @{text "simp (no_asm_simp) only: split_tupled_all"} \\
       
   126       & @{text "\<approx>"} & @{text "simp only: split_tupled_all"} \\
       
   127       & @{text "\<lless>"} & @{text "clarify"} \\
       
   128   \end{tabular}
       
   129 *}
       
   130 
       
   131 
       
   132 section {* Tacticals *}
       
   133 
       
   134 text {*
       
   135   Classic Isabelle provides a huge amount of tacticals for combination
       
   136   and modification of existing tactics.  This has been greatly reduced
       
   137   in Isar, providing the bare minimum of combinators only: ``@{text
       
   138   ","}'' (sequential composition), ``@{text "|"}'' (alternative
       
   139   choices), ``@{text "?"}'' (try), ``@{text "+"}'' (repeat at least
       
   140   once).  These are usually sufficient in practice; if all fails,
       
   141   arbitrary ML tactic code may be invoked via the @{method tactic}
       
   142   method (see \secref{sec:tactics}).
       
   143 
       
   144   \medskip Common ML tacticals may be expressed directly in Isar as
       
   145   follows:
       
   146 
       
   147   \medskip
       
   148   \begin{tabular}{lll}
       
   149     @{text "tac\<^sub>1"}~@{ML_text THEN}~@{text "tac\<^sub>2"} & & @{text "meth\<^sub>1, meth\<^sub>2"} \\
       
   150     @{text "tac\<^sub>1"}~@{ML_text ORELSE}~@{text "tac\<^sub>2"} & & @{text "meth\<^sub>1 | meth\<^sub>2"} \\
       
   151     @{ML TRY}~@{text tac} & & @{text "meth?"} \\
       
   152     @{ML REPEAT1}~@{text tac} & & @{text "meth+"} \\
       
   153     @{ML REPEAT}~@{text tac} & & @{text "(meth+)?"} \\
       
   154     @{ML EVERY}~@{text "[tac\<^sub>1, \<dots>]"} & & @{text "meth\<^sub>1, \<dots>"} \\
       
   155     @{ML FIRST}~@{text "[tac\<^sub>1, \<dots>]"} & & @{text "meth\<^sub>1 | \<dots>"} \\
       
   156   \end{tabular}
       
   157   \medskip
       
   158 
       
   159   \medskip @{ML CHANGED} (see \cite{isabelle-implementation}) is
       
   160   usually not required in Isar, since most basic proof methods already
       
   161   fail unless there is an actual change in the goal state.
       
   162   Nevertheless, ``@{text "?"}''  (try) may be used to accept
       
   163   \emph{unchanged} results as well.
       
   164 
       
   165   \medskip @{ML ALLGOALS}, @{ML SOMEGOAL} etc.\ (see
       
   166   \cite{isabelle-implementation}) are not available in Isar, since
       
   167   there is no direct goal addressing.  Nevertheless, some basic
       
   168   methods address all goals internally, notably @{method simp_all}
       
   169   (see \secref{sec:simplifier}).  Also note that @{ML ALLGOALS} can be
       
   170   often replaced by ``@{text "+"}'' (repeat at least once), although
       
   171   this usually has a different operational behavior: subgoals are
       
   172   solved in a different order.
       
   173 
       
   174   \medskip Iterated resolution, such as
       
   175   @{ML_text "REPEAT (FIRSTGOAL (resolve_tac ...))"}, is usually better
       
   176   expressed using the @{method intro} and @{method elim} methods of
       
   177   Isar (see \secref{sec:classical}).
       
   178 *}
       
   179 
       
   180 end