author | paulson |
Tue, 08 May 2001 16:01:28 +0200 | |
changeset 11289 | 65782388cf40 |
parent 11144 | f53ea84bab23 |
child 11367 | 7b2dbfb5cc3d |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/Ord.thy |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
2624 | 6 |
Type classes for order signatures and orders. |
923 | 7 |
*) |
8 |
||
11140 | 9 |
theory Ord = HOL: |
923 | 10 |
|
5889 | 11 |
|
923 | 12 |
axclass |
11140 | 13 |
ord < "term" |
923 | 14 |
|
3820 | 15 |
syntax |
11140 | 16 |
"op <" :: "['a::ord, 'a] => bool" ("op <") |
17 |
"op <=" :: "['a::ord, 'a] => bool" ("op <=") |
|
3820 | 18 |
|
8882 | 19 |
global |
20 |
||
923 | 21 |
consts |
11140 | 22 |
"op <" :: "['a::ord, 'a] => bool" ("(_/ < _)" [50, 51] 50) |
23 |
"op <=" :: "['a::ord, 'a] => bool" ("(_/ <= _)" [50, 51] 50) |
|
923 | 24 |
|
8882 | 25 |
local |
2608 | 26 |
|
3820 | 27 |
syntax (symbols) |
11144 | 28 |
"op <=" :: "['a::ord, 'a] => bool" ("op \<le>") |
29 |
"op <=" :: "['a::ord, 'a] => bool" ("(_/ \<le> _)" [50, 51] 50) |
|
11140 | 30 |
|
31 |
(*Tell Blast_tac about overloading of < and <= to reduce the risk of |
|
32 |
its applying a rule for the wrong type*) |
|
33 |
ML {* |
|
34 |
Blast.overloaded ("op <" , domain_type); |
|
35 |
Blast.overloaded ("op <=", domain_type); |
|
36 |
*} |
|
37 |
||
38 |
||
39 |
constdefs |
|
40 |
mono :: "['a::ord => 'b::ord] => bool" (*monotonicity*) |
|
41 |
"mono(f) == (!A B. A <= B --> f(A) <= f(B))" |
|
42 |
||
43 |
lemma monoI [intro?]: "[| !!A B. A <= B ==> f(A) <= f(B) |] ==> mono(f)" |
|
44 |
apply (unfold mono_def) |
|
45 |
apply fast |
|
46 |
done |
|
47 |
||
48 |
lemma monoD [dest?]: "[| mono(f); A <= B |] ==> f(A) <= f(B)" |
|
49 |
apply (unfold mono_def) |
|
50 |
apply fast |
|
51 |
done |
|
52 |
||
53 |
||
54 |
constdefs |
|
55 |
min :: "['a::ord, 'a] => 'a" |
|
56 |
"min a b == (if a <= b then a else b)" |
|
57 |
max :: "['a::ord, 'a] => 'a" |
|
58 |
"max a b == (if a <= b then b else a)" |
|
2259 | 59 |
|
11140 | 60 |
lemma min_leastL: "(!!x. least <= x) ==> min least x = least" |
61 |
apply (simp add: min_def) |
|
62 |
done |
|
63 |
||
64 |
lemma min_of_mono: |
|
65 |
"!x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)" |
|
66 |
apply (simp add: min_def) |
|
67 |
done |
|
68 |
||
69 |
lemma max_leastL: "(!!x. least <= x) ==> max least x = x" |
|
70 |
apply (simp add: max_def) |
|
71 |
done |
|
72 |
||
73 |
lemma max_of_mono: |
|
74 |
"!x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)" |
|
75 |
apply (simp add: max_def) |
|
76 |
done |
|
3947 | 77 |
|
11140 | 78 |
constdefs |
79 |
LeastM :: "['a => 'b::ord, 'a => bool] => 'a" |
|
80 |
"LeastM m P == @x. P x & (!y. P y --> m x <= m y)" |
|
81 |
Least :: "('a::ord => bool) => 'a" (binder "LEAST " 10) |
|
82 |
"Least == LeastM (%x. x)" |
|
83 |
||
84 |
syntax |
|
85 |
"@LeastM" :: "[pttrn, 'a=>'b::ord, bool] => 'a" ("LEAST _ WRT _. _" [0,4,10]10) |
|
86 |
translations |
|
87 |
"LEAST x WRT m. P" == "LeastM m (%x. P)" |
|
88 |
||
89 |
lemma LeastMI2: "[| P x; !!y. P y ==> m x <= m y; |
|
11144 | 90 |
!!x. [| P x; \<forall>y. P y --> m x \<le> m y |] ==> Q x |
11140 | 91 |
|] ==> Q (LeastM m P)"; |
92 |
apply (unfold LeastM_def) |
|
93 |
apply (rule someI2_ex) |
|
94 |
apply blast |
|
95 |
apply blast |
|
96 |
done |
|
2608 | 97 |
|
98 |
||
11140 | 99 |
section "Orders" |
100 |
||
2608 | 101 |
axclass order < ord |
11140 | 102 |
order_refl [iff]: "x <= x" |
103 |
order_trans: "[| x <= y; y <= z |] ==> x <= z" |
|
104 |
order_antisym: "[| x <= y; y <= x |] ==> x = y" |
|
105 |
order_less_le: "x < y = (x <= y & x ~= y)" |
|
106 |
||
107 |
(** Reflexivity **) |
|
108 |
||
109 |
(*This form is useful with the classical reasoner*) |
|
110 |
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y" |
|
111 |
apply (erule ssubst) |
|
112 |
apply (rule order_refl) |
|
113 |
done |
|
114 |
||
115 |
lemma order_less_irrefl [simp]: "~ x < (x::'a::order)" |
|
116 |
apply (simp (no_asm) add: order_less_le) |
|
117 |
done |
|
118 |
||
119 |
lemma order_le_less: "(x::'a::order) <= y = (x < y | x = y)" |
|
120 |
apply (simp (no_asm) add: order_less_le) |
|
121 |
(*NOT suitable for AddIffs, since it can cause PROOF FAILED*) |
|
122 |
apply (blast intro!: order_refl) |
|
123 |
done |
|
124 |
||
125 |
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard] |
|
126 |
||
127 |
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y" |
|
128 |
apply (simp add: order_less_le) |
|
129 |
done |
|
130 |
||
131 |
(** Asymmetry **) |
|
132 |
||
133 |
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y<x)" |
|
134 |
apply (simp add: order_less_le order_antisym) |
|
135 |
done |
|
136 |
||
137 |
(* [| n<m; ~P ==> m<n |] ==> P *) |
|
138 |
lemmas order_less_asym = order_less_not_sym [THEN contrapos_np, standard] |
|
139 |
||
140 |
(* Transitivity *) |
|
141 |
||
142 |
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z" |
|
143 |
apply (simp add: order_less_le) |
|
144 |
apply (blast intro: order_trans order_antisym) |
|
145 |
done |
|
146 |
||
147 |
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z" |
|
148 |
apply (simp add: order_less_le) |
|
149 |
apply (blast intro: order_trans order_antisym) |
|
150 |
done |
|
151 |
||
152 |
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z" |
|
153 |
apply (simp add: order_less_le) |
|
154 |
apply (blast intro: order_trans order_antisym) |
|
155 |
done |
|
156 |
||
157 |
||
158 |
(** Useful for simplification, but too risky to include by default. **) |
|
159 |
||
160 |
lemma order_less_imp_not_less: "(x::'a::order) < y ==> (~ y < x) = True" |
|
161 |
apply (blast elim: order_less_asym) |
|
162 |
done |
|
163 |
||
164 |
lemma order_less_imp_triv: "(x::'a::order) < y ==> (y < x --> P) = True" |
|
165 |
apply (blast elim: order_less_asym) |
|
166 |
done |
|
167 |
||
168 |
lemma order_less_imp_not_eq: "(x::'a::order) < y ==> (x = y) = False" |
|
169 |
apply auto |
|
170 |
done |
|
171 |
||
172 |
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==> (y = x) = False" |
|
173 |
apply auto |
|
174 |
done |
|
175 |
||
176 |
(* Other operators *) |
|
177 |
||
178 |
lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least" |
|
179 |
apply (simp (no_asm_simp) add: min_def) |
|
180 |
apply (blast intro: order_antisym) |
|
181 |
done |
|
182 |
||
183 |
lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x" |
|
184 |
apply (simp add: max_def) |
|
185 |
apply (blast intro: order_antisym) |
|
186 |
done |
|
187 |
||
188 |
lemma LeastM_equality: |
|
189 |
"[| P k; !!x. P x ==> m k <= m x |] ==> m (LEAST x WRT m. P x) = |
|
190 |
(m k::'a::order)"; |
|
191 |
apply (rule LeastMI2) |
|
192 |
apply assumption |
|
193 |
apply blast |
|
194 |
apply (blast intro!: order_antisym) |
|
195 |
done |
|
196 |
||
197 |
lemma Least_equality: |
|
198 |
"[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"; |
|
199 |
apply (unfold Least_def) |
|
200 |
apply (erule LeastM_equality) |
|
201 |
apply blast |
|
202 |
done |
|
203 |
||
204 |
||
205 |
section "Linear/Total Orders" |
|
923 | 206 |
|
4640 | 207 |
axclass linorder < order |
11140 | 208 |
linorder_linear: "x <= y | y <= x" |
209 |
||
210 |
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x" |
|
211 |
apply (simp (no_asm) add: order_less_le) |
|
212 |
apply (cut_tac linorder_linear) |
|
213 |
apply blast |
|
214 |
done |
|
215 |
||
216 |
lemma linorder_less_split: |
|
217 |
"[| (x::'a::linorder)<y ==> P; x=y ==> P; y<x ==> P |] ==> P" |
|
218 |
apply (cut_tac linorder_less_linear) |
|
219 |
apply blast |
|
220 |
done |
|
221 |
||
222 |
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)" |
|
223 |
apply (simp (no_asm) add: order_less_le) |
|
224 |
apply (cut_tac linorder_linear) |
|
225 |
apply (blast intro: order_antisym) |
|
226 |
done |
|
227 |
||
228 |
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)" |
|
229 |
apply (simp (no_asm) add: order_less_le) |
|
230 |
apply (cut_tac linorder_linear) |
|
231 |
apply (blast intro: order_antisym) |
|
232 |
done |
|
233 |
||
234 |
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)" |
|
235 |
apply (cut_tac x = "x" and y = "y" in linorder_less_linear) |
|
236 |
apply auto |
|
237 |
done |
|
238 |
||
239 |
(* eliminates ~= in premises *) |
|
240 |
lemmas linorder_neqE = linorder_neq_iff [THEN iffD1, THEN disjE, standard] |
|
241 |
||
242 |
section "min & max on (linear) orders" |
|
243 |
||
244 |
lemma min_same [simp]: "min (x::'a::order) x = x" |
|
245 |
apply (simp add: min_def) |
|
246 |
done |
|
247 |
||
248 |
lemma max_same [simp]: "max (x::'a::order) x = x" |
|
249 |
apply (simp add: max_def) |
|
250 |
done |
|
251 |
||
252 |
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)" |
|
253 |
apply (unfold max_def) |
|
254 |
apply (simp (no_asm)) |
|
255 |
apply (cut_tac linorder_linear) |
|
256 |
apply (blast intro: order_trans) |
|
257 |
done |
|
258 |
||
259 |
lemma le_maxI1: "(x::'a::linorder) <= max x y" |
|
260 |
apply (simp (no_asm) add: le_max_iff_disj) |
|
261 |
done |
|
262 |
||
263 |
lemma le_maxI2: "(y::'a::linorder) <= max x y" |
|
264 |
apply (simp (no_asm) add: le_max_iff_disj) |
|
265 |
done |
|
266 |
(*CANNOT use with AddSIs because blast_tac will give PROOF FAILED.*) |
|
267 |
||
268 |
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)" |
|
269 |
apply (simp (no_asm) add: max_def order_le_less) |
|
270 |
apply (cut_tac linorder_less_linear) |
|
271 |
apply (blast intro: order_less_trans) |
|
272 |
done |
|
273 |
||
274 |
lemma max_le_iff_conj [simp]: |
|
275 |
"!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)" |
|
276 |
apply (simp (no_asm) add: max_def) |
|
277 |
apply (cut_tac linorder_linear) |
|
278 |
apply (blast intro: order_trans) |
|
279 |
done |
|
280 |
||
281 |
lemma max_less_iff_conj [simp]: |
|
282 |
"!!z::'a::linorder. (max x y < z) = (x < z & y < z)" |
|
283 |
apply (simp (no_asm) add: order_le_less max_def) |
|
284 |
apply (cut_tac linorder_less_linear) |
|
285 |
apply (blast intro: order_less_trans) |
|
286 |
done |
|
287 |
||
288 |
lemma le_min_iff_conj [simp]: |
|
289 |
"!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)" |
|
290 |
apply (simp (no_asm) add: min_def) |
|
291 |
apply (cut_tac linorder_linear) |
|
292 |
apply (blast intro: order_trans) |
|
293 |
done |
|
294 |
(* AddIffs screws up a blast_tac in MiniML *) |
|
295 |
||
296 |
lemma min_less_iff_conj [simp]: |
|
297 |
"!!z::'a::linorder. (z < min x y) = (z < x & z < y)" |
|
298 |
apply (simp (no_asm) add: order_le_less min_def) |
|
299 |
apply (cut_tac linorder_less_linear) |
|
300 |
apply (blast intro: order_less_trans) |
|
301 |
done |
|
302 |
||
303 |
lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)" |
|
304 |
apply (unfold min_def) |
|
305 |
apply (simp (no_asm)) |
|
306 |
apply (cut_tac linorder_linear) |
|
307 |
apply (blast intro: order_trans) |
|
308 |
done |
|
309 |
||
310 |
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)" |
|
311 |
apply (unfold min_def) |
|
312 |
apply (simp (no_asm) add: order_le_less) |
|
313 |
apply (cut_tac linorder_less_linear) |
|
314 |
apply (blast intro: order_less_trans) |
|
315 |
done |
|
316 |
||
317 |
lemma split_min: |
|
318 |
"P(min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))" |
|
319 |
apply (simp (no_asm) add: min_def) |
|
320 |
done |
|
321 |
||
322 |
lemma split_max: |
|
323 |
"P(max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))" |
|
324 |
apply (simp (no_asm) add: max_def) |
|
325 |
done |
|
4640 | 326 |
|
7238
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
327 |
|
11140 | 328 |
section "bounded quantifiers" |
7238
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
329 |
|
6402 | 330 |
syntax |
11140 | 331 |
"_lessAll" :: "[idt, 'a, bool] => bool" ("(3ALL _<_./ _)" [0, 0, 10] 10) |
332 |
"_lessEx" :: "[idt, 'a, bool] => bool" ("(3EX _<_./ _)" [0, 0, 10] 10) |
|
333 |
"_leAll" :: "[idt, 'a, bool] => bool" ("(3ALL _<=_./ _)" [0, 0, 10] 10) |
|
334 |
"_leEx" :: "[idt, 'a, bool] => bool" ("(3EX _<=_./ _)" [0, 0, 10] 10) |
|
7238
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
335 |
|
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
336 |
syntax (symbols) |
11144 | 337 |
"_lessAll" :: "[idt, 'a, bool] => bool" ("(3\<forall>_<_./ _)" [0, 0, 10] 10) |
338 |
"_lessEx" :: "[idt, 'a, bool] => bool" ("(3\<exists>_<_./ _)" [0, 0, 10] 10) |
|
339 |
"_leAll" :: "[idt, 'a, bool] => bool" ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10) |
|
340 |
"_leEx" :: "[idt, 'a, bool] => bool" ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10) |
|
7238
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
341 |
|
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
342 |
syntax (HOL) |
11140 | 343 |
"_lessAll" :: "[idt, 'a, bool] => bool" ("(3! _<_./ _)" [0, 0, 10] 10) |
344 |
"_lessEx" :: "[idt, 'a, bool] => bool" ("(3? _<_./ _)" [0, 0, 10] 10) |
|
345 |
"_leAll" :: "[idt, 'a, bool] => bool" ("(3! _<=_./ _)" [0, 0, 10] 10) |
|
346 |
"_leEx" :: "[idt, 'a, bool] => bool" ("(3? _<=_./ _)" [0, 0, 10] 10) |
|
7238
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
347 |
|
6402 | 348 |
translations |
7238
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
349 |
"ALL x<y. P" => "ALL x. x < y --> P" |
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
350 |
"EX x<y. P" => "EX x. x < y & P" |
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
351 |
"ALL x<=y. P" => "ALL x. x <= y --> P" |
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
352 |
"EX x<=y. P" => "EX x. x <= y & P" |
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
wenzelm
parents:
6855
diff
changeset
|
353 |
|
6402 | 354 |
|
11140 | 355 |
ML |
356 |
{* |
|
357 |
val mono_def = thm "mono_def"; |
|
358 |
val monoI = thm "monoI"; |
|
359 |
val monoD = thm "monoD"; |
|
360 |
val min_def = thm "min_def"; |
|
361 |
val min_of_mono = thm "min_of_mono"; |
|
362 |
val max_def = thm "max_def"; |
|
363 |
val max_of_mono = thm "max_of_mono"; |
|
364 |
val min_leastL = thm "min_leastL"; |
|
365 |
val max_leastL = thm "max_leastL"; |
|
366 |
val LeastMI2 = thm "LeastMI2"; |
|
367 |
val LeastM_equality = thm "LeastM_equality"; |
|
368 |
val Least_def = thm "Least_def"; |
|
369 |
val Least_equality = thm "Least_equality"; |
|
370 |
val min_leastR = thm "min_leastR"; |
|
371 |
val max_leastR = thm "max_leastR"; |
|
372 |
val order_eq_refl = thm "order_eq_refl"; |
|
373 |
val order_less_irrefl = thm "order_less_irrefl"; |
|
374 |
val order_le_less = thm "order_le_less"; |
|
375 |
val order_le_imp_less_or_eq = thm "order_le_imp_less_or_eq"; |
|
376 |
val order_less_imp_le = thm "order_less_imp_le"; |
|
377 |
val order_less_not_sym = thm "order_less_not_sym"; |
|
378 |
val order_less_asym = thm "order_less_asym"; |
|
379 |
val order_less_trans = thm "order_less_trans"; |
|
380 |
val order_le_less_trans = thm "order_le_less_trans"; |
|
381 |
val order_less_le_trans = thm "order_less_le_trans"; |
|
382 |
val order_less_imp_not_less = thm "order_less_imp_not_less"; |
|
383 |
val order_less_imp_triv = thm "order_less_imp_triv"; |
|
384 |
val order_less_imp_not_eq = thm "order_less_imp_not_eq"; |
|
385 |
val order_less_imp_not_eq2 = thm "order_less_imp_not_eq2"; |
|
386 |
val linorder_less_linear = thm "linorder_less_linear"; |
|
387 |
val linorder_less_split = thm "linorder_less_split"; |
|
388 |
val linorder_not_less = thm "linorder_not_less"; |
|
389 |
val linorder_not_le = thm "linorder_not_le"; |
|
390 |
val linorder_neq_iff = thm "linorder_neq_iff"; |
|
391 |
val linorder_neqE = thm "linorder_neqE"; |
|
392 |
val min_same = thm "min_same"; |
|
393 |
val max_same = thm "max_same"; |
|
394 |
val le_max_iff_disj = thm "le_max_iff_disj"; |
|
395 |
val le_maxI1 = thm "le_maxI1"; |
|
396 |
val le_maxI2 = thm "le_maxI2"; |
|
397 |
val less_max_iff_disj = thm "less_max_iff_disj"; |
|
398 |
val max_le_iff_conj = thm "max_le_iff_conj"; |
|
399 |
val max_less_iff_conj = thm "max_less_iff_conj"; |
|
400 |
val le_min_iff_conj = thm "le_min_iff_conj"; |
|
401 |
val min_less_iff_conj = thm "min_less_iff_conj"; |
|
402 |
val min_le_iff_disj = thm "min_le_iff_disj"; |
|
403 |
val min_less_iff_disj = thm "min_less_iff_disj"; |
|
404 |
val split_min = thm "split_min"; |
|
405 |
val split_max = thm "split_max"; |
|
406 |
val order_refl = thm "order_refl"; |
|
407 |
val order_trans = thm "order_trans"; |
|
408 |
val order_antisym = thm "order_antisym"; |
|
409 |
val order_less_le = thm "order_less_le"; |
|
410 |
val linorder_linear = thm "linorder_linear"; |
|
411 |
*} |
|
412 |
||
923 | 413 |
end |