author | nipkow |
Wed, 06 Jun 2018 18:19:55 +0200 | |
changeset 68403 | 223172b97d0b |
parent 67561 | f0b11413f1c9 |
child 69597 | ff784d5a5bfb |
permissions | -rw-r--r-- |
61656 | 1 |
(*:maxLineLen=78:*) |
2 |
||
26782 | 3 |
theory Generic |
63531 | 4 |
imports Main Base |
26782 | 5 |
begin |
6 |
||
58618 | 7 |
chapter \<open>Generic tools and packages \label{ch:gen-tools}\<close> |
26782 | 8 |
|
58618 | 9 |
section \<open>Configuration options \label{sec:config}\<close> |
26782 | 10 |
|
63531 | 11 |
text \<open> |
12 |
Isabelle/Pure maintains a record of named configuration options within the |
|
13 |
theory or proof context, with values of type @{ML_type bool}, @{ML_type |
|
14 |
int}, @{ML_type real}, or @{ML_type string}. Tools may declare options in |
|
15 |
ML, and then refer to these values (relative to the context). Thus global |
|
16 |
reference variables are easily avoided. The user may change the value of a |
|
17 |
configuration option by means of an associated attribute of the same name. |
|
18 |
This form of context declaration works particularly well with commands such |
|
19 |
as @{command "declare"} or @{command "using"} like this: |
|
58618 | 20 |
\<close> |
42655 | 21 |
|
59905 | 22 |
(*<*)experiment begin(*>*) |
42655 | 23 |
declare [[show_main_goal = false]] |
26782 | 24 |
|
42655 | 25 |
notepad |
26 |
begin |
|
27 |
note [[show_main_goal = true]] |
|
28 |
end |
|
59905 | 29 |
(*<*)end(*>*) |
42655 | 30 |
|
59921 | 31 |
text \<open> |
26782 | 32 |
\begin{matharray}{rcll} |
61493 | 33 |
@{command_def "print_options"} & : & \<open>context \<rightarrow>\<close> \\ |
26782 | 34 |
\end{matharray} |
35 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
36 |
@{rail \<open> |
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59905
diff
changeset
|
37 |
@@{command print_options} ('!'?) |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59905
diff
changeset
|
38 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
39 |
@{syntax name} ('=' ('true' | 'false' | @{syntax int} | @{syntax float} | @{syntax name}))? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
40 |
\<close>} |
26782 | 41 |
|
63531 | 42 |
\<^descr> @{command "print_options"} prints the available configuration options, |
43 |
with names, types, and current values; the ``\<open>!\<close>'' option indicates extra |
|
44 |
verbosity. |
|
26782 | 45 |
|
63531 | 46 |
\<^descr> \<open>name = value\<close> as an attribute expression modifies the named option, with |
47 |
the syntax of the value depending on the option's type. For @{ML_type bool} |
|
48 |
the default value is \<open>true\<close>. Any attempt to change a global option in a |
|
49 |
local context is ignored. |
|
58618 | 50 |
\<close> |
26782 | 51 |
|
52 |
||
58618 | 53 |
section \<open>Basic proof tools\<close> |
26782 | 54 |
|
58618 | 55 |
subsection \<open>Miscellaneous methods and attributes \label{sec:misc-meth-att}\<close> |
26782 | 56 |
|
58618 | 57 |
text \<open> |
26782 | 58 |
\begin{matharray}{rcl} |
61493 | 59 |
@{method_def unfold} & : & \<open>method\<close> \\ |
60 |
@{method_def fold} & : & \<open>method\<close> \\ |
|
61 |
@{method_def insert} & : & \<open>method\<close> \\[0.5ex] |
|
62 |
@{method_def erule}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\ |
|
63 |
@{method_def drule}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\ |
|
64 |
@{method_def frule}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\ |
|
65 |
@{method_def intro} & : & \<open>method\<close> \\ |
|
66 |
@{method_def elim} & : & \<open>method\<close> \\ |
|
67 |
@{method_def fail} & : & \<open>method\<close> \\ |
|
68 |
@{method_def succeed} & : & \<open>method\<close> \\ |
|
69 |
@{method_def sleep} & : & \<open>method\<close> \\ |
|
26782 | 70 |
\end{matharray} |
71 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
72 |
@{rail \<open> |
62969 | 73 |
(@@{method fold} | @@{method unfold} | @@{method insert}) @{syntax thms} |
26782 | 74 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
75 |
(@@{method erule} | @@{method drule} | @@{method frule}) |
62969 | 76 |
('(' @{syntax nat} ')')? @{syntax thms} |
43365 | 77 |
; |
62969 | 78 |
(@@{method intro} | @@{method elim}) @{syntax thms}? |
60556 | 79 |
; |
80 |
@@{method sleep} @{syntax real} |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
81 |
\<close>} |
26782 | 82 |
|
63531 | 83 |
\<^descr> @{method unfold}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> and @{method fold}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> expand (or |
84 |
fold back) the given definitions throughout all goals; any chained facts |
|
85 |
provided are inserted into the goal and subject to rewriting as well. |
|
26782 | 86 |
|
63821 | 87 |
Unfolding works in two stages: first, the given equations are used directly |
88 |
for rewriting; second, the equations are passed through the attribute |
|
89 |
@{attribute_ref abs_def} before rewriting --- to ensure that definitions are |
|
90 |
fully expanded, regardless of the actual parameters that are provided. |
|
91 |
||
63531 | 92 |
\<^descr> @{method insert}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> inserts theorems as facts into all goals of |
93 |
the proof state. Note that current facts indicated for forward chaining are |
|
94 |
ignored. |
|
95 |
||
96 |
\<^descr> @{method erule}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close>, @{method drule}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close>, and @{method |
|
97 |
frule}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> are similar to the basic @{method rule} method (see |
|
98 |
\secref{sec:pure-meth-att}), but apply rules by elim-resolution, |
|
99 |
destruct-resolution, and forward-resolution, respectively @{cite |
|
100 |
"isabelle-implementation"}. The optional natural number argument (default 0) |
|
101 |
specifies additional assumption steps to be performed here. |
|
26782 | 102 |
|
103 |
Note that these methods are improper ones, mainly serving for |
|
63531 | 104 |
experimentation and tactic script emulation. Different modes of basic rule |
105 |
application are usually expressed in Isar at the proof language level, |
|
106 |
rather than via implicit proof state manipulations. For example, a proper |
|
107 |
single-step elimination would be done using the plain @{method rule} method, |
|
108 |
with forward chaining of current facts. |
|
26782 | 109 |
|
63531 | 110 |
\<^descr> @{method intro} and @{method elim} repeatedly refine some goal by intro- |
111 |
or elim-resolution, after having inserted any chained facts. Exactly the |
|
112 |
rules given as arguments are taken into account; this allows fine-tuned |
|
113 |
decomposition of a proof problem, in contrast to common automated tools. |
|
43365 | 114 |
|
63531 | 115 |
\<^descr> @{method fail} yields an empty result sequence; it is the identity of the |
116 |
``\<open>|\<close>'' method combinator (cf.\ \secref{sec:proof-meth}). |
|
60554 | 117 |
|
63531 | 118 |
\<^descr> @{method succeed} yields a single (unchanged) result; it is the identity |
119 |
of the ``\<open>,\<close>'' method combinator (cf.\ \secref{sec:proof-meth}). |
|
26782 | 120 |
|
63531 | 121 |
\<^descr> @{method sleep}~\<open>s\<close> succeeds after a real-time delay of \<open>s\<close> seconds. This |
122 |
is occasionally useful for demonstration and testing purposes. |
|
26782 | 123 |
|
124 |
||
125 |
\begin{matharray}{rcl} |
|
61493 | 126 |
@{attribute_def tagged} & : & \<open>attribute\<close> \\ |
127 |
@{attribute_def untagged} & : & \<open>attribute\<close> \\[0.5ex] |
|
128 |
@{attribute_def THEN} & : & \<open>attribute\<close> \\ |
|
129 |
@{attribute_def unfolded} & : & \<open>attribute\<close> \\ |
|
130 |
@{attribute_def folded} & : & \<open>attribute\<close> \\ |
|
131 |
@{attribute_def abs_def} & : & \<open>attribute\<close> \\[0.5ex] |
|
132 |
@{attribute_def rotated} & : & \<open>attribute\<close> \\ |
|
133 |
@{attribute_def (Pure) elim_format} & : & \<open>attribute\<close> \\ |
|
134 |
@{attribute_def no_vars}\<open>\<^sup>*\<close> & : & \<open>attribute\<close> \\ |
|
26782 | 135 |
\end{matharray} |
136 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
137 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
138 |
@@{attribute tagged} @{syntax name} @{syntax name} |
26782 | 139 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
140 |
@@{attribute untagged} @{syntax name} |
26782 | 141 |
; |
62969 | 142 |
@@{attribute THEN} ('[' @{syntax nat} ']')? @{syntax thm} |
26782 | 143 |
; |
62969 | 144 |
(@@{attribute unfolded} | @@{attribute folded}) @{syntax thms} |
26782 | 145 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
146 |
@@{attribute rotated} @{syntax int}? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
147 |
\<close>} |
26782 | 148 |
|
63531 | 149 |
\<^descr> @{attribute tagged}~\<open>name value\<close> and @{attribute untagged}~\<open>name\<close> add and |
150 |
remove \<^emph>\<open>tags\<close> of some theorem. Tags may be any list of string pairs that |
|
151 |
serve as formal comment. The first string is considered the tag name, the |
|
152 |
second its value. Note that @{attribute untagged} removes any tags of the |
|
153 |
same name. |
|
26782 | 154 |
|
63531 | 155 |
\<^descr> @{attribute THEN}~\<open>a\<close> composes rules by resolution; it resolves with the |
156 |
first premise of \<open>a\<close> (an alternative position may be also specified). See |
|
157 |
also @{ML_op "RS"} in @{cite "isabelle-implementation"}. |
|
26782 | 158 |
|
63531 | 159 |
\<^descr> @{attribute unfolded}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> and @{attribute folded}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> |
160 |
expand and fold back again the given definitions throughout a rule. |
|
26782 | 161 |
|
63531 | 162 |
\<^descr> @{attribute abs_def} turns an equation of the form @{prop "f x y \<equiv> t"} |
63821 | 163 |
into @{prop "f \<equiv> \<lambda>x y. t"}, which ensures that @{method simp} steps always |
164 |
expand it. This also works for object-logic equality. |
|
47497 | 165 |
|
63531 | 166 |
\<^descr> @{attribute rotated}~\<open>n\<close> rotate the premises of a theorem by \<open>n\<close> (default |
167 |
1). |
|
26782 | 168 |
|
63531 | 169 |
\<^descr> @{attribute (Pure) elim_format} turns a destruction rule into elimination |
170 |
rule format, by resolving with the rule @{prop "PROP A \<Longrightarrow> (PROP A \<Longrightarrow> PROP B) \<Longrightarrow> |
|
171 |
PROP B"}. |
|
26782 | 172 |
|
63531 | 173 |
Note that the Classical Reasoner (\secref{sec:classical}) provides its own |
174 |
version of this operation. |
|
26782 | 175 |
|
63531 | 176 |
\<^descr> @{attribute no_vars} replaces schematic variables by free ones; this is |
177 |
mainly for tuning output of pretty printed theorems. |
|
58618 | 178 |
\<close> |
26782 | 179 |
|
180 |
||
58618 | 181 |
subsection \<open>Low-level equational reasoning\<close> |
27044 | 182 |
|
58618 | 183 |
text \<open> |
27044 | 184 |
\begin{matharray}{rcl} |
61493 | 185 |
@{method_def subst} & : & \<open>method\<close> \\ |
186 |
@{method_def hypsubst} & : & \<open>method\<close> \\ |
|
187 |
@{method_def split} & : & \<open>method\<close> \\ |
|
27044 | 188 |
\end{matharray} |
189 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
190 |
@{rail \<open> |
62969 | 191 |
@@{method subst} ('(' 'asm' ')')? \<newline> ('(' (@{syntax nat}+) ')')? @{syntax thm} |
27044 | 192 |
; |
62969 | 193 |
@@{method split} @{syntax thms} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
194 |
\<close>} |
27044 | 195 |
|
63531 | 196 |
These methods provide low-level facilities for equational reasoning that are |
197 |
intended for specialized applications only. Normally, single step |
|
198 |
calculations would be performed in a structured text (see also |
|
199 |
\secref{sec:calculation}), while the Simplifier methods provide the |
|
200 |
canonical way for automated normalization (see \secref{sec:simplifier}). |
|
201 |
||
202 |
\<^descr> @{method subst}~\<open>eq\<close> performs a single substitution step using rule \<open>eq\<close>, |
|
203 |
which may be either a meta or object equality. |
|
27044 | 204 |
|
63531 | 205 |
\<^descr> @{method subst}~\<open>(asm) eq\<close> substitutes in an assumption. |
27044 | 206 |
|
63531 | 207 |
\<^descr> @{method subst}~\<open>(i \<dots> j) eq\<close> performs several substitutions in the |
208 |
conclusion. The numbers \<open>i\<close> to \<open>j\<close> indicate the positions to substitute at. |
|
209 |
Positions are ordered from the top of the term tree moving down from left to |
|
210 |
right. For example, in \<open>(a + b) + (c + d)\<close> there are three positions where |
|
211 |
commutativity of \<open>+\<close> is applicable: 1 refers to \<open>a + b\<close>, 2 to the whole |
|
212 |
term, and 3 to \<open>c + d\<close>. |
|
27044 | 213 |
|
63531 | 214 |
If the positions in the list \<open>(i \<dots> j)\<close> are non-overlapping (e.g.\ \<open>(2 3)\<close> in |
215 |
\<open>(a + b) + (c + d)\<close>) you may assume all substitutions are performed |
|
216 |
simultaneously. Otherwise the behaviour of \<open>subst\<close> is not specified. |
|
27044 | 217 |
|
63531 | 218 |
\<^descr> @{method subst}~\<open>(asm) (i \<dots> j) eq\<close> performs the substitutions in the |
219 |
assumptions. The positions refer to the assumptions in order from left to |
|
220 |
right. For example, given in a goal of the form \<open>P (a + b) \<Longrightarrow> P (c + d) \<Longrightarrow> \<dots>\<close>, |
|
221 |
position 1 of commutativity of \<open>+\<close> is the subterm \<open>a + b\<close> and position 2 is |
|
222 |
the subterm \<open>c + d\<close>. |
|
27044 | 223 |
|
63531 | 224 |
\<^descr> @{method hypsubst} performs substitution using some assumption; this only |
225 |
works for equations of the form \<open>x = t\<close> where \<open>x\<close> is a free or bound |
|
226 |
variable. |
|
27044 | 227 |
|
63531 | 228 |
\<^descr> @{method split}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> performs single-step case splitting using the |
229 |
given rules. Splitting is performed in the conclusion or some assumption of |
|
230 |
the subgoal, depending of the structure of the rule. |
|
27044 | 231 |
|
63531 | 232 |
Note that the @{method simp} method already involves repeated application of |
233 |
split rules as declared in the current context, using @{attribute split}, |
|
234 |
for example. |
|
58618 | 235 |
\<close> |
27044 | 236 |
|
237 |
||
58618 | 238 |
section \<open>The Simplifier \label{sec:simplifier}\<close> |
26782 | 239 |
|
62655 | 240 |
text \<open> |
241 |
The Simplifier performs conditional and unconditional rewriting and uses |
|
242 |
contextual information: rule declarations in the background theory or local |
|
243 |
proof context are taken into account, as well as chained facts and subgoal |
|
244 |
premises (``local assumptions''). There are several general hooks that allow |
|
245 |
to modify the simplification strategy, or incorporate other proof tools that |
|
246 |
solve sub-problems, produce rewrite rules on demand etc. |
|
50063 | 247 |
|
62655 | 248 |
The rewriting strategy is always strictly bottom up, except for congruence |
249 |
rules, which are applied while descending into a term. Conditions in |
|
250 |
conditional rewrite rules are solved recursively before the rewrite rule is |
|
251 |
applied. |
|
50075 | 252 |
|
62655 | 253 |
The default Simplifier setup of major object logics (HOL, HOLCF, FOL, ZF) |
254 |
makes the Simplifier ready for immediate use, without engaging into the |
|
255 |
internal structures. Thus it serves as general-purpose proof tool with the |
|
256 |
main focus on equational reasoning, and a bit more than that. |
|
58618 | 257 |
\<close> |
50063 | 258 |
|
259 |
||
58618 | 260 |
subsection \<open>Simplification methods \label{sec:simp-meth}\<close> |
26782 | 261 |
|
58618 | 262 |
text \<open> |
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
263 |
\begin{tabular}{rcll} |
61493 | 264 |
@{method_def simp} & : & \<open>method\<close> \\ |
265 |
@{method_def simp_all} & : & \<open>method\<close> \\ |
|
63532
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
266 |
\<open>Pure.\<close>@{method_def (Pure) simp} & : & \<open>method\<close> \\ |
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
267 |
\<open>Pure.\<close>@{method_def (Pure) simp_all} & : & \<open>method\<close> \\ |
61493 | 268 |
@{attribute_def simp_depth_limit} & : & \<open>attribute\<close> & default \<open>100\<close> \\ |
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
269 |
\end{tabular} |
61421 | 270 |
\<^medskip> |
26782 | 271 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
272 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
273 |
(@@{method simp} | @@{method simp_all}) opt? (@{syntax simpmod} * ) |
26782 | 274 |
; |
275 |
||
40255
9ffbc25e1606
eliminated obsolete \_ escapes in rail environments;
wenzelm
parents:
35613
diff
changeset
|
276 |
opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')' |
26782 | 277 |
; |
68403 | 278 |
@{syntax_def simpmod}: ('add' | 'del' | 'flip' | 'only' | |
279 |
'split' (() | '!' | 'del') | 'cong' (() | 'add' | 'del')) |
|
280 |
':' @{syntax thms} |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
281 |
\<close>} |
26782 | 282 |
|
62655 | 283 |
\<^descr> @{method simp} invokes the Simplifier on the first subgoal, after |
284 |
inserting chained facts as additional goal premises; further rule |
|
285 |
declarations may be included via \<open>(simp add: facts)\<close>. The proof method fails |
|
286 |
if the subgoal remains unchanged after simplification. |
|
26782 | 287 |
|
62655 | 288 |
Note that the original goal premises and chained facts are subject to |
289 |
simplification themselves, while declarations via \<open>add\<close>/\<open>del\<close> merely follow |
|
290 |
the policies of the object-logic to extract rewrite rules from theorems, |
|
291 |
without further simplification. This may lead to slightly different behavior |
|
292 |
in either case, which might be required precisely like that in some boundary |
|
293 |
situations to perform the intended simplification step! |
|
50063 | 294 |
|
61421 | 295 |
\<^medskip> |
68403 | 296 |
Modifier \<open>flip\<close> deletes the following theorems from the simpset and adds |
297 |
their symmetric version (i.e.\ lhs and rhs exchanged). No warning is shown |
|
298 |
if the original theorem was not present. |
|
299 |
||
300 |
\<^medskip> |
|
62655 | 301 |
The \<open>only\<close> modifier first removes all other rewrite rules, looper tactics |
302 |
(including split rules), congruence rules, and then behaves like \<open>add\<close>. |
|
303 |
Implicit solvers remain, which means that trivial rules like reflexivity or |
|
304 |
introduction of \<open>True\<close> are available to solve the simplified subgoals, but |
|
305 |
also non-trivial tools like linear arithmetic in HOL. The latter may lead to |
|
306 |
some surprise of the meaning of ``only'' in Isabelle/HOL compared to |
|
307 |
English! |
|
26782 | 308 |
|
61421 | 309 |
\<^medskip> |
62655 | 310 |
The \<open>split\<close> modifiers add or delete rules for the Splitter (see also |
311 |
\secref{sec:simp-strategies} on the looper). This works only if the |
|
312 |
Simplifier method has been properly setup to include the Splitter (all major |
|
313 |
object logics such HOL, HOLCF, FOL, ZF do this already). |
|
63650 | 314 |
The \<open>!\<close> option causes the split rules to be used aggressively: |
315 |
after each application of a split rule in the conclusion, the \<open>safe\<close> |
|
316 |
tactic of the classical reasoner (see \secref{sec:classical:partial}) |
|
317 |
is applied to the new goal. The net effect is that the goal is split into |
|
318 |
the different cases. This option can speed up simplification of goals |
|
319 |
with many nested conditional or case expressions significantly. |
|
26782 | 320 |
|
50065 | 321 |
There is also a separate @{method_ref split} method available for |
62655 | 322 |
single-step case splitting. The effect of repeatedly applying \<open>(split thms)\<close> |
323 |
can be imitated by ``\<open>(simp only: split: thms)\<close>''. |
|
50065 | 324 |
|
61421 | 325 |
\<^medskip> |
62655 | 326 |
The \<open>cong\<close> modifiers add or delete Simplifier congruence rules (see also |
327 |
\secref{sec:simp-rules}); the default is to add. |
|
50063 | 328 |
|
62655 | 329 |
\<^descr> @{method simp_all} is similar to @{method simp}, but acts on all goals, |
330 |
working backwards from the last to the first one as usual in Isabelle.\<^footnote>\<open>The |
|
331 |
order is irrelevant for goals without schematic variables, so simplification |
|
332 |
might actually be performed in parallel here.\<close> |
|
50063 | 333 |
|
62655 | 334 |
Chained facts are inserted into all subgoals, before the simplification |
335 |
process starts. Further rule declarations are the same as for @{method |
|
336 |
simp}. |
|
50063 | 337 |
|
338 |
The proof method fails if all subgoals remain unchanged after |
|
339 |
simplification. |
|
26782 | 340 |
|
62655 | 341 |
\<^descr> @{attribute simp_depth_limit} limits the number of recursive invocations |
342 |
of the Simplifier during conditional rewriting. |
|
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
343 |
|
26782 | 344 |
|
62655 | 345 |
By default the Simplifier methods above take local assumptions fully into |
346 |
account, using equational assumptions in the subsequent normalization |
|
347 |
process, or simplifying assumptions themselves. Further options allow to |
|
348 |
fine-tune the behavior of the Simplifier in this respect, corresponding to a |
|
349 |
variety of ML tactics as follows.\<^footnote>\<open>Unlike the corresponding Isar proof |
|
350 |
methods, the ML tactics do not insist in changing the goal state.\<close> |
|
50063 | 351 |
|
352 |
\begin{center} |
|
353 |
\small |
|
59782 | 354 |
\begin{tabular}{|l|l|p{0.3\textwidth}|} |
50063 | 355 |
\hline |
356 |
Isar method & ML tactic & behavior \\\hline |
|
357 |
||
62655 | 358 |
\<open>(simp (no_asm))\<close> & @{ML simp_tac} & assumptions are ignored completely |
359 |
\\\hline |
|
26782 | 360 |
|
62655 | 361 |
\<open>(simp (no_asm_simp))\<close> & @{ML asm_simp_tac} & assumptions are used in the |
362 |
simplification of the conclusion but are not themselves simplified \\\hline |
|
50063 | 363 |
|
62655 | 364 |
\<open>(simp (no_asm_use))\<close> & @{ML full_simp_tac} & assumptions are simplified but |
365 |
are not used in the simplification of each other or the conclusion \\\hline |
|
26782 | 366 |
|
62655 | 367 |
\<open>(simp)\<close> & @{ML asm_full_simp_tac} & assumptions are used in the |
368 |
simplification of the conclusion and to simplify other assumptions \\\hline |
|
50063 | 369 |
|
62655 | 370 |
\<open>(simp (asm_lr))\<close> & @{ML asm_lr_simp_tac} & compatibility mode: an |
371 |
assumption is only used for simplifying assumptions which are to the right |
|
372 |
of it \\\hline |
|
50063 | 373 |
|
59782 | 374 |
\end{tabular} |
50063 | 375 |
\end{center} |
63532
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
376 |
|
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
377 |
\<^medskip> |
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
378 |
In Isabelle/Pure, proof methods @{method (Pure) simp} and @{method (Pure) |
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
379 |
simp_all} only know about meta-equality \<open>\<equiv>\<close>. Any new object-logic needs to |
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
380 |
re-define these methods via @{ML Simplifier.method_setup} in ML: |
b01154b74314
provide Pure.simp/simp_all, which only know about meta-equality;
wenzelm
parents:
63531
diff
changeset
|
381 |
Isabelle/FOL or Isabelle/HOL may serve as blue-prints. |
58618 | 382 |
\<close> |
26782 | 383 |
|
384 |
||
58618 | 385 |
subsubsection \<open>Examples\<close> |
50064 | 386 |
|
62655 | 387 |
text \<open> |
388 |
We consider basic algebraic simplifications in Isabelle/HOL. The rather |
|
389 |
trivial goal @{prop "0 + (x + 0) = x + 0 + 0"} looks like a good candidate |
|
390 |
to be solved by a single call of @{method simp}: |
|
58618 | 391 |
\<close> |
50064 | 392 |
|
393 |
lemma "0 + (x + 0) = x + 0 + 0" apply simp? oops |
|
394 |
||
62655 | 395 |
text \<open> |
67399 | 396 |
The above attempt \<^emph>\<open>fails\<close>, because @{term "0"} and @{term "(+)"} in the |
62655 | 397 |
HOL library are declared as generic type class operations, without stating |
398 |
any algebraic laws yet. More specific types are required to get access to |
|
399 |
certain standard simplifications of the theory context, e.g.\ like this:\<close> |
|
50064 | 400 |
|
401 |
lemma fixes x :: nat shows "0 + (x + 0) = x + 0 + 0" by simp |
|
402 |
lemma fixes x :: int shows "0 + (x + 0) = x + 0 + 0" by simp |
|
403 |
lemma fixes x :: "'a :: monoid_add" shows "0 + (x + 0) = x + 0 + 0" by simp |
|
404 |
||
58618 | 405 |
text \<open> |
61421 | 406 |
\<^medskip> |
62655 | 407 |
In many cases, assumptions of a subgoal are also needed in the |
408 |
simplification process. For example: |
|
58618 | 409 |
\<close> |
50064 | 410 |
|
411 |
lemma fixes x :: nat shows "x = 0 \<Longrightarrow> x + x = 0" by simp |
|
412 |
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" apply simp oops |
|
413 |
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" using assms by simp |
|
414 |
||
62655 | 415 |
text \<open> |
416 |
As seen above, local assumptions that shall contribute to simplification |
|
417 |
need to be part of the subgoal already, or indicated explicitly for use by |
|
418 |
the subsequent method invocation. Both too little or too much information |
|
419 |
can make simplification fail, for different reasons. |
|
50064 | 420 |
|
62655 | 421 |
In the next example the malicious assumption @{prop "\<And>x::nat. f x = g (f (g |
422 |
x))"} does not contribute to solve the problem, but makes the default |
|
423 |
@{method simp} method loop: the rewrite rule \<open>f ?x \<equiv> g (f (g ?x))\<close> extracted |
|
424 |
from the assumption does not terminate. The Simplifier notices certain |
|
425 |
simple forms of nontermination, but not this one. The problem can be solved |
|
426 |
nonetheless, by ignoring assumptions via special options as explained |
|
427 |
before: |
|
58618 | 428 |
\<close> |
50064 | 429 |
|
430 |
lemma "(\<And>x::nat. f x = g (f (g x))) \<Longrightarrow> f 0 = f 0 + 0" |
|
431 |
by (simp (no_asm)) |
|
432 |
||
62655 | 433 |
text \<open> |
434 |
The latter form is typical for long unstructured proof scripts, where the |
|
435 |
control over the goal content is limited. In structured proofs it is usually |
|
436 |
better to avoid pushing too many facts into the goal state in the first |
|
437 |
place. Assumptions in the Isar proof context do not intrude the reasoning if |
|
438 |
not used explicitly. This is illustrated for a toplevel statement and a |
|
50064 | 439 |
local proof body as follows: |
58618 | 440 |
\<close> |
50064 | 441 |
|
442 |
lemma |
|
443 |
assumes "\<And>x::nat. f x = g (f (g x))" |
|
444 |
shows "f 0 = f 0 + 0" by simp |
|
445 |
||
446 |
notepad |
|
447 |
begin |
|
448 |
assume "\<And>x::nat. f x = g (f (g x))" |
|
449 |
have "f 0 = f 0 + 0" by simp |
|
450 |
end |
|
451 |
||
61421 | 452 |
text \<open> |
453 |
\<^medskip> |
|
62655 | 454 |
Because assumptions may simplify each other, there can be very subtle cases |
455 |
of nontermination. For example, the regular @{method simp} method applied to |
|
456 |
@{prop "P (f x) \<Longrightarrow> y = x \<Longrightarrow> f x = f y \<Longrightarrow> Q"} gives rise to the infinite |
|
457 |
reduction sequence |
|
50064 | 458 |
\[ |
61493 | 459 |
\<open>P (f x)\<close> \stackrel{\<open>f x \<equiv> f y\<close>}{\longmapsto} |
460 |
\<open>P (f y)\<close> \stackrel{\<open>y \<equiv> x\<close>}{\longmapsto} |
|
461 |
\<open>P (f x)\<close> \stackrel{\<open>f x \<equiv> f y\<close>}{\longmapsto} \cdots |
|
50064 | 462 |
\] |
62655 | 463 |
whereas applying the same to @{prop "y = x \<Longrightarrow> f x = f y \<Longrightarrow> P (f x) \<Longrightarrow> Q"} |
464 |
terminates (without solving the goal): |
|
58618 | 465 |
\<close> |
50064 | 466 |
|
467 |
lemma "y = x \<Longrightarrow> f x = f y \<Longrightarrow> P (f x) \<Longrightarrow> Q" |
|
468 |
apply simp |
|
469 |
oops |
|
470 |
||
62655 | 471 |
text \<open> |
472 |
See also \secref{sec:simp-trace} for options to enable Simplifier trace |
|
473 |
mode, which often helps to diagnose problems with rewrite systems. |
|
58618 | 474 |
\<close> |
50064 | 475 |
|
476 |
||
58618 | 477 |
subsection \<open>Declaring rules \label{sec:simp-rules}\<close> |
26782 | 478 |
|
58618 | 479 |
text \<open> |
26782 | 480 |
\begin{matharray}{rcl} |
61493 | 481 |
@{attribute_def simp} & : & \<open>attribute\<close> \\ |
482 |
@{attribute_def split} & : & \<open>attribute\<close> \\ |
|
483 |
@{attribute_def cong} & : & \<open>attribute\<close> \\ |
|
484 |
@{command_def "print_simpset"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\ |
|
26782 | 485 |
\end{matharray} |
486 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
487 |
@{rail \<open> |
63650 | 488 |
(@@{attribute simp} | @@{attribute cong}) (() | 'add' | 'del') | |
489 |
@@{attribute split} (() | '!' | 'del') |
|
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59905
diff
changeset
|
490 |
; |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59905
diff
changeset
|
491 |
@@{command print_simpset} ('!'?) |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
492 |
\<close>} |
26782 | 493 |
|
62655 | 494 |
\<^descr> @{attribute simp} declares rewrite rules, by adding or deleting them from |
495 |
the simpset within the theory or proof context. Rewrite rules are theorems |
|
496 |
expressing some form of equality, for example: |
|
50076 | 497 |
|
61493 | 498 |
\<open>Suc ?m + ?n = ?m + Suc ?n\<close> \\ |
499 |
\<open>?P \<and> ?P \<longleftrightarrow> ?P\<close> \\ |
|
500 |
\<open>?A \<union> ?B \<equiv> {x. x \<in> ?A \<or> x \<in> ?B}\<close> |
|
50076 | 501 |
|
61421 | 502 |
\<^medskip> |
62655 | 503 |
Conditional rewrites such as \<open>?m < ?n \<Longrightarrow> ?m div ?n = 0\<close> are also permitted; |
504 |
the conditions can be arbitrary formulas. |
|
50076 | 505 |
|
61421 | 506 |
\<^medskip> |
62655 | 507 |
Internally, all rewrite rules are translated into Pure equalities, theorems |
508 |
with conclusion \<open>lhs \<equiv> rhs\<close>. The simpset contains a function for extracting |
|
509 |
equalities from arbitrary theorems, which is usually installed when the |
|
510 |
object-logic is configured initially. For example, \<open>\<not> ?x \<in> {}\<close> could be |
|
511 |
turned into \<open>?x \<in> {} \<equiv> False\<close>. Theorems that are declared as @{attribute |
|
512 |
simp} and local assumptions within a goal are treated uniformly in this |
|
513 |
respect. |
|
50076 | 514 |
|
62655 | 515 |
The Simplifier accepts the following formats for the \<open>lhs\<close> term: |
50076 | 516 |
|
62655 | 517 |
\<^enum> First-order patterns, considering the sublanguage of application of |
518 |
constant operators to variable operands, without \<open>\<lambda>\<close>-abstractions or |
|
519 |
functional variables. For example: |
|
50076 | 520 |
|
61493 | 521 |
\<open>(?x + ?y) + ?z \<equiv> ?x + (?y + ?z)\<close> \\ |
522 |
\<open>f (f ?x ?y) ?z \<equiv> f ?x (f ?y ?z)\<close> |
|
50076 | 523 |
|
62655 | 524 |
\<^enum> Higher-order patterns in the sense of @{cite "nipkow-patterns"}. These |
525 |
are terms in \<open>\<beta>\<close>-normal form (this will always be the case unless you have |
|
526 |
done something strange) where each occurrence of an unknown is of the form |
|
527 |
\<open>?F x\<^sub>1 \<dots> x\<^sub>n\<close>, where the \<open>x\<^sub>i\<close> are distinct bound variables. |
|
50076 | 528 |
|
62655 | 529 |
For example, \<open>(\<forall>x. ?P x \<and> ?Q x) \<equiv> (\<forall>x. ?P x) \<and> (\<forall>x. ?Q x)\<close> or its |
530 |
symmetric form, since the \<open>rhs\<close> is also a higher-order pattern. |
|
50076 | 531 |
|
62655 | 532 |
\<^enum> Physical first-order patterns over raw \<open>\<lambda>\<close>-term structure without |
533 |
\<open>\<alpha>\<beta>\<eta>\<close>-equality; abstractions and bound variables are treated like |
|
534 |
quasi-constant term material. |
|
50076 | 535 |
|
62655 | 536 |
For example, the rule \<open>?f ?x \<in> range ?f = True\<close> rewrites the term \<open>g a \<in> |
537 |
range g\<close> to \<open>True\<close>, but will fail to match \<open>g (h b) \<in> range (\<lambda>x. g (h |
|
538 |
x))\<close>. However, offending subterms (in our case \<open>?f ?x\<close>, which is not a |
|
539 |
pattern) can be replaced by adding new variables and conditions like this: |
|
540 |
\<open>?y = ?f ?x \<Longrightarrow> ?y \<in> range ?f = True\<close> is acceptable as a conditional rewrite |
|
541 |
rule of the second category since conditions can be arbitrary terms. |
|
50076 | 542 |
|
61439 | 543 |
\<^descr> @{attribute split} declares case split rules. |
26782 | 544 |
|
62655 | 545 |
\<^descr> @{attribute cong} declares congruence rules to the Simplifier context. |
45645 | 546 |
|
547 |
Congruence rules are equalities of the form @{text [display] |
|
548 |
"\<dots> \<Longrightarrow> f ?x\<^sub>1 \<dots> ?x\<^sub>n = f ?y\<^sub>1 \<dots> ?y\<^sub>n"} |
|
549 |
||
62655 | 550 |
This controls the simplification of the arguments of \<open>f\<close>. For example, some |
551 |
arguments can be simplified under additional assumptions: |
|
552 |
@{text [display] |
|
553 |
"?P\<^sub>1 \<longleftrightarrow> ?Q\<^sub>1 \<Longrightarrow> |
|
554 |
(?Q\<^sub>1 \<Longrightarrow> ?P\<^sub>2 \<longleftrightarrow> ?Q\<^sub>2) \<Longrightarrow> |
|
555 |
(?P\<^sub>1 \<longrightarrow> ?P\<^sub>2) \<longleftrightarrow> (?Q\<^sub>1 \<longrightarrow> ?Q\<^sub>2)"} |
|
45645 | 556 |
|
62655 | 557 |
Given this rule, the Simplifier assumes \<open>?Q\<^sub>1\<close> and extracts rewrite rules |
558 |
from it when simplifying \<open>?P\<^sub>2\<close>. Such local assumptions are effective for |
|
559 |
rewriting formulae such as \<open>x = 0 \<longrightarrow> y + x = y\<close>. |
|
45645 | 560 |
|
561 |
%FIXME |
|
562 |
%The local assumptions are also provided as theorems to the solver; |
|
563 |
%see \secref{sec:simp-solver} below. |
|
564 |
||
61421 | 565 |
\<^medskip> |
62655 | 566 |
The following congruence rule for bounded quantifiers also supplies |
567 |
contextual information --- about the bound variable: @{text [display] |
|
568 |
"(?A = ?B) \<Longrightarrow> |
|
569 |
(\<And>x. x \<in> ?B \<Longrightarrow> ?P x \<longleftrightarrow> ?Q x) \<Longrightarrow> |
|
45645 | 570 |
(\<forall>x \<in> ?A. ?P x) \<longleftrightarrow> (\<forall>x \<in> ?B. ?Q x)"} |
571 |
||
61421 | 572 |
\<^medskip> |
62655 | 573 |
This congruence rule for conditional expressions can supply contextual |
574 |
information for simplifying the arms: @{text [display] |
|
575 |
"?p = ?q \<Longrightarrow> |
|
576 |
(?q \<Longrightarrow> ?a = ?c) \<Longrightarrow> |
|
577 |
(\<not> ?q \<Longrightarrow> ?b = ?d) \<Longrightarrow> |
|
45645 | 578 |
(if ?p then ?a else ?b) = (if ?q then ?c else ?d)"} |
579 |
||
62655 | 580 |
A congruence rule can also \<^emph>\<open>prevent\<close> simplification of some arguments. Here |
581 |
is an alternative congruence rule for conditional expressions that conforms |
|
582 |
to non-strict functional evaluation: @{text [display] |
|
583 |
"?p = ?q \<Longrightarrow> |
|
584 |
(if ?p then ?a else ?b) = (if ?q then ?a else ?b)"} |
|
45645 | 585 |
|
62655 | 586 |
Only the first argument is simplified; the others remain unchanged. This can |
587 |
make simplification much faster, but may require an extra case split over |
|
588 |
the condition \<open>?q\<close> to prove the goal. |
|
50063 | 589 |
|
62655 | 590 |
\<^descr> @{command "print_simpset"} prints the collection of rules declared to the |
591 |
Simplifier, which is also known as ``simpset'' internally; the ``\<open>!\<close>'' |
|
592 |
option indicates extra verbosity. |
|
50077 | 593 |
|
62655 | 594 |
The implicit simpset of the theory context is propagated monotonically |
595 |
through the theory hierarchy: forming a new theory, the union of the |
|
596 |
simpsets of its imports are taken as starting point. Also note that |
|
597 |
definitional packages like @{command "datatype"}, @{command "primrec"}, |
|
598 |
@{command "fun"} routinely declare Simplifier rules to the target context, |
|
599 |
while plain @{command "definition"} is an exception in \<^emph>\<open>not\<close> declaring |
|
50065 | 600 |
anything. |
601 |
||
61421 | 602 |
\<^medskip> |
62655 | 603 |
It is up the user to manipulate the current simpset further by explicitly |
604 |
adding or deleting theorems as simplification rules, or installing other |
|
605 |
tools via simplification procedures (\secref{sec:simproc}). Good simpsets |
|
606 |
are hard to design. Rules that obviously simplify, like \<open>?n + 0 \<equiv> ?n\<close> are |
|
607 |
good candidates for the implicit simpset, unless a special non-normalizing |
|
608 |
behavior of certain operations is intended. More specific rules (such as |
|
609 |
distributive laws, which duplicate subterms) should be added only for |
|
610 |
specific proof steps. Conversely, sometimes a rule needs to be deleted just |
|
611 |
for some part of a proof. The need of frequent additions or deletions may |
|
612 |
indicate a poorly designed simpset. |
|
50065 | 613 |
|
614 |
\begin{warn} |
|
62655 | 615 |
The union of simpsets from theory imports (as described above) is not always |
616 |
a good starting point for the new theory. If some ancestors have deleted |
|
617 |
simplification rules because they are no longer wanted, while others have |
|
618 |
left those rules in, then the union will contain the unwanted rules, and |
|
619 |
thus have to be deleted again in the theory body. |
|
50065 | 620 |
\end{warn} |
58618 | 621 |
\<close> |
45645 | 622 |
|
623 |
||
58618 | 624 |
subsection \<open>Ordered rewriting with permutative rules\<close> |
50080 | 625 |
|
62655 | 626 |
text \<open> |
627 |
A rewrite rule is \<^emph>\<open>permutative\<close> if the left-hand side and right-hand side |
|
628 |
are the equal up to renaming of variables. The most common permutative rule |
|
629 |
is commutativity: \<open>?x + ?y = ?y + ?x\<close>. Other examples include \<open>(?x - ?y) - |
|
630 |
?z = (?x - ?z) - ?y\<close> in arithmetic and \<open>insert ?x (insert ?y ?A) = insert ?y |
|
631 |
(insert ?x ?A)\<close> for sets. Such rules are common enough to merit special |
|
632 |
attention. |
|
50080 | 633 |
|
62655 | 634 |
Because ordinary rewriting loops given such rules, the Simplifier employs a |
635 |
special strategy, called \<^emph>\<open>ordered rewriting\<close>. Permutative rules are |
|
636 |
detected and only applied if the rewriting step decreases the redex wrt.\ a |
|
637 |
given term ordering. For example, commutativity rewrites \<open>b + a\<close> to \<open>a + b\<close>, |
|
638 |
but then stops, because the redex cannot be decreased further in the sense |
|
639 |
of the term ordering. |
|
50080 | 640 |
|
62655 | 641 |
The default is lexicographic ordering of term structure, but this could be |
642 |
also changed locally for special applications via @{index_ML |
|
67561
f0b11413f1c9
clarified signature: prefer proper order operation;
wenzelm
parents:
67399
diff
changeset
|
643 |
Simplifier.set_term_ord} in Isabelle/ML. |
50080 | 644 |
|
61421 | 645 |
\<^medskip> |
62655 | 646 |
Permutative rewrite rules are declared to the Simplifier just like other |
647 |
rewrite rules. Their special status is recognized automatically, and their |
|
648 |
application is guarded by the term ordering accordingly. |
|
649 |
\<close> |
|
50080 | 650 |
|
651 |
||
58618 | 652 |
subsubsection \<open>Rewriting with AC operators\<close> |
50080 | 653 |
|
62655 | 654 |
text \<open> |
655 |
Ordered rewriting is particularly effective in the case of |
|
656 |
associative-commutative operators. (Associativity by itself is not |
|
657 |
permutative.) When dealing with an AC-operator \<open>f\<close>, keep the following |
|
658 |
points in mind: |
|
50080 | 659 |
|
62655 | 660 |
\<^item> The associative law must always be oriented from left to right, namely |
661 |
\<open>f (f x y) z = f x (f y z)\<close>. The opposite orientation, if used with |
|
662 |
commutativity, leads to looping in conjunction with the standard term |
|
663 |
order. |
|
50080 | 664 |
|
62655 | 665 |
\<^item> To complete your set of rewrite rules, you must add not just |
666 |
associativity (A) and commutativity (C) but also a derived rule |
|
667 |
\<^emph>\<open>left-commutativity\<close> (LC): \<open>f x (f y z) = f y (f x z)\<close>. |
|
50080 | 668 |
|
669 |
Ordered rewriting with the combination of A, C, and LC sorts a term |
|
670 |
lexicographically --- the rewriting engine imitates bubble-sort. |
|
58618 | 671 |
\<close> |
50080 | 672 |
|
59905 | 673 |
experiment |
50080 | 674 |
fixes f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infix "\<bullet>" 60) |
675 |
assumes assoc: "(x \<bullet> y) \<bullet> z = x \<bullet> (y \<bullet> z)" |
|
676 |
assumes commute: "x \<bullet> y = y \<bullet> x" |
|
677 |
begin |
|
678 |
||
679 |
lemma left_commute: "x \<bullet> (y \<bullet> z) = y \<bullet> (x \<bullet> z)" |
|
680 |
proof - |
|
681 |
have "(x \<bullet> y) \<bullet> z = (y \<bullet> x) \<bullet> z" by (simp only: commute) |
|
682 |
then show ?thesis by (simp only: assoc) |
|
683 |
qed |
|
684 |
||
685 |
lemmas AC_rules = assoc commute left_commute |
|
686 |
||
62655 | 687 |
text \<open> |
688 |
Thus the Simplifier is able to establish equalities with arbitrary |
|
689 |
permutations of subterms, by normalizing to a common standard form. For |
|
690 |
example: |
|
691 |
\<close> |
|
50080 | 692 |
|
693 |
lemma "(b \<bullet> c) \<bullet> a = xxx" |
|
694 |
apply (simp only: AC_rules) |
|
58618 | 695 |
txt \<open>@{subgoals}\<close> |
50080 | 696 |
oops |
697 |
||
698 |
lemma "(b \<bullet> c) \<bullet> a = a \<bullet> (b \<bullet> c)" by (simp only: AC_rules) |
|
699 |
lemma "(b \<bullet> c) \<bullet> a = c \<bullet> (b \<bullet> a)" by (simp only: AC_rules) |
|
700 |
lemma "(b \<bullet> c) \<bullet> a = (c \<bullet> b) \<bullet> a" by (simp only: AC_rules) |
|
701 |
||
702 |
end |
|
703 |
||
62655 | 704 |
text \<open> |
705 |
Martin and Nipkow @{cite "martin-nipkow"} discuss the theory and give many |
|
706 |
examples; other algebraic structures are amenable to ordered rewriting, such |
|
707 |
as Boolean rings. The Boyer-Moore theorem prover @{cite bm88book} also |
|
708 |
employs ordered rewriting. |
|
58618 | 709 |
\<close> |
50080 | 710 |
|
711 |
||
58618 | 712 |
subsubsection \<open>Re-orienting equalities\<close> |
50080 | 713 |
|
58618 | 714 |
text \<open>Another application of ordered rewriting uses the derived rule |
50080 | 715 |
@{thm [source] eq_commute}: @{thm [source = false] eq_commute} to |
716 |
reverse equations. |
|
717 |
||
718 |
This is occasionally useful to re-orient local assumptions according |
|
719 |
to the term ordering, when other built-in mechanisms of |
|
58618 | 720 |
reorientation and mutual simplification fail to apply.\<close> |
50080 | 721 |
|
722 |
||
58618 | 723 |
subsection \<open>Simplifier tracing and debugging \label{sec:simp-trace}\<close> |
50063 | 724 |
|
58618 | 725 |
text \<open> |
50063 | 726 |
\begin{tabular}{rcll} |
61493 | 727 |
@{attribute_def simp_trace} & : & \<open>attribute\<close> & default \<open>false\<close> \\ |
728 |
@{attribute_def simp_trace_depth_limit} & : & \<open>attribute\<close> & default \<open>1\<close> \\ |
|
729 |
@{attribute_def simp_debug} & : & \<open>attribute\<close> & default \<open>false\<close> \\ |
|
730 |
@{attribute_def simp_trace_new} & : & \<open>attribute\<close> \\ |
|
731 |
@{attribute_def simp_break} & : & \<open>attribute\<close> \\ |
|
50063 | 732 |
\end{tabular} |
61421 | 733 |
\<^medskip> |
50063 | 734 |
|
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
735 |
@{rail \<open> |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
736 |
@@{attribute simp_trace_new} ('interactive')? \<newline> |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
737 |
('mode' '=' ('full' | 'normal'))? \<newline> |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
738 |
('depth' '=' @{syntax nat})? |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
739 |
; |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
740 |
|
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
741 |
@@{attribute simp_break} (@{syntax term}*) |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
742 |
\<close>} |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
743 |
|
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
744 |
These attributes and configurations options control various aspects of |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
745 |
Simplifier tracing and debugging. |
50063 | 746 |
|
62655 | 747 |
\<^descr> @{attribute simp_trace} makes the Simplifier output internal operations. |
748 |
This includes rewrite steps, but also bookkeeping like modifications of the |
|
749 |
simpset. |
|
50063 | 750 |
|
62655 | 751 |
\<^descr> @{attribute simp_trace_depth_limit} limits the effect of @{attribute |
752 |
simp_trace} to the given depth of recursive Simplifier invocations (when |
|
753 |
solving conditions of rewrite rules). |
|
50063 | 754 |
|
62655 | 755 |
\<^descr> @{attribute simp_debug} makes the Simplifier output some extra information |
756 |
about internal operations. This includes any attempted invocation of |
|
757 |
simplification procedures. |
|
50063 | 758 |
|
61439 | 759 |
\<^descr> @{attribute simp_trace_new} controls Simplifier tracing within |
58552 | 760 |
Isabelle/PIDE applications, notably Isabelle/jEdit @{cite "isabelle-jedit"}. |
62655 | 761 |
This provides a hierarchical representation of the rewriting steps performed |
762 |
by the Simplifier. |
|
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
763 |
|
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
764 |
Users can configure the behaviour by specifying breakpoints, verbosity and |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
765 |
enabling or disabling the interactive mode. In normal verbosity (the |
62655 | 766 |
default), only rule applications matching a breakpoint will be shown to the |
767 |
user. In full verbosity, all rule applications will be logged. Interactive |
|
768 |
mode interrupts the normal flow of the Simplifier and defers the decision |
|
769 |
how to continue to the user via some GUI dialog. |
|
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
770 |
|
61439 | 771 |
\<^descr> @{attribute simp_break} declares term or theorem breakpoints for |
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
772 |
@{attribute simp_trace_new} as described above. Term breakpoints are |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
773 |
patterns which are checked for matches on the redex of a rule application. |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
774 |
Theorem breakpoints trigger when the corresponding theorem is applied in a |
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
775 |
rewrite step. For example: |
58618 | 776 |
\<close> |
50063 | 777 |
|
59905 | 778 |
(*<*)experiment begin(*>*) |
57591
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents:
57590
diff
changeset
|
779 |
declare conjI [simp_break] |
57590 | 780 |
declare [[simp_break "?x \<and> ?y"]] |
59905 | 781 |
(*<*)end(*>*) |
57590 | 782 |
|
50063 | 783 |
|
58618 | 784 |
subsection \<open>Simplification procedures \label{sec:simproc}\<close> |
26782 | 785 |
|
62655 | 786 |
text \<open> |
787 |
Simplification procedures are ML functions that produce proven rewrite rules |
|
788 |
on demand. They are associated with higher-order patterns that approximate |
|
789 |
the left-hand sides of equations. The Simplifier first matches the current |
|
790 |
redex against one of the LHS patterns; if this succeeds, the corresponding |
|
791 |
ML function is invoked, passing the Simplifier context and redex term. Thus |
|
792 |
rules may be specifically fashioned for particular situations, resulting in |
|
793 |
a more powerful mechanism than term rewriting by a fixed set of rules. |
|
42925 | 794 |
|
62655 | 795 |
Any successful result needs to be a (possibly conditional) rewrite rule \<open>t \<equiv> |
796 |
u\<close> that is applicable to the current redex. The rule will be applied just as |
|
797 |
any ordinary rewrite rule. It is expected to be already in \<^emph>\<open>internal form\<close>, |
|
798 |
bypassing the automatic preprocessing of object-level equivalences. |
|
42925 | 799 |
|
26782 | 800 |
\begin{matharray}{rcl} |
61493 | 801 |
@{command_def "simproc_setup"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\ |
802 |
simproc & : & \<open>attribute\<close> \\ |
|
26782 | 803 |
\end{matharray} |
804 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
805 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
806 |
@@{command simproc_setup} @{syntax name} '(' (@{syntax term} + '|') ')' '=' |
62913 | 807 |
@{syntax text}; |
26782 | 808 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
809 |
@@{attribute simproc} (('add' ':')? | 'del' ':') (@{syntax name}+) |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
810 |
\<close>} |
26782 | 811 |
|
62655 | 812 |
\<^descr> @{command "simproc_setup"} defines a named simplification procedure that |
813 |
is invoked by the Simplifier whenever any of the given term patterns match |
|
814 |
the current redex. The implementation, which is provided as ML source text, |
|
815 |
needs to be of type |
|
816 |
@{ML_type "morphism -> Proof.context -> cterm -> thm option"}, where the |
|
817 |
@{ML_type cterm} represents the current redex \<open>r\<close> and the result is supposed |
|
818 |
to be some proven rewrite rule \<open>r \<equiv> r'\<close> (or a generalized version), or @{ML |
|
819 |
NONE} to indicate failure. The @{ML_type Proof.context} argument holds the |
|
820 |
full context of the current Simplifier invocation. The @{ML_type morphism} |
|
821 |
informs about the difference of the original compilation context wrt.\ the |
|
62913 | 822 |
one of the actual application later on. |
26782 | 823 |
|
62913 | 824 |
Morphisms are only relevant for simprocs that are defined within a local |
825 |
target context, e.g.\ in a locale. |
|
26782 | 826 |
|
62655 | 827 |
\<^descr> \<open>simproc add: name\<close> and \<open>simproc del: name\<close> add or delete named simprocs |
828 |
to the current Simplifier context. The default is to add a simproc. Note |
|
829 |
that @{command "simproc_setup"} already adds the new simproc to the |
|
830 |
subsequent context. |
|
58618 | 831 |
\<close> |
26782 | 832 |
|
833 |
||
58618 | 834 |
subsubsection \<open>Example\<close> |
42925 | 835 |
|
62655 | 836 |
text \<open> |
837 |
The following simplification procedure for @{thm [source = false, |
|
838 |
show_types] unit_eq} in HOL performs fine-grained control over rule |
|
839 |
application, beyond higher-order pattern matching. Declaring @{thm unit_eq} |
|
840 |
as @{attribute simp} directly would make the Simplifier loop! Note that a |
|
841 |
version of this simplification procedure is already active in Isabelle/HOL. |
|
842 |
\<close> |
|
42925 | 843 |
|
59905 | 844 |
(*<*)experiment begin(*>*) |
59782 | 845 |
simproc_setup unit ("x::unit") = |
846 |
\<open>fn _ => fn _ => fn ct => |
|
59582 | 847 |
if HOLogic.is_unit (Thm.term_of ct) then NONE |
59782 | 848 |
else SOME (mk_meta_eq @{thm unit_eq})\<close> |
59905 | 849 |
(*<*)end(*>*) |
42925 | 850 |
|
62655 | 851 |
text \<open> |
852 |
Since the Simplifier applies simplification procedures frequently, it is |
|
853 |
important to make the failure check in ML reasonably fast.\<close> |
|
42925 | 854 |
|
855 |
||
58618 | 856 |
subsection \<open>Configurable Simplifier strategies \label{sec:simp-strategies}\<close> |
50079 | 857 |
|
62655 | 858 |
text \<open> |
859 |
The core term-rewriting engine of the Simplifier is normally used in |
|
860 |
combination with some add-on components that modify the strategy and allow |
|
861 |
to integrate other non-Simplifier proof tools. These may be reconfigured in |
|
862 |
ML as explained below. Even if the default strategies of object-logics like |
|
863 |
Isabelle/HOL are used unchanged, it helps to understand how the standard |
|
864 |
Simplifier strategies work.\<close> |
|
50079 | 865 |
|
866 |
||
58618 | 867 |
subsubsection \<open>The subgoaler\<close> |
50079 | 868 |
|
58618 | 869 |
text \<open> |
50079 | 870 |
\begin{mldecls} |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
871 |
@{index_ML Simplifier.set_subgoaler: "(Proof.context -> int -> tactic) -> |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
872 |
Proof.context -> Proof.context"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
873 |
@{index_ML Simplifier.prems_of: "Proof.context -> thm list"} \\ |
50079 | 874 |
\end{mldecls} |
875 |
||
876 |
The subgoaler is the tactic used to solve subgoals arising out of |
|
62655 | 877 |
conditional rewrite rules or congruence rules. The default should be |
878 |
simplification itself. In rare situations, this strategy may need to be |
|
879 |
changed. For example, if the premise of a conditional rule is an instance of |
|
880 |
its conclusion, as in \<open>Suc ?m < ?n \<Longrightarrow> ?m < ?n\<close>, the default strategy could |
|
881 |
loop. % FIXME !?? |
|
50079 | 882 |
|
62655 | 883 |
\<^descr> @{ML Simplifier.set_subgoaler}~\<open>tac ctxt\<close> sets the subgoaler of the |
884 |
context to \<open>tac\<close>. The tactic will be applied to the context of the running |
|
885 |
Simplifier instance. |
|
50079 | 886 |
|
62655 | 887 |
\<^descr> @{ML Simplifier.prems_of}~\<open>ctxt\<close> retrieves the current set of premises |
888 |
from the context. This may be non-empty only if the Simplifier has been |
|
889 |
told to utilize local assumptions in the first place (cf.\ the options in |
|
890 |
\secref{sec:simp-meth}). |
|
50079 | 891 |
|
892 |
As an example, consider the following alternative subgoaler: |
|
58618 | 893 |
\<close> |
50079 | 894 |
|
59905 | 895 |
ML_val \<open> |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
896 |
fun subgoaler_tac ctxt = |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58618
diff
changeset
|
897 |
assume_tac ctxt ORELSE' |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
898 |
resolve_tac ctxt (Simplifier.prems_of ctxt) ORELSE' |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
899 |
asm_simp_tac ctxt |
58618 | 900 |
\<close> |
50079 | 901 |
|
62655 | 902 |
text \<open> |
903 |
This tactic first tries to solve the subgoal by assumption or by resolving |
|
904 |
with with one of the premises, calling simplification only if that fails.\<close> |
|
50079 | 905 |
|
906 |
||
58618 | 907 |
subsubsection \<open>The solver\<close> |
50079 | 908 |
|
58618 | 909 |
text \<open> |
50079 | 910 |
\begin{mldecls} |
911 |
@{index_ML_type solver} \\ |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
912 |
@{index_ML Simplifier.mk_solver: "string -> |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
913 |
(Proof.context -> int -> tactic) -> solver"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
914 |
@{index_ML_op setSolver: "Proof.context * solver -> Proof.context"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
915 |
@{index_ML_op addSolver: "Proof.context * solver -> Proof.context"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
916 |
@{index_ML_op setSSolver: "Proof.context * solver -> Proof.context"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
917 |
@{index_ML_op addSSolver: "Proof.context * solver -> Proof.context"} \\ |
50079 | 918 |
\end{mldecls} |
919 |
||
62655 | 920 |
A solver is a tactic that attempts to solve a subgoal after simplification. |
921 |
Its core functionality is to prove trivial subgoals such as @{prop "True"} |
|
922 |
and \<open>t = t\<close>, but object-logics might be more ambitious. For example, |
|
923 |
Isabelle/HOL performs a restricted version of linear arithmetic here. |
|
50079 | 924 |
|
62655 | 925 |
Solvers are packaged up in abstract type @{ML_type solver}, with @{ML |
926 |
Simplifier.mk_solver} as the only operation to create a solver. |
|
50079 | 927 |
|
61421 | 928 |
\<^medskip> |
62655 | 929 |
Rewriting does not instantiate unknowns. For example, rewriting alone cannot |
930 |
prove \<open>a \<in> ?A\<close> since this requires instantiating \<open>?A\<close>. The solver, however, |
|
931 |
is an arbitrary tactic and may instantiate unknowns as it pleases. This is |
|
932 |
the only way the Simplifier can handle a conditional rewrite rule whose |
|
933 |
condition contains extra variables. When a simplification tactic is to be |
|
934 |
combined with other provers, especially with the Classical Reasoner, it is |
|
935 |
important whether it can be considered safe or not. For this reason a |
|
936 |
simpset contains two solvers: safe and unsafe. |
|
50079 | 937 |
|
62655 | 938 |
The standard simplification strategy solely uses the unsafe solver, which is |
939 |
appropriate in most cases. For special applications where the simplification |
|
940 |
process is not allowed to instantiate unknowns within the goal, |
|
941 |
simplification starts with the safe solver, but may still apply the ordinary |
|
942 |
unsafe one in nested simplifications for conditional rules or congruences. |
|
943 |
Note that in this way the overall tactic is not totally safe: it may |
|
944 |
instantiate unknowns that appear also in other subgoals. |
|
50079 | 945 |
|
62655 | 946 |
\<^descr> @{ML Simplifier.mk_solver}~\<open>name tac\<close> turns \<open>tac\<close> into a solver; the |
947 |
\<open>name\<close> is only attached as a comment and has no further significance. |
|
50079 | 948 |
|
62655 | 949 |
\<^descr> \<open>ctxt setSSolver solver\<close> installs \<open>solver\<close> as the safe solver of \<open>ctxt\<close>. |
50079 | 950 |
|
62655 | 951 |
\<^descr> \<open>ctxt addSSolver solver\<close> adds \<open>solver\<close> as an additional safe solver; it |
952 |
will be tried after the solvers which had already been present in \<open>ctxt\<close>. |
|
50079 | 953 |
|
62655 | 954 |
\<^descr> \<open>ctxt setSolver solver\<close> installs \<open>solver\<close> as the unsafe solver of \<open>ctxt\<close>. |
955 |
||
956 |
\<^descr> \<open>ctxt addSolver solver\<close> adds \<open>solver\<close> as an additional unsafe solver; it |
|
957 |
will be tried after the solvers which had already been present in \<open>ctxt\<close>. |
|
50079 | 958 |
|
959 |
||
61421 | 960 |
\<^medskip> |
62655 | 961 |
The solver tactic is invoked with the context of the running Simplifier. |
962 |
Further operations may be used to retrieve relevant information, such as the |
|
963 |
list of local Simplifier premises via @{ML Simplifier.prems_of} --- this |
|
964 |
list may be non-empty only if the Simplifier runs in a mode that utilizes |
|
965 |
local assumptions (see also \secref{sec:simp-meth}). The solver is also |
|
966 |
presented the full goal including its assumptions in any case. Thus it can |
|
967 |
use these (e.g.\ by calling @{ML assume_tac}), even if the Simplifier proper |
|
968 |
happens to ignore local premises at the moment. |
|
50079 | 969 |
|
61421 | 970 |
\<^medskip> |
62655 | 971 |
As explained before, the subgoaler is also used to solve the premises of |
972 |
congruence rules. These are usually of the form \<open>s = ?x\<close>, where \<open>s\<close> needs to |
|
973 |
be simplified and \<open>?x\<close> needs to be instantiated with the result. Typically, |
|
50079 | 974 |
the subgoaler will invoke the Simplifier at some point, which will |
62655 | 975 |
eventually call the solver. For this reason, solver tactics must be prepared |
976 |
to solve goals of the form \<open>t = ?x\<close>, usually by reflexivity. In particular, |
|
977 |
reflexivity should be tried before any of the fancy automated proof tools. |
|
50079 | 978 |
|
62655 | 979 |
It may even happen that due to simplification the subgoal is no longer an |
980 |
equality. For example, \<open>False \<longleftrightarrow> ?Q\<close> could be rewritten to \<open>\<not> ?Q\<close>. To cover |
|
981 |
this case, the solver could try resolving with the theorem \<open>\<not> False\<close> of the |
|
50079 | 982 |
object-logic. |
983 |
||
61421 | 984 |
\<^medskip> |
50079 | 985 |
\begin{warn} |
62655 | 986 |
If a premise of a congruence rule cannot be proved, then the congruence is |
987 |
ignored. This should only happen if the rule is \<^emph>\<open>conditional\<close> --- that is, |
|
988 |
contains premises not of the form \<open>t = ?x\<close>. Otherwise it indicates that some |
|
989 |
congruence rule, or possibly the subgoaler or solver, is faulty. |
|
50079 | 990 |
\end{warn} |
58618 | 991 |
\<close> |
50079 | 992 |
|
993 |
||
58618 | 994 |
subsubsection \<open>The looper\<close> |
50079 | 995 |
|
58618 | 996 |
text \<open> |
50079 | 997 |
\begin{mldecls} |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
998 |
@{index_ML_op setloop: "Proof.context * |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
999 |
(Proof.context -> int -> tactic) -> Proof.context"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1000 |
@{index_ML_op addloop: "Proof.context * |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1001 |
(string * (Proof.context -> int -> tactic)) |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1002 |
-> Proof.context"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1003 |
@{index_ML_op delloop: "Proof.context * string -> Proof.context"} \\ |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1004 |
@{index_ML Splitter.add_split: "thm -> Proof.context -> Proof.context"} \\ |
63650 | 1005 |
@{index_ML Splitter.add_split: "thm -> Proof.context -> Proof.context"} \\ |
1006 |
@{index_ML Splitter.add_split_bang: " |
|
1007 |
thm -> Proof.context -> Proof.context"} \\ |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1008 |
@{index_ML Splitter.del_split: "thm -> Proof.context -> Proof.context"} \\ |
50079 | 1009 |
\end{mldecls} |
1010 |
||
62655 | 1011 |
The looper is a list of tactics that are applied after simplification, in |
1012 |
case the solver failed to solve the simplified goal. If the looper succeeds, |
|
1013 |
the simplification process is started all over again. Each of the subgoals |
|
1014 |
generated by the looper is attacked in turn, in reverse order. |
|
50079 | 1015 |
|
62655 | 1016 |
A typical looper is \<^emph>\<open>case splitting\<close>: the expansion of a conditional. |
1017 |
Another possibility is to apply an elimination rule on the assumptions. More |
|
1018 |
adventurous loopers could start an induction. |
|
50079 | 1019 |
|
62655 | 1020 |
\<^descr> \<open>ctxt setloop tac\<close> installs \<open>tac\<close> as the only looper tactic of \<open>ctxt\<close>. |
50079 | 1021 |
|
62655 | 1022 |
\<^descr> \<open>ctxt addloop (name, tac)\<close> adds \<open>tac\<close> as an additional looper tactic |
1023 |
with name \<open>name\<close>, which is significant for managing the collection of |
|
1024 |
loopers. The tactic will be tried after the looper tactics that had |
|
1025 |
already been present in \<open>ctxt\<close>. |
|
50079 | 1026 |
|
62655 | 1027 |
\<^descr> \<open>ctxt delloop name\<close> deletes the looper tactic that was associated with |
1028 |
\<open>name\<close> from \<open>ctxt\<close>. |
|
50079 | 1029 |
|
63650 | 1030 |
\<^descr> @{ML Splitter.add_split}~\<open>thm ctxt\<close> adds split tactic |
1031 |
for \<open>thm\<close> as additional looper tactic of \<open>ctxt\<close> |
|
1032 |
(overwriting previous split tactic for the same constant). |
|
1033 |
||
1034 |
\<^descr> @{ML Splitter.add_split_bang}~\<open>thm ctxt\<close> adds aggressive |
|
1035 |
(see \S\ref{sec:simp-meth}) |
|
1036 |
split tactic for \<open>thm\<close> as additional looper tactic of \<open>ctxt\<close> |
|
1037 |
(overwriting previous split tactic for the same constant). |
|
50079 | 1038 |
|
62655 | 1039 |
\<^descr> @{ML Splitter.del_split}~\<open>thm ctxt\<close> deletes the split tactic |
1040 |
corresponding to \<open>thm\<close> from the looper tactics of \<open>ctxt\<close>. |
|
50079 | 1041 |
|
62655 | 1042 |
The splitter replaces applications of a given function; the right-hand side |
1043 |
of the replacement can be anything. For example, here is a splitting rule |
|
1044 |
for conditional expressions: |
|
50079 | 1045 |
|
1046 |
@{text [display] "?P (if ?Q ?x ?y) \<longleftrightarrow> (?Q \<longrightarrow> ?P ?x) \<and> (\<not> ?Q \<longrightarrow> ?P ?y)"} |
|
1047 |
||
62655 | 1048 |
Another example is the elimination operator for Cartesian products (which |
1049 |
happens to be called @{const case_prod} in Isabelle/HOL: |
|
50079 | 1050 |
|
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
61421
diff
changeset
|
1051 |
@{text [display] "?P (case_prod ?f ?p) \<longleftrightarrow> (\<forall>a b. ?p = (a, b) \<longrightarrow> ?P (f a b))"} |
50079 | 1052 |
|
62655 | 1053 |
For technical reasons, there is a distinction between case splitting in the |
1054 |
conclusion and in the premises of a subgoal. The former is done by @{ML |
|
1055 |
Splitter.split_tac} with rules like @{thm [source] if_split} or @{thm |
|
1056 |
[source] option.split}, which do not split the subgoal, while the latter is |
|
1057 |
done by @{ML Splitter.split_asm_tac} with rules like @{thm [source] |
|
1058 |
if_split_asm} or @{thm [source] option.split_asm}, which split the subgoal. |
|
1059 |
The function @{ML Splitter.add_split} automatically takes care of which |
|
1060 |
tactic to call, analyzing the form of the rules given as argument; it is the |
|
1061 |
same operation behind \<open>split\<close> attribute or method modifier syntax in the |
|
1062 |
Isar source language. |
|
50079 | 1063 |
|
62655 | 1064 |
Case splits should be allowed only when necessary; they are expensive and |
1065 |
hard to control. Case-splitting on if-expressions in the conclusion is |
|
1066 |
usually beneficial, so it is enabled by default in Isabelle/HOL and |
|
1067 |
Isabelle/FOL/ZF. |
|
50079 | 1068 |
|
1069 |
\begin{warn} |
|
62655 | 1070 |
With @{ML Splitter.split_asm_tac} as looper component, the Simplifier may |
1071 |
split subgoals! This might cause unexpected problems in tactic expressions |
|
1072 |
that silently assume 0 or 1 subgoals after simplification. |
|
50079 | 1073 |
\end{warn} |
58618 | 1074 |
\<close> |
50079 | 1075 |
|
1076 |
||
58618 | 1077 |
subsection \<open>Forward simplification \label{sec:simp-forward}\<close> |
26782 | 1078 |
|
58618 | 1079 |
text \<open> |
26782 | 1080 |
\begin{matharray}{rcl} |
61493 | 1081 |
@{attribute_def simplified} & : & \<open>attribute\<close> \\ |
26782 | 1082 |
\end{matharray} |
1083 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1084 |
@{rail \<open> |
62969 | 1085 |
@@{attribute simplified} opt? @{syntax thms}? |
26782 | 1086 |
; |
1087 |
||
40255
9ffbc25e1606
eliminated obsolete \_ escapes in rail environments;
wenzelm
parents:
35613
diff
changeset
|
1088 |
opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use') ')' |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1089 |
\<close>} |
26782 | 1090 |
|
62655 | 1091 |
\<^descr> @{attribute simplified}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> causes a theorem to be simplified, |
1092 |
either by exactly the specified rules \<open>a\<^sub>1, \<dots>, a\<^sub>n\<close>, or the implicit |
|
1093 |
Simplifier context if no arguments are given. The result is fully simplified |
|
1094 |
by default, including assumptions and conclusion; the options \<open>no_asm\<close> etc.\ |
|
1095 |
tune the Simplifier in the same way as the for the \<open>simp\<close> method. |
|
26782 | 1096 |
|
62655 | 1097 |
Note that forward simplification restricts the Simplifier to its most basic |
1098 |
operation of term rewriting; solver and looper tactics |
|
1099 |
(\secref{sec:simp-strategies}) are \<^emph>\<open>not\<close> involved here. The @{attribute |
|
1100 |
simplified} attribute should be only rarely required under normal |
|
1101 |
circumstances. |
|
58618 | 1102 |
\<close> |
26782 | 1103 |
|
1104 |
||
58618 | 1105 |
section \<open>The Classical Reasoner \label{sec:classical}\<close> |
26782 | 1106 |
|
58618 | 1107 |
subsection \<open>Basic concepts\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1108 |
|
58618 | 1109 |
text \<open>Although Isabelle is generic, many users will be working in |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1110 |
some extension of classical first-order logic. Isabelle/ZF is built |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1111 |
upon theory FOL, while Isabelle/HOL conceptually contains |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1112 |
first-order logic as a fragment. Theorem-proving in predicate logic |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1113 |
is undecidable, but many automated strategies have been developed to |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1114 |
assist in this task. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1115 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1116 |
Isabelle's classical reasoner is a generic package that accepts |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1117 |
certain information about a logic and delivers a suite of automatic |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1118 |
proof tools, based on rules that are classified and declared in the |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1119 |
context. These proof procedures are slow and simplistic compared |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1120 |
with high-end automated theorem provers, but they can save |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1121 |
considerable time and effort in practice. They can prove theorems |
58552 | 1122 |
such as Pelletier's @{cite pelletier86} problems 40 and 41 in a few |
58618 | 1123 |
milliseconds (including full proof reconstruction):\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1124 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1125 |
lemma "(\<exists>y. \<forall>x. F x y \<longleftrightarrow> F x x) \<longrightarrow> \<not> (\<forall>x. \<exists>y. \<forall>z. F z y \<longleftrightarrow> \<not> F z x)" |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1126 |
by blast |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1127 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1128 |
lemma "(\<forall>z. \<exists>y. \<forall>x. f x y \<longleftrightarrow> f x z \<and> \<not> f x x) \<longrightarrow> \<not> (\<exists>z. \<forall>x. f x z)" |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1129 |
by blast |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1130 |
|
58618 | 1131 |
text \<open>The proof tools are generic. They are not restricted to |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1132 |
first-order logic, and have been heavily used in the development of |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1133 |
the Isabelle/HOL library and applications. The tactics can be |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1134 |
traced, and their components can be called directly; in this manner, |
58618 | 1135 |
any proof can be viewed interactively.\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1136 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1137 |
|
58618 | 1138 |
subsubsection \<open>The sequent calculus\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1139 |
|
58618 | 1140 |
text \<open>Isabelle supports natural deduction, which is easy to use for |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1141 |
interactive proof. But natural deduction does not easily lend |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1142 |
itself to automation, and has a bias towards intuitionism. For |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1143 |
certain proofs in classical logic, it can not be called natural. |
61477 | 1144 |
The \<^emph>\<open>sequent calculus\<close>, a generalization of natural deduction, |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1145 |
is easier to automate. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1146 |
|
61493 | 1147 |
A \<^bold>\<open>sequent\<close> has the form \<open>\<Gamma> \<turnstile> \<Delta>\<close>, where \<open>\<Gamma>\<close> |
61572 | 1148 |
and \<open>\<Delta>\<close> are sets of formulae.\<^footnote>\<open>For first-order |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1149 |
logic, sequents can equivalently be made from lists or multisets of |
61572 | 1150 |
formulae.\<close> The sequent \<open>P\<^sub>1, \<dots>, P\<^sub>m \<turnstile> Q\<^sub>1, \<dots>, Q\<^sub>n\<close> is |
61493 | 1151 |
\<^bold>\<open>valid\<close> if \<open>P\<^sub>1 \<and> \<dots> \<and> P\<^sub>m\<close> implies \<open>Q\<^sub>1 \<or> \<dots> \<or> |
1152 |
Q\<^sub>n\<close>. Thus \<open>P\<^sub>1, \<dots>, P\<^sub>m\<close> represent assumptions, each of which |
|
1153 |
is true, while \<open>Q\<^sub>1, \<dots>, Q\<^sub>n\<close> represent alternative goals. A |
|
61477 | 1154 |
sequent is \<^bold>\<open>basic\<close> if its left and right sides have a common |
61493 | 1155 |
formula, as in \<open>P, Q \<turnstile> Q, R\<close>; basic sequents are trivially |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1156 |
valid. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1157 |
|
61477 | 1158 |
Sequent rules are classified as \<^bold>\<open>right\<close> or \<^bold>\<open>left\<close>, |
61493 | 1159 |
indicating which side of the \<open>\<turnstile>\<close> symbol they operate on. |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1160 |
Rules that operate on the right side are analogous to natural |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1161 |
deduction's introduction rules, and left rules are analogous to |
61493 | 1162 |
elimination rules. The sequent calculus analogue of \<open>(\<longrightarrow>I)\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1163 |
is the rule |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1164 |
\[ |
61493 | 1165 |
\infer[\<open>(\<longrightarrow>R)\<close>]{\<open>\<Gamma> \<turnstile> \<Delta>, P \<longrightarrow> Q\<close>}{\<open>P, \<Gamma> \<turnstile> \<Delta>, Q\<close>} |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1166 |
\] |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1167 |
Applying the rule backwards, this breaks down some implication on |
61493 | 1168 |
the right side of a sequent; \<open>\<Gamma>\<close> and \<open>\<Delta>\<close> stand for |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1169 |
the sets of formulae that are unaffected by the inference. The |
61493 | 1170 |
analogue of the pair \<open>(\<or>I1)\<close> and \<open>(\<or>I2)\<close> is the |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1171 |
single rule |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1172 |
\[ |
61493 | 1173 |
\infer[\<open>(\<or>R)\<close>]{\<open>\<Gamma> \<turnstile> \<Delta>, P \<or> Q\<close>}{\<open>\<Gamma> \<turnstile> \<Delta>, P, Q\<close>} |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1174 |
\] |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1175 |
This breaks down some disjunction on the right side, replacing it by |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1176 |
both disjuncts. Thus, the sequent calculus is a kind of |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1177 |
multiple-conclusion logic. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1178 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1179 |
To illustrate the use of multiple formulae on the right, let us |
61493 | 1180 |
prove the classical theorem \<open>(P \<longrightarrow> Q) \<or> (Q \<longrightarrow> P)\<close>. Working |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1181 |
backwards, we reduce this formula to a basic sequent: |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1182 |
\[ |
61493 | 1183 |
\infer[\<open>(\<or>R)\<close>]{\<open>\<turnstile> (P \<longrightarrow> Q) \<or> (Q \<longrightarrow> P)\<close>} |
1184 |
{\infer[\<open>(\<longrightarrow>R)\<close>]{\<open>\<turnstile> (P \<longrightarrow> Q), (Q \<longrightarrow> P)\<close>} |
|
1185 |
{\infer[\<open>(\<longrightarrow>R)\<close>]{\<open>P \<turnstile> Q, (Q \<longrightarrow> P)\<close>} |
|
1186 |
{\<open>P, Q \<turnstile> Q, P\<close>}}} |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1187 |
\] |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1188 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1189 |
This example is typical of the sequent calculus: start with the |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1190 |
desired theorem and apply rules backwards in a fairly arbitrary |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1191 |
manner. This yields a surprisingly effective proof procedure. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1192 |
Quantifiers add only few complications, since Isabelle handles |
58552 | 1193 |
parameters and schematic variables. See @{cite \<open>Chapter 10\<close> |
58618 | 1194 |
"paulson-ml2"} for further discussion.\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1195 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1196 |
|
58618 | 1197 |
subsubsection \<open>Simulating sequents by natural deduction\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1198 |
|
58618 | 1199 |
text \<open>Isabelle can represent sequents directly, as in the |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1200 |
object-logic LK. But natural deduction is easier to work with, and |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1201 |
most object-logics employ it. Fortunately, we can simulate the |
61493 | 1202 |
sequent \<open>P\<^sub>1, \<dots>, P\<^sub>m \<turnstile> Q\<^sub>1, \<dots>, Q\<^sub>n\<close> by the Isabelle formula |
1203 |
\<open>P\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> P\<^sub>m \<Longrightarrow> \<not> Q\<^sub>2 \<Longrightarrow> ... \<Longrightarrow> \<not> Q\<^sub>n \<Longrightarrow> Q\<^sub>1\<close> where the order of |
|
1204 |
the assumptions and the choice of \<open>Q\<^sub>1\<close> are arbitrary. |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1205 |
Elim-resolution plays a key role in simulating sequent proofs. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1206 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1207 |
We can easily handle reasoning on the left. Elim-resolution with |
61493 | 1208 |
the rules \<open>(\<or>E)\<close>, \<open>(\<bottom>E)\<close> and \<open>(\<exists>E)\<close> achieves |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1209 |
a similar effect as the corresponding sequent rules. For the other |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1210 |
connectives, we use sequent-style elimination rules instead of |
61493 | 1211 |
destruction rules such as \<open>(\<and>E1, 2)\<close> and \<open>(\<forall>E)\<close>. |
1212 |
But note that the rule \<open>(\<not>L)\<close> has no effect under our |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1213 |
representation of sequents! |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1214 |
\[ |
61493 | 1215 |
\infer[\<open>(\<not>L)\<close>]{\<open>\<not> P, \<Gamma> \<turnstile> \<Delta>\<close>}{\<open>\<Gamma> \<turnstile> \<Delta>, P\<close>} |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1216 |
\] |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1217 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1218 |
What about reasoning on the right? Introduction rules can only |
61493 | 1219 |
affect the formula in the conclusion, namely \<open>Q\<^sub>1\<close>. The |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1220 |
other right-side formulae are represented as negated assumptions, |
61493 | 1221 |
\<open>\<not> Q\<^sub>2, \<dots>, \<not> Q\<^sub>n\<close>. In order to operate on one of these, it |
1222 |
must first be exchanged with \<open>Q\<^sub>1\<close>. Elim-resolution with the |
|
1223 |
\<open>swap\<close> rule has this effect: \<open>\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R\<close> |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1224 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1225 |
To ensure that swaps occur only when necessary, each introduction |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1226 |
rule is converted into a swapped form: it is resolved with the |
61493 | 1227 |
second premise of \<open>(swap)\<close>. The swapped form of \<open>(\<and>I)\<close>, which might be called \<open>(\<not>\<and>E)\<close>, is |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1228 |
@{text [display] "\<not> (P \<and> Q) \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> (\<not> R \<Longrightarrow> Q) \<Longrightarrow> R"} |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1229 |
|
61493 | 1230 |
Similarly, the swapped form of \<open>(\<longrightarrow>I)\<close> is |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1231 |
@{text [display] "\<not> (P \<longrightarrow> Q) \<Longrightarrow> (\<not> R \<Longrightarrow> P \<Longrightarrow> Q) \<Longrightarrow> R"} |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1232 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1233 |
Swapped introduction rules are applied using elim-resolution, which |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1234 |
deletes the negated formula. Our representation of sequents also |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1235 |
requires the use of ordinary introduction rules. If we had no |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1236 |
regard for readability of intermediate goal states, we could treat |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1237 |
the right side more uniformly by representing sequents as @{text |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1238 |
[display] "P\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> P\<^sub>m \<Longrightarrow> \<not> Q\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> \<not> Q\<^sub>n \<Longrightarrow> \<bottom>"} |
58618 | 1239 |
\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1240 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1241 |
|
58618 | 1242 |
subsubsection \<open>Extra rules for the sequent calculus\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1243 |
|
61493 | 1244 |
text \<open>As mentioned, destruction rules such as \<open>(\<and>E1, 2)\<close> and |
1245 |
\<open>(\<forall>E)\<close> must be replaced by sequent-style elimination rules. |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1246 |
In addition, we need rules to embody the classical equivalence |
61493 | 1247 |
between \<open>P \<longrightarrow> Q\<close> and \<open>\<not> P \<or> Q\<close>. The introduction |
1248 |
rules \<open>(\<or>I1, 2)\<close> are replaced by a rule that simulates |
|
1249 |
\<open>(\<or>R)\<close>: @{text [display] "(\<not> Q \<Longrightarrow> P) \<Longrightarrow> P \<or> Q"} |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1250 |
|
61493 | 1251 |
The destruction rule \<open>(\<longrightarrow>E)\<close> is replaced by @{text [display] |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1252 |
"(P \<longrightarrow> Q) \<Longrightarrow> (\<not> P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"} |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1253 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1254 |
Quantifier replication also requires special rules. In classical |
61493 | 1255 |
logic, \<open>\<exists>x. P x\<close> is equivalent to \<open>\<not> (\<forall>x. \<not> P x)\<close>; |
1256 |
the rules \<open>(\<exists>R)\<close> and \<open>(\<forall>L)\<close> are dual: |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1257 |
\[ |
61493 | 1258 |
\infer[\<open>(\<exists>R)\<close>]{\<open>\<Gamma> \<turnstile> \<Delta>, \<exists>x. P x\<close>}{\<open>\<Gamma> \<turnstile> \<Delta>, \<exists>x. P x, P t\<close>} |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1259 |
\qquad |
61493 | 1260 |
\infer[\<open>(\<forall>L)\<close>]{\<open>\<forall>x. P x, \<Gamma> \<turnstile> \<Delta>\<close>}{\<open>P t, \<forall>x. P x, \<Gamma> \<turnstile> \<Delta>\<close>} |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1261 |
\] |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1262 |
Thus both kinds of quantifier may be replicated. Theorems requiring |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1263 |
multiple uses of a universal formula are easy to invent; consider |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1264 |
@{text [display] "(\<forall>x. P x \<longrightarrow> P (f x)) \<and> P a \<longrightarrow> P (f\<^sup>n a)"} for any |
61493 | 1265 |
\<open>n > 1\<close>. Natural examples of the multiple use of an |
1266 |
existential formula are rare; a standard one is \<open>\<exists>x. \<forall>y. P x |
|
1267 |
\<longrightarrow> P y\<close>. |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1268 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1269 |
Forgoing quantifier replication loses completeness, but gains |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1270 |
decidability, since the search space becomes finite. Many useful |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1271 |
theorems can be proved without replication, and the search generally |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1272 |
delivers its verdict in a reasonable time. To adopt this approach, |
61493 | 1273 |
represent the sequent rules \<open>(\<exists>R)\<close>, \<open>(\<exists>L)\<close> and |
1274 |
\<open>(\<forall>R)\<close> by \<open>(\<exists>I)\<close>, \<open>(\<exists>E)\<close> and \<open>(\<forall>I)\<close>, |
|
1275 |
respectively, and put \<open>(\<forall>E)\<close> into elimination form: @{text |
|
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1276 |
[display] "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> Q) \<Longrightarrow> Q"} |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1277 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1278 |
Elim-resolution with this rule will delete the universal formula |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1279 |
after a single use. To replicate universal quantifiers, replace the |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1280 |
rule by @{text [display] "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> \<forall>x. P x \<Longrightarrow> Q) \<Longrightarrow> Q"} |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1281 |
|
61493 | 1282 |
To replicate existential quantifiers, replace \<open>(\<exists>I)\<close> by |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1283 |
@{text [display] "(\<not> (\<exists>x. P x) \<Longrightarrow> P t) \<Longrightarrow> \<exists>x. P x"} |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1284 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1285 |
All introduction rules mentioned above are also useful in swapped |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1286 |
form. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1287 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1288 |
Replication makes the search space infinite; we must apply the rules |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1289 |
with care. The classical reasoner distinguishes between safe and |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1290 |
unsafe rules, applying the latter only when there is no alternative. |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1291 |
Depth-first search may well go down a blind alley; best-first search |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1292 |
is better behaved in an infinite search space. However, quantifier |
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1293 |
replication is too expensive to prove any but the simplest theorems. |
58618 | 1294 |
\<close> |
42927
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1295 |
|
c40adab7568e
moved/updated introduction to Classical Reasoner;
wenzelm
parents:
42925
diff
changeset
|
1296 |
|
58618 | 1297 |
subsection \<open>Rule declarations\<close> |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1298 |
|
58618 | 1299 |
text \<open>The proof tools of the Classical Reasoner depend on |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1300 |
collections of rules declared in the context, which are classified |
61477 | 1301 |
as introduction, elimination or destruction and as \<^emph>\<open>safe\<close> or |
1302 |
\<^emph>\<open>unsafe\<close>. In general, safe rules can be attempted blindly, |
|
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1303 |
while unsafe rules must be used with care. A safe rule must never |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1304 |
reduce a provable goal to an unprovable set of subgoals. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1305 |
|
61493 | 1306 |
The rule \<open>P \<Longrightarrow> P \<or> Q\<close> is unsafe because it reduces \<open>P |
1307 |
\<or> Q\<close> to \<open>P\<close>, which might turn out as premature choice of an |
|
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1308 |
unprovable subgoal. Any rule is unsafe whose premises contain new |
61493 | 1309 |
unknowns. The elimination rule \<open>\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> Q) \<Longrightarrow> Q\<close> is |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1310 |
unsafe, since it is applied via elim-resolution, which discards the |
61493 | 1311 |
assumption \<open>\<forall>x. P x\<close> and replaces it by the weaker |
1312 |
assumption \<open>P t\<close>. The rule \<open>P t \<Longrightarrow> \<exists>x. P x\<close> is |
|
1313 |
unsafe for similar reasons. The quantifier duplication rule \<open>\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> \<forall>x. P x \<Longrightarrow> Q) \<Longrightarrow> Q\<close> is unsafe in a different sense: |
|
1314 |
since it keeps the assumption \<open>\<forall>x. P x\<close>, it is prone to |
|
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1315 |
looping. In classical first-order logic, all rules are safe except |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1316 |
those mentioned above. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1317 |
|
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1318 |
The safe~/ unsafe distinction is vague, and may be regarded merely |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1319 |
as a way of giving some rules priority over others. One could argue |
61493 | 1320 |
that \<open>(\<or>E)\<close> is unsafe, because repeated application of it |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1321 |
could generate exponentially many subgoals. Induction rules are |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1322 |
unsafe because inductive proofs are difficult to set up |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1323 |
automatically. Any inference is unsafe that instantiates an unknown |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1324 |
in the proof state --- thus matching must be used, rather than |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1325 |
unification. Even proof by assumption is unsafe if it instantiates |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1326 |
unknowns shared with other subgoals. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1327 |
|
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1328 |
\begin{matharray}{rcl} |
61493 | 1329 |
@{command_def "print_claset"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\ |
1330 |
@{attribute_def intro} & : & \<open>attribute\<close> \\ |
|
1331 |
@{attribute_def elim} & : & \<open>attribute\<close> \\ |
|
1332 |
@{attribute_def dest} & : & \<open>attribute\<close> \\ |
|
1333 |
@{attribute_def rule} & : & \<open>attribute\<close> \\ |
|
1334 |
@{attribute_def iff} & : & \<open>attribute\<close> \\ |
|
1335 |
@{attribute_def swapped} & : & \<open>attribute\<close> \\ |
|
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1336 |
\end{matharray} |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1337 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1338 |
@{rail \<open> |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1339 |
(@@{attribute intro} | @@{attribute elim} | @@{attribute dest}) ('!' | () | '?') @{syntax nat}? |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1340 |
; |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1341 |
@@{attribute rule} 'del' |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1342 |
; |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1343 |
@@{attribute iff} (((() | 'add') '?'?) | 'del') |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1344 |
\<close>} |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1345 |
|
61439 | 1346 |
\<^descr> @{command "print_claset"} prints the collection of rules |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1347 |
declared to the Classical Reasoner, i.e.\ the @{ML_type claset} |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1348 |
within the context. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1349 |
|
61439 | 1350 |
\<^descr> @{attribute intro}, @{attribute elim}, and @{attribute dest} |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1351 |
declare introduction, elimination, and destruction rules, |
61477 | 1352 |
respectively. By default, rules are considered as \<^emph>\<open>unsafe\<close> |
61493 | 1353 |
(i.e.\ not applied blindly without backtracking), while ``\<open>!\<close>'' classifies as \<^emph>\<open>safe\<close>. Rule declarations marked by |
1354 |
``\<open>?\<close>'' coincide with those of Isabelle/Pure, cf.\ |
|
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1355 |
\secref{sec:pure-meth-att} (i.e.\ are only applied in single steps |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1356 |
of the @{method rule} method). The optional natural number |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1357 |
specifies an explicit weight argument, which is ignored by the |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1358 |
automated reasoning tools, but determines the search order of single |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1359 |
rule steps. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1360 |
|
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1361 |
Introduction rules are those that can be applied using ordinary |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1362 |
resolution. Their swapped forms are generated internally, which |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1363 |
will be applied using elim-resolution. Elimination rules are |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1364 |
applied using elim-resolution. Rules are sorted by the number of |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1365 |
new subgoals they will yield; rules that generate the fewest |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1366 |
subgoals will be tried first. Otherwise, later declarations take |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1367 |
precedence over earlier ones. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1368 |
|
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1369 |
Rules already present in the context with the same classification |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1370 |
are ignored. A warning is printed if the rule has already been |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1371 |
added with some other classification, but the rule is added anyway |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1372 |
as requested. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1373 |
|
61493 | 1374 |
\<^descr> @{attribute rule}~\<open>del\<close> deletes all occurrences of a |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1375 |
rule from the classical context, regardless of its classification as |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1376 |
introduction~/ elimination~/ destruction and safe~/ unsafe. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1377 |
|
61439 | 1378 |
\<^descr> @{attribute iff} declares logical equivalences to the |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1379 |
Simplifier and the Classical reasoner at the same time. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1380 |
Non-conditional rules result in a safe introduction and elimination |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1381 |
pair; conditional ones are considered unsafe. Rules with negative |
61493 | 1382 |
conclusion are automatically inverted (using \<open>\<not>\<close>-elimination |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1383 |
internally). |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1384 |
|
61493 | 1385 |
The ``\<open>?\<close>'' version of @{attribute iff} declares rules to |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1386 |
the Isabelle/Pure context only, and omits the Simplifier |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1387 |
declaration. |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1388 |
|
61439 | 1389 |
\<^descr> @{attribute swapped} turns an introduction rule into an |
61493 | 1390 |
elimination, by resolving with the classical swap principle \<open>\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R\<close> in the second position. This is mainly for |
42928
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1391 |
illustrative purposes: the Classical Reasoner already swaps rules |
9d946de41120
updated and re-unified classical rule declarations;
wenzelm
parents:
42927
diff
changeset
|
1392 |
internally as explained above. |
58618 | 1393 |
\<close> |
26782 | 1394 |
|
1395 |
||
58618 | 1396 |
subsection \<open>Structured methods\<close> |
43365 | 1397 |
|
58618 | 1398 |
text \<open> |
43365 | 1399 |
\begin{matharray}{rcl} |
61493 | 1400 |
@{method_def rule} & : & \<open>method\<close> \\ |
1401 |
@{method_def contradiction} & : & \<open>method\<close> \\ |
|
43365 | 1402 |
\end{matharray} |
1403 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1404 |
@{rail \<open> |
62969 | 1405 |
@@{method rule} @{syntax thms}? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1406 |
\<close>} |
43365 | 1407 |
|
61439 | 1408 |
\<^descr> @{method rule} as offered by the Classical Reasoner is a |
43365 | 1409 |
refinement over the Pure one (see \secref{sec:pure-meth-att}). Both |
1410 |
versions work the same, but the classical version observes the |
|
1411 |
classical rule context in addition to that of Isabelle/Pure. |
|
1412 |
||
1413 |
Common object logics (HOL, ZF, etc.) declare a rich collection of |
|
1414 |
classical rules (even if these would qualify as intuitionistic |
|
1415 |
ones), but only few declarations to the rule context of |
|
1416 |
Isabelle/Pure (\secref{sec:pure-meth-att}). |
|
1417 |
||
61439 | 1418 |
\<^descr> @{method contradiction} solves some goal by contradiction, |
61493 | 1419 |
deriving any result from both \<open>\<not> A\<close> and \<open>A\<close>. Chained |
43365 | 1420 |
facts, which are guaranteed to participate, may appear in either |
1421 |
order. |
|
58618 | 1422 |
\<close> |
43365 | 1423 |
|
1424 |
||
58618 | 1425 |
subsection \<open>Fully automated methods\<close> |
26782 | 1426 |
|
58618 | 1427 |
text \<open> |
26782 | 1428 |
\begin{matharray}{rcl} |
61493 | 1429 |
@{method_def blast} & : & \<open>method\<close> \\ |
1430 |
@{method_def auto} & : & \<open>method\<close> \\ |
|
1431 |
@{method_def force} & : & \<open>method\<close> \\ |
|
1432 |
@{method_def fast} & : & \<open>method\<close> \\ |
|
1433 |
@{method_def slow} & : & \<open>method\<close> \\ |
|
1434 |
@{method_def best} & : & \<open>method\<close> \\ |
|
1435 |
@{method_def fastforce} & : & \<open>method\<close> \\ |
|
1436 |
@{method_def slowsimp} & : & \<open>method\<close> \\ |
|
1437 |
@{method_def bestsimp} & : & \<open>method\<close> \\ |
|
1438 |
@{method_def deepen} & : & \<open>method\<close> \\ |
|
26782 | 1439 |
\end{matharray} |
1440 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1441 |
@{rail \<open> |
42930 | 1442 |
@@{method blast} @{syntax nat}? (@{syntax clamod} * ) |
1443 |
; |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
1444 |
@@{method auto} (@{syntax nat} @{syntax nat})? (@{syntax clasimpmod} * ) |
26782 | 1445 |
; |
42930 | 1446 |
@@{method force} (@{syntax clasimpmod} * ) |
1447 |
; |
|
1448 |
(@@{method fast} | @@{method slow} | @@{method best}) (@{syntax clamod} * ) |
|
26782 | 1449 |
; |
44911 | 1450 |
(@@{method fastforce} | @@{method slowsimp} | @@{method bestsimp}) |
42930 | 1451 |
(@{syntax clasimpmod} * ) |
1452 |
; |
|
43367 | 1453 |
@@{method deepen} (@{syntax nat} ?) (@{syntax clamod} * ) |
1454 |
; |
|
42930 | 1455 |
@{syntax_def clamod}: |
62969 | 1456 |
(('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del') ':' @{syntax thms} |
42930 | 1457 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
1458 |
@{syntax_def clasimpmod}: ('simp' (() | 'add' | 'del' | 'only') | |
63650 | 1459 |
'cong' (() | 'add' | 'del') | |
1460 |
'split' (() | '!' | 'del') | |
|
26782 | 1461 |
'iff' (((() | 'add') '?'?) | 'del') | |
62969 | 1462 |
(('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' @{syntax thms} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1463 |
\<close>} |
26782 | 1464 |
|
61439 | 1465 |
\<^descr> @{method blast} is a separate classical tableau prover that |
42930 | 1466 |
uses the same classical rule declarations as explained before. |
1467 |
||
1468 |
Proof search is coded directly in ML using special data structures. |
|
1469 |
A successful proof is then reconstructed using regular Isabelle |
|
1470 |
inferences. It is faster and more powerful than the other classical |
|
1471 |
reasoning tools, but has major limitations too. |
|
1472 |
||
61459
5f2ddeb15c06
clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents:
61458
diff
changeset
|
1473 |
\<^item> It does not use the classical wrapper tacticals, such as the |
61458 | 1474 |
integration with the Simplifier of @{method fastforce}. |
42930 | 1475 |
|
61459
5f2ddeb15c06
clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents:
61458
diff
changeset
|
1476 |
\<^item> It does not perform higher-order unification, as needed by the |
61458 | 1477 |
rule @{thm [source=false] rangeI} in HOL. There are often |
1478 |
alternatives to such rules, for example @{thm [source=false] |
|
1479 |
range_eqI}. |
|
42930 | 1480 |
|
61459
5f2ddeb15c06
clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents:
61458
diff
changeset
|
1481 |
\<^item> Function variables may only be applied to parameters of the |
61458 | 1482 |
subgoal. (This restriction arises because the prover does not use |
1483 |
higher-order unification.) If other function variables are present |
|
1484 |
then the prover will fail with the message |
|
1485 |
@{verbatim [display] \<open>Function unknown's argument not a bound variable\<close>} |
|
42930 | 1486 |
|
61459
5f2ddeb15c06
clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents:
61458
diff
changeset
|
1487 |
\<^item> Its proof strategy is more general than @{method fast} but can |
61458 | 1488 |
be slower. If @{method blast} fails or seems to be running forever, |
1489 |
try @{method fast} and the other proof tools described below. |
|
42930 | 1490 |
|
1491 |
The optional integer argument specifies a bound for the number of |
|
1492 |
unsafe steps used in a proof. By default, @{method blast} starts |
|
1493 |
with a bound of 0 and increases it successively to 20. In contrast, |
|
61493 | 1494 |
\<open>(blast lim)\<close> tries to prove the goal using a search bound |
1495 |
of \<open>lim\<close>. Sometimes a slow proof using @{method blast} can |
|
42930 | 1496 |
be made much faster by supplying the successful search bound to this |
1497 |
proof method instead. |
|
1498 |
||
61439 | 1499 |
\<^descr> @{method auto} combines classical reasoning with |
42930 | 1500 |
simplification. It is intended for situations where there are a lot |
1501 |
of mostly trivial subgoals; it proves all the easy ones, leaving the |
|
1502 |
ones it cannot prove. Occasionally, attempting to prove the hard |
|
1503 |
ones may take a long time. |
|
1504 |
||
61493 | 1505 |
The optional depth arguments in \<open>(auto m n)\<close> refer to its |
1506 |
builtin classical reasoning procedures: \<open>m\<close> (default 4) is for |
|
1507 |
@{method blast}, which is tried first, and \<open>n\<close> (default 2) is |
|
43332 | 1508 |
for a slower but more general alternative that also takes wrappers |
1509 |
into account. |
|
42930 | 1510 |
|
61439 | 1511 |
\<^descr> @{method force} is intended to prove the first subgoal |
42930 | 1512 |
completely, using many fancy proof tools and performing a rather |
1513 |
exhaustive search. As a result, proof attempts may take rather long |
|
1514 |
or diverge easily. |
|
1515 |
||
61439 | 1516 |
\<^descr> @{method fast}, @{method best}, @{method slow} attempt to |
42930 | 1517 |
prove the first subgoal using sequent-style reasoning as explained |
1518 |
before. Unlike @{method blast}, they construct proofs directly in |
|
1519 |
Isabelle. |
|
26782 | 1520 |
|
42930 | 1521 |
There is a difference in search strategy and back-tracking: @{method |
1522 |
fast} uses depth-first search and @{method best} uses best-first |
|
1523 |
search (guided by a heuristic function: normally the total size of |
|
1524 |
the proof state). |
|
1525 |
||
1526 |
Method @{method slow} is like @{method fast}, but conducts a broader |
|
1527 |
search: it may, when backtracking from a failed proof attempt, undo |
|
1528 |
even the step of proving a subgoal by assumption. |
|
1529 |
||
61439 | 1530 |
\<^descr> @{method fastforce}, @{method slowsimp}, @{method bestsimp} |
47967
c422128d3889
discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents:
47497
diff
changeset
|
1531 |
are like @{method fast}, @{method slow}, @{method best}, |
c422128d3889
discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents:
47497
diff
changeset
|
1532 |
respectively, but use the Simplifier as additional wrapper. The name |
c422128d3889
discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents:
47497
diff
changeset
|
1533 |
@{method fastforce}, reflects the behaviour of this popular method |
c422128d3889
discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents:
47497
diff
changeset
|
1534 |
better without requiring an understanding of its implementation. |
42930 | 1535 |
|
61439 | 1536 |
\<^descr> @{method deepen} works by exhaustive search up to a certain |
43367 | 1537 |
depth. The start depth is 4 (unless specified explicitly), and the |
1538 |
depth is increased iteratively up to 10. Unsafe rules are modified |
|
1539 |
to preserve the formula they act on, so that it be used repeatedly. |
|
1540 |
This method can prove more goals than @{method fast}, but is much |
|
1541 |
slower, for example if the assumptions have many universal |
|
1542 |
quantifiers. |
|
1543 |
||
42930 | 1544 |
|
1545 |
Any of the above methods support additional modifiers of the context |
|
1546 |
of classical (and simplifier) rules, but the ones related to the |
|
61493 | 1547 |
Simplifier are explicitly prefixed by \<open>simp\<close> here. The |
42930 | 1548 |
semantics of these ad-hoc rule declarations is analogous to the |
1549 |
attributes given before. Facts provided by forward chaining are |
|
1550 |
inserted into the goal before commencing proof search. |
|
58618 | 1551 |
\<close> |
42930 | 1552 |
|
1553 |
||
63650 | 1554 |
subsection \<open>Partially automated methods\label{sec:classical:partial}\<close> |
42930 | 1555 |
|
58618 | 1556 |
text \<open>These proof methods may help in situations when the |
42930 | 1557 |
fully-automated tools fail. The result is a simpler subgoal that |
1558 |
can be tackled by other means, such as by manual instantiation of |
|
1559 |
quantifiers. |
|
1560 |
||
1561 |
\begin{matharray}{rcl} |
|
61493 | 1562 |
@{method_def safe} & : & \<open>method\<close> \\ |
1563 |
@{method_def clarify} & : & \<open>method\<close> \\ |
|
1564 |
@{method_def clarsimp} & : & \<open>method\<close> \\ |
|
42930 | 1565 |
\end{matharray} |
1566 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1567 |
@{rail \<open> |
42930 | 1568 |
(@@{method safe} | @@{method clarify}) (@{syntax clamod} * ) |
1569 |
; |
|
1570 |
@@{method clarsimp} (@{syntax clasimpmod} * ) |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1571 |
\<close>} |
42930 | 1572 |
|
61439 | 1573 |
\<^descr> @{method safe} repeatedly performs safe steps on all subgoals. |
42930 | 1574 |
It is deterministic, with at most one outcome. |
1575 |
||
61439 | 1576 |
\<^descr> @{method clarify} performs a series of safe steps without |
50108 | 1577 |
splitting subgoals; see also @{method clarify_step}. |
42930 | 1578 |
|
61439 | 1579 |
\<^descr> @{method clarsimp} acts like @{method clarify}, but also does |
42930 | 1580 |
simplification. Note that if the Simplifier context includes a |
1581 |
splitter for the premises, the subgoal may still be split. |
|
58618 | 1582 |
\<close> |
26782 | 1583 |
|
1584 |
||
58618 | 1585 |
subsection \<open>Single-step tactics\<close> |
43366 | 1586 |
|
58618 | 1587 |
text \<open> |
50108 | 1588 |
\begin{matharray}{rcl} |
61493 | 1589 |
@{method_def safe_step} & : & \<open>method\<close> \\ |
1590 |
@{method_def inst_step} & : & \<open>method\<close> \\ |
|
1591 |
@{method_def step} & : & \<open>method\<close> \\ |
|
1592 |
@{method_def slow_step} & : & \<open>method\<close> \\ |
|
1593 |
@{method_def clarify_step} & : & \<open>method\<close> \\ |
|
50108 | 1594 |
\end{matharray} |
43366 | 1595 |
|
50070
e447ad4d6edd
avoid clash of terminology wrt. "semi-automated" in the sense of Isar (e.g. method "rule");
wenzelm
parents:
50068
diff
changeset
|
1596 |
These are the primitive tactics behind the automated proof methods |
e447ad4d6edd
avoid clash of terminology wrt. "semi-automated" in the sense of Isar (e.g. method "rule");
wenzelm
parents:
50068
diff
changeset
|
1597 |
of the Classical Reasoner. By calling them yourself, you can |
e447ad4d6edd
avoid clash of terminology wrt. "semi-automated" in the sense of Isar (e.g. method "rule");
wenzelm
parents:
50068
diff
changeset
|
1598 |
execute these procedures one step at a time. |
43366 | 1599 |
|
61439 | 1600 |
\<^descr> @{method safe_step} performs a safe step on the first subgoal. |
50108 | 1601 |
The safe wrapper tacticals are applied to a tactic that may include |
1602 |
proof by assumption or Modus Ponens (taking care not to instantiate |
|
1603 |
unknowns), or substitution. |
|
43366 | 1604 |
|
61439 | 1605 |
\<^descr> @{method inst_step} is like @{method safe_step}, but allows |
43366 | 1606 |
unknowns to be instantiated. |
1607 |
||
61439 | 1608 |
\<^descr> @{method step} is the basic step of the proof procedure, it |
50108 | 1609 |
operates on the first subgoal. The unsafe wrapper tacticals are |
1610 |
applied to a tactic that tries @{method safe}, @{method inst_step}, |
|
1611 |
or applies an unsafe rule from the context. |
|
43366 | 1612 |
|
61439 | 1613 |
\<^descr> @{method slow_step} resembles @{method step}, but allows |
50108 | 1614 |
backtracking between using safe rules with instantiation (@{method |
1615 |
inst_step}) and using unsafe rules. The resulting search space is |
|
1616 |
larger. |
|
43366 | 1617 |
|
61439 | 1618 |
\<^descr> @{method clarify_step} performs a safe step on the first |
50108 | 1619 |
subgoal; no splitting step is applied. For example, the subgoal |
61493 | 1620 |
\<open>A \<and> B\<close> is left as a conjunction. Proof by assumption, |
50108 | 1621 |
Modus Ponens, etc., may be performed provided they do not |
61493 | 1622 |
instantiate unknowns. Assumptions of the form \<open>x = t\<close> may |
50108 | 1623 |
be eliminated. The safe wrapper tactical is applied. |
58618 | 1624 |
\<close> |
43366 | 1625 |
|
1626 |
||
58618 | 1627 |
subsection \<open>Modifying the search step\<close> |
50071 | 1628 |
|
58618 | 1629 |
text \<open> |
50071 | 1630 |
\begin{mldecls} |
1631 |
@{index_ML_type wrapper: "(int -> tactic) -> (int -> tactic)"} \\[0.5ex] |
|
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1632 |
@{index_ML_op addSWrapper: "Proof.context * |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1633 |
(string * (Proof.context -> wrapper)) -> Proof.context"} \\ |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1634 |
@{index_ML_op addSbefore: "Proof.context * |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1635 |
(string * (Proof.context -> int -> tactic)) -> Proof.context"} \\ |
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1636 |
@{index_ML_op addSafter: "Proof.context * |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1637 |
(string * (Proof.context -> int -> tactic)) -> Proof.context"} \\ |
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1638 |
@{index_ML_op delSWrapper: "Proof.context * string -> Proof.context"} \\[0.5ex] |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1639 |
@{index_ML_op addWrapper: "Proof.context * |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1640 |
(string * (Proof.context -> wrapper)) -> Proof.context"} \\ |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1641 |
@{index_ML_op addbefore: "Proof.context * |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1642 |
(string * (Proof.context -> int -> tactic)) -> Proof.context"} \\ |
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1643 |
@{index_ML_op addafter: "Proof.context * |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
1644 |
(string * (Proof.context -> int -> tactic)) -> Proof.context"} \\ |
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
50108
diff
changeset
|
1645 |
@{index_ML_op delWrapper: "Proof.context * string -> Proof.context"} \\[0.5ex] |
50071 | 1646 |
@{index_ML addSss: "Proof.context -> Proof.context"} \\ |
1647 |
@{index_ML addss: "Proof.context -> Proof.context"} \\ |
|
1648 |
\end{mldecls} |
|
1649 |
||
1650 |
The proof strategy of the Classical Reasoner is simple. Perform as |
|
1651 |
many safe inferences as possible; or else, apply certain safe rules, |
|
1652 |
allowing instantiation of unknowns; or else, apply an unsafe rule. |
|
61493 | 1653 |
The tactics also eliminate assumptions of the form \<open>x = t\<close> |
50071 | 1654 |
by substitution if they have been set up to do so. They may perform |
61493 | 1655 |
a form of Modus Ponens: if there are assumptions \<open>P \<longrightarrow> Q\<close> and |
1656 |
\<open>P\<close>, then replace \<open>P \<longrightarrow> Q\<close> by \<open>Q\<close>. |
|
50071 | 1657 |
|
1658 |
The classical reasoning tools --- except @{method blast} --- allow |
|
1659 |
to modify this basic proof strategy by applying two lists of |
|
61477 | 1660 |
arbitrary \<^emph>\<open>wrapper tacticals\<close> to it. The first wrapper list, |
50108 | 1661 |
which is considered to contain safe wrappers only, affects @{method |
1662 |
safe_step} and all the tactics that call it. The second one, which |
|
1663 |
may contain unsafe wrappers, affects the unsafe parts of @{method |
|
1664 |
step}, @{method slow_step}, and the tactics that call them. A |
|
50071 | 1665 |
wrapper transforms each step of the search, for example by |
1666 |
attempting other tactics before or after the original step tactic. |
|
1667 |
All members of a wrapper list are applied in turn to the respective |
|
1668 |
step tactic. |
|
1669 |
||
1670 |
Initially the two wrapper lists are empty, which means no |
|
1671 |
modification of the step tactics. Safe and unsafe wrappers are added |
|
59905 | 1672 |
to the context with the functions given below, supplying them with |
50071 | 1673 |
wrapper names. These names may be used to selectively delete |
1674 |
wrappers. |
|
1675 |
||
61493 | 1676 |
\<^descr> \<open>ctxt addSWrapper (name, wrapper)\<close> adds a new wrapper, |
50071 | 1677 |
which should yield a safe tactic, to modify the existing safe step |
1678 |
tactic. |
|
1679 |
||
61493 | 1680 |
\<^descr> \<open>ctxt addSbefore (name, tac)\<close> adds the given tactic as a |
61477 | 1681 |
safe wrapper, such that it is tried \<^emph>\<open>before\<close> each safe step of |
50071 | 1682 |
the search. |
1683 |
||
61493 | 1684 |
\<^descr> \<open>ctxt addSafter (name, tac)\<close> adds the given tactic as a |
50071 | 1685 |
safe wrapper, such that it is tried when a safe step of the search |
1686 |
would fail. |
|
1687 |
||
61493 | 1688 |
\<^descr> \<open>ctxt delSWrapper name\<close> deletes the safe wrapper with |
50071 | 1689 |
the given name. |
1690 |
||
61493 | 1691 |
\<^descr> \<open>ctxt addWrapper (name, wrapper)\<close> adds a new wrapper to |
50071 | 1692 |
modify the existing (unsafe) step tactic. |
1693 |
||
61493 | 1694 |
\<^descr> \<open>ctxt addbefore (name, tac)\<close> adds the given tactic as an |
50071 | 1695 |
unsafe wrapper, such that it its result is concatenated |
61477 | 1696 |
\<^emph>\<open>before\<close> the result of each unsafe step. |
50071 | 1697 |
|
61493 | 1698 |
\<^descr> \<open>ctxt addafter (name, tac)\<close> adds the given tactic as an |
61477 | 1699 |
unsafe wrapper, such that it its result is concatenated \<^emph>\<open>after\<close> |
50071 | 1700 |
the result of each unsafe step. |
1701 |
||
61493 | 1702 |
\<^descr> \<open>ctxt delWrapper name\<close> deletes the unsafe wrapper with |
50071 | 1703 |
the given name. |
1704 |
||
61493 | 1705 |
\<^descr> \<open>addSss\<close> adds the simpset of the context to its |
50071 | 1706 |
classical set. The assumptions and goal will be simplified, in a |
1707 |
rather safe way, after each safe step of the search. |
|
1708 |
||
61493 | 1709 |
\<^descr> \<open>addss\<close> adds the simpset of the context to its |
50071 | 1710 |
classical set. The assumptions and goal will be simplified, before |
1711 |
the each unsafe step of the search. |
|
58618 | 1712 |
\<close> |
50071 | 1713 |
|
1714 |
||
58618 | 1715 |
section \<open>Object-logic setup \label{sec:object-logic}\<close> |
26790 | 1716 |
|
58618 | 1717 |
text \<open> |
26790 | 1718 |
\begin{matharray}{rcl} |
61493 | 1719 |
@{command_def "judgment"} & : & \<open>theory \<rightarrow> theory\<close> \\ |
1720 |
@{method_def atomize} & : & \<open>method\<close> \\ |
|
1721 |
@{attribute_def atomize} & : & \<open>attribute\<close> \\ |
|
1722 |
@{attribute_def rule_format} & : & \<open>attribute\<close> \\ |
|
1723 |
@{attribute_def rulify} & : & \<open>attribute\<close> \\ |
|
26790 | 1724 |
\end{matharray} |
1725 |
||
1726 |
The very starting point for any Isabelle object-logic is a ``truth |
|
1727 |
judgment'' that links object-level statements to the meta-logic |
|
61493 | 1728 |
(with its minimal language of \<open>prop\<close> that covers universal |
1729 |
quantification \<open>\<And>\<close> and implication \<open>\<Longrightarrow>\<close>). |
|
26790 | 1730 |
|
1731 |
Common object-logics are sufficiently expressive to internalize rule |
|
61493 | 1732 |
statements over \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close> within their own |
26790 | 1733 |
language. This is useful in certain situations where a rule needs |
1734 |
to be viewed as an atomic statement from the meta-level perspective, |
|
61493 | 1735 |
e.g.\ \<open>\<And>x. x \<in> A \<Longrightarrow> P x\<close> versus \<open>\<forall>x \<in> A. P x\<close>. |
26790 | 1736 |
|
1737 |
From the following language elements, only the @{method atomize} |
|
1738 |
method and @{attribute rule_format} attribute are occasionally |
|
1739 |
required by end-users, the rest is for those who need to setup their |
|
1740 |
own object-logic. In the latter case existing formulations of |
|
1741 |
Isabelle/FOL or Isabelle/HOL may be taken as realistic examples. |
|
1742 |
||
1743 |
Generic tools may refer to the information provided by object-logic |
|
1744 |
declarations internally. |
|
1745 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1746 |
@{rail \<open> |
46494
ea2ae63336f3
clarified outer syntax "constdecl", which is only local to some rail diagrams;
wenzelm
parents:
46277
diff
changeset
|
1747 |
@@{command judgment} @{syntax name} '::' @{syntax type} @{syntax mixfix}? |
26790 | 1748 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
1749 |
@@{attribute atomize} ('(' 'full' ')')? |
26790 | 1750 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
40291
diff
changeset
|
1751 |
@@{attribute rule_format} ('(' 'noasm' ')')? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1752 |
\<close>} |
26790 | 1753 |
|
61493 | 1754 |
\<^descr> @{command "judgment"}~\<open>c :: \<sigma> (mx)\<close> declares constant |
1755 |
\<open>c\<close> as the truth judgment of the current object-logic. Its |
|
1756 |
type \<open>\<sigma>\<close> should specify a coercion of the category of |
|
1757 |
object-level propositions to \<open>prop\<close> of the Pure meta-logic; |
|
1758 |
the mixfix annotation \<open>(mx)\<close> would typically just link the |
|
1759 |
object language (internally of syntactic category \<open>logic\<close>) |
|
1760 |
with that of \<open>prop\<close>. Only one @{command "judgment"} |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28754
diff
changeset
|
1761 |
declaration may be given in any theory development. |
26790 | 1762 |
|
61439 | 1763 |
\<^descr> @{method atomize} (as a method) rewrites any non-atomic |
26790 | 1764 |
premises of a sub-goal, using the meta-level equations declared via |
1765 |
@{attribute atomize} (as an attribute) beforehand. As a result, |
|
1766 |
heavily nested goals become amenable to fundamental operations such |
|
61493 | 1767 |
as resolution (cf.\ the @{method (Pure) rule} method). Giving the ``\<open>(full)\<close>'' option here means to turn the whole subgoal into an |
26790 | 1768 |
object-statement (if possible), including the outermost parameters |
1769 |
and assumptions as well. |
|
1770 |
||
1771 |
A typical collection of @{attribute atomize} rules for a particular |
|
1772 |
object-logic would provide an internalization for each of the |
|
61493 | 1773 |
connectives of \<open>\<And>\<close>, \<open>\<Longrightarrow>\<close>, and \<open>\<equiv>\<close>. |
26790 | 1774 |
Meta-level conjunction should be covered as well (this is |
1775 |
particularly important for locales, see \secref{sec:locale}). |
|
1776 |
||
61439 | 1777 |
\<^descr> @{attribute rule_format} rewrites a theorem by the equalities |
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28754
diff
changeset
|
1778 |
declared as @{attribute rulify} rules in the current object-logic. |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28754
diff
changeset
|
1779 |
By default, the result is fully normalized, including assumptions |
61493 | 1780 |
and conclusions at any depth. The \<open>(no_asm)\<close> option |
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28754
diff
changeset
|
1781 |
restricts the transformation to the conclusion of a rule. |
26790 | 1782 |
|
1783 |
In common object-logics (HOL, FOL, ZF), the effect of @{attribute |
|
1784 |
rule_format} is to replace (bounded) universal quantification |
|
61493 | 1785 |
(\<open>\<forall>\<close>) and implication (\<open>\<longrightarrow>\<close>) by the corresponding |
1786 |
rule statements over \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close>. |
|
58618 | 1787 |
\<close> |
26790 | 1788 |
|
50083 | 1789 |
|
58618 | 1790 |
section \<open>Tracing higher-order unification\<close> |
50083 | 1791 |
|
58618 | 1792 |
text \<open> |
50083 | 1793 |
\begin{tabular}{rcll} |
61493 | 1794 |
@{attribute_def unify_trace_simp} & : & \<open>attribute\<close> & default \<open>false\<close> \\ |
1795 |
@{attribute_def unify_trace_types} & : & \<open>attribute\<close> & default \<open>false\<close> \\ |
|
1796 |
@{attribute_def unify_trace_bound} & : & \<open>attribute\<close> & default \<open>50\<close> \\ |
|
1797 |
@{attribute_def unify_search_bound} & : & \<open>attribute\<close> & default \<open>60\<close> \\ |
|
50083 | 1798 |
\end{tabular} |
61421 | 1799 |
\<^medskip> |
50083 | 1800 |
|
1801 |
Higher-order unification works well in most practical situations, |
|
1802 |
but sometimes needs extra care to identify problems. These tracing |
|
1803 |
options may help. |
|
1804 |
||
61439 | 1805 |
\<^descr> @{attribute unify_trace_simp} controls tracing of the |
50083 | 1806 |
simplification phase of higher-order unification. |
1807 |
||
61439 | 1808 |
\<^descr> @{attribute unify_trace_types} controls warnings of |
50083 | 1809 |
incompleteness, when unification is not considering all possible |
1810 |
instantiations of schematic type variables. |
|
1811 |
||
61439 | 1812 |
\<^descr> @{attribute unify_trace_bound} determines the depth where |
50083 | 1813 |
unification starts to print tracing information once it reaches |
1814 |
depth; 0 for full tracing. At the default value, tracing |
|
1815 |
information is almost never printed in practice. |
|
1816 |
||
61439 | 1817 |
\<^descr> @{attribute unify_search_bound} prevents unification from |
50083 | 1818 |
searching past the given depth. Because of this bound, higher-order |
1819 |
unification cannot return an infinite sequence, though it can return |
|
1820 |
an exponentially long one. The search rarely approaches the default |
|
1821 |
value in practice. If the search is cut off, unification prints a |
|
1822 |
warning ``Unification bound exceeded''. |
|
1823 |
||
1824 |
||
1825 |
\begin{warn} |
|
1826 |
Options for unification cannot be modified in a local context. Only |
|
1827 |
the global theory content is taken into account. |
|
1828 |
\end{warn} |
|
58618 | 1829 |
\<close> |
50083 | 1830 |
|
26782 | 1831 |
end |