author | paulson |
Thu, 19 Aug 1999 15:11:12 +0200 | |
changeset 7283 | 5cfe2944910a |
parent 6956 | 18c0457efd3d |
child 7494 | 45905028bb1d |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/Ord.ML |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Tobias Nipkow, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
6 |
The type class for ordered types |
|
7 |
*) |
|
8 |
||
5449
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
9 |
(*Tell Blast_tac about overloading of < and <= to reduce the risk of |
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
10 |
its applying a rule for the wrong type*) |
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
11 |
Blast.overloaded ("op <", domain_type); |
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
12 |
Blast.overloaded ("op <=", domain_type); |
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
13 |
|
2608 | 14 |
(** mono **) |
923 | 15 |
|
5316 | 16 |
val [prem] = Goalw [mono_def] |
923 | 17 |
"[| !!A B. A <= B ==> f(A) <= f(B) |] ==> mono(f)"; |
18 |
by (REPEAT (ares_tac [allI, impI, prem] 1)); |
|
19 |
qed "monoI"; |
|
6956 | 20 |
AddXIs [monoI]; |
923 | 21 |
|
5316 | 22 |
Goalw [mono_def] "[| mono(f); A <= B |] ==> f(A) <= f(B)"; |
23 |
by (Fast_tac 1); |
|
923 | 24 |
qed "monoD"; |
6956 | 25 |
AddXDs [monoD]; |
923 | 26 |
|
2608 | 27 |
|
28 |
section "Orders"; |
|
29 |
||
5538 | 30 |
(** Reflexivity **) |
31 |
||
6115 | 32 |
AddIffs [order_refl]; |
2608 | 33 |
|
4600 | 34 |
(*This form is useful with the classical reasoner*) |
5069 | 35 |
Goal "!!x::'a::order. x = y ==> x <= y"; |
4600 | 36 |
by (etac ssubst 1); |
37 |
by (rtac order_refl 1); |
|
38 |
qed "order_eq_refl"; |
|
39 |
||
5069 | 40 |
Goal "~ x < (x::'a::order)"; |
4089 | 41 |
by (simp_tac (simpset() addsimps [order_less_le]) 1); |
2608 | 42 |
qed "order_less_irrefl"; |
5449
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
43 |
Addsimps [order_less_irrefl]; |
2608 | 44 |
|
5069 | 45 |
Goal "(x::'a::order) <= y = (x < y | x = y)"; |
4089 | 46 |
by (simp_tac (simpset() addsimps [order_less_le]) 1); |
5449
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
47 |
(*NOT suitable for AddIffs, since it can cause PROOF FAILED*) |
d853d1ac85a3
Adds order_refl, order_less_irrefl as simps, not as Iffs, to avoid PROOF FAILED
paulson
parents:
5316
diff
changeset
|
48 |
by (blast_tac (claset() addSIs [order_refl]) 1); |
2608 | 49 |
qed "order_le_less"; |
50 |
||
5538 | 51 |
(** Asymmetry **) |
52 |
||
53 |
Goal "(x::'a::order) < y ==> ~ (y<x)"; |
|
54 |
by (asm_full_simp_tac (simpset() addsimps [order_less_le, order_antisym]) 1); |
|
55 |
qed "order_less_not_sym"; |
|
56 |
||
57 |
(* [| n<m; ~P ==> m<n |] ==> P *) |
|
58 |
bind_thm ("order_less_asym", order_less_not_sym RS swap); |
|
59 |
||
6073 | 60 |
(* Transitivity *) |
61 |
||
62 |
Goal "!!x::'a::order. [| x < y; y < z |] ==> x < z"; |
|
63 |
by (asm_full_simp_tac (simpset() addsimps [order_less_le]) 1); |
|
64 |
by (blast_tac (claset() addIs [order_trans,order_antisym]) 1); |
|
65 |
qed "order_less_trans"; |
|
66 |
||
6780 | 67 |
Goal "!!x::'a::order. [| x <= y; y < z |] ==> x < z"; |
68 |
by (asm_full_simp_tac (simpset() addsimps [order_less_le]) 1); |
|
69 |
by (blast_tac (claset() addIs [order_trans,order_antisym]) 1); |
|
70 |
qed "order_le_less_trans"; |
|
71 |
||
72 |
Goal "!!x::'a::order. [| x < y; y <= z |] ==> x < z"; |
|
73 |
by (asm_full_simp_tac (simpset() addsimps [order_less_le]) 1); |
|
74 |
by (blast_tac (claset() addIs [order_trans,order_antisym]) 1); |
|
75 |
qed "order_less_le_trans"; |
|
76 |
||
5538 | 77 |
|
78 |
(** Useful for simplification, but too risky to include by default. **) |
|
79 |
||
80 |
Goal "(x::'a::order) < y ==> (~ y < x) = True"; |
|
81 |
by (blast_tac (claset() addEs [order_less_asym]) 1); |
|
82 |
qed "order_less_imp_not_less"; |
|
83 |
||
84 |
Goal "(x::'a::order) < y ==> (y < x --> P) = True"; |
|
85 |
by (blast_tac (claset() addEs [order_less_asym]) 1); |
|
86 |
qed "order_less_imp_triv"; |
|
87 |
||
88 |
Goal "(x::'a::order) < y ==> (x = y) = False"; |
|
89 |
by Auto_tac; |
|
90 |
qed "order_less_imp_not_eq"; |
|
91 |
||
92 |
Goal "(x::'a::order) < y ==> (y = x) = False"; |
|
93 |
by Auto_tac; |
|
94 |
qed "order_less_imp_not_eq2"; |
|
95 |
||
96 |
||
2608 | 97 |
(** min **) |
98 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
99 |
val prems = Goalw [min_def] "(!!x. least <= x) ==> min least x = least"; |
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
100 |
by (simp_tac (simpset() addsimps prems) 1); |
2608 | 101 |
qed "min_leastL"; |
102 |
||
5316 | 103 |
val prems = Goalw [min_def] |
2608 | 104 |
"(!!x::'a::order. least <= x) ==> min x least = least"; |
2935 | 105 |
by (cut_facts_tac prems 1); |
106 |
by (Asm_simp_tac 1); |
|
4089 | 107 |
by (blast_tac (claset() addIs [order_antisym]) 1); |
2608 | 108 |
qed "min_leastR"; |
4640 | 109 |
|
110 |
||
111 |
section "Linear/Total Orders"; |
|
112 |
||
5069 | 113 |
Goal "!!x::'a::linorder. x<y | x=y | y<x"; |
4640 | 114 |
by (simp_tac (simpset() addsimps [order_less_le]) 1); |
5132 | 115 |
by (cut_facts_tac [linorder_linear] 1); |
4640 | 116 |
by (Blast_tac 1); |
117 |
qed "linorder_less_linear"; |
|
118 |
||
6128 | 119 |
Goal "!!x::'a::linorder. (~ x < y) = (y <= x)"; |
120 |
by (simp_tac (simpset() addsimps [order_less_le]) 1); |
|
121 |
by (cut_facts_tac [linorder_linear] 1); |
|
122 |
by (blast_tac (claset() addIs [order_antisym]) 1); |
|
123 |
qed "linorder_not_less"; |
|
124 |
||
125 |
Goal "!!x::'a::linorder. (~ x <= y) = (y < x)"; |
|
126 |
by (simp_tac (simpset() addsimps [order_less_le]) 1); |
|
127 |
by (cut_facts_tac [linorder_linear] 1); |
|
128 |
by (blast_tac (claset() addIs [order_antisym]) 1); |
|
129 |
qed "linorder_not_le"; |
|
130 |
||
131 |
Goal "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"; |
|
132 |
by (cut_inst_tac [("x","x"),("y","y")] linorder_less_linear 1); |
|
133 |
by Auto_tac; |
|
134 |
qed "linorder_neq_iff"; |
|
135 |
||
136 |
(* eliminates ~= in premises *) |
|
137 |
bind_thm("linorder_neqE", linorder_neq_iff RS iffD1 RS disjE); |
|
138 |
||
139 |
(** min & max **) |
|
140 |
||
6433 | 141 |
Goalw [min_def] "min (x::'a::order) x = x"; |
6814 | 142 |
by (Simp_tac 1); |
6433 | 143 |
qed "min_same"; |
144 |
Addsimps [min_same]; |
|
145 |
||
146 |
Goalw [max_def] "max (x::'a::order) x = x"; |
|
6814 | 147 |
by (Simp_tac 1); |
6433 | 148 |
qed "max_same"; |
149 |
Addsimps [max_same]; |
|
150 |
||
5069 | 151 |
Goalw [max_def] "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"; |
4686 | 152 |
by (Simp_tac 1); |
5132 | 153 |
by (cut_facts_tac [linorder_linear] 1); |
4640 | 154 |
by (blast_tac (claset() addIs [order_trans]) 1); |
155 |
qed "le_max_iff_disj"; |
|
156 |
||
6073 | 157 |
Goalw [max_def] "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"; |
158 |
by (simp_tac (simpset() addsimps [order_le_less]) 1); |
|
159 |
by (cut_facts_tac [linorder_less_linear] 1); |
|
160 |
by (blast_tac (claset() addIs [order_less_trans]) 1); |
|
161 |
qed "less_max_iff_disj"; |
|
162 |
||
5069 | 163 |
Goalw [max_def] "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"; |
4686 | 164 |
by (Simp_tac 1); |
5132 | 165 |
by (cut_facts_tac [linorder_linear] 1); |
4640 | 166 |
by (blast_tac (claset() addIs [order_trans]) 1); |
167 |
qed "max_le_iff_conj"; |
|
5673 | 168 |
Addsimps [max_le_iff_conj]; |
4640 | 169 |
|
6433 | 170 |
Goalw [max_def] "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"; |
171 |
by (simp_tac (simpset() addsimps [order_le_less]) 1); |
|
172 |
by (cut_facts_tac [linorder_less_linear] 1); |
|
173 |
by (blast_tac (claset() addIs [order_less_trans]) 1); |
|
174 |
qed "max_less_iff_conj"; |
|
175 |
Addsimps [max_less_iff_conj]; |
|
176 |
||
5069 | 177 |
Goalw [min_def] "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"; |
4686 | 178 |
by (Simp_tac 1); |
5132 | 179 |
by (cut_facts_tac [linorder_linear] 1); |
4640 | 180 |
by (blast_tac (claset() addIs [order_trans]) 1); |
181 |
qed "le_min_iff_conj"; |
|
5673 | 182 |
Addsimps [le_min_iff_conj]; |
183 |
(* AddIffs screws up a blast_tac in MiniML *) |
|
4640 | 184 |
|
6433 | 185 |
Goalw [min_def] "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"; |
186 |
by (simp_tac (simpset() addsimps [order_le_less]) 1); |
|
187 |
by (cut_facts_tac [linorder_less_linear] 1); |
|
188 |
by (blast_tac (claset() addIs [order_less_trans]) 1); |
|
189 |
qed "min_less_iff_conj"; |
|
190 |
Addsimps [min_less_iff_conj]; |
|
191 |
||
5069 | 192 |
Goalw [min_def] "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"; |
4686 | 193 |
by (Simp_tac 1); |
5132 | 194 |
by (cut_facts_tac [linorder_linear] 1); |
4640 | 195 |
by (blast_tac (claset() addIs [order_trans]) 1); |
196 |
qed "min_le_iff_disj"; |
|
6157 | 197 |
|
198 |
Goalw [min_def] |
|
199 |
"P(min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"; |
|
6301 | 200 |
by (Simp_tac 1); |
6157 | 201 |
qed "split_min"; |
202 |
||
203 |
Goalw [max_def] |
|
204 |
"P(max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"; |
|
6301 | 205 |
by (Simp_tac 1); |
6157 | 206 |
qed "split_max"; |