18537
|
1 |
|
|
2 |
(* $Id$ *)
|
|
3 |
|
|
4 |
theory tactic imports base begin
|
|
5 |
|
20452
|
6 |
chapter {* Tactical reasoning *}
|
18537
|
7 |
|
20451
|
8 |
text {*
|
|
9 |
The basic idea of tactical theorem proving is to refine the initial
|
|
10 |
claim in a backwards fashion, until a solved form is reached. An
|
|
11 |
intermediate goal consists of several subgoals that need to be
|
|
12 |
solved in order to achieve the main statement; zero subgoals means
|
|
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 |
*}
|
18537
|
18 |
|
|
19 |
|
|
20 |
section {* Goals \label{sec:tactical-goals} *}
|
|
21 |
|
20451
|
22 |
text {*
|
|
23 |
Isabelle/Pure represents a goal\glossary{Tactical goal}{A theorem of
|
|
24 |
\seeglossary{Horn Clause} form stating that a number of subgoals
|
|
25 |
imply the main conclusion, which is marked as a protected
|
|
26 |
proposition.} as a theorem stating that the subgoals imply the main
|
|
27 |
goal: @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}. The outermost goal
|
|
28 |
structure is that of a Horn Clause\glossary{Horn Clause}{An iterated
|
|
29 |
implication @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}, without any
|
|
30 |
outermost quantifiers. Strictly speaking, propositions @{text
|
|
31 |
"A\<^sub>i"} need to be atomic in Horn Clauses, but Isabelle admits
|
|
32 |
arbitrary substructure here (nested @{text "\<Longrightarrow>"} and @{text "\<And>"}
|
|
33 |
connectives).}: i.e.\ an iterated implication without any
|
|
34 |
quantifiers\footnote{Recall that outermost @{text "\<And>x. \<phi>[x]"} is
|
|
35 |
always represented via schematic variables in the body: @{text
|
|
36 |
"\<phi>[?x]"}. These variables may get instantiated during the course of
|
|
37 |
reasoning.}. For @{text "n = 0"} a goal is called ``solved''.
|
18537
|
38 |
|
20451
|
39 |
The structure of each subgoal @{text "A\<^sub>i"} is that of a
|
|
40 |
general Hereditary Harrop Formula @{text "\<And>x\<^sub>1 \<dots>
|
|
41 |
\<And>x\<^sub>k. H\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> H\<^sub>m \<Longrightarrow> B"} according to the normal
|
|
42 |
form where any local @{text \<And>} is pulled before @{text \<Longrightarrow>}. Here
|
|
43 |
@{text "x\<^sub>1, \<dots>, x\<^sub>k"} are goal parameters, i.e.\
|
|
44 |
arbitrary-but-fixed entities of certain types, and @{text
|
|
45 |
"H\<^sub>1, \<dots>, H\<^sub>m"} are goal hypotheses, i.e.\ facts that may
|
|
46 |
be assumed locally. Together, this forms the goal context of the
|
|
47 |
conclusion @{text B} to be established. The goal hypotheses may be
|
|
48 |
again Hereditary Harrop Formulas, although the level of nesting
|
|
49 |
rarely exceeds 1--2 in practice.
|
18537
|
50 |
|
20451
|
51 |
The main conclusion @{text C} is internally marked as a protected
|
|
52 |
proposition\glossary{Protected proposition}{An arbitrarily
|
|
53 |
structured proposition @{text "C"} which is forced to appear as
|
|
54 |
atomic by wrapping it into a propositional identity operator;
|
|
55 |
notation @{text "#C"}. Protecting a proposition prevents basic
|
|
56 |
inferences from entering into that structure for the time being.},
|
|
57 |
which is occasionally represented explicitly by the notation @{text
|
|
58 |
"#C"}. This ensures that the decomposition into subgoals and main
|
|
59 |
conclusion is well-defined for arbitrarily structured claims.
|
18537
|
60 |
|
20451
|
61 |
\medskip Basic goal management is performed via the following
|
|
62 |
Isabelle/Pure rules:
|
18537
|
63 |
|
|
64 |
\[
|
|
65 |
\infer[@{text "(init)"}]{@{text "C \<Longrightarrow> #C"}}{} \qquad
|
|
66 |
\infer[@{text "(finish)"}]{@{text "#C"}}{@{text "C"}}
|
|
67 |
\]
|
|
68 |
|
|
69 |
\medskip The following low-level variants admit general reasoning
|
|
70 |
with protected propositions:
|
|
71 |
|
|
72 |
\[
|
|
73 |
\infer[@{text "(protect)"}]{@{text "#C"}}{@{text "C"}} \qquad
|
|
74 |
\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"}}
|
|
75 |
\]
|
|
76 |
*}
|
|
77 |
|
|
78 |
text %mlref {*
|
|
79 |
\begin{mldecls}
|
|
80 |
@{index_ML Goal.init: "cterm -> thm"} \\
|
|
81 |
@{index_ML Goal.finish: "thm -> thm"} \\
|
|
82 |
@{index_ML Goal.protect: "thm -> thm"} \\
|
|
83 |
@{index_ML Goal.conclude: "thm -> thm"} \\
|
|
84 |
\end{mldecls}
|
|
85 |
|
|
86 |
\begin{description}
|
|
87 |
|
20451
|
88 |
\item @{ML "Goal.init"}~@{text "\<phi>"} initializes a tactical goal from
|
18537
|
89 |
the type-checked proposition @{text \<phi>}.
|
|
90 |
|
|
91 |
\item @{ML "Goal.finish"}~@{text "th"} checks whether theorem @{text
|
20451
|
92 |
"th"} is a solved goal configuration (no subgoals), and concludes
|
18537
|
93 |
the result by removing the goal protection.
|
|
94 |
|
20451
|
95 |
\item @{ML "Goal.protect"}~@{text "th"} protects the full statement
|
18537
|
96 |
of theorem @{text "th"}.
|
|
97 |
|
|
98 |
\item @{ML "Goal.conclude"}~@{text "th"} removes the goal protection
|
|
99 |
for any number of pending subgoals.
|
|
100 |
|
|
101 |
\end{description}
|
|
102 |
*}
|
|
103 |
|
|
104 |
|
|
105 |
section {* Tactics *}
|
|
106 |
|
|
107 |
text {*
|
|
108 |
|
|
109 |
FIXME
|
|
110 |
|
|
111 |
\glossary{Tactic}{Any function that maps a \seeglossary{tactical goal}
|
|
112 |
to a lazy sequence of possible sucessors. This scheme subsumes
|
|
113 |
failure (empty result sequence), as well as lazy enumeration of proof
|
|
114 |
search results. Error conditions are usually mapped to an empty
|
|
115 |
result, which gives further tactics a chance to try in turn.
|
|
116 |
Commonly, tactics either take an argument to address a particular
|
|
117 |
subgoal, or operate on a certain range of subgoals in a uniform
|
|
118 |
fashion. In any case, the main conclusion is normally left untouched,
|
|
119 |
apart from instantiating \seeglossary{schematic variables}.}
|
|
120 |
|
|
121 |
|
|
122 |
*}
|
|
123 |
|
|
124 |
section {* Tacticals *}
|
|
125 |
|
|
126 |
text {*
|
|
127 |
|
|
128 |
FIXME
|
|
129 |
|
|
130 |
\glossary{Tactical}{A functional combinator for building up complex
|
|
131 |
tactics from simpler ones. Typical tactical perform sequential
|
|
132 |
composition, disjunction (choice), iteration, or goal addressing.
|
|
133 |
Various search strategies may be expressed via tacticals.}
|
|
134 |
|
|
135 |
*}
|
|
136 |
|
|
137 |
section {* Programmed proofs *}
|
|
138 |
|
|
139 |
text {*
|
|
140 |
In order to perform a complete tactical proof under program control,
|
|
141 |
one needs to set up an initial goal configuration, apply a tactic,
|
|
142 |
and finish the result, cf.\ the rules given in
|
|
143 |
\secref{sec:tactical-goals}. Further checks are required to ensure
|
|
144 |
that the result is actually an instance of the original claim --
|
|
145 |
ill-behaved tactics could have destroyed that information.
|
|
146 |
|
|
147 |
Several simultaneous claims may be handled within a single goal
|
20451
|
148 |
statement by using meta-level conjunction internally. The whole
|
|
149 |
configuration may be considered within a context of
|
|
150 |
arbitrary-but-fixed parameters and hypotheses, which will be
|
|
151 |
available as local facts during the proof and discharged into
|
18537
|
152 |
implications in the result.
|
|
153 |
|
|
154 |
All of these administrative tasks are packaged into a separate
|
|
155 |
operation, such that the user merely needs to provide the statement
|
|
156 |
and tactic to be applied.
|
|
157 |
*}
|
|
158 |
|
|
159 |
text %mlref {*
|
|
160 |
\begin{mldecls}
|
20042
|
161 |
@{index_ML Goal.prove: "Proof.context -> string list -> term list -> term ->
|
20316
|
162 |
({prems: thm list, context: Proof.context} -> tactic) -> thm"} \\
|
20042
|
163 |
@{index_ML Goal.prove_multi: "Proof.context -> string list -> term list -> term list ->
|
20316
|
164 |
({prems: thm list, context: Proof.context} -> tactic) -> thm list"} \\
|
20042
|
165 |
@{index_ML Goal.prove_global: "theory -> string list -> term list -> term ->
|
|
166 |
(thm list -> tactic) -> thm"} \\
|
18537
|
167 |
\end{mldecls}
|
|
168 |
|
|
169 |
\begin{description}
|
|
170 |
|
20042
|
171 |
\item @{ML Goal.prove}~@{text "ctxt xs As C tac"} states goal @{text
|
18537
|
172 |
"C"} in the context of arbitrary-but-fixed parameters @{text "xs"}
|
|
173 |
and hypotheses @{text "As"} and applies tactic @{text "tac"} to
|
|
174 |
solve it. The latter may depend on the local assumptions being
|
|
175 |
presented as facts. The result is essentially @{text "\<And>xs. As \<Longrightarrow>
|
|
176 |
C"}, but is normalized by pulling @{text "\<And>"} before @{text "\<Longrightarrow>"}
|
|
177 |
(the conclusion @{text "C"} itself may be a rule statement), turning
|
|
178 |
the quantifier prefix into schematic variables, and generalizing
|
|
179 |
implicit type-variables.
|
|
180 |
|
|
181 |
\item @{ML Goal.prove_multi} is simular to @{ML Goal.prove}, but
|
|
182 |
states several conclusions simultaneously. @{ML
|
|
183 |
Tactic.conjunction_tac} may be used to split these into individual
|
|
184 |
subgoals before commencing the actual proof.
|
|
185 |
|
20042
|
186 |
\item @{ML Goal.prove_global} is a degraded version of @{ML
|
|
187 |
Goal.prove} for theory level goals; it includes a global @{ML
|
|
188 |
Drule.standard} for the result.
|
|
189 |
|
18537
|
190 |
\end{description}
|
|
191 |
*}
|
|
192 |
|
|
193 |
end
|
|
194 |
|