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