author | Christian Urban <urbanc@in.tum.de> |
Wed, 04 Feb 2009 20:26:38 +0000 | |
changeset 95 | 7235374f34c8 |
parent 93 | 62fb91f86908 |
child 99 | de625e5f6a36 |
permissions | -rw-r--r-- |
93 | 1 |
theory Tactical |
2 |
imports Base |
|
3 |
begin |
|
4 |
||
5 |
chapter {* Tactical Reasoning\label{chp:tactical} *} |
|
6 |
||
7 |
text {* |
|
8 |
||
9 |
The main reason for descending to the ML-level of Isabelle is to be able to |
|
10 |
implement automatic proof procedures. Such proof procedures usually lessen |
|
11 |
considerably the burden of manual reasoning, for example, when introducing |
|
12 |
new definitions. These proof procedures are centred around refining a goal |
|
13 |
state using tactics. This is similar to the @{text apply}-style reasoning at |
|
14 |
the user level, where goals are modified in a sequence of proof steps until |
|
15 |
all of them are solved. |
|
16 |
||
17 |
||
18 |
*} |
|
19 |
||
20 |
section {* Tactical Reasoning *} |
|
21 |
||
22 |
text {* |
|
23 |
To see how tactics work, let us first transcribe a simple @{text apply}-style proof |
|
24 |
into ML. Consider the following proof. |
|
25 |
*} |
|
26 |
||
27 |
lemma disj_swap: "P \<or> Q \<Longrightarrow> Q \<or> P" |
|
28 |
apply(erule disjE) |
|
29 |
apply(rule disjI2) |
|
30 |
apply(assumption) |
|
31 |
apply(rule disjI1) |
|
32 |
apply(assumption) |
|
33 |
done |
|
34 |
||
35 |
text {* |
|
36 |
This proof translates to the following ML-code. |
|
37 |
||
38 |
@{ML_response_fake [display,gray] |
|
39 |
"let |
|
40 |
val ctxt = @{context} |
|
41 |
val goal = @{prop \"P \<or> Q \<Longrightarrow> Q \<or> P\"} |
|
42 |
in |
|
43 |
Goal.prove ctxt [\"P\", \"Q\"] [] goal |
|
44 |
(fn _ => |
|
45 |
etac @{thm disjE} 1 |
|
46 |
THEN rtac @{thm disjI2} 1 |
|
47 |
THEN atac 1 |
|
48 |
THEN rtac @{thm disjI1} 1 |
|
49 |
THEN atac 1) |
|
50 |
end" "?P \<or> ?Q \<Longrightarrow> ?Q \<or> ?P"} |
|
51 |
||
52 |
To start the proof, the function @{ML "Goal.prove"}~@{text "ctxt xs As C |
|
53 |
tac"} sets up a goal state for proving the goal @{text C} under the |
|
54 |
assumptions @{text As} (empty in the proof at hand) with the variables |
|
55 |
@{text xs} that will be generalised once the goal is proved (in our case |
|
56 |
@{text P} and @{text Q}). The @{text "tac"} is the tactic that proves the goal; |
|
57 |
it can make use of the local assumptions (there are none in this example). |
|
58 |
The functions @{ML etac}, @{ML rtac} and @{ML atac} correspond to |
|
59 |
@{text erule}, @{text rule} and @{text assumption}, respectively. |
|
60 |
The operator @{ML THEN} strings tactics together. |
|
61 |
||
62 |
\begin{readmore} |
|
63 |
To learn more about the function @{ML Goal.prove} see \isccite{sec:results} and |
|
64 |
the file @{ML_file "Pure/goal.ML"}. For more information about the internals of goals see |
|
65 |
\isccite{sec:tactical-goals}. |
|
66 |
\end{readmore} |
|
67 |
||
68 |
Note that we used antiquotations for referencing the theorems. We could also |
|
69 |
just have written @{ML "etac disjE 1"} and so on, but this is considered bad |
|
70 |
style. The reason is that the binding for @{ML disjE} can be re-assigned by |
|
71 |
the user and thus one does not have complete control over which theorem is |
|
72 |
actually applied. This problem is nicely prevented by using antiquotations, |
|
73 |
because then the theorems are fixed statically at compile-time. |
|
74 |
||
75 |
During the development of automatic proof procedures, it will often be necessary |
|
76 |
to test a tactic on examples. This can be conveniently |
|
77 |
done with the command \isacommand{apply}@{text "(tactic \<verbopen> \<dots> \<verbclose>)"}. |
|
78 |
Consider the following sequence of tactics |
|
79 |
*} |
|
80 |
||
81 |
ML{*val foo_tac = |
|
82 |
(etac @{thm disjE} 1 |
|
83 |
THEN rtac @{thm disjI2} 1 |
|
84 |
THEN atac 1 |
|
85 |
THEN rtac @{thm disjI1} 1 |
|
86 |
THEN atac 1)*} |
|
87 |
||
88 |
text {* and the Isabelle proof: *} |
|
89 |
||
90 |
lemma "P \<or> Q \<Longrightarrow> Q \<or> P" |
|
91 |
apply(tactic {* foo_tac *}) |
|
92 |
done |
|
93 |
||
94 |
text {* |
|
95 |
The apply-step applies the @{ML foo_tac} and therefore solves the goal completely. |
|
96 |
Inside @{text "tactic \<verbopen> \<dots> \<verbclose>"} |
|
97 |
we can call any function that returns a tactic. |
|
98 |
||
99 |
As can be seen, each tactic in @{ML foo_tac} has a hard-coded number that |
|
100 |
stands for the subgoal analysed by the tactic. In our case, we only focus on the first |
|
101 |
subgoal. This is sometimes wanted, but usually not. To avoid the explicit numbering in the |
|
102 |
tactic, you can write |
|
103 |
*} |
|
104 |
||
105 |
ML{*val foo_tac' = |
|
106 |
(etac @{thm disjE} |
|
107 |
THEN' rtac @{thm disjI2} |
|
108 |
THEN' atac |
|
109 |
THEN' rtac @{thm disjI1} |
|
110 |
THEN' atac)*} |
|
111 |
||
112 |
text {* |
|
113 |
and then give the number for the subgoal explicitly when the tactic is |
|
114 |
called. So in the next proof we discharge first the second subgoal, |
|
115 |
and after that the first. |
|
116 |
*} |
|
117 |
||
118 |
lemma "P1 \<or> Q1 \<Longrightarrow> Q1 \<or> P1" |
|
119 |
and "P2 \<or> Q2 \<Longrightarrow> Q2 \<or> P2" |
|
120 |
apply(tactic {* foo_tac' 2 *}) |
|
121 |
apply(tactic {* foo_tac' 1 *}) |
|
122 |
done |
|
123 |
||
124 |
text {* |
|
125 |
The tactic @{ML foo_tac} is very specific for analysing goals of the form |
|
126 |
@{prop "P \<or> Q \<Longrightarrow> Q \<or> P"}. If the goal is not of this form, then @{ML foo_tac} |
|
127 |
throws the error message about an empty result sequence---meaning the tactic |
|
128 |
failed. The reason for this message is that tactics are functions that map |
|
129 |
a goal state to a (lazy) sequence of successor states, hence the type of a |
|
130 |
tactic is |
|
131 |
||
132 |
@{text [display, gray] "type tactic = thm -> thm Seq.seq"} |
|
133 |
||
134 |
Consequently, if a tactic fails, then it returns the empty sequence. This |
|
135 |
is by the way the default behaviour for a failing tactic; tactics should |
|
136 |
not raise exceptions. |
|
137 |
||
138 |
In the following example there are two possibilities for how to apply the tactic. |
|
139 |
*} |
|
140 |
||
141 |
lemma "\<lbrakk>P \<or> Q; P \<or> Q\<rbrakk> \<Longrightarrow> Q \<or> P" |
|
142 |
apply(tactic {* foo_tac' 1 *}) |
|
143 |
back |
|
144 |
done |
|
145 |
||
146 |
text {* |
|
147 |
The application of the tactic results in a sequence of two possible |
|
148 |
proofs. The Isabelle command \isacommand{back} allows us to explore both |
|
149 |
possibilities. |
|
150 |
||
151 |
\begin{readmore} |
|
152 |
See @{ML_file "Pure/General/seq.ML"} for the implementation of lazy |
|
153 |
sequences. However in day-to-day Isabelle programming, one rarely |
|
154 |
constructs sequences explicitly, but uses the predefined functions |
|
155 |
instead. See @{ML_file "Pure/tactic.ML"} and |
|
156 |
@{ML_file "Pure/tctical.ML"} for the code of basic tactics and tactic |
|
157 |
combinators; see also Chapters 3 and 4 in |
|
158 |
the old Isabelle Reference Manual. |
|
159 |
\end{readmore} |
|
160 |
||
161 |
*} |
|
162 |
||
163 |
||
164 |
section {* Basic Tactics *} |
|
165 |
||
166 |
lemma shows "False \<Longrightarrow> False" |
|
167 |
apply(tactic {* atac 1 *}) |
|
168 |
done |
|
169 |
||
170 |
lemma shows "True \<and> True" |
|
171 |
apply(tactic {* rtac @{thm conjI} 1 *}) |
|
172 |
txt {* @{subgoals [display]} *} |
|
173 |
(*<*)oops(*>*) |
|
174 |
||
175 |
lemma |
|
176 |
shows "Foo" |
|
177 |
and "True \<and> True" |
|
178 |
apply(tactic {* rtac @{thm conjI} 2 *}) |
|
179 |
txt {* @{subgoals [display]} *} |
|
180 |
(*<*)oops(*>*) |
|
181 |
||
182 |
lemma shows "False \<and> False \<Longrightarrow> False" |
|
183 |
apply(tactic {* etac @{thm conjE} 1 *}) |
|
184 |
txt {* @{subgoals [display]} *} |
|
185 |
(*<*)oops(*>*) |
|
186 |
||
187 |
lemma shows "False \<and> True \<Longrightarrow> False" |
|
188 |
apply(tactic {* dtac @{thm conjunct2} 1 *}) |
|
189 |
txt {* @{subgoals [display]} *} |
|
190 |
(*<*)oops(*>*) |
|
191 |
||
192 |
text {* |
|
193 |
similarly @{ML ftac} |
|
194 |
*} |
|
195 |
||
196 |
text {* diagnostics *} |
|
197 |
lemma shows "True \<Longrightarrow> False" |
|
198 |
apply(tactic {* print_tac "foo message" *}) |
|
199 |
(*<*)oops(*>*) |
|
200 |
||
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
201 |
text {* Let us assume the following four string conversion functions: *} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
202 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
203 |
ML{*fun str_of_cterm ctxt t = |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
204 |
Syntax.string_of_term ctxt (term_of t) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
205 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
206 |
fun str_of_cterms ctxt ts = |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
207 |
commas (map (str_of_cterm ctxt) ts) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
208 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
209 |
fun str_of_thm ctxt thm = |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
210 |
let |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
211 |
val {prop, ...} = crep_thm thm |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
212 |
in |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
213 |
str_of_cterm ctxt prop |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
214 |
end |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
215 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
216 |
fun str_of_thms ctxt thms = |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
217 |
commas (map (str_of_thm ctxt) thms)*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
218 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
219 |
text {* |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
220 |
and the following function |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
221 |
*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
222 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
223 |
ML{*fun sp_tac {prems, params, asms, concl, context, schematics} = |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
224 |
let |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
225 |
val str_of_params = str_of_cterms context params |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
226 |
val str_of_asms = str_of_cterms context asms |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
227 |
val str_of_concl = str_of_cterm context concl |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
228 |
val str_of_prems = str_of_thms context prems |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
229 |
val str_of_schms = str_of_cterms context (snd schematics) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
230 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
231 |
val _ = (warning ("params: " ^ str_of_params); |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
232 |
warning ("schematics: " ^ str_of_schms); |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
233 |
warning ("asms: " ^ str_of_asms); |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
234 |
warning ("concl: " ^ str_of_concl); |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
235 |
warning ("prems: " ^ str_of_prems)) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
236 |
in |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
237 |
no_tac |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
238 |
end*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
239 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
240 |
text {* |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
241 |
then the tactic @{ML SUBPROOF} fixes the parameters and binds the various components |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
242 |
of a proof state into a record. For example |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
243 |
*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
244 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
245 |
lemma |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
246 |
shows "\<And>x y. A x y \<Longrightarrow> B y x \<longrightarrow> C (?z y) x" |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
247 |
apply(tactic {* SUBPROOF sp_tac @{context} 1 *})? |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
248 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
249 |
txt {* |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
250 |
prints out |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
251 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
252 |
\begin{center} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
253 |
\begin{tabular}{ll} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
254 |
params: & @{term x}, @{term y}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
255 |
schematics: & @{term z}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
256 |
asms: & @{term "A x y"}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
257 |
concl: & @{term "B y x \<longrightarrow> C (z y) x"}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
258 |
prems: & @{term "A x y"} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
259 |
\end{tabular} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
260 |
\end{center} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
261 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
262 |
Continuing the proof script with |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
263 |
*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
264 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
265 |
apply(rule impI) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
266 |
apply(tactic {* SUBPROOF sp_tac @{context} 1 *})? |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
267 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
268 |
txt {* |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
269 |
prints out |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
270 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
271 |
\begin{center} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
272 |
\begin{tabular}{ll} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
273 |
params: & @{term x}, @{term y}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
274 |
schematics: & @{term z}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
275 |
asms: & @{term "A x y"}, @{term "B y x"}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
276 |
concl: & @{term "C (z y) x"}\\ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
277 |
prems: & @{term "A x y"}, @{term "B y x"} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
278 |
\end{tabular} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
279 |
\end{center} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
280 |
*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
281 |
(*<*)oops(*>*) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
282 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
283 |
|
93 | 284 |
text {* |
285 |
@{ML PRIMITIVE}? @{ML SUBGOAL} see page 32 in ref |
|
286 |
*} |
|
287 |
||
288 |
text {* |
|
289 |
@{ML all_tac} @{ML no_tac} |
|
290 |
*} |
|
291 |
||
292 |
section {* Operations on Tactics *} |
|
293 |
||
294 |
text {* THEN *} |
|
295 |
||
296 |
lemma shows "(True \<and> True) \<and> False" |
|
297 |
apply(tactic {* (rtac @{thm conjI} 1) THEN (rtac @{thm conjI} 1) *}) |
|
298 |
txt {* @{subgoals [display]} *} |
|
299 |
(*<*)oops(*>*) |
|
300 |
||
301 |
lemma shows "True \<and> False" |
|
302 |
apply(tactic {* (rtac @{thm disjI1} 1) ORELSE (rtac @{thm conjI} 1) *}) |
|
303 |
txt {* @{subgoals [display]} *} |
|
304 |
(*<*)oops(*>*) |
|
305 |
||
306 |
||
307 |
text {* |
|
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
308 |
@{ML EVERY} @{ML REPEAT} |
93 | 309 |
|
310 |
@{ML rewrite_goals_tac} |
|
311 |
@{ML cut_facts_tac} |
|
312 |
@{ML ObjectLogic.full_atomize_tac} |
|
313 |
@{ML ObjectLogic.rulify_tac} |
|
314 |
@{ML resolve_tac} |
|
315 |
*} |
|
316 |
||
317 |
||
318 |
||
319 |
text {* |
|
320 |
||
321 |
||
322 |
A goal (or goal state) is a special @{ML_type thm}, which by |
|
323 |
convention is an implication of the form: |
|
324 |
||
325 |
@{text[display] "A\<^isub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^isub>n \<Longrightarrow> #(C)"} |
|
326 |
||
327 |
where @{term C} is the goal to be proved and the @{term "A\<^isub>i"} are the open |
|
328 |
subgoals. |
|
329 |
Since the goal @{term C} can potentially be an implication, there is a |
|
330 |
@{text "#"} wrapped around it, which prevents that premises are |
|
331 |
misinterpreted as open subgoals. The wrapper @{text "# :: prop \<Rightarrow> |
|
332 |
prop"} is just the identity function and used as a syntactic marker. |
|
333 |
||
334 |
||
335 |
||
336 |
||
337 |
||
338 |
While tactics can operate on the subgoals (the @{text "A\<^isub>i"} above), they |
|
339 |
are expected to leave the conclusion @{term C} intact, with the |
|
340 |
exception of possibly instantiating schematic variables. |
|
341 |
||
342 |
||
343 |
||
344 |
*} |
|
345 |
||
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
346 |
section {* Structured Proofs *} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
347 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
348 |
lemma True |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
349 |
proof |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
350 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
351 |
{ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
352 |
fix A B C |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
353 |
assume r: "A & B \<Longrightarrow> C" |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
354 |
assume A B |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
355 |
then have "A & B" .. |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
356 |
then have C by (rule r) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
357 |
} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
358 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
359 |
{ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
360 |
fix A B C |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
361 |
assume r: "A & B \<Longrightarrow> C" |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
362 |
assume A B |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
363 |
note conjI [OF this] |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
364 |
note r [OF this] |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
365 |
} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
366 |
oops |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
367 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
368 |
ML {* fun prop ctxt s = |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
369 |
Thm.cterm_of (ProofContext.theory_of ctxt) (Syntax.read_prop ctxt s) *} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
370 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
371 |
ML {* |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
372 |
val ctxt0 = @{context}; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
373 |
val ctxt = ctxt0; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
374 |
val (_, ctxt) = Variable.add_fixes ["A", "B", "C"] ctxt; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
375 |
val ([r], ctxt) = Assumption.add_assumes [prop ctxt "A & B \<Longrightarrow> C"] ctxt; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
376 |
val (this, ctxt) = Assumption.add_assumes [prop ctxt "A", prop ctxt "B"] ctxt; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
377 |
val this = [@{thm conjI} OF this]; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
378 |
val this = r OF this; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
379 |
val this = Assumption.export false ctxt ctxt0 this |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
380 |
val this = Variable.export ctxt ctxt0 [this] |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
381 |
*} |
93 | 382 |
|
383 |
||
384 |
end |