doc-src/IsarImplementation/Thy/Tactic.thy
author wenzelm
Mon, 18 Oct 2010 15:35:20 +0100
changeset 39864 f3b4fde34cd1
parent 39852 9c977f899ebf
child 40800 330eb65c9469
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29755
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 28785
diff changeset
     1
theory Tactic
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 28785
diff changeset
     2
imports Base
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 28785
diff changeset
     3
begin
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     4
20452
wenzelm
parents: 20451
diff changeset
     5
chapter {* Tactical reasoning *}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     6
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
     7
text {* Tactical reasoning works by refining an initial claim in a
20474
wenzelm
parents: 20472
diff changeset
     8
  backwards fashion, until a solved form is reached.  A @{text "goal"}
wenzelm
parents: 20472
diff changeset
     9
  consists of several subgoals that need to be solved in order to
wenzelm
parents: 20472
diff changeset
    10
  achieve the main statement; zero subgoals means that the proof may
wenzelm
parents: 20472
diff changeset
    11
  be finished.  A @{text "tactic"} is a refinement operation that maps
wenzelm
parents: 20472
diff changeset
    12
  a goal to a lazy sequence of potential successors.  A @{text
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
    13
  "tactical"} is a combinator for composing tactics.  *}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    14
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    15
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    16
section {* Goals \label{sec:tactical-goals} *}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    17
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20316
diff changeset
    18
text {*
29758
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    19
  Isabelle/Pure represents a goal as a theorem stating that the
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    20
  subgoals imply the main goal: @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow>
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    21
  C"}.  The outermost goal structure is that of a Horn Clause: i.e.\
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    22
  an iterated implication without any quantifiers\footnote{Recall that
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    23
  outermost @{text "\<And>x. \<phi>[x]"} is always represented via schematic
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    24
  variables in the body: @{text "\<phi>[?x]"}.  These variables may get
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    25
  instantiated during the course of reasoning.}.  For @{text "n = 0"}
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    26
  a goal is called ``solved''.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    27
29761
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    28
  The structure of each subgoal @{text "A\<^sub>i"} is that of a
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    29
  general Hereditary Harrop Formula @{text "\<And>x\<^sub>1 \<dots>
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    30
  \<And>x\<^sub>k. H\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> H\<^sub>m \<Longrightarrow> B"}.  Here @{text
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    31
  "x\<^sub>1, \<dots>, x\<^sub>k"} are goal parameters, i.e.\
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    32
  arbitrary-but-fixed entities of certain types, and @{text
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    33
  "H\<^sub>1, \<dots>, H\<^sub>m"} are goal hypotheses, i.e.\ facts that may
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    34
  be assumed locally.  Together, this forms the goal context of the
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    35
  conclusion @{text B} to be established.  The goal hypotheses may be
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    36
  again arbitrary Hereditary Harrop Formulas, although the level of
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
    37
  nesting rarely exceeds 1--2 in practice.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    38
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20316
diff changeset
    39
  The main conclusion @{text C} is internally marked as a protected
29758
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    40
  proposition, which is represented explicitly by the notation @{text
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
    41
  "#C"} here.  This ensures that the decomposition into subgoals and
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
    42
  main conclusion is well-defined for arbitrarily structured claims.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    43
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20316
diff changeset
    44
  \medskip Basic goal management is performed via the following
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20316
diff changeset
    45
  Isabelle/Pure rules:
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    46
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    47
  \[
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    48
  \infer[@{text "(init)"}]{@{text "C \<Longrightarrow> #C"}}{} \qquad
20547
wenzelm
parents: 20474
diff changeset
    49
  \infer[@{text "(finish)"}]{@{text "C"}}{@{text "#C"}}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    50
  \]
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    51
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    52
  \medskip The following low-level variants admit general reasoning
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    53
  with protected propositions:
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    54
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    55
  \[
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    56
  \infer[@{text "(protect)"}]{@{text "#C"}}{@{text "C"}} \qquad
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    57
  \infer[@{text "(conclude)"}]{@{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}}{@{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> #C"}}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    58
  \]
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    59
*}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    60
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    61
text %mlref {*
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    62
  \begin{mldecls}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    63
  @{index_ML Goal.init: "cterm -> thm"} \\
32201
3689b647356d updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents: 30272
diff changeset
    64
  @{index_ML Goal.finish: "Proof.context -> thm -> thm"} \\
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    65
  @{index_ML Goal.protect: "thm -> thm"} \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    66
  @{index_ML Goal.conclude: "thm -> thm"} \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    67
  \end{mldecls}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    68
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    69
  \begin{description}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    70
20474
wenzelm
parents: 20472
diff changeset
    71
  \item @{ML "Goal.init"}~@{text C} initializes a tactical goal from
wenzelm
parents: 20472
diff changeset
    72
  the well-formed proposition @{text C}.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    73
32201
3689b647356d updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents: 30272
diff changeset
    74
  \item @{ML "Goal.finish"}~@{text "ctxt thm"} checks whether theorem
20474
wenzelm
parents: 20472
diff changeset
    75
  @{text "thm"} is a solved goal (no subgoals), and concludes the
32201
3689b647356d updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents: 30272
diff changeset
    76
  result by removing the goal protection.  The context is only
3689b647356d updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents: 30272
diff changeset
    77
  required for printing error messages.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    78
20474
wenzelm
parents: 20472
diff changeset
    79
  \item @{ML "Goal.protect"}~@{text "thm"} protects the full statement
wenzelm
parents: 20472
diff changeset
    80
  of theorem @{text "thm"}.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    81
20474
wenzelm
parents: 20472
diff changeset
    82
  \item @{ML "Goal.conclude"}~@{text "thm"} removes the goal
wenzelm
parents: 20472
diff changeset
    83
  protection, even if there are pending subgoals.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    84
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    85
  \end{description}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    86
*}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    87
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    88
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 34930
diff changeset
    89
section {* Tactics\label{sec:tactics} *}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    90
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    91
text {* A @{text "tactic"} is a function @{text "goal \<rightarrow> goal\<^sup>*\<^sup>*"} that
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    92
  maps a given goal state (represented as a theorem, cf.\
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    93
  \secref{sec:tactical-goals}) to a lazy sequence of potential
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    94
  successor states.  The underlying sequence implementation is lazy
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    95
  both in head and tail, and is purely functional in \emph{not}
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    96
  supporting memoing.\footnote{The lack of memoing and the strict
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    97
  nature of SML requires some care when working with low-level
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
    98
  sequence operations, to avoid duplicate or premature evaluation of
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
    99
  results.  It also means that modified runtime behavior, such as
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   100
  timeout, is very hard to achieve for general tactics.}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   101
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   102
  An \emph{empty result sequence} means that the tactic has failed: in
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   103
  a compound tactic expression other tactics might be tried instead,
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   104
  or the whole refinement step might fail outright, producing a
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   105
  toplevel error message in the end.  When implementing tactics from
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   106
  scratch, one should take care to observe the basic protocol of
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   107
  mapping regular error conditions to an empty result; only serious
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   108
  faults should emerge as exceptions.
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   109
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   110
  By enumerating \emph{multiple results}, a tactic can easily express
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   111
  the potential outcome of an internal search process.  There are also
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   112
  combinators for building proof tools that involve search
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   113
  systematically, see also \secref{sec:tacticals}.
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   114
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   115
  \medskip As explained before, a goal state essentially consists of a
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   116
  list of subgoals that imply the main goal (conclusion).  Tactics may
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   117
  operate on all subgoals or on a particularly specified subgoal, but
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   118
  must not change the main conclusion (apart from instantiating
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   119
  schematic goal variables).
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   120
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   121
  Tactics with explicit \emph{subgoal addressing} are of the form
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   122
  @{text "int \<rightarrow> tactic"} and may be applied to a particular subgoal
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   123
  (counting from 1).  If the subgoal number is out of range, the
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   124
  tactic should fail with an empty result sequence, but must not raise
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   125
  an exception!
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   126
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   127
  Operating on a particular subgoal means to replace it by an interval
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   128
  of zero or more subgoals in the same place; other subgoals must not
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   129
  be affected, apart from instantiating schematic variables ranging
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   130
  over the whole goal state.
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   131
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   132
  A common pattern of composing tactics with subgoal addressing is to
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   133
  try the first one, and then the second one only if the subgoal has
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   134
  not been solved yet.  Special care is required here to avoid bumping
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   135
  into unrelated subgoals that happen to come after the original
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   136
  subgoal.  Assuming that there is only a single initial subgoal is a
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   137
  very common error when implementing tactics!
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   138
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   139
  Tactics with internal subgoal addressing should expose the subgoal
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   140
  index as @{text "int"} argument in full generality; a hardwired
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   141
  subgoal 1 is not acceptable.
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   142
  
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   143
  \medskip The main well-formedness conditions for proper tactics are
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   144
  summarized as follows.
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   145
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   146
  \begin{itemize}
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   147
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   148
  \item General tactic failure is indicated by an empty result, only
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   149
  serious faults may produce an exception.
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   150
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   151
  \item The main conclusion must not be changed, apart from
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   152
  instantiating schematic variables.
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   153
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   154
  \item A tactic operates either uniformly on all subgoals, or
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   155
  specifically on a selected subgoal (without bumping into unrelated
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   156
  subgoals).
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   157
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   158
  \item Range errors in subgoal addressing produce an empty result.
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   159
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   160
  \end{itemize}
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   161
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   162
  Some of these conditions are checked by higher-level goal
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   163
  infrastructure (\secref{sec:struct-goals}); others are not checked
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   164
  explicitly, and violating them merely results in ill-behaved tactics
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   165
  experienced by the user (e.g.\ tactics that insist in being
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   166
  applicable only to singleton goals, or prevent composition via
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   167
  standard tacticals).
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   168
*}
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   169
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   170
text %mlref {*
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   171
  \begin{mldecls}
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   172
  @{index_ML_type tactic: "thm -> thm Seq.seq"} \\
28783
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   173
  @{index_ML no_tac: tactic} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   174
  @{index_ML all_tac: tactic} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   175
  @{index_ML print_tac: "string -> tactic"} \\[1ex]
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   176
  @{index_ML PRIMITIVE: "(thm -> thm) -> tactic"} \\[1ex]
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   177
  @{index_ML SUBGOAL: "(term * int -> tactic) -> int -> tactic"} \\
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   178
  @{index_ML CSUBGOAL: "(cterm * int -> tactic) -> int -> tactic"} \\
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   179
  \end{mldecls}
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   180
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   181
  \begin{description}
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   182
39864
wenzelm
parents: 39852
diff changeset
   183
  \item Type @{ML_type tactic} represents tactics.  The
wenzelm
parents: 39852
diff changeset
   184
  well-formedness conditions described above need to be observed.  See
wenzelm
parents: 39852
diff changeset
   185
  also @{"file" "~~/src/Pure/General/seq.ML"} for the underlying
wenzelm
parents: 39852
diff changeset
   186
  implementation of lazy sequences.
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   187
39864
wenzelm
parents: 39852
diff changeset
   188
  \item Type @{ML_type "int -> tactic"} represents tactics with
wenzelm
parents: 39852
diff changeset
   189
  explicit subgoal addressing, with well-formedness conditions as
wenzelm
parents: 39852
diff changeset
   190
  described above.
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   191
28783
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   192
  \item @{ML no_tac} is a tactic that always fails, returning the
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   193
  empty sequence.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   194
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   195
  \item @{ML all_tac} is a tactic that always succeeds, returning a
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   196
  singleton sequence with unchanged goal state.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   197
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   198
  \item @{ML print_tac}~@{text "message"} is like @{ML all_tac}, but
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   199
  prints a message together with the goal state on the tracing
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   200
  channel.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   201
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   202
  \item @{ML PRIMITIVE}~@{text rule} turns a primitive inference rule
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   203
  into a tactic with unique result.  Exception @{ML THM} is considered
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   204
  a regular tactic failure and produces an empty result; other
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   205
  exceptions are passed through.
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   206
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   207
  \item @{ML SUBGOAL}~@{text "(fn (subgoal, i) => tactic)"} is the
28783
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   208
  most basic form to produce a tactic with subgoal addressing.  The
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   209
  given abstraction over the subgoal term and subgoal number allows to
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   210
  peek at the relevant information of the full goal state.  The
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   211
  subgoal range is checked as required above.
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   212
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   213
  \item @{ML CSUBGOAL} is similar to @{ML SUBGOAL}, but passes the
28783
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   214
  subgoal as @{ML_type cterm} instead of raw @{ML_type term}.  This
28782
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   215
  avoids expensive re-certification in situations where the subgoal is
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   216
  used directly for primitive inferences.
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   217
a2165c8ca58b basic ML reference for tactics;
wenzelm
parents: 28781
diff changeset
   218
  \end{description}
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   219
*}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   220
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   221
28785
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   222
subsection {* Resolution and assumption tactics \label{sec:resolve-assume-tac} *}
28783
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   223
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   224
text {* \emph{Resolution} is the most basic mechanism for refining a
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   225
  subgoal using a theorem as object-level rule.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   226
  \emph{Elim-resolution} is particularly suited for elimination rules:
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   227
  it resolves with a rule, proves its first premise by assumption, and
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   228
  finally deletes that assumption from any new subgoals.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   229
  \emph{Destruct-resolution} is like elim-resolution, but the given
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   230
  destruction rules are first turned into canonical elimination
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   231
  format.  \emph{Forward-resolution} is like destruct-resolution, but
28785
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   232
  without deleting the selected assumption.  The @{text "r/e/d/f"}
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   233
  naming convention is maintained for several different kinds of
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   234
  resolution rules and tactics.
28783
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   235
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   236
  Assumption tactics close a subgoal by unifying some of its premises
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   237
  against its conclusion.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   238
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   239
  \medskip All the tactics in this section operate on a subgoal
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   240
  designated by a positive integer.  Other subgoals might be affected
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   241
  indirectly, due to instantiation of schematic variables.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   242
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   243
  There are various sources of non-determinism, the tactic result
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   244
  sequence enumerates all possibilities of the following choices (if
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   245
  applicable):
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   246
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   247
  \begin{enumerate}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   248
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   249
  \item selecting one of the rules given as argument to the tactic;
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   250
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   251
  \item selecting a subgoal premise to eliminate, unifying it against
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   252
  the first premise of the rule;
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   253
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   254
  \item unifying the conclusion of the subgoal to the conclusion of
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   255
  the rule.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   256
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   257
  \end{enumerate}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   258
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   259
  Recall that higher-order unification may produce multiple results
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   260
  that are enumerated here.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   261
*}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   262
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   263
text %mlref {*
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   264
  \begin{mldecls}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   265
  @{index_ML resolve_tac: "thm list -> int -> tactic"} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   266
  @{index_ML eresolve_tac: "thm list -> int -> tactic"} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   267
  @{index_ML dresolve_tac: "thm list -> int -> tactic"} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   268
  @{index_ML forward_tac: "thm list -> int -> tactic"} \\[1ex]
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   269
  @{index_ML assume_tac: "int -> tactic"} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   270
  @{index_ML eq_assume_tac: "int -> tactic"} \\[1ex]
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   271
  @{index_ML match_tac: "thm list -> int -> tactic"} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   272
  @{index_ML ematch_tac: "thm list -> int -> tactic"} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   273
  @{index_ML dmatch_tac: "thm list -> int -> tactic"} \\
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   274
  \end{mldecls}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   275
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   276
  \begin{description}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   277
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   278
  \item @{ML resolve_tac}~@{text "thms i"} refines the goal state
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   279
  using the given theorems, which should normally be introduction
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   280
  rules.  The tactic resolves a rule's conclusion with subgoal @{text
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   281
  i}, replacing it by the corresponding versions of the rule's
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   282
  premises.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   283
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   284
  \item @{ML eresolve_tac}~@{text "thms i"} performs elim-resolution
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   285
  with the given theorems, which should normally be elimination rules.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   286
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   287
  \item @{ML dresolve_tac}~@{text "thms i"} performs
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   288
  destruct-resolution with the given theorems, which should normally
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   289
  be destruction rules.  This replaces an assumption by the result of
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   290
  applying one of the rules.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   291
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   292
  \item @{ML forward_tac} is like @{ML dresolve_tac} except that the
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   293
  selected assumption is not deleted.  It applies a rule to an
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   294
  assumption, adding the result as a new assumption.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   295
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   296
  \item @{ML assume_tac}~@{text i} attempts to solve subgoal @{text i}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   297
  by assumption (modulo higher-order unification).
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   298
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   299
  \item @{ML eq_assume_tac} is similar to @{ML assume_tac}, but checks
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   300
  only for immediate @{text "\<alpha>"}-convertibility instead of using
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   301
  unification.  It succeeds (with a unique next state) if one of the
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   302
  assumptions is equal to the subgoal's conclusion.  Since it does not
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   303
  instantiate variables, it cannot make other subgoals unprovable.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   304
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   305
  \item @{ML match_tac}, @{ML ematch_tac}, and @{ML dmatch_tac} are
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   306
  similar to @{ML resolve_tac}, @{ML eresolve_tac}, and @{ML
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   307
  dresolve_tac}, respectively, but do not instantiate schematic
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   308
  variables in the goal state.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   309
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   310
  Flexible subgoals are not updated at will, but are left alone.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   311
  Strictly speaking, matching means to treat the unknowns in the goal
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   312
  state as constants; these tactics merely discard unifiers that would
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   313
  update the goal state.
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   314
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   315
  \end{description}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   316
*}
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   317
dd886b5756a7 more on basic tactics;
wenzelm
parents: 28782
diff changeset
   318
28785
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   319
subsection {* Explicit instantiation within a subgoal context *}
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   320
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   321
text {* The main resolution tactics (\secref{sec:resolve-assume-tac})
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   322
  use higher-order unification, which works well in many practical
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   323
  situations despite its daunting theoretical properties.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   324
  Nonetheless, there are important problem classes where unguided
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   325
  higher-order unification is not so useful.  This typically involves
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   326
  rules like universal elimination, existential introduction, or
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   327
  equational substitution.  Here the unification problem involves
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   328
  fully flexible @{text "?P ?x"} schemes, which are hard to manage
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   329
  without further hints.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   330
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   331
  By providing a (small) rigid term for @{text "?x"} explicitly, the
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   332
  remaining unification problem is to assign a (large) term to @{text
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   333
  "?P"}, according to the shape of the given subgoal.  This is
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   334
  sufficiently well-behaved in most practical situations.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   335
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   336
  \medskip Isabelle provides separate versions of the standard @{text
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   337
  "r/e/d/f"} resolution tactics that allow to provide explicit
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   338
  instantiations of unknowns of the given rule, wrt.\ terms that refer
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   339
  to the implicit context of the selected subgoal.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   340
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   341
  An instantiation consists of a list of pairs of the form @{text
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   342
  "(?x, t)"}, where @{text ?x} is a schematic variable occurring in
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   343
  the given rule, and @{text t} is a term from the current proof
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   344
  context, augmented by the local goal parameters of the selected
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   345
  subgoal; cf.\ the @{text "focus"} operation described in
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   346
  \secref{sec:variables}.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   347
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   348
  Entering the syntactic context of a subgoal is a brittle operation,
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   349
  because its exact form is somewhat accidental, and the choice of
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   350
  bound variable names depends on the presence of other local and
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   351
  global names.  Explicit renaming of subgoal parameters prior to
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   352
  explicit instantiation might help to achieve a bit more robustness.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   353
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   354
  Type instantiations may be given as well, via pairs like @{text
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   355
  "(?'a, \<tau>)"}.  Type instantiations are distinguished from term
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   356
  instantiations by the syntactic form of the schematic variable.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   357
  Types are instantiated before terms are.  Since term instantiation
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   358
  already performs simple type-inference, so explicit type
28785
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   359
  instantiations are seldom necessary.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   360
*}
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   361
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   362
text %mlref {*
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   363
  \begin{mldecls}
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   364
  @{index_ML res_inst_tac: "Proof.context -> (indexname * string) list -> thm -> int -> tactic"} \\
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   365
  @{index_ML eres_inst_tac: "Proof.context -> (indexname * string) list -> thm -> int -> tactic"} \\
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   366
  @{index_ML dres_inst_tac: "Proof.context -> (indexname * string) list -> thm -> int -> tactic"} \\
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   367
  @{index_ML forw_inst_tac: "Proof.context -> (indexname * string) list -> thm -> int -> tactic"} \\[1ex]
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   368
  @{index_ML rename_tac: "string list -> int -> tactic"} \\
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   369
  \end{mldecls}
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   370
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   371
  \begin{description}
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   372
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   373
  \item @{ML res_inst_tac}~@{text "ctxt insts thm i"} instantiates the
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   374
  rule @{text thm} with the instantiations @{text insts}, as described
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   375
  above, and then performs resolution on subgoal @{text i}.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   376
  
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   377
  \item @{ML eres_inst_tac} is like @{ML res_inst_tac}, but performs
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   378
  elim-resolution.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   379
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   380
  \item @{ML dres_inst_tac} is like @{ML res_inst_tac}, but performs
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   381
  destruct-resolution.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   382
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   383
  \item @{ML forw_inst_tac} is like @{ML dres_inst_tac} except that
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   384
  the selected assumption is not deleted.
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   385
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   386
  \item @{ML rename_tac}~@{text "names i"} renames the innermost
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   387
  parameters of subgoal @{text i} according to the provided @{text
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   388
  names} (which need to be distinct indentifiers).
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   389
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   390
  \end{description}
34930
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   391
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   392
  For historical reasons, the above instantiation tactics take
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   393
  unparsed string arguments, which makes them hard to use in general
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   394
  ML code.  The slightly more advanced @{ML Subgoal.FOCUS} combinator
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   395
  of \secref{sec:struct-goals} allows to refer to internal goal
f3bce1cc513c added Subgoal.FOCUS;
wenzelm
parents: 32201
diff changeset
   396
  structure with explicit context management.
28785
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   397
*}
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   398
64163cddf3e6 added section "Explicit instantiation within a subgoal context";
wenzelm
parents: 28783
diff changeset
   399
28781
1da96325eedf added section "Tactics";
wenzelm
parents: 20547
diff changeset
   400
section {* Tacticals \label{sec:tacticals} *}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   401
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   402
text {*
29758
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   403
  A \emph{tactical} is a functional combinator for building up complex
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   404
  tactics from simpler ones.  Typical tactical perform sequential
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   405
  composition, disjunction (choice), iteration, or goal addressing.
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   406
  Various search strategies may be expressed via tacticals.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   407
29758
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   408
  \medskip FIXME
39852
9c977f899ebf tuned chapter arrangement;
wenzelm
parents: 39847
diff changeset
   409
9c977f899ebf tuned chapter arrangement;
wenzelm
parents: 39847
diff changeset
   410
  \medskip The chapter on tacticals in \cite{isabelle-ref} is still
9c977f899ebf tuned chapter arrangement;
wenzelm
parents: 39847
diff changeset
   411
  applicable, despite a few outdated details.  *}
30272
2d612824e642 regenerated document;
wenzelm
parents: 30270
diff changeset
   412
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   413
end