doc-src/IsarImplementation/Thy/document/Tactic.tex
changeset 40406 313a24b66a8d
parent 39885 6a3f7941c3a0
child 40802 3cd23f676c5b
equal deleted inserted replaced
40405:42671298f037 40406:313a24b66a8d
    36 }
    36 }
    37 \isamarkuptrue%
    37 \isamarkuptrue%
    38 %
    38 %
    39 \begin{isamarkuptext}%
    39 \begin{isamarkuptext}%
    40 Isabelle/Pure represents a goal as a theorem stating that the
    40 Isabelle/Pure represents a goal as a theorem stating that the
    41   subgoals imply the main goal: \isa{A\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymLongrightarrow}\ A\isactrlsub n\ {\isasymLongrightarrow}\ C}.  The outermost goal structure is that of a Horn Clause: i.e.\
    41   subgoals imply the main goal: \isa{A\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ A\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ C}.  The outermost goal structure is that of a Horn Clause: i.e.\
    42   an iterated implication without any quantifiers\footnote{Recall that
    42   an iterated implication without any quantifiers\footnote{Recall that
    43   outermost \isa{{\isasymAnd}x{\isachardot}\ {\isasymphi}{\isacharbrackleft}x{\isacharbrackright}} is always represented via schematic
    43   outermost \isa{{\isaliteral{5C3C416E643E}{\isasymAnd}}x{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5C3C7068693E}{\isasymphi}}{\isaliteral{5B}{\isacharbrackleft}}x{\isaliteral{5D}{\isacharbrackright}}} is always represented via schematic
    44   variables in the body: \isa{{\isasymphi}{\isacharbrackleft}{\isacharquery}x{\isacharbrackright}}.  These variables may get
    44   variables in the body: \isa{{\isaliteral{5C3C7068693E}{\isasymphi}}{\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{3F}{\isacharquery}}x{\isaliteral{5D}{\isacharbrackright}}}.  These variables may get
    45   instantiated during the course of reasoning.}.  For \isa{n\ {\isacharequal}\ {\isadigit{0}}}
    45   instantiated during the course of reasoning.}.  For \isa{n\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{0}}}
    46   a goal is called ``solved''.
    46   a goal is called ``solved''.
    47 
    47 
    48   The structure of each subgoal \isa{A\isactrlsub i} is that of a
    48   The structure of each subgoal \isa{A\isaliteral{5C3C5E7375623E}{}\isactrlsub i} is that of a
    49   general Hereditary Harrop Formula \isa{{\isasymAnd}x\isactrlsub {\isadigit{1}}\ {\isasymdots}\ {\isasymAnd}x\isactrlsub k{\isachardot}\ H\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymLongrightarrow}\ H\isactrlsub m\ {\isasymLongrightarrow}\ B}.  Here \isa{x\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlsub k} are goal parameters, i.e.\
    49   general Hereditary Harrop Formula \isa{{\isaliteral{5C3C416E643E}{\isasymAnd}}x\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C416E643E}{\isasymAnd}}x\isaliteral{5C3C5E7375623E}{}\isactrlsub k{\isaliteral{2E}{\isachardot}}\ H\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ H\isaliteral{5C3C5E7375623E}{}\isactrlsub m\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ B}.  Here \isa{x\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ x\isaliteral{5C3C5E7375623E}{}\isactrlsub k} are goal parameters, i.e.\
    50   arbitrary-but-fixed entities of certain types, and \isa{H\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ H\isactrlsub m} are goal hypotheses, i.e.\ facts that may
    50   arbitrary-but-fixed entities of certain types, and \isa{H\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ H\isaliteral{5C3C5E7375623E}{}\isactrlsub m} are goal hypotheses, i.e.\ facts that may
    51   be assumed locally.  Together, this forms the goal context of the
    51   be assumed locally.  Together, this forms the goal context of the
    52   conclusion \isa{B} to be established.  The goal hypotheses may be
    52   conclusion \isa{B} to be established.  The goal hypotheses may be
    53   again arbitrary Hereditary Harrop Formulas, although the level of
    53   again arbitrary Hereditary Harrop Formulas, although the level of
    54   nesting rarely exceeds 1--2 in practice.
    54   nesting rarely exceeds 1--2 in practice.
    55 
    55 
    56   The main conclusion \isa{C} is internally marked as a protected
    56   The main conclusion \isa{C} is internally marked as a protected
    57   proposition, which is represented explicitly by the notation \isa{{\isacharhash}C} here.  This ensures that the decomposition into subgoals and
    57   proposition, which is represented explicitly by the notation \isa{{\isaliteral{23}{\isacharhash}}C} here.  This ensures that the decomposition into subgoals and
    58   main conclusion is well-defined for arbitrarily structured claims.
    58   main conclusion is well-defined for arbitrarily structured claims.
    59 
    59 
    60   \medskip Basic goal management is performed via the following
    60   \medskip Basic goal management is performed via the following
    61   Isabelle/Pure rules:
    61   Isabelle/Pure rules:
    62 
    62 
    63   \[
    63   \[
    64   \infer[\isa{{\isacharparenleft}init{\isacharparenright}}]{\isa{C\ {\isasymLongrightarrow}\ {\isacharhash}C}}{} \qquad
    64   \infer[\isa{{\isaliteral{28}{\isacharparenleft}}init{\isaliteral{29}{\isacharparenright}}}]{\isa{C\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{23}{\isacharhash}}C}}{} \qquad
    65   \infer[\isa{{\isacharparenleft}finish{\isacharparenright}}]{\isa{C}}{\isa{{\isacharhash}C}}
    65   \infer[\isa{{\isaliteral{28}{\isacharparenleft}}finish{\isaliteral{29}{\isacharparenright}}}]{\isa{C}}{\isa{{\isaliteral{23}{\isacharhash}}C}}
    66   \]
    66   \]
    67 
    67 
    68   \medskip The following low-level variants admit general reasoning
    68   \medskip The following low-level variants admit general reasoning
    69   with protected propositions:
    69   with protected propositions:
    70 
    70 
    71   \[
    71   \[
    72   \infer[\isa{{\isacharparenleft}protect{\isacharparenright}}]{\isa{{\isacharhash}C}}{\isa{C}} \qquad
    72   \infer[\isa{{\isaliteral{28}{\isacharparenleft}}protect{\isaliteral{29}{\isacharparenright}}}]{\isa{{\isaliteral{23}{\isacharhash}}C}}{\isa{C}} \qquad
    73   \infer[\isa{{\isacharparenleft}conclude{\isacharparenright}}]{\isa{A\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymLongrightarrow}\ A\isactrlsub n\ {\isasymLongrightarrow}\ C}}{\isa{A\isactrlsub {\isadigit{1}}\ {\isasymLongrightarrow}\ {\isasymdots}\ {\isasymLongrightarrow}\ A\isactrlsub n\ {\isasymLongrightarrow}\ {\isacharhash}C}}
    73   \infer[\isa{{\isaliteral{28}{\isacharparenleft}}conclude{\isaliteral{29}{\isacharparenright}}}]{\isa{A\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ A\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ C}}{\isa{A\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ A\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ {\isaliteral{23}{\isacharhash}}C}}
    74   \]%
    74   \]%
    75 \end{isamarkuptext}%
    75 \end{isamarkuptext}%
    76 \isamarkuptrue%
    76 \isamarkuptrue%
    77 %
    77 %
    78 \isadelimmlref
    78 \isadelimmlref
   119 \isamarkupsection{Tactics\label{sec:tactics}%
   119 \isamarkupsection{Tactics\label{sec:tactics}%
   120 }
   120 }
   121 \isamarkuptrue%
   121 \isamarkuptrue%
   122 %
   122 %
   123 \begin{isamarkuptext}%
   123 \begin{isamarkuptext}%
   124 A \isa{tactic} is a function \isa{goal\ {\isasymrightarrow}\ goal\isactrlsup {\isacharasterisk}\isactrlsup {\isacharasterisk}} that
   124 A \isa{tactic} is a function \isa{goal\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ goal\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}\isaliteral{5C3C5E7375703E}{}\isactrlsup {\isaliteral{2A}{\isacharasterisk}}} that
   125   maps a given goal state (represented as a theorem, cf.\
   125   maps a given goal state (represented as a theorem, cf.\
   126   \secref{sec:tactical-goals}) to a lazy sequence of potential
   126   \secref{sec:tactical-goals}) to a lazy sequence of potential
   127   successor states.  The underlying sequence implementation is lazy
   127   successor states.  The underlying sequence implementation is lazy
   128   both in head and tail, and is purely functional in \emph{not}
   128   both in head and tail, and is purely functional in \emph{not}
   129   supporting memoing.\footnote{The lack of memoing and the strict
   129   supporting memoing.\footnote{The lack of memoing and the strict
   150   operate on all subgoals or on a particularly specified subgoal, but
   150   operate on all subgoals or on a particularly specified subgoal, but
   151   must not change the main conclusion (apart from instantiating
   151   must not change the main conclusion (apart from instantiating
   152   schematic goal variables).
   152   schematic goal variables).
   153 
   153 
   154   Tactics with explicit \emph{subgoal addressing} are of the form
   154   Tactics with explicit \emph{subgoal addressing} are of the form
   155   \isa{int\ {\isasymrightarrow}\ tactic} and may be applied to a particular subgoal
   155   \isa{int\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ tactic} and may be applied to a particular subgoal
   156   (counting from 1).  If the subgoal number is out of range, the
   156   (counting from 1).  If the subgoal number is out of range, the
   157   tactic should fail with an empty result sequence, but must not raise
   157   tactic should fail with an empty result sequence, but must not raise
   158   an exception!
   158   an exception!
   159 
   159 
   160   Operating on a particular subgoal means to replace it by an interval
   160   Operating on a particular subgoal means to replace it by an interval
   220 
   220 
   221   \begin{description}
   221   \begin{description}
   222 
   222 
   223   \item Type \verb|tactic| represents tactics.  The
   223   \item Type \verb|tactic| represents tactics.  The
   224   well-formedness conditions described above need to be observed.  See
   224   well-formedness conditions described above need to be observed.  See
   225   also \hyperlink{file.~~/src/Pure/General/seq.ML}{\mbox{\isa{\isatt{{\isachartilde}{\isachartilde}{\isacharslash}src{\isacharslash}Pure{\isacharslash}General{\isacharslash}seq{\isachardot}ML}}}} for the underlying
   225   also \hyperlink{file.~~/src/Pure/General/seq.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}General{\isaliteral{2F}{\isacharslash}}seq{\isaliteral{2E}{\isachardot}}ML}}}} for the underlying
   226   implementation of lazy sequences.
   226   implementation of lazy sequences.
   227 
   227 
   228   \item Type \verb|int -> tactic| represents tactics with
   228   \item Type \verb|int -> tactic| represents tactics with
   229   explicit subgoal addressing, with well-formedness conditions as
   229   explicit subgoal addressing, with well-formedness conditions as
   230   described above.
   230   described above.
   242   \item \verb|PRIMITIVE|~\isa{rule} turns a primitive inference rule
   242   \item \verb|PRIMITIVE|~\isa{rule} turns a primitive inference rule
   243   into a tactic with unique result.  Exception \verb|THM| is considered
   243   into a tactic with unique result.  Exception \verb|THM| is considered
   244   a regular tactic failure and produces an empty result; other
   244   a regular tactic failure and produces an empty result; other
   245   exceptions are passed through.
   245   exceptions are passed through.
   246 
   246 
   247   \item \verb|SUBGOAL|~\isa{{\isacharparenleft}fn\ {\isacharparenleft}subgoal{\isacharcomma}\ i{\isacharparenright}\ {\isacharequal}{\isachargreater}\ tactic{\isacharparenright}} is the
   247   \item \verb|SUBGOAL|~\isa{{\isaliteral{28}{\isacharparenleft}}fn\ {\isaliteral{28}{\isacharparenleft}}subgoal{\isaliteral{2C}{\isacharcomma}}\ i{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\ tactic{\isaliteral{29}{\isacharparenright}}} is the
   248   most basic form to produce a tactic with subgoal addressing.  The
   248   most basic form to produce a tactic with subgoal addressing.  The
   249   given abstraction over the subgoal term and subgoal number allows to
   249   given abstraction over the subgoal term and subgoal number allows to
   250   peek at the relevant information of the full goal state.  The
   250   peek at the relevant information of the full goal state.  The
   251   subgoal range is checked as required above.
   251   subgoal range is checked as required above.
   252 
   252 
   277   it resolves with a rule, proves its first premise by assumption, and
   277   it resolves with a rule, proves its first premise by assumption, and
   278   finally deletes that assumption from any new subgoals.
   278   finally deletes that assumption from any new subgoals.
   279   \emph{Destruct-resolution} is like elim-resolution, but the given
   279   \emph{Destruct-resolution} is like elim-resolution, but the given
   280   destruction rules are first turned into canonical elimination
   280   destruction rules are first turned into canonical elimination
   281   format.  \emph{Forward-resolution} is like destruct-resolution, but
   281   format.  \emph{Forward-resolution} is like destruct-resolution, but
   282   without deleting the selected assumption.  The \isa{r{\isacharslash}e{\isacharslash}d{\isacharslash}f}
   282   without deleting the selected assumption.  The \isa{r{\isaliteral{2F}{\isacharslash}}e{\isaliteral{2F}{\isacharslash}}d{\isaliteral{2F}{\isacharslash}}f}
   283   naming convention is maintained for several different kinds of
   283   naming convention is maintained for several different kinds of
   284   resolution rules and tactics.
   284   resolution rules and tactics.
   285 
   285 
   286   Assumption tactics close a subgoal by unifying some of its premises
   286   Assumption tactics close a subgoal by unifying some of its premises
   287   against its conclusion.
   287   against its conclusion.
   351 
   351 
   352   \item \verb|assume_tac|~\isa{i} attempts to solve subgoal \isa{i}
   352   \item \verb|assume_tac|~\isa{i} attempts to solve subgoal \isa{i}
   353   by assumption (modulo higher-order unification).
   353   by assumption (modulo higher-order unification).
   354 
   354 
   355   \item \verb|eq_assume_tac| is similar to \verb|assume_tac|, but checks
   355   \item \verb|eq_assume_tac| is similar to \verb|assume_tac|, but checks
   356   only for immediate \isa{{\isasymalpha}}-convertibility instead of using
   356   only for immediate \isa{{\isaliteral{5C3C616C7068613E}{\isasymalpha}}}-convertibility instead of using
   357   unification.  It succeeds (with a unique next state) if one of the
   357   unification.  It succeeds (with a unique next state) if one of the
   358   assumptions is equal to the subgoal's conclusion.  Since it does not
   358   assumptions is equal to the subgoal's conclusion.  Since it does not
   359   instantiate variables, it cannot make other subgoals unprovable.
   359   instantiate variables, it cannot make other subgoals unprovable.
   360 
   360 
   361   \item \verb|match_tac|, \verb|ematch_tac|, and \verb|dmatch_tac| are
   361   \item \verb|match_tac|, \verb|ematch_tac|, and \verb|dmatch_tac| are
   388   situations despite its daunting theoretical properties.
   388   situations despite its daunting theoretical properties.
   389   Nonetheless, there are important problem classes where unguided
   389   Nonetheless, there are important problem classes where unguided
   390   higher-order unification is not so useful.  This typically involves
   390   higher-order unification is not so useful.  This typically involves
   391   rules like universal elimination, existential introduction, or
   391   rules like universal elimination, existential introduction, or
   392   equational substitution.  Here the unification problem involves
   392   equational substitution.  Here the unification problem involves
   393   fully flexible \isa{{\isacharquery}P\ {\isacharquery}x} schemes, which are hard to manage
   393   fully flexible \isa{{\isaliteral{3F}{\isacharquery}}P\ {\isaliteral{3F}{\isacharquery}}x} schemes, which are hard to manage
   394   without further hints.
   394   without further hints.
   395 
   395 
   396   By providing a (small) rigid term for \isa{{\isacharquery}x} explicitly, the
   396   By providing a (small) rigid term for \isa{{\isaliteral{3F}{\isacharquery}}x} explicitly, the
   397   remaining unification problem is to assign a (large) term to \isa{{\isacharquery}P}, according to the shape of the given subgoal.  This is
   397   remaining unification problem is to assign a (large) term to \isa{{\isaliteral{3F}{\isacharquery}}P}, according to the shape of the given subgoal.  This is
   398   sufficiently well-behaved in most practical situations.
   398   sufficiently well-behaved in most practical situations.
   399 
   399 
   400   \medskip Isabelle provides separate versions of the standard \isa{r{\isacharslash}e{\isacharslash}d{\isacharslash}f} resolution tactics that allow to provide explicit
   400   \medskip Isabelle provides separate versions of the standard \isa{r{\isaliteral{2F}{\isacharslash}}e{\isaliteral{2F}{\isacharslash}}d{\isaliteral{2F}{\isacharslash}}f} resolution tactics that allow to provide explicit
   401   instantiations of unknowns of the given rule, wrt.\ terms that refer
   401   instantiations of unknowns of the given rule, wrt.\ terms that refer
   402   to the implicit context of the selected subgoal.
   402   to the implicit context of the selected subgoal.
   403 
   403 
   404   An instantiation consists of a list of pairs of the form \isa{{\isacharparenleft}{\isacharquery}x{\isacharcomma}\ t{\isacharparenright}}, where \isa{{\isacharquery}x} is a schematic variable occurring in
   404   An instantiation consists of a list of pairs of the form \isa{{\isaliteral{28}{\isacharparenleft}}{\isaliteral{3F}{\isacharquery}}x{\isaliteral{2C}{\isacharcomma}}\ t{\isaliteral{29}{\isacharparenright}}}, where \isa{{\isaliteral{3F}{\isacharquery}}x} is a schematic variable occurring in
   405   the given rule, and \isa{t} is a term from the current proof
   405   the given rule, and \isa{t} is a term from the current proof
   406   context, augmented by the local goal parameters of the selected
   406   context, augmented by the local goal parameters of the selected
   407   subgoal; cf.\ the \isa{focus} operation described in
   407   subgoal; cf.\ the \isa{focus} operation described in
   408   \secref{sec:variables}.
   408   \secref{sec:variables}.
   409 
   409 
   411   because its exact form is somewhat accidental, and the choice of
   411   because its exact form is somewhat accidental, and the choice of
   412   bound variable names depends on the presence of other local and
   412   bound variable names depends on the presence of other local and
   413   global names.  Explicit renaming of subgoal parameters prior to
   413   global names.  Explicit renaming of subgoal parameters prior to
   414   explicit instantiation might help to achieve a bit more robustness.
   414   explicit instantiation might help to achieve a bit more robustness.
   415 
   415 
   416   Type instantiations may be given as well, via pairs like \isa{{\isacharparenleft}{\isacharquery}{\isacharprime}a{\isacharcomma}\ {\isasymtau}{\isacharparenright}}.  Type instantiations are distinguished from term
   416   Type instantiations may be given as well, via pairs like \isa{{\isaliteral{28}{\isacharparenleft}}{\isaliteral{3F}{\isacharquery}}{\isaliteral{27}{\isacharprime}}a{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}{\isaliteral{29}{\isacharparenright}}}.  Type instantiations are distinguished from term
   417   instantiations by the syntactic form of the schematic variable.
   417   instantiations by the syntactic form of the schematic variable.
   418   Types are instantiated before terms are.  Since term instantiation
   418   Types are instantiated before terms are.  Since term instantiation
   419   already performs simple type-inference, so explicit type
   419   already performs simple type-inference, so explicit type
   420   instantiations are seldom necessary.%
   420   instantiations are seldom necessary.%
   421 \end{isamarkuptext}%
   421 \end{isamarkuptext}%