author | Christian Urban <urbanc@in.tum.de> |
Wed, 11 Feb 2009 17:40:24 +0000 | |
changeset 108 | 8bea3f74889d |
parent 107 | 258ce361ba1b |
child 109 | b4234e8a0202 |
permissions | -rw-r--r-- |
93 | 1 |
theory Tactical |
99 | 2 |
imports Base FirstSteps |
93 | 3 |
begin |
4 |
||
5 |
chapter {* Tactical Reasoning\label{chp:tactical} *} |
|
6 |
||
7 |
text {* |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
8 |
The main reason for descending to the ML-level of Isabelle is to be able to |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
9 |
implement automatic proof procedures. Such proof procedures usually lessen |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
10 |
considerably the burden of manual reasoning, for example, when introducing |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
11 |
new definitions. These proof procedures are centred around refining a goal |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
12 |
state using tactics. This is similar to the \isacommand{apply}-style |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
13 |
reasoning at the user level, where goals are modified in a sequence of proof |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
14 |
steps until all of them are solved. However, there are also more structured |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
15 |
operations available on the ML-level that help with the handling of |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
16 |
variables and assumptions. |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
17 |
|
93 | 18 |
*} |
19 |
||
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
20 |
section {* Basics of Reasoning with Tactics*} |
93 | 21 |
|
22 |
text {* |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
23 |
To see how tactics work, let us first transcribe a simple \isacommand{apply}-style proof |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
24 |
into ML. Suppose the following proof. |
93 | 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 |
|
99 | 53 |
tac"} sets up a goal state for proving the goal @{text C} |
54 |
(that is @{prop "P \<or> Q \<Longrightarrow> Q \<or> P"} in the proof at hand) under the |
|
55 |
assumptions @{text As} (happens to be empty) with the variables |
|
93 | 56 |
@{text xs} that will be generalised once the goal is proved (in our case |
57 |
@{text P} and @{text Q}). The @{text "tac"} is the tactic that proves the goal; |
|
58 |
it can make use of the local assumptions (there are none in this example). |
|
59 |
The functions @{ML etac}, @{ML rtac} and @{ML atac} correspond to |
|
60 |
@{text erule}, @{text rule} and @{text assumption}, respectively. |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
61 |
The operator @{ML THEN} strings the tactics together. |
93 | 62 |
|
63 |
\begin{readmore} |
|
99 | 64 |
To learn more about the function @{ML Goal.prove} see \isccite{sec:results} |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
65 |
and the file @{ML_file "Pure/goal.ML"}. See @{ML_file |
99 | 66 |
"Pure/tactic.ML"} and @{ML_file "Pure/tctical.ML"} for the code of basic |
67 |
tactics and tactic combinators; see also Chapters 3 and 4 in the old |
|
68 |
Isabelle Reference Manual. |
|
93 | 69 |
\end{readmore} |
70 |
||
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
71 |
Note that in the code above we used antiquotations for referencing the theorems. Many theorems |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
72 |
also have ML-bindings with the same name. Therefore, we could also just have |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
73 |
written @{ML "etac disjE 1"}, or in case there are no ML-binding obtained |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
74 |
the theorem dynamically using the function @{ML thm}; for example |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
75 |
@{ML "etac (thm \"disjE\") 1"}. Both ways however are considered bad style! |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
76 |
The reason |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
77 |
is that the binding for @{ML disjE} can be re-assigned by the user and thus |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
78 |
one does not have complete control over which theorem is actually |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
79 |
applied. This problem is nicely prevented by using antiquotations, because |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
80 |
then the theorems are fixed statically at compile-time. |
93 | 81 |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
82 |
During the development of automatic proof procedures, you will often find it |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
83 |
necessary to test a tactic on examples. This can be conveniently |
93 | 84 |
done with the command \isacommand{apply}@{text "(tactic \<verbopen> \<dots> \<verbclose>)"}. |
85 |
Consider the following sequence of tactics |
|
86 |
*} |
|
87 |
||
88 |
ML{*val foo_tac = |
|
89 |
(etac @{thm disjE} 1 |
|
90 |
THEN rtac @{thm disjI2} 1 |
|
91 |
THEN atac 1 |
|
92 |
THEN rtac @{thm disjI1} 1 |
|
93 |
THEN atac 1)*} |
|
94 |
||
95 |
text {* and the Isabelle proof: *} |
|
96 |
||
97 |
lemma "P \<or> Q \<Longrightarrow> Q \<or> P" |
|
98 |
apply(tactic {* foo_tac *}) |
|
99 |
done |
|
100 |
||
101 |
text {* |
|
104 | 102 |
By using @{text "tactic \<verbopen> \<dots> \<verbclose>"} you can call from the |
103 |
user level of Isabelle the tactic @{ML foo_tac} or |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
104 |
any other function that returns a tactic. |
93 | 105 |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
106 |
The tactic @{ML foo_tac} is just a sequence of simple tactics stringed |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
107 |
together by @{ML THEN}. As can be seen, each simple tactic in @{ML foo_tac} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
108 |
has a hard-coded number that stands for the subgoal analysed by the |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
109 |
tactic (@{text "1"} stands for the first, or top-most, subgoal). This hard-coding |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
110 |
of goals is sometimes wanted, but usually it is not. To avoid the explicit numbering, |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
111 |
you can write\label{tac:footacprime} |
93 | 112 |
*} |
113 |
||
114 |
ML{*val foo_tac' = |
|
115 |
(etac @{thm disjE} |
|
116 |
THEN' rtac @{thm disjI2} |
|
117 |
THEN' atac |
|
118 |
THEN' rtac @{thm disjI1} |
|
119 |
THEN' atac)*} |
|
120 |
||
121 |
text {* |
|
122 |
and then give the number for the subgoal explicitly when the tactic is |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
123 |
called. So in the next proof you can first discharge the second subgoal, and |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
124 |
after that the first. |
93 | 125 |
*} |
126 |
||
127 |
lemma "P1 \<or> Q1 \<Longrightarrow> Q1 \<or> P1" |
|
128 |
and "P2 \<or> Q2 \<Longrightarrow> Q2 \<or> P2" |
|
129 |
apply(tactic {* foo_tac' 2 *}) |
|
130 |
apply(tactic {* foo_tac' 1 *}) |
|
131 |
done |
|
132 |
||
133 |
text {* |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
134 |
This kind of addressing is more difficult to achieve when the goal is |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
135 |
hard-coded inside the tactic. For most operators that combine tactics |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
136 |
(@{ML THEN} is only one such operator) a ``primed'' version exists. |
99 | 137 |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
138 |
The tactics @{ML foo_tac} and @{ML foo_tac'} are very specific for |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
139 |
analysing goals being only of the form @{prop "P \<or> Q \<Longrightarrow> Q \<or> P"}. If the goal is not |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
140 |
of this form, then they throw the error message: |
99 | 141 |
|
142 |
\begin{isabelle} |
|
143 |
@{text "*** empty result sequence -- proof command failed"}\\ |
|
144 |
@{text "*** At command \"apply\"."} |
|
145 |
\end{isabelle} |
|
146 |
||
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
147 |
Meaning the tactics failed. The reason for this error message is that tactics |
99 | 148 |
are functions that map a goal state to a (lazy) sequence of successor states, |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
149 |
hence the type of a tactic is: |
93 | 150 |
|
151 |
@{text [display, gray] "type tactic = thm -> thm Seq.seq"} |
|
152 |
||
99 | 153 |
It is custom that if a tactic fails, it should return the empty sequence: |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
154 |
therefore your own tactics should not raise exceptions willy-nilly. Only |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
155 |
in very grave failure situations should a tactic raise the exception |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
156 |
@{text THM}. |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
157 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
158 |
The simplest tactics are @{ML no_tac} and @{ML all_tac}. The first returns |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
159 |
the empty sequence and is defined as |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
160 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
161 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
162 |
ML{*fun no_tac thm = Seq.empty*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
163 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
164 |
text {* |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
165 |
which means @{ML no_tac} always fails. The second returns the given theorem wrapped |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
166 |
as a single member sequence; @{ML all_tac} is defined as |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
167 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
168 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
169 |
ML{*fun all_tac thm = Seq.single thm*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
170 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
171 |
text {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
172 |
which means it always succeeds (but also does not make any progress |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
173 |
with the proof). |
93 | 174 |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
175 |
The lazy list of possible successor states shows through at the user-level |
99 | 176 |
of Isabelle when using the command \isacommand{back}. For instance in the |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
177 |
following proof there are two possibilities for how to apply |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
178 |
@{ML foo_tac'}: either using the first assumption or the second. |
93 | 179 |
*} |
180 |
||
181 |
lemma "\<lbrakk>P \<or> Q; P \<or> Q\<rbrakk> \<Longrightarrow> Q \<or> P" |
|
182 |
apply(tactic {* foo_tac' 1 *}) |
|
183 |
back |
|
184 |
done |
|
185 |
||
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
186 |
|
93 | 187 |
text {* |
99 | 188 |
By using \isacommand{back}, we construct the proof that uses the |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
189 |
second assumption. In more interesting situations, only by exploring |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
190 |
different possibilities one might be able to find a proof. |
99 | 191 |
|
93 | 192 |
\begin{readmore} |
193 |
See @{ML_file "Pure/General/seq.ML"} for the implementation of lazy |
|
194 |
sequences. However in day-to-day Isabelle programming, one rarely |
|
195 |
constructs sequences explicitly, but uses the predefined functions |
|
99 | 196 |
instead. |
93 | 197 |
\end{readmore} |
198 |
||
104 | 199 |
It might be surprising that tactics, which transform |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
200 |
one proof state to the next, are functions from theorems to theorem |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
201 |
(sequences). The surprise resolves by knowing that every |
104 | 202 |
goal state is indeed a theorem. To shed more light on this, |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
203 |
let us modify the code of @{ML all_tac} to obtain the following |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
204 |
tactic |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
205 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
206 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
207 |
ML{*fun my_print_tac ctxt thm = |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
208 |
let |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
209 |
val _ = warning (str_of_thm ctxt thm) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
210 |
in |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
211 |
Seq.single thm |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
212 |
end*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
213 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
214 |
text {* |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
215 |
which prints out the given theorem (using the string-function defined |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
216 |
in Section~\ref{sec:printing}) and then behaves like @{ML all_tac}. We |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
217 |
are now in the position to inspect every goal state in a proof. Consider |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
218 |
the proof below: on the left-hand side we show the goal state as shown |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
219 |
by Isabelle, on the right-hand side the print out from @{ML my_print_tac}. |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
220 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
221 |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
222 |
lemma shows "\<lbrakk>A; B\<rbrakk> \<Longrightarrow> A \<and> B" |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
223 |
apply(tactic {* my_print_tac @{context} *}) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
224 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
225 |
txt{* \small |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
226 |
\begin{tabularstar}{\textwidth}{@ {}l@ {\extracolsep{\fill}}l@ {}} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
227 |
\begin{minipage}[t]{0.3\textwidth} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
228 |
@{subgoals [display]} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
229 |
\end{minipage} & |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
230 |
@{text "(\<lbrakk>A; B\<rbrakk> \<Longrightarrow> A \<and> B) \<Longrightarrow> (\<lbrakk>A; B\<rbrakk> \<Longrightarrow> A \<and> B)"} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
231 |
\end{tabularstar} |
93 | 232 |
*} |
233 |
||
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
234 |
apply(rule conjI) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
235 |
apply(tactic {* my_print_tac @{context} *}) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
236 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
237 |
txt{* \small |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
238 |
\begin{tabularstar}{\textwidth}{@ {}l@ {\extracolsep{\fill}}l@ {}} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
239 |
\begin{minipage}[t]{0.26\textwidth} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
240 |
@{subgoals [display]} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
241 |
\end{minipage} & |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
242 |
@{text "(\<lbrakk>A; B\<rbrakk> \<Longrightarrow> A) \<Longrightarrow> (\<lbrakk>A; B\<rbrakk> \<Longrightarrow> B) \<Longrightarrow> (\<lbrakk>A; B\<rbrakk> \<Longrightarrow> A \<and> B)"} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
243 |
\end{tabularstar} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
244 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
245 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
246 |
apply(assumption) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
247 |
apply(tactic {* my_print_tac @{context} *}) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
248 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
249 |
txt{* \small |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
250 |
\begin{tabularstar}{\textwidth}{@ {}l@ {\extracolsep{\fill}}l@ {}} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
251 |
\begin{minipage}[t]{0.3\textwidth} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
252 |
@{subgoals [display]} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
253 |
\end{minipage} & |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
254 |
@{text "(\<lbrakk>A; B\<rbrakk> \<Longrightarrow> B) \<Longrightarrow> (\<lbrakk>A; B\<rbrakk> \<Longrightarrow> A \<and> B)"} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
255 |
\end{tabularstar} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
256 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
257 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
258 |
apply(assumption) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
259 |
apply(tactic {* my_print_tac @{context} *}) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
260 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
261 |
txt{* \small |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
262 |
\begin{tabularstar}{\textwidth}{@ {}l@ {\extracolsep{\fill}}l@ {}} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
263 |
\begin{minipage}[t]{0.3\textwidth} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
264 |
@{subgoals [display]} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
265 |
\end{minipage} & |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
266 |
@{text "\<lbrakk>A; B\<rbrakk> \<Longrightarrow> A \<and> B"} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
267 |
\end{tabularstar} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
268 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
269 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
270 |
done |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
271 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
272 |
text {* |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
273 |
As can be seen, internally every goal state is an implication of the form |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
274 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
275 |
@{text[display] "A\<^isub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^isub>n \<Longrightarrow> (C)"} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
276 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
277 |
where @{term C} is the goal to be proved and the @{term "A\<^isub>i"} are the |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
278 |
subgoals. So after setting up the lemma, the goal state is always of the form |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
279 |
@{text "C \<Longrightarrow> (C)"}; when the proof is finished we are left with @{text "(C)"}. |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
280 |
Since the goal @{term C} can potentially be an implication, |
104 | 281 |
there is a ``protector'' wrapped around it (in from of an outermost constant |
282 |
@{text "Const (\"prop\", bool \<Rightarrow> bool)"} applied to each goal; |
|
283 |
however this constant is invisible in the print out above). This |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
284 |
prevents that premises of @{text C} are mis-interpreted as open subgoals. |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
285 |
While tactics can operate on the subgoals (the @{text "A\<^isub>i"} above), they |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
286 |
are expected to leave the conclusion @{term C} intact, with the |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
287 |
exception of possibly instantiating schematic variables. If you use |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
288 |
the predefined tactics, this will always be the case. |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
289 |
|
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
290 |
\begin{readmore} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
291 |
For more information about the internals of goals see \isccite{sec:tactical-goals}. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
292 |
\end{readmore} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
293 |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
294 |
*} |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
295 |
|
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
296 |
section {* Simple Tactics *} |
93 | 297 |
|
99 | 298 |
text {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
299 |
A simple tactic is @{ML print_tac}, which is quite useful for low-level debugging of tactics. |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
300 |
It just prints out a message and the current goal state. |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
301 |
*} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
302 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
303 |
lemma shows "False \<Longrightarrow> True" |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
304 |
apply(tactic {* print_tac "foo message" *}) |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
305 |
txt{*\begin{minipage}{\textwidth}\small |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
306 |
@{text "foo message"}\\[3mm] |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
307 |
@{prop "False \<Longrightarrow> True"}\\ |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
308 |
@{text " 1. False \<Longrightarrow> True"}\\ |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
309 |
\end{minipage} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
310 |
*} |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
311 |
(*<*)oops(*>*) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
312 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
313 |
text {* |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
314 |
Another simple tactic is the function @{ML atac}, which, as shown in the previous |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
315 |
section, corresponds to the assumption command. |
99 | 316 |
*} |
317 |
||
318 |
lemma shows "P \<Longrightarrow> P" |
|
93 | 319 |
apply(tactic {* atac 1 *}) |
320 |
done |
|
321 |
||
99 | 322 |
text {* |
323 |
Similarly, @{ML rtac}, @{ML dtac}, @{ML etac} and @{ML ftac} correspond |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
324 |
to @{text rule}, @{text drule}, @{text erule} and @{text frule}, |
104 | 325 |
respectively. Each of them takes a theorem as argument. Below are three |
326 |
examples with the resulting goal state. How |
|
327 |
they work should be self-explanatory. |
|
99 | 328 |
*} |
329 |
||
330 |
lemma shows "P \<and> Q" |
|
93 | 331 |
apply(tactic {* rtac @{thm conjI} 1 *}) |
104 | 332 |
txt{*\begin{minipage}{\textwidth} |
333 |
@{subgoals [display]} |
|
334 |
\end{minipage}*} |
|
93 | 335 |
(*<*)oops(*>*) |
336 |
||
99 | 337 |
lemma shows "P \<and> Q \<Longrightarrow> False" |
93 | 338 |
apply(tactic {* etac @{thm conjE} 1 *}) |
104 | 339 |
txt{*\begin{minipage}{\textwidth} |
340 |
@{subgoals [display]} |
|
341 |
\end{minipage}*} |
|
93 | 342 |
(*<*)oops(*>*) |
343 |
||
344 |
lemma shows "False \<and> True \<Longrightarrow> False" |
|
345 |
apply(tactic {* dtac @{thm conjunct2} 1 *}) |
|
104 | 346 |
txt{*\begin{minipage}{\textwidth} |
347 |
@{subgoals [display]} |
|
348 |
\end{minipage}*} |
|
93 | 349 |
(*<*)oops(*>*) |
350 |
||
351 |
text {* |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
352 |
As mentioned in the previous section, most basic tactics take a number as |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
353 |
argument, which addresses the subgoal they are analysing. In the proof below, |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
354 |
we first analyse the second subgoal by focusing on this subgoal first. |
99 | 355 |
*} |
356 |
||
357 |
lemma shows "Foo" and "P \<and> Q" |
|
358 |
apply(tactic {* rtac @{thm conjI} 2 *}) |
|
104 | 359 |
txt {*\begin{minipage}{\textwidth} |
360 |
@{subgoals [display]} |
|
361 |
\end{minipage}*} |
|
99 | 362 |
(*<*)oops(*>*) |
363 |
||
364 |
text {* |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
365 |
The function @{ML resolve_tac} is similar to @{ML rtac}, except that it |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
366 |
expects a list of theorems as arguments. From this list it will apply the |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
367 |
first applicable theorem (later theorems that are also applicable can be |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
368 |
explored via the lazy sequences mechanism). Given the code |
93 | 369 |
*} |
370 |
||
99 | 371 |
ML{*val resolve_tac_xmp = resolve_tac [@{thm impI}, @{thm conjI}]*} |
372 |
||
373 |
text {* |
|
374 |
an example for @{ML resolve_tac} is the following proof where first an outermost |
|
375 |
implication is analysed and then an outermost conjunction. |
|
376 |
*} |
|
377 |
||
378 |
lemma shows "C \<longrightarrow> (A \<and> B)" and "(A \<longrightarrow> B) \<and> C" |
|
379 |
apply(tactic {* resolve_tac_xmp 1 *}) |
|
380 |
apply(tactic {* resolve_tac_xmp 2 *}) |
|
104 | 381 |
txt{*\begin{minipage}{\textwidth} |
382 |
@{subgoals [display]} |
|
383 |
\end{minipage}*} |
|
99 | 384 |
(*<*)oops(*>*) |
385 |
||
386 |
text {* |
|
387 |
Similarly versions exists for @{ML atac} (@{ML assume_tac}), @{ML etac} |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
388 |
(@{ML eresolve_tac}) and so on. |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
389 |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
390 |
Another simple tactic is @{ML cut_facts_tac}. It inserts a list of theorems |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
391 |
into the assumptions of the current goal state. For example: |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
392 |
*} |
99 | 393 |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
394 |
lemma shows "True \<noteq> False" |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
395 |
apply(tactic {* cut_facts_tac [@{thm True_def}, @{thm False_def}] 1 *}) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
396 |
txt{*\begin{minipage}{\textwidth} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
397 |
@{subgoals [display]} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
398 |
\end{minipage}*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
399 |
(*<*)oops(*>*) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
400 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
401 |
text {* |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
402 |
Since rules are applied using higher-order unification, an automatic proof |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
403 |
procedure might become too fragile, if it just applies inference rules as |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
404 |
shown above. The reason is that a number of rules introduce meta-variables |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
405 |
into the goal state. Consider for example the proof |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
406 |
*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
407 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
408 |
lemma shows "\<forall>x\<in>A. P x \<Longrightarrow> Q x" |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
409 |
apply(drule bspec) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
410 |
txt{*\begin{minipage}{\textwidth} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
411 |
@{subgoals [display]} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
412 |
\end{minipage}*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
413 |
(*<*)oops(*>*) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
414 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
415 |
text {* |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
416 |
where the application of @{text bspec} results into two subgoals involving the |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
417 |
meta-variable @{text "?x"}. The point is that if you are not careful, tactics |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
418 |
applied to the first subgoal might instantiate this meta-variable in such a |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
419 |
way that the second subgoal becomes unprovable. If it is clear what the @{text "?x"} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
420 |
should be, then this situation can be avoided by introducing a more |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
421 |
constraint version of the @{text bspec}-rule. Such constraints can be enforced by |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
422 |
pre-instantiating theorems with other theorems, for example by using the |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
423 |
function @{ML RS} |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
424 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
425 |
@{ML_response_fake [display,gray] |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
426 |
"@{thm disjI1} RS @{thm conjI}" "\<lbrakk>?P1; ?Q\<rbrakk> \<Longrightarrow> (?P1 \<or> ?Q1) \<and> ?Q"} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
427 |
|
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
428 |
which, for instance, instantiates the first premise of the @{text conjI}-rule |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
429 |
with the rule @{text disjI1}. If this is impossible, as in the case of |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
430 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
431 |
@{ML_response_fake_both [display,gray] |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
432 |
"@{thm conjI} RS @{thm mp}" |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
433 |
"*** Exception- THM (\"RSN: no unifiers\", 1, |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
434 |
[\"\<lbrakk>?P; ?Q\<rbrakk> \<Longrightarrow> ?P \<and> ?Q\", \"\<lbrakk>?P \<longrightarrow> ?Q; ?P\<rbrakk> \<Longrightarrow> ?Q\"]) raised"} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
435 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
436 |
the function raises an exception. The function @{ML RSN} is similar, but |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
437 |
takes a number as argument and thus you can make explicit which premise |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
438 |
should be instantiated. |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
439 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
440 |
To improve readability of the theorems we produce below, we shall use |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
441 |
the following function |
99 | 442 |
*} |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
443 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
444 |
ML{*fun no_vars ctxt thm = |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
445 |
let |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
446 |
val ((_, [thm']), _) = Variable.import_thms true [thm] ctxt |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
447 |
in |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
448 |
thm' |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
449 |
end*} |
93 | 450 |
|
99 | 451 |
text {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
452 |
that transform the schematic variables of a theorem into free variables. |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
453 |
This means for the first @{ML RS}-expression above: |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
454 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
455 |
@{ML_response_fake [display,gray] |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
456 |
"no_vars @{context} (@{thm disjI1} RS @{thm conjI})" "\<lbrakk>P; Q\<rbrakk> \<Longrightarrow> (P \<or> Qa) \<and> Q"} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
457 |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
458 |
If you want to instantiate more than one premise of a theorem, you can use |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
459 |
the function @{ML MRS}: |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
460 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
461 |
@{ML_response_fake [display,gray] |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
462 |
"no_vars @{context} ([@{thm disjI1}, @{thm disjI2}] MRS @{thm conjI})" |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
463 |
"\<lbrakk>P; Q\<rbrakk> \<Longrightarrow> (P \<or> Qa) \<and> (Pa \<or> Q)"} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
464 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
465 |
If you need to instantiate lists of theorems, you can use the |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
466 |
functions @{ML RL} and @{ML MRL}. For example in the code below |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
467 |
every theorem in the first list is instantiated against every |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
468 |
theorem in the second. |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
469 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
470 |
@{ML_response_fake [display,gray] |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
471 |
"[@{thm impI}, @{thm disjI2}] RL [@{thm conjI}, @{thm disjI1}]" |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
472 |
"[\<lbrakk>P \<Longrightarrow> Q; Qa\<rbrakk> \<Longrightarrow> (P \<longrightarrow> Q) \<and> Qa, |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
473 |
\<lbrakk>Q; Qa\<rbrakk> \<Longrightarrow> (P \<or> Q) \<and> Qa, |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
474 |
(P \<Longrightarrow> Q) \<Longrightarrow> (P \<longrightarrow> Q) \<or> Qa, |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
475 |
Q \<Longrightarrow> (P \<or> Q) \<or> Qa]"} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
476 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
477 |
\begin{readmore} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
478 |
The combinators for instantiating theorems are defined in @{ML_file "Pure/drule.ML"}. |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
479 |
\end{readmore} |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
480 |
|
104 | 481 |
Often proofs involve elaborate operations on assumptions and |
482 |
@{text "\<And>"}-quantified variables. To do such operations on the ML-level |
|
483 |
using the basic tactics is very unwieldy and brittle. Some convenience and |
|
99 | 484 |
safety is provided by the tactic @{ML SUBPROOF}. This tactic fixes the parameters |
485 |
and binds the various components of a proof state into a record. |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
486 |
To see what happens, assume the function defined in Figure~\ref{fig:sptac}, which |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
487 |
takes a record as argument and just prints out the content of this record (using the |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
488 |
string transformation functions defined in Section~\ref{sec:printing}). Consider |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
489 |
now the proof |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
490 |
*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
491 |
|
99 | 492 |
text_raw{* |
493 |
\begin{figure} |
|
494 |
\begin{isabelle} |
|
495 |
*} |
|
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
496 |
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
|
497 |
let |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
498 |
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
|
499 |
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
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
504 |
val _ = (warning ("params: " ^ str_of_params); |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
505 |
warning ("schematics: " ^ str_of_schms); |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
506 |
warning ("assumptions: " ^ str_of_asms); |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
507 |
warning ("conclusion: " ^ str_of_concl); |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
508 |
warning ("premises: " ^ str_of_prems)) |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
509 |
in |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
510 |
no_tac |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
511 |
end*} |
99 | 512 |
text_raw{* |
513 |
\end{isabelle} |
|
514 |
\caption{A function that prints out the various parameters provided by the tactic |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
515 |
@{ML SUBPROOF}. It uses the functions defined in Section~\ref{sec:printing} for |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
516 |
extracting strings from @{ML_type cterm}s and @{ML_type thm}s.\label{fig:sptac}} |
99 | 517 |
\end{figure} |
518 |
*} |
|
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
519 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
520 |
|
99 | 521 |
lemma shows "\<And>x y. A x y \<Longrightarrow> B y x \<longrightarrow> C (?z y) x" |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
522 |
apply(tactic {* SUBPROOF sp_tac @{context} 1 *})? |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
523 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
524 |
txt {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
525 |
which gives the printout: |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
526 |
|
99 | 527 |
\begin{quote}\small |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
528 |
\begin{tabular}{ll} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
529 |
params: & @{term x}, @{term y}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
530 |
schematics: & @{term z}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
531 |
assumptions: & @{term "A x y"}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
532 |
conclusion: & @{term "B y x \<longrightarrow> C (z y) x"}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
533 |
premises: & @{term "A x y"} |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
534 |
\end{tabular} |
99 | 535 |
\end{quote} |
536 |
||
537 |
Note in the actual output the brown colour of the variables @{term x} and |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
538 |
@{term y}. Although they are parameters in the original goal, they are fixed inside |
99 | 539 |
the subproof. Similarly the schematic variable @{term z}. The assumption |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
540 |
@{prop "A x y"} is bound as @{ML_type cterm} to the record-variable |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
541 |
@{text asms} but also as @{ML_type thm} to @{text prems}. |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
542 |
|
99 | 543 |
Notice also that we had to append @{text "?"} to \isacommand{apply}. The |
544 |
reason is that @{ML SUBPROOF} normally expects that the subgoal is solved completely. |
|
545 |
Since in the function @{ML sp_tac} we returned the tactic @{ML no_tac}, the subproof |
|
546 |
obviously fails. The question-mark allows us to recover from this failure |
|
547 |
in a graceful manner so that the warning messages are not overwritten |
|
104 | 548 |
by an error message. |
99 | 549 |
|
550 |
If we continue the proof script by applying the @{text impI}-rule |
|
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
551 |
*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
552 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
553 |
apply(rule impI) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
554 |
apply(tactic {* SUBPROOF sp_tac @{context} 1 *})? |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
555 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
556 |
txt {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
557 |
then @{ML sp_tac} prints out |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
558 |
|
99 | 559 |
\begin{quote}\small |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
560 |
\begin{tabular}{ll} |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
561 |
params: & @{term x}, @{term y}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
562 |
schematics: & @{term z}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
563 |
assumptions: & @{term "A x y"}, @{term "B y x"}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
564 |
conclusion: & @{term "C (z y) x"}\\ |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
565 |
premises: & @{term "A x y"}, @{term "B y x"} |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
566 |
\end{tabular} |
99 | 567 |
\end{quote} |
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
568 |
*} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
569 |
(*<*)oops(*>*) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
570 |
|
99 | 571 |
text {* |
104 | 572 |
where we now also have @{term "B y x"} as an assumption. |
99 | 573 |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
574 |
One convenience of @{ML SUBPROOF} is that we can apply the assumptions |
99 | 575 |
using the usual tactics, because the parameter @{text prems} |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
576 |
contains them as theorems. With this we can easily |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
577 |
implement a tactic that almost behaves like @{ML atac}, namely: |
99 | 578 |
*} |
579 |
||
104 | 580 |
ML{*val atac' = SUBPROOF (fn {prems, ...} => resolve_tac prems 1)*} |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
581 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
582 |
text {* |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
583 |
If we apply it to the next lemma |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
584 |
*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
585 |
|
99 | 586 |
lemma shows "\<And>x y. \<lbrakk>B x y; A x y; C x y\<rbrakk> \<Longrightarrow> A x y" |
104 | 587 |
apply(tactic {* atac' @{context} 1 *}) |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
588 |
txt{* we get |
99 | 589 |
@{subgoals [display]} *} |
590 |
(*<*)oops(*>*) |
|
591 |
||
104 | 592 |
text {* |
593 |
The restriction in this tactic is that it cannot instantiate any |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
594 |
schematic variable. This might be seen as a defect, but it is actually |
104 | 595 |
an advantage in the situations for which @{ML SUBPROOF} was designed: |
596 |
the reason is that instantiation of schematic variables can affect |
|
597 |
several goals and can render them unprovable. @{ML SUBPROOF} is meant |
|
598 |
to avoid this. |
|
599 |
||
600 |
Notice that @{ML atac'} calls @{ML resolve_tac} with the subgoal |
|
601 |
number @{text "1"} and also the ``outer'' call to @{ML SUBPROOF} in |
|
602 |
the \isacommand{apply}-step uses @{text "1"}. Another advantage |
|
603 |
of @{ML SUBGOAL} is that the addressing inside it is completely |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
604 |
local to the subproof inside. It is therefore possible to also apply |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
605 |
@{ML atac'} to the second goal by just writing: |
104 | 606 |
*} |
607 |
||
608 |
lemma shows "True" and "\<And>x y. \<lbrakk>B x y; A x y; C x y\<rbrakk> \<Longrightarrow> A x y" |
|
609 |
apply(tactic {* atac' @{context} 2 *}) |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
610 |
apply(rule TrueI) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
611 |
done |
104 | 612 |
|
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
613 |
|
93 | 614 |
text {* |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
615 |
\begin{readmore} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
616 |
The function @{ML SUBPROOF} is defined in @{ML_file "Pure/subgoal.ML"} and |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
617 |
also described in \isccite{sec:results}. |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
618 |
\end{readmore} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
619 |
|
104 | 620 |
A similar but less powerful function than @{ML SUBPROOF} is @{ML SUBGOAL}. |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
621 |
It allows you to inspect a given subgoal. With this you can implement |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
622 |
a tactic that applies a rule according to the topmost connective in the |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
623 |
subgoal (to illustrate this we only analyse a few connectives). The code |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
624 |
of this tactic is as follows.\label{tac:selecttac} |
93 | 625 |
*} |
626 |
||
99 | 627 |
ML %linenumbers{*fun select_tac (t,i) = |
628 |
case t of |
|
629 |
@{term "Trueprop"} $ t' => select_tac (t',i) |
|
630 |
| @{term "op \<and>"} $ _ $ _ => rtac @{thm conjI} i |
|
631 |
| @{term "op \<longrightarrow>"} $ _ $ _ => rtac @{thm impI} i |
|
632 |
| @{term "Not"} $ _ => rtac @{thm notI} i |
|
633 |
| Const (@{const_name "All"}, _) $ _ => rtac @{thm allI} i |
|
104 | 634 |
| _ => all_tac*} |
99 | 635 |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
636 |
text {* |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
637 |
In line 3 you need to descend under the outermost @{term "Trueprop"} in order |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
638 |
to get to the connective you like to analyse. Otherwise goals like @{prop "A \<and> B"} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
639 |
are not properly analysed. While for the first four pattern we can use the |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
640 |
@{text "@term"}-antiquotation, the pattern in Line 7 cannot be constructed |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
641 |
in this way. The reason is that an antiquotation would fix the type of the |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
642 |
quantified variable. So you really have to construct the pattern |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
643 |
using the term-constructors. This is not necessary in other cases, because |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
644 |
their type is always something involving @{typ bool}. The final patter is |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
645 |
for the case where the goal does not fall into any of the categories before. |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
646 |
In this case we chose to just return @{ML all_tac} (i.e., @{ML select_tac} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
647 |
never fails). |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
648 |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
649 |
Let us now see how to apply this tactic. Consider the four goals: |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
650 |
*} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
651 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
652 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
653 |
lemma shows "A \<and> B" and "A \<longrightarrow> B \<longrightarrow>C" and "\<forall>x. D x" and "E \<Longrightarrow> F" |
104 | 654 |
apply(tactic {* SUBGOAL select_tac 4 *}) |
655 |
apply(tactic {* SUBGOAL select_tac 3 *}) |
|
656 |
apply(tactic {* SUBGOAL select_tac 2 *}) |
|
99 | 657 |
apply(tactic {* SUBGOAL select_tac 1 *}) |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
658 |
txt{* \begin{minipage}{\textwidth} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
659 |
@{subgoals [display]} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
660 |
\end{minipage} *} |
99 | 661 |
(*<*)oops(*>*) |
662 |
||
663 |
text {* |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
664 |
where in all but the last the tactic applied an introduction rule. |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
665 |
Note that we applied the tactic to subgoals in ``reverse'' order. |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
666 |
This is a trick in order to be independent from what subgoals are |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
667 |
that are produced by the rule. If we had applied it in the other order |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
668 |
*} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
669 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
670 |
lemma shows "A \<and> B" and "A \<longrightarrow> B \<longrightarrow>C" and "\<forall>x. D x" and "E \<Longrightarrow> F" |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
671 |
apply(tactic {* SUBGOAL select_tac 1 *}) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
672 |
apply(tactic {* SUBGOAL select_tac 3 *}) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
673 |
apply(tactic {* SUBGOAL select_tac 4 *}) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
674 |
apply(tactic {* SUBGOAL select_tac 5 *}) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
675 |
(*<*)oops(*>*) |
99 | 676 |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
677 |
text {* |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
678 |
then we have to be careful to not apply the tactic to the two subgoals the |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
679 |
first goal produced. To do this can result in quite messy code. In contrast, |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
680 |
the ``reverse application'' is easy to implement. |
104 | 681 |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
682 |
However, this example is very contrived: there are much simpler methods to implement |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
683 |
such a proof procedure analysing a goal according to its topmost |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
684 |
connective. These simpler methods use tactic combinators which will be explained |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
685 |
in the next section. |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
686 |
*} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
687 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
688 |
section {* Tactic Combinators *} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
689 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
690 |
text {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
691 |
The purpose of tactic combinators is to build powerful tactics out of |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
692 |
smaller components. In the previous section we already used @{ML THEN}, which |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
693 |
strings two tactics together in sequence. For example: |
93 | 694 |
*} |
695 |
||
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
696 |
lemma shows "(Foo \<and> Bar) \<and> False" |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
697 |
apply(tactic {* rtac @{thm conjI} 1 THEN rtac @{thm conjI} 1 *}) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
698 |
txt {* \begin{minipage}{\textwidth} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
699 |
@{subgoals [display]} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
700 |
\end{minipage} *} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
701 |
(*<*)oops(*>*) |
99 | 702 |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
703 |
text {* |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
704 |
If you want to avoid the hard-coded subgoal addressing, then you can use |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
705 |
the ``primed'' version of @{ML THEN}. For example: |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
706 |
*} |
93 | 707 |
|
99 | 708 |
lemma shows "(Foo \<and> Bar) \<and> False" |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
709 |
apply(tactic {* (rtac @{thm conjI} THEN' rtac @{thm conjI}) 1 *}) |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
710 |
txt {* \begin{minipage}{\textwidth} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
711 |
@{subgoals [display]} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
712 |
\end{minipage} *} |
93 | 713 |
(*<*)oops(*>*) |
714 |
||
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
715 |
text {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
716 |
For most tactic combinators such a ``primed'' version exists and |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
717 |
in what follows we will usually prefer it over the ``unprimed'' one. |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
718 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
719 |
If there is a list of tactics that should all be tried out in |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
720 |
sequence, you can use the combinator @{ML EVERY'}. For example |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
721 |
the function @{ML foo_tac'} from page~\ref{tac:footacprime} can also |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
722 |
be written as: |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
723 |
*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
724 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
725 |
ML{*val foo_tac'' = EVERY' [etac @{thm disjE}, rtac @{thm disjI2}, |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
726 |
atac, rtac @{thm disjI1}, atac]*} |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
727 |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
728 |
text {* |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
729 |
There is even another way: in automatic proof procedures (in contrast to |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
730 |
tactics that might be called by the user) there are often long lists of |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
731 |
tactics that are applied to the first subgoal. Instead of writing the code |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
732 |
above and then calling @{ML "foo_tac'' 1"}, you can also just write |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
733 |
*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
734 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
735 |
ML{*val foo_tac1 = EVERY1 [etac @{thm disjE}, rtac @{thm disjI2}, |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
736 |
atac, rtac @{thm disjI1}, atac]*} |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
737 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
738 |
text {* |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
739 |
With the combinators @{ML THEN'}, @{ML EVERY'} and @{ML EVERY1} it must be |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
740 |
guaranteed that all component tactics successfully apply; otherwise the |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
741 |
whole tactic will fail. If you rather want to try out a number of tactics, |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
742 |
then you can use the combinator @{ML ORELSE'} for two tactics, and @{ML FIRST'} |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
743 |
(or @{ML FIRST1}) for a list of tactics. For example, the tactic |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
744 |
*} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
745 |
|
99 | 746 |
ML{*val orelse_xmp = (rtac @{thm disjI1} ORELSE' rtac @{thm conjI})*} |
747 |
||
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
748 |
text {* |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
749 |
will first try out whether rule @{text disjI} applies and after that |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
750 |
whether @{text conjI}. To see this consider the proof: |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
751 |
*} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
752 |
|
99 | 753 |
lemma shows "True \<and> False" and "Foo \<or> Bar" |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
754 |
apply(tactic {* orelse_xmp 2 *}) |
99 | 755 |
apply(tactic {* orelse_xmp 1 *}) |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
756 |
txt {* which results in the goal state |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
757 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
758 |
\begin{minipage}{\textwidth} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
759 |
@{subgoals [display]} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
760 |
\end{minipage} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
761 |
*} |
93 | 762 |
(*<*)oops(*>*) |
763 |
||
764 |
||
765 |
text {* |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
766 |
Using @{ML FIRST'} we can write our @{ML select_tac} from Page~\ref{tac:selecttac} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
767 |
simply as follows: |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
768 |
*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
769 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
770 |
ML{*val select_tac' = FIRST' [rtac @{thm conjI}, rtac @{thm impI}, |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
771 |
rtac @{thm notI}, rtac @{thm allI}, K all_tac]*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
772 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
773 |
text {* |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
774 |
Since we like to mimic the behaviour of @{ML select_tac} as closely as possible, |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
775 |
we must include @{ML all_tac} at the end of the list (@{ML all_tac} must also |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
776 |
be ``wrapped up'' using the @{ML K}-combinator, as it does not take a subgoal |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
777 |
number as argument). We can test the tactic on the same proof: |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
778 |
*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
779 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
780 |
lemma shows "A \<and> B" and "A \<longrightarrow> B \<longrightarrow>C" and "\<forall>x. D x" and "E \<Longrightarrow> F" |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
781 |
apply(tactic {* select_tac' 4 *}) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
782 |
apply(tactic {* select_tac' 3 *}) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
783 |
apply(tactic {* select_tac' 2 *}) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
784 |
apply(tactic {* select_tac' 1 *}) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
785 |
txt{* \begin{minipage}{\textwidth} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
786 |
@{subgoals [display]} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
787 |
\end{minipage} *} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
788 |
(*<*)oops(*>*) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
789 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
790 |
text {* |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
791 |
Because such repeated applications of a tactic to the reverse order of |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
792 |
\emph{all} subgoals is quite common, there is the tactics combinator |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
793 |
@{ML ALLGOALS} that simplifies this. Using this combinator we can simply |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
794 |
write: *} |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
795 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
796 |
lemma shows "A \<and> B" and "A \<longrightarrow> B \<longrightarrow>C" and "\<forall>x. D x" and "E \<Longrightarrow> F" |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
797 |
apply(tactic {* ALLGOALS select_tac' *}) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
798 |
txt{* \begin{minipage}{\textwidth} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
799 |
@{subgoals [display]} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
800 |
\end{minipage} *} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
801 |
(*<*)oops(*>*) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
802 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
803 |
text {* |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
804 |
Remember that we chose to write @{ML select_tac'} in such a way that it always |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
805 |
succeeds. This can be potentially very confusing for the user, for example, |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
806 |
in cases the goals is the form |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
807 |
*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
808 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
809 |
lemma shows "E \<Longrightarrow> F" |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
810 |
apply(tactic {* select_tac' 1 *}) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
811 |
txt{* \begin{minipage}{\textwidth} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
812 |
@{subgoals [display]} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
813 |
\end{minipage} *} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
814 |
(*<*)oops(*>*) |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
815 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
816 |
text {* |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
817 |
where no rule applies. The reason is that the user has little chance |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
818 |
to see whether progress in the proof has been made or not. We could simply |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
819 |
delete th @{ML "K all_tac"} from the end of the list. Then @{ML select_tac'} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
820 |
would only succeed on goals where it can make progress. But for the sake of |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
821 |
argument, let us suppose that this deletion is not an option. In such cases, you |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
822 |
can use the combinator @{ML CHANGED} to make sure the subgoal has been |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
823 |
changed by the tactic. Because now |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
824 |
*} |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
825 |
|
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
826 |
lemma shows "E \<Longrightarrow> F" |
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
827 |
apply(tactic {* CHANGED (select_tac' 1) *})(*<*)?(*>*) |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
828 |
txt{* results in the error message: |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
829 |
\begin{isabelle} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
830 |
@{text "*** empty result sequence -- proof command failed"}\\ |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
831 |
@{text "*** At command \"apply\"."} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
832 |
\end{isabelle} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
833 |
*}(*<*)oops(*>*) |
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
834 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
835 |
|
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
836 |
text {* |
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
837 |
Meaning the tactic failed. |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
838 |
|
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
839 |
We can extend @{ML select_tac'} so that it not just applies to the top-most |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
840 |
connective, but also to the ones immediately ``underneath''. For this you can use the |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
841 |
tactic combinator @{ML REPEAT}. For example suppose the following tactic |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
842 |
*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
843 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
844 |
ML{*val repeat_xmp = REPEAT (CHANGED (select_tac' 1)) *} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
845 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
846 |
text {* and the proof *} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
847 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
848 |
lemma shows "((\<not>A) \<and> (\<forall>x. B x)) \<and> (C \<longrightarrow> D)" |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
849 |
apply(tactic {* repeat_xmp *}) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
850 |
txt{* \begin{minipage}{\textwidth} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
851 |
@{subgoals [display]} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
852 |
\end{minipage} *} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
853 |
(*<*)oops(*>*) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
854 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
855 |
text {* |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
856 |
Here it is crucial that @{ML select_tac'} is prefixed with @{ML CHANGED}, |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
857 |
because otherwise @{ML REPEAT} runs into an infinite loop. The function |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
858 |
@{ML REPEAT1} is similar, but runs the tactic at least once (failing if |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
859 |
this is not possible). |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
860 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
861 |
If you are after the ``primed'' version of @{ML repeat_xmp} then it |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
862 |
needs to be coded as |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
863 |
*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
864 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
865 |
ML{*val repeat_xmp' = REPEAT o CHANGED o select_tac'*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
866 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
867 |
text {* |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
868 |
since there are no ``primed'' versions of @{ML REPEAT} and @{ML CHANGED}. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
869 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
870 |
If you look closely at the goal state above, the tactics @{ML repeat_xmp} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
871 |
and @{ML repeat_xmp'} are not yet quite what we are after: the problem is |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
872 |
that goals 2 and 3 are not yet analysed. This is because both tactics |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
873 |
apply repeatedly only to the first subgoal. To analyse also all |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
874 |
resulting subgoals, you can use the function @{ML REPEAT_ALL_NEW}. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
875 |
Suppose the tactic |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
876 |
*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
877 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
878 |
ML{*val repeat_all_new_xmp = REPEAT_ALL_NEW (CHANGED o select_tac')*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
879 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
880 |
text {* |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
881 |
which analyses the topmost connectives also in all resulting |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
882 |
subgoals. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
883 |
*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
884 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
885 |
lemma shows "((\<not>A) \<and> (\<forall>x. B x)) \<and> (C \<longrightarrow> D)" |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
886 |
apply(tactic {* repeat_all_new_xmp 1 *}) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
887 |
txt{* \begin{minipage}{\textwidth} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
888 |
@{subgoals [display]} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
889 |
\end{minipage} *} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
890 |
(*<*)oops(*>*) |
93 | 891 |
|
108
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
892 |
text {* |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
893 |
The last tactic combinator we describe here is @{ML DETERM}. Recall |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
894 |
that tactics produce a lazy sequence of successor goal states. These |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
895 |
states can be explored using the command \isacommand{back}. For example |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
896 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
897 |
*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
898 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
899 |
lemma "\<lbrakk>P1 \<or> Q1; P2 \<or> Q2\<rbrakk> \<Longrightarrow> R" |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
900 |
apply(tactic {* etac @{thm disjE} 1 *}) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
901 |
txt{* applies the rule to the first assumption |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
902 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
903 |
\begin{minipage}{\textwidth} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
904 |
@{subgoals [display]} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
905 |
\end{minipage} *} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
906 |
(*<*) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
907 |
oops |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
908 |
lemma "\<lbrakk>P1 \<or> Q1; P2 \<or> Q2\<rbrakk> \<Longrightarrow> R" |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
909 |
apply(tactic {* etac @{thm disjE} 1 *}) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
910 |
(*>*) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
911 |
back |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
912 |
txt{* whereas it is now applied to the second |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
913 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
914 |
\begin{minipage}{\textwidth} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
915 |
@{subgoals [display]} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
916 |
\end{minipage} *} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
917 |
(*<*)oops(*>*) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
918 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
919 |
text {* |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
920 |
Sometimes this leads to confusing behaviour of tactics and also has |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
921 |
the potential to explode the search space for tactics build on top. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
922 |
This can be avoided by prefixing the tactic with @{ML DETERM}. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
923 |
*} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
924 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
925 |
lemma "\<lbrakk>P1 \<or> Q1; P2 \<or> Q2\<rbrakk> \<Longrightarrow> R" |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
926 |
apply(tactic {* DETERM (etac @{thm disjE} 1) *}) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
927 |
txt {*\begin{minipage}{\textwidth} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
928 |
@{subgoals [display]} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
929 |
\end{minipage} *} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
930 |
(*<*)oops(*>*) |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
931 |
text {* |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
932 |
This will prune the search space to just the first possibility. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
933 |
Attempting to apply \isacommand{back} in this goal states gives the |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
934 |
error message: |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
935 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
936 |
\begin{isabelle} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
937 |
@{text "*** back: no alternatives"}\\ |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
938 |
@{text "*** At command \"back\"."} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
939 |
\end{isabelle} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
940 |
|
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
941 |
\begin{readmore} |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
942 |
Most tactic combinators are defined in @{ML_file "Pure/tctical.ML"}. |
8bea3f74889d
added to the tactical chapter; polished; added the tabularstar environment (which is just tabular*)
Christian Urban <urbanc@in.tum.de>
parents:
107
diff
changeset
|
943 |
\end{readmore} |
107
258ce361ba1b
polished and more material in the tactic chapter
Christian Urban <urbanc@in.tum.de>
parents:
105
diff
changeset
|
944 |
|
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
945 |
*} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
946 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
947 |
section {* Rewriting and Simplifier Tactics *} |
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
948 |
|
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
949 |
text {* |
93 | 950 |
@{ML rewrite_goals_tac} |
951 |
@{ML ObjectLogic.full_atomize_tac} |
|
952 |
@{ML ObjectLogic.rulify_tac} |
|
953 |
*} |
|
954 |
||
105
f49dc7e96235
added more to the Tactical section
Christian Urban <urbanc@in.tum.de>
parents:
104
diff
changeset
|
955 |
|
95
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
956 |
section {* Structured Proofs *} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
957 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
958 |
lemma True |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
959 |
proof |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
960 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
961 |
{ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
962 |
fix A B C |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
963 |
assume r: "A & B \<Longrightarrow> C" |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
964 |
assume A B |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
965 |
then have "A & B" .. |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
966 |
then have C by (rule r) |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
967 |
} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
968 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
969 |
{ |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
970 |
fix A B C |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
971 |
assume r: "A & B \<Longrightarrow> C" |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
972 |
assume A B |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
973 |
note conjI [OF this] |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
974 |
note r [OF this] |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
975 |
} |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
976 |
oops |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
977 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
978 |
ML {* fun prop ctxt s = |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
979 |
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
|
980 |
|
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
981 |
ML {* |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
982 |
val ctxt0 = @{context}; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
983 |
val ctxt = ctxt0; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
984 |
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
|
985 |
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
|
986 |
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
|
987 |
val this = [@{thm conjI} OF this]; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
988 |
val this = r OF this; |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
989 |
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
|
990 |
val this = Variable.export ctxt ctxt0 [this] |
7235374f34c8
added some preliminary notes about SUBPROOF
Christian Urban <urbanc@in.tum.de>
parents:
93
diff
changeset
|
991 |
*} |
93 | 992 |
|
993 |
||
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
99
diff
changeset
|
994 |
|
93 | 995 |
end |