src/Doc/Implementation/Tactic.thy
changeset 61477 e467ae7aa808
parent 61458 987533262fc2
child 61493 0debd22f0c0e
equal deleted inserted replaced
61476:1884c40f1539 61477:e467ae7aa808
    91 
    91 
    92 text \<open>A @{text "tactic"} is a function @{text "goal \<rightarrow> goal\<^sup>*\<^sup>*"} that
    92 text \<open>A @{text "tactic"} is a function @{text "goal \<rightarrow> goal\<^sup>*\<^sup>*"} that
    93   maps a given goal state (represented as a theorem, cf.\
    93   maps a given goal state (represented as a theorem, cf.\
    94   \secref{sec:tactical-goals}) to a lazy sequence of potential
    94   \secref{sec:tactical-goals}) to a lazy sequence of potential
    95   successor states.  The underlying sequence implementation is lazy
    95   successor states.  The underlying sequence implementation is lazy
    96   both in head and tail, and is purely functional in \emph{not}
    96   both in head and tail, and is purely functional in \<^emph>\<open>not\<close>
    97   supporting memoing.\footnote{The lack of memoing and the strict
    97   supporting memoing.\footnote{The lack of memoing and the strict
    98   nature of ML requires some care when working with low-level
    98   nature of ML requires some care when working with low-level
    99   sequence operations, to avoid duplicate or premature evaluation of
    99   sequence operations, to avoid duplicate or premature evaluation of
   100   results.  It also means that modified runtime behavior, such as
   100   results.  It also means that modified runtime behavior, such as
   101   timeout, is very hard to achieve for general tactics.}
   101   timeout, is very hard to achieve for general tactics.}
   102 
   102 
   103   An \emph{empty result sequence} means that the tactic has failed: in
   103   An \<^emph>\<open>empty result sequence\<close> means that the tactic has failed: in
   104   a compound tactic expression other tactics might be tried instead,
   104   a compound tactic expression other tactics might be tried instead,
   105   or the whole refinement step might fail outright, producing a
   105   or the whole refinement step might fail outright, producing a
   106   toplevel error message in the end.  When implementing tactics from
   106   toplevel error message in the end.  When implementing tactics from
   107   scratch, one should take care to observe the basic protocol of
   107   scratch, one should take care to observe the basic protocol of
   108   mapping regular error conditions to an empty result; only serious
   108   mapping regular error conditions to an empty result; only serious
   109   faults should emerge as exceptions.
   109   faults should emerge as exceptions.
   110 
   110 
   111   By enumerating \emph{multiple results}, a tactic can easily express
   111   By enumerating \<^emph>\<open>multiple results\<close>, a tactic can easily express
   112   the potential outcome of an internal search process.  There are also
   112   the potential outcome of an internal search process.  There are also
   113   combinators for building proof tools that involve search
   113   combinators for building proof tools that involve search
   114   systematically, see also \secref{sec:tacticals}.
   114   systematically, see also \secref{sec:tacticals}.
   115 
   115 
   116   \<^medskip>
   116   \<^medskip>
   118   list of subgoals that imply the main goal (conclusion).  Tactics may
   118   list of subgoals that imply the main goal (conclusion).  Tactics may
   119   operate on all subgoals or on a particularly specified subgoal, but
   119   operate on all subgoals or on a particularly specified subgoal, but
   120   must not change the main conclusion (apart from instantiating
   120   must not change the main conclusion (apart from instantiating
   121   schematic goal variables).
   121   schematic goal variables).
   122 
   122 
   123   Tactics with explicit \emph{subgoal addressing} are of the form
   123   Tactics with explicit \<^emph>\<open>subgoal addressing\<close> are of the form
   124   @{text "int \<rightarrow> tactic"} and may be applied to a particular subgoal
   124   @{text "int \<rightarrow> tactic"} and may be applied to a particular subgoal
   125   (counting from 1).  If the subgoal number is out of range, the
   125   (counting from 1).  If the subgoal number is out of range, the
   126   tactic should fail with an empty result sequence, but must not raise
   126   tactic should fail with an empty result sequence, but must not raise
   127   an exception!
   127   an exception!
   128 
   128 
   227 \<close>
   227 \<close>
   228 
   228 
   229 
   229 
   230 subsection \<open>Resolution and assumption tactics \label{sec:resolve-assume-tac}\<close>
   230 subsection \<open>Resolution and assumption tactics \label{sec:resolve-assume-tac}\<close>
   231 
   231 
   232 text \<open>\emph{Resolution} is the most basic mechanism for refining a
   232 text \<open>\<^emph>\<open>Resolution\<close> is the most basic mechanism for refining a
   233   subgoal using a theorem as object-level rule.
   233   subgoal using a theorem as object-level rule.
   234   \emph{Elim-resolution} is particularly suited for elimination rules:
   234   \<^emph>\<open>Elim-resolution\<close> is particularly suited for elimination rules:
   235   it resolves with a rule, proves its first premise by assumption, and
   235   it resolves with a rule, proves its first premise by assumption, and
   236   finally deletes that assumption from any new subgoals.
   236   finally deletes that assumption from any new subgoals.
   237   \emph{Destruct-resolution} is like elim-resolution, but the given
   237   \<^emph>\<open>Destruct-resolution\<close> is like elim-resolution, but the given
   238   destruction rules are first turned into canonical elimination
   238   destruction rules are first turned into canonical elimination
   239   format.  \emph{Forward-resolution} is like destruct-resolution, but
   239   format.  \<^emph>\<open>Forward-resolution\<close> is like destruct-resolution, but
   240   without deleting the selected assumption.  The @{text "r/e/d/f"}
   240   without deleting the selected assumption.  The @{text "r/e/d/f"}
   241   naming convention is maintained for several different kinds of
   241   naming convention is maintained for several different kinds of
   242   resolution rules and tactics.
   242   resolution rules and tactics.
   243 
   243 
   244   Assumption tactics close a subgoal by unifying some of its premises
   244   Assumption tactics close a subgoal by unifying some of its premises
   518 \<close>
   518 \<close>
   519 
   519 
   520 
   520 
   521 section \<open>Tacticals \label{sec:tacticals}\<close>
   521 section \<open>Tacticals \label{sec:tacticals}\<close>
   522 
   522 
   523 text \<open>A \emph{tactical} is a functional combinator for building up
   523 text \<open>A \<^emph>\<open>tactical\<close> is a functional combinator for building up
   524   complex tactics from simpler ones.  Common tacticals perform
   524   complex tactics from simpler ones.  Common tacticals perform
   525   sequential composition, disjunctive choice, iteration, or goal
   525   sequential composition, disjunctive choice, iteration, or goal
   526   addressing.  Various search strategies may be expressed via
   526   addressing.  Various search strategies may be expressed via
   527   tacticals.
   527   tacticals.
   528 \<close>
   528 \<close>
   570   choice: if @{text "tac\<^sub>1"} succeeds then @{text "tac\<^sub>2"} is excluded
   570   choice: if @{text "tac\<^sub>1"} succeeds then @{text "tac\<^sub>2"} is excluded
   571   from the result.
   571   from the result.
   572 
   572 
   573   \<^descr> @{text "tac\<^sub>1"}~@{ML_op APPEND}~@{text "tac\<^sub>2"} concatenates the
   573   \<^descr> @{text "tac\<^sub>1"}~@{ML_op APPEND}~@{text "tac\<^sub>2"} concatenates the
   574   possible results of @{text "tac\<^sub>1"} and @{text "tac\<^sub>2"}.  Unlike
   574   possible results of @{text "tac\<^sub>1"} and @{text "tac\<^sub>2"}.  Unlike
   575   @{ML_op "ORELSE"} there is \emph{no commitment} to either tactic, so
   575   @{ML_op "ORELSE"} there is \<^emph>\<open>no commitment\<close> to either tactic, so
   576   @{ML_op "APPEND"} helps to avoid incompleteness during search, at
   576   @{ML_op "APPEND"} helps to avoid incompleteness during search, at
   577   the cost of potential inefficiencies.
   577   the cost of potential inefficiencies.
   578 
   578 
   579   \<^descr> @{ML EVERY}~@{text "[tac\<^sub>1, \<dots>, tac\<^sub>n]"} abbreviates @{text
   579   \<^descr> @{ML EVERY}~@{text "[tac\<^sub>1, \<dots>, tac\<^sub>n]"} abbreviates @{text
   580   "tac\<^sub>1"}~@{ML_op THEN}~@{text "\<dots>"}~@{ML_op THEN}~@{text "tac\<^sub>n"}.
   580   "tac\<^sub>1"}~@{ML_op THEN}~@{text "\<dots>"}~@{ML_op THEN}~@{text "tac\<^sub>n"}.
   686 
   686 
   687 text \<open>Tactics with explicit subgoal addressing
   687 text \<open>Tactics with explicit subgoal addressing
   688   @{ML_type "int -> tactic"} can be used together with tacticals that
   688   @{ML_type "int -> tactic"} can be used together with tacticals that
   689   act like ``subgoal quantifiers'': guided by success of the body
   689   act like ``subgoal quantifiers'': guided by success of the body
   690   tactic a certain range of subgoals is covered.  Thus the body tactic
   690   tactic a certain range of subgoals is covered.  Thus the body tactic
   691   is applied to \emph{all} subgoals, \emph{some} subgoal etc.
   691   is applied to \<^emph>\<open>all\<close> subgoals, \<^emph>\<open>some\<close> subgoal etc.
   692 
   692 
   693   Suppose that the goal state has @{text "n \<ge> 0"} subgoals.  Many of
   693   Suppose that the goal state has @{text "n \<ge> 0"} subgoals.  Many of
   694   these tacticals address subgoal ranges counting downwards from
   694   these tacticals address subgoal ranges counting downwards from
   695   @{text "n"} towards @{text "1"}.  This has the fortunate effect that
   695   @{text "n"} towards @{text "1"}.  This has the fortunate effect that
   696   newly emerging subgoals are concatenated in the result, without
   696   newly emerging subgoals are concatenated in the result, without