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