author | wenzelm |
Fri, 08 Oct 1999 16:18:51 +0200 | |
changeset 7807 | 6a102f74ad0a |
parent 7620 | 8d721c3f4acb |
child 7920 | 1ee85d4205b2 |
permissions | -rw-r--r-- |
104 | 1 |
%% $Id$ |
3950 | 2 |
\chapter{Simplification} |
3 |
\label{chap:simplification} |
|
104 | 4 |
\index{simplification|(} |
5 |
||
4395 | 6 |
This chapter describes Isabelle's generic simplification package. It |
7 |
performs conditional and unconditional rewriting and uses contextual |
|
8 |
information (`local assumptions'). It provides several general hooks, |
|
9 |
which can provide automatic case splits during rewriting, for example. |
|
10 |
The simplifier is already set up for many of Isabelle's logics: \FOL, |
|
11 |
\ZF, \HOL, \HOLCF. |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
12 |
|
4395 | 13 |
The first section is a quick introduction to the simplifier that |
14 |
should be sufficient to get started. The later sections explain more |
|
15 |
advanced features. |
|
16 |
||
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
17 |
|
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
18 |
\section{Simplification for dummies} |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
19 |
\label{sec:simp-for-dummies} |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
20 |
|
4395 | 21 |
Basic use of the simplifier is particularly easy because each theory |
4557 | 22 |
is equipped with sensible default information controlling the rewrite |
23 |
process --- namely the implicit {\em current |
|
24 |
simpset}\index{simpset!current}. A suite of simple commands is |
|
25 |
provided that refer to the implicit simpset of the current theory |
|
26 |
context. |
|
4395 | 27 |
|
28 |
\begin{warn} |
|
29 |
Make sure that you are working within the correct theory context. |
|
30 |
Executing proofs interactively, or loading them from ML files |
|
31 |
without associated theories may require setting the current theory |
|
32 |
manually via the \ttindex{context} command. |
|
33 |
\end{warn} |
|
34 |
||
35 |
\subsection{Simplification tactics} \label{sec:simp-for-dummies-tacs} |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
36 |
\begin{ttbox} |
4395 | 37 |
Simp_tac : int -> tactic |
38 |
Asm_simp_tac : int -> tactic |
|
39 |
Full_simp_tac : int -> tactic |
|
40 |
Asm_full_simp_tac : int -> tactic |
|
41 |
trace_simp : bool ref \hfill{\bf initially false} |
|
42 |
\end{ttbox} |
|
43 |
||
44 |
\begin{ttdescription} |
|
45 |
\item[\ttindexbold{Simp_tac} $i$] simplifies subgoal~$i$ using the |
|
46 |
current simpset. It may solve the subgoal completely if it has |
|
47 |
become trivial, using the simpset's solver tactic. |
|
48 |
||
49 |
\item[\ttindexbold{Asm_simp_tac}]\index{assumptions!in simplification} |
|
50 |
is like \verb$Simp_tac$, but extracts additional rewrite rules from |
|
51 |
the local assumptions. |
|
52 |
||
53 |
\item[\ttindexbold{Full_simp_tac}] is like \verb$Simp_tac$, but also |
|
54 |
simplifies the assumptions (without using the assumptions to |
|
55 |
simplify each other or the actual goal). |
|
56 |
||
57 |
\item[\ttindexbold{Asm_full_simp_tac}] is like \verb$Asm_simp_tac$, |
|
4889 | 58 |
but also simplifies the assumptions. In particular, assumptions can |
59 |
simplify each other. |
|
60 |
\footnote{\texttt{Asm_full_simp_tac} used to process the assumptions from |
|
61 |
left to right. For backwards compatibilty reasons only there is now |
|
62 |
\texttt{Asm_lr_simp_tac} that behaves like the old \texttt{Asm_full_simp_tac}.} |
|
4395 | 63 |
\item[set \ttindexbold{trace_simp};] makes the simplifier output |
64 |
internal operations. This includes rewrite steps, but also |
|
65 |
bookkeeping like modifications of the simpset. |
|
66 |
\end{ttdescription} |
|
67 |
||
68 |
\medskip |
|
69 |
||
70 |
As an example, consider the theory of arithmetic in \HOL. The (rather |
|
71 |
trivial) goal $0 + (x + 0) = x + 0 + 0$ can be solved by a single call |
|
72 |
of \texttt{Simp_tac} as follows: |
|
73 |
\begin{ttbox} |
|
74 |
context Arith.thy; |
|
5205 | 75 |
Goal "0 + (x + 0) = x + 0 + 0"; |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
76 |
{\out 1. 0 + (x + 0) = x + 0 + 0} |
4395 | 77 |
by (Simp_tac 1); |
78 |
{\out Level 1} |
|
79 |
{\out 0 + (x + 0) = x + 0 + 0} |
|
80 |
{\out No subgoals!} |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
81 |
\end{ttbox} |
4395 | 82 |
|
83 |
The simplifier uses the current simpset of \texttt{Arith.thy}, which |
|
84 |
contains suitable theorems like $\Var{n}+0 = \Var{n}$ and $0+\Var{n} = |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
85 |
\Var{n}$. |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
86 |
|
4395 | 87 |
\medskip In many cases, assumptions of a subgoal are also needed in |
88 |
the simplification process. For example, \texttt{x = 0 ==> x + x = 0} |
|
89 |
is solved by \texttt{Asm_simp_tac} as follows: |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
90 |
\begin{ttbox} |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
91 |
{\out 1. x = 0 ==> x + x = 0} |
2479 | 92 |
by (Asm_simp_tac 1); |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
93 |
\end{ttbox} |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
94 |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
95 |
\medskip \texttt{Asm_full_simp_tac} is the most powerful of this quartet |
4395 | 96 |
of tactics but may also loop where some of the others terminate. For |
97 |
example, |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
98 |
\begin{ttbox} |
4395 | 99 |
{\out 1. ALL x. f x = g (f (g x)) ==> f 0 = f 0 + 0} |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
100 |
\end{ttbox} |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
101 |
is solved by \texttt{Simp_tac}, but \texttt{Asm_simp_tac} and {\tt |
4395 | 102 |
Asm_simp_tac} loop because the rewrite rule $f\,\Var{x} = |
103 |
g\,(f\,(g\,\Var{x}))$ extracted from the assumption does not |
|
104 |
terminate. Isabelle notices certain simple forms of nontermination, |
|
4889 | 105 |
but not this one. Because assumptions may simplify each other, there can be |
106 |
very subtle cases of nontermination. |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
107 |
|
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
108 |
\begin{warn} |
4889 | 109 |
\verb$Asm_full_simp_tac$ may miss opportunities to simplify an assumption |
110 |
$A@i$ using an assumption $A@j$ in case $A@j$ is to the right of $A@i$. |
|
111 |
For example, given the subgoal |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
112 |
\begin{ttbox} |
4889 | 113 |
{\out [| \dots f a \dots; P a; ALL x. P x --> f x = g x |] ==> \dots} |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
114 |
\end{ttbox} |
4889 | 115 |
\verb$Asm_full_simp_tac$ will not simplify the \texttt{f a} on the left. |
116 |
This problem can be overcome by reordering assumptions (see |
|
117 |
\S\ref{sec:reordering-asms}). Future versions of \verb$Asm_full_simp_tac$ |
|
118 |
will not suffer from this deficiency. |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
119 |
\end{warn} |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
120 |
|
4395 | 121 |
\medskip |
122 |
||
3108 | 123 |
Using the simplifier effectively may take a bit of experimentation. |
4395 | 124 |
Set the \verb$trace_simp$\index{tracing!of simplification} flag to get |
125 |
a better idea of what is going on. The resulting output can be |
|
126 |
enormous, especially since invocations of the simplifier are often |
|
127 |
nested (e.g.\ when solving conditions of rewrite rules). |
|
128 |
||
129 |
||
130 |
\subsection{Modifying the current simpset} |
|
131 |
\begin{ttbox} |
|
132 |
Addsimps : thm list -> unit |
|
133 |
Delsimps : thm list -> unit |
|
134 |
Addsimprocs : simproc list -> unit |
|
135 |
Delsimprocs : simproc list -> unit |
|
136 |
Addcongs : thm list -> unit |
|
137 |
Delcongs : thm list -> unit |
|
5549 | 138 |
Addsplits : thm list -> unit |
139 |
Delsplits : thm list -> unit |
|
4395 | 140 |
\end{ttbox} |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
141 |
|
4395 | 142 |
Depending on the theory context, the \texttt{Add} and \texttt{Del} |
143 |
functions manipulate basic components of the associated current |
|
144 |
simpset. Internally, all rewrite rules have to be expressed as |
|
145 |
(conditional) meta-equalities. This form is derived automatically |
|
146 |
from object-level equations that are supplied by the user. Another |
|
147 |
source of rewrite rules are \emph{simplification procedures}, that is |
|
148 |
\ML\ functions that produce suitable theorems on demand, depending on |
|
149 |
the current redex. Congruences are a more advanced feature; see |
|
150 |
\S\ref{sec:simp-congs}. |
|
151 |
||
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
152 |
\begin{ttdescription} |
4395 | 153 |
|
154 |
\item[\ttindexbold{Addsimps} $thms$;] adds rewrite rules derived from |
|
155 |
$thms$ to the current simpset. |
|
156 |
||
157 |
\item[\ttindexbold{Delsimps} $thms$;] deletes rewrite rules derived |
|
158 |
from $thms$ from the current simpset. |
|
159 |
||
160 |
\item[\ttindexbold{Addsimprocs} $procs$;] adds simplification |
|
161 |
procedures $procs$ to the current simpset. |
|
162 |
||
163 |
\item[\ttindexbold{Delsimprocs} $procs$;] deletes simplification |
|
164 |
procedures $procs$ from the current simpset. |
|
165 |
||
166 |
\item[\ttindexbold{Addcongs} $thms$;] adds congruence rules to the |
|
167 |
current simpset. |
|
168 |
||
5549 | 169 |
\item[\ttindexbold{Delcongs} $thms$;] deletes congruence rules from the |
170 |
current simpset. |
|
171 |
||
172 |
\item[\ttindexbold{Addsplits} $thms$;] adds splitting rules to the |
|
173 |
current simpset. |
|
174 |
||
175 |
\item[\ttindexbold{Delsplits} $thms$;] deletes splitting rules from the |
|
4395 | 176 |
current simpset. |
177 |
||
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
178 |
\end{ttdescription} |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
179 |
|
4395 | 180 |
When a new theory is built, its implicit simpset is initialized by the |
181 |
union of the respective simpsets of its parent theories. In addition, |
|
182 |
certain theory definition constructs (e.g.\ \ttindex{datatype} and |
|
183 |
\ttindex{primrec} in \HOL) implicitly augment the current simpset. |
|
184 |
Ordinary definitions are not added automatically! |
|
185 |
||
186 |
It is up the user to manipulate the current simpset further by |
|
187 |
explicitly adding or deleting theorems and simplification procedures. |
|
188 |
||
189 |
\medskip |
|
190 |
||
5205 | 191 |
Good simpsets are hard to design. Rules that obviously simplify, |
192 |
like $\Var{n}+0 = \Var{n}$, should be added to the current simpset right after |
|
193 |
they have been proved. More specific ones (such as distributive laws, which |
|
194 |
duplicate subterms) should be added only for specific proofs and deleted |
|
195 |
afterwards. Conversely, sometimes a rule needs |
|
196 |
to be removed for a certain proof and restored afterwards. The need of |
|
197 |
frequent additions or deletions may indicate a badly designed |
|
198 |
simpset. |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
199 |
|
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
200 |
\begin{warn} |
4395 | 201 |
The union of the parent simpsets (as described above) is not always |
202 |
a good starting point for the new theory. If some ancestors have |
|
203 |
deleted simplification rules because they are no longer wanted, |
|
204 |
while others have left those rules in, then the union will contain |
|
5205 | 205 |
the unwanted rules. After this union is formed, changes to |
206 |
a parent simpset have no effect on the child simpset. |
|
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
207 |
\end{warn} |
104 | 208 |
|
209 |
||
286 | 210 |
\section{Simplification sets}\index{simplification sets} |
4395 | 211 |
|
212 |
The simplifier is controlled by information contained in {\bf |
|
213 |
simpsets}. These consist of several components, including rewrite |
|
214 |
rules, simplification procedures, congruence rules, and the subgoaler, |
|
215 |
solver and looper tactics. The simplifier should be set up with |
|
216 |
sensible defaults so that most simplifier calls specify only rewrite |
|
217 |
rules or simplification procedures. Experienced users can exploit the |
|
218 |
other components to streamline proofs in more sophisticated manners. |
|
219 |
||
220 |
\subsection{Inspecting simpsets} |
|
221 |
\begin{ttbox} |
|
222 |
print_ss : simpset -> unit |
|
4889 | 223 |
rep_ss : simpset -> \{mss : meta_simpset, |
4664 | 224 |
subgoal_tac: simpset -> int -> tactic, |
7620 | 225 |
loop_tacs : (string * (int -> tactic))list, |
226 |
finish_tac : solver list, |
|
227 |
unsafe_finish_tac : solver list\} |
|
4395 | 228 |
\end{ttbox} |
229 |
\begin{ttdescription} |
|
230 |
||
231 |
\item[\ttindexbold{print_ss} $ss$;] displays the printable contents of |
|
232 |
simpset $ss$. This includes the rewrite rules and congruences in |
|
233 |
their internal form expressed as meta-equalities. The names of the |
|
234 |
simplification procedures and the patterns they are invoked on are |
|
235 |
also shown. The other parts, functions and tactics, are |
|
236 |
non-printable. |
|
237 |
||
4664 | 238 |
\item[\ttindexbold{rep_ss} $ss$;] decomposes $ss$ as a record of its internal |
239 |
components, namely the meta_simpset, the subgoaler, the loop, and the safe |
|
240 |
and unsafe solvers. |
|
241 |
||
4395 | 242 |
\end{ttdescription} |
243 |
||
323 | 244 |
|
4395 | 245 |
\subsection{Building simpsets} |
246 |
\begin{ttbox} |
|
247 |
empty_ss : simpset |
|
248 |
merge_ss : simpset * simpset -> simpset |
|
249 |
\end{ttbox} |
|
250 |
\begin{ttdescription} |
|
251 |
||
252 |
\item[\ttindexbold{empty_ss}] is the empty simpset. This is not very |
|
253 |
useful under normal circumstances because it doesn't contain |
|
254 |
suitable tactics (subgoaler etc.). When setting up the simplifier |
|
255 |
for a particular object-logic, one will typically define a more |
|
256 |
appropriate ``almost empty'' simpset. For example, in \HOL\ this is |
|
257 |
called \ttindexbold{HOL_basic_ss}. |
|
258 |
||
259 |
\item[\ttindexbold{merge_ss} ($ss@1$, $ss@2$)] merges simpsets $ss@1$ |
|
260 |
and $ss@2$ by building the union of their respective rewrite rules, |
|
261 |
simplification procedures and congruences. The other components |
|
4557 | 262 |
(tactics etc.) cannot be merged, though; they are taken from either |
263 |
simpset\footnote{Actually from $ss@1$, but it would unwise to count |
|
264 |
on that.}. |
|
4395 | 265 |
|
266 |
\end{ttdescription} |
|
267 |
||
268 |
||
269 |
\subsection{Accessing the current simpset} |
|
5575 | 270 |
\label{sec:access-current-simpset} |
4395 | 271 |
|
272 |
\begin{ttbox} |
|
5575 | 273 |
simpset : unit -> simpset |
274 |
simpset_ref : unit -> simpset ref |
|
4395 | 275 |
simpset_of : theory -> simpset |
276 |
simpset_ref_of : theory -> simpset ref |
|
277 |
print_simpset : theory -> unit |
|
5575 | 278 |
SIMPSET :(simpset -> tactic) -> tactic |
279 |
SIMPSET' :(simpset -> 'a -> tactic) -> 'a -> tactic |
|
4395 | 280 |
\end{ttbox} |
281 |
||
282 |
Each theory contains a current simpset\index{simpset!current} stored |
|
283 |
within a private ML reference variable. This can be retrieved and |
|
284 |
modified as follows. |
|
285 |
||
286 |
\begin{ttdescription} |
|
287 |
||
288 |
\item[\ttindexbold{simpset}();] retrieves the simpset value from the |
|
289 |
current theory context. |
|
290 |
||
291 |
\item[\ttindexbold{simpset_ref}();] retrieves the simpset reference |
|
292 |
variable from the current theory context. This can be assigned to |
|
293 |
by using \texttt{:=} in ML. |
|
294 |
||
295 |
\item[\ttindexbold{simpset_of} $thy$;] retrieves the simpset value |
|
296 |
from theory $thy$. |
|
297 |
||
298 |
\item[\ttindexbold{simpset_ref_of} $thy$;] retrieves the simpset |
|
299 |
reference variable from theory $thy$. |
|
300 |
||
5575 | 301 |
\item[\ttindexbold{print_simpset} $thy$;] prints the current simpset |
302 |
of theory $thy$ in the same way as \texttt{print_ss}. |
|
303 |
||
5574 | 304 |
\item[\ttindexbold{SIMPSET} $tacf$, \ttindexbold{SIMPSET'} $tacf'$] |
305 |
are tacticals that make a tactic depend on the implicit current |
|
306 |
simpset of the theory associated with the proof state they are |
|
307 |
applied on. |
|
308 |
||
4395 | 309 |
\end{ttdescription} |
310 |
||
5574 | 311 |
\begin{warn} |
312 |
There is a subtle difference between \texttt{(SIMPSET'~$tacf$)} and |
|
313 |
\texttt{($tacf$~(simpset()))}. For example \texttt{(SIMPSET' |
|
314 |
simp_tac)} would depend on the theory of the proof state it is |
|
315 |
applied to, while \texttt{(simp_tac (simpset()))} implicitly refers |
|
316 |
to the current theory context. Both are usually the same in proof |
|
317 |
scripts, provided that goals are only stated within the current |
|
318 |
theory. Robust programs would not count on that, of course. |
|
319 |
\end{warn} |
|
320 |
||
104 | 321 |
|
332 | 322 |
\subsection{Rewrite rules} |
4395 | 323 |
\begin{ttbox} |
324 |
addsimps : simpset * thm list -> simpset \hfill{\bf infix 4} |
|
325 |
delsimps : simpset * thm list -> simpset \hfill{\bf infix 4} |
|
326 |
\end{ttbox} |
|
327 |
||
328 |
\index{rewrite rules|(} Rewrite rules are theorems expressing some |
|
329 |
form of equality, for example: |
|
323 | 330 |
\begin{eqnarray*} |
331 |
Suc(\Var{m}) + \Var{n} &=& \Var{m} + Suc(\Var{n}) \\ |
|
332 |
\Var{P}\conj\Var{P} &\bimp& \Var{P} \\ |
|
714 | 333 |
\Var{A} \un \Var{B} &\equiv& \{x.x\in \Var{A} \disj x\in \Var{B}\} |
323 | 334 |
\end{eqnarray*} |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
335 |
Conditional rewrites such as $\Var{m}<\Var{n} \Imp \Var{m}/\Var{n} = |
4395 | 336 |
0$ are also permitted; the conditions can be arbitrary formulas. |
104 | 337 |
|
4395 | 338 |
Internally, all rewrite rules are translated into meta-equalities, |
339 |
theorems with conclusion $lhs \equiv rhs$. Each simpset contains a |
|
340 |
function for extracting equalities from arbitrary theorems. For |
|
341 |
example, $\neg(\Var{x}\in \{\})$ could be turned into $\Var{x}\in \{\} |
|
342 |
\equiv False$. This function can be installed using |
|
343 |
\ttindex{setmksimps} but only the definer of a logic should need to do |
|
344 |
this; see \S\ref{sec:setmksimps}. The function processes theorems |
|
345 |
added by \texttt{addsimps} as well as local assumptions. |
|
104 | 346 |
|
4395 | 347 |
\begin{ttdescription} |
348 |
||
349 |
\item[$ss$ \ttindexbold{addsimps} $thms$] adds rewrite rules derived |
|
350 |
from $thms$ to the simpset $ss$. |
|
351 |
||
352 |
\item[$ss$ \ttindexbold{delsimps} $thms$] deletes rewrite rules |
|
353 |
derived from $thms$ from the simpset $ss$. |
|
354 |
||
355 |
\end{ttdescription} |
|
104 | 356 |
|
332 | 357 |
\begin{warn} |
4395 | 358 |
The simplifier will accept all standard rewrite rules: those where |
359 |
all unknowns are of base type. Hence ${\Var{i}+(\Var{j}+\Var{k})} = |
|
360 |
{(\Var{i}+\Var{j})+\Var{k}}$ is OK. |
|
361 |
||
362 |
It will also deal gracefully with all rules whose left-hand sides |
|
363 |
are so-called {\em higher-order patterns}~\cite{nipkow-patterns}. |
|
364 |
\indexbold{higher-order pattern}\indexbold{pattern, higher-order} |
|
365 |
These are terms in $\beta$-normal form (this will always be the case |
|
366 |
unless you have done something strange) where each occurrence of an |
|
367 |
unknown is of the form $\Var{F}(x@1,\dots,x@n)$, where the $x@i$ are |
|
368 |
distinct bound variables. Hence $(\forall x.\Var{P}(x) \land |
|
369 |
\Var{Q}(x)) \bimp (\forall x.\Var{P}(x)) \land (\forall |
|
370 |
x.\Var{Q}(x))$ is also OK, in both directions. |
|
371 |
||
372 |
In some rare cases the rewriter will even deal with quite general |
|
373 |
rules: for example ${\Var{f}(\Var{x})\in range(\Var{f})} = True$ |
|
374 |
rewrites $g(a) \in range(g)$ to $True$, but will fail to match |
|
375 |
$g(h(b)) \in range(\lambda x.g(h(x)))$. However, you can replace |
|
376 |
the offending subterms (in our case $\Var{f}(\Var{x})$, which is not |
|
377 |
a pattern) by adding new variables and conditions: $\Var{y} = |
|
378 |
\Var{f}(\Var{x}) \Imp \Var{y}\in range(\Var{f}) = True$ is |
|
379 |
acceptable as a conditional rewrite rule since conditions can be |
|
380 |
arbitrary terms. |
|
381 |
||
382 |
There is basically no restriction on the form of the right-hand |
|
383 |
sides. They may not contain extraneous term or type variables, |
|
384 |
though. |
|
104 | 385 |
\end{warn} |
332 | 386 |
\index{rewrite rules|)} |
387 |
||
4395 | 388 |
|
4947 | 389 |
\subsection{*Simplification procedures} |
4395 | 390 |
\begin{ttbox} |
391 |
addsimprocs : simpset * simproc list -> simpset |
|
392 |
delsimprocs : simpset * simproc list -> simpset |
|
393 |
\end{ttbox} |
|
394 |
||
4557 | 395 |
Simplification procedures are {\ML} objects of abstract type |
396 |
\texttt{simproc}. Basically they are just functions that may produce |
|
4395 | 397 |
\emph{proven} rewrite rules on demand. They are associated with |
398 |
certain patterns that conceptually represent left-hand sides of |
|
399 |
equations; these are shown by \texttt{print_ss}. During its |
|
400 |
operation, the simplifier may offer a simplification procedure the |
|
401 |
current redex and ask for a suitable rewrite rule. Thus rules may be |
|
402 |
specifically fashioned for particular situations, resulting in a more |
|
403 |
powerful mechanism than term rewriting by a fixed set of rules. |
|
404 |
||
405 |
||
406 |
\begin{ttdescription} |
|
407 |
||
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
408 |
\item[$ss$ \ttindexbold{addsimprocs} $procs$] adds the simplification |
4395 | 409 |
procedures $procs$ to the current simpset. |
410 |
||
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
411 |
\item[$ss$ \ttindexbold{delsimprocs} $procs$] deletes the simplification |
4395 | 412 |
procedures $procs$ from the current simpset. |
413 |
||
414 |
\end{ttdescription} |
|
415 |
||
4557 | 416 |
For example, simplification procedures \ttindexbold{nat_cancel} of |
417 |
\texttt{HOL/Arith} cancel common summands and constant factors out of |
|
418 |
several relations of sums over natural numbers. |
|
419 |
||
420 |
Consider the following goal, which after cancelling $a$ on both sides |
|
421 |
contains a factor of $2$. Simplifying with the simpset of |
|
422 |
\texttt{Arith.thy} will do the cancellation automatically: |
|
423 |
\begin{ttbox} |
|
424 |
{\out 1. x + a + x < y + y + 2 + a + a + a + a + a} |
|
425 |
by (Simp_tac 1); |
|
426 |
{\out 1. x < Suc (a + (a + y))} |
|
427 |
\end{ttbox} |
|
428 |
||
4395 | 429 |
|
430 |
\subsection{*Congruence rules}\index{congruence rules}\label{sec:simp-congs} |
|
431 |
\begin{ttbox} |
|
432 |
addcongs : simpset * thm list -> simpset \hfill{\bf infix 4} |
|
433 |
delcongs : simpset * thm list -> simpset \hfill{\bf infix 4} |
|
434 |
addeqcongs : simpset * thm list -> simpset \hfill{\bf infix 4} |
|
435 |
deleqcongs : simpset * thm list -> simpset \hfill{\bf infix 4} |
|
436 |
\end{ttbox} |
|
437 |
||
104 | 438 |
Congruence rules are meta-equalities of the form |
3108 | 439 |
\[ \dots \Imp |
104 | 440 |
f(\Var{x@1},\ldots,\Var{x@n}) \equiv f(\Var{y@1},\ldots,\Var{y@n}). |
441 |
\] |
|
323 | 442 |
This governs the simplification of the arguments of~$f$. For |
104 | 443 |
example, some arguments can be simplified under additional assumptions: |
444 |
\[ \List{\Var{P@1} \bimp \Var{Q@1};\; \Var{Q@1} \Imp \Var{P@2} \bimp \Var{Q@2}} |
|
445 |
\Imp (\Var{P@1} \imp \Var{P@2}) \equiv (\Var{Q@1} \imp \Var{Q@2}) |
|
446 |
\] |
|
4395 | 447 |
Given this rule, the simplifier assumes $Q@1$ and extracts rewrite |
448 |
rules from it when simplifying~$P@2$. Such local assumptions are |
|
449 |
effective for rewriting formulae such as $x=0\imp y+x=y$. The local |
|
450 |
assumptions are also provided as theorems to the solver; see |
|
451 |
\S~\ref{sec:simp-solver} below. |
|
698
23734672dc12
updated discussion of congruence rules in first section
lcp
parents:
332
diff
changeset
|
452 |
|
4395 | 453 |
\begin{ttdescription} |
454 |
||
455 |
\item[$ss$ \ttindexbold{addcongs} $thms$] adds congruence rules to the |
|
456 |
simpset $ss$. These are derived from $thms$ in an appropriate way, |
|
457 |
depending on the underlying object-logic. |
|
458 |
||
459 |
\item[$ss$ \ttindexbold{delcongs} $thms$] deletes congruence rules |
|
460 |
derived from $thms$. |
|
461 |
||
462 |
\item[$ss$ \ttindexbold{addeqcongs} $thms$] adds congruence rules in |
|
463 |
their internal form (conclusions using meta-equality) to simpset |
|
464 |
$ss$. This is the basic mechanism that \texttt{addcongs} is built |
|
465 |
on. It should be rarely used directly. |
|
466 |
||
467 |
\item[$ss$ \ttindexbold{deleqcongs} $thms$] deletes congruence rules |
|
468 |
in internal form from simpset $ss$. |
|
469 |
||
470 |
\end{ttdescription} |
|
471 |
||
472 |
\medskip |
|
473 |
||
474 |
Here are some more examples. The congruence rule for bounded |
|
475 |
quantifiers also supplies contextual information, this time about the |
|
476 |
bound variable: |
|
286 | 477 |
\begin{eqnarray*} |
478 |
&&\List{\Var{A}=\Var{B};\; |
|
479 |
\Forall x. x\in \Var{B} \Imp \Var{P}(x) = \Var{Q}(x)} \Imp{} \\ |
|
480 |
&&\qquad\qquad |
|
481 |
(\forall x\in \Var{A}.\Var{P}(x)) = (\forall x\in \Var{B}.\Var{Q}(x)) |
|
482 |
\end{eqnarray*} |
|
323 | 483 |
The congruence rule for conditional expressions can supply contextual |
484 |
information for simplifying the arms: |
|
104 | 485 |
\[ \List{\Var{p}=\Var{q};~ \Var{q} \Imp \Var{a}=\Var{c};~ |
486 |
\neg\Var{q} \Imp \Var{b}=\Var{d}} \Imp |
|
487 |
if(\Var{p},\Var{a},\Var{b}) \equiv if(\Var{q},\Var{c},\Var{d}) |
|
488 |
\] |
|
698
23734672dc12
updated discussion of congruence rules in first section
lcp
parents:
332
diff
changeset
|
489 |
A congruence rule can also {\em prevent\/} simplification of some arguments. |
104 | 490 |
Here is an alternative congruence rule for conditional expressions: |
491 |
\[ \Var{p}=\Var{q} \Imp |
|
492 |
if(\Var{p},\Var{a},\Var{b}) \equiv if(\Var{q},\Var{a},\Var{b}) |
|
493 |
\] |
|
494 |
Only the first argument is simplified; the others remain unchanged. |
|
495 |
This can make simplification much faster, but may require an extra case split |
|
496 |
to prove the goal. |
|
497 |
||
498 |
||
4395 | 499 |
\subsection{*The subgoaler}\label{sec:simp-subgoaler} |
500 |
\begin{ttbox} |
|
501 |
setsubgoaler : simpset * (simpset -> int -> tactic) -> simpset \hfill{\bf infix 4} |
|
502 |
prems_of_ss : simpset -> thm list |
|
503 |
\end{ttbox} |
|
504 |
||
104 | 505 |
The subgoaler is the tactic used to solve subgoals arising out of |
506 |
conditional rewrite rules or congruence rules. The default should be |
|
4395 | 507 |
simplification itself. Occasionally this strategy needs to be |
508 |
changed. For example, if the premise of a conditional rule is an |
|
509 |
instance of its conclusion, as in $Suc(\Var{m}) < \Var{n} \Imp \Var{m} |
|
510 |
< \Var{n}$, the default strategy could loop. |
|
104 | 511 |
|
4395 | 512 |
\begin{ttdescription} |
513 |
||
514 |
\item[$ss$ \ttindexbold{setsubgoaler} $tacf$] sets the subgoaler of |
|
515 |
$ss$ to $tacf$. The function $tacf$ will be applied to the current |
|
516 |
simplifier context expressed as a simpset. |
|
517 |
||
518 |
\item[\ttindexbold{prems_of_ss} $ss$] retrieves the current set of |
|
519 |
premises from simplifier context $ss$. This may be non-empty only |
|
520 |
if the simplifier has been told to utilize local assumptions in the |
|
521 |
first place, e.g.\ if invoked via \texttt{asm_simp_tac}. |
|
522 |
||
523 |
\end{ttdescription} |
|
524 |
||
525 |
As an example, consider the following subgoaler: |
|
104 | 526 |
\begin{ttbox} |
4395 | 527 |
fun subgoaler ss = |
528 |
assume_tac ORELSE' |
|
529 |
resolve_tac (prems_of_ss ss) ORELSE' |
|
530 |
asm_simp_tac ss; |
|
104 | 531 |
\end{ttbox} |
4395 | 532 |
This tactic first tries to solve the subgoal by assumption or by |
533 |
resolving with with one of the premises, calling simplification only |
|
534 |
if that fails. |
|
535 |
||
104 | 536 |
|
698
23734672dc12
updated discussion of congruence rules in first section
lcp
parents:
332
diff
changeset
|
537 |
\subsection{*The solver}\label{sec:simp-solver} |
4395 | 538 |
\begin{ttbox} |
7620 | 539 |
mk_solver : string -> (thm list -> int -> tactic) -> solver |
540 |
setSolver : simpset * solver -> simpset \hfill{\bf infix 4} |
|
541 |
addSolver : simpset * solver -> simpset \hfill{\bf infix 4} |
|
542 |
setSSolver : simpset * solver -> simpset \hfill{\bf infix 4} |
|
543 |
addSSolver : simpset * solver -> simpset \hfill{\bf infix 4} |
|
4395 | 544 |
\end{ttbox} |
545 |
||
7620 | 546 |
A solver is a tactic that attempts to solve a subgoal after |
4395 | 547 |
simplification. Typically it just proves trivial subgoals such as |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
548 |
\texttt{True} and $t=t$. It could use sophisticated means such as {\tt |
4395 | 549 |
blast_tac}, though that could make simplification expensive. |
7620 | 550 |
To keep things more abstract, solvers are packaged up in type |
551 |
\texttt{solver}. The only way to create a solver is via \texttt{mk_solver}. |
|
286 | 552 |
|
3108 | 553 |
Rewriting does not instantiate unknowns. For example, rewriting |
554 |
cannot prove $a\in \Var{A}$ since this requires |
|
555 |
instantiating~$\Var{A}$. The solver, however, is an arbitrary tactic |
|
556 |
and may instantiate unknowns as it pleases. This is the only way the |
|
557 |
simplifier can handle a conditional rewrite rule whose condition |
|
3485
f27a30a18a17
Now there are TWO spaces after each full stop, so that the Emacs sentence
paulson
parents:
3134
diff
changeset
|
558 |
contains extra variables. When a simplification tactic is to be |
3108 | 559 |
combined with other provers, especially with the classical reasoner, |
4395 | 560 |
it is important whether it can be considered safe or not. For this |
7620 | 561 |
reason a simpset contains two solvers, a safe and an unsafe one. |
2628
1fe7c9f599c2
description of del(eq)congs, safe and unsafe solver
oheimb
parents:
2613
diff
changeset
|
562 |
|
3108 | 563 |
The standard simplification strategy solely uses the unsafe solver, |
4395 | 564 |
which is appropriate in most cases. For special applications where |
3108 | 565 |
the simplification process is not allowed to instantiate unknowns |
4395 | 566 |
within the goal, simplification starts with the safe solver, but may |
567 |
still apply the ordinary unsafe one in nested simplifications for |
|
568 |
conditional rules or congruences. |
|
569 |
||
570 |
\begin{ttdescription} |
|
7620 | 571 |
\item[\ttindexbold{mk_solver} $s$ $tacf$] converts $tacf$ into a new solver; |
572 |
the string $s$ is only attached as a comment and has no other significance. |
|
573 |
||
4395 | 574 |
\item[$ss$ \ttindexbold{setSSolver} $tacf$] installs $tacf$ as the |
575 |
\emph{safe} solver of $ss$. |
|
576 |
||
577 |
\item[$ss$ \ttindexbold{addSSolver} $tacf$] adds $tacf$ as an |
|
578 |
additional \emph{safe} solver; it will be tried after the solvers |
|
579 |
which had already been present in $ss$. |
|
580 |
||
581 |
\item[$ss$ \ttindexbold{setSolver} $tacf$] installs $tacf$ as the |
|
582 |
unsafe solver of $ss$. |
|
583 |
||
584 |
\item[$ss$ \ttindexbold{addSolver} $tacf$] adds $tacf$ as an |
|
585 |
additional unsafe solver; it will be tried after the solvers which |
|
586 |
had already been present in $ss$. |
|
323 | 587 |
|
4395 | 588 |
\end{ttdescription} |
589 |
||
590 |
\medskip |
|
104 | 591 |
|
4395 | 592 |
\index{assumptions!in simplification} The solver tactic is invoked |
593 |
with a list of theorems, namely assumptions that hold in the local |
|
594 |
context. This may be non-empty only if the simplifier has been told |
|
595 |
to utilize local assumptions in the first place, e.g.\ if invoked via |
|
596 |
\texttt{asm_simp_tac}. The solver is also presented the full goal |
|
597 |
including its assumptions in any case. Thus it can use these (e.g.\ |
|
598 |
by calling \texttt{assume_tac}), even if the list of premises is not |
|
599 |
passed. |
|
600 |
||
601 |
\medskip |
|
602 |
||
603 |
As explained in \S\ref{sec:simp-subgoaler}, the subgoaler is also used |
|
604 |
to solve the premises of congruence rules. These are usually of the |
|
605 |
form $s = \Var{x}$, where $s$ needs to be simplified and $\Var{x}$ |
|
606 |
needs to be instantiated with the result. Typically, the subgoaler |
|
607 |
will invoke the simplifier at some point, which will eventually call |
|
608 |
the solver. For this reason, solver tactics must be prepared to solve |
|
609 |
goals of the form $t = \Var{x}$, usually by reflexivity. In |
|
610 |
particular, reflexivity should be tried before any of the fancy |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
611 |
tactics like \texttt{blast_tac}. |
323 | 612 |
|
3108 | 613 |
It may even happen that due to simplification the subgoal is no longer |
614 |
an equality. For example $False \bimp \Var{Q}$ could be rewritten to |
|
615 |
$\neg\Var{Q}$. To cover this case, the solver could try resolving |
|
616 |
with the theorem $\neg False$. |
|
104 | 617 |
|
4395 | 618 |
\medskip |
619 |
||
104 | 620 |
\begin{warn} |
4395 | 621 |
If the simplifier aborts with the message \texttt{Failed congruence |
3108 | 622 |
proof!}, then the subgoaler or solver has failed to prove a |
623 |
premise of a congruence rule. This should never occur under normal |
|
624 |
circumstances; it indicates that some congruence rule, or possibly |
|
625 |
the subgoaler or solver, is faulty. |
|
104 | 626 |
\end{warn} |
627 |
||
323 | 628 |
|
4395 | 629 |
\subsection{*The looper}\label{sec:simp-looper} |
630 |
\begin{ttbox} |
|
5549 | 631 |
setloop : simpset * (int -> tactic) -> simpset \hfill{\bf infix 4} |
632 |
addloop : simpset * (string * (int -> tactic)) -> simpset \hfill{\bf infix 4} |
|
633 |
delloop : simpset * string -> simpset \hfill{\bf infix 4} |
|
4395 | 634 |
addsplits : simpset * thm list -> simpset \hfill{\bf infix 4} |
5549 | 635 |
delsplits : simpset * thm list -> simpset \hfill{\bf infix 4} |
4395 | 636 |
\end{ttbox} |
637 |
||
5549 | 638 |
The looper is a list of tactics that are applied after simplification, in case |
4395 | 639 |
the solver failed to solve the simplified goal. If the looper |
640 |
succeeds, the simplification process is started all over again. Each |
|
641 |
of the subgoals generated by the looper is attacked in turn, in |
|
642 |
reverse order. |
|
643 |
||
644 |
A typical looper is case splitting: the expansion of a conditional. |
|
645 |
Another possibility is to apply an elimination rule on the |
|
646 |
assumptions. More adventurous loopers could start an induction. |
|
647 |
||
648 |
\begin{ttdescription} |
|
649 |
||
5549 | 650 |
\item[$ss$ \ttindexbold{setloop} $tacf$] installs $tacf$ as the only looper |
651 |
tactic of $ss$. |
|
4395 | 652 |
|
5549 | 653 |
\item[$ss$ \ttindexbold{addloop} $(name,tacf)$] adds $tacf$ as an additional |
654 |
looper tactic with name $name$; it will be tried after the looper tactics |
|
655 |
that had already been present in $ss$. |
|
656 |
||
657 |
\item[$ss$ \ttindexbold{delloop} $name$] deletes the looper tactic $name$ |
|
658 |
from $ss$. |
|
4395 | 659 |
|
660 |
\item[$ss$ \ttindexbold{addsplits} $thms$] adds |
|
5549 | 661 |
split tactics for $thms$ as additional looper tactics of $ss$. |
662 |
||
663 |
\item[$ss$ \ttindexbold{addsplits} $thms$] deletes the |
|
664 |
split tactics for $thms$ from the looper tactics of $ss$. |
|
4395 | 665 |
|
666 |
\end{ttdescription} |
|
667 |
||
5549 | 668 |
The splitter replaces applications of a given function; the right-hand side |
669 |
of the replacement can be anything. For example, here is a splitting rule |
|
670 |
for conditional expressions: |
|
671 |
\[ \Var{P}(if(\Var{Q},\Var{x},\Var{y})) \bimp (\Var{Q} \imp \Var{P}(\Var{x})) |
|
672 |
\conj (\lnot\Var{Q} \imp \Var{P}(\Var{y})) |
|
673 |
\] |
|
674 |
Another example is the elimination operator (which happens to be |
|
675 |
called~$split$) for Cartesian products: |
|
676 |
\[ \Var{P}(split(\Var{f},\Var{p})) \bimp (\forall a~b. \Var{p} = |
|
677 |
\langle a,b\rangle \imp \Var{P}(\Var{f}(a,b))) |
|
678 |
\] |
|
679 |
||
680 |
For technical reasons, there is a distinction between case splitting in the |
|
681 |
conclusion and in the premises of a subgoal. The former is done by |
|
682 |
\texttt{split_tac} with rules like \texttt{split_if}, |
|
683 |
which does not split the subgoal, while the latter is done by |
|
684 |
\texttt{split_asm_tac} with rules like \texttt{split_if_asm}, |
|
685 |
which splits the subgoal. |
|
686 |
The operator \texttt{addsplits} automatically takes care of which tactic to |
|
687 |
call, analyzing the form of the rules given as argument. |
|
688 |
\begin{warn} |
|
689 |
Due to \texttt{split_asm_tac}, the simplifier may split subgoals! |
|
690 |
\end{warn} |
|
691 |
||
692 |
Case splits should be allowed only when necessary; they are expensive |
|
693 |
and hard to control. Here is an example of use, where \texttt{split_if} |
|
694 |
is the first rule above: |
|
695 |
\begin{ttbox} |
|
696 |
by (simp_tac (simpset() addloop ("split if",split_tac [split_if])) 1); |
|
697 |
\end{ttbox} |
|
5776 | 698 |
Users would usually prefer the following shortcut using \texttt{addsplits}: |
5549 | 699 |
\begin{ttbox} |
700 |
by (simp_tac (simpset() addsplits [split_if]) 1); |
|
701 |
\end{ttbox} |
|
104 | 702 |
|
703 |
||
4395 | 704 |
\section{The simplification tactics}\label{simp-tactics} |
705 |
\index{simplification!tactics}\index{tactics!simplification} |
|
706 |
\begin{ttbox} |
|
707 |
simp_tac : simpset -> int -> tactic |
|
708 |
asm_simp_tac : simpset -> int -> tactic |
|
709 |
full_simp_tac : simpset -> int -> tactic |
|
710 |
asm_full_simp_tac : simpset -> int -> tactic |
|
711 |
safe_asm_full_simp_tac : simpset -> int -> tactic |
|
712 |
\end{ttbox} |
|
2567 | 713 |
|
4395 | 714 |
These are the basic tactics that are underlying any actual |
715 |
simplification work. The rewriting strategy is always strictly bottom |
|
716 |
up, except for congruence rules, which are applied while descending |
|
717 |
into a term. Conditions in conditional rewrite rules are solved |
|
718 |
recursively before the rewrite rule is applied. |
|
104 | 719 |
|
4395 | 720 |
\begin{ttdescription} |
721 |
||
722 |
\item[\ttindexbold{simp_tac}, \ttindexbold{asm_simp_tac}, |
|
723 |
\ttindexbold{full_simp_tac}, \ttindexbold{asm_full_simp_tac}] are |
|
724 |
the basic simplification tactics that work exactly like their |
|
725 |
namesakes in \S\ref{sec:simp-for-dummies}, except that they are |
|
726 |
explicitly supplied with a simpset. |
|
727 |
||
728 |
\item[\ttindexbold{safe_asm_full_simp_tac}] is like |
|
729 |
\texttt{asm_full_simp_tac}, but uses the safe solver as explained in |
|
730 |
\S\ref{sec:simp-solver}. This tactic is mainly intended for |
|
731 |
building special tools, e.g.\ for combining the simplifier with the |
|
732 |
classical reasoner. It is rarely used directly. |
|
733 |
||
734 |
\end{ttdescription} |
|
104 | 735 |
|
4395 | 736 |
\medskip |
104 | 737 |
|
4395 | 738 |
Local modifications of simpsets within a proof are often much cleaner |
739 |
by using above tactics in conjunction with explicit simpsets, rather |
|
740 |
than their capitalized counterparts. For example |
|
1213 | 741 |
\begin{ttbox} |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
742 |
Addsimps \(thms\); |
2479 | 743 |
by (Simp_tac \(i\)); |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
744 |
Delsimps \(thms\); |
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
745 |
\end{ttbox} |
4395 | 746 |
can be expressed more appropriately as |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
747 |
\begin{ttbox} |
4395 | 748 |
by (simp_tac (simpset() addsimps \(thms\)) \(i\)); |
1213 | 749 |
\end{ttbox} |
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
750 |
|
4395 | 751 |
\medskip |
752 |
||
753 |
Also note that functions depending implicitly on the current theory |
|
754 |
context (like capital \texttt{Simp_tac} and the other commands of |
|
755 |
\S\ref{sec:simp-for-dummies}) should be considered harmful outside of |
|
756 |
actual proof scripts. In particular, ML programs like theory |
|
757 |
definition packages or special tactics should refer to simpsets only |
|
758 |
explicitly, via the above tactics used in conjunction with |
|
759 |
\texttt{simpset_of} or the \texttt{SIMPSET} tacticals. |
|
760 |
||
1860
71bfeecfa96c
Documented simplification tactics which make use of the implicit simpset.
nipkow
parents:
1387
diff
changeset
|
761 |
|
5370 | 762 |
\section{Forward rules and conversions} |
763 |
\index{simplification!forward rules}\index{simplification!conversions} |
|
764 |
\begin{ttbox}\index{*simplify}\index{*asm_simplify}\index{*full_simplify}\index{*asm_full_simplify}\index{*Simplifier.rewrite}\index{*Simplifier.asm_rewrite}\index{*Simplifier.full_rewrite}\index{*Simplifier.asm_full_rewrite} |
|
4395 | 765 |
simplify : simpset -> thm -> thm |
766 |
asm_simplify : simpset -> thm -> thm |
|
767 |
full_simplify : simpset -> thm -> thm |
|
5370 | 768 |
asm_full_simplify : simpset -> thm -> thm\medskip |
769 |
Simplifier.rewrite : simpset -> cterm -> thm |
|
770 |
Simplifier.asm_rewrite : simpset -> cterm -> thm |
|
771 |
Simplifier.full_rewrite : simpset -> cterm -> thm |
|
772 |
Simplifier.asm_full_rewrite : simpset -> cterm -> thm |
|
4395 | 773 |
\end{ttbox} |
774 |
||
5370 | 775 |
The first four of these functions provide \emph{forward} rules for |
776 |
simplification. Their effect is analogous to the corresponding |
|
777 |
tactics described in \S\ref{simp-tactics}, but affect the whole |
|
778 |
theorem instead of just a certain subgoal. Also note that the |
|
779 |
looper~/ solver process as described in \S\ref{sec:simp-looper} and |
|
780 |
\S\ref{sec:simp-solver} is omitted in forward simplification. |
|
781 |
||
782 |
The latter four are \emph{conversions}, establishing proven equations |
|
783 |
of the form $t \equiv u$ where the l.h.s.\ $t$ has been given as |
|
784 |
argument. |
|
4395 | 785 |
|
786 |
\begin{warn} |
|
5370 | 787 |
Forward simplification rules and conversions should be used rarely |
788 |
in ordinary proof scripts. The main intention is to provide an |
|
789 |
internal interface to the simplifier for special utilities. |
|
4395 | 790 |
\end{warn} |
791 |
||
792 |
||
793 |
\section{Examples of using the simplifier} |
|
3112 | 794 |
\index{examples!of simplification} Assume we are working within {\tt |
5205 | 795 |
FOL} (see the file \texttt{FOL/ex/Nat}) and that |
323 | 796 |
\begin{ttdescription} |
797 |
\item[Nat.thy] |
|
798 |
is a theory including the constants $0$, $Suc$ and $+$, |
|
799 |
\item[add_0] |
|
800 |
is the rewrite rule $0+\Var{n} = \Var{n}$, |
|
801 |
\item[add_Suc] |
|
802 |
is the rewrite rule $Suc(\Var{m})+\Var{n} = Suc(\Var{m}+\Var{n})$, |
|
803 |
\item[induct] |
|
804 |
is the induction rule $\List{\Var{P}(0);\; \Forall x. \Var{P}(x)\Imp |
|
805 |
\Var{P}(Suc(x))} \Imp \Var{P}(\Var{n})$. |
|
806 |
\end{ttdescription} |
|
4395 | 807 |
We augment the implicit simpset inherited from \texttt{Nat} with the |
4557 | 808 |
basic rewrite rules for addition of natural numbers: |
104 | 809 |
\begin{ttbox} |
3112 | 810 |
Addsimps [add_0, add_Suc]; |
104 | 811 |
\end{ttbox} |
323 | 812 |
|
813 |
\subsection{A trivial example} |
|
286 | 814 |
Proofs by induction typically involve simplification. Here is a proof |
815 |
that~0 is a right identity: |
|
104 | 816 |
\begin{ttbox} |
5205 | 817 |
Goal "m+0 = m"; |
104 | 818 |
{\out Level 0} |
819 |
{\out m + 0 = m} |
|
820 |
{\out 1. m + 0 = m} |
|
286 | 821 |
\end{ttbox} |
822 |
The first step is to perform induction on the variable~$m$. This returns a |
|
823 |
base case and inductive step as two subgoals: |
|
824 |
\begin{ttbox} |
|
104 | 825 |
by (res_inst_tac [("n","m")] induct 1); |
826 |
{\out Level 1} |
|
827 |
{\out m + 0 = m} |
|
828 |
{\out 1. 0 + 0 = 0} |
|
829 |
{\out 2. !!x. x + 0 = x ==> Suc(x) + 0 = Suc(x)} |
|
830 |
\end{ttbox} |
|
286 | 831 |
Simplification solves the first subgoal trivially: |
104 | 832 |
\begin{ttbox} |
3112 | 833 |
by (Simp_tac 1); |
104 | 834 |
{\out Level 2} |
835 |
{\out m + 0 = m} |
|
836 |
{\out 1. !!x. x + 0 = x ==> Suc(x) + 0 = Suc(x)} |
|
837 |
\end{ttbox} |
|
3112 | 838 |
The remaining subgoal requires \ttindex{Asm_simp_tac} in order to use the |
104 | 839 |
induction hypothesis as a rewrite rule: |
840 |
\begin{ttbox} |
|
3112 | 841 |
by (Asm_simp_tac 1); |
104 | 842 |
{\out Level 3} |
843 |
{\out m + 0 = m} |
|
844 |
{\out No subgoals!} |
|
845 |
\end{ttbox} |
|
846 |
||
323 | 847 |
\subsection{An example of tracing} |
3108 | 848 |
\index{tracing!of simplification|(}\index{*trace_simp} |
4557 | 849 |
|
850 |
Let us prove a similar result involving more complex terms. We prove |
|
851 |
that addition is commutative. |
|
104 | 852 |
\begin{ttbox} |
5205 | 853 |
Goal "m+Suc(n) = Suc(m+n)"; |
104 | 854 |
{\out Level 0} |
855 |
{\out m + Suc(n) = Suc(m + n)} |
|
856 |
{\out 1. m + Suc(n) = Suc(m + n)} |
|
286 | 857 |
\end{ttbox} |
4557 | 858 |
Performing induction on~$m$ yields two subgoals: |
286 | 859 |
\begin{ttbox} |
104 | 860 |
by (res_inst_tac [("n","m")] induct 1); |
861 |
{\out Level 1} |
|
862 |
{\out m + Suc(n) = Suc(m + n)} |
|
863 |
{\out 1. 0 + Suc(n) = Suc(0 + n)} |
|
286 | 864 |
{\out 2. !!x. x + Suc(n) = Suc(x + n) ==>} |
865 |
{\out Suc(x) + Suc(n) = Suc(Suc(x) + n)} |
|
866 |
\end{ttbox} |
|
867 |
Simplification solves the first subgoal, this time rewriting two |
|
868 |
occurrences of~0: |
|
869 |
\begin{ttbox} |
|
3112 | 870 |
by (Simp_tac 1); |
104 | 871 |
{\out Level 2} |
872 |
{\out m + Suc(n) = Suc(m + n)} |
|
286 | 873 |
{\out 1. !!x. x + Suc(n) = Suc(x + n) ==>} |
874 |
{\out Suc(x) + Suc(n) = Suc(Suc(x) + n)} |
|
104 | 875 |
\end{ttbox} |
876 |
Switching tracing on illustrates how the simplifier solves the remaining |
|
877 |
subgoal: |
|
878 |
\begin{ttbox} |
|
4395 | 879 |
set trace_simp; |
3112 | 880 |
by (Asm_simp_tac 1); |
323 | 881 |
\ttbreak |
3112 | 882 |
{\out Adding rewrite rule:} |
5370 | 883 |
{\out .x + Suc n == Suc (.x + n)} |
323 | 884 |
\ttbreak |
5370 | 885 |
{\out Applying instance of rewrite rule:} |
886 |
{\out ?m + Suc ?n == Suc (?m + ?n)} |
|
104 | 887 |
{\out Rewriting:} |
5370 | 888 |
{\out Suc .x + Suc n == Suc (Suc .x + n)} |
323 | 889 |
\ttbreak |
5370 | 890 |
{\out Applying instance of rewrite rule:} |
891 |
{\out Suc ?m + ?n == Suc (?m + ?n)} |
|
104 | 892 |
{\out Rewriting:} |
5370 | 893 |
{\out Suc .x + n == Suc (.x + n)} |
323 | 894 |
\ttbreak |
5370 | 895 |
{\out Applying instance of rewrite rule:} |
896 |
{\out Suc ?m + ?n == Suc (?m + ?n)} |
|
104 | 897 |
{\out Rewriting:} |
5370 | 898 |
{\out Suc .x + n == Suc (.x + n)} |
3112 | 899 |
\ttbreak |
5370 | 900 |
{\out Applying instance of rewrite rule:} |
901 |
{\out ?x = ?x == True} |
|
3112 | 902 |
{\out Rewriting:} |
5370 | 903 |
{\out Suc (Suc (.x + n)) = Suc (Suc (.x + n)) == True} |
323 | 904 |
\ttbreak |
104 | 905 |
{\out Level 3} |
906 |
{\out m + Suc(n) = Suc(m + n)} |
|
907 |
{\out No subgoals!} |
|
908 |
\end{ttbox} |
|
286 | 909 |
Many variations are possible. At Level~1 (in either example) we could have |
910 |
solved both subgoals at once using the tactical \ttindex{ALLGOALS}: |
|
104 | 911 |
\begin{ttbox} |
3112 | 912 |
by (ALLGOALS Asm_simp_tac); |
104 | 913 |
{\out Level 2} |
914 |
{\out m + Suc(n) = Suc(m + n)} |
|
915 |
{\out No subgoals!} |
|
916 |
\end{ttbox} |
|
3108 | 917 |
\index{tracing!of simplification|)} |
104 | 918 |
|
4557 | 919 |
|
323 | 920 |
\subsection{Free variables and simplification} |
4557 | 921 |
|
922 |
Here is a conjecture to be proved for an arbitrary function~$f$ |
|
923 |
satisfying the law $f(Suc(\Var{n})) = Suc(f(\Var{n}))$: |
|
104 | 924 |
\begin{ttbox} |
5205 | 925 |
val [prem] = Goal "(!!n. f(Suc(n)) = Suc(f(n))) ==> f(i+j) = i+f(j)"; |
104 | 926 |
{\out Level 0} |
927 |
{\out f(i + j) = i + f(j)} |
|
928 |
{\out 1. f(i + j) = i + f(j)} |
|
323 | 929 |
\ttbreak |
286 | 930 |
{\out val prem = "f(Suc(?n)) = Suc(f(?n))} |
931 |
{\out [!!n. f(Suc(n)) = Suc(f(n))]" : thm} |
|
323 | 932 |
\end{ttbox} |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
933 |
In the theorem~\texttt{prem}, note that $f$ is a free variable while |
323 | 934 |
$\Var{n}$ is a schematic variable. |
935 |
\begin{ttbox} |
|
104 | 936 |
by (res_inst_tac [("n","i")] induct 1); |
937 |
{\out Level 1} |
|
938 |
{\out f(i + j) = i + f(j)} |
|
939 |
{\out 1. f(0 + j) = 0 + f(j)} |
|
940 |
{\out 2. !!x. f(x + j) = x + f(j) ==> f(Suc(x) + j) = Suc(x) + f(j)} |
|
941 |
\end{ttbox} |
|
942 |
We simplify each subgoal in turn. The first one is trivial: |
|
943 |
\begin{ttbox} |
|
3112 | 944 |
by (Simp_tac 1); |
104 | 945 |
{\out Level 2} |
946 |
{\out f(i + j) = i + f(j)} |
|
947 |
{\out 1. !!x. f(x + j) = x + f(j) ==> f(Suc(x) + j) = Suc(x) + f(j)} |
|
948 |
\end{ttbox} |
|
3112 | 949 |
The remaining subgoal requires rewriting by the premise, so we add it |
4395 | 950 |
to the current simpset: |
104 | 951 |
\begin{ttbox} |
4395 | 952 |
by (asm_simp_tac (simpset() addsimps [prem]) 1); |
104 | 953 |
{\out Level 3} |
954 |
{\out f(i + j) = i + f(j)} |
|
955 |
{\out No subgoals!} |
|
956 |
\end{ttbox} |
|
957 |
||
1213 | 958 |
\subsection{Reordering assumptions} |
959 |
\label{sec:reordering-asms} |
|
960 |
\index{assumptions!reordering} |
|
961 |
||
4395 | 962 |
As mentioned in \S\ref{sec:simp-for-dummies-tacs}, |
963 |
\ttindex{asm_full_simp_tac} may require the assumptions to be permuted |
|
964 |
to be more effective. Given the subgoal |
|
1213 | 965 |
\begin{ttbox} |
4889 | 966 |
{\out 1. [| ALL x. P x --> f x = g x; Q(f a); P a; R |] ==> S} |
1213 | 967 |
\end{ttbox} |
968 |
we can rotate the assumptions two positions to the right |
|
969 |
\begin{ttbox} |
|
970 |
by (rotate_tac ~2 1); |
|
971 |
\end{ttbox} |
|
972 |
to obtain |
|
973 |
\begin{ttbox} |
|
4889 | 974 |
{\out 1. [| P a; R; ALL x. P x --> f x = g x; Q(f a) |] ==> S} |
1213 | 975 |
\end{ttbox} |
4889 | 976 |
which enables \verb$asm_full_simp_tac$ to simplify \verb$Q(f a)$ to |
977 |
\verb$Q(g a)$ because now all required assumptions are to the left of |
|
978 |
\verb$Q(f a)$. |
|
1213 | 979 |
|
980 |
Since rotation alone cannot produce arbitrary permutations, you can also pick |
|
981 |
out a particular assumption which needs to be rewritten and move it the the |
|
3485
f27a30a18a17
Now there are TWO spaces after each full stop, so that the Emacs sentence
paulson
parents:
3134
diff
changeset
|
982 |
right end of the assumptions. In the above case rotation can be replaced by |
1213 | 983 |
\begin{ttbox} |
4889 | 984 |
by (dres_inst_tac [("psi","Q(f a)")] asm_rl 1); |
1213 | 985 |
\end{ttbox} |
986 |
which is more directed and leads to |
|
987 |
\begin{ttbox} |
|
4889 | 988 |
{\out 1. [| ALL x. P x --> f x = g x; P a; R; Q(f a) |] ==> S} |
1213 | 989 |
\end{ttbox} |
990 |
||
4395 | 991 |
\begin{warn} |
992 |
Reordering assumptions usually leads to brittle proofs and should be |
|
4889 | 993 |
avoided. Future versions of \verb$asm_full_simp_tac$ will completely |
994 |
remove the need for such manipulations. |
|
4395 | 995 |
\end{warn} |
996 |
||
286 | 997 |
|
332 | 998 |
\section{Permutative rewrite rules} |
323 | 999 |
\index{rewrite rules!permutative|(} |
1000 |
||
1001 |
A rewrite rule is {\bf permutative} if the left-hand side and right-hand |
|
1002 |
side are the same up to renaming of variables. The most common permutative |
|
1003 |
rule is commutativity: $x+y = y+x$. Other examples include $(x-y)-z = |
|
1004 |
(x-z)-y$ in arithmetic and $insert(x,insert(y,A)) = insert(y,insert(x,A))$ |
|
1005 |
for sets. Such rules are common enough to merit special attention. |
|
1006 |
||
4395 | 1007 |
Because ordinary rewriting loops given such rules, the simplifier |
1008 |
employs a special strategy, called {\bf ordered |
|
1009 |
rewriting}\index{rewriting!ordered}. There is a standard |
|
1010 |
lexicographic ordering on terms. This should be perfectly OK in most |
|
1011 |
cases, but can be changed for special applications. |
|
1012 |
||
4947 | 1013 |
\begin{ttbox} |
1014 |
settermless : simpset * (term * term -> bool) -> simpset \hfill{\bf infix 4} |
|
1015 |
\end{ttbox} |
|
4395 | 1016 |
\begin{ttdescription} |
1017 |
||
1018 |
\item[$ss$ \ttindexbold{settermless} $rel$] installs relation $rel$ as |
|
1019 |
term order in simpset $ss$. |
|
1020 |
||
1021 |
\end{ttdescription} |
|
1022 |
||
1023 |
\medskip |
|
323 | 1024 |
|
4395 | 1025 |
A permutative rewrite rule is applied only if it decreases the given |
1026 |
term with respect to this ordering. For example, commutativity |
|
1027 |
rewrites~$b+a$ to $a+b$, but then stops because $a+b$ is strictly less |
|
1028 |
than $b+a$. The Boyer-Moore theorem prover~\cite{bm88book} also |
|
1029 |
employs ordered rewriting. |
|
1030 |
||
1031 |
Permutative rewrite rules are added to simpsets just like other |
|
1032 |
rewrite rules; the simplifier recognizes their special status |
|
1033 |
automatically. They are most effective in the case of |
|
1034 |
associative-commutative operators. (Associativity by itself is not |
|
1035 |
permutative.) When dealing with an AC-operator~$f$, keep the |
|
1036 |
following points in mind: |
|
323 | 1037 |
\begin{itemize}\index{associative-commutative operators} |
4395 | 1038 |
|
1039 |
\item The associative law must always be oriented from left to right, |
|
1040 |
namely $f(f(x,y),z) = f(x,f(y,z))$. The opposite orientation, if |
|
1041 |
used with commutativity, leads to looping in conjunction with the |
|
1042 |
standard term order. |
|
323 | 1043 |
|
1044 |
\item To complete your set of rewrite rules, you must add not just |
|
1045 |
associativity~(A) and commutativity~(C) but also a derived rule, {\bf |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1046 |
left-com\-mut\-ativ\-ity} (LC): $f(x,f(y,z)) = f(y,f(x,z))$. |
323 | 1047 |
\end{itemize} |
1048 |
Ordered rewriting with the combination of A, C, and~LC sorts a term |
|
1049 |
lexicographically: |
|
1050 |
\[\def\maps#1{\stackrel{#1}{\longmapsto}} |
|
1051 |
(b+c)+a \maps{A} b+(c+a) \maps{C} b+(a+c) \maps{LC} a+(b+c) \] |
|
1052 |
Martin and Nipkow~\cite{martin-nipkow} discuss the theory and give many |
|
1053 |
examples; other algebraic structures are amenable to ordered rewriting, |
|
1054 |
such as boolean rings. |
|
1055 |
||
3108 | 1056 |
\subsection{Example: sums of natural numbers} |
4395 | 1057 |
|
1058 |
This example is again set in \HOL\ (see \texttt{HOL/ex/NatSum}). |
|
1059 |
Theory \thydx{Arith} contains natural numbers arithmetic. Its |
|
1060 |
associated simpset contains many arithmetic laws including |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1061 |
distributivity of~$\times$ over~$+$, while \texttt{add_ac} is a list |
4395 | 1062 |
consisting of the A, C and LC laws for~$+$ on type \texttt{nat}. Let |
1063 |
us prove the theorem |
|
323 | 1064 |
\[ \sum@{i=1}^n i = n\times(n+1)/2. \] |
1065 |
% |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1066 |
A functional~\texttt{sum} represents the summation operator under the |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1067 |
interpretation $\texttt{sum} \, f \, (n + 1) = \sum@{i=0}^n f\,i$. We |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1068 |
extend \texttt{Arith} as follows: |
323 | 1069 |
\begin{ttbox} |
1070 |
NatSum = Arith + |
|
1387 | 1071 |
consts sum :: [nat=>nat, nat] => nat |
4245 | 1072 |
primrec "sum" nat |
1073 |
"sum f 0 = 0" |
|
1074 |
"sum f (Suc n) = f(n) + sum f n" |
|
323 | 1075 |
end |
1076 |
\end{ttbox} |
|
4245 | 1077 |
The \texttt{primrec} declaration automatically adds rewrite rules for |
4557 | 1078 |
\texttt{sum} to the default simpset. We now remove the |
1079 |
\texttt{nat_cancel} simplification procedures (in order not to spoil |
|
1080 |
the example) and insert the AC-rules for~$+$: |
|
323 | 1081 |
\begin{ttbox} |
4557 | 1082 |
Delsimprocs nat_cancel; |
4245 | 1083 |
Addsimps add_ac; |
323 | 1084 |
\end{ttbox} |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1085 |
Our desired theorem now reads $\texttt{sum} \, (\lambda i.i) \, (n+1) = |
323 | 1086 |
n\times(n+1)/2$. The Isabelle goal has both sides multiplied by~$2$: |
1087 |
\begin{ttbox} |
|
5205 | 1088 |
Goal "2 * sum (\%i.i) (Suc n) = n * Suc n"; |
323 | 1089 |
{\out Level 0} |
3108 | 1090 |
{\out 2 * sum (\%i. i) (Suc n) = n * Suc n} |
1091 |
{\out 1. 2 * sum (\%i. i) (Suc n) = n * Suc n} |
|
323 | 1092 |
\end{ttbox} |
3108 | 1093 |
Induction should not be applied until the goal is in the simplest |
1094 |
form: |
|
323 | 1095 |
\begin{ttbox} |
4245 | 1096 |
by (Simp_tac 1); |
323 | 1097 |
{\out Level 1} |
3108 | 1098 |
{\out 2 * sum (\%i. i) (Suc n) = n * Suc n} |
1099 |
{\out 1. n + (sum (\%i. i) n + sum (\%i. i) n) = n * n} |
|
323 | 1100 |
\end{ttbox} |
3108 | 1101 |
Ordered rewriting has sorted the terms in the left-hand side. The |
1102 |
subgoal is now ready for induction: |
|
323 | 1103 |
\begin{ttbox} |
4245 | 1104 |
by (induct_tac "n" 1); |
323 | 1105 |
{\out Level 2} |
3108 | 1106 |
{\out 2 * sum (\%i. i) (Suc n) = n * Suc n} |
1107 |
{\out 1. 0 + (sum (\%i. i) 0 + sum (\%i. i) 0) = 0 * 0} |
|
323 | 1108 |
\ttbreak |
4245 | 1109 |
{\out 2. !!n. n + (sum (\%i. i) n + sum (\%i. i) n) = n * n} |
1110 |
{\out ==> Suc n + (sum (\%i. i) (Suc n) + sum (\%i. i) (Suc n)) =} |
|
1111 |
{\out Suc n * Suc n} |
|
323 | 1112 |
\end{ttbox} |
1113 |
Simplification proves both subgoals immediately:\index{*ALLGOALS} |
|
1114 |
\begin{ttbox} |
|
4245 | 1115 |
by (ALLGOALS Asm_simp_tac); |
323 | 1116 |
{\out Level 3} |
3108 | 1117 |
{\out 2 * sum (\%i. i) (Suc n) = n * Suc n} |
323 | 1118 |
{\out No subgoals!} |
1119 |
\end{ttbox} |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1120 |
Simplification cannot prove the induction step if we omit \texttt{add_ac} from |
4245 | 1121 |
the simpset. Observe that like terms have not been collected: |
323 | 1122 |
\begin{ttbox} |
4245 | 1123 |
{\out Level 3} |
1124 |
{\out 2 * sum (\%i. i) (Suc n) = n * Suc n} |
|
1125 |
{\out 1. !!n. n + sum (\%i. i) n + (n + sum (\%i. i) n) = n + n * n} |
|
1126 |
{\out ==> n + (n + sum (\%i. i) n) + (n + (n + sum (\%i. i) n)) =} |
|
1127 |
{\out n + (n + (n + n * n))} |
|
323 | 1128 |
\end{ttbox} |
1129 |
Ordered rewriting proves this by sorting the left-hand side. Proving |
|
1130 |
arithmetic theorems without ordered rewriting requires explicit use of |
|
1131 |
commutativity. This is tedious; try it and see! |
|
1132 |
||
1133 |
Ordered rewriting is equally successful in proving |
|
1134 |
$\sum@{i=1}^n i^3 = n^2\times(n+1)^2/4$. |
|
1135 |
||
1136 |
||
1137 |
\subsection{Re-orienting equalities} |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1138 |
Ordered rewriting with the derived rule \texttt{symmetry} can reverse |
4557 | 1139 |
equations: |
323 | 1140 |
\begin{ttbox} |
1141 |
val symmetry = prove_goal HOL.thy "(x=y) = (y=x)" |
|
3128
d01d4c0c4b44
New acknowledgements; fixed overfull lines and tables
paulson
parents:
3112
diff
changeset
|
1142 |
(fn _ => [Blast_tac 1]); |
323 | 1143 |
\end{ttbox} |
1144 |
This is frequently useful. Assumptions of the form $s=t$, where $t$ occurs |
|
1145 |
in the conclusion but not~$s$, can often be brought into the right form. |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1146 |
For example, ordered rewriting with \texttt{symmetry} can prove the goal |
323 | 1147 |
\[ f(a)=b \conj f(a)=c \imp b=c. \] |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1148 |
Here \texttt{symmetry} reverses both $f(a)=b$ and $f(a)=c$ |
323 | 1149 |
because $f(a)$ is lexicographically greater than $b$ and~$c$. These |
1150 |
re-oriented equations, as rewrite rules, replace $b$ and~$c$ in the |
|
1151 |
conclusion by~$f(a)$. |
|
1152 |
||
1153 |
Another example is the goal $\neg(t=u) \imp \neg(u=t)$. |
|
1154 |
The differing orientations make this appear difficult to prove. Ordered |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1155 |
rewriting with \texttt{symmetry} makes the equalities agree. (Without |
323 | 1156 |
knowing more about~$t$ and~$u$ we cannot say whether they both go to $t=u$ |
1157 |
or~$u=t$.) Then the simplifier can prove the goal outright. |
|
1158 |
||
1159 |
\index{rewrite rules!permutative|)} |
|
1160 |
||
1161 |
||
4395 | 1162 |
\section{*Coding simplification procedures} |
1163 |
\begin{ttbox} |
|
1164 |
mk_simproc: string -> cterm list -> |
|
1165 |
(Sign.sg -> thm list -> term -> thm option) -> simproc |
|
1166 |
\end{ttbox} |
|
1167 |
||
1168 |
\begin{ttdescription} |
|
1169 |
\item[\ttindexbold{mk_simproc}~$name$~$lhss$~$proc$] makes $proc$ a |
|
1170 |
simplification procedure for left-hand side patterns $lhss$. The |
|
1171 |
name just serves as a comment. The function $proc$ may be invoked |
|
1172 |
by the simplifier for redex positions matched by one of $lhss$ as |
|
1173 |
described below. |
|
1174 |
\end{ttdescription} |
|
1175 |
||
1176 |
Simplification procedures are applied in a two-stage process as |
|
1177 |
follows: The simplifier tries to match the current redex position |
|
1178 |
against any one of the $lhs$ patterns of any simplification procedure. |
|
1179 |
If this succeeds, it invokes the corresponding {\ML} function, passing |
|
1180 |
with the current signature, local assumptions and the (potential) |
|
1181 |
redex. The result may be either \texttt{None} (indicating failure) or |
|
1182 |
\texttt{Some~$thm$}. |
|
1183 |
||
1184 |
Any successful result is supposed to be a (possibly conditional) |
|
1185 |
rewrite rule $t \equiv u$ that is applicable to the current redex. |
|
1186 |
The rule will be applied just as any ordinary rewrite rule. It is |
|
1187 |
expected to be already in \emph{internal form}, though, bypassing the |
|
1188 |
automatic preprocessing of object-level equivalences. |
|
1189 |
||
1190 |
\medskip |
|
1191 |
||
1192 |
As an example of how to write your own simplification procedures, |
|
1193 |
consider eta-expansion of pair abstraction (see also |
|
1194 |
\texttt{HOL/Modelcheck/MCSyn} where this is used to provide external |
|
1195 |
model checker syntax). |
|
1196 |
||
1197 |
The {\HOL} theory of tuples (see \texttt{HOL/Prod}) provides an |
|
1198 |
operator \texttt{split} together with some concrete syntax supporting |
|
1199 |
$\lambda\,(x,y).b$ abstractions. Assume that we would like to offer a |
|
1200 |
tactic that rewrites any function $\lambda\,p.f\,p$ (where $p$ is of |
|
1201 |
some pair type) to $\lambda\,(x,y).f\,(x,y)$. The corresponding rule |
|
1202 |
is: |
|
1203 |
\begin{ttbox} |
|
1204 |
pair_eta_expand: (f::'a*'b=>'c) = (\%(x, y). f (x, y)) |
|
1205 |
\end{ttbox} |
|
1206 |
Unfortunately, term rewriting using this rule directly would not |
|
1207 |
terminate! We now use the simplification procedure mechanism in order |
|
1208 |
to stop the simplifier from applying this rule over and over again, |
|
1209 |
making it rewrite only actual abstractions. The simplification |
|
1210 |
procedure \texttt{pair_eta_expand_proc} is defined as follows: |
|
1211 |
\begin{ttbox} |
|
1212 |
local |
|
1213 |
val lhss = |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1214 |
[read_cterm (sign_of Prod.thy) |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1215 |
("f::'a*'b=>'c", TVar (("'z", 0), []))]; |
4395 | 1216 |
val rew = mk_meta_eq pair_eta_expand; \medskip |
1217 |
fun proc _ _ (Abs _) = Some rew |
|
1218 |
| proc _ _ _ = None; |
|
1219 |
in |
|
4560 | 1220 |
val pair_eta_expand_proc = mk_simproc "pair_eta_expand" lhss proc; |
4395 | 1221 |
end; |
1222 |
\end{ttbox} |
|
1223 |
This is an example of using \texttt{pair_eta_expand_proc}: |
|
1224 |
\begin{ttbox} |
|
1225 |
{\out 1. P (\%p::'a * 'a. fst p + snd p + z)} |
|
1226 |
by (simp_tac (simpset() addsimprocs [pair_eta_expand_proc]) 1); |
|
1227 |
{\out 1. P (\%(x::'a,y::'a). x + y + z)} |
|
1228 |
\end{ttbox} |
|
1229 |
||
1230 |
\medskip |
|
1231 |
||
1232 |
In the above example the simplification procedure just did fine |
|
1233 |
grained control over rule application, beyond higher-order pattern |
|
1234 |
matching. Usually, procedures would do some more work, in particular |
|
1235 |
prove particular theorems depending on the current redex. |
|
1236 |
||
1237 |
||
323 | 1238 |
\section{*Setting up the simplifier}\label{sec:setting-up-simp} |
1239 |
\index{simplification!setting up} |
|
286 | 1240 |
|
1241 |
Setting up the simplifier for new logics is complicated. This section |
|
4395 | 1242 |
describes how the simplifier is installed for intuitionistic |
1243 |
first-order logic; the code is largely taken from {\tt |
|
1244 |
FOL/simpdata.ML} of the Isabelle sources. |
|
286 | 1245 |
|
6569 | 1246 |
The simplifier and the case splitting tactic, which reside on separate files, |
1247 |
are not part of Pure Isabelle. They must be loaded explicitly by the |
|
1248 |
object-logic as follows (below \texttt{\~\relax\~\relax} refers to |
|
1249 |
\texttt{\$ISABELLE_HOME}): |
|
286 | 1250 |
\begin{ttbox} |
6569 | 1251 |
use "\~\relax\~\relax/src/Provers/simplifier.ML"; |
1252 |
use "\~\relax\~\relax/src/Provers/splitter.ML"; |
|
286 | 1253 |
\end{ttbox} |
1254 |
||
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1255 |
Simplification requires converting object-equalities to meta-level rewrite |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1256 |
rules. This demands rules stating that equal terms and equivalent formulae |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1257 |
are also equal at the meta-level. The rule declaration part of the file |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1258 |
\texttt{FOL/IFOL.thy} contains the two lines |
323 | 1259 |
\begin{ttbox}\index{*eq_reflection theorem}\index{*iff_reflection theorem} |
286 | 1260 |
eq_reflection "(x=y) ==> (x==y)" |
1261 |
iff_reflection "(P<->Q) ==> (P==Q)" |
|
1262 |
\end{ttbox} |
|
323 | 1263 |
Of course, you should only assert such rules if they are true for your |
286 | 1264 |
particular logic. In Constructive Type Theory, equality is a ternary |
4395 | 1265 |
relation of the form $a=b\in A$; the type~$A$ determines the meaning |
1266 |
of the equality essentially as a partial equivalence relation. The |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1267 |
present simplifier cannot be used. Rewriting in \texttt{CTT} uses |
4395 | 1268 |
another simplifier, which resides in the file {\tt |
1269 |
Provers/typedsimp.ML} and is not documented. Even this does not |
|
1270 |
work for later variants of Constructive Type Theory that use |
|
323 | 1271 |
intensional equality~\cite{nordstrom90}. |
286 | 1272 |
|
1273 |
||
1274 |
\subsection{A collection of standard rewrite rules} |
|
4557 | 1275 |
|
1276 |
We first prove lots of standard rewrite rules about the logical |
|
1277 |
connectives. These include cancellation and associative laws. We |
|
1278 |
define a function that echoes the desired law and then supplies it the |
|
1279 |
prover for intuitionistic \FOL: |
|
286 | 1280 |
\begin{ttbox} |
1281 |
fun int_prove_fun s = |
|
1282 |
(writeln s; |
|
1283 |
prove_goal IFOL.thy s |
|
1284 |
(fn prems => [ (cut_facts_tac prems 1), |
|
4395 | 1285 |
(IntPr.fast_tac 1) ])); |
286 | 1286 |
\end{ttbox} |
1287 |
The following rewrite rules about conjunction are a selection of those |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1288 |
proved on \texttt{FOL/simpdata.ML}. Later, these will be supplied to the |
286 | 1289 |
standard simpset. |
1290 |
\begin{ttbox} |
|
4395 | 1291 |
val conj_simps = map int_prove_fun |
286 | 1292 |
["P & True <-> P", "True & P <-> P", |
1293 |
"P & False <-> False", "False & P <-> False", |
|
1294 |
"P & P <-> P", |
|
1295 |
"P & ~P <-> False", "~P & P <-> False", |
|
1296 |
"(P & Q) & R <-> P & (Q & R)"]; |
|
1297 |
\end{ttbox} |
|
1298 |
The file also proves some distributive laws. As they can cause exponential |
|
1299 |
blowup, they will not be included in the standard simpset. Instead they |
|
323 | 1300 |
are merely bound to an \ML{} identifier, for user reference. |
286 | 1301 |
\begin{ttbox} |
4395 | 1302 |
val distrib_simps = map int_prove_fun |
286 | 1303 |
["P & (Q | R) <-> P&Q | P&R", |
1304 |
"(Q | R) & P <-> Q&P | R&P", |
|
1305 |
"(P | Q --> R) <-> (P --> R) & (Q --> R)"]; |
|
1306 |
\end{ttbox} |
|
1307 |
||
1308 |
||
1309 |
\subsection{Functions for preprocessing the rewrite rules} |
|
323 | 1310 |
\label{sec:setmksimps} |
4395 | 1311 |
\begin{ttbox}\indexbold{*setmksimps} |
1312 |
setmksimps : simpset * (thm -> thm list) -> simpset \hfill{\bf infix 4} |
|
1313 |
\end{ttbox} |
|
286 | 1314 |
The next step is to define the function for preprocessing rewrite rules. |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1315 |
This will be installed by calling \texttt{setmksimps} below. Preprocessing |
286 | 1316 |
occurs whenever rewrite rules are added, whether by user command or |
1317 |
automatically. Preprocessing involves extracting atomic rewrites at the |
|
1318 |
object-level, then reflecting them to the meta-level. |
|
1319 |
||
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1320 |
To start, the function \texttt{gen_all} strips any meta-level |
286 | 1321 |
quantifiers from the front of the given theorem. Usually there are none |
1322 |
anyway. |
|
1323 |
\begin{ttbox} |
|
1324 |
fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th; |
|
1325 |
\end{ttbox} |
|
5549 | 1326 |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1327 |
The function \texttt{atomize} analyses a theorem in order to extract |
286 | 1328 |
atomic rewrite rules. The head of all the patterns, matched by the |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1329 |
wildcard~\texttt{_}, is the coercion function \texttt{Trueprop}. |
286 | 1330 |
\begin{ttbox} |
1331 |
fun atomize th = case concl_of th of |
|
1332 |
_ $ (Const("op &",_) $ _ $ _) => atomize(th RS conjunct1) \at |
|
1333 |
atomize(th RS conjunct2) |
|
1334 |
| _ $ (Const("op -->",_) $ _ $ _) => atomize(th RS mp) |
|
1335 |
| _ $ (Const("All",_) $ _) => atomize(th RS spec) |
|
1336 |
| _ $ (Const("True",_)) => [] |
|
1337 |
| _ $ (Const("False",_)) => [] |
|
1338 |
| _ => [th]; |
|
1339 |
\end{ttbox} |
|
1340 |
There are several cases, depending upon the form of the conclusion: |
|
1341 |
\begin{itemize} |
|
1342 |
\item Conjunction: extract rewrites from both conjuncts. |
|
1343 |
\item Implication: convert $P\imp Q$ to the meta-implication $P\Imp Q$ and |
|
1344 |
extract rewrites from~$Q$; these will be conditional rewrites with the |
|
1345 |
condition~$P$. |
|
1346 |
\item Universal quantification: remove the quantifier, replacing the bound |
|
1347 |
variable by a schematic variable, and extract rewrites from the body. |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1348 |
\item \texttt{True} and \texttt{False} contain no useful rewrites. |
286 | 1349 |
\item Anything else: return the theorem in a singleton list. |
1350 |
\end{itemize} |
|
1351 |
The resulting theorems are not literally atomic --- they could be |
|
5549 | 1352 |
disjunctive, for example --- but are broken down as much as possible. |
1353 |
See the file \texttt{ZF/simpdata.ML} for a sophisticated translation of |
|
1354 |
set-theoretic formulae into rewrite rules. |
|
1355 |
||
1356 |
For standard situations like the above, |
|
1357 |
there is a generic auxiliary function \ttindexbold{mk_atomize} that takes a |
|
1358 |
list of pairs $(name, thms)$, where $name$ is an operator name and |
|
1359 |
$thms$ is a list of theorems to resolve with in case the pattern matches, |
|
1360 |
and returns a suitable \texttt{atomize} function. |
|
1361 |
||
104 | 1362 |
|
286 | 1363 |
The simplified rewrites must now be converted into meta-equalities. The |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1364 |
rule \texttt{eq_reflection} converts equality rewrites, while {\tt |
286 | 1365 |
iff_reflection} converts if-and-only-if rewrites. The latter possibility |
1366 |
can arise in two other ways: the negative theorem~$\neg P$ is converted to |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1367 |
$P\equiv\texttt{False}$, and any other theorem~$P$ is converted to |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1368 |
$P\equiv\texttt{True}$. The rules \texttt{iff_reflection_F} and {\tt |
286 | 1369 |
iff_reflection_T} accomplish this conversion. |
1370 |
\begin{ttbox} |
|
1371 |
val P_iff_F = int_prove_fun "~P ==> (P <-> False)"; |
|
1372 |
val iff_reflection_F = P_iff_F RS iff_reflection; |
|
1373 |
\ttbreak |
|
1374 |
val P_iff_T = int_prove_fun "P ==> (P <-> True)"; |
|
1375 |
val iff_reflection_T = P_iff_T RS iff_reflection; |
|
1376 |
\end{ttbox} |
|
5549 | 1377 |
The function \texttt{mk_eq} converts a theorem to a meta-equality |
286 | 1378 |
using the case analysis described above. |
1379 |
\begin{ttbox} |
|
5549 | 1380 |
fun mk_eq th = case concl_of th of |
286 | 1381 |
_ $ (Const("op =",_)$_$_) => th RS eq_reflection |
1382 |
| _ $ (Const("op <->",_)$_$_) => th RS iff_reflection |
|
1383 |
| _ $ (Const("Not",_)$_) => th RS iff_reflection_F |
|
1384 |
| _ => th RS iff_reflection_T; |
|
1385 |
\end{ttbox} |
|
5549 | 1386 |
The three functions \texttt{gen_all}, \texttt{atomize} and \texttt{mk_eq} |
1387 |
will be composed together and supplied below to \texttt{setmksimps}. |
|
286 | 1388 |
|
1389 |
||
1390 |
\subsection{Making the initial simpset} |
|
4395 | 1391 |
|
4798 | 1392 |
It is time to assemble these items. We define the infix operator |
4395 | 1393 |
\ttindex{addcongs} to insert congruence rules; given a list of |
1394 |
theorems, it converts their conclusions into meta-equalities and |
|
1395 |
passes them to \ttindex{addeqcongs}. |
|
286 | 1396 |
\begin{ttbox} |
4395 | 1397 |
infix 4 addcongs; |
286 | 1398 |
fun ss addcongs congs = |
1399 |
ss addeqcongs (congs RL [eq_reflection,iff_reflection]); |
|
1400 |
\end{ttbox} |
|
4395 | 1401 |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1402 |
The list \texttt{IFOL_simps} contains the default rewrite rules for |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1403 |
intuitionistic first-order logic. The first of these is the reflexive law |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1404 |
expressed as the equivalence $(a=a)\bimp\texttt{True}$; the rewrite rule $a=a$ is |
4395 | 1405 |
clearly useless. |
1406 |
\begin{ttbox} |
|
1407 |
val IFOL_simps = |
|
1408 |
[refl RS P_iff_T] \at conj_simps \at disj_simps \at not_simps \at |
|
1409 |
imp_simps \at iff_simps \at quant_simps; |
|
286 | 1410 |
\end{ttbox} |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1411 |
The list \texttt{triv_rls} contains trivial theorems for the solver. Any |
286 | 1412 |
subgoal that is simplified to one of these will be removed. |
1413 |
\begin{ttbox} |
|
1414 |
val notFalseI = int_prove_fun "~False"; |
|
1415 |
val triv_rls = [TrueI,refl,iff_refl,notFalseI]; |
|
1416 |
\end{ttbox} |
|
323 | 1417 |
% |
4395 | 1418 |
The basic simpset for intuitionistic \FOL{} is |
1419 |
\ttindexbold{FOL_basic_ss}. It preprocess rewrites using {\tt |
|
5549 | 1420 |
gen_all}, \texttt{atomize} and \texttt{mk_eq}. It solves simplified |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1421 |
subgoals using \texttt{triv_rls} and assumptions, and by detecting |
4395 | 1422 |
contradictions. It uses \ttindex{asm_simp_tac} to tackle subgoals of |
1423 |
conditional rewrites. |
|
1424 |
||
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1425 |
Other simpsets built from \texttt{FOL_basic_ss} will inherit these items. |
4395 | 1426 |
In particular, \ttindexbold{IFOL_ss}, which introduces {\tt |
1427 |
IFOL_simps} as rewrite rules. \ttindexbold{FOL_ss} will later |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1428 |
extend \texttt{IFOL_ss} with classical rewrite rules such as $\neg\neg |
4395 | 1429 |
P\bimp P$. |
2628
1fe7c9f599c2
description of del(eq)congs, safe and unsafe solver
oheimb
parents:
2613
diff
changeset
|
1430 |
\index{*setmksimps}\index{*setSSolver}\index{*setSolver}\index{*setsubgoaler} |
286 | 1431 |
\index{*addsimps}\index{*addcongs} |
1432 |
\begin{ttbox} |
|
4395 | 1433 |
fun unsafe_solver prems = FIRST'[resolve_tac (triv_rls {\at} prems), |
2628
1fe7c9f599c2
description of del(eq)congs, safe and unsafe solver
oheimb
parents:
2613
diff
changeset
|
1434 |
atac, etac FalseE]; |
4395 | 1435 |
|
1436 |
fun safe_solver prems = FIRST'[match_tac (triv_rls {\at} prems), |
|
2628
1fe7c9f599c2
description of del(eq)congs, safe and unsafe solver
oheimb
parents:
2613
diff
changeset
|
1437 |
eq_assume_tac, ematch_tac [FalseE]]; |
4395 | 1438 |
|
1439 |
val FOL_basic_ss = empty_ss setsubgoaler asm_simp_tac |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1440 |
addsimprocs [defALL_regroup, defEX_regroup] |
4395 | 1441 |
setSSolver safe_solver |
1442 |
setSolver unsafe_solver |
|
5549 | 1443 |
setmksimps (map mk_eq o atomize o gen_all); |
4395 | 1444 |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1445 |
val IFOL_ss = FOL_basic_ss addsimps (IFOL_simps {\at} |
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1446 |
int_ex_simps {\at} int_all_simps) |
4395 | 1447 |
addcongs [imp_cong]; |
286 | 1448 |
\end{ttbox} |
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1449 |
This simpset takes \texttt{imp_cong} as a congruence rule in order to use |
286 | 1450 |
contextual information to simplify the conclusions of implications: |
1451 |
\[ \List{\Var{P}\bimp\Var{P'};\; \Var{P'} \Imp \Var{Q}\bimp\Var{Q'}} \Imp |
|
1452 |
(\Var{P}\imp\Var{Q}) \bimp (\Var{P'}\imp\Var{Q'}) |
|
1453 |
\] |
|
4597
a0bdee64194c
Fixed a lot of overfull and underfull lines (hboxes)
paulson
parents:
4560
diff
changeset
|
1454 |
By adding the congruence rule \texttt{conj_cong}, we could obtain a similar |
286 | 1455 |
effect for conjunctions. |
1456 |
||
1457 |
||
5549 | 1458 |
\subsection{Splitter setup}\index{simplification!setting up the splitter} |
4557 | 1459 |
|
5549 | 1460 |
To set up case splitting, we have to call the \ML{} functor \ttindex{ |
1461 |
SplitterFun}, which takes the argument signature \texttt{SPLITTER_DATA}. |
|
1462 |
So we prove the theorem \texttt{meta_eq_to_iff} below and store it, together |
|
1463 |
with the \texttt{mk_eq} function described above and several standard |
|
1464 |
theorems, in the structure \texttt{SplitterData}. Calling the functor with |
|
1465 |
this data yields a new instantiation of the splitter for our logic. |
|
286 | 1466 |
\begin{ttbox} |
5549 | 1467 |
val meta_eq_to_iff = prove_goal IFOL.thy "x==y ==> x<->y" |
1468 |
(fn [prem] => [rewtac prem, rtac iffI 1, atac 1, atac 1]); |
|
286 | 1469 |
\ttbreak |
5549 | 1470 |
structure SplitterData = |
1471 |
struct |
|
1472 |
structure Simplifier = Simplifier |
|
1473 |
val mk_eq = mk_eq |
|
1474 |
val meta_eq_to_iff = meta_eq_to_iff |
|
1475 |
val iffD = iffD2 |
|
1476 |
val disjE = disjE |
|
1477 |
val conjE = conjE |
|
1478 |
val exE = exE |
|
1479 |
val contrapos = contrapos |
|
1480 |
val contrapos2 = contrapos2 |
|
1481 |
val notnotD = notnotD |
|
1482 |
end; |
|
1483 |
\ttbreak |
|
1484 |
structure Splitter = SplitterFun(SplitterData); |
|
286 | 1485 |
\end{ttbox} |
1486 |
||
104 | 1487 |
|
5370 | 1488 |
\subsection{Theory setup}\index{simplification!setting up the theory} |
1489 |
\begin{ttbox}\indexbold{*Simplifier.setup}\index{*setup!simplifier} |
|
1490 |
Simplifier.setup: (theory -> theory) list |
|
4395 | 1491 |
\end{ttbox} |
1492 |
||
5370 | 1493 |
Advanced theory related features of the simplifier (e.g.\ implicit |
1494 |
simpset support) have to be set up explicitly. The simplifier already |
|
1495 |
provides a suitable setup function definition. This has to be |
|
1496 |
installed into the base theory of any new object-logic via a |
|
1497 |
\texttt{setup} declaration. |
|
4395 | 1498 |
|
5370 | 1499 |
For example, this is done in \texttt{FOL/IFOL.thy} as follows: |
4395 | 1500 |
\begin{ttbox} |
5370 | 1501 |
setup Simplifier.setup |
4395 | 1502 |
\end{ttbox} |
1503 |
||
104 | 1504 |
|
1505 |
\index{simplification|)} |
|
5370 | 1506 |
|
1507 |
||
1508 |
%%% Local Variables: |
|
1509 |
%%% mode: latex |
|
1510 |
%%% TeX-master: "ref" |
|
1511 |
%%% End: |