doc-src/IsarImplementation/Thy/tactic.thy
changeset 20451 27ea2ba48fa3
parent 20316 99b6e2900c0f
child 20452 6d8b29c7a960
equal deleted inserted replaced
20450:725a91601ed1 20451:27ea2ba48fa3
     1 
     1 
     2 (* $Id$ *)
     2 (* $Id$ *)
     3 
     3 
     4 theory tactic imports base begin
     4 theory tactic imports base begin
     5 
     5 
     6 chapter {* Tactical theorem proving *}
     6 chapter {* Goal-directed reasoning *}
     7 
     7 
     8 text {* The basic idea of tactical theorem proving is to refine the
     8 text {*
     9 initial claim in a backwards fashion, until a solved form is reached.
     9   The basic idea of tactical theorem proving is to refine the initial
    10 An intermediate goal consists of several subgoals that need to be
    10   claim in a backwards fashion, until a solved form is reached.  An
    11 solved in order to achieve the main statement; zero subgoals means
    11   intermediate goal consists of several subgoals that need to be
    12 that the proof may be finished.  Goal refinement operations are called
    12   solved in order to achieve the main statement; zero subgoals means
    13 tactics; combinators for composing tactics are called tacticals.  *}
    13   that the proof may be finished.  A @{text "tactic"} is a refinement
       
    14   operation that maps a goal to a lazy sequence of potential
       
    15   successors.  A @{text "tactical"} is a combinator for composing
       
    16   tactics.
       
    17 *}
    14 
    18 
    15 
    19 
    16 section {* Goals \label{sec:tactical-goals} *}
    20 section {* Goals \label{sec:tactical-goals} *}
    17 
    21 
    18 text {* Isabelle/Pure represents a goal\glossary{Tactical goal}{A
    22 text {*
    19 theorem of \seeglossary{Horn Clause} form stating that a number of
    23   Isabelle/Pure represents a goal\glossary{Tactical goal}{A theorem of
    20 subgoals imply the main conclusion, which is marked as a protected
    24   \seeglossary{Horn Clause} form stating that a number of subgoals
    21 proposition.} as a theorem stating that the subgoals imply the main
    25   imply the main conclusion, which is marked as a protected
    22 goal: @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}.  The outermost goal
    26   proposition.} as a theorem stating that the subgoals imply the main
    23 structure is that of a Horn Clause\glossary{Horn Clause}{An iterated
    27   goal: @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}.  The outermost goal
    24 implication @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}, without any
    28   structure is that of a Horn Clause\glossary{Horn Clause}{An iterated
    25 outermost quantifiers.  Strictly speaking, propositions @{text
    29   implication @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}, without any
    26 "A\<^sub>i"} need to be atomic in Horn Clauses, but Isabelle admits
    30   outermost quantifiers.  Strictly speaking, propositions @{text
    27 arbitrary substructure here (nested @{text "\<Longrightarrow>"} and @{text "\<And>"}
    31   "A\<^sub>i"} need to be atomic in Horn Clauses, but Isabelle admits
    28 connectives).}: an iterated implication without any
    32   arbitrary substructure here (nested @{text "\<Longrightarrow>"} and @{text "\<And>"}
    29 quantifiers\footnote{Recall that outermost @{text "\<And>x. \<phi>[x]"} is
    33   connectives).}: i.e.\ an iterated implication without any
    30 always represented via schematic variables in the body: @{text
    34   quantifiers\footnote{Recall that outermost @{text "\<And>x. \<phi>[x]"} is
    31 "\<phi>[?x]"}.  These may get instantiated during the course of
    35   always represented via schematic variables in the body: @{text
    32 reasoning.}.  For @{text "n = 0"} a goal is solved.
    36   "\<phi>[?x]"}.  These variables may get instantiated during the course of
       
    37   reasoning.}.  For @{text "n = 0"} a goal is called ``solved''.
    33 
    38 
    34 The structure of each subgoal @{text "A\<^sub>i"} is that of a general
    39   The structure of each subgoal @{text "A\<^sub>i"} is that of a
    35 Heriditary Harrop Formula @{text "\<And>x\<^sub>1 \<dots> \<And>x\<^sub>k. H\<^sub>1 \<Longrightarrow>
    40   general Hereditary Harrop Formula @{text "\<And>x\<^sub>1 \<dots>
    36 \<dots> \<Longrightarrow> H\<^sub>m \<Longrightarrow> B"} according to the normal form where any local
    41   \<And>x\<^sub>k. H\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> H\<^sub>m \<Longrightarrow> B"} according to the normal
    37 @{text \<And>} is pulled before @{text \<Longrightarrow>}.  Here @{text "x\<^sub>1, \<dots>,
    42   form where any local @{text \<And>} is pulled before @{text \<Longrightarrow>}.  Here
    38 x\<^sub>k"} are goal parameters, i.e.\ arbitrary-but-fixed entities of
    43   @{text "x\<^sub>1, \<dots>, x\<^sub>k"} are goal parameters, i.e.\
    39 certain types, and @{text "H\<^sub>1, \<dots>, H\<^sub>m"} are goal
    44   arbitrary-but-fixed entities of certain types, and @{text
    40 hypotheses, i.e.\ facts that may be assumed locally.  Together, this
    45   "H\<^sub>1, \<dots>, H\<^sub>m"} are goal hypotheses, i.e.\ facts that may
    41 forms the goal context of the conclusion @{text B} to be established.
    46   be assumed locally.  Together, this forms the goal context of the
    42 The goal hypotheses may be again arbitrary Harrop Formulas, although
    47   conclusion @{text B} to be established.  The goal hypotheses may be
    43 the level of nesting rarely exceeds 1--2 in practice.
    48   again Hereditary Harrop Formulas, although the level of nesting
       
    49   rarely exceeds 1--2 in practice.
    44 
    50 
    45 The main conclusion @{text C} is internally marked as a protected
    51   The main conclusion @{text C} is internally marked as a protected
    46 proposition\glossary{Protected proposition}{An arbitrarily structured
    52   proposition\glossary{Protected proposition}{An arbitrarily
    47 proposition @{text "C"} which is forced to appear as atomic by
    53   structured proposition @{text "C"} which is forced to appear as
    48 wrapping it into a propositional identity operator; notation @{text
    54   atomic by wrapping it into a propositional identity operator;
    49 "#C"}.  Protecting a proposition prevents basic inferences from
    55   notation @{text "#C"}.  Protecting a proposition prevents basic
    50 entering into that structure for the time being.}, which is
    56   inferences from entering into that structure for the time being.},
    51 occasionally represented explicitly by the notation @{text "#C"}.
    57   which is occasionally represented explicitly by the notation @{text
    52 This ensures that the decomposition into subgoals and main conclusion
    58   "#C"}.  This ensures that the decomposition into subgoals and main
    53 is well-defined for arbitrarily structured claims.
    59   conclusion is well-defined for arbitrarily structured claims.
    54 
    60 
    55 \medskip Basic goal management is performed via the following
    61   \medskip Basic goal management is performed via the following
    56 Isabelle/Pure rules:
    62   Isabelle/Pure rules:
    57 
    63 
    58   \[
    64   \[
    59   \infer[@{text "(init)"}]{@{text "C \<Longrightarrow> #C"}}{} \qquad
    65   \infer[@{text "(init)"}]{@{text "C \<Longrightarrow> #C"}}{} \qquad
    60   \infer[@{text "(finish)"}]{@{text "#C"}}{@{text "C"}}
    66   \infer[@{text "(finish)"}]{@{text "#C"}}{@{text "C"}}
    61   \]
    67   \]
    77   @{index_ML Goal.conclude: "thm -> thm"} \\
    83   @{index_ML Goal.conclude: "thm -> thm"} \\
    78   \end{mldecls}
    84   \end{mldecls}
    79 
    85 
    80   \begin{description}
    86   \begin{description}
    81 
    87 
    82   \item @{ML "Goal.init"}~@{text "\<phi>"} initializes a tactical goal with
    88   \item @{ML "Goal.init"}~@{text "\<phi>"} initializes a tactical goal from
    83   the type-checked proposition @{text \<phi>}.
    89   the type-checked proposition @{text \<phi>}.
    84 
    90 
    85   \item @{ML "Goal.finish"}~@{text "th"} checks whether theorem @{text
    91   \item @{ML "Goal.finish"}~@{text "th"} checks whether theorem @{text
    86   "th"} is a solved goal configuration (zero subgoals), and concludes
    92   "th"} is a solved goal configuration (no subgoals), and concludes
    87   the result by removing the goal protection.
    93   the result by removing the goal protection.
    88 
    94 
    89   \item @{ML "Goal.protect"}~@{text "th"} protects the whole statement
    95   \item @{ML "Goal.protect"}~@{text "th"} protects the full statement
    90   of theorem @{text "th"}.
    96   of theorem @{text "th"}.
    91 
    97 
    92   \item @{ML "Goal.conclude"}~@{text "th"} removes the goal protection
    98   \item @{ML "Goal.conclude"}~@{text "th"} removes the goal protection
    93   for any number of pending subgoals.
    99   for any number of pending subgoals.
    94 
   100 
   137   \secref{sec:tactical-goals}.  Further checks are required to ensure
   143   \secref{sec:tactical-goals}.  Further checks are required to ensure
   138   that the result is actually an instance of the original claim --
   144   that the result is actually an instance of the original claim --
   139   ill-behaved tactics could have destroyed that information.
   145   ill-behaved tactics could have destroyed that information.
   140 
   146 
   141   Several simultaneous claims may be handled within a single goal
   147   Several simultaneous claims may be handled within a single goal
   142   statement by using meta-level conjunction internally.\footnote{This
   148   statement by using meta-level conjunction internally.  The whole
   143   is merely syntax for certain derived statements within
   149   configuration may be considered within a context of
   144   Isabelle/Pure, there is no need to introduce a separate conjunction
   150   arbitrary-but-fixed parameters and hypotheses, which will be
   145   operator.}  The whole configuration may be considered within a
   151   available as local facts during the proof and discharged into
   146   context of arbitrary-but-fixed parameters and hypotheses, which will
       
   147   be available as local facts during the proof and discharged into
       
   148   implications in the result.
   152   implications in the result.
   149 
   153 
   150   All of these administrative tasks are packaged into a separate
   154   All of these administrative tasks are packaged into a separate
   151   operation, such that the user merely needs to provide the statement
   155   operation, such that the user merely needs to provide the statement
   152   and tactic to be applied.
   156   and tactic to be applied.