src/HOL/Orderings.thy
author haftmann
Tue Jun 05 19:23:09 2007 +0200 (2007-06-05)
changeset 23263 0c227412b285
parent 23247 b99dce43d252
child 23417 42c1a89b45c1
permissions -rw-r--r--
tuned boostrap
nipkow@15524
     1
(*  Title:      HOL/Orderings.thy
nipkow@15524
     2
    ID:         $Id$
nipkow@15524
     3
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
nipkow@15524
     4
*)
nipkow@15524
     5
haftmann@21329
     6
header {* Syntactic and abstract orders *}
nipkow@15524
     7
nipkow@15524
     8
theory Orderings
haftmann@23247
     9
imports HOL
haftmann@23263
    10
uses
haftmann@23263
    11
  (*"~~/src/Provers/quasi.ML"*)
haftmann@23263
    12
  "~~/src/Provers/order.ML"
nipkow@15524
    13
begin
nipkow@15524
    14
haftmann@21329
    15
subsection {* Order syntax *}
nipkow@15524
    16
haftmann@22473
    17
class ord = type +
wenzelm@21656
    18
  fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"  (infix "\<sqsubseteq>" 50)
wenzelm@21656
    19
    and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool"  (infix "\<sqsubset>" 50)
wenzelm@21204
    20
begin
wenzelm@21204
    21
wenzelm@21204
    22
notation
wenzelm@21656
    23
  less_eq  ("op \<^loc><=") and
haftmann@21620
    24
  less_eq  ("(_/ \<^loc><= _)" [51, 51] 50) and
wenzelm@21656
    25
  less  ("op \<^loc><") and
wenzelm@21656
    26
  less  ("(_/ \<^loc>< _)"  [51, 51] 50)
haftmann@21620
    27
  
wenzelm@21204
    28
notation (xsymbols)
wenzelm@21404
    29
  less_eq  ("op \<^loc>\<le>") and
wenzelm@21259
    30
  less_eq  ("(_/ \<^loc>\<le> _)"  [51, 51] 50)
nipkow@15524
    31
wenzelm@21204
    32
notation (HTML output)
wenzelm@21404
    33
  less_eq  ("op \<^loc>\<le>") and
wenzelm@21259
    34
  less_eq  ("(_/ \<^loc>\<le> _)"  [51, 51] 50)
wenzelm@21204
    35
wenzelm@21204
    36
abbreviation (input)
wenzelm@21656
    37
  greater  (infix "\<^loc>>" 50) where
haftmann@21620
    38
  "x \<^loc>> y \<equiv> y \<^loc>< x"
haftmann@21620
    39
wenzelm@21656
    40
abbreviation (input)
wenzelm@21656
    41
  greater_eq  (infix "\<^loc>>=" 50) where
wenzelm@21656
    42
  "x \<^loc>>= y \<equiv> y \<^loc><= x"
wenzelm@21204
    43
wenzelm@21656
    44
notation (input)
wenzelm@21656
    45
  greater_eq  (infix "\<^loc>\<ge>" 50)
wenzelm@21204
    46
haftmann@22738
    47
text {*
haftmann@22738
    48
  syntactic min/max -- these definitions reach
haftmann@22738
    49
  their usual semantics in class linorder ahead.
haftmann@22738
    50
*}
haftmann@22738
    51
haftmann@22738
    52
definition
haftmann@22738
    53
  min :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@22841
    54
  "min a b = (if a \<^loc>\<le> b then a else b)"
haftmann@22738
    55
haftmann@22738
    56
definition
haftmann@22738
    57
  max :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@22841
    58
  "max a b = (if a \<^loc>\<le> b then b else a)"
haftmann@22738
    59
wenzelm@21204
    60
end
wenzelm@21204
    61
wenzelm@21204
    62
notation
wenzelm@21656
    63
  less_eq  ("op <=") and
haftmann@21620
    64
  less_eq  ("(_/ <= _)" [51, 51] 50) and
wenzelm@21656
    65
  less  ("op <") and
wenzelm@21656
    66
  less  ("(_/ < _)"  [51, 51] 50)
wenzelm@21204
    67
  
wenzelm@21204
    68
notation (xsymbols)
wenzelm@21404
    69
  less_eq  ("op \<le>") and
wenzelm@21259
    70
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
nipkow@15524
    71
wenzelm@21204
    72
notation (HTML output)
wenzelm@21404
    73
  less_eq  ("op \<le>") and
wenzelm@21259
    74
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
haftmann@20714
    75
wenzelm@19536
    76
abbreviation (input)
wenzelm@21656
    77
  greater  (infix ">" 50) where
haftmann@21620
    78
  "x > y \<equiv> y < x"
haftmann@21620
    79
wenzelm@21656
    80
abbreviation (input)
wenzelm@21656
    81
  greater_eq  (infix ">=" 50) where
wenzelm@21656
    82
  "x >= y \<equiv> y <= x"
haftmann@21620
    83
wenzelm@21656
    84
notation (input)
wenzelm@21656
    85
  greater_eq  (infix "\<ge>" 50)
nipkow@15524
    86
haftmann@23087
    87
lemmas min_def [code func, code unfold, code inline del] = min_def [folded ord_class.min]
haftmann@23087
    88
lemmas max_def [code func, code unfold, code inline del] = max_def [folded ord_class.max]
haftmann@22738
    89
nipkow@15524
    90
haftmann@22841
    91
subsection {* Partial orders *}
nipkow@15524
    92
haftmann@22841
    93
class order = ord +
haftmann@22316
    94
  assumes less_le: "x \<sqsubset> y \<longleftrightarrow> x \<sqsubseteq> y \<and> x \<noteq> y"
haftmann@22384
    95
  and order_refl [iff]: "x \<sqsubseteq> x"
haftmann@22384
    96
  and order_trans: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> z"
haftmann@22841
    97
  assumes antisym: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> x \<Longrightarrow> x = y"
haftmann@22841
    98
haftmann@21248
    99
begin
haftmann@21248
   100
nipkow@15524
   101
text {* Reflexivity. *}
nipkow@15524
   102
haftmann@22841
   103
lemma eq_refl: "x = y \<Longrightarrow> x \<^loc>\<le> y"
nipkow@15524
   104
    -- {* This form is useful with the classical reasoner. *}
nipkow@23212
   105
by (erule ssubst) (rule order_refl)
nipkow@15524
   106
haftmann@22841
   107
lemma less_irrefl [iff]: "\<not> x \<^loc>< x"
nipkow@23212
   108
by (simp add: less_le)
nipkow@15524
   109
haftmann@22841
   110
lemma le_less: "x \<^loc>\<le> y \<longleftrightarrow> x \<^loc>< y \<or> x = y"
nipkow@15524
   111
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
nipkow@23212
   112
by (simp add: less_le) blast
nipkow@15524
   113
haftmann@22841
   114
lemma le_imp_less_or_eq: "x \<^loc>\<le> y \<Longrightarrow> x \<^loc>< y \<or> x = y"
nipkow@23212
   115
unfolding less_le by blast
nipkow@15524
   116
haftmann@22841
   117
lemma less_imp_le: "x \<^loc>< y \<Longrightarrow> x \<^loc>\<le> y"
nipkow@23212
   118
unfolding less_le by blast
haftmann@21248
   119
haftmann@22841
   120
lemma less_imp_neq: "x \<^loc>< y \<Longrightarrow> x \<noteq> y"
nipkow@23212
   121
by (erule contrapos_pn, erule subst, rule less_irrefl)
haftmann@21329
   122
haftmann@21329
   123
haftmann@21329
   124
text {* Useful for simplification, but too risky to include by default. *}
haftmann@21329
   125
haftmann@22841
   126
lemma less_imp_not_eq: "x \<^loc>< y \<Longrightarrow> (x = y) \<longleftrightarrow> False"
nipkow@23212
   127
by auto
haftmann@21329
   128
haftmann@22841
   129
lemma less_imp_not_eq2: "x \<^loc>< y \<Longrightarrow> (y = x) \<longleftrightarrow> False"
nipkow@23212
   130
by auto
haftmann@21329
   131
haftmann@21329
   132
haftmann@21329
   133
text {* Transitivity rules for calculational reasoning *}
haftmann@21329
   134
haftmann@22841
   135
lemma neq_le_trans: "a \<noteq> b \<Longrightarrow> a \<^loc>\<le> b \<Longrightarrow> a \<^loc>< b"
nipkow@23212
   136
by (simp add: less_le)
haftmann@21329
   137
haftmann@22841
   138
lemma le_neq_trans: "a \<^loc>\<le> b \<Longrightarrow> a \<noteq> b \<Longrightarrow> a \<^loc>< b"
nipkow@23212
   139
by (simp add: less_le)
haftmann@21329
   140
nipkow@15524
   141
nipkow@15524
   142
text {* Asymmetry. *}
nipkow@15524
   143
haftmann@22841
   144
lemma less_not_sym: "x \<^loc>< y \<Longrightarrow> \<not> (y \<^loc>< x)"
nipkow@23212
   145
by (simp add: less_le antisym)
nipkow@15524
   146
haftmann@22841
   147
lemma less_asym: "x \<^loc>< y \<Longrightarrow> (\<not> P \<Longrightarrow> y \<^loc>< x) \<Longrightarrow> P"
nipkow@23212
   148
by (drule less_not_sym, erule contrapos_np) simp
nipkow@15524
   149
haftmann@22841
   150
lemma eq_iff: "x = y \<longleftrightarrow> x \<^loc>\<le> y \<and> y \<^loc>\<le> x"
nipkow@23212
   151
by (blast intro: antisym)
nipkow@15524
   152
haftmann@22841
   153
lemma antisym_conv: "y \<^loc>\<le> x \<Longrightarrow> x \<^loc>\<le> y \<longleftrightarrow> x = y"
nipkow@23212
   154
by (blast intro: antisym)
nipkow@15524
   155
haftmann@22841
   156
lemma less_imp_neq: "x \<^loc>< y \<Longrightarrow> x \<noteq> y"
nipkow@23212
   157
by (erule contrapos_pn, erule subst, rule less_irrefl)
haftmann@21248
   158
haftmann@21083
   159
nipkow@15524
   160
text {* Transitivity. *}
nipkow@15524
   161
haftmann@22841
   162
lemma less_trans: "x \<^loc>< y \<Longrightarrow> y \<^loc>< z \<Longrightarrow> x \<^loc>< z"
nipkow@23212
   163
by (simp add: less_le) (blast intro: order_trans antisym)
nipkow@15524
   164
haftmann@22841
   165
lemma le_less_trans: "x \<^loc>\<le> y \<Longrightarrow> y \<^loc>< z \<Longrightarrow> x \<^loc>< z"
nipkow@23212
   166
by (simp add: less_le) (blast intro: order_trans antisym)
nipkow@15524
   167
haftmann@22841
   168
lemma less_le_trans: "x \<^loc>< y \<Longrightarrow> y \<^loc>\<le> z \<Longrightarrow> x \<^loc>< z"
nipkow@23212
   169
by (simp add: less_le) (blast intro: order_trans antisym)
nipkow@15524
   170
nipkow@15524
   171
nipkow@15524
   172
text {* Useful for simplification, but too risky to include by default. *}
nipkow@15524
   173
haftmann@22841
   174
lemma less_imp_not_less: "x \<^loc>< y \<Longrightarrow> (\<not> y \<^loc>< x) \<longleftrightarrow> True"
nipkow@23212
   175
by (blast elim: less_asym)
nipkow@15524
   176
haftmann@22841
   177
lemma less_imp_triv: "x \<^loc>< y \<Longrightarrow> (y \<^loc>< x \<longrightarrow> P) \<longleftrightarrow> True"
nipkow@23212
   178
by (blast elim: less_asym)
nipkow@15524
   179
haftmann@21248
   180
haftmann@21083
   181
text {* Transitivity rules for calculational reasoning *}
nipkow@15524
   182
haftmann@22841
   183
lemma less_asym': "a \<^loc>< b \<Longrightarrow> b \<^loc>< a \<Longrightarrow> P"
nipkow@23212
   184
by (rule less_asym)
haftmann@21248
   185
haftmann@22916
   186
haftmann@22916
   187
text {* Reverse order *}
haftmann@22916
   188
haftmann@22916
   189
lemma order_reverse:
haftmann@23018
   190
  "order (\<lambda>x y. y \<^loc>\<le> x) (\<lambda>x y. y \<^loc>< x)"
nipkow@23212
   191
by unfold_locales
nipkow@23212
   192
   (simp add: less_le, auto intro: antisym order_trans)
haftmann@22916
   193
haftmann@21248
   194
end
nipkow@15524
   195
haftmann@21329
   196
haftmann@21329
   197
subsection {* Linear (total) orders *}
haftmann@21329
   198
haftmann@22316
   199
class linorder = order +
haftmann@21216
   200
  assumes linear: "x \<sqsubseteq> y \<or> y \<sqsubseteq> x"
haftmann@21248
   201
begin
haftmann@21248
   202
haftmann@22841
   203
lemma less_linear: "x \<^loc>< y \<or> x = y \<or> y \<^loc>< x"
nipkow@23212
   204
unfolding less_le using less_le linear by blast
haftmann@21248
   205
haftmann@22841
   206
lemma le_less_linear: "x \<^loc>\<le> y \<or> y \<^loc>< x"
nipkow@23212
   207
by (simp add: le_less less_linear)
haftmann@21248
   208
haftmann@21248
   209
lemma le_cases [case_names le ge]:
haftmann@22841
   210
  "(x \<^loc>\<le> y \<Longrightarrow> P) \<Longrightarrow> (y \<^loc>\<le> x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212
   211
using linear by blast
haftmann@21248
   212
haftmann@22384
   213
lemma linorder_cases [case_names less equal greater]:
nipkow@23212
   214
  "(x \<^loc>< y \<Longrightarrow> P) \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> (y \<^loc>< x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212
   215
using less_linear by blast
haftmann@21248
   216
haftmann@22841
   217
lemma not_less: "\<not> x \<^loc>< y \<longleftrightarrow> y \<^loc>\<le> x"
nipkow@23212
   218
apply (simp add: less_le)
nipkow@23212
   219
using linear apply (blast intro: antisym)
nipkow@23212
   220
done
nipkow@23212
   221
nipkow@23212
   222
lemma not_less_iff_gr_or_eq:
nipkow@23212
   223
 "\<not>(x \<^loc>< y) \<longleftrightarrow> (x \<^loc>> y | x = y)"
nipkow@23212
   224
apply(simp add:not_less le_less)
nipkow@23212
   225
apply blast
nipkow@23212
   226
done
nipkow@15524
   227
haftmann@22841
   228
lemma not_le: "\<not> x \<^loc>\<le> y \<longleftrightarrow> y \<^loc>< x"
nipkow@23212
   229
apply (simp add: less_le)
nipkow@23212
   230
using linear apply (blast intro: antisym)
nipkow@23212
   231
done
nipkow@15524
   232
haftmann@22841
   233
lemma neq_iff: "x \<noteq> y \<longleftrightarrow> x \<^loc>< y \<or> y \<^loc>< x"
nipkow@23212
   234
by (cut_tac x = x and y = y in less_linear, auto)
nipkow@15524
   235
haftmann@22841
   236
lemma neqE: "x \<noteq> y \<Longrightarrow> (x \<^loc>< y \<Longrightarrow> R) \<Longrightarrow> (y \<^loc>< x \<Longrightarrow> R) \<Longrightarrow> R"
nipkow@23212
   237
by (simp add: neq_iff) blast
nipkow@15524
   238
haftmann@22841
   239
lemma antisym_conv1: "\<not> x \<^loc>< y \<Longrightarrow> x \<^loc>\<le> y \<longleftrightarrow> x = y"
nipkow@23212
   240
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   241
haftmann@22841
   242
lemma antisym_conv2: "x \<^loc>\<le> y \<Longrightarrow> \<not> x \<^loc>< y \<longleftrightarrow> x = y"
nipkow@23212
   243
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   244
haftmann@22841
   245
lemma antisym_conv3: "\<not> y \<^loc>< x \<Longrightarrow> \<not> x \<^loc>< y \<longleftrightarrow> x = y"
nipkow@23212
   246
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   247
paulson@16796
   248
text{*Replacing the old Nat.leI*}
haftmann@22841
   249
lemma leI: "\<not> x \<^loc>< y \<Longrightarrow> y \<^loc>\<le> x"
nipkow@23212
   250
unfolding not_less .
paulson@16796
   251
haftmann@22841
   252
lemma leD: "y \<^loc>\<le> x \<Longrightarrow> \<not> x \<^loc>< y"
nipkow@23212
   253
unfolding not_less .
paulson@16796
   254
paulson@16796
   255
(*FIXME inappropriate name (or delete altogether)*)
haftmann@22841
   256
lemma not_leE: "\<not> y \<^loc>\<le> x \<Longrightarrow> x \<^loc>< y"
nipkow@23212
   257
unfolding not_le .
haftmann@21248
   258
haftmann@22916
   259
haftmann@22916
   260
text {* Reverse order *}
haftmann@22916
   261
haftmann@22916
   262
lemma linorder_reverse:
haftmann@23018
   263
  "linorder (\<lambda>x y. y \<^loc>\<le> x) (\<lambda>x y. y \<^loc>< x)"
nipkow@23212
   264
by unfold_locales
nipkow@23212
   265
  (simp add: less_le, auto intro: antisym order_trans simp add: linear)
haftmann@22916
   266
haftmann@22916
   267
haftmann@22738
   268
text {* min/max properties *}
haftmann@22384
   269
haftmann@21383
   270
lemma min_le_iff_disj:
haftmann@22841
   271
  "min x y \<^loc>\<le> z \<longleftrightarrow> x \<^loc>\<le> z \<or> y \<^loc>\<le> z"
nipkow@23212
   272
unfolding min_def using linear by (auto intro: order_trans)
haftmann@21383
   273
haftmann@21383
   274
lemma le_max_iff_disj:
haftmann@22841
   275
  "z \<^loc>\<le> max x y \<longleftrightarrow> z \<^loc>\<le> x \<or> z \<^loc>\<le> y"
nipkow@23212
   276
unfolding max_def using linear by (auto intro: order_trans)
haftmann@21383
   277
haftmann@21383
   278
lemma min_less_iff_disj:
haftmann@22841
   279
  "min x y \<^loc>< z \<longleftrightarrow> x \<^loc>< z \<or> y \<^loc>< z"
nipkow@23212
   280
unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   281
haftmann@21383
   282
lemma less_max_iff_disj:
haftmann@22841
   283
  "z \<^loc>< max x y \<longleftrightarrow> z \<^loc>< x \<or> z \<^loc>< y"
nipkow@23212
   284
unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   285
haftmann@21383
   286
lemma min_less_iff_conj [simp]:
haftmann@22841
   287
  "z \<^loc>< min x y \<longleftrightarrow> z \<^loc>< x \<and> z \<^loc>< y"
nipkow@23212
   288
unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   289
haftmann@21383
   290
lemma max_less_iff_conj [simp]:
haftmann@22841
   291
  "max x y \<^loc>< z \<longleftrightarrow> x \<^loc>< z \<and> y \<^loc>< z"
nipkow@23212
   292
unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   293
haftmann@21383
   294
lemma split_min:
haftmann@22841
   295
  "P (min i j) \<longleftrightarrow> (i \<^loc>\<le> j \<longrightarrow> P i) \<and> (\<not> i \<^loc>\<le> j \<longrightarrow> P j)"
nipkow@23212
   296
by (simp add: min_def)
haftmann@21383
   297
haftmann@21383
   298
lemma split_max:
haftmann@22841
   299
  "P (max i j) \<longleftrightarrow> (i \<^loc>\<le> j \<longrightarrow> P j) \<and> (\<not> i \<^loc>\<le> j \<longrightarrow> P i)"
nipkow@23212
   300
by (simp add: max_def)
haftmann@21383
   301
haftmann@21248
   302
end
haftmann@21248
   303
haftmann@22916
   304
subsection {* Name duplicates -- including min/max interpretation *}
haftmann@21248
   305
haftmann@22384
   306
lemmas order_less_le = less_le
haftmann@22841
   307
lemmas order_eq_refl = order_class.eq_refl
haftmann@22841
   308
lemmas order_less_irrefl = order_class.less_irrefl
haftmann@22841
   309
lemmas order_le_less = order_class.le_less
haftmann@22841
   310
lemmas order_le_imp_less_or_eq = order_class.le_imp_less_or_eq
haftmann@22841
   311
lemmas order_less_imp_le = order_class.less_imp_le
haftmann@22841
   312
lemmas order_less_imp_not_eq = order_class.less_imp_not_eq
haftmann@22841
   313
lemmas order_less_imp_not_eq2 = order_class.less_imp_not_eq2
haftmann@22841
   314
lemmas order_neq_le_trans = order_class.neq_le_trans
haftmann@22841
   315
lemmas order_le_neq_trans = order_class.le_neq_trans
haftmann@22316
   316
haftmann@22384
   317
lemmas order_antisym = antisym
haftmann@22316
   318
lemmas order_less_not_sym = order_class.less_not_sym
haftmann@22316
   319
lemmas order_less_asym = order_class.less_asym
haftmann@22316
   320
lemmas order_eq_iff = order_class.eq_iff
haftmann@22316
   321
lemmas order_antisym_conv = order_class.antisym_conv
haftmann@22316
   322
lemmas order_less_trans = order_class.less_trans
haftmann@22316
   323
lemmas order_le_less_trans = order_class.le_less_trans
haftmann@22316
   324
lemmas order_less_le_trans = order_class.less_le_trans
haftmann@22316
   325
lemmas order_less_imp_not_less = order_class.less_imp_not_less
haftmann@22316
   326
lemmas order_less_imp_triv = order_class.less_imp_triv
haftmann@22316
   327
lemmas order_less_asym' = order_class.less_asym'
haftmann@22316
   328
haftmann@22384
   329
lemmas linorder_linear = linear
haftmann@22316
   330
lemmas linorder_less_linear = linorder_class.less_linear
haftmann@22316
   331
lemmas linorder_le_less_linear = linorder_class.le_less_linear
haftmann@22316
   332
lemmas linorder_le_cases = linorder_class.le_cases
haftmann@22316
   333
lemmas linorder_not_less = linorder_class.not_less
haftmann@22316
   334
lemmas linorder_not_le = linorder_class.not_le
haftmann@22316
   335
lemmas linorder_neq_iff = linorder_class.neq_iff
haftmann@22316
   336
lemmas linorder_neqE = linorder_class.neqE
haftmann@22316
   337
lemmas linorder_antisym_conv1 = linorder_class.antisym_conv1
haftmann@22316
   338
lemmas linorder_antisym_conv2 = linorder_class.antisym_conv2
haftmann@22316
   339
lemmas linorder_antisym_conv3 = linorder_class.antisym_conv3
paulson@16796
   340
haftmann@23087
   341
lemmas min_le_iff_disj = linorder_class.min_le_iff_disj [folded ord_class.min]
haftmann@23087
   342
lemmas le_max_iff_disj = linorder_class.le_max_iff_disj [folded ord_class.max]
haftmann@23087
   343
lemmas min_less_iff_disj = linorder_class.min_less_iff_disj [folded ord_class.min]
haftmann@23087
   344
lemmas less_max_iff_disj = linorder_class.less_max_iff_disj [folded ord_class.max]
haftmann@23087
   345
lemmas min_less_iff_conj [simp] = linorder_class.min_less_iff_conj [folded ord_class.min]
haftmann@23087
   346
lemmas max_less_iff_conj [simp] = linorder_class.max_less_iff_conj [folded ord_class.max]
haftmann@23087
   347
lemmas split_min = linorder_class.split_min [folded ord_class.min]
haftmann@23087
   348
lemmas split_max = linorder_class.split_max [folded ord_class.max]
haftmann@22916
   349
haftmann@21083
   350
haftmann@21083
   351
subsection {* Reasoning tools setup *}
haftmann@21083
   352
haftmann@21091
   353
ML {*
haftmann@21091
   354
local
haftmann@21091
   355
haftmann@21091
   356
fun decomp_gen sort thy (Trueprop $ t) =
haftmann@21248
   357
  let
haftmann@21248
   358
    fun of_sort t =
haftmann@21248
   359
      let
haftmann@21248
   360
        val T = type_of t
haftmann@21248
   361
      in
haftmann@21091
   362
        (* exclude numeric types: linear arithmetic subsumes transitivity *)
haftmann@21248
   363
        T <> HOLogic.natT andalso T <> HOLogic.intT
haftmann@21248
   364
          andalso T <> HOLogic.realT andalso Sign.of_sort thy (T, sort)
haftmann@21248
   365
      end;
haftmann@22916
   366
    fun dec (Const (@{const_name Not}, _) $ t) = (case dec t
haftmann@21248
   367
          of NONE => NONE
haftmann@21248
   368
           | SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2))
haftmann@22916
   369
      | dec (Const (@{const_name "op ="},  _) $ t1 $ t2) =
haftmann@21248
   370
          if of_sort t1
haftmann@21248
   371
          then SOME (t1, "=", t2)
haftmann@21248
   372
          else NONE
haftmann@22997
   373
      | dec (Const (@{const_name Orderings.less_eq},  _) $ t1 $ t2) =
haftmann@21248
   374
          if of_sort t1
haftmann@21248
   375
          then SOME (t1, "<=", t2)
haftmann@21248
   376
          else NONE
haftmann@22997
   377
      | dec (Const (@{const_name Orderings.less},  _) $ t1 $ t2) =
haftmann@21248
   378
          if of_sort t1
haftmann@21248
   379
          then SOME (t1, "<", t2)
haftmann@21248
   380
          else NONE
haftmann@21248
   381
      | dec _ = NONE;
haftmann@21091
   382
  in dec t end;
haftmann@21091
   383
haftmann@21091
   384
in
haftmann@21091
   385
haftmann@22841
   386
(* sorry - there is no preorder class
haftmann@21248
   387
structure Quasi_Tac = Quasi_Tac_Fun (
haftmann@21248
   388
struct
haftmann@21248
   389
  val le_trans = thm "order_trans";
haftmann@21248
   390
  val le_refl = thm "order_refl";
haftmann@21248
   391
  val eqD1 = thm "order_eq_refl";
haftmann@21248
   392
  val eqD2 = thm "sym" RS thm "order_eq_refl";
haftmann@21248
   393
  val less_reflE = thm "order_less_irrefl" RS thm "notE";
haftmann@21248
   394
  val less_imp_le = thm "order_less_imp_le";
haftmann@21248
   395
  val le_neq_trans = thm "order_le_neq_trans";
haftmann@21248
   396
  val neq_le_trans = thm "order_neq_le_trans";
haftmann@21248
   397
  val less_imp_neq = thm "less_imp_neq";
haftmann@22738
   398
  val decomp_trans = decomp_gen ["Orderings.preorder"];
haftmann@22738
   399
  val decomp_quasi = decomp_gen ["Orderings.preorder"];
haftmann@22841
   400
end);*)
haftmann@21091
   401
haftmann@21091
   402
structure Order_Tac = Order_Tac_Fun (
haftmann@21248
   403
struct
haftmann@21248
   404
  val less_reflE = thm "order_less_irrefl" RS thm "notE";
haftmann@21248
   405
  val le_refl = thm "order_refl";
haftmann@21248
   406
  val less_imp_le = thm "order_less_imp_le";
haftmann@21248
   407
  val not_lessI = thm "linorder_not_less" RS thm "iffD2";
haftmann@21248
   408
  val not_leI = thm "linorder_not_le" RS thm "iffD2";
haftmann@21248
   409
  val not_lessD = thm "linorder_not_less" RS thm "iffD1";
haftmann@21248
   410
  val not_leD = thm "linorder_not_le" RS thm "iffD1";
haftmann@21248
   411
  val eqI = thm "order_antisym";
haftmann@21248
   412
  val eqD1 = thm "order_eq_refl";
haftmann@21248
   413
  val eqD2 = thm "sym" RS thm "order_eq_refl";
haftmann@21248
   414
  val less_trans = thm "order_less_trans";
haftmann@21248
   415
  val less_le_trans = thm "order_less_le_trans";
haftmann@21248
   416
  val le_less_trans = thm "order_le_less_trans";
haftmann@21248
   417
  val le_trans = thm "order_trans";
haftmann@21248
   418
  val le_neq_trans = thm "order_le_neq_trans";
haftmann@21248
   419
  val neq_le_trans = thm "order_neq_le_trans";
haftmann@21248
   420
  val less_imp_neq = thm "less_imp_neq";
haftmann@21248
   421
  val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
haftmann@21248
   422
  val not_sym = thm "not_sym";
haftmann@21248
   423
  val decomp_part = decomp_gen ["Orderings.order"];
haftmann@21248
   424
  val decomp_lin = decomp_gen ["Orderings.linorder"];
haftmann@21248
   425
end);
haftmann@21091
   426
haftmann@21091
   427
end;
haftmann@21091
   428
*}
haftmann@21091
   429
haftmann@21083
   430
setup {*
haftmann@21083
   431
let
haftmann@21083
   432
haftmann@21083
   433
fun prp t thm = (#prop (rep_thm thm) = t);
nipkow@15524
   434
haftmann@21083
   435
fun prove_antisym_le sg ss ((le as Const(_,T)) $ r $ s) =
haftmann@21083
   436
  let val prems = prems_of_ss ss;
haftmann@22916
   437
      val less = Const (@{const_name less}, T);
haftmann@21083
   438
      val t = HOLogic.mk_Trueprop(le $ s $ r);
haftmann@21083
   439
  in case find_first (prp t) prems of
haftmann@21083
   440
       NONE =>
haftmann@21083
   441
         let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s))
haftmann@21083
   442
         in case find_first (prp t) prems of
haftmann@21083
   443
              NONE => NONE
haftmann@22738
   444
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_antisym_conv1}))
haftmann@21083
   445
         end
haftmann@22738
   446
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm order_antisym_conv}))
haftmann@21083
   447
  end
haftmann@21083
   448
  handle THM _ => NONE;
nipkow@15524
   449
haftmann@21083
   450
fun prove_antisym_less sg ss (NotC $ ((less as Const(_,T)) $ r $ s)) =
haftmann@21083
   451
  let val prems = prems_of_ss ss;
haftmann@22916
   452
      val le = Const (@{const_name less_eq}, T);
haftmann@21083
   453
      val t = HOLogic.mk_Trueprop(le $ r $ s);
haftmann@21083
   454
  in case find_first (prp t) prems of
haftmann@21083
   455
       NONE =>
haftmann@21083
   456
         let val t = HOLogic.mk_Trueprop(NotC $ (less $ s $ r))
haftmann@21083
   457
         in case find_first (prp t) prems of
haftmann@21083
   458
              NONE => NONE
haftmann@22738
   459
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_antisym_conv3}))
haftmann@21083
   460
         end
haftmann@22738
   461
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_antisym_conv2}))
haftmann@21083
   462
  end
haftmann@21083
   463
  handle THM _ => NONE;
nipkow@15524
   464
haftmann@21248
   465
fun add_simprocs procs thy =
haftmann@21248
   466
  (Simplifier.change_simpset_of thy (fn ss => ss
haftmann@21248
   467
    addsimprocs (map (fn (name, raw_ts, proc) =>
haftmann@21248
   468
      Simplifier.simproc thy name raw_ts proc)) procs); thy);
haftmann@21248
   469
fun add_solver name tac thy =
haftmann@21248
   470
  (Simplifier.change_simpset_of thy (fn ss => ss addSolver
haftmann@21248
   471
    (mk_solver name (K tac))); thy);
haftmann@21083
   472
haftmann@21083
   473
in
haftmann@21248
   474
  add_simprocs [
haftmann@21248
   475
       ("antisym le", ["(x::'a::order) <= y"], prove_antisym_le),
haftmann@21248
   476
       ("antisym less", ["~ (x::'a::linorder) < y"], prove_antisym_less)
haftmann@21248
   477
     ]
haftmann@21248
   478
  #> add_solver "Trans_linear" Order_Tac.linear_tac
haftmann@21248
   479
  #> add_solver "Trans_partial" Order_Tac.partial_tac
haftmann@21248
   480
  (* Adding the transitivity reasoners also as safe solvers showed a slight
haftmann@21248
   481
     speed up, but the reasoning strength appears to be not higher (at least
haftmann@21248
   482
     no breaking of additional proofs in the entire HOL distribution, as
haftmann@21248
   483
     of 5 March 2004, was observed). *)
haftmann@21083
   484
end
haftmann@21083
   485
*}
nipkow@15524
   486
nipkow@15524
   487
haftmann@21083
   488
subsection {* Bounded quantifiers *}
haftmann@21083
   489
haftmann@21083
   490
syntax
wenzelm@21180
   491
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   492
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   493
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   494
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   495
wenzelm@21180
   496
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3ALL _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   497
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3EX _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   498
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _>=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   499
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _>=_./ _)" [0, 0, 10] 10)
haftmann@21083
   500
haftmann@21083
   501
syntax (xsymbols)
wenzelm@21180
   502
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   503
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   504
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   505
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   506
wenzelm@21180
   507
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   508
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   509
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   510
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   511
haftmann@21083
   512
syntax (HOL)
wenzelm@21180
   513
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   514
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   515
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   516
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3? _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   517
haftmann@21083
   518
syntax (HTML output)
wenzelm@21180
   519
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   520
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   521
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   522
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   523
wenzelm@21180
   524
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   525
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   526
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   527
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   528
haftmann@21083
   529
translations
haftmann@21083
   530
  "ALL x<y. P"   =>  "ALL x. x < y \<longrightarrow> P"
haftmann@21083
   531
  "EX x<y. P"    =>  "EX x. x < y \<and> P"
haftmann@21083
   532
  "ALL x<=y. P"  =>  "ALL x. x <= y \<longrightarrow> P"
haftmann@21083
   533
  "EX x<=y. P"   =>  "EX x. x <= y \<and> P"
haftmann@21083
   534
  "ALL x>y. P"   =>  "ALL x. x > y \<longrightarrow> P"
haftmann@21083
   535
  "EX x>y. P"    =>  "EX x. x > y \<and> P"
haftmann@21083
   536
  "ALL x>=y. P"  =>  "ALL x. x >= y \<longrightarrow> P"
haftmann@21083
   537
  "EX x>=y. P"   =>  "EX x. x >= y \<and> P"
haftmann@21083
   538
haftmann@21083
   539
print_translation {*
haftmann@21083
   540
let
haftmann@22916
   541
  val All_binder = Syntax.binder_name @{const_syntax All};
haftmann@22916
   542
  val Ex_binder = Syntax.binder_name @{const_syntax Ex};
wenzelm@22377
   543
  val impl = @{const_syntax "op -->"};
wenzelm@22377
   544
  val conj = @{const_syntax "op &"};
haftmann@22916
   545
  val less = @{const_syntax less};
haftmann@22916
   546
  val less_eq = @{const_syntax less_eq};
wenzelm@21180
   547
wenzelm@21180
   548
  val trans =
wenzelm@21524
   549
   [((All_binder, impl, less), ("_All_less", "_All_greater")),
wenzelm@21524
   550
    ((All_binder, impl, less_eq), ("_All_less_eq", "_All_greater_eq")),
wenzelm@21524
   551
    ((Ex_binder, conj, less), ("_Ex_less", "_Ex_greater")),
wenzelm@21524
   552
    ((Ex_binder, conj, less_eq), ("_Ex_less_eq", "_Ex_greater_eq"))];
wenzelm@21180
   553
krauss@22344
   554
  fun matches_bound v t = 
krauss@22344
   555
     case t of (Const ("_bound", _) $ Free (v', _)) => (v = v')
krauss@22344
   556
              | _ => false
krauss@22344
   557
  fun contains_var v = Term.exists_subterm (fn Free (x, _) => x = v | _ => false)
krauss@22344
   558
  fun mk v c n P = Syntax.const c $ Syntax.mark_bound v $ n $ P
wenzelm@21180
   559
wenzelm@21180
   560
  fun tr' q = (q,
wenzelm@21180
   561
    fn [Const ("_bound", _) $ Free (v, _), Const (c, _) $ (Const (d, _) $ t $ u) $ P] =>
wenzelm@21180
   562
      (case AList.lookup (op =) trans (q, c, d) of
wenzelm@21180
   563
        NONE => raise Match
wenzelm@21180
   564
      | SOME (l, g) =>
krauss@22344
   565
          if matches_bound v t andalso not (contains_var v u) then mk v l u P
krauss@22344
   566
          else if matches_bound v u andalso not (contains_var v t) then mk v g t P
krauss@22344
   567
          else raise Match)
wenzelm@21180
   568
     | _ => raise Match);
wenzelm@21524
   569
in [tr' All_binder, tr' Ex_binder] end
haftmann@21083
   570
*}
haftmann@21083
   571
haftmann@21083
   572
haftmann@21383
   573
subsection {* Transitivity reasoning *}
haftmann@21383
   574
haftmann@21383
   575
lemma ord_le_eq_trans: "a <= b ==> b = c ==> a <= c"
nipkow@23212
   576
by (rule subst)
haftmann@21383
   577
haftmann@21383
   578
lemma ord_eq_le_trans: "a = b ==> b <= c ==> a <= c"
nipkow@23212
   579
by (rule ssubst)
haftmann@21383
   580
haftmann@21383
   581
lemma ord_less_eq_trans: "a < b ==> b = c ==> a < c"
nipkow@23212
   582
by (rule subst)
haftmann@21383
   583
haftmann@21383
   584
lemma ord_eq_less_trans: "a = b ==> b < c ==> a < c"
nipkow@23212
   585
by (rule ssubst)
haftmann@21383
   586
haftmann@21383
   587
lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>
haftmann@21383
   588
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   589
proof -
haftmann@21383
   590
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   591
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   592
  also assume "f b < c"
haftmann@21383
   593
  finally (order_less_trans) show ?thesis .
haftmann@21383
   594
qed
haftmann@21383
   595
haftmann@21383
   596
lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>
haftmann@21383
   597
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   598
proof -
haftmann@21383
   599
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   600
  assume "a < f b"
haftmann@21383
   601
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383
   602
  finally (order_less_trans) show ?thesis .
haftmann@21383
   603
qed
haftmann@21383
   604
haftmann@21383
   605
lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>
haftmann@21383
   606
  (!!x y. x <= y ==> f x <= f y) ==> f a < c"
haftmann@21383
   607
proof -
haftmann@21383
   608
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   609
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   610
  also assume "f b < c"
haftmann@21383
   611
  finally (order_le_less_trans) show ?thesis .
haftmann@21383
   612
qed
haftmann@21383
   613
haftmann@21383
   614
lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>
haftmann@21383
   615
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   616
proof -
haftmann@21383
   617
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   618
  assume "a <= f b"
haftmann@21383
   619
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383
   620
  finally (order_le_less_trans) show ?thesis .
haftmann@21383
   621
qed
haftmann@21383
   622
haftmann@21383
   623
lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>
haftmann@21383
   624
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   625
proof -
haftmann@21383
   626
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   627
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   628
  also assume "f b <= c"
haftmann@21383
   629
  finally (order_less_le_trans) show ?thesis .
haftmann@21383
   630
qed
haftmann@21383
   631
haftmann@21383
   632
lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>
haftmann@21383
   633
  (!!x y. x <= y ==> f x <= f y) ==> a < f c"
haftmann@21383
   634
proof -
haftmann@21383
   635
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   636
  assume "a < f b"
haftmann@21383
   637
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   638
  finally (order_less_le_trans) show ?thesis .
haftmann@21383
   639
qed
haftmann@21383
   640
haftmann@21383
   641
lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>
haftmann@21383
   642
  (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383
   643
proof -
haftmann@21383
   644
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   645
  assume "a <= f b"
haftmann@21383
   646
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   647
  finally (order_trans) show ?thesis .
haftmann@21383
   648
qed
haftmann@21383
   649
haftmann@21383
   650
lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>
haftmann@21383
   651
  (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383
   652
proof -
haftmann@21383
   653
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   654
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   655
  also assume "f b <= c"
haftmann@21383
   656
  finally (order_trans) show ?thesis .
haftmann@21383
   657
qed
haftmann@21383
   658
haftmann@21383
   659
lemma ord_le_eq_subst: "a <= b ==> f b = c ==>
haftmann@21383
   660
  (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383
   661
proof -
haftmann@21383
   662
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   663
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   664
  also assume "f b = c"
haftmann@21383
   665
  finally (ord_le_eq_trans) show ?thesis .
haftmann@21383
   666
qed
haftmann@21383
   667
haftmann@21383
   668
lemma ord_eq_le_subst: "a = f b ==> b <= c ==>
haftmann@21383
   669
  (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383
   670
proof -
haftmann@21383
   671
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   672
  assume "a = f b"
haftmann@21383
   673
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   674
  finally (ord_eq_le_trans) show ?thesis .
haftmann@21383
   675
qed
haftmann@21383
   676
haftmann@21383
   677
lemma ord_less_eq_subst: "a < b ==> f b = c ==>
haftmann@21383
   678
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   679
proof -
haftmann@21383
   680
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   681
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   682
  also assume "f b = c"
haftmann@21383
   683
  finally (ord_less_eq_trans) show ?thesis .
haftmann@21383
   684
qed
haftmann@21383
   685
haftmann@21383
   686
lemma ord_eq_less_subst: "a = f b ==> b < c ==>
haftmann@21383
   687
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   688
proof -
haftmann@21383
   689
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   690
  assume "a = f b"
haftmann@21383
   691
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383
   692
  finally (ord_eq_less_trans) show ?thesis .
haftmann@21383
   693
qed
haftmann@21383
   694
haftmann@21383
   695
text {*
haftmann@21383
   696
  Note that this list of rules is in reverse order of priorities.
haftmann@21383
   697
*}
haftmann@21383
   698
haftmann@21383
   699
lemmas order_trans_rules [trans] =
haftmann@21383
   700
  order_less_subst2
haftmann@21383
   701
  order_less_subst1
haftmann@21383
   702
  order_le_less_subst2
haftmann@21383
   703
  order_le_less_subst1
haftmann@21383
   704
  order_less_le_subst2
haftmann@21383
   705
  order_less_le_subst1
haftmann@21383
   706
  order_subst2
haftmann@21383
   707
  order_subst1
haftmann@21383
   708
  ord_le_eq_subst
haftmann@21383
   709
  ord_eq_le_subst
haftmann@21383
   710
  ord_less_eq_subst
haftmann@21383
   711
  ord_eq_less_subst
haftmann@21383
   712
  forw_subst
haftmann@21383
   713
  back_subst
haftmann@21383
   714
  rev_mp
haftmann@21383
   715
  mp
haftmann@21383
   716
  order_neq_le_trans
haftmann@21383
   717
  order_le_neq_trans
haftmann@21383
   718
  order_less_trans
haftmann@21383
   719
  order_less_asym'
haftmann@21383
   720
  order_le_less_trans
haftmann@21383
   721
  order_less_le_trans
haftmann@21383
   722
  order_trans
haftmann@21383
   723
  order_antisym
haftmann@21383
   724
  ord_le_eq_trans
haftmann@21383
   725
  ord_eq_le_trans
haftmann@21383
   726
  ord_less_eq_trans
haftmann@21383
   727
  ord_eq_less_trans
haftmann@21383
   728
  trans
haftmann@21383
   729
haftmann@21083
   730
wenzelm@21180
   731
(* FIXME cleanup *)
wenzelm@21180
   732
haftmann@21083
   733
text {* These support proving chains of decreasing inequalities
haftmann@21083
   734
    a >= b >= c ... in Isar proofs. *}
haftmann@21083
   735
haftmann@21083
   736
lemma xt1:
haftmann@21083
   737
  "a = b ==> b > c ==> a > c"
haftmann@21083
   738
  "a > b ==> b = c ==> a > c"
haftmann@21083
   739
  "a = b ==> b >= c ==> a >= c"
haftmann@21083
   740
  "a >= b ==> b = c ==> a >= c"
haftmann@21083
   741
  "(x::'a::order) >= y ==> y >= x ==> x = y"
haftmann@21083
   742
  "(x::'a::order) >= y ==> y >= z ==> x >= z"
haftmann@21083
   743
  "(x::'a::order) > y ==> y >= z ==> x > z"
haftmann@21083
   744
  "(x::'a::order) >= y ==> y > z ==> x > z"
haftmann@21083
   745
  "(a::'a::order) > b ==> b > a ==> ?P"
haftmann@21083
   746
  "(x::'a::order) > y ==> y > z ==> x > z"
haftmann@21083
   747
  "(a::'a::order) >= b ==> a ~= b ==> a > b"
haftmann@21083
   748
  "(a::'a::order) ~= b ==> a >= b ==> a > b"
haftmann@21083
   749
  "a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c" 
haftmann@21083
   750
  "a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   751
  "a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   752
  "a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@21083
   753
by auto
haftmann@21083
   754
haftmann@21083
   755
lemma xt2:
haftmann@21083
   756
  "(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   757
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   758
haftmann@21083
   759
lemma xt3: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==> 
haftmann@21083
   760
    (!!x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@21083
   761
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   762
haftmann@21083
   763
lemma xt4: "(a::'a::order) > f b ==> (b::'b::order) >= c ==>
haftmann@21083
   764
  (!!x y. x >= y ==> f x >= f y) ==> a > f c"
haftmann@21083
   765
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   766
haftmann@21083
   767
lemma xt5: "(a::'a::order) > b ==> (f b::'b::order) >= c==>
haftmann@21083
   768
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   769
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
   770
haftmann@21083
   771
lemma xt6: "(a::'a::order) >= f b ==> b > c ==>
haftmann@21083
   772
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   773
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   774
haftmann@21083
   775
lemma xt7: "(a::'a::order) >= b ==> (f b::'b::order) > c ==>
haftmann@21083
   776
    (!!x y. x >= y ==> f x >= f y) ==> f a > c"
haftmann@21083
   777
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   778
haftmann@21083
   779
lemma xt8: "(a::'a::order) > f b ==> (b::'b::order) > c ==>
haftmann@21083
   780
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   781
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   782
haftmann@21083
   783
lemma xt9: "(a::'a::order) > b ==> (f b::'b::order) > c ==>
haftmann@21083
   784
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   785
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
   786
haftmann@21083
   787
lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9
haftmann@21083
   788
haftmann@21083
   789
(* 
haftmann@21083
   790
  Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands
haftmann@21083
   791
  for the wrong thing in an Isar proof.
haftmann@21083
   792
haftmann@21083
   793
  The extra transitivity rules can be used as follows: 
haftmann@21083
   794
haftmann@21083
   795
lemma "(a::'a::order) > z"
haftmann@21083
   796
proof -
haftmann@21083
   797
  have "a >= b" (is "_ >= ?rhs")
haftmann@21083
   798
    sorry
haftmann@21083
   799
  also have "?rhs >= c" (is "_ >= ?rhs")
haftmann@21083
   800
    sorry
haftmann@21083
   801
  also (xtrans) have "?rhs = d" (is "_ = ?rhs")
haftmann@21083
   802
    sorry
haftmann@21083
   803
  also (xtrans) have "?rhs >= e" (is "_ >= ?rhs")
haftmann@21083
   804
    sorry
haftmann@21083
   805
  also (xtrans) have "?rhs > f" (is "_ > ?rhs")
haftmann@21083
   806
    sorry
haftmann@21083
   807
  also (xtrans) have "?rhs > z"
haftmann@21083
   808
    sorry
haftmann@21083
   809
  finally (xtrans) show ?thesis .
haftmann@21083
   810
qed
haftmann@21083
   811
haftmann@21083
   812
  Alternatively, one can use "declare xtrans [trans]" and then
haftmann@21083
   813
  leave out the "(xtrans)" above.
haftmann@21083
   814
*)
haftmann@21083
   815
haftmann@21546
   816
subsection {* Order on bool *}
haftmann@21546
   817
haftmann@22886
   818
instance bool :: order 
haftmann@21546
   819
  le_bool_def: "P \<le> Q \<equiv> P \<longrightarrow> Q"
haftmann@21546
   820
  less_bool_def: "P < Q \<equiv> P \<le> Q \<and> P \<noteq> Q"
haftmann@22916
   821
  by intro_classes (auto simp add: le_bool_def less_bool_def)
haftmann@21546
   822
haftmann@21546
   823
lemma le_boolI: "(P \<Longrightarrow> Q) \<Longrightarrow> P \<le> Q"
nipkow@23212
   824
by (simp add: le_bool_def)
haftmann@21546
   825
haftmann@21546
   826
lemma le_boolI': "P \<longrightarrow> Q \<Longrightarrow> P \<le> Q"
nipkow@23212
   827
by (simp add: le_bool_def)
haftmann@21546
   828
haftmann@21546
   829
lemma le_boolE: "P \<le> Q \<Longrightarrow> P \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
nipkow@23212
   830
by (simp add: le_bool_def)
haftmann@21546
   831
haftmann@21546
   832
lemma le_boolD: "P \<le> Q \<Longrightarrow> P \<longrightarrow> Q"
nipkow@23212
   833
by (simp add: le_bool_def)
haftmann@21546
   834
haftmann@22348
   835
lemma [code func]:
haftmann@22348
   836
  "False \<le> b \<longleftrightarrow> True"
haftmann@22348
   837
  "True \<le> b \<longleftrightarrow> b"
haftmann@22348
   838
  "False < b \<longleftrightarrow> b"
haftmann@22348
   839
  "True < b \<longleftrightarrow> False"
haftmann@22348
   840
  unfolding le_bool_def less_bool_def by simp_all
haftmann@22348
   841
haftmann@22424
   842
haftmann@21383
   843
subsection {* Monotonicity, syntactic least value operator and min/max *}
haftmann@21083
   844
haftmann@21216
   845
locale mono =
haftmann@21216
   846
  fixes f
haftmann@21216
   847
  assumes mono: "A \<le> B \<Longrightarrow> f A \<le> f B"
haftmann@21216
   848
haftmann@21216
   849
lemmas monoI [intro?] = mono.intro
haftmann@21216
   850
  and monoD [dest?] = mono.mono
haftmann@21083
   851
haftmann@21083
   852
constdefs
haftmann@21083
   853
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
haftmann@21083
   854
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
haftmann@21083
   855
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
haftmann@21083
   856
haftmann@21383
   857
lemma LeastI2_order:
haftmann@21383
   858
  "[| P (x::'a::order);
haftmann@21383
   859
      !!y. P y ==> x <= y;
haftmann@21383
   860
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
haftmann@21383
   861
   ==> Q (Least P)"
nipkow@23212
   862
apply (unfold Least_def)
nipkow@23212
   863
apply (rule theI2)
nipkow@23212
   864
  apply (blast intro: order_antisym)+
nipkow@23212
   865
done
haftmann@21383
   866
haftmann@21383
   867
lemma Least_equality:
nipkow@23212
   868
  "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
nipkow@23212
   869
apply (simp add: Least_def)
nipkow@23212
   870
apply (rule the_equality)
nipkow@23212
   871
apply (auto intro!: order_antisym)
nipkow@23212
   872
done
haftmann@21383
   873
haftmann@21383
   874
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
nipkow@23212
   875
by (simp add: min_def)
haftmann@21383
   876
haftmann@21383
   877
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
nipkow@23212
   878
by (simp add: max_def)
haftmann@21383
   879
haftmann@21383
   880
lemma min_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> min x least = least"
nipkow@23212
   881
apply (simp add: min_def)
nipkow@23212
   882
apply (blast intro: order_antisym)
nipkow@23212
   883
done
haftmann@21383
   884
haftmann@21383
   885
lemma max_leastR: "(\<And>x\<Colon>'a\<Colon>order. least \<le> x) \<Longrightarrow> max x least = x"
nipkow@23212
   886
apply (simp add: max_def)
nipkow@23212
   887
apply (blast intro: order_antisym)
nipkow@23212
   888
done
haftmann@21383
   889
haftmann@21383
   890
lemma min_of_mono:
nipkow@23212
   891
  "(!!x y. (f x <= f y) = (x <= y)) ==> min (f m) (f n) = f (min m n)"
nipkow@23212
   892
by (simp add: min_def)
haftmann@21383
   893
haftmann@21383
   894
lemma max_of_mono:
nipkow@23212
   895
  "(!!x y. (f x <= f y) = (x <= y)) ==> max (f m) (f n) = f (max m n)"
nipkow@23212
   896
by (simp add: max_def)
haftmann@21383
   897
haftmann@22548
   898
haftmann@22548
   899
subsection {* legacy ML bindings *}
wenzelm@21673
   900
wenzelm@21673
   901
ML {*
haftmann@22548
   902
val monoI = @{thm monoI};
haftmann@22886
   903
*}
wenzelm@21673
   904
nipkow@15524
   905
end