| author | haftmann | 
| Fri, 10 Oct 2008 06:45:53 +0200 | |
| changeset 28562 | 4e74209f113e | 
| parent 28516 | e6fdcaaadbd3 | 
| child 28685 | 275122631271 | 
| permissions | -rw-r--r-- | 
| 28516 | 1  | 
(* Title: HOL/Orderings.thy  | 
| 15524 | 2  | 
ID: $Id$  | 
3  | 
Author: Tobias Nipkow, Markus Wenzel, and Larry Paulson  | 
|
4  | 
*)  | 
|
5  | 
||
| 25614 | 6  | 
header {* Abstract orderings *}
 | 
| 15524 | 7  | 
|
8  | 
theory Orderings  | 
|
| 
26796
 
c554b77061e5
- Now imports Code_Setup, rather than Set and Fun, since the theorems
 
berghofe 
parents: 
26496 
diff
changeset
 | 
9  | 
imports Code_Setup  | 
| 28516 | 10  | 
uses "~~/src/Provers/order.ML"  | 
| 15524 | 11  | 
begin  | 
12  | 
||
| 27682 | 13  | 
subsection {* Quasi orders *}
 | 
| 15524 | 14  | 
|
| 27682 | 15  | 
class preorder = ord +  | 
16  | 
assumes less_le_not_le: "x < y \<longleftrightarrow> x \<le> y \<and> \<not> (y \<le> x)"  | 
|
| 25062 | 17  | 
and order_refl [iff]: "x \<le> x"  | 
18  | 
and order_trans: "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"  | 
|
| 21248 | 19  | 
begin  | 
20  | 
||
| 15524 | 21  | 
text {* Reflexivity. *}
 | 
22  | 
||
| 25062 | 23  | 
lemma eq_refl: "x = y \<Longrightarrow> x \<le> y"  | 
| 15524 | 24  | 
    -- {* This form is useful with the classical reasoner. *}
 | 
| 23212 | 25  | 
by (erule ssubst) (rule order_refl)  | 
| 15524 | 26  | 
|
| 25062 | 27  | 
lemma less_irrefl [iff]: "\<not> x < x"  | 
| 27682 | 28  | 
by (simp add: less_le_not_le)  | 
29  | 
||
30  | 
lemma less_imp_le: "x < y \<Longrightarrow> x \<le> y"  | 
|
31  | 
unfolding less_le_not_le by blast  | 
|
32  | 
||
33  | 
||
34  | 
text {* Asymmetry. *}
 | 
|
35  | 
||
36  | 
lemma less_not_sym: "x < y \<Longrightarrow> \<not> (y < x)"  | 
|
37  | 
by (simp add: less_le_not_le)  | 
|
38  | 
||
39  | 
lemma less_asym: "x < y \<Longrightarrow> (\<not> P \<Longrightarrow> y < x) \<Longrightarrow> P"  | 
|
40  | 
by (drule less_not_sym, erule contrapos_np) simp  | 
|
41  | 
||
42  | 
||
43  | 
text {* Transitivity. *}
 | 
|
44  | 
||
45  | 
lemma less_trans: "x < y \<Longrightarrow> y < z \<Longrightarrow> x < z"  | 
|
46  | 
by (auto simp add: less_le_not_le intro: order_trans)  | 
|
47  | 
||
48  | 
lemma le_less_trans: "x \<le> y \<Longrightarrow> y < z \<Longrightarrow> x < z"  | 
|
49  | 
by (auto simp add: less_le_not_le intro: order_trans)  | 
|
50  | 
||
51  | 
lemma less_le_trans: "x < y \<Longrightarrow> y \<le> z \<Longrightarrow> x < z"  | 
|
52  | 
by (auto simp add: less_le_not_le intro: order_trans)  | 
|
53  | 
||
54  | 
||
55  | 
text {* Useful for simplification, but too risky to include by default. *}
 | 
|
56  | 
||
57  | 
lemma less_imp_not_less: "x < y \<Longrightarrow> (\<not> y < x) \<longleftrightarrow> True"  | 
|
58  | 
by (blast elim: less_asym)  | 
|
59  | 
||
60  | 
lemma less_imp_triv: "x < y \<Longrightarrow> (y < x \<longrightarrow> P) \<longleftrightarrow> True"  | 
|
61  | 
by (blast elim: less_asym)  | 
|
62  | 
||
63  | 
||
64  | 
text {* Transitivity rules for calculational reasoning *}
 | 
|
65  | 
||
66  | 
lemma less_asym': "a < b \<Longrightarrow> b < a \<Longrightarrow> P"  | 
|
67  | 
by (rule less_asym)  | 
|
68  | 
||
69  | 
||
70  | 
text {* Dual order *}
 | 
|
71  | 
||
72  | 
lemma dual_preorder:  | 
|
73  | 
"preorder (op \<ge>) (op >)"  | 
|
74  | 
by unfold_locales (auto simp add: less_le_not_le intro: order_trans)  | 
|
75  | 
||
76  | 
end  | 
|
77  | 
||
78  | 
||
79  | 
subsection {* Partial orders *}
 | 
|
80  | 
||
81  | 
class order = preorder +  | 
|
82  | 
assumes antisym: "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"  | 
|
83  | 
begin  | 
|
84  | 
||
85  | 
text {* Reflexivity. *}
 | 
|
86  | 
||
87  | 
lemma less_le: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> y"  | 
|
88  | 
by (auto simp add: less_le_not_le intro: antisym)  | 
|
| 15524 | 89  | 
|
| 25062 | 90  | 
lemma le_less: "x \<le> y \<longleftrightarrow> x < y \<or> x = y"  | 
| 15524 | 91  | 
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
 | 
| 23212 | 92  | 
by (simp add: less_le) blast  | 
| 15524 | 93  | 
|
| 25062 | 94  | 
lemma le_imp_less_or_eq: "x \<le> y \<Longrightarrow> x < y \<or> x = y"  | 
| 23212 | 95  | 
unfolding less_le by blast  | 
| 15524 | 96  | 
|
| 21329 | 97  | 
|
98  | 
text {* Useful for simplification, but too risky to include by default. *}
 | 
|
99  | 
||
| 25062 | 100  | 
lemma less_imp_not_eq: "x < y \<Longrightarrow> (x = y) \<longleftrightarrow> False"  | 
| 23212 | 101  | 
by auto  | 
| 21329 | 102  | 
|
| 25062 | 103  | 
lemma less_imp_not_eq2: "x < y \<Longrightarrow> (y = x) \<longleftrightarrow> False"  | 
| 23212 | 104  | 
by auto  | 
| 21329 | 105  | 
|
106  | 
||
107  | 
text {* Transitivity rules for calculational reasoning *}
 | 
|
108  | 
||
| 25062 | 109  | 
lemma neq_le_trans: "a \<noteq> b \<Longrightarrow> a \<le> b \<Longrightarrow> a < b"  | 
| 23212 | 110  | 
by (simp add: less_le)  | 
| 21329 | 111  | 
|
| 25062 | 112  | 
lemma le_neq_trans: "a \<le> b \<Longrightarrow> a \<noteq> b \<Longrightarrow> a < b"  | 
| 23212 | 113  | 
by (simp add: less_le)  | 
| 21329 | 114  | 
|
| 15524 | 115  | 
|
116  | 
text {* Asymmetry. *}
 | 
|
117  | 
||
| 25062 | 118  | 
lemma eq_iff: "x = y \<longleftrightarrow> x \<le> y \<and> y \<le> x"  | 
| 23212 | 119  | 
by (blast intro: antisym)  | 
| 15524 | 120  | 
|
| 25062 | 121  | 
lemma antisym_conv: "y \<le> x \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"  | 
| 23212 | 122  | 
by (blast intro: antisym)  | 
| 15524 | 123  | 
|
| 25062 | 124  | 
lemma less_imp_neq: "x < y \<Longrightarrow> x \<noteq> y"  | 
| 23212 | 125  | 
by (erule contrapos_pn, erule subst, rule less_irrefl)  | 
| 21248 | 126  | 
|
| 21083 | 127  | 
|
| 27107 | 128  | 
text {* Least value operator *}
 | 
129  | 
||
| 27299 | 130  | 
definition (in ord)  | 
| 27107 | 131  | 
  Least :: "('a \<Rightarrow> bool) \<Rightarrow> 'a" (binder "LEAST " 10) where
 | 
132  | 
"Least P = (THE x. P x \<and> (\<forall>y. P y \<longrightarrow> x \<le> y))"  | 
|
133  | 
||
134  | 
lemma Least_equality:  | 
|
135  | 
assumes "P x"  | 
|
136  | 
and "\<And>y. P y \<Longrightarrow> x \<le> y"  | 
|
137  | 
shows "Least P = x"  | 
|
138  | 
unfolding Least_def by (rule the_equality)  | 
|
139  | 
(blast intro: assms antisym)+  | 
|
140  | 
||
141  | 
lemma LeastI2_order:  | 
|
142  | 
assumes "P x"  | 
|
143  | 
and "\<And>y. P y \<Longrightarrow> x \<le> y"  | 
|
144  | 
and "\<And>x. P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> x \<le> y \<Longrightarrow> Q x"  | 
|
145  | 
shows "Q (Least P)"  | 
|
146  | 
unfolding Least_def by (rule theI2)  | 
|
147  | 
(blast intro: assms antisym)+  | 
|
148  | 
||
149  | 
||
| 26014 | 150  | 
text {* Dual order *}
 | 
| 22916 | 151  | 
|
| 26014 | 152  | 
lemma dual_order:  | 
| 25103 | 153  | 
"order (op \<ge>) (op >)"  | 
| 27682 | 154  | 
by (intro_locales, rule dual_preorder) (unfold_locales, rule antisym)  | 
| 22916 | 155  | 
|
| 21248 | 156  | 
end  | 
| 15524 | 157  | 
|
| 21329 | 158  | 
|
159  | 
subsection {* Linear (total) orders *}
 | 
|
160  | 
||
| 22316 | 161  | 
class linorder = order +  | 
| 25207 | 162  | 
assumes linear: "x \<le> y \<or> y \<le> x"  | 
| 21248 | 163  | 
begin  | 
164  | 
||
| 25062 | 165  | 
lemma less_linear: "x < y \<or> x = y \<or> y < x"  | 
| 23212 | 166  | 
unfolding less_le using less_le linear by blast  | 
| 21248 | 167  | 
|
| 25062 | 168  | 
lemma le_less_linear: "x \<le> y \<or> y < x"  | 
| 23212 | 169  | 
by (simp add: le_less less_linear)  | 
| 21248 | 170  | 
|
171  | 
lemma le_cases [case_names le ge]:  | 
|
| 25062 | 172  | 
"(x \<le> y \<Longrightarrow> P) \<Longrightarrow> (y \<le> x \<Longrightarrow> P) \<Longrightarrow> P"  | 
| 23212 | 173  | 
using linear by blast  | 
| 21248 | 174  | 
|
| 
22384
 
33a46e6c7f04
prefix of class interpretation not mandatory any longer
 
haftmann 
parents: 
22377 
diff
changeset
 | 
175  | 
lemma linorder_cases [case_names less equal greater]:  | 
| 25062 | 176  | 
"(x < y \<Longrightarrow> P) \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> (y < x \<Longrightarrow> P) \<Longrightarrow> P"  | 
| 23212 | 177  | 
using less_linear by blast  | 
| 21248 | 178  | 
|
| 25062 | 179  | 
lemma not_less: "\<not> x < y \<longleftrightarrow> y \<le> x"  | 
| 23212 | 180  | 
apply (simp add: less_le)  | 
181  | 
using linear apply (blast intro: antisym)  | 
|
182  | 
done  | 
|
183  | 
||
184  | 
lemma not_less_iff_gr_or_eq:  | 
|
| 25062 | 185  | 
"\<not>(x < y) \<longleftrightarrow> (x > y | x = y)"  | 
| 23212 | 186  | 
apply(simp add:not_less le_less)  | 
187  | 
apply blast  | 
|
188  | 
done  | 
|
| 15524 | 189  | 
|
| 25062 | 190  | 
lemma not_le: "\<not> x \<le> y \<longleftrightarrow> y < x"  | 
| 23212 | 191  | 
apply (simp add: less_le)  | 
192  | 
using linear apply (blast intro: antisym)  | 
|
193  | 
done  | 
|
| 15524 | 194  | 
|
| 25062 | 195  | 
lemma neq_iff: "x \<noteq> y \<longleftrightarrow> x < y \<or> y < x"  | 
| 23212 | 196  | 
by (cut_tac x = x and y = y in less_linear, auto)  | 
| 15524 | 197  | 
|
| 25062 | 198  | 
lemma neqE: "x \<noteq> y \<Longrightarrow> (x < y \<Longrightarrow> R) \<Longrightarrow> (y < x \<Longrightarrow> R) \<Longrightarrow> R"  | 
| 23212 | 199  | 
by (simp add: neq_iff) blast  | 
| 15524 | 200  | 
|
| 25062 | 201  | 
lemma antisym_conv1: "\<not> x < y \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"  | 
| 23212 | 202  | 
by (blast intro: antisym dest: not_less [THEN iffD1])  | 
| 15524 | 203  | 
|
| 25062 | 204  | 
lemma antisym_conv2: "x \<le> y \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"  | 
| 23212 | 205  | 
by (blast intro: antisym dest: not_less [THEN iffD1])  | 
| 15524 | 206  | 
|
| 25062 | 207  | 
lemma antisym_conv3: "\<not> y < x \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"  | 
| 23212 | 208  | 
by (blast intro: antisym dest: not_less [THEN iffD1])  | 
| 15524 | 209  | 
|
| 25062 | 210  | 
lemma leI: "\<not> x < y \<Longrightarrow> y \<le> x"  | 
| 23212 | 211  | 
unfolding not_less .  | 
| 16796 | 212  | 
|
| 25062 | 213  | 
lemma leD: "y \<le> x \<Longrightarrow> \<not> x < y"  | 
| 23212 | 214  | 
unfolding not_less .  | 
| 16796 | 215  | 
|
216  | 
(*FIXME inappropriate name (or delete altogether)*)  | 
|
| 25062 | 217  | 
lemma not_leE: "\<not> y \<le> x \<Longrightarrow> x < y"  | 
| 23212 | 218  | 
unfolding not_le .  | 
| 21248 | 219  | 
|
| 22916 | 220  | 
|
| 26014 | 221  | 
text {* Dual order *}
 | 
| 22916 | 222  | 
|
| 26014 | 223  | 
lemma dual_linorder:  | 
| 25103 | 224  | 
"linorder (op \<ge>) (op >)"  | 
| 27682 | 225  | 
by (rule linorder.intro, rule dual_order) (unfold_locales, rule linear)  | 
| 22916 | 226  | 
|
227  | 
||
| 23881 | 228  | 
text {* min/max *}
 | 
229  | 
||
| 27299 | 230  | 
definition (in ord) min :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where  | 
| 28516 | 231  | 
[code del]: "min a b = (if a \<le> b then a else b)"  | 
| 23881 | 232  | 
|
| 27299 | 233  | 
definition (in ord) max :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where  | 
| 28516 | 234  | 
[code del]: "max a b = (if a \<le> b then b else a)"  | 
| 
22384
 
33a46e6c7f04
prefix of class interpretation not mandatory any longer
 
haftmann 
parents: 
22377 
diff
changeset
 | 
235  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
236  | 
lemma min_le_iff_disj:  | 
| 25062 | 237  | 
"min x y \<le> z \<longleftrightarrow> x \<le> z \<or> y \<le> z"  | 
| 23212 | 238  | 
unfolding min_def using linear by (auto intro: order_trans)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
239  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
240  | 
lemma le_max_iff_disj:  | 
| 25062 | 241  | 
"z \<le> max x y \<longleftrightarrow> z \<le> x \<or> z \<le> y"  | 
| 23212 | 242  | 
unfolding max_def using linear by (auto intro: order_trans)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
243  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
244  | 
lemma min_less_iff_disj:  | 
| 25062 | 245  | 
"min x y < z \<longleftrightarrow> x < z \<or> y < z"  | 
| 23212 | 246  | 
unfolding min_def le_less using less_linear by (auto intro: less_trans)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
247  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
248  | 
lemma less_max_iff_disj:  | 
| 25062 | 249  | 
"z < max x y \<longleftrightarrow> z < x \<or> z < y"  | 
| 23212 | 250  | 
unfolding max_def le_less using less_linear by (auto intro: less_trans)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
251  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
252  | 
lemma min_less_iff_conj [simp]:  | 
| 25062 | 253  | 
"z < min x y \<longleftrightarrow> z < x \<and> z < y"  | 
| 23212 | 254  | 
unfolding min_def le_less using less_linear by (auto intro: less_trans)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
255  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
256  | 
lemma max_less_iff_conj [simp]:  | 
| 25062 | 257  | 
"max x y < z \<longleftrightarrow> x < z \<and> y < z"  | 
| 23212 | 258  | 
unfolding max_def le_less using less_linear by (auto intro: less_trans)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
259  | 
|
| 
24286
 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 
paulson 
parents: 
23948 
diff
changeset
 | 
260  | 
lemma split_min [noatp]:  | 
| 25062 | 261  | 
"P (min i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P i) \<and> (\<not> i \<le> j \<longrightarrow> P j)"  | 
| 23212 | 262  | 
by (simp add: min_def)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
263  | 
|
| 
24286
 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 
paulson 
parents: 
23948 
diff
changeset
 | 
264  | 
lemma split_max [noatp]:  | 
| 25062 | 265  | 
"P (max i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P j) \<and> (\<not> i \<le> j \<longrightarrow> P i)"  | 
| 23212 | 266  | 
by (simp add: max_def)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
267  | 
|
| 21248 | 268  | 
end  | 
269  | 
||
| 28516 | 270  | 
text {* Explicit dictionaries for code generation *}
 | 
271  | 
||
272  | 
lemma min_ord_min [code, code unfold, code inline del]:  | 
|
273  | 
"min = ord.min (op \<le>)"  | 
|
274  | 
by (rule ext)+ (simp add: min_def ord.min_def)  | 
|
275  | 
||
276  | 
declare ord.min_def [code]  | 
|
277  | 
||
278  | 
lemma max_ord_max [code, code unfold, code inline del]:  | 
|
279  | 
"max = ord.max (op \<le>)"  | 
|
280  | 
by (rule ext)+ (simp add: max_def ord.max_def)  | 
|
281  | 
||
282  | 
declare ord.max_def [code]  | 
|
283  | 
||
| 23948 | 284  | 
|
| 21083 | 285  | 
subsection {* Reasoning tools setup *}
 | 
286  | 
||
| 21091 | 287  | 
ML {*
 | 
288  | 
||
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
289  | 
signature ORDERS =  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
290  | 
sig  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
291  | 
val print_structures: Proof.context -> unit  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
292  | 
val setup: theory -> theory  | 
| 
24704
 
9a95634ab135
Transitivity reasoner gets additional argument of premises to improve integration with simplifier.
 
ballarin 
parents: 
24641 
diff
changeset
 | 
293  | 
val order_tac: thm list -> Proof.context -> int -> tactic  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
294  | 
end;  | 
| 21091 | 295  | 
|
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
296  | 
structure Orders: ORDERS =  | 
| 21248 | 297  | 
struct  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
298  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
299  | 
(** Theory and context data **)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
300  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
301  | 
fun struct_eq ((s1: string, ts1), (s2, ts2)) =  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
302  | 
(s1 = s2) andalso eq_list (op aconv) (ts1, ts2);  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
303  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
304  | 
structure Data = GenericDataFun  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
305  | 
(  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
306  | 
type T = ((string * term list) * Order_Tac.less_arith) list;  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
307  | 
(* Order structures:  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
308  | 
identifier of the structure, list of operations and record of theorems  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
309  | 
needed to set up the transitivity reasoner,  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
310  | 
identifier and operations identify the structure uniquely. *)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
311  | 
val empty = [];  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
312  | 
val extend = I;  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
313  | 
fun merge _ = AList.join struct_eq (K fst);  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
314  | 
);  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
315  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
316  | 
fun print_structures ctxt =  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
317  | 
let  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
318  | 
val structs = Data.get (Context.Proof ctxt);  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
319  | 
fun pretty_term t = Pretty.block  | 
| 24920 | 320  | 
[Pretty.quote (Syntax.pretty_term ctxt t), Pretty.brk 1,  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
321  | 
Pretty.str "::", Pretty.brk 1,  | 
| 24920 | 322  | 
Pretty.quote (Syntax.pretty_typ ctxt (type_of t))];  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
323  | 
fun pretty_struct ((s, ts), _) = Pretty.block  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
324  | 
[Pretty.str s, Pretty.str ":", Pretty.brk 1,  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
325  | 
       Pretty.enclose "(" ")" (Pretty.breaks (map pretty_term ts))];
 | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
326  | 
in  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
327  | 
Pretty.writeln (Pretty.big_list "Order structures:" (map pretty_struct structs))  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
328  | 
end;  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
329  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
330  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
331  | 
(** Method **)  | 
| 21091 | 332  | 
|
| 
24704
 
9a95634ab135
Transitivity reasoner gets additional argument of premises to improve integration with simplifier.
 
ballarin 
parents: 
24641 
diff
changeset
 | 
333  | 
fun struct_tac ((s, [eq, le, less]), thms) prems =  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
334  | 
let  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
335  | 
fun decomp thy (Trueprop $ t) =  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
336  | 
let  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
337  | 
fun excluded t =  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
338  | 
(* exclude numeric types: linear arithmetic subsumes transitivity *)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
339  | 
let val T = type_of t  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
340  | 
in  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
341  | 
T = HOLogic.natT orelse T = HOLogic.intT orelse T = HOLogic.realT  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
342  | 
end;  | 
| 
24741
 
a53f5db5acbb
Fixed setup of transitivity reasoner (function decomp).
 
ballarin 
parents: 
24704 
diff
changeset
 | 
343  | 
fun rel (bin_op $ t1 $ t2) =  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
344  | 
if excluded t1 then NONE  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
345  | 
else if Pattern.matches thy (eq, bin_op) then SOME (t1, "=", t2)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
346  | 
else if Pattern.matches thy (le, bin_op) then SOME (t1, "<=", t2)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
347  | 
else if Pattern.matches thy (less, bin_op) then SOME (t1, "<", t2)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
348  | 
else NONE  | 
| 
24741
 
a53f5db5acbb
Fixed setup of transitivity reasoner (function decomp).
 
ballarin 
parents: 
24704 
diff
changeset
 | 
349  | 
| rel _ = NONE;  | 
| 
 
a53f5db5acbb
Fixed setup of transitivity reasoner (function decomp).
 
ballarin 
parents: 
24704 
diff
changeset
 | 
350  | 
	fun dec (Const (@{const_name Not}, _) $ t) = (case rel t
 | 
| 
 
a53f5db5acbb
Fixed setup of transitivity reasoner (function decomp).
 
ballarin 
parents: 
24704 
diff
changeset
 | 
351  | 
of NONE => NONE  | 
| 
 
a53f5db5acbb
Fixed setup of transitivity reasoner (function decomp).
 
ballarin 
parents: 
24704 
diff
changeset
 | 
352  | 
| SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2))  | 
| 
 
a53f5db5acbb
Fixed setup of transitivity reasoner (function decomp).
 
ballarin 
parents: 
24704 
diff
changeset
 | 
353  | 
| dec x = rel x;  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
354  | 
in dec t end;  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
355  | 
in  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
356  | 
case s of  | 
| 
24704
 
9a95634ab135
Transitivity reasoner gets additional argument of premises to improve integration with simplifier.
 
ballarin 
parents: 
24641 
diff
changeset
 | 
357  | 
"order" => Order_Tac.partial_tac decomp thms prems  | 
| 
 
9a95634ab135
Transitivity reasoner gets additional argument of premises to improve integration with simplifier.
 
ballarin 
parents: 
24641 
diff
changeset
 | 
358  | 
| "linorder" => Order_Tac.linear_tac decomp thms prems  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
359  | 
    | _ => error ("Unknown kind of order `" ^ s ^ "' encountered in transitivity reasoner.")
 | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
360  | 
end  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
361  | 
|
| 
24704
 
9a95634ab135
Transitivity reasoner gets additional argument of premises to improve integration with simplifier.
 
ballarin 
parents: 
24641 
diff
changeset
 | 
362  | 
fun order_tac prems ctxt =  | 
| 
 
9a95634ab135
Transitivity reasoner gets additional argument of premises to improve integration with simplifier.
 
ballarin 
parents: 
24641 
diff
changeset
 | 
363  | 
FIRST' (map (fn s => CHANGED o struct_tac s prems) (Data.get (Context.Proof ctxt)));  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
364  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
365  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
366  | 
(** Attribute **)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
367  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
368  | 
fun add_struct_thm s tag =  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
369  | 
Thm.declaration_attribute  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
370  | 
(fn thm => Data.map (AList.map_default struct_eq (s, Order_Tac.empty TrueI) (Order_Tac.update tag thm)));  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
371  | 
fun del_struct s =  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
372  | 
Thm.declaration_attribute  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
373  | 
(fn _ => Data.map (AList.delete struct_eq s));  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
374  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
375  | 
val attribute = Attrib.syntax  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
376  | 
(Scan.lift ((Args.add -- Args.name >> (fn (_, s) => SOME s) ||  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
377  | 
Args.del >> K NONE) --| Args.colon (* FIXME ||  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
378  | 
Scan.succeed true *) ) -- Scan.lift Args.name --  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
379  | 
Scan.repeat Args.term  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
380  | 
>> (fn ((SOME tag, n), ts) => add_struct_thm (n, ts) tag  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
381  | 
| ((NONE, n), ts) => del_struct (n, ts)));  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
382  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
383  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
384  | 
(** Diagnostic command **)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
385  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
386  | 
val print = Toplevel.unknown_context o  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
387  | 
Toplevel.keep (Toplevel.node_case  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
388  | 
(Context.cases (print_structures o ProofContext.init) print_structures)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
389  | 
(print_structures o Proof.context_of));  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
390  | 
|
| 24867 | 391  | 
val _ =  | 
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
392  | 
OuterSyntax.improper_command "print_orders"  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
393  | 
"print order structures available to transitivity reasoner" OuterKeyword.diag  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
394  | 
(Scan.succeed (Toplevel.no_timing o print));  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
395  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
396  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
397  | 
(** Setup **)  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
398  | 
|
| 24867 | 399  | 
val setup =  | 
400  | 
Method.add_methods  | 
|
401  | 
    [("order", Method.ctxt_args (Method.SIMPLE_METHOD' o order_tac []), "transitivity reasoner")] #>
 | 
|
402  | 
  Attrib.add_attributes [("order", attribute, "theorems controlling transitivity reasoner")];
 | 
|
| 21091 | 403  | 
|
404  | 
end;  | 
|
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
405  | 
|
| 21091 | 406  | 
*}  | 
407  | 
||
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
408  | 
setup Orders.setup  | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
409  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
410  | 
|
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
411  | 
text {* Declarations to set up transitivity reasoner of partial and linear orders. *}
 | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
412  | 
|
| 25076 | 413  | 
context order  | 
414  | 
begin  | 
|
415  | 
||
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
416  | 
(* The type constraint on @{term op =} below is necessary since the operation
 | 
| 
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
417  | 
is not a parameter of the locale. *)  | 
| 25076 | 418  | 
|
| 27689 | 419  | 
declare less_irrefl [THEN notE, order add less_reflE: order "op = :: 'a \<Rightarrow> 'a \<Rightarrow> bool" "op <=" "op <"]  | 
420  | 
||
421  | 
declare order_refl [order add le_refl: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
422  | 
||
423  | 
declare less_imp_le [order add less_imp_le: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
424  | 
||
425  | 
declare antisym [order add eqI: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
426  | 
||
427  | 
declare eq_refl [order add eqD1: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
428  | 
||
429  | 
declare sym [THEN eq_refl, order add eqD2: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
430  | 
||
431  | 
declare less_trans [order add less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
432  | 
||
433  | 
declare less_le_trans [order add less_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
434  | 
||
435  | 
declare le_less_trans [order add le_less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
436  | 
||
437  | 
declare order_trans [order add le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
438  | 
||
439  | 
declare le_neq_trans [order add le_neq_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
440  | 
||
441  | 
declare neq_le_trans [order add neq_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
442  | 
||
443  | 
declare less_imp_neq [order add less_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
444  | 
||
445  | 
declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
446  | 
||
447  | 
declare not_sym [order add not_sym: order "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
448  | 
|
| 25076 | 449  | 
end  | 
450  | 
||
451  | 
context linorder  | 
|
452  | 
begin  | 
|
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
453  | 
|
| 27689 | 454  | 
declare [[order del: order "op = :: 'a => 'a => bool" "op <=" "op <"]]  | 
455  | 
||
456  | 
declare less_irrefl [THEN notE, order add less_reflE: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
457  | 
||
458  | 
declare order_refl [order add le_refl: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
459  | 
||
460  | 
declare less_imp_le [order add less_imp_le: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
461  | 
||
462  | 
declare not_less [THEN iffD2, order add not_lessI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
463  | 
||
464  | 
declare not_le [THEN iffD2, order add not_leI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
465  | 
||
466  | 
declare not_less [THEN iffD1, order add not_lessD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
467  | 
||
468  | 
declare not_le [THEN iffD1, order add not_leD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
469  | 
||
470  | 
declare antisym [order add eqI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
471  | 
||
472  | 
declare eq_refl [order add eqD1: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
| 25076 | 473  | 
|
| 27689 | 474  | 
declare sym [THEN eq_refl, order add eqD2: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
475  | 
||
476  | 
declare less_trans [order add less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
477  | 
||
478  | 
declare less_le_trans [order add less_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
479  | 
||
480  | 
declare le_less_trans [order add le_less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
481  | 
||
482  | 
declare order_trans [order add le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
483  | 
||
484  | 
declare le_neq_trans [order add le_neq_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
485  | 
||
486  | 
declare neq_le_trans [order add neq_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
487  | 
||
488  | 
declare less_imp_neq [order add less_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
489  | 
||
490  | 
declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
491  | 
||
492  | 
declare not_sym [order add not_sym: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]  | 
|
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
493  | 
|
| 25076 | 494  | 
end  | 
495  | 
||
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
496  | 
|
| 21083 | 497  | 
setup {*
 | 
498  | 
let  | 
|
499  | 
||
500  | 
fun prp t thm = (#prop (rep_thm thm) = t);  | 
|
| 15524 | 501  | 
|
| 21083 | 502  | 
fun prove_antisym_le sg ss ((le as Const(_,T)) $ r $ s) =  | 
503  | 
let val prems = prems_of_ss ss;  | 
|
| 22916 | 504  | 
      val less = Const (@{const_name less}, T);
 | 
| 21083 | 505  | 
val t = HOLogic.mk_Trueprop(le $ s $ r);  | 
506  | 
in case find_first (prp t) prems of  | 
|
507  | 
NONE =>  | 
|
508  | 
let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s))  | 
|
509  | 
in case find_first (prp t) prems of  | 
|
510  | 
NONE => NONE  | 
|
| 24422 | 511  | 
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv1}))
 | 
| 21083 | 512  | 
end  | 
| 24422 | 513  | 
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm order_class.antisym_conv}))
 | 
| 21083 | 514  | 
end  | 
515  | 
handle THM _ => NONE;  | 
|
| 15524 | 516  | 
|
| 21083 | 517  | 
fun prove_antisym_less sg ss (NotC $ ((less as Const(_,T)) $ r $ s)) =  | 
518  | 
let val prems = prems_of_ss ss;  | 
|
| 22916 | 519  | 
      val le = Const (@{const_name less_eq}, T);
 | 
| 21083 | 520  | 
val t = HOLogic.mk_Trueprop(le $ r $ s);  | 
521  | 
in case find_first (prp t) prems of  | 
|
522  | 
NONE =>  | 
|
523  | 
let val t = HOLogic.mk_Trueprop(NotC $ (less $ s $ r))  | 
|
524  | 
in case find_first (prp t) prems of  | 
|
525  | 
NONE => NONE  | 
|
| 24422 | 526  | 
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv3}))
 | 
| 21083 | 527  | 
end  | 
| 24422 | 528  | 
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv2}))
 | 
| 21083 | 529  | 
end  | 
530  | 
handle THM _ => NONE;  | 
|
| 15524 | 531  | 
|
| 21248 | 532  | 
fun add_simprocs procs thy =  | 
| 
26496
 
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
 
wenzelm 
parents: 
26324 
diff
changeset
 | 
533  | 
Simplifier.map_simpset (fn ss => ss  | 
| 21248 | 534  | 
addsimprocs (map (fn (name, raw_ts, proc) =>  | 
| 
26496
 
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
 
wenzelm 
parents: 
26324 
diff
changeset
 | 
535  | 
Simplifier.simproc thy name raw_ts proc) procs)) thy;  | 
| 
 
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
 
wenzelm 
parents: 
26324 
diff
changeset
 | 
536  | 
fun add_solver name tac =  | 
| 
 
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
 
wenzelm 
parents: 
26324 
diff
changeset
 | 
537  | 
Simplifier.map_simpset (fn ss => ss addSolver  | 
| 
 
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
 
wenzelm 
parents: 
26324 
diff
changeset
 | 
538  | 
mk_solver' name (fn ss => tac (Simplifier.prems_of_ss ss) (Simplifier.the_context ss)));  | 
| 21083 | 539  | 
|
540  | 
in  | 
|
| 21248 | 541  | 
add_simprocs [  | 
542  | 
       ("antisym le", ["(x::'a::order) <= y"], prove_antisym_le),
 | 
|
543  | 
       ("antisym less", ["~ (x::'a::linorder) < y"], prove_antisym_less)
 | 
|
544  | 
]  | 
|
| 
24641
 
448edc627ee4
Transitivity reasoner set up for locales order and linorder.
 
ballarin 
parents: 
24422 
diff
changeset
 | 
545  | 
#> add_solver "Transitivity" Orders.order_tac  | 
| 21248 | 546  | 
(* Adding the transitivity reasoners also as safe solvers showed a slight  | 
547  | 
speed up, but the reasoning strength appears to be not higher (at least  | 
|
548  | 
no breaking of additional proofs in the entire HOL distribution, as  | 
|
549  | 
of 5 March 2004, was observed). *)  | 
|
| 21083 | 550  | 
end  | 
551  | 
*}  | 
|
| 15524 | 552  | 
|
553  | 
||
| 24422 | 554  | 
subsection {* Name duplicates *}
 | 
555  | 
||
556  | 
lemmas order_less_le = less_le  | 
|
| 27682 | 557  | 
lemmas order_eq_refl = preorder_class.eq_refl  | 
558  | 
lemmas order_less_irrefl = preorder_class.less_irrefl  | 
|
| 24422 | 559  | 
lemmas order_le_less = order_class.le_less  | 
560  | 
lemmas order_le_imp_less_or_eq = order_class.le_imp_less_or_eq  | 
|
| 27682 | 561  | 
lemmas order_less_imp_le = preorder_class.less_imp_le  | 
| 24422 | 562  | 
lemmas order_less_imp_not_eq = order_class.less_imp_not_eq  | 
563  | 
lemmas order_less_imp_not_eq2 = order_class.less_imp_not_eq2  | 
|
564  | 
lemmas order_neq_le_trans = order_class.neq_le_trans  | 
|
565  | 
lemmas order_le_neq_trans = order_class.le_neq_trans  | 
|
566  | 
||
567  | 
lemmas order_antisym = antisym  | 
|
| 27682 | 568  | 
lemmas order_less_not_sym = preorder_class.less_not_sym  | 
569  | 
lemmas order_less_asym = preorder_class.less_asym  | 
|
| 24422 | 570  | 
lemmas order_eq_iff = order_class.eq_iff  | 
571  | 
lemmas order_antisym_conv = order_class.antisym_conv  | 
|
| 27682 | 572  | 
lemmas order_less_trans = preorder_class.less_trans  | 
573  | 
lemmas order_le_less_trans = preorder_class.le_less_trans  | 
|
574  | 
lemmas order_less_le_trans = preorder_class.less_le_trans  | 
|
575  | 
lemmas order_less_imp_not_less = preorder_class.less_imp_not_less  | 
|
576  | 
lemmas order_less_imp_triv = preorder_class.less_imp_triv  | 
|
577  | 
lemmas order_less_asym' = preorder_class.less_asym'  | 
|
| 24422 | 578  | 
|
579  | 
lemmas linorder_linear = linear  | 
|
580  | 
lemmas linorder_less_linear = linorder_class.less_linear  | 
|
581  | 
lemmas linorder_le_less_linear = linorder_class.le_less_linear  | 
|
582  | 
lemmas linorder_le_cases = linorder_class.le_cases  | 
|
583  | 
lemmas linorder_not_less = linorder_class.not_less  | 
|
584  | 
lemmas linorder_not_le = linorder_class.not_le  | 
|
585  | 
lemmas linorder_neq_iff = linorder_class.neq_iff  | 
|
586  | 
lemmas linorder_neqE = linorder_class.neqE  | 
|
587  | 
lemmas linorder_antisym_conv1 = linorder_class.antisym_conv1  | 
|
588  | 
lemmas linorder_antisym_conv2 = linorder_class.antisym_conv2  | 
|
589  | 
lemmas linorder_antisym_conv3 = linorder_class.antisym_conv3  | 
|
590  | 
||
591  | 
||
| 21083 | 592  | 
subsection {* Bounded quantifiers *}
 | 
593  | 
||
594  | 
syntax  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
595  | 
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3ALL _<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
596  | 
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3EX _<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
597  | 
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _<=_./ _)" [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
598  | 
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _<=_./ _)" [0, 0, 10] 10)
 | 
| 21083 | 599  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
600  | 
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3ALL _>_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
601  | 
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3EX _>_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
602  | 
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _>=_./ _)" [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
603  | 
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _>=_./ _)" [0, 0, 10] 10)
 | 
| 21083 | 604  | 
|
605  | 
syntax (xsymbols)  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
606  | 
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
607  | 
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
608  | 
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
609  | 
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
 | 
| 21083 | 610  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
611  | 
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
612  | 
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
613  | 
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
614  | 
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
 | 
| 21083 | 615  | 
|
616  | 
syntax (HOL)  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
617  | 
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3! _<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
618  | 
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3? _<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
619  | 
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3! _<=_./ _)" [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
620  | 
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3? _<=_./ _)" [0, 0, 10] 10)
 | 
| 21083 | 621  | 
|
622  | 
syntax (HTML output)  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
623  | 
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
624  | 
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
625  | 
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
626  | 
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
 | 
| 21083 | 627  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
628  | 
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
629  | 
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
630  | 
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
631  | 
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
 | 
| 21083 | 632  | 
|
633  | 
translations  | 
|
634  | 
"ALL x<y. P" => "ALL x. x < y \<longrightarrow> P"  | 
|
635  | 
"EX x<y. P" => "EX x. x < y \<and> P"  | 
|
636  | 
"ALL x<=y. P" => "ALL x. x <= y \<longrightarrow> P"  | 
|
637  | 
"EX x<=y. P" => "EX x. x <= y \<and> P"  | 
|
638  | 
"ALL x>y. P" => "ALL x. x > y \<longrightarrow> P"  | 
|
639  | 
"EX x>y. P" => "EX x. x > y \<and> P"  | 
|
640  | 
"ALL x>=y. P" => "ALL x. x >= y \<longrightarrow> P"  | 
|
641  | 
"EX x>=y. P" => "EX x. x >= y \<and> P"  | 
|
642  | 
||
643  | 
print_translation {*
 | 
|
644  | 
let  | 
|
| 22916 | 645  | 
  val All_binder = Syntax.binder_name @{const_syntax All};
 | 
646  | 
  val Ex_binder = Syntax.binder_name @{const_syntax Ex};
 | 
|
| 22377 | 647  | 
  val impl = @{const_syntax "op -->"};
 | 
648  | 
  val conj = @{const_syntax "op &"};
 | 
|
| 22916 | 649  | 
  val less = @{const_syntax less};
 | 
650  | 
  val less_eq = @{const_syntax less_eq};
 | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
651  | 
|
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
652  | 
val trans =  | 
| 21524 | 653  | 
   [((All_binder, impl, less), ("_All_less", "_All_greater")),
 | 
654  | 
    ((All_binder, impl, less_eq), ("_All_less_eq", "_All_greater_eq")),
 | 
|
655  | 
    ((Ex_binder, conj, less), ("_Ex_less", "_Ex_greater")),
 | 
|
656  | 
    ((Ex_binder, conj, less_eq), ("_Ex_less_eq", "_Ex_greater_eq"))];
 | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
657  | 
|
| 
22344
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
658  | 
fun matches_bound v t =  | 
| 
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
659  | 
     case t of (Const ("_bound", _) $ Free (v', _)) => (v = v')
 | 
| 
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
660  | 
| _ => false  | 
| 
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
661  | 
fun contains_var v = Term.exists_subterm (fn Free (x, _) => x = v | _ => false)  | 
| 
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
662  | 
fun mk v c n P = Syntax.const c $ Syntax.mark_bound v $ n $ P  | 
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
663  | 
|
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
664  | 
fun tr' q = (q,  | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
665  | 
    fn [Const ("_bound", _) $ Free (v, _), Const (c, _) $ (Const (d, _) $ t $ u) $ P] =>
 | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
666  | 
(case AList.lookup (op =) trans (q, c, d) of  | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
667  | 
NONE => raise Match  | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
668  | 
| SOME (l, g) =>  | 
| 
22344
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
669  | 
if matches_bound v t andalso not (contains_var v u) then mk v l u P  | 
| 
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
670  | 
else if matches_bound v u andalso not (contains_var v t) then mk v g t P  | 
| 
 
eddeabf16b5d
Fixed print translations for quantifiers a la "ALL x>=t. P x". These used
 
krauss 
parents: 
22316 
diff
changeset
 | 
671  | 
else raise Match)  | 
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
672  | 
| _ => raise Match);  | 
| 21524 | 673  | 
in [tr' All_binder, tr' Ex_binder] end  | 
| 21083 | 674  | 
*}  | 
675  | 
||
676  | 
||
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
677  | 
subsection {* Transitivity reasoning *}
 | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
678  | 
|
| 25193 | 679  | 
context ord  | 
680  | 
begin  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
681  | 
|
| 25193 | 682  | 
lemma ord_le_eq_trans: "a \<le> b \<Longrightarrow> b = c \<Longrightarrow> a \<le> c"  | 
683  | 
by (rule subst)  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
684  | 
|
| 25193 | 685  | 
lemma ord_eq_le_trans: "a = b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"  | 
686  | 
by (rule ssubst)  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
687  | 
|
| 25193 | 688  | 
lemma ord_less_eq_trans: "a < b \<Longrightarrow> b = c \<Longrightarrow> a < c"  | 
689  | 
by (rule subst)  | 
|
690  | 
||
691  | 
lemma ord_eq_less_trans: "a = b \<Longrightarrow> b < c \<Longrightarrow> a < c"  | 
|
692  | 
by (rule ssubst)  | 
|
693  | 
||
694  | 
end  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
695  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
696  | 
lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
697  | 
(!!x y. x < y ==> f x < f y) ==> f a < c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
698  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
699  | 
assume r: "!!x y. x < y ==> f x < f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
700  | 
assume "a < b" hence "f a < f b" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
701  | 
also assume "f b < c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
702  | 
finally (order_less_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
703  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
704  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
705  | 
lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
706  | 
(!!x y. x < y ==> f x < f y) ==> a < f c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
707  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
708  | 
assume r: "!!x y. x < y ==> f x < f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
709  | 
assume "a < f b"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
710  | 
also assume "b < c" hence "f b < f c" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
711  | 
finally (order_less_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
712  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
713  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
714  | 
lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
715  | 
(!!x y. x <= y ==> f x <= f y) ==> f a < c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
716  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
717  | 
assume r: "!!x y. x <= y ==> f x <= f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
718  | 
assume "a <= b" hence "f a <= f b" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
719  | 
also assume "f b < c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
720  | 
finally (order_le_less_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
721  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
722  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
723  | 
lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
724  | 
(!!x y. x < y ==> f x < f y) ==> a < f c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
725  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
726  | 
assume r: "!!x y. x < y ==> f x < f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
727  | 
assume "a <= f b"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
728  | 
also assume "b < c" hence "f b < f c" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
729  | 
finally (order_le_less_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
730  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
731  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
732  | 
lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
733  | 
(!!x y. x < y ==> f x < f y) ==> f a < c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
734  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
735  | 
assume r: "!!x y. x < y ==> f x < f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
736  | 
assume "a < b" hence "f a < f b" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
737  | 
also assume "f b <= c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
738  | 
finally (order_less_le_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
739  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
740  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
741  | 
lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
742  | 
(!!x y. x <= y ==> f x <= f y) ==> a < f c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
743  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
744  | 
assume r: "!!x y. x <= y ==> f x <= f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
745  | 
assume "a < f b"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
746  | 
also assume "b <= c" hence "f b <= f c" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
747  | 
finally (order_less_le_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
748  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
749  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
750  | 
lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
751  | 
(!!x y. x <= y ==> f x <= f y) ==> a <= f c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
752  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
753  | 
assume r: "!!x y. x <= y ==> f x <= f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
754  | 
assume "a <= f b"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
755  | 
also assume "b <= c" hence "f b <= f c" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
756  | 
finally (order_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
757  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
758  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
759  | 
lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
760  | 
(!!x y. x <= y ==> f x <= f y) ==> f a <= c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
761  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
762  | 
assume r: "!!x y. x <= y ==> f x <= f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
763  | 
assume "a <= b" hence "f a <= f b" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
764  | 
also assume "f b <= c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
765  | 
finally (order_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
766  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
767  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
768  | 
lemma ord_le_eq_subst: "a <= b ==> f b = c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
769  | 
(!!x y. x <= y ==> f x <= f y) ==> f a <= c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
770  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
771  | 
assume r: "!!x y. x <= y ==> f x <= f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
772  | 
assume "a <= b" hence "f a <= f b" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
773  | 
also assume "f b = c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
774  | 
finally (ord_le_eq_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
775  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
776  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
777  | 
lemma ord_eq_le_subst: "a = f b ==> b <= c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
778  | 
(!!x y. x <= y ==> f x <= f y) ==> a <= f c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
779  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
780  | 
assume r: "!!x y. x <= y ==> f x <= f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
781  | 
assume "a = f b"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
782  | 
also assume "b <= c" hence "f b <= f c" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
783  | 
finally (ord_eq_le_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
784  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
785  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
786  | 
lemma ord_less_eq_subst: "a < b ==> f b = c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
787  | 
(!!x y. x < y ==> f x < f y) ==> f a < c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
788  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
789  | 
assume r: "!!x y. x < y ==> f x < f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
790  | 
assume "a < b" hence "f a < f b" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
791  | 
also assume "f b = c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
792  | 
finally (ord_less_eq_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
793  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
794  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
795  | 
lemma ord_eq_less_subst: "a = f b ==> b < c ==>  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
796  | 
(!!x y. x < y ==> f x < f y) ==> a < f c"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
797  | 
proof -  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
798  | 
assume r: "!!x y. x < y ==> f x < f y"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
799  | 
assume "a = f b"  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
800  | 
also assume "b < c" hence "f b < f c" by (rule r)  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
801  | 
finally (ord_eq_less_trans) show ?thesis .  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
802  | 
qed  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
803  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
804  | 
text {*
 | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
805  | 
Note that this list of rules is in reverse order of priorities.  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
806  | 
*}  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
807  | 
|
| 27682 | 808  | 
lemmas [trans] =  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
809  | 
order_less_subst2  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
810  | 
order_less_subst1  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
811  | 
order_le_less_subst2  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
812  | 
order_le_less_subst1  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
813  | 
order_less_le_subst2  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
814  | 
order_less_le_subst1  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
815  | 
order_subst2  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
816  | 
order_subst1  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
817  | 
ord_le_eq_subst  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
818  | 
ord_eq_le_subst  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
819  | 
ord_less_eq_subst  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
820  | 
ord_eq_less_subst  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
821  | 
forw_subst  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
822  | 
back_subst  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
823  | 
rev_mp  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
824  | 
mp  | 
| 27682 | 825  | 
|
826  | 
lemmas (in order) [trans] =  | 
|
827  | 
neq_le_trans  | 
|
828  | 
le_neq_trans  | 
|
829  | 
||
830  | 
lemmas (in preorder) [trans] =  | 
|
831  | 
less_trans  | 
|
832  | 
less_asym'  | 
|
833  | 
le_less_trans  | 
|
834  | 
less_le_trans  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
835  | 
order_trans  | 
| 27682 | 836  | 
|
837  | 
lemmas (in order) [trans] =  | 
|
838  | 
antisym  | 
|
839  | 
||
840  | 
lemmas (in ord) [trans] =  | 
|
841  | 
ord_le_eq_trans  | 
|
842  | 
ord_eq_le_trans  | 
|
843  | 
ord_less_eq_trans  | 
|
844  | 
ord_eq_less_trans  | 
|
845  | 
||
846  | 
lemmas [trans] =  | 
|
847  | 
trans  | 
|
848  | 
||
849  | 
lemmas order_trans_rules =  | 
|
850  | 
order_less_subst2  | 
|
851  | 
order_less_subst1  | 
|
852  | 
order_le_less_subst2  | 
|
853  | 
order_le_less_subst1  | 
|
854  | 
order_less_le_subst2  | 
|
855  | 
order_less_le_subst1  | 
|
856  | 
order_subst2  | 
|
857  | 
order_subst1  | 
|
858  | 
ord_le_eq_subst  | 
|
859  | 
ord_eq_le_subst  | 
|
860  | 
ord_less_eq_subst  | 
|
861  | 
ord_eq_less_subst  | 
|
862  | 
forw_subst  | 
|
863  | 
back_subst  | 
|
864  | 
rev_mp  | 
|
865  | 
mp  | 
|
866  | 
neq_le_trans  | 
|
867  | 
le_neq_trans  | 
|
868  | 
less_trans  | 
|
869  | 
less_asym'  | 
|
870  | 
le_less_trans  | 
|
871  | 
less_le_trans  | 
|
872  | 
order_trans  | 
|
873  | 
antisym  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
874  | 
ord_le_eq_trans  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
875  | 
ord_eq_le_trans  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
876  | 
ord_less_eq_trans  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
877  | 
ord_eq_less_trans  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
878  | 
trans  | 
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
879  | 
|
| 
21180
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
880  | 
(* FIXME cleanup *)  | 
| 
 
f27f12bcafb8
fixed print_translation for ALL/EX and <, <=, etc.; tuned syntax names;
 
wenzelm 
parents: 
21091 
diff
changeset
 | 
881  | 
|
| 21083 | 882  | 
text {* These support proving chains of decreasing inequalities
 | 
883  | 
a >= b >= c ... in Isar proofs. *}  | 
|
884  | 
||
885  | 
lemma xt1:  | 
|
886  | 
"a = b ==> b > c ==> a > c"  | 
|
887  | 
"a > b ==> b = c ==> a > c"  | 
|
888  | 
"a = b ==> b >= c ==> a >= c"  | 
|
889  | 
"a >= b ==> b = c ==> a >= c"  | 
|
890  | 
"(x::'a::order) >= y ==> y >= x ==> x = y"  | 
|
891  | 
"(x::'a::order) >= y ==> y >= z ==> x >= z"  | 
|
892  | 
"(x::'a::order) > y ==> y >= z ==> x > z"  | 
|
893  | 
"(x::'a::order) >= y ==> y > z ==> x > z"  | 
|
| 23417 | 894  | 
"(a::'a::order) > b ==> b > a ==> P"  | 
| 21083 | 895  | 
"(x::'a::order) > y ==> y > z ==> x > z"  | 
896  | 
"(a::'a::order) >= b ==> a ~= b ==> a > b"  | 
|
897  | 
"(a::'a::order) ~= b ==> a >= b ==> a > b"  | 
|
898  | 
"a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c"  | 
|
899  | 
"a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c"  | 
|
900  | 
"a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"  | 
|
901  | 
"a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c"  | 
|
| 25076 | 902  | 
by auto  | 
| 21083 | 903  | 
|
904  | 
lemma xt2:  | 
|
905  | 
"(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"  | 
|
906  | 
by (subgoal_tac "f b >= f c", force, force)  | 
|
907  | 
||
908  | 
lemma xt3: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==>  | 
|
909  | 
(!!x y. x >= y ==> f x >= f y) ==> f a >= c"  | 
|
910  | 
by (subgoal_tac "f a >= f b", force, force)  | 
|
911  | 
||
912  | 
lemma xt4: "(a::'a::order) > f b ==> (b::'b::order) >= c ==>  | 
|
913  | 
(!!x y. x >= y ==> f x >= f y) ==> a > f c"  | 
|
914  | 
by (subgoal_tac "f b >= f c", force, force)  | 
|
915  | 
||
916  | 
lemma xt5: "(a::'a::order) > b ==> (f b::'b::order) >= c==>  | 
|
917  | 
(!!x y. x > y ==> f x > f y) ==> f a > c"  | 
|
918  | 
by (subgoal_tac "f a > f b", force, force)  | 
|
919  | 
||
920  | 
lemma xt6: "(a::'a::order) >= f b ==> b > c ==>  | 
|
921  | 
(!!x y. x > y ==> f x > f y) ==> a > f c"  | 
|
922  | 
by (subgoal_tac "f b > f c", force, force)  | 
|
923  | 
||
924  | 
lemma xt7: "(a::'a::order) >= b ==> (f b::'b::order) > c ==>  | 
|
925  | 
(!!x y. x >= y ==> f x >= f y) ==> f a > c"  | 
|
926  | 
by (subgoal_tac "f a >= f b", force, force)  | 
|
927  | 
||
928  | 
lemma xt8: "(a::'a::order) > f b ==> (b::'b::order) > c ==>  | 
|
929  | 
(!!x y. x > y ==> f x > f y) ==> a > f c"  | 
|
930  | 
by (subgoal_tac "f b > f c", force, force)  | 
|
931  | 
||
932  | 
lemma xt9: "(a::'a::order) > b ==> (f b::'b::order) > c ==>  | 
|
933  | 
(!!x y. x > y ==> f x > f y) ==> f a > c"  | 
|
934  | 
by (subgoal_tac "f a > f b", force, force)  | 
|
935  | 
||
936  | 
lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9  | 
|
937  | 
||
938  | 
(*  | 
|
939  | 
Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands  | 
|
940  | 
for the wrong thing in an Isar proof.  | 
|
941  | 
||
942  | 
The extra transitivity rules can be used as follows:  | 
|
943  | 
||
944  | 
lemma "(a::'a::order) > z"  | 
|
945  | 
proof -  | 
|
946  | 
have "a >= b" (is "_ >= ?rhs")  | 
|
947  | 
sorry  | 
|
948  | 
also have "?rhs >= c" (is "_ >= ?rhs")  | 
|
949  | 
sorry  | 
|
950  | 
also (xtrans) have "?rhs = d" (is "_ = ?rhs")  | 
|
951  | 
sorry  | 
|
952  | 
also (xtrans) have "?rhs >= e" (is "_ >= ?rhs")  | 
|
953  | 
sorry  | 
|
954  | 
also (xtrans) have "?rhs > f" (is "_ > ?rhs")  | 
|
955  | 
sorry  | 
|
956  | 
also (xtrans) have "?rhs > z"  | 
|
957  | 
sorry  | 
|
958  | 
finally (xtrans) show ?thesis .  | 
|
959  | 
qed  | 
|
960  | 
||
961  | 
Alternatively, one can use "declare xtrans [trans]" and then  | 
|
962  | 
leave out the "(xtrans)" above.  | 
|
963  | 
*)  | 
|
964  | 
||
| 21546 | 965  | 
subsection {* Order on bool *}
 | 
966  | 
||
| 26324 | 967  | 
instantiation bool :: order  | 
| 25510 | 968  | 
begin  | 
969  | 
||
970  | 
definition  | 
|
| 28562 | 971  | 
le_bool_def [code del]: "P \<le> Q \<longleftrightarrow> P \<longrightarrow> Q"  | 
| 25510 | 972  | 
|
973  | 
definition  | 
|
| 28562 | 974  | 
less_bool_def [code del]: "(P\<Colon>bool) < Q \<longleftrightarrow> P \<le> Q \<and> P \<noteq> Q"  | 
| 25510 | 975  | 
|
976  | 
instance  | 
|
| 22916 | 977  | 
by intro_classes (auto simp add: le_bool_def less_bool_def)  | 
| 25510 | 978  | 
|
979  | 
end  | 
|
| 21546 | 980  | 
|
981  | 
lemma le_boolI: "(P \<Longrightarrow> Q) \<Longrightarrow> P \<le> Q"  | 
|
| 23212 | 982  | 
by (simp add: le_bool_def)  | 
| 21546 | 983  | 
|
984  | 
lemma le_boolI': "P \<longrightarrow> Q \<Longrightarrow> P \<le> Q"  | 
|
| 23212 | 985  | 
by (simp add: le_bool_def)  | 
| 21546 | 986  | 
|
987  | 
lemma le_boolE: "P \<le> Q \<Longrightarrow> P \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"  | 
|
| 23212 | 988  | 
by (simp add: le_bool_def)  | 
| 21546 | 989  | 
|
990  | 
lemma le_boolD: "P \<le> Q \<Longrightarrow> P \<longrightarrow> Q"  | 
|
| 23212 | 991  | 
by (simp add: le_bool_def)  | 
| 21546 | 992  | 
|
| 28562 | 993  | 
lemma [code]:  | 
| 22348 | 994  | 
"False \<le> b \<longleftrightarrow> True"  | 
995  | 
"True \<le> b \<longleftrightarrow> b"  | 
|
996  | 
"False < b \<longleftrightarrow> b"  | 
|
997  | 
"True < b \<longleftrightarrow> False"  | 
|
998  | 
unfolding le_bool_def less_bool_def by simp_all  | 
|
999  | 
||
| 22424 | 1000  | 
|
| 23881 | 1001  | 
subsection {* Order on functions *}
 | 
1002  | 
||
| 25510 | 1003  | 
instantiation "fun" :: (type, ord) ord  | 
1004  | 
begin  | 
|
1005  | 
||
1006  | 
definition  | 
|
| 28562 | 1007  | 
le_fun_def [code del]: "f \<le> g \<longleftrightarrow> (\<forall>x. f x \<le> g x)"  | 
| 23881 | 1008  | 
|
| 25510 | 1009  | 
definition  | 
| 28562 | 1010  | 
less_fun_def [code del]: "(f\<Colon>'a \<Rightarrow> 'b) < g \<longleftrightarrow> f \<le> g \<and> f \<noteq> g"  | 
| 25510 | 1011  | 
|
1012  | 
instance ..  | 
|
1013  | 
||
1014  | 
end  | 
|
| 23881 | 1015  | 
|
1016  | 
instance "fun" :: (type, order) order  | 
|
1017  | 
by default  | 
|
| 
26796
 
c554b77061e5
- Now imports Code_Setup, rather than Set and Fun, since the theorems
 
berghofe 
parents: 
26496 
diff
changeset
 | 
1018  | 
(auto simp add: le_fun_def less_fun_def  | 
| 
 
c554b77061e5
- Now imports Code_Setup, rather than Set and Fun, since the theorems
 
berghofe 
parents: 
26496 
diff
changeset
 | 
1019  | 
intro: order_trans order_antisym intro!: ext)  | 
| 23881 | 1020  | 
|
1021  | 
lemma le_funI: "(\<And>x. f x \<le> g x) \<Longrightarrow> f \<le> g"  | 
|
1022  | 
unfolding le_fun_def by simp  | 
|
1023  | 
||
1024  | 
lemma le_funE: "f \<le> g \<Longrightarrow> (f x \<le> g x \<Longrightarrow> P) \<Longrightarrow> P"  | 
|
1025  | 
unfolding le_fun_def by simp  | 
|
1026  | 
||
1027  | 
lemma le_funD: "f \<le> g \<Longrightarrow> f x \<le> g x"  | 
|
1028  | 
unfolding le_fun_def by simp  | 
|
1029  | 
||
1030  | 
text {*
 | 
|
1031  | 
  Handy introduction and elimination rules for @{text "\<le>"}
 | 
|
1032  | 
on unary and binary predicates  | 
|
1033  | 
*}  | 
|
1034  | 
||
| 
26796
 
c554b77061e5
- Now imports Code_Setup, rather than Set and Fun, since the theorems
 
berghofe 
parents: 
26496 
diff
changeset
 | 
1035  | 
lemma predicate1I:  | 
| 23881 | 1036  | 
assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"  | 
1037  | 
shows "P \<le> Q"  | 
|
1038  | 
apply (rule le_funI)  | 
|
1039  | 
apply (rule le_boolI)  | 
|
1040  | 
apply (rule PQ)  | 
|
1041  | 
apply assumption  | 
|
1042  | 
done  | 
|
1043  | 
||
1044  | 
lemma predicate1D [Pure.dest, dest]: "P \<le> Q \<Longrightarrow> P x \<Longrightarrow> Q x"  | 
|
1045  | 
apply (erule le_funE)  | 
|
1046  | 
apply (erule le_boolE)  | 
|
1047  | 
apply assumption+  | 
|
1048  | 
done  | 
|
1049  | 
||
1050  | 
lemma predicate2I [Pure.intro!, intro!]:  | 
|
1051  | 
assumes PQ: "\<And>x y. P x y \<Longrightarrow> Q x y"  | 
|
1052  | 
shows "P \<le> Q"  | 
|
1053  | 
apply (rule le_funI)+  | 
|
1054  | 
apply (rule le_boolI)  | 
|
1055  | 
apply (rule PQ)  | 
|
1056  | 
apply assumption  | 
|
1057  | 
done  | 
|
1058  | 
||
1059  | 
lemma predicate2D [Pure.dest, dest]: "P \<le> Q \<Longrightarrow> P x y \<Longrightarrow> Q x y"  | 
|
1060  | 
apply (erule le_funE)+  | 
|
1061  | 
apply (erule le_boolE)  | 
|
1062  | 
apply assumption+  | 
|
1063  | 
done  | 
|
1064  | 
||
1065  | 
lemma rev_predicate1D: "P x ==> P <= Q ==> Q x"  | 
|
1066  | 
by (rule predicate1D)  | 
|
1067  | 
||
1068  | 
lemma rev_predicate2D: "P x y ==> P <= Q ==> Q x y"  | 
|
1069  | 
by (rule predicate2D)  | 
|
1070  | 
||
1071  | 
||
1072  | 
subsection {* Monotonicity, least value operator and min/max *}
 | 
|
| 21083 | 1073  | 
|
| 25076 | 1074  | 
context order  | 
1075  | 
begin  | 
|
1076  | 
||
1077  | 
definition  | 
|
1078  | 
  mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool"
 | 
|
1079  | 
where  | 
|
1080  | 
"mono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<le> f y)"  | 
|
1081  | 
||
1082  | 
lemma monoI [intro?]:  | 
|
1083  | 
fixes f :: "'a \<Rightarrow> 'b\<Colon>order"  | 
|
1084  | 
shows "(\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y) \<Longrightarrow> mono f"  | 
|
1085  | 
unfolding mono_def by iprover  | 
|
| 
21216
 
1c8580913738
made locale partial_order compatible with axclass order; changed import order; consecutive changes
 
haftmann 
parents: 
21204 
diff
changeset
 | 
1086  | 
|
| 25076 | 1087  | 
lemma monoD [dest?]:  | 
1088  | 
fixes f :: "'a \<Rightarrow> 'b\<Colon>order"  | 
|
1089  | 
shows "mono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"  | 
|
1090  | 
unfolding mono_def by iprover  | 
|
1091  | 
||
1092  | 
end  | 
|
1093  | 
||
1094  | 
context linorder  | 
|
1095  | 
begin  | 
|
1096  | 
||
1097  | 
lemma min_of_mono:  | 
|
1098  | 
fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"  | 
|
| 25377 | 1099  | 
shows "mono f \<Longrightarrow> min (f m) (f n) = f (min m n)"  | 
| 25076 | 1100  | 
by (auto simp: mono_def Orderings.min_def min_def intro: Orderings.antisym)  | 
1101  | 
||
1102  | 
lemma max_of_mono:  | 
|
1103  | 
fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"  | 
|
| 25377 | 1104  | 
shows "mono f \<Longrightarrow> max (f m) (f n) = f (max m n)"  | 
| 25076 | 1105  | 
by (auto simp: mono_def Orderings.max_def max_def intro: Orderings.antisym)  | 
1106  | 
||
1107  | 
end  | 
|
| 21083 | 1108  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1109  | 
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"  | 
| 23212 | 1110  | 
by (simp add: min_def)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1111  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1112  | 
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"  | 
| 23212 | 1113  | 
by (simp add: max_def)  | 
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1114  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1115  | 
lemma min_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> min x least = least"  | 
| 23212 | 1116  | 
apply (simp add: min_def)  | 
1117  | 
apply (blast intro: order_antisym)  | 
|
1118  | 
done  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1119  | 
|
| 
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1120  | 
lemma max_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> max x least = x"  | 
| 23212 | 1121  | 
apply (simp add: max_def)  | 
1122  | 
apply (blast intro: order_antisym)  | 
|
1123  | 
done  | 
|
| 
21383
 
17e6275e13f5
added transitivity rules, reworking of min/max lemmas
 
haftmann 
parents: 
21329 
diff
changeset
 | 
1124  | 
|
| 27823 | 1125  | 
|
1126  | 
subsection {* Dense orders *}
 | 
|
1127  | 
||
1128  | 
class dense_linear_order = linorder +  | 
|
1129  | 
assumes gt_ex: "\<exists>y. x < y"  | 
|
1130  | 
and lt_ex: "\<exists>y. y < x"  | 
|
1131  | 
and dense: "x < y \<Longrightarrow> (\<exists>z. x < z \<and> z < y)"  | 
|
1132  | 
(*see further theory Dense_Linear_Order*)  | 
|
1133  | 
||
1134  | 
||
1135  | 
subsection {* Wellorders *}
 | 
|
1136  | 
||
1137  | 
class wellorder = linorder +  | 
|
1138  | 
assumes less_induct [case_names less]: "(\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P a"  | 
|
1139  | 
begin  | 
|
1140  | 
||
1141  | 
lemma wellorder_Least_lemma:  | 
|
1142  | 
fixes k :: 'a  | 
|
1143  | 
assumes "P k"  | 
|
1144  | 
shows "P (LEAST x. P x)" and "(LEAST x. P x) \<le> k"  | 
|
1145  | 
proof -  | 
|
1146  | 
have "P (LEAST x. P x) \<and> (LEAST x. P x) \<le> k"  | 
|
1147  | 
using assms proof (induct k rule: less_induct)  | 
|
1148  | 
case (less x) then have "P x" by simp  | 
|
1149  | 
show ?case proof (rule classical)  | 
|
1150  | 
assume assm: "\<not> (P (LEAST a. P a) \<and> (LEAST a. P a) \<le> x)"  | 
|
1151  | 
have "\<And>y. P y \<Longrightarrow> x \<le> y"  | 
|
1152  | 
proof (rule classical)  | 
|
1153  | 
fix y  | 
|
1154  | 
assume "P y" and "\<not> x \<le> y"  | 
|
1155  | 
with less have "P (LEAST a. P a)" and "(LEAST a. P a) \<le> y"  | 
|
1156  | 
by (auto simp add: not_le)  | 
|
1157  | 
with assm have "x < (LEAST a. P a)" and "(LEAST a. P a) \<le> y"  | 
|
1158  | 
by auto  | 
|
1159  | 
then show "x \<le> y" by auto  | 
|
1160  | 
qed  | 
|
1161  | 
with `P x` have Least: "(LEAST a. P a) = x"  | 
|
1162  | 
by (rule Least_equality)  | 
|
1163  | 
with `P x` show ?thesis by simp  | 
|
1164  | 
qed  | 
|
1165  | 
qed  | 
|
1166  | 
then show "P (LEAST x. P x)" and "(LEAST x. P x) \<le> k" by auto  | 
|
1167  | 
qed  | 
|
1168  | 
||
1169  | 
lemmas LeastI = wellorder_Least_lemma(1)  | 
|
1170  | 
lemmas Least_le = wellorder_Least_lemma(2)  | 
|
1171  | 
||
1172  | 
-- "The following 3 lemmas are due to Brian Huffman"  | 
|
1173  | 
lemma LeastI_ex: "\<exists>x. P x \<Longrightarrow> P (Least P)"  | 
|
1174  | 
by (erule exE) (erule LeastI)  | 
|
1175  | 
||
1176  | 
lemma LeastI2:  | 
|
1177  | 
"P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"  | 
|
1178  | 
by (blast intro: LeastI)  | 
|
1179  | 
||
1180  | 
lemma LeastI2_ex:  | 
|
1181  | 
"\<exists>a. P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"  | 
|
1182  | 
by (blast intro: LeastI_ex)  | 
|
1183  | 
||
1184  | 
lemma not_less_Least: "k < (LEAST x. P x) \<Longrightarrow> \<not> P k"  | 
|
1185  | 
apply (simp (no_asm_use) add: not_le [symmetric])  | 
|
1186  | 
apply (erule contrapos_nn)  | 
|
1187  | 
apply (erule Least_le)  | 
|
1188  | 
done  | 
|
1189  | 
||
1190  | 
end  | 
|
1191  | 
||
| 15524 | 1192  | 
end  |