| author | mueller |
| Tue, 20 May 1997 10:28:19 +0200 | |
| changeset 3225 | cee363fc07d7 |
| parent 3128 | d01d4c0c4b44 |
| child 4317 | 7264fa2ff2ec |
| permissions | -rw-r--r-- |
| 104 | 1 |
%% $Id$ |
2 |
\chapter{Proof Management: The Subgoal Module}
|
|
3 |
\index{proofs|(}
|
|
4 |
\index{subgoal module|(}
|
|
5 |
\index{reading!goals|see{proofs, starting}}
|
|
| 321 | 6 |
|
7 |
The subgoal module stores the current proof state\index{proof state} and
|
|
8 |
many previous states; commands can produce new states or return to previous |
|
9 |
ones. The {\em state list\/} at level $n$ is a list of pairs
|
|
| 104 | 10 |
\[ [(\psi@n,\Psi@n),\; (\psi@{n-1},\Psi@{n-1}),\; \ldots,\; (\psi@0,[])] \]
|
11 |
where $\psi@n$ is the current proof state, $\psi@{n-1}$ is the previous
|
|
12 |
one, \ldots, and $\psi@0$ is the initial proof state. The $\Psi@i$ are |
|
13 |
sequences (lazy lists) of proof states, storing branch points where a |
|
14 |
tactic returned a list longer than one. The state lists permit various |
|
15 |
forms of backtracking. |
|
16 |
||
17 |
Chopping elements from the state list reverts to previous proof states. |
|
18 |
Besides this, the \ttindex{undo} command keeps a list of state lists. The
|
|
19 |
module actually maintains a stack of state lists, to support several |
|
20 |
proofs at the same time. |
|
21 |
||
22 |
The subgoal module always contains some proof state. At the start of the |
|
23 |
Isabelle session, this state consists of a dummy formula. |
|
24 |
||
25 |
||
26 |
\section{Basic commands}
|
|
27 |
Most proofs begin with {\tt goal} or {\tt goalw} and require no other
|
|
| 3108 | 28 |
commands than {\tt by}, {\tt chop} and {\tt undo}. They typically end
|
29 |
with a call to {\tt qed}.
|
|
| 104 | 30 |
\subsection{Starting a backward proof}
|
| 321 | 31 |
\index{proofs!starting}
|
| 104 | 32 |
\begin{ttbox}
|
33 |
goal : theory -> string -> thm list |
|
34 |
goalw : theory -> thm list -> string -> thm list |
|
| 3108 | 35 |
goalw_cterm : thm list -> cterm -> thm list |
| 104 | 36 |
premises : unit -> thm list |
37 |
\end{ttbox}
|
|
38 |
The {\tt goal} commands start a new proof by setting the goal. They
|
|
39 |
replace the current state list by a new one consisting of the initial proof |
|
40 |
state. They also empty the \ttindex{undo} list; this command cannot be
|
|
41 |
undone! |
|
42 |
||
43 |
They all return a list of meta-hypotheses taken from the main goal. If |
|
44 |
this list is non-empty, bind its value to an \ML{} identifier by typing
|
|
45 |
something like |
|
46 |
\begin{ttbox}
|
|
| 332 | 47 |
val prems = goal{\it theory\/ formula};
|
| 321 | 48 |
\end{ttbox}\index{assumptions!of main goal}
|
| 3108 | 49 |
These assumptions serve as the premises when you are deriving a rule. |
50 |
They are also stored internally and can be retrieved later by the |
|
51 |
function {\tt premises}. When the proof is finished, {\tt qed}
|
|
52 |
compares the stored assumptions with the actual assumptions in the |
|
53 |
proof state. |
|
| 104 | 54 |
|
| 321 | 55 |
\index{definitions!unfolding}
|
| 104 | 56 |
Some of the commands unfold definitions using meta-rewrite rules. This |
| 332 | 57 |
expansion affects both the initial subgoal and the premises, which would |
| 321 | 58 |
otherwise require use of {\tt rewrite_goals_tac} and
|
59 |
{\tt rewrite_rule}.
|
|
| 104 | 60 |
|
| 321 | 61 |
\index{*"!"! symbol!in main goal}
|
62 |
If the main goal has the form {\tt"!!{\it vars}.\ \ldots"}, with an
|
|
63 |
outermost quantifier, then the list of premises will be empty. Subgoal~1 |
|
64 |
will contain the meta-quantified {\it vars\/} as parameters and the goal's
|
|
65 |
premises as assumptions. This avoids having to call |
|
66 |
\ttindex{cut_facts_tac} with the list of premises (\S\ref{cut_facts_tac}).
|
|
| 104 | 67 |
|
| 321 | 68 |
\begin{ttdescription}
|
69 |
\item[\ttindexbold{goal} {\it theory} {\it formula};]
|
|
| 104 | 70 |
begins a new proof, where {\it theory} is usually an \ML\ identifier
|
71 |
and the {\it formula\/} is written as an \ML\ string.
|
|
72 |
||
| 321 | 73 |
\item[\ttindexbold{goalw} {\it theory} {\it defs} {\it formula};]
|
| 104 | 74 |
is like {\tt goal} but also applies the list of {\it defs\/} as
|
75 |
meta-rewrite rules to the first subgoal and the premises. |
|
| 321 | 76 |
\index{meta-rewriting}
|
| 104 | 77 |
|
| 3108 | 78 |
\item[\ttindexbold{goalw_cterm} {\it theory} {\it defs} {\it ct};] is
|
79 |
a version of {\tt goalw} for programming applications. The main
|
|
80 |
goal is supplied as a cterm, not as a string. Typically, the cterm |
|
81 |
is created from a term~$t$ by \hbox{\tt cterm_of (sign_of thy) $t$}.
|
|
82 |
\index{*cterm_of}\index{*sign_of}
|
|
| 104 | 83 |
|
84 |
\item[\ttindexbold{premises}()]
|
|
| 321 | 85 |
returns the list of meta-hypotheses associated with the current proof (in |
86 |
case you forgot to bind them to an \ML{} identifier).
|
|
87 |
\end{ttdescription}
|
|
88 |
||
| 104 | 89 |
|
90 |
\subsection{Applying a tactic}
|
|
| 321 | 91 |
\index{tactics!commands for applying}
|
| 104 | 92 |
\begin{ttbox}
|
93 |
by : tactic -> unit |
|
94 |
byev : tactic list -> unit |
|
95 |
\end{ttbox}
|
|
96 |
These commands extend the state list. They apply a tactic to the current |
|
97 |
proof state. If the tactic succeeds, it returns a non-empty sequence of |
|
98 |
next states. The head of the sequence becomes the next state, while the |
|
99 |
tail is retained for backtracking (see~{\tt back}).
|
|
| 321 | 100 |
\begin{ttdescription} \item[\ttindexbold{by} {\it tactic};]
|
| 104 | 101 |
applies the {\it tactic\/} to the proof state.
|
102 |
||
| 321 | 103 |
\item[\ttindexbold{byev} {\it tactics};]
|
| 104 | 104 |
applies the list of {\it tactics}, one at a time. It is useful for testing
|
105 |
calls to {\tt prove_goal}, and abbreviates \hbox{\tt by (EVERY {\it
|
|
106 |
tactics})}. |
|
| 321 | 107 |
\end{ttdescription}
|
| 104 | 108 |
|
| 286 | 109 |
\noindent{\it Error indications:}\nobreak
|
| 104 | 110 |
\begin{itemize}
|
| 286 | 111 |
\item {\footnotesize\tt "by:\ tactic failed"} means that the tactic
|
112 |
returned an empty sequence when applied to the current proof state. |
|
113 |
\item {\footnotesize\tt "Warning:\ same as previous level"} means that the
|
|
114 |
new proof state is identical to the previous state. |
|
115 |
\item{\footnotesize\tt "Warning:\ signature of proof state has changed"}
|
|
116 |
means that some rule was applied whose theory is outside the theory of |
|
117 |
the initial proof state. This could signify a mistake such as expressing |
|
118 |
the goal in intuitionistic logic and proving it using classical logic. |
|
| 104 | 119 |
\end{itemize}
|
120 |
||
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
121 |
\subsection{Extracting and storing the proved theorem}
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
122 |
\label{ExtractingAndStoringTheProvedTheorem}
|
|
1233
2856f382f033
minor corrections to indexing; added thms_containing
paulson
parents:
1225
diff
changeset
|
123 |
\index{theorems!extracting proved}
|
| 104 | 124 |
\begin{ttbox}
|
| 1283 | 125 |
qed : string -> unit |
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
126 |
result : unit -> thm |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
127 |
uresult : unit -> thm |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
128 |
bind_thm : string * thm -> unit |
| 1283 | 129 |
store_thm : string * thm -> thm |
| 104 | 130 |
\end{ttbox}
|
| 321 | 131 |
\begin{ttdescription}
|
| 1283 | 132 |
\item[\ttindexbold{qed} $name$] is the usual way of ending a proof.
|
133 |
It combines {\tt result} and {\tt bind_thm}: it gets the theorem using {\tt
|
|
134 |
result()} and stores it in Isabelle's theorem database. See below for |
|
135 |
details. |
|
136 |
||
| 321 | 137 |
\item[\ttindexbold{result}()]\index{assumptions!of main goal}
|
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
138 |
returns the final theorem, after converting the free variables to |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
139 |
schematics. It discharges the assumptions supplied to the matching |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
140 |
{\tt goal} command.
|
| 104 | 141 |
|
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
142 |
It raises an exception unless the proof state passes certain checks. There |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
143 |
must be no assumptions other than those supplied to {\tt goal}. There
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
144 |
must be no subgoals. The theorem proved must be a (first-order) instance |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
145 |
of the original goal, as stated in the {\tt goal} command. This allows
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
146 |
{\bf answer extraction} --- instantiation of variables --- but no other
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
147 |
changes to the main goal. The theorem proved must have the same signature |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
148 |
as the initial proof state. |
| 104 | 149 |
|
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
150 |
These checks are needed because an Isabelle tactic can return any proof |
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
151 |
state at all. |
| 321 | 152 |
|
153 |
\item[\ttindexbold{uresult}()] is like {\tt result()} but omits the checks.
|
|
154 |
It is needed when the initial goal contains function unknowns, when |
|
155 |
definitions are unfolded in the main goal (by calling |
|
156 |
\ttindex{rewrite_tac}),\index{definitions!unfolding} or when
|
|
157 |
\ttindex{assume_ax} has been used.
|
|
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
158 |
|
| 1283 | 159 |
\item[\ttindexbold{bind_thm}($name$, $thm$)]\index{theorems!storing}
|
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
160 |
stores {\tt standard($thm$)} (see \S\ref{MiscellaneousForwardRules})
|
| 1283 | 161 |
in Isabelle's theorem database and in the {\ML} variable $name$. The
|
162 |
theorem can be retrieved from the database using {\tt get_thm}
|
|
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
163 |
(see \S\ref{BasicOperationsOnTheories}).
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
164 |
|
| 1283 | 165 |
\item[\ttindexbold{store_thm}($name$, $thm$)]\index{theorems!storing} stores
|
166 |
$thm$ in Isabelle's theorem database and returns that theorem. |
|
| 321 | 167 |
\end{ttdescription}
|
| 104 | 168 |
|
169 |
||
| 1222 | 170 |
\subsection{Retrieving theorems}
|
171 |
\index{theorems!retrieving}
|
|
172 |
||
173 |
The following functions retrieve theorems (together with their names) from |
|
| 1225 | 174 |
the theorem database. Hence they can only find theorems that have explicitly |
175 |
been stored in the database using \ttindex{qed}, \ttindex{bind_thm} or
|
|
| 1222 | 176 |
related functions. |
177 |
\begin{ttbox}
|
|
|
1233
2856f382f033
minor corrections to indexing; added thms_containing
paulson
parents:
1225
diff
changeset
|
178 |
findI : int -> (string * thm) list |
|
2856f382f033
minor corrections to indexing; added thms_containing
paulson
parents:
1225
diff
changeset
|
179 |
findE : int -> int -> (string * thm) list |
|
2856f382f033
minor corrections to indexing; added thms_containing
paulson
parents:
1225
diff
changeset
|
180 |
findEs : int -> (string * thm) list |
|
2856f382f033
minor corrections to indexing; added thms_containing
paulson
parents:
1225
diff
changeset
|
181 |
thms_containing : string list -> (string * thm) list |
| 1222 | 182 |
\end{ttbox}
|
183 |
\begin{ttdescription}
|
|
184 |
\item[\ttindexbold{findI} $i$]\index{assumptions!of main goal}
|
|
| 1225 | 185 |
returns all ``introduction rules'' applicable to subgoal $i$ --- all |
| 1222 | 186 |
theorems whose conclusion matches (rather than unifies with) subgoal |
| 1225 | 187 |
$i$. Useful in connection with {\tt resolve_tac}.
|
| 1222 | 188 |
|
189 |
\item[\ttindexbold{findE} $n$ $i$] returns all ``elimination rules''
|
|
| 1225 | 190 |
applicable to premise $n$ of subgoal $i$ --- all those theorems whose |
191 |
first premise matches premise $n$ of subgoal $i$. Useful in connection with |
|
| 1222 | 192 |
{\tt eresolve_tac} and {\tt dresolve_tac}.
|
193 |
||
194 |
\item[\ttindexbold{findEs} $i$] returns all ``elimination rules'' applicable
|
|
| 1225 | 195 |
to subgoal $i$ --- all those theorems whose first premise matches some |
196 |
premise of subgoal $i$. Useful in connection with {\tt eresolve_tac} and
|
|
| 1222 | 197 |
{\tt dresolve_tac}.
|
198 |
||
| 1225 | 199 |
\item[\ttindexbold{thms_containing} $strings$] returns all theorems that
|
200 |
contain all of the constants in $strings$. Note that a few basic constants |
|
| 1222 | 201 |
like \verb$==>$ are ignored. |
202 |
\end{ttdescription}
|
|
203 |
||
204 |
||
| 104 | 205 |
\subsection{Undoing and backtracking}
|
206 |
\begin{ttbox}
|
|
207 |
chop : unit -> unit |
|
208 |
choplev : int -> unit |
|
209 |
back : unit -> unit |
|
210 |
undo : unit -> unit |
|
211 |
\end{ttbox}
|
|
| 321 | 212 |
\begin{ttdescription}
|
| 104 | 213 |
\item[\ttindexbold{chop}();]
|
214 |
deletes the top level of the state list, cancelling the last \ttindex{by}
|
|
215 |
command. It provides a limited undo facility, and the {\tt undo} command
|
|
216 |
can cancel it. |
|
217 |
||
218 |
\item[\ttindexbold{choplev} {\it n};]
|
|
|
2128
4e8644805af2
Documents the use of negative arguments to choplev and prlev
paulson
parents:
1283
diff
changeset
|
219 |
truncates the state list to level~{\it n}, if $n\geq0$. A negative value
|
|
4e8644805af2
Documents the use of negative arguments to choplev and prlev
paulson
parents:
1283
diff
changeset
|
220 |
of~$n$ refers to the $n$th previous level: |
|
4e8644805af2
Documents the use of negative arguments to choplev and prlev
paulson
parents:
1283
diff
changeset
|
221 |
\hbox{\verb|choplev ~1|} has the same effect as {\tt chop}.
|
| 104 | 222 |
|
223 |
\item[\ttindexbold{back}();]
|
|
224 |
searches the state list for a non-empty branch point, starting from the top |
|
225 |
level. The first one found becomes the current proof state --- the most |
|
| 286 | 226 |
recent alternative branch is taken. This is a form of interactive |
227 |
backtracking. |
|
| 104 | 228 |
|
229 |
\item[\ttindexbold{undo}();]
|
|
230 |
cancels the most recent change to the proof state by the commands \ttindex{by},
|
|
231 |
{\tt chop}, {\tt choplev}, and~{\tt back}. It {\bf cannot}
|
|
232 |
cancel {\tt goal} or {\tt undo} itself. It can be repeated to
|
|
233 |
cancel a series of commands. |
|
| 321 | 234 |
\end{ttdescription}
|
| 286 | 235 |
|
236 |
\goodbreak |
|
237 |
\noindent{\it Error indications for {\tt back}:}\par\nobreak
|
|
| 104 | 238 |
\begin{itemize}
|
| 286 | 239 |
\item{\footnotesize\tt"Warning:\ same as previous choice at this level"}
|
240 |
means {\tt back} found a non-empty branch point, but that it contained
|
|
241 |
the same proof state as the current one. |
|
242 |
\item{\footnotesize\tt "Warning:\ signature of proof state has changed"}
|
|
243 |
means the signature of the alternative proof state differs from that of |
|
244 |
the current state. |
|
245 |
\item {\footnotesize\tt "back:\ no alternatives"} means {\tt back} could
|
|
246 |
find no alternative proof state. |
|
| 104 | 247 |
\end{itemize}
|
248 |
||
| 507 | 249 |
\subsection{Printing the proof state}\label{sec:goals-printing}
|
| 321 | 250 |
\index{proof state!printing of}
|
| 104 | 251 |
\begin{ttbox}
|
252 |
pr : unit -> unit |
|
253 |
prlev : int -> unit |
|
| 2528 | 254 |
prlim : int -> unit |
| 104 | 255 |
goals_limit: int ref \hfill{\bf initially 10}
|
256 |
\end{ttbox}
|
|
| 2528 | 257 |
See also the printing control options described |
258 |
in~\S\ref{sec:printing-control}.
|
|
| 321 | 259 |
\begin{ttdescription}
|
| 104 | 260 |
\item[\ttindexbold{pr}();]
|
261 |
prints the current proof state. |
|
262 |
||
263 |
\item[\ttindexbold{prlev} {\it n};]
|
|
|
2128
4e8644805af2
Documents the use of negative arguments to choplev and prlev
paulson
parents:
1283
diff
changeset
|
264 |
prints the proof state at level {\it n}, if $n\geq0$. A negative value
|
|
4e8644805af2
Documents the use of negative arguments to choplev and prlev
paulson
parents:
1283
diff
changeset
|
265 |
of~$n$ refers to the $n$th previous level. This command allows |
|
4e8644805af2
Documents the use of negative arguments to choplev and prlev
paulson
parents:
1283
diff
changeset
|
266 |
you to review earlier stages of the proof. |
| 104 | 267 |
|
| 2528 | 268 |
\item[\ttindexbold{prlim} {\it k};]
|
269 |
prints the current proof state, limiting the number of subgoals to~$k$. It |
|
270 |
updates {\tt goals_limit} (see below) and is helpful when there are many
|
|
271 |
subgoals. |
|
272 |
||
| 321 | 273 |
\item[\ttindexbold{goals_limit} := {\it k};]
|
| 104 | 274 |
specifies~$k$ as the maximum number of subgoals to print. |
| 321 | 275 |
\end{ttdescription}
|
| 104 | 276 |
|
277 |
||
278 |
\subsection{Timing}
|
|
| 321 | 279 |
\index{timing statistics}\index{proofs!timing}
|
| 104 | 280 |
\begin{ttbox}
|
281 |
proof_timing: bool ref \hfill{\bf initially false}
|
|
282 |
\end{ttbox}
|
|
283 |
||
| 321 | 284 |
\begin{ttdescription}
|
285 |
\item[\ttindexbold{proof_timing} := true;]
|
|
| 104 | 286 |
makes the \ttindex{by} and \ttindex{prove_goal} commands display how much
|
287 |
processor time was spent. This information is compiler-dependent. |
|
| 321 | 288 |
\end{ttdescription}
|
| 104 | 289 |
|
290 |
||
291 |
\section{Shortcuts for applying tactics}
|
|
| 321 | 292 |
\index{shortcuts!for {\tt by} commands}
|
| 104 | 293 |
These commands call \ttindex{by} with common tactics. Their chief purpose
|
294 |
is to minimise typing, although the scanning shortcuts are useful in their |
|
295 |
own right. Chapter~\ref{tactics} explains the tactics themselves.
|
|
296 |
||
297 |
\subsection{Refining a given subgoal}
|
|
298 |
\begin{ttbox}
|
|
| 321 | 299 |
ba : int -> unit |
300 |
br : thm -> int -> unit |
|
301 |
be : thm -> int -> unit |
|
302 |
bd : thm -> int -> unit |
|
303 |
brs : thm list -> int -> unit |
|
304 |
bes : thm list -> int -> unit |
|
305 |
bds : thm list -> int -> unit |
|
| 104 | 306 |
\end{ttbox}
|
307 |
||
| 321 | 308 |
\begin{ttdescription}
|
| 104 | 309 |
\item[\ttindexbold{ba} {\it i};]
|
| 321 | 310 |
performs \hbox{\tt by (assume_tac {\it i});}
|
| 104 | 311 |
|
312 |
\item[\ttindexbold{br} {\it thm} {\it i};]
|
|
| 321 | 313 |
performs \hbox{\tt by (resolve_tac [{\it thm}] {\it i});}
|
| 104 | 314 |
|
315 |
\item[\ttindexbold{be} {\it thm} {\it i};]
|
|
| 321 | 316 |
performs \hbox{\tt by (eresolve_tac [{\it thm}] {\it i});}
|
| 104 | 317 |
|
318 |
\item[\ttindexbold{bd} {\it thm} {\it i};]
|
|
| 321 | 319 |
performs \hbox{\tt by (dresolve_tac [{\it thm}] {\it i});}
|
| 104 | 320 |
|
321 |
\item[\ttindexbold{brs} {\it thms} {\it i};]
|
|
| 321 | 322 |
performs \hbox{\tt by (resolve_tac {\it thms} {\it i});}
|
| 104 | 323 |
|
324 |
\item[\ttindexbold{bes} {\it thms} {\it i};]
|
|
| 321 | 325 |
performs \hbox{\tt by (eresolve_tac {\it thms} {\it i});}
|
| 104 | 326 |
|
327 |
\item[\ttindexbold{bds} {\it thms} {\it i};]
|
|
| 321 | 328 |
performs \hbox{\tt by (dresolve_tac {\it thms} {\it i});}
|
329 |
\end{ttdescription}
|
|
| 104 | 330 |
|
331 |
||
332 |
\subsection{Scanning shortcuts}
|
|
333 |
These shortcuts scan for a suitable subgoal (starting from subgoal~1). |
|
334 |
They refine the first subgoal for which the tactic succeeds. Thus, they |
|
335 |
require less typing than {\tt br}, etc. They display the selected
|
|
336 |
subgoal's number; please watch this, for it may not be what you expect! |
|
337 |
||
338 |
\begin{ttbox}
|
|
| 321 | 339 |
fa : unit -> unit |
340 |
fr : thm -> unit |
|
341 |
fe : thm -> unit |
|
342 |
fd : thm -> unit |
|
343 |
frs : thm list -> unit |
|
344 |
fes : thm list -> unit |
|
345 |
fds : thm list -> unit |
|
| 104 | 346 |
\end{ttbox}
|
347 |
||
| 321 | 348 |
\begin{ttdescription}
|
| 104 | 349 |
\item[\ttindexbold{fa}();]
|
| 321 | 350 |
solves some subgoal by assumption. |
| 104 | 351 |
|
352 |
\item[\ttindexbold{fr} {\it thm};]
|
|
353 |
refines some subgoal using \hbox{\tt resolve_tac [{\it thm}]}
|
|
354 |
||
355 |
\item[\ttindexbold{fe} {\it thm};]
|
|
356 |
refines some subgoal using \hbox{\tt eresolve_tac [{\it thm}]}
|
|
357 |
||
358 |
\item[\ttindexbold{fd} {\it thm};]
|
|
359 |
refines some subgoal using \hbox{\tt dresolve_tac [{\it thm}]}
|
|
360 |
||
361 |
\item[\ttindexbold{frs} {\it thms};]
|
|
362 |
refines some subgoal using \hbox{\tt resolve_tac {\it thms}}
|
|
363 |
||
364 |
\item[\ttindexbold{fes} {\it thms};]
|
|
365 |
refines some subgoal using \hbox{\tt eresolve_tac {\it thms}}
|
|
366 |
||
367 |
\item[\ttindexbold{fds} {\it thms};]
|
|
368 |
refines some subgoal using \hbox{\tt dresolve_tac {\it thms}}
|
|
| 321 | 369 |
\end{ttdescription}
|
| 104 | 370 |
|
371 |
\subsection{Other shortcuts}
|
|
372 |
\begin{ttbox}
|
|
373 |
bw : thm -> unit |
|
374 |
bws : thm list -> unit |
|
375 |
ren : string -> int -> unit |
|
376 |
\end{ttbox}
|
|
| 321 | 377 |
\begin{ttdescription}
|
| 104 | 378 |
\item[\ttindexbold{bw} {\it def};]
|
379 |
performs \hbox{\tt by (rewrite_goals_tac [{\it def}]);}
|
|
380 |
It unfolds definitions in the subgoals (but not the main goal), by |
|
| 321 | 381 |
meta-rewriting with the given definition. |
382 |
\index{meta-rewriting}
|
|
| 104 | 383 |
|
384 |
\item[\ttindexbold{bws}]
|
|
385 |
is like {\tt bw} but takes a list of definitions.
|
|
386 |
||
387 |
\item[\ttindexbold{ren} {\it names} {\it i};]
|
|
388 |
performs \hbox{\tt by (rename_tac {\it names} {\it i});} it renames
|
|
| 332 | 389 |
parameters in subgoal~$i$. (Ignore the message {\footnotesize\tt Warning:\
|
390 |
same as previous level}.) |
|
| 321 | 391 |
\index{parameters!renaming}
|
392 |
\end{ttdescription}
|
|
| 104 | 393 |
|
394 |
||
| 321 | 395 |
\section{Executing batch proofs}
|
|
3128
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
396 |
\index{batch execution}%
|
|
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
397 |
To save space below, let type \texttt{tacfun} abbreviate \texttt{thm list ->
|
|
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
398 |
tactic list}, which is the type of a tactical proof. |
| 286 | 399 |
\begin{ttbox}
|
|
3128
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
400 |
prove_goal : theory -> string -> tacfun -> thm |
|
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
401 |
qed_goal : string -> theory -> string -> tacfun -> unit |
|
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
402 |
prove_goalw: theory -> thm list -> string -> tacfun -> thm |
|
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
403 |
qed_goalw : string -> theory -> thm list -> string -> tacfun -> unit |
|
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3108
diff
changeset
|
404 |
prove_goalw_cterm: thm list -> cterm -> tacfun -> thm |
| 104 | 405 |
\end{ttbox}
|
| 321 | 406 |
These batch functions create an initial proof state, then apply a tactic to |
407 |
it, yielding a sequence of final proof states. The head of the sequence is |
|
| 104 | 408 |
returned, provided it is an instance of the theorem originally proposed. |
409 |
The forms {\tt prove_goal}, {\tt prove_goalw} and {\tt prove_goalw_cterm}
|
|
| 321 | 410 |
are analogous to {\tt goal}, {\tt goalw} and {\tt goalw_cterm}.
|
| 104 | 411 |
|
412 |
The tactic is specified by a function from theorem lists to tactic lists. |
|
| 332 | 413 |
The function is applied to the list of meta-assumptions taken from |
414 |
the main goal. The resulting tactics are applied in sequence (using {\tt
|
|
415 |
EVERY}). For example, a proof consisting of the commands |
|
| 104 | 416 |
\begin{ttbox}
|
417 |
val prems = goal {\it theory} {\it formula};
|
|
418 |
by \(tac@1\); \ldots by \(tac@n\); |
|
| 3108 | 419 |
qed "my_thm"; |
| 104 | 420 |
\end{ttbox}
|
421 |
can be transformed to an expression as follows: |
|
422 |
\begin{ttbox}
|
|
| 3108 | 423 |
qed_goal "my_thm" {\it theory} {\it formula}
|
| 104 | 424 |
(fn prems=> [ \(tac@1\), \ldots, \(tac@n\) ]); |
425 |
\end{ttbox}
|
|
426 |
The methods perform identical processing of the initial {\it formula} and
|
|
| 332 | 427 |
the final proof state. But {\tt prove_goal} executes the tactic as a
|
428 |
atomic operation, bypassing the subgoal module; the current interactive |
|
429 |
proof is unaffected. |
|
430 |
% |
|
| 321 | 431 |
\begin{ttdescription}
|
432 |
\item[\ttindexbold{prove_goal} {\it theory} {\it formula} {\it tacsf};]
|
|
| 104 | 433 |
executes a proof of the {\it formula\/} in the given {\it theory}, using
|
434 |
the given tactic function. |
|
435 |
||
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
436 |
\item[\ttindexbold{qed_goal} $name$ $theory$ $formula$ $tacsf$;]
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
437 |
acts like {\tt prove_goal} but also stores the resulting theorem in
|
| 1283 | 438 |
Isabelle's theorem database and in the {\ML} variable $name$ (see
|
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
439 |
\S\ref{ExtractingAndStoringTheProvedTheorem}).
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
440 |
|
| 104 | 441 |
\item[\ttindexbold{prove_goalw} {\it theory} {\it defs} {\it formula}
|
| 321 | 442 |
{\it tacsf};]\index{meta-rewriting}
|
| 104 | 443 |
is like {\tt prove_goal} but also applies the list of {\it defs\/} as
|
444 |
meta-rewrite rules to the first subgoal and the premises. |
|
445 |
||
|
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
446 |
\item[\ttindexbold{qed_goalw} $name$ $theory$ $defs$ $formula$ $tacsf$;]
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
447 |
is analogous to {\tt qed_goal}.
|
|
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
507
diff
changeset
|
448 |
|
| 104 | 449 |
\item[\ttindexbold{prove_goalw_cterm} {\it theory} {\it defs} {\it ct}
|
| 321 | 450 |
{\it tacsf};]
|
451 |
is a version of {\tt prove_goalw} for programming applications. The main
|
|
| 104 | 452 |
goal is supplied as a cterm, not as a string. Typically, the cterm is |
| 286 | 453 |
created from a term~$t$ as follows: |
454 |
\begin{ttbox}
|
|
| 3108 | 455 |
cterm_of (sign_of thy) \(t\) |
| 286 | 456 |
\end{ttbox}
|
| 3108 | 457 |
\index{*cterm_of}\index{*sign_of}
|
| 321 | 458 |
\end{ttdescription}
|
| 104 | 459 |
|
460 |
||
| 321 | 461 |
\section{Managing multiple proofs}
|
462 |
\index{proofs!managing multiple}
|
|
| 104 | 463 |
You may save the current state of the subgoal module and resume work on it |
464 |
later. This serves two purposes. |
|
465 |
\begin{enumerate}
|
|
466 |
\item At some point, you may be uncertain of the next step, and |
|
467 |
wish to experiment. |
|
468 |
||
469 |
\item During a proof, you may see that a lemma should be proved first. |
|
470 |
\end{enumerate}
|
|
471 |
Each saved proof state consists of a list of levels; \ttindex{chop} behaves
|
|
472 |
independently for each of the saved proofs. In addition, each saved state |
|
473 |
carries a separate \ttindex{undo} list.
|
|
474 |
||
| 321 | 475 |
\subsection{The stack of proof states}
|
476 |
\index{proofs!stacking}
|
|
| 104 | 477 |
\begin{ttbox}
|
478 |
push_proof : unit -> unit |
|
479 |
pop_proof : unit -> thm list |
|
480 |
rotate_proof : unit -> thm list |
|
481 |
\end{ttbox}
|
|
482 |
The subgoal module maintains a stack of proof states. Most subgoal |
|
| 321 | 483 |
commands affect only the top of the stack. The \ttindex{goal} command {\em
|
484 |
replaces\/} the top of the stack; the only command that pushes a proof on the |
|
| 104 | 485 |
stack is {\tt push_proof}.
|
486 |
||
487 |
To save some point of the proof, call {\tt push_proof}. You may now
|
|
| 321 | 488 |
state a lemma using {\tt goal}, or simply continue to apply tactics.
|
| 104 | 489 |
Later, you can return to the saved point by calling {\tt pop_proof} or
|
490 |
{\tt rotate_proof}.
|
|
491 |
||
492 |
To view the entire stack, call {\tt rotate_proof} repeatedly; as it rotates
|
|
493 |
the stack, it prints the new top element. |
|
494 |
||
| 321 | 495 |
\begin{ttdescription}
|
| 104 | 496 |
\item[\ttindexbold{push_proof}();]
|
497 |
duplicates the top element of the stack, pushing a copy of the current |
|
498 |
proof state on to the stack. |
|
499 |
||
500 |
\item[\ttindexbold{pop_proof}();]
|
|
501 |
discards the top element of the stack. It returns the list of |
|
| 332 | 502 |
assumptions associated with the new proof; you should bind these to an |
| 104 | 503 |
\ML\ identifier. They can also be obtained by calling \ttindex{premises}.
|
504 |
||
| 321 | 505 |
\item[\ttindexbold{rotate_proof}();]
|
506 |
\index{assumptions!of main goal}
|
|
| 104 | 507 |
rotates the stack, moving the top element to the bottom. It returns the |
508 |
list of assumptions associated with the new proof. |
|
| 321 | 509 |
\end{ttdescription}
|
| 104 | 510 |
|
511 |
||
| 321 | 512 |
\subsection{Saving and restoring proof states}
|
513 |
\index{proofs!saving and restoring}
|
|
| 104 | 514 |
\begin{ttbox}
|
515 |
save_proof : unit -> proof |
|
516 |
restore_proof : proof -> thm list |
|
517 |
\end{ttbox}
|
|
518 |
States of the subgoal module may be saved as \ML\ values of |
|
| 321 | 519 |
type~\mltydx{proof}, and later restored.
|
| 104 | 520 |
|
| 321 | 521 |
\begin{ttdescription}
|
| 104 | 522 |
\item[\ttindexbold{save_proof}();]
|
523 |
returns the current state, which is on top of the stack. |
|
524 |
||
| 321 | 525 |
\item[\ttindexbold{restore_proof} {\it prf};]\index{assumptions!of main goal}
|
526 |
replaces the top of the stack by~{\it prf}. It returns the list of
|
|
527 |
assumptions associated with the new proof. |
|
528 |
\end{ttdescription}
|
|
| 104 | 529 |
|
530 |
||
| 321 | 531 |
\section{Debugging and inspecting}
|
532 |
\index{tactics!debugging}
|
|
| 2611 | 533 |
These functions can be useful when you are debugging a tactic. They refer |
534 |
to the current proof state stored in the subgoal module. A tactic |
|
535 |
should never call them; it should operate on the proof state supplied as its |
|
536 |
argument. |
|
| 104 | 537 |
|
| 321 | 538 |
\subsection{Reading and printing terms}
|
539 |
\index{terms!reading of}\index{terms!printing of}\index{types!printing of}
|
|
| 104 | 540 |
\begin{ttbox}
|
541 |
read : string -> term |
|
542 |
prin : term -> unit |
|
543 |
printyp : typ -> unit |
|
544 |
\end{ttbox}
|
|
545 |
These read and print terms (or types) using the syntax associated with the |
|
546 |
proof state. |
|
547 |
||
| 321 | 548 |
\begin{ttdescription}
|
| 104 | 549 |
\item[\ttindexbold{read} {\it string}]
|
550 |
reads the {\it string} as a term, without type checking.
|
|
551 |
||
552 |
\item[\ttindexbold{prin} {\it t};]
|
|
553 |
prints the term~$t$ at the terminal. |
|
554 |
||
555 |
\item[\ttindexbold{printyp} {\it T};]
|
|
556 |
prints the type~$T$ at the terminal. |
|
| 321 | 557 |
\end{ttdescription}
|
| 104 | 558 |
|
| 321 | 559 |
\subsection{Inspecting the proof state}
|
560 |
\index{proofs!inspecting the state}
|
|
| 104 | 561 |
\begin{ttbox}
|
562 |
topthm : unit -> thm |
|
563 |
getgoal : int -> term |
|
564 |
gethyps : int -> thm list |
|
565 |
\end{ttbox}
|
|
566 |
||
| 321 | 567 |
\begin{ttdescription}
|
| 104 | 568 |
\item[\ttindexbold{topthm}()]
|
569 |
returns the proof state as an Isabelle theorem. This is what \ttindex{by}
|
|
570 |
would supply to a tactic at this point. It omits the post-processing of |
|
571 |
\ttindex{result} and \ttindex{uresult}.
|
|
572 |
||
573 |
\item[\ttindexbold{getgoal} {\it i}]
|
|
574 |
returns subgoal~$i$ of the proof state, as a term. You may print |
|
575 |
this using {\tt prin}, though you may have to examine the internal
|
|
576 |
data structure in order to locate the problem! |
|
577 |
||
| 321 | 578 |
\item[\ttindexbold{gethyps} {\it i}]
|
579 |
returns the hypotheses of subgoal~$i$ as meta-level assumptions. In |
|
580 |
these theorems, the subgoal's parameters become free variables. This |
|
581 |
command is supplied for debugging uses of \ttindex{METAHYPS}.
|
|
582 |
\end{ttdescription}
|
|
| 104 | 583 |
|
| 2611 | 584 |
|
| 321 | 585 |
\subsection{Filtering lists of rules}
|
| 104 | 586 |
\begin{ttbox}
|
587 |
filter_goal: (term*term->bool) -> thm list -> int -> thm list |
|
588 |
\end{ttbox}
|
|
589 |
||
| 321 | 590 |
\begin{ttdescription}
|
| 104 | 591 |
\item[\ttindexbold{filter_goal} {\it could} {\it ths} {\it i}]
|
592 |
applies \hbox{\tt filter_thms {\it could}} to subgoal~$i$ of the proof
|
|
593 |
state and returns the list of theorems that survive the filtering. |
|
| 321 | 594 |
\end{ttdescription}
|
| 104 | 595 |
|
596 |
\index{subgoal module|)}
|
|
597 |
\index{proofs|)}
|