src/HOL/Orderings.thy
author hoelzl
Tue Mar 26 12:20:58 2013 +0100 (2013-03-26)
changeset 51526 155263089e7b
parent 51487 f4bfdee99304
child 51546 2e26df807dc7
permissions -rw-r--r--
move SEQ.thy and Lim.thy to Limits.thy
haftmann@28685
     1
(*  Title:      HOL/Orderings.thy
nipkow@15524
     2
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
nipkow@15524
     3
*)
nipkow@15524
     4
haftmann@25614
     5
header {* Abstract orderings *}
nipkow@15524
     6
nipkow@15524
     7
theory Orderings
haftmann@35301
     8
imports HOL
wenzelm@46950
     9
keywords "print_orders" :: diag
nipkow@15524
    10
begin
nipkow@15524
    11
wenzelm@48891
    12
ML_file "~~/src/Provers/order.ML"
wenzelm@48891
    13
ML_file "~~/src/Provers/quasi.ML"  (* FIXME unused? *)
wenzelm@48891
    14
haftmann@51487
    15
subsection {* Abstract ordering *}
haftmann@51487
    16
haftmann@51487
    17
locale ordering =
haftmann@51487
    18
  fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<preceq>" 50)
haftmann@51487
    19
   and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<prec>" 50)
haftmann@51487
    20
  assumes strict_iff_order: "a \<prec> b \<longleftrightarrow> a \<preceq> b \<and> a \<noteq> b"
haftmann@51487
    21
  assumes refl: "a \<preceq> a" -- {* not @{text iff}: makes problems due to multiple (dual) interpretations *}
haftmann@51487
    22
    and antisym: "a \<preceq> b \<Longrightarrow> b \<preceq> a \<Longrightarrow> a = b"
haftmann@51487
    23
    and trans: "a \<preceq> b \<Longrightarrow> b \<preceq> c \<Longrightarrow> a \<preceq> c"
haftmann@51487
    24
begin
haftmann@51487
    25
haftmann@51487
    26
lemma strict_implies_order:
haftmann@51487
    27
  "a \<prec> b \<Longrightarrow> a \<preceq> b"
haftmann@51487
    28
  by (simp add: strict_iff_order)
haftmann@51487
    29
haftmann@51487
    30
lemma strict_implies_not_eq:
haftmann@51487
    31
  "a \<prec> b \<Longrightarrow> a \<noteq> b"
haftmann@51487
    32
  by (simp add: strict_iff_order)
haftmann@51487
    33
haftmann@51487
    34
lemma not_eq_order_implies_strict:
haftmann@51487
    35
  "a \<noteq> b \<Longrightarrow> a \<preceq> b \<Longrightarrow> a \<prec> b"
haftmann@51487
    36
  by (simp add: strict_iff_order)
haftmann@51487
    37
haftmann@51487
    38
lemma order_iff_strict:
haftmann@51487
    39
  "a \<preceq> b \<longleftrightarrow> a \<prec> b \<or> a = b"
haftmann@51487
    40
  by (auto simp add: strict_iff_order refl)
haftmann@51487
    41
haftmann@51487
    42
lemma irrefl: -- {* not @{text iff}: makes problems due to multiple (dual) interpretations *}
haftmann@51487
    43
  "\<not> a \<prec> a"
haftmann@51487
    44
  by (simp add: strict_iff_order)
haftmann@51487
    45
haftmann@51487
    46
lemma asym:
haftmann@51487
    47
  "a \<prec> b \<Longrightarrow> b \<prec> a \<Longrightarrow> False"
haftmann@51487
    48
  by (auto simp add: strict_iff_order intro: antisym)
haftmann@51487
    49
haftmann@51487
    50
lemma strict_trans1:
haftmann@51487
    51
  "a \<preceq> b \<Longrightarrow> b \<prec> c \<Longrightarrow> a \<prec> c"
haftmann@51487
    52
  by (auto simp add: strict_iff_order intro: trans antisym)
haftmann@51487
    53
haftmann@51487
    54
lemma strict_trans2:
haftmann@51487
    55
  "a \<prec> b \<Longrightarrow> b \<preceq> c \<Longrightarrow> a \<prec> c"
haftmann@51487
    56
  by (auto simp add: strict_iff_order intro: trans antisym)
haftmann@51487
    57
haftmann@51487
    58
lemma strict_trans:
haftmann@51487
    59
  "a \<prec> b \<Longrightarrow> b \<prec> c \<Longrightarrow> a \<prec> c"
haftmann@51487
    60
  by (auto intro: strict_trans1 strict_implies_order)
haftmann@51487
    61
haftmann@51487
    62
end
haftmann@51487
    63
haftmann@51487
    64
locale ordering_top = ordering +
haftmann@51487
    65
  fixes top :: "'a"
haftmann@51487
    66
  assumes extremum [simp]: "a \<preceq> top"
haftmann@51487
    67
begin
haftmann@51487
    68
haftmann@51487
    69
lemma extremum_uniqueI:
haftmann@51487
    70
  "top \<preceq> a \<Longrightarrow> a = top"
haftmann@51487
    71
  by (rule antisym) auto
haftmann@51487
    72
haftmann@51487
    73
lemma extremum_unique:
haftmann@51487
    74
  "top \<preceq> a \<longleftrightarrow> a = top"
haftmann@51487
    75
  by (auto intro: antisym)
haftmann@51487
    76
haftmann@51487
    77
lemma extremum_strict [simp]:
haftmann@51487
    78
  "\<not> (top \<prec> a)"
haftmann@51487
    79
  using extremum [of a] by (auto simp add: order_iff_strict intro: asym irrefl)
haftmann@51487
    80
haftmann@51487
    81
lemma not_eq_extremum:
haftmann@51487
    82
  "a \<noteq> top \<longleftrightarrow> a \<prec> top"
haftmann@51487
    83
  by (auto simp add: order_iff_strict intro: not_eq_order_implies_strict extremum)
haftmann@51487
    84
haftmann@51487
    85
end  
haftmann@51487
    86
haftmann@51487
    87
haftmann@35092
    88
subsection {* Syntactic orders *}
haftmann@35092
    89
haftmann@35092
    90
class ord =
haftmann@35092
    91
  fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@35092
    92
    and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
haftmann@35092
    93
begin
haftmann@35092
    94
haftmann@35092
    95
notation
haftmann@35092
    96
  less_eq  ("op <=") and
haftmann@35092
    97
  less_eq  ("(_/ <= _)" [51, 51] 50) and
haftmann@35092
    98
  less  ("op <") and
haftmann@35092
    99
  less  ("(_/ < _)"  [51, 51] 50)
haftmann@35092
   100
  
haftmann@35092
   101
notation (xsymbols)
haftmann@35092
   102
  less_eq  ("op \<le>") and
haftmann@35092
   103
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
haftmann@35092
   104
haftmann@35092
   105
notation (HTML output)
haftmann@35092
   106
  less_eq  ("op \<le>") and
haftmann@35092
   107
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
haftmann@35092
   108
haftmann@35092
   109
abbreviation (input)
haftmann@35092
   110
  greater_eq  (infix ">=" 50) where
haftmann@35092
   111
  "x >= y \<equiv> y <= x"
haftmann@35092
   112
haftmann@35092
   113
notation (input)
haftmann@35092
   114
  greater_eq  (infix "\<ge>" 50)
haftmann@35092
   115
haftmann@35092
   116
abbreviation (input)
haftmann@35092
   117
  greater  (infix ">" 50) where
haftmann@35092
   118
  "x > y \<equiv> y < x"
haftmann@35092
   119
haftmann@35092
   120
end
haftmann@35092
   121
haftmann@35092
   122
haftmann@27682
   123
subsection {* Quasi orders *}
nipkow@15524
   124
haftmann@27682
   125
class preorder = ord +
haftmann@27682
   126
  assumes less_le_not_le: "x < y \<longleftrightarrow> x \<le> y \<and> \<not> (y \<le> x)"
haftmann@25062
   127
  and order_refl [iff]: "x \<le> x"
haftmann@25062
   128
  and order_trans: "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
haftmann@21248
   129
begin
haftmann@21248
   130
nipkow@15524
   131
text {* Reflexivity. *}
nipkow@15524
   132
haftmann@25062
   133
lemma eq_refl: "x = y \<Longrightarrow> x \<le> y"
nipkow@15524
   134
    -- {* This form is useful with the classical reasoner. *}
nipkow@23212
   135
by (erule ssubst) (rule order_refl)
nipkow@15524
   136
haftmann@25062
   137
lemma less_irrefl [iff]: "\<not> x < x"
haftmann@27682
   138
by (simp add: less_le_not_le)
haftmann@27682
   139
haftmann@27682
   140
lemma less_imp_le: "x < y \<Longrightarrow> x \<le> y"
haftmann@27682
   141
unfolding less_le_not_le by blast
haftmann@27682
   142
haftmann@27682
   143
haftmann@27682
   144
text {* Asymmetry. *}
haftmann@27682
   145
haftmann@27682
   146
lemma less_not_sym: "x < y \<Longrightarrow> \<not> (y < x)"
haftmann@27682
   147
by (simp add: less_le_not_le)
haftmann@27682
   148
haftmann@27682
   149
lemma less_asym: "x < y \<Longrightarrow> (\<not> P \<Longrightarrow> y < x) \<Longrightarrow> P"
haftmann@27682
   150
by (drule less_not_sym, erule contrapos_np) simp
haftmann@27682
   151
haftmann@27682
   152
haftmann@27682
   153
text {* Transitivity. *}
haftmann@27682
   154
haftmann@27682
   155
lemma less_trans: "x < y \<Longrightarrow> y < z \<Longrightarrow> x < z"
haftmann@27682
   156
by (auto simp add: less_le_not_le intro: order_trans) 
haftmann@27682
   157
haftmann@27682
   158
lemma le_less_trans: "x \<le> y \<Longrightarrow> y < z \<Longrightarrow> x < z"
haftmann@27682
   159
by (auto simp add: less_le_not_le intro: order_trans) 
haftmann@27682
   160
haftmann@27682
   161
lemma less_le_trans: "x < y \<Longrightarrow> y \<le> z \<Longrightarrow> x < z"
haftmann@27682
   162
by (auto simp add: less_le_not_le intro: order_trans) 
haftmann@27682
   163
haftmann@27682
   164
haftmann@27682
   165
text {* Useful for simplification, but too risky to include by default. *}
haftmann@27682
   166
haftmann@27682
   167
lemma less_imp_not_less: "x < y \<Longrightarrow> (\<not> y < x) \<longleftrightarrow> True"
haftmann@27682
   168
by (blast elim: less_asym)
haftmann@27682
   169
haftmann@27682
   170
lemma less_imp_triv: "x < y \<Longrightarrow> (y < x \<longrightarrow> P) \<longleftrightarrow> True"
haftmann@27682
   171
by (blast elim: less_asym)
haftmann@27682
   172
haftmann@27682
   173
haftmann@27682
   174
text {* Transitivity rules for calculational reasoning *}
haftmann@27682
   175
haftmann@27682
   176
lemma less_asym': "a < b \<Longrightarrow> b < a \<Longrightarrow> P"
haftmann@27682
   177
by (rule less_asym)
haftmann@27682
   178
haftmann@27682
   179
haftmann@27682
   180
text {* Dual order *}
haftmann@27682
   181
haftmann@27682
   182
lemma dual_preorder:
haftmann@36635
   183
  "class.preorder (op \<ge>) (op >)"
haftmann@28823
   184
proof qed (auto simp add: less_le_not_le intro: order_trans)
haftmann@27682
   185
haftmann@27682
   186
end
haftmann@27682
   187
haftmann@27682
   188
haftmann@27682
   189
subsection {* Partial orders *}
haftmann@27682
   190
haftmann@27682
   191
class order = preorder +
haftmann@27682
   192
  assumes antisym: "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
haftmann@27682
   193
begin
haftmann@27682
   194
haftmann@51487
   195
lemma less_le: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> y"
haftmann@51487
   196
  by (auto simp add: less_le_not_le intro: antisym)
haftmann@51487
   197
haftmann@51487
   198
end
haftmann@51487
   199
haftmann@51487
   200
sublocale order < order!: ordering less_eq less
haftmann@51487
   201
  by default (auto intro: antisym order_trans simp add: less_le)
haftmann@27682
   202
haftmann@51487
   203
sublocale order < dual_order!: ordering greater_eq greater
haftmann@51487
   204
  by default (auto intro: antisym order_trans simp add: less_le)
haftmann@51487
   205
haftmann@51487
   206
context order
haftmann@51487
   207
begin
haftmann@51487
   208
haftmann@51487
   209
text {* Reflexivity. *}
nipkow@15524
   210
haftmann@25062
   211
lemma le_less: "x \<le> y \<longleftrightarrow> x < y \<or> x = y"
nipkow@15524
   212
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
nipkow@23212
   213
by (simp add: less_le) blast
nipkow@15524
   214
haftmann@25062
   215
lemma le_imp_less_or_eq: "x \<le> y \<Longrightarrow> x < y \<or> x = y"
nipkow@23212
   216
unfolding less_le by blast
nipkow@15524
   217
haftmann@21329
   218
haftmann@21329
   219
text {* Useful for simplification, but too risky to include by default. *}
haftmann@21329
   220
haftmann@25062
   221
lemma less_imp_not_eq: "x < y \<Longrightarrow> (x = y) \<longleftrightarrow> False"
nipkow@23212
   222
by auto
haftmann@21329
   223
haftmann@25062
   224
lemma less_imp_not_eq2: "x < y \<Longrightarrow> (y = x) \<longleftrightarrow> False"
nipkow@23212
   225
by auto
haftmann@21329
   226
haftmann@21329
   227
haftmann@21329
   228
text {* Transitivity rules for calculational reasoning *}
haftmann@21329
   229
haftmann@25062
   230
lemma neq_le_trans: "a \<noteq> b \<Longrightarrow> a \<le> b \<Longrightarrow> a < b"
nipkow@23212
   231
by (simp add: less_le)
haftmann@21329
   232
haftmann@25062
   233
lemma le_neq_trans: "a \<le> b \<Longrightarrow> a \<noteq> b \<Longrightarrow> a < b"
nipkow@23212
   234
by (simp add: less_le)
haftmann@21329
   235
nipkow@15524
   236
nipkow@15524
   237
text {* Asymmetry. *}
nipkow@15524
   238
haftmann@25062
   239
lemma eq_iff: "x = y \<longleftrightarrow> x \<le> y \<and> y \<le> x"
nipkow@23212
   240
by (blast intro: antisym)
nipkow@15524
   241
haftmann@25062
   242
lemma antisym_conv: "y \<le> x \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
nipkow@23212
   243
by (blast intro: antisym)
nipkow@15524
   244
haftmann@25062
   245
lemma less_imp_neq: "x < y \<Longrightarrow> x \<noteq> y"
nipkow@23212
   246
by (erule contrapos_pn, erule subst, rule less_irrefl)
haftmann@21248
   247
haftmann@21083
   248
haftmann@27107
   249
text {* Least value operator *}
haftmann@27107
   250
haftmann@27299
   251
definition (in ord)
haftmann@27107
   252
  Least :: "('a \<Rightarrow> bool) \<Rightarrow> 'a" (binder "LEAST " 10) where
haftmann@27107
   253
  "Least P = (THE x. P x \<and> (\<forall>y. P y \<longrightarrow> x \<le> y))"
haftmann@27107
   254
haftmann@27107
   255
lemma Least_equality:
haftmann@27107
   256
  assumes "P x"
haftmann@27107
   257
    and "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27107
   258
  shows "Least P = x"
haftmann@27107
   259
unfolding Least_def by (rule the_equality)
haftmann@27107
   260
  (blast intro: assms antisym)+
haftmann@27107
   261
haftmann@27107
   262
lemma LeastI2_order:
haftmann@27107
   263
  assumes "P x"
haftmann@27107
   264
    and "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27107
   265
    and "\<And>x. P x \<Longrightarrow> \<forall>y. P y \<longrightarrow> x \<le> y \<Longrightarrow> Q x"
haftmann@27107
   266
  shows "Q (Least P)"
haftmann@27107
   267
unfolding Least_def by (rule theI2)
haftmann@27107
   268
  (blast intro: assms antisym)+
haftmann@27107
   269
haftmann@27107
   270
haftmann@26014
   271
text {* Dual order *}
haftmann@22916
   272
haftmann@26014
   273
lemma dual_order:
haftmann@36635
   274
  "class.order (op \<ge>) (op >)"
haftmann@27682
   275
by (intro_locales, rule dual_preorder) (unfold_locales, rule antisym)
haftmann@22916
   276
haftmann@21248
   277
end
nipkow@15524
   278
haftmann@21329
   279
haftmann@21329
   280
subsection {* Linear (total) orders *}
haftmann@21329
   281
haftmann@22316
   282
class linorder = order +
haftmann@25207
   283
  assumes linear: "x \<le> y \<or> y \<le> x"
haftmann@21248
   284
begin
haftmann@21248
   285
haftmann@25062
   286
lemma less_linear: "x < y \<or> x = y \<or> y < x"
nipkow@23212
   287
unfolding less_le using less_le linear by blast
haftmann@21248
   288
haftmann@25062
   289
lemma le_less_linear: "x \<le> y \<or> y < x"
nipkow@23212
   290
by (simp add: le_less less_linear)
haftmann@21248
   291
haftmann@21248
   292
lemma le_cases [case_names le ge]:
haftmann@25062
   293
  "(x \<le> y \<Longrightarrow> P) \<Longrightarrow> (y \<le> x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212
   294
using linear by blast
haftmann@21248
   295
haftmann@22384
   296
lemma linorder_cases [case_names less equal greater]:
haftmann@25062
   297
  "(x < y \<Longrightarrow> P) \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> (y < x \<Longrightarrow> P) \<Longrightarrow> P"
nipkow@23212
   298
using less_linear by blast
haftmann@21248
   299
haftmann@25062
   300
lemma not_less: "\<not> x < y \<longleftrightarrow> y \<le> x"
nipkow@23212
   301
apply (simp add: less_le)
nipkow@23212
   302
using linear apply (blast intro: antisym)
nipkow@23212
   303
done
nipkow@23212
   304
nipkow@23212
   305
lemma not_less_iff_gr_or_eq:
haftmann@25062
   306
 "\<not>(x < y) \<longleftrightarrow> (x > y | x = y)"
nipkow@23212
   307
apply(simp add:not_less le_less)
nipkow@23212
   308
apply blast
nipkow@23212
   309
done
nipkow@15524
   310
haftmann@25062
   311
lemma not_le: "\<not> x \<le> y \<longleftrightarrow> y < x"
nipkow@23212
   312
apply (simp add: less_le)
nipkow@23212
   313
using linear apply (blast intro: antisym)
nipkow@23212
   314
done
nipkow@15524
   315
haftmann@25062
   316
lemma neq_iff: "x \<noteq> y \<longleftrightarrow> x < y \<or> y < x"
nipkow@23212
   317
by (cut_tac x = x and y = y in less_linear, auto)
nipkow@15524
   318
haftmann@25062
   319
lemma neqE: "x \<noteq> y \<Longrightarrow> (x < y \<Longrightarrow> R) \<Longrightarrow> (y < x \<Longrightarrow> R) \<Longrightarrow> R"
nipkow@23212
   320
by (simp add: neq_iff) blast
nipkow@15524
   321
haftmann@25062
   322
lemma antisym_conv1: "\<not> x < y \<Longrightarrow> x \<le> y \<longleftrightarrow> x = y"
nipkow@23212
   323
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   324
haftmann@25062
   325
lemma antisym_conv2: "x \<le> y \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
nipkow@23212
   326
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   327
haftmann@25062
   328
lemma antisym_conv3: "\<not> y < x \<Longrightarrow> \<not> x < y \<longleftrightarrow> x = y"
nipkow@23212
   329
by (blast intro: antisym dest: not_less [THEN iffD1])
nipkow@15524
   330
haftmann@25062
   331
lemma leI: "\<not> x < y \<Longrightarrow> y \<le> x"
nipkow@23212
   332
unfolding not_less .
paulson@16796
   333
haftmann@25062
   334
lemma leD: "y \<le> x \<Longrightarrow> \<not> x < y"
nipkow@23212
   335
unfolding not_less .
paulson@16796
   336
paulson@16796
   337
(*FIXME inappropriate name (or delete altogether)*)
haftmann@25062
   338
lemma not_leE: "\<not> y \<le> x \<Longrightarrow> x < y"
nipkow@23212
   339
unfolding not_le .
haftmann@21248
   340
haftmann@22916
   341
haftmann@26014
   342
text {* Dual order *}
haftmann@22916
   343
haftmann@26014
   344
lemma dual_linorder:
haftmann@36635
   345
  "class.linorder (op \<ge>) (op >)"
haftmann@36635
   346
by (rule class.linorder.intro, rule dual_order) (unfold_locales, rule linear)
haftmann@22916
   347
haftmann@22916
   348
haftmann@23881
   349
text {* min/max *}
haftmann@23881
   350
haftmann@27299
   351
definition (in ord) min :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@37767
   352
  "min a b = (if a \<le> b then a else b)"
haftmann@23881
   353
haftmann@27299
   354
definition (in ord) max :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
haftmann@37767
   355
  "max a b = (if a \<le> b then b else a)"
haftmann@22384
   356
haftmann@21383
   357
lemma min_le_iff_disj:
haftmann@25062
   358
  "min x y \<le> z \<longleftrightarrow> x \<le> z \<or> y \<le> z"
nipkow@23212
   359
unfolding min_def using linear by (auto intro: order_trans)
haftmann@21383
   360
haftmann@21383
   361
lemma le_max_iff_disj:
haftmann@25062
   362
  "z \<le> max x y \<longleftrightarrow> z \<le> x \<or> z \<le> y"
nipkow@23212
   363
unfolding max_def using linear by (auto intro: order_trans)
haftmann@21383
   364
haftmann@21383
   365
lemma min_less_iff_disj:
haftmann@25062
   366
  "min x y < z \<longleftrightarrow> x < z \<or> y < z"
nipkow@23212
   367
unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   368
haftmann@21383
   369
lemma less_max_iff_disj:
haftmann@25062
   370
  "z < max x y \<longleftrightarrow> z < x \<or> z < y"
nipkow@23212
   371
unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   372
haftmann@21383
   373
lemma min_less_iff_conj [simp]:
haftmann@25062
   374
  "z < min x y \<longleftrightarrow> z < x \<and> z < y"
nipkow@23212
   375
unfolding min_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   376
haftmann@21383
   377
lemma max_less_iff_conj [simp]:
haftmann@25062
   378
  "max x y < z \<longleftrightarrow> x < z \<and> y < z"
nipkow@23212
   379
unfolding max_def le_less using less_linear by (auto intro: less_trans)
haftmann@21383
   380
blanchet@35828
   381
lemma split_min [no_atp]:
haftmann@25062
   382
  "P (min i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P i) \<and> (\<not> i \<le> j \<longrightarrow> P j)"
nipkow@23212
   383
by (simp add: min_def)
haftmann@21383
   384
blanchet@35828
   385
lemma split_max [no_atp]:
haftmann@25062
   386
  "P (max i j) \<longleftrightarrow> (i \<le> j \<longrightarrow> P j) \<and> (\<not> i \<le> j \<longrightarrow> P i)"
nipkow@23212
   387
by (simp add: max_def)
haftmann@21383
   388
haftmann@21248
   389
end
haftmann@21248
   390
haftmann@23948
   391
haftmann@21083
   392
subsection {* Reasoning tools setup *}
haftmann@21083
   393
haftmann@21091
   394
ML {*
haftmann@21091
   395
ballarin@24641
   396
signature ORDERS =
ballarin@24641
   397
sig
ballarin@24641
   398
  val print_structures: Proof.context -> unit
wenzelm@47432
   399
  val attrib_setup: theory -> theory
wenzelm@32215
   400
  val order_tac: Proof.context -> thm list -> int -> tactic
ballarin@24641
   401
end;
haftmann@21091
   402
ballarin@24641
   403
structure Orders: ORDERS =
haftmann@21248
   404
struct
ballarin@24641
   405
ballarin@24641
   406
(** Theory and context data **)
ballarin@24641
   407
ballarin@24641
   408
fun struct_eq ((s1: string, ts1), (s2, ts2)) =
ballarin@24641
   409
  (s1 = s2) andalso eq_list (op aconv) (ts1, ts2);
ballarin@24641
   410
wenzelm@33519
   411
structure Data = Generic_Data
ballarin@24641
   412
(
ballarin@24641
   413
  type T = ((string * term list) * Order_Tac.less_arith) list;
ballarin@24641
   414
    (* Order structures:
ballarin@24641
   415
       identifier of the structure, list of operations and record of theorems
ballarin@24641
   416
       needed to set up the transitivity reasoner,
ballarin@24641
   417
       identifier and operations identify the structure uniquely. *)
ballarin@24641
   418
  val empty = [];
ballarin@24641
   419
  val extend = I;
wenzelm@33519
   420
  fun merge data = AList.join struct_eq (K fst) data;
ballarin@24641
   421
);
ballarin@24641
   422
ballarin@24641
   423
fun print_structures ctxt =
ballarin@24641
   424
  let
ballarin@24641
   425
    val structs = Data.get (Context.Proof ctxt);
ballarin@24641
   426
    fun pretty_term t = Pretty.block
wenzelm@24920
   427
      [Pretty.quote (Syntax.pretty_term ctxt t), Pretty.brk 1,
ballarin@24641
   428
        Pretty.str "::", Pretty.brk 1,
wenzelm@24920
   429
        Pretty.quote (Syntax.pretty_typ ctxt (type_of t))];
ballarin@24641
   430
    fun pretty_struct ((s, ts), _) = Pretty.block
ballarin@24641
   431
      [Pretty.str s, Pretty.str ":", Pretty.brk 1,
ballarin@24641
   432
       Pretty.enclose "(" ")" (Pretty.breaks (map pretty_term ts))];
ballarin@24641
   433
  in
ballarin@24641
   434
    Pretty.writeln (Pretty.big_list "Order structures:" (map pretty_struct structs))
ballarin@24641
   435
  end;
ballarin@24641
   436
ballarin@24641
   437
ballarin@24641
   438
(** Method **)
haftmann@21091
   439
wenzelm@32215
   440
fun struct_tac ((s, [eq, le, less]), thms) ctxt prems =
ballarin@24641
   441
  let
berghofe@30107
   442
    fun decomp thy (@{const Trueprop} $ t) =
ballarin@24641
   443
      let
ballarin@24641
   444
        fun excluded t =
ballarin@24641
   445
          (* exclude numeric types: linear arithmetic subsumes transitivity *)
ballarin@24641
   446
          let val T = type_of t
ballarin@24641
   447
          in
wenzelm@32960
   448
            T = HOLogic.natT orelse T = HOLogic.intT orelse T = HOLogic.realT
ballarin@24641
   449
          end;
wenzelm@32960
   450
        fun rel (bin_op $ t1 $ t2) =
ballarin@24641
   451
              if excluded t1 then NONE
ballarin@24641
   452
              else if Pattern.matches thy (eq, bin_op) then SOME (t1, "=", t2)
ballarin@24641
   453
              else if Pattern.matches thy (le, bin_op) then SOME (t1, "<=", t2)
ballarin@24641
   454
              else if Pattern.matches thy (less, bin_op) then SOME (t1, "<", t2)
ballarin@24641
   455
              else NONE
wenzelm@32960
   456
          | rel _ = NONE;
wenzelm@32960
   457
        fun dec (Const (@{const_name Not}, _) $ t) = (case rel t
wenzelm@32960
   458
              of NONE => NONE
wenzelm@32960
   459
               | SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2))
ballarin@24741
   460
          | dec x = rel x;
berghofe@30107
   461
      in dec t end
berghofe@30107
   462
      | decomp thy _ = NONE;
ballarin@24641
   463
  in
ballarin@24641
   464
    case s of
wenzelm@32215
   465
      "order" => Order_Tac.partial_tac decomp thms ctxt prems
wenzelm@32215
   466
    | "linorder" => Order_Tac.linear_tac decomp thms ctxt prems
ballarin@24641
   467
    | _ => error ("Unknown kind of order `" ^ s ^ "' encountered in transitivity reasoner.")
ballarin@24641
   468
  end
ballarin@24641
   469
wenzelm@32215
   470
fun order_tac ctxt prems =
wenzelm@32215
   471
  FIRST' (map (fn s => CHANGED o struct_tac s ctxt prems) (Data.get (Context.Proof ctxt)));
ballarin@24641
   472
ballarin@24641
   473
ballarin@24641
   474
(** Attribute **)
ballarin@24641
   475
ballarin@24641
   476
fun add_struct_thm s tag =
ballarin@24641
   477
  Thm.declaration_attribute
ballarin@24641
   478
    (fn thm => Data.map (AList.map_default struct_eq (s, Order_Tac.empty TrueI) (Order_Tac.update tag thm)));
ballarin@24641
   479
fun del_struct s =
ballarin@24641
   480
  Thm.declaration_attribute
ballarin@24641
   481
    (fn _ => Data.map (AList.delete struct_eq s));
ballarin@24641
   482
wenzelm@30722
   483
val attrib_setup =
wenzelm@30722
   484
  Attrib.setup @{binding order}
wenzelm@30722
   485
    (Scan.lift ((Args.add -- Args.name >> (fn (_, s) => SOME s) || Args.del >> K NONE) --|
wenzelm@30722
   486
      Args.colon (* FIXME || Scan.succeed true *) ) -- Scan.lift Args.name --
wenzelm@30722
   487
      Scan.repeat Args.term
wenzelm@30722
   488
      >> (fn ((SOME tag, n), ts) => add_struct_thm (n, ts) tag
wenzelm@30722
   489
           | ((NONE, n), ts) => del_struct (n, ts)))
wenzelm@30722
   490
    "theorems controlling transitivity reasoner";
ballarin@24641
   491
ballarin@24641
   492
ballarin@24641
   493
(** Diagnostic command **)
ballarin@24641
   494
wenzelm@24867
   495
val _ =
wenzelm@46961
   496
  Outer_Syntax.improper_command @{command_spec "print_orders"}
wenzelm@46961
   497
    "print order structures available to transitivity reasoner"
wenzelm@30806
   498
    (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o
wenzelm@30806
   499
        Toplevel.keep (print_structures o Toplevel.context_of)));
ballarin@24641
   500
haftmann@21091
   501
end;
ballarin@24641
   502
haftmann@21091
   503
*}
haftmann@21091
   504
wenzelm@47432
   505
setup Orders.attrib_setup
wenzelm@47432
   506
wenzelm@47432
   507
method_setup order = {*
wenzelm@47432
   508
  Scan.succeed (fn ctxt => SIMPLE_METHOD' (Orders.order_tac ctxt []))
wenzelm@47432
   509
*} "transitivity reasoner"
ballarin@24641
   510
ballarin@24641
   511
ballarin@24641
   512
text {* Declarations to set up transitivity reasoner of partial and linear orders. *}
ballarin@24641
   513
haftmann@25076
   514
context order
haftmann@25076
   515
begin
haftmann@25076
   516
ballarin@24641
   517
(* The type constraint on @{term op =} below is necessary since the operation
ballarin@24641
   518
   is not a parameter of the locale. *)
haftmann@25076
   519
haftmann@27689
   520
declare less_irrefl [THEN notE, order add less_reflE: order "op = :: 'a \<Rightarrow> 'a \<Rightarrow> bool" "op <=" "op <"]
haftmann@27689
   521
  
haftmann@27689
   522
declare order_refl  [order add le_refl: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   523
  
haftmann@27689
   524
declare less_imp_le [order add less_imp_le: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   525
  
haftmann@27689
   526
declare antisym [order add eqI: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   527
haftmann@27689
   528
declare eq_refl [order add eqD1: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   529
haftmann@27689
   530
declare sym [THEN eq_refl, order add eqD2: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   531
haftmann@27689
   532
declare less_trans [order add less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   533
  
haftmann@27689
   534
declare less_le_trans [order add less_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   535
  
haftmann@27689
   536
declare le_less_trans [order add le_less_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   537
haftmann@27689
   538
declare order_trans [order add le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   539
haftmann@27689
   540
declare le_neq_trans [order add le_neq_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   541
haftmann@27689
   542
declare neq_le_trans [order add neq_le_trans: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   543
haftmann@27689
   544
declare less_imp_neq [order add less_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   545
haftmann@27689
   546
declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: order "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   547
haftmann@27689
   548
declare not_sym [order add not_sym: order "op = :: 'a => 'a => bool" "op <=" "op <"]
ballarin@24641
   549
haftmann@25076
   550
end
haftmann@25076
   551
haftmann@25076
   552
context linorder
haftmann@25076
   553
begin
ballarin@24641
   554
haftmann@27689
   555
declare [[order del: order "op = :: 'a => 'a => bool" "op <=" "op <"]]
haftmann@27689
   556
haftmann@27689
   557
declare less_irrefl [THEN notE, order add less_reflE: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   558
haftmann@27689
   559
declare order_refl [order add le_refl: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   560
haftmann@27689
   561
declare less_imp_le [order add less_imp_le: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   562
haftmann@27689
   563
declare not_less [THEN iffD2, order add not_lessI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   564
haftmann@27689
   565
declare not_le [THEN iffD2, order add not_leI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   566
haftmann@27689
   567
declare not_less [THEN iffD1, order add not_lessD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   568
haftmann@27689
   569
declare not_le [THEN iffD1, order add not_leD: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   570
haftmann@27689
   571
declare antisym [order add eqI: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   572
haftmann@27689
   573
declare eq_refl [order add eqD1: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@25076
   574
haftmann@27689
   575
declare sym [THEN eq_refl, order add eqD2: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   576
haftmann@27689
   577
declare less_trans [order add less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   578
haftmann@27689
   579
declare less_le_trans [order add less_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   580
haftmann@27689
   581
declare le_less_trans [order add le_less_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   582
haftmann@27689
   583
declare order_trans [order add le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   584
haftmann@27689
   585
declare le_neq_trans [order add le_neq_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   586
haftmann@27689
   587
declare neq_le_trans [order add neq_le_trans: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   588
haftmann@27689
   589
declare less_imp_neq [order add less_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   590
haftmann@27689
   591
declare eq_neq_eq_imp_neq [order add eq_neq_eq_imp_neq: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
haftmann@27689
   592
haftmann@27689
   593
declare not_sym [order add not_sym: linorder "op = :: 'a => 'a => bool" "op <=" "op <"]
ballarin@24641
   594
haftmann@25076
   595
end
haftmann@25076
   596
ballarin@24641
   597
haftmann@21083
   598
setup {*
haftmann@21083
   599
let
haftmann@21083
   600
wenzelm@44058
   601
fun prp t thm = Thm.prop_of thm = t;  (* FIXME aconv!? *)
nipkow@15524
   602
haftmann@21083
   603
fun prove_antisym_le sg ss ((le as Const(_,T)) $ r $ s) =
wenzelm@43597
   604
  let val prems = Simplifier.prems_of ss;
haftmann@22916
   605
      val less = Const (@{const_name less}, T);
haftmann@21083
   606
      val t = HOLogic.mk_Trueprop(le $ s $ r);
haftmann@21083
   607
  in case find_first (prp t) prems of
haftmann@21083
   608
       NONE =>
haftmann@21083
   609
         let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s))
haftmann@21083
   610
         in case find_first (prp t) prems of
haftmann@21083
   611
              NONE => NONE
haftmann@24422
   612
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv1}))
haftmann@21083
   613
         end
haftmann@24422
   614
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm order_class.antisym_conv}))
haftmann@21083
   615
  end
haftmann@21083
   616
  handle THM _ => NONE;
nipkow@15524
   617
haftmann@21083
   618
fun prove_antisym_less sg ss (NotC $ ((less as Const(_,T)) $ r $ s)) =
wenzelm@43597
   619
  let val prems = Simplifier.prems_of ss;
haftmann@22916
   620
      val le = Const (@{const_name less_eq}, T);
haftmann@21083
   621
      val t = HOLogic.mk_Trueprop(le $ r $ s);
haftmann@21083
   622
  in case find_first (prp t) prems of
haftmann@21083
   623
       NONE =>
haftmann@21083
   624
         let val t = HOLogic.mk_Trueprop(NotC $ (less $ s $ r))
haftmann@21083
   625
         in case find_first (prp t) prems of
haftmann@21083
   626
              NONE => NONE
haftmann@24422
   627
            | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv3}))
haftmann@21083
   628
         end
haftmann@24422
   629
     | SOME thm => SOME(mk_meta_eq(thm RS @{thm linorder_class.antisym_conv2}))
haftmann@21083
   630
  end
haftmann@21083
   631
  handle THM _ => NONE;
nipkow@15524
   632
haftmann@21248
   633
fun add_simprocs procs thy =
wenzelm@42795
   634
  Simplifier.map_simpset_global (fn ss => ss
haftmann@21248
   635
    addsimprocs (map (fn (name, raw_ts, proc) =>
wenzelm@38715
   636
      Simplifier.simproc_global thy name raw_ts proc) procs)) thy;
wenzelm@42795
   637
wenzelm@26496
   638
fun add_solver name tac =
wenzelm@42795
   639
  Simplifier.map_simpset_global (fn ss => ss addSolver
wenzelm@43597
   640
    mk_solver name (fn ss => tac (Simplifier.the_context ss) (Simplifier.prems_of ss)));
haftmann@21083
   641
haftmann@21083
   642
in
haftmann@21248
   643
  add_simprocs [
haftmann@21248
   644
       ("antisym le", ["(x::'a::order) <= y"], prove_antisym_le),
haftmann@21248
   645
       ("antisym less", ["~ (x::'a::linorder) < y"], prove_antisym_less)
haftmann@21248
   646
     ]
ballarin@24641
   647
  #> add_solver "Transitivity" Orders.order_tac
haftmann@21248
   648
  (* Adding the transitivity reasoners also as safe solvers showed a slight
haftmann@21248
   649
     speed up, but the reasoning strength appears to be not higher (at least
haftmann@21248
   650
     no breaking of additional proofs in the entire HOL distribution, as
haftmann@21248
   651
     of 5 March 2004, was observed). *)
haftmann@21083
   652
end
haftmann@21083
   653
*}
nipkow@15524
   654
nipkow@15524
   655
haftmann@21083
   656
subsection {* Bounded quantifiers *}
haftmann@21083
   657
haftmann@21083
   658
syntax
wenzelm@21180
   659
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   660
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   661
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   662
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   663
wenzelm@21180
   664
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3ALL _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   665
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3EX _>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   666
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3ALL _>=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   667
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3EX _>=_./ _)" [0, 0, 10] 10)
haftmann@21083
   668
haftmann@21083
   669
syntax (xsymbols)
wenzelm@21180
   670
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   671
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   672
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   673
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   674
wenzelm@21180
   675
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   676
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   677
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   678
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   679
haftmann@21083
   680
syntax (HOL)
wenzelm@21180
   681
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   682
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   683
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@21180
   684
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3? _<=_./ _)" [0, 0, 10] 10)
haftmann@21083
   685
haftmann@21083
   686
syntax (HTML output)
wenzelm@21180
   687
  "_All_less" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   688
  "_Ex_less" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   689
  "_All_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   690
  "_Ex_less_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
haftmann@21083
   691
wenzelm@21180
   692
  "_All_greater" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   693
  "_Ex_greater" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
wenzelm@21180
   694
  "_All_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
wenzelm@21180
   695
  "_Ex_greater_eq" :: "[idt, 'a, bool] => bool"    ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
haftmann@21083
   696
haftmann@21083
   697
translations
haftmann@21083
   698
  "ALL x<y. P"   =>  "ALL x. x < y \<longrightarrow> P"
haftmann@21083
   699
  "EX x<y. P"    =>  "EX x. x < y \<and> P"
haftmann@21083
   700
  "ALL x<=y. P"  =>  "ALL x. x <= y \<longrightarrow> P"
haftmann@21083
   701
  "EX x<=y. P"   =>  "EX x. x <= y \<and> P"
haftmann@21083
   702
  "ALL x>y. P"   =>  "ALL x. x > y \<longrightarrow> P"
haftmann@21083
   703
  "EX x>y. P"    =>  "EX x. x > y \<and> P"
haftmann@21083
   704
  "ALL x>=y. P"  =>  "ALL x. x >= y \<longrightarrow> P"
haftmann@21083
   705
  "EX x>=y. P"   =>  "EX x. x >= y \<and> P"
haftmann@21083
   706
haftmann@21083
   707
print_translation {*
haftmann@21083
   708
let
wenzelm@42287
   709
  val All_binder = Mixfix.binder_name @{const_syntax All};
wenzelm@42287
   710
  val Ex_binder = Mixfix.binder_name @{const_syntax Ex};
haftmann@38786
   711
  val impl = @{const_syntax HOL.implies};
haftmann@38795
   712
  val conj = @{const_syntax HOL.conj};
haftmann@22916
   713
  val less = @{const_syntax less};
haftmann@22916
   714
  val less_eq = @{const_syntax less_eq};
wenzelm@21180
   715
wenzelm@21180
   716
  val trans =
wenzelm@35115
   717
   [((All_binder, impl, less),
wenzelm@35115
   718
    (@{syntax_const "_All_less"}, @{syntax_const "_All_greater"})),
wenzelm@35115
   719
    ((All_binder, impl, less_eq),
wenzelm@35115
   720
    (@{syntax_const "_All_less_eq"}, @{syntax_const "_All_greater_eq"})),
wenzelm@35115
   721
    ((Ex_binder, conj, less),
wenzelm@35115
   722
    (@{syntax_const "_Ex_less"}, @{syntax_const "_Ex_greater"})),
wenzelm@35115
   723
    ((Ex_binder, conj, less_eq),
wenzelm@35115
   724
    (@{syntax_const "_Ex_less_eq"}, @{syntax_const "_Ex_greater_eq"}))];
wenzelm@21180
   725
wenzelm@35115
   726
  fun matches_bound v t =
wenzelm@35115
   727
    (case t of
wenzelm@35364
   728
      Const (@{syntax_const "_bound"}, _) $ Free (v', _) => v = v'
wenzelm@35115
   729
    | _ => false);
wenzelm@35115
   730
  fun contains_var v = Term.exists_subterm (fn Free (x, _) => x = v | _ => false);
wenzelm@49660
   731
  fun mk x c n P = Syntax.const c $ Syntax_Trans.mark_bound_body x $ n $ P;
wenzelm@21180
   732
wenzelm@21180
   733
  fun tr' q = (q,
wenzelm@49660
   734
    fn [Const (@{syntax_const "_bound"}, _) $ Free (v, T),
wenzelm@35364
   735
        Const (c, _) $ (Const (d, _) $ t $ u) $ P] =>
wenzelm@35115
   736
        (case AList.lookup (op =) trans (q, c, d) of
wenzelm@35115
   737
          NONE => raise Match
wenzelm@35115
   738
        | SOME (l, g) =>
wenzelm@49660
   739
            if matches_bound v t andalso not (contains_var v u) then mk (v, T) l u P
wenzelm@49660
   740
            else if matches_bound v u andalso not (contains_var v t) then mk (v, T) g t P
wenzelm@35115
   741
            else raise Match)
wenzelm@21180
   742
     | _ => raise Match);
wenzelm@21524
   743
in [tr' All_binder, tr' Ex_binder] end
haftmann@21083
   744
*}
haftmann@21083
   745
haftmann@21083
   746
haftmann@21383
   747
subsection {* Transitivity reasoning *}
haftmann@21383
   748
haftmann@25193
   749
context ord
haftmann@25193
   750
begin
haftmann@21383
   751
haftmann@25193
   752
lemma ord_le_eq_trans: "a \<le> b \<Longrightarrow> b = c \<Longrightarrow> a \<le> c"
haftmann@25193
   753
  by (rule subst)
haftmann@21383
   754
haftmann@25193
   755
lemma ord_eq_le_trans: "a = b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"
haftmann@25193
   756
  by (rule ssubst)
haftmann@21383
   757
haftmann@25193
   758
lemma ord_less_eq_trans: "a < b \<Longrightarrow> b = c \<Longrightarrow> a < c"
haftmann@25193
   759
  by (rule subst)
haftmann@25193
   760
haftmann@25193
   761
lemma ord_eq_less_trans: "a = b \<Longrightarrow> b < c \<Longrightarrow> a < c"
haftmann@25193
   762
  by (rule ssubst)
haftmann@25193
   763
haftmann@25193
   764
end
haftmann@21383
   765
haftmann@21383
   766
lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>
haftmann@21383
   767
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   768
proof -
haftmann@21383
   769
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   770
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   771
  also assume "f b < c"
haftmann@34250
   772
  finally (less_trans) show ?thesis .
haftmann@21383
   773
qed
haftmann@21383
   774
haftmann@21383
   775
lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>
haftmann@21383
   776
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   777
proof -
haftmann@21383
   778
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   779
  assume "a < f b"
haftmann@21383
   780
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@34250
   781
  finally (less_trans) show ?thesis .
haftmann@21383
   782
qed
haftmann@21383
   783
haftmann@21383
   784
lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>
haftmann@21383
   785
  (!!x y. x <= y ==> f x <= f y) ==> f a < c"
haftmann@21383
   786
proof -
haftmann@21383
   787
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   788
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   789
  also assume "f b < c"
haftmann@34250
   790
  finally (le_less_trans) show ?thesis .
haftmann@21383
   791
qed
haftmann@21383
   792
haftmann@21383
   793
lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>
haftmann@21383
   794
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   795
proof -
haftmann@21383
   796
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   797
  assume "a <= f b"
haftmann@21383
   798
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@34250
   799
  finally (le_less_trans) show ?thesis .
haftmann@21383
   800
qed
haftmann@21383
   801
haftmann@21383
   802
lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>
haftmann@21383
   803
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   804
proof -
haftmann@21383
   805
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   806
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   807
  also assume "f b <= c"
haftmann@34250
   808
  finally (less_le_trans) show ?thesis .
haftmann@21383
   809
qed
haftmann@21383
   810
haftmann@21383
   811
lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>
haftmann@21383
   812
  (!!x y. x <= y ==> f x <= f y) ==> a < f c"
haftmann@21383
   813
proof -
haftmann@21383
   814
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   815
  assume "a < f b"
haftmann@21383
   816
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@34250
   817
  finally (less_le_trans) show ?thesis .
haftmann@21383
   818
qed
haftmann@21383
   819
haftmann@21383
   820
lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>
haftmann@21383
   821
  (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383
   822
proof -
haftmann@21383
   823
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   824
  assume "a <= f b"
haftmann@21383
   825
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   826
  finally (order_trans) show ?thesis .
haftmann@21383
   827
qed
haftmann@21383
   828
haftmann@21383
   829
lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>
haftmann@21383
   830
  (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383
   831
proof -
haftmann@21383
   832
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   833
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   834
  also assume "f b <= c"
haftmann@21383
   835
  finally (order_trans) show ?thesis .
haftmann@21383
   836
qed
haftmann@21383
   837
haftmann@21383
   838
lemma ord_le_eq_subst: "a <= b ==> f b = c ==>
haftmann@21383
   839
  (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
haftmann@21383
   840
proof -
haftmann@21383
   841
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   842
  assume "a <= b" hence "f a <= f b" by (rule r)
haftmann@21383
   843
  also assume "f b = c"
haftmann@21383
   844
  finally (ord_le_eq_trans) show ?thesis .
haftmann@21383
   845
qed
haftmann@21383
   846
haftmann@21383
   847
lemma ord_eq_le_subst: "a = f b ==> b <= c ==>
haftmann@21383
   848
  (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
haftmann@21383
   849
proof -
haftmann@21383
   850
  assume r: "!!x y. x <= y ==> f x <= f y"
haftmann@21383
   851
  assume "a = f b"
haftmann@21383
   852
  also assume "b <= c" hence "f b <= f c" by (rule r)
haftmann@21383
   853
  finally (ord_eq_le_trans) show ?thesis .
haftmann@21383
   854
qed
haftmann@21383
   855
haftmann@21383
   856
lemma ord_less_eq_subst: "a < b ==> f b = c ==>
haftmann@21383
   857
  (!!x y. x < y ==> f x < f y) ==> f a < c"
haftmann@21383
   858
proof -
haftmann@21383
   859
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   860
  assume "a < b" hence "f a < f b" by (rule r)
haftmann@21383
   861
  also assume "f b = c"
haftmann@21383
   862
  finally (ord_less_eq_trans) show ?thesis .
haftmann@21383
   863
qed
haftmann@21383
   864
haftmann@21383
   865
lemma ord_eq_less_subst: "a = f b ==> b < c ==>
haftmann@21383
   866
  (!!x y. x < y ==> f x < f y) ==> a < f c"
haftmann@21383
   867
proof -
haftmann@21383
   868
  assume r: "!!x y. x < y ==> f x < f y"
haftmann@21383
   869
  assume "a = f b"
haftmann@21383
   870
  also assume "b < c" hence "f b < f c" by (rule r)
haftmann@21383
   871
  finally (ord_eq_less_trans) show ?thesis .
haftmann@21383
   872
qed
haftmann@21383
   873
haftmann@21383
   874
text {*
haftmann@21383
   875
  Note that this list of rules is in reverse order of priorities.
haftmann@21383
   876
*}
haftmann@21383
   877
haftmann@27682
   878
lemmas [trans] =
haftmann@21383
   879
  order_less_subst2
haftmann@21383
   880
  order_less_subst1
haftmann@21383
   881
  order_le_less_subst2
haftmann@21383
   882
  order_le_less_subst1
haftmann@21383
   883
  order_less_le_subst2
haftmann@21383
   884
  order_less_le_subst1
haftmann@21383
   885
  order_subst2
haftmann@21383
   886
  order_subst1
haftmann@21383
   887
  ord_le_eq_subst
haftmann@21383
   888
  ord_eq_le_subst
haftmann@21383
   889
  ord_less_eq_subst
haftmann@21383
   890
  ord_eq_less_subst
haftmann@21383
   891
  forw_subst
haftmann@21383
   892
  back_subst
haftmann@21383
   893
  rev_mp
haftmann@21383
   894
  mp
haftmann@27682
   895
haftmann@27682
   896
lemmas (in order) [trans] =
haftmann@27682
   897
  neq_le_trans
haftmann@27682
   898
  le_neq_trans
haftmann@27682
   899
haftmann@27682
   900
lemmas (in preorder) [trans] =
haftmann@27682
   901
  less_trans
haftmann@27682
   902
  less_asym'
haftmann@27682
   903
  le_less_trans
haftmann@27682
   904
  less_le_trans
haftmann@21383
   905
  order_trans
haftmann@27682
   906
haftmann@27682
   907
lemmas (in order) [trans] =
haftmann@27682
   908
  antisym
haftmann@27682
   909
haftmann@27682
   910
lemmas (in ord) [trans] =
haftmann@27682
   911
  ord_le_eq_trans
haftmann@27682
   912
  ord_eq_le_trans
haftmann@27682
   913
  ord_less_eq_trans
haftmann@27682
   914
  ord_eq_less_trans
haftmann@27682
   915
haftmann@27682
   916
lemmas [trans] =
haftmann@27682
   917
  trans
haftmann@27682
   918
haftmann@27682
   919
lemmas order_trans_rules =
haftmann@27682
   920
  order_less_subst2
haftmann@27682
   921
  order_less_subst1
haftmann@27682
   922
  order_le_less_subst2
haftmann@27682
   923
  order_le_less_subst1
haftmann@27682
   924
  order_less_le_subst2
haftmann@27682
   925
  order_less_le_subst1
haftmann@27682
   926
  order_subst2
haftmann@27682
   927
  order_subst1
haftmann@27682
   928
  ord_le_eq_subst
haftmann@27682
   929
  ord_eq_le_subst
haftmann@27682
   930
  ord_less_eq_subst
haftmann@27682
   931
  ord_eq_less_subst
haftmann@27682
   932
  forw_subst
haftmann@27682
   933
  back_subst
haftmann@27682
   934
  rev_mp
haftmann@27682
   935
  mp
haftmann@27682
   936
  neq_le_trans
haftmann@27682
   937
  le_neq_trans
haftmann@27682
   938
  less_trans
haftmann@27682
   939
  less_asym'
haftmann@27682
   940
  le_less_trans
haftmann@27682
   941
  less_le_trans
haftmann@27682
   942
  order_trans
haftmann@27682
   943
  antisym
haftmann@21383
   944
  ord_le_eq_trans
haftmann@21383
   945
  ord_eq_le_trans
haftmann@21383
   946
  ord_less_eq_trans
haftmann@21383
   947
  ord_eq_less_trans
haftmann@21383
   948
  trans
haftmann@21383
   949
haftmann@21083
   950
text {* These support proving chains of decreasing inequalities
haftmann@21083
   951
    a >= b >= c ... in Isar proofs. *}
haftmann@21083
   952
blanchet@45221
   953
lemma xt1 [no_atp]:
haftmann@21083
   954
  "a = b ==> b > c ==> a > c"
haftmann@21083
   955
  "a > b ==> b = c ==> a > c"
haftmann@21083
   956
  "a = b ==> b >= c ==> a >= c"
haftmann@21083
   957
  "a >= b ==> b = c ==> a >= c"
haftmann@21083
   958
  "(x::'a::order) >= y ==> y >= x ==> x = y"
haftmann@21083
   959
  "(x::'a::order) >= y ==> y >= z ==> x >= z"
haftmann@21083
   960
  "(x::'a::order) > y ==> y >= z ==> x > z"
haftmann@21083
   961
  "(x::'a::order) >= y ==> y > z ==> x > z"
wenzelm@23417
   962
  "(a::'a::order) > b ==> b > a ==> P"
haftmann@21083
   963
  "(x::'a::order) > y ==> y > z ==> x > z"
haftmann@21083
   964
  "(a::'a::order) >= b ==> a ~= b ==> a > b"
haftmann@21083
   965
  "(a::'a::order) ~= b ==> a >= b ==> a > b"
haftmann@21083
   966
  "a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c" 
haftmann@21083
   967
  "a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   968
  "a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   969
  "a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@25076
   970
  by auto
haftmann@21083
   971
blanchet@45221
   972
lemma xt2 [no_atp]:
haftmann@21083
   973
  "(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c"
haftmann@21083
   974
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   975
blanchet@45221
   976
lemma xt3 [no_atp]: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==>
haftmann@21083
   977
    (!!x y. x >= y ==> f x >= f y) ==> f a >= c"
haftmann@21083
   978
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   979
blanchet@45221
   980
lemma xt4 [no_atp]: "(a::'a::order) > f b ==> (b::'b::order) >= c ==>
haftmann@21083
   981
  (!!x y. x >= y ==> f x >= f y) ==> a > f c"
haftmann@21083
   982
by (subgoal_tac "f b >= f c", force, force)
haftmann@21083
   983
blanchet@45221
   984
lemma xt5 [no_atp]: "(a::'a::order) > b ==> (f b::'b::order) >= c==>
haftmann@21083
   985
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
   986
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
   987
blanchet@45221
   988
lemma xt6 [no_atp]: "(a::'a::order) >= f b ==> b > c ==>
haftmann@21083
   989
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   990
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   991
blanchet@45221
   992
lemma xt7 [no_atp]: "(a::'a::order) >= b ==> (f b::'b::order) > c ==>
haftmann@21083
   993
    (!!x y. x >= y ==> f x >= f y) ==> f a > c"
haftmann@21083
   994
by (subgoal_tac "f a >= f b", force, force)
haftmann@21083
   995
blanchet@45221
   996
lemma xt8 [no_atp]: "(a::'a::order) > f b ==> (b::'b::order) > c ==>
haftmann@21083
   997
    (!!x y. x > y ==> f x > f y) ==> a > f c"
haftmann@21083
   998
by (subgoal_tac "f b > f c", force, force)
haftmann@21083
   999
blanchet@45221
  1000
lemma xt9 [no_atp]: "(a::'a::order) > b ==> (f b::'b::order) > c ==>
haftmann@21083
  1001
    (!!x y. x > y ==> f x > f y) ==> f a > c"
haftmann@21083
  1002
by (subgoal_tac "f a > f b", force, force)
haftmann@21083
  1003
blanchet@45221
  1004
lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9 [no_atp]
haftmann@21083
  1005
haftmann@21083
  1006
(* 
haftmann@21083
  1007
  Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands
haftmann@21083
  1008
  for the wrong thing in an Isar proof.
haftmann@21083
  1009
haftmann@21083
  1010
  The extra transitivity rules can be used as follows: 
haftmann@21083
  1011
haftmann@21083
  1012
lemma "(a::'a::order) > z"
haftmann@21083
  1013
proof -
haftmann@21083
  1014
  have "a >= b" (is "_ >= ?rhs")
haftmann@21083
  1015
    sorry
haftmann@21083
  1016
  also have "?rhs >= c" (is "_ >= ?rhs")
haftmann@21083
  1017
    sorry
haftmann@21083
  1018
  also (xtrans) have "?rhs = d" (is "_ = ?rhs")
haftmann@21083
  1019
    sorry
haftmann@21083
  1020
  also (xtrans) have "?rhs >= e" (is "_ >= ?rhs")
haftmann@21083
  1021
    sorry
haftmann@21083
  1022
  also (xtrans) have "?rhs > f" (is "_ > ?rhs")
haftmann@21083
  1023
    sorry
haftmann@21083
  1024
  also (xtrans) have "?rhs > z"
haftmann@21083
  1025
    sorry
haftmann@21083
  1026
  finally (xtrans) show ?thesis .
haftmann@21083
  1027
qed
haftmann@21083
  1028
haftmann@21083
  1029
  Alternatively, one can use "declare xtrans [trans]" and then
haftmann@21083
  1030
  leave out the "(xtrans)" above.
haftmann@21083
  1031
*)
haftmann@21083
  1032
haftmann@23881
  1033
haftmann@23881
  1034
subsection {* Monotonicity, least value operator and min/max *}
haftmann@21083
  1035
haftmann@25076
  1036
context order
haftmann@25076
  1037
begin
haftmann@25076
  1038
haftmann@30298
  1039
definition mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool" where
haftmann@25076
  1040
  "mono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<le> f y)"
haftmann@25076
  1041
haftmann@25076
  1042
lemma monoI [intro?]:
haftmann@25076
  1043
  fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@25076
  1044
  shows "(\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y) \<Longrightarrow> mono f"
haftmann@25076
  1045
  unfolding mono_def by iprover
haftmann@21216
  1046
haftmann@25076
  1047
lemma monoD [dest?]:
haftmann@25076
  1048
  fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@25076
  1049
  shows "mono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
haftmann@25076
  1050
  unfolding mono_def by iprover
haftmann@25076
  1051
haftmann@51263
  1052
lemma monoE:
haftmann@51263
  1053
  fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@51263
  1054
  assumes "mono f"
haftmann@51263
  1055
  assumes "x \<le> y"
haftmann@51263
  1056
  obtains "f x \<le> f y"
haftmann@51263
  1057
proof
haftmann@51263
  1058
  from assms show "f x \<le> f y" by (simp add: mono_def)
haftmann@51263
  1059
qed
haftmann@51263
  1060
haftmann@30298
  1061
definition strict_mono :: "('a \<Rightarrow> 'b\<Colon>order) \<Rightarrow> bool" where
haftmann@30298
  1062
  "strict_mono f \<longleftrightarrow> (\<forall>x y. x < y \<longrightarrow> f x < f y)"
haftmann@30298
  1063
haftmann@30298
  1064
lemma strict_monoI [intro?]:
haftmann@30298
  1065
  assumes "\<And>x y. x < y \<Longrightarrow> f x < f y"
haftmann@30298
  1066
  shows "strict_mono f"
haftmann@30298
  1067
  using assms unfolding strict_mono_def by auto
haftmann@30298
  1068
haftmann@30298
  1069
lemma strict_monoD [dest?]:
haftmann@30298
  1070
  "strict_mono f \<Longrightarrow> x < y \<Longrightarrow> f x < f y"
haftmann@30298
  1071
  unfolding strict_mono_def by auto
haftmann@30298
  1072
haftmann@30298
  1073
lemma strict_mono_mono [dest?]:
haftmann@30298
  1074
  assumes "strict_mono f"
haftmann@30298
  1075
  shows "mono f"
haftmann@30298
  1076
proof (rule monoI)
haftmann@30298
  1077
  fix x y
haftmann@30298
  1078
  assume "x \<le> y"
haftmann@30298
  1079
  show "f x \<le> f y"
haftmann@30298
  1080
  proof (cases "x = y")
haftmann@30298
  1081
    case True then show ?thesis by simp
haftmann@30298
  1082
  next
haftmann@30298
  1083
    case False with `x \<le> y` have "x < y" by simp
haftmann@30298
  1084
    with assms strict_monoD have "f x < f y" by auto
haftmann@30298
  1085
    then show ?thesis by simp
haftmann@30298
  1086
  qed
haftmann@30298
  1087
qed
haftmann@30298
  1088
haftmann@25076
  1089
end
haftmann@25076
  1090
haftmann@25076
  1091
context linorder
haftmann@25076
  1092
begin
haftmann@25076
  1093
haftmann@51263
  1094
lemma mono_invE:
haftmann@51263
  1095
  fixes f :: "'a \<Rightarrow> 'b\<Colon>order"
haftmann@51263
  1096
  assumes "mono f"
haftmann@51263
  1097
  assumes "f x < f y"
haftmann@51263
  1098
  obtains "x \<le> y"
haftmann@51263
  1099
proof
haftmann@51263
  1100
  show "x \<le> y"
haftmann@51263
  1101
  proof (rule ccontr)
haftmann@51263
  1102
    assume "\<not> x \<le> y"
haftmann@51263
  1103
    then have "y \<le> x" by simp
haftmann@51263
  1104
    with `mono f` obtain "f y \<le> f x" by (rule monoE)
haftmann@51263
  1105
    with `f x < f y` show False by simp
haftmann@51263
  1106
  qed
haftmann@51263
  1107
qed
haftmann@51263
  1108
haftmann@30298
  1109
lemma strict_mono_eq:
haftmann@30298
  1110
  assumes "strict_mono f"
haftmann@30298
  1111
  shows "f x = f y \<longleftrightarrow> x = y"
haftmann@30298
  1112
proof
haftmann@30298
  1113
  assume "f x = f y"
haftmann@30298
  1114
  show "x = y" proof (cases x y rule: linorder_cases)
haftmann@30298
  1115
    case less with assms strict_monoD have "f x < f y" by auto
haftmann@30298
  1116
    with `f x = f y` show ?thesis by simp
haftmann@30298
  1117
  next
haftmann@30298
  1118
    case equal then show ?thesis .
haftmann@30298
  1119
  next
haftmann@30298
  1120
    case greater with assms strict_monoD have "f y < f x" by auto
haftmann@30298
  1121
    with `f x = f y` show ?thesis by simp
haftmann@30298
  1122
  qed
haftmann@30298
  1123
qed simp
haftmann@30298
  1124
haftmann@30298
  1125
lemma strict_mono_less_eq:
haftmann@30298
  1126
  assumes "strict_mono f"
haftmann@30298
  1127
  shows "f x \<le> f y \<longleftrightarrow> x \<le> y"
haftmann@30298
  1128
proof
haftmann@30298
  1129
  assume "x \<le> y"
haftmann@30298
  1130
  with assms strict_mono_mono monoD show "f x \<le> f y" by auto
haftmann@30298
  1131
next
haftmann@30298
  1132
  assume "f x \<le> f y"
haftmann@30298
  1133
  show "x \<le> y" proof (rule ccontr)
haftmann@30298
  1134
    assume "\<not> x \<le> y" then have "y < x" by simp
haftmann@30298
  1135
    with assms strict_monoD have "f y < f x" by auto
haftmann@30298
  1136
    with `f x \<le> f y` show False by simp
haftmann@30298
  1137
  qed
haftmann@30298
  1138
qed
haftmann@30298
  1139
  
haftmann@30298
  1140
lemma strict_mono_less:
haftmann@30298
  1141
  assumes "strict_mono f"
haftmann@30298
  1142
  shows "f x < f y \<longleftrightarrow> x < y"
haftmann@30298
  1143
  using assms
haftmann@30298
  1144
    by (auto simp add: less_le Orderings.less_le strict_mono_eq strict_mono_less_eq)
haftmann@30298
  1145
haftmann@25076
  1146
lemma min_of_mono:
haftmann@25076
  1147
  fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"
wenzelm@25377
  1148
  shows "mono f \<Longrightarrow> min (f m) (f n) = f (min m n)"
haftmann@25076
  1149
  by (auto simp: mono_def Orderings.min_def min_def intro: Orderings.antisym)
haftmann@25076
  1150
haftmann@25076
  1151
lemma max_of_mono:
haftmann@25076
  1152
  fixes f :: "'a \<Rightarrow> 'b\<Colon>linorder"
wenzelm@25377
  1153
  shows "mono f \<Longrightarrow> max (f m) (f n) = f (max m n)"
haftmann@25076
  1154
  by (auto simp: mono_def Orderings.max_def max_def intro: Orderings.antisym)
haftmann@25076
  1155
haftmann@25076
  1156
end
haftmann@21083
  1157
noschinl@45931
  1158
lemma min_absorb1: "x \<le> y \<Longrightarrow> min x y = x"
nipkow@23212
  1159
by (simp add: min_def)
haftmann@21383
  1160
noschinl@45931
  1161
lemma max_absorb2: "x \<le> y ==> max x y = y"
nipkow@23212
  1162
by (simp add: max_def)
haftmann@21383
  1163
noschinl@45931
  1164
lemma min_absorb2: "(y\<Colon>'a\<Colon>order) \<le> x \<Longrightarrow> min x y = y"
noschinl@45931
  1165
by (simp add:min_def)
noschinl@45893
  1166
noschinl@45931
  1167
lemma max_absorb1: "(y\<Colon>'a\<Colon>order) \<le> x \<Longrightarrow> max x y = x"
noschinl@45893
  1168
by (simp add: max_def)
noschinl@45893
  1169
noschinl@45893
  1170
haftmann@21383
  1171
haftmann@43813
  1172
subsection {* (Unique) top and bottom elements *}
haftmann@28685
  1173
haftmann@43813
  1174
class bot = order +
haftmann@43853
  1175
  fixes bot :: 'a ("\<bottom>")
haftmann@51487
  1176
  assumes bot_least: "\<bottom> \<le> a"
haftmann@51487
  1177
haftmann@51487
  1178
sublocale bot < bot!: ordering_top greater_eq greater bot
haftmann@51487
  1179
proof
haftmann@51487
  1180
qed (fact bot_least)
haftmann@51487
  1181
haftmann@51487
  1182
context bot
haftmann@43814
  1183
begin
haftmann@43814
  1184
haftmann@43853
  1185
lemma le_bot:
haftmann@43853
  1186
  "a \<le> \<bottom> \<Longrightarrow> a = \<bottom>"
haftmann@51487
  1187
  by (fact bot.extremum_uniqueI)
haftmann@43853
  1188
haftmann@43816
  1189
lemma bot_unique:
haftmann@43853
  1190
  "a \<le> \<bottom> \<longleftrightarrow> a = \<bottom>"
haftmann@51487
  1191
  by (fact bot.extremum_unique)
haftmann@43853
  1192
haftmann@51487
  1193
lemma not_less_bot:
haftmann@51487
  1194
  "\<not> a < \<bottom>"
haftmann@51487
  1195
  by (fact bot.extremum_strict)
haftmann@43816
  1196
haftmann@43814
  1197
lemma bot_less:
haftmann@43853
  1198
  "a \<noteq> \<bottom> \<longleftrightarrow> \<bottom> < a"
haftmann@51487
  1199
  by (fact bot.not_eq_extremum)
haftmann@43814
  1200
haftmann@43814
  1201
end
haftmann@41082
  1202
haftmann@43813
  1203
class top = order +
haftmann@43853
  1204
  fixes top :: 'a ("\<top>")
haftmann@51487
  1205
  assumes top_greatest: "a \<le> \<top>"
haftmann@51487
  1206
haftmann@51487
  1207
sublocale top < top!: ordering_top less_eq less top
haftmann@51487
  1208
proof
haftmann@51487
  1209
qed (fact top_greatest)
haftmann@51487
  1210
haftmann@51487
  1211
context top
haftmann@43814
  1212
begin
haftmann@43814
  1213
haftmann@43853
  1214
lemma top_le:
haftmann@43853
  1215
  "\<top> \<le> a \<Longrightarrow> a = \<top>"
haftmann@51487
  1216
  by (fact top.extremum_uniqueI)
haftmann@43853
  1217
haftmann@43816
  1218
lemma top_unique:
haftmann@43853
  1219
  "\<top> \<le> a \<longleftrightarrow> a = \<top>"
haftmann@51487
  1220
  by (fact top.extremum_unique)
haftmann@43853
  1221
haftmann@51487
  1222
lemma not_top_less:
haftmann@51487
  1223
  "\<not> \<top> < a"
haftmann@51487
  1224
  by (fact top.extremum_strict)
haftmann@43816
  1225
haftmann@43814
  1226
lemma less_top:
haftmann@43853
  1227
  "a \<noteq> \<top> \<longleftrightarrow> a < \<top>"
haftmann@51487
  1228
  by (fact top.not_eq_extremum)
haftmann@43814
  1229
haftmann@43814
  1230
end
haftmann@28685
  1231
haftmann@28685
  1232
haftmann@27823
  1233
subsection {* Dense orders *}
haftmann@27823
  1234
hoelzl@51329
  1235
class inner_dense_order = order +
hoelzl@51329
  1236
  assumes dense: "x < y \<Longrightarrow> (\<exists>z. x < z \<and> z < y)"
hoelzl@51329
  1237
hoelzl@51329
  1238
class inner_dense_linorder = linorder + inner_dense_order
hoelzl@35579
  1239
begin
haftmann@27823
  1240
hoelzl@35579
  1241
lemma dense_le:
hoelzl@35579
  1242
  fixes y z :: 'a
hoelzl@35579
  1243
  assumes "\<And>x. x < y \<Longrightarrow> x \<le> z"
hoelzl@35579
  1244
  shows "y \<le> z"
hoelzl@35579
  1245
proof (rule ccontr)
hoelzl@35579
  1246
  assume "\<not> ?thesis"
hoelzl@35579
  1247
  hence "z < y" by simp
hoelzl@35579
  1248
  from dense[OF this]
hoelzl@35579
  1249
  obtain x where "x < y" and "z < x" by safe
hoelzl@35579
  1250
  moreover have "x \<le> z" using assms[OF `x < y`] .
hoelzl@35579
  1251
  ultimately show False by auto
hoelzl@35579
  1252
qed
hoelzl@35579
  1253
hoelzl@35579
  1254
lemma dense_le_bounded:
hoelzl@35579
  1255
  fixes x y z :: 'a
hoelzl@35579
  1256
  assumes "x < y"
hoelzl@35579
  1257
  assumes *: "\<And>w. \<lbrakk> x < w ; w < y \<rbrakk> \<Longrightarrow> w \<le> z"
hoelzl@35579
  1258
  shows "y \<le> z"
hoelzl@35579
  1259
proof (rule dense_le)
hoelzl@35579
  1260
  fix w assume "w < y"
hoelzl@35579
  1261
  from dense[OF `x < y`] obtain u where "x < u" "u < y" by safe
hoelzl@35579
  1262
  from linear[of u w]
hoelzl@35579
  1263
  show "w \<le> z"
hoelzl@35579
  1264
  proof (rule disjE)
hoelzl@35579
  1265
    assume "u \<le> w"
hoelzl@35579
  1266
    from less_le_trans[OF `x < u` `u \<le> w`] `w < y`
hoelzl@35579
  1267
    show "w \<le> z" by (rule *)
hoelzl@35579
  1268
  next
hoelzl@35579
  1269
    assume "w \<le> u"
hoelzl@35579
  1270
    from `w \<le> u` *[OF `x < u` `u < y`]
hoelzl@35579
  1271
    show "w \<le> z" by (rule order_trans)
hoelzl@35579
  1272
  qed
hoelzl@35579
  1273
qed
hoelzl@35579
  1274
hoelzl@51329
  1275
lemma dense_ge:
hoelzl@51329
  1276
  fixes y z :: 'a
hoelzl@51329
  1277
  assumes "\<And>x. z < x \<Longrightarrow> y \<le> x"
hoelzl@51329
  1278
  shows "y \<le> z"
hoelzl@51329
  1279
proof (rule ccontr)
hoelzl@51329
  1280
  assume "\<not> ?thesis"
hoelzl@51329
  1281
  hence "z < y" by simp
hoelzl@51329
  1282
  from dense[OF this]
hoelzl@51329
  1283
  obtain x where "x < y" and "z < x" by safe
hoelzl@51329
  1284
  moreover have "y \<le> x" using assms[OF `z < x`] .
hoelzl@51329
  1285
  ultimately show False by auto
hoelzl@51329
  1286
qed
hoelzl@51329
  1287
hoelzl@51329
  1288
lemma dense_ge_bounded:
hoelzl@51329
  1289
  fixes x y z :: 'a
hoelzl@51329
  1290
  assumes "z < x"
hoelzl@51329
  1291
  assumes *: "\<And>w. \<lbrakk> z < w ; w < x \<rbrakk> \<Longrightarrow> y \<le> w"
hoelzl@51329
  1292
  shows "y \<le> z"
hoelzl@51329
  1293
proof (rule dense_ge)
hoelzl@51329
  1294
  fix w assume "z < w"
hoelzl@51329
  1295
  from dense[OF `z < x`] obtain u where "z < u" "u < x" by safe
hoelzl@51329
  1296
  from linear[of u w]
hoelzl@51329
  1297
  show "y \<le> w"
hoelzl@51329
  1298
  proof (rule disjE)
hoelzl@51329
  1299
    assume "w \<le> u"
hoelzl@51329
  1300
    from `z < w` le_less_trans[OF `w \<le> u` `u < x`]
hoelzl@51329
  1301
    show "y \<le> w" by (rule *)
hoelzl@51329
  1302
  next
hoelzl@51329
  1303
    assume "u \<le> w"
hoelzl@51329
  1304
    from *[OF `z < u` `u < x`] `u \<le> w`
hoelzl@51329
  1305
    show "y \<le> w" by (rule order_trans)
hoelzl@51329
  1306
  qed
hoelzl@51329
  1307
qed
hoelzl@51329
  1308
hoelzl@35579
  1309
end
haftmann@27823
  1310
hoelzl@51329
  1311
class no_top = order + 
hoelzl@51329
  1312
  assumes gt_ex: "\<exists>y. x < y"
hoelzl@51329
  1313
hoelzl@51329
  1314
class no_bot = order + 
hoelzl@51329
  1315
  assumes lt_ex: "\<exists>y. y < x"
hoelzl@51329
  1316
hoelzl@51329
  1317
class dense_linorder = inner_dense_linorder + no_top + no_bot
hoelzl@51329
  1318
haftmann@27823
  1319
subsection {* Wellorders *}
haftmann@27823
  1320
haftmann@27823
  1321
class wellorder = linorder +
haftmann@27823
  1322
  assumes less_induct [case_names less]: "(\<And>x. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P a"
haftmann@27823
  1323
begin
haftmann@27823
  1324
haftmann@27823
  1325
lemma wellorder_Least_lemma:
haftmann@27823
  1326
  fixes k :: 'a
haftmann@27823
  1327
  assumes "P k"
haftmann@34250
  1328
  shows LeastI: "P (LEAST x. P x)" and Least_le: "(LEAST x. P x) \<le> k"
haftmann@27823
  1329
proof -
haftmann@27823
  1330
  have "P (LEAST x. P x) \<and> (LEAST x. P x) \<le> k"
haftmann@27823
  1331
  using assms proof (induct k rule: less_induct)
haftmann@27823
  1332
    case (less x) then have "P x" by simp
haftmann@27823
  1333
    show ?case proof (rule classical)
haftmann@27823
  1334
      assume assm: "\<not> (P (LEAST a. P a) \<and> (LEAST a. P a) \<le> x)"
haftmann@27823
  1335
      have "\<And>y. P y \<Longrightarrow> x \<le> y"
haftmann@27823
  1336
      proof (rule classical)
haftmann@27823
  1337
        fix y
hoelzl@38705
  1338
        assume "P y" and "\<not> x \<le> y"
haftmann@27823
  1339
        with less have "P (LEAST a. P a)" and "(LEAST a. P a) \<le> y"
haftmann@27823
  1340
          by (auto simp add: not_le)
haftmann@27823
  1341
        with assm have "x < (LEAST a. P a)" and "(LEAST a. P a) \<le> y"
haftmann@27823
  1342
          by auto
haftmann@27823
  1343
        then show "x \<le> y" by auto
haftmann@27823
  1344
      qed
haftmann@27823
  1345
      with `P x` have Least: "(LEAST a. P a) = x"
haftmann@27823
  1346
        by (rule Least_equality)
haftmann@27823
  1347
      with `P x` show ?thesis by simp
haftmann@27823
  1348
    qed
haftmann@27823
  1349
  qed
haftmann@27823
  1350
  then show "P (LEAST x. P x)" and "(LEAST x. P x) \<le> k" by auto
haftmann@27823
  1351
qed
haftmann@27823
  1352
haftmann@27823
  1353
-- "The following 3 lemmas are due to Brian Huffman"
haftmann@27823
  1354
lemma LeastI_ex: "\<exists>x. P x \<Longrightarrow> P (Least P)"
haftmann@27823
  1355
  by (erule exE) (erule LeastI)
haftmann@27823
  1356
haftmann@27823
  1357
lemma LeastI2:
haftmann@27823
  1358
  "P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"
haftmann@27823
  1359
  by (blast intro: LeastI)
haftmann@27823
  1360
haftmann@27823
  1361
lemma LeastI2_ex:
haftmann@27823
  1362
  "\<exists>a. P a \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> Q (Least P)"
haftmann@27823
  1363
  by (blast intro: LeastI_ex)
haftmann@27823
  1364
hoelzl@38705
  1365
lemma LeastI2_wellorder:
hoelzl@38705
  1366
  assumes "P a"
hoelzl@38705
  1367
  and "\<And>a. \<lbrakk> P a; \<forall>b. P b \<longrightarrow> a \<le> b \<rbrakk> \<Longrightarrow> Q a"
hoelzl@38705
  1368
  shows "Q (Least P)"
hoelzl@38705
  1369
proof (rule LeastI2_order)
hoelzl@38705
  1370
  show "P (Least P)" using `P a` by (rule LeastI)
hoelzl@38705
  1371
next
hoelzl@38705
  1372
  fix y assume "P y" thus "Least P \<le> y" by (rule Least_le)
hoelzl@38705
  1373
next
hoelzl@38705
  1374
  fix x assume "P x" "\<forall>y. P y \<longrightarrow> x \<le> y" thus "Q x" by (rule assms(2))
hoelzl@38705
  1375
qed
hoelzl@38705
  1376
haftmann@27823
  1377
lemma not_less_Least: "k < (LEAST x. P x) \<Longrightarrow> \<not> P k"
haftmann@27823
  1378
apply (simp (no_asm_use) add: not_le [symmetric])
haftmann@27823
  1379
apply (erule contrapos_nn)
haftmann@27823
  1380
apply (erule Least_le)
haftmann@27823
  1381
done
haftmann@27823
  1382
hoelzl@38705
  1383
end
haftmann@27823
  1384
haftmann@28685
  1385
haftmann@46631
  1386
subsection {* Order on @{typ bool} *}
haftmann@28685
  1387
huffman@45262
  1388
instantiation bool :: "{bot, top, linorder}"
haftmann@28685
  1389
begin
haftmann@28685
  1390
haftmann@28685
  1391
definition
haftmann@41080
  1392
  le_bool_def [simp]: "P \<le> Q \<longleftrightarrow> P \<longrightarrow> Q"
haftmann@28685
  1393
haftmann@28685
  1394
definition
haftmann@41080
  1395
  [simp]: "(P\<Colon>bool) < Q \<longleftrightarrow> \<not> P \<and> Q"
haftmann@28685
  1396
haftmann@28685
  1397
definition
haftmann@46631
  1398
  [simp]: "\<bottom> \<longleftrightarrow> False"
haftmann@28685
  1399
haftmann@28685
  1400
definition
haftmann@46631
  1401
  [simp]: "\<top> \<longleftrightarrow> True"
haftmann@28685
  1402
haftmann@28685
  1403
instance proof
haftmann@41080
  1404
qed auto
haftmann@28685
  1405
nipkow@15524
  1406
end
haftmann@28685
  1407
haftmann@28685
  1408
lemma le_boolI: "(P \<Longrightarrow> Q) \<Longrightarrow> P \<le> Q"
haftmann@41080
  1409
  by simp
haftmann@28685
  1410
haftmann@28685
  1411
lemma le_boolI': "P \<longrightarrow> Q \<Longrightarrow> P \<le> Q"
haftmann@41080
  1412
  by simp
haftmann@28685
  1413
haftmann@28685
  1414
lemma le_boolE: "P \<le> Q \<Longrightarrow> P \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@41080
  1415
  by simp
haftmann@28685
  1416
haftmann@28685
  1417
lemma le_boolD: "P \<le> Q \<Longrightarrow> P \<longrightarrow> Q"
haftmann@41080
  1418
  by simp
haftmann@32899
  1419
haftmann@46631
  1420
lemma bot_boolE: "\<bottom> \<Longrightarrow> P"
haftmann@41080
  1421
  by simp
haftmann@32899
  1422
haftmann@46631
  1423
lemma top_boolI: \<top>
haftmann@41080
  1424
  by simp
haftmann@28685
  1425
haftmann@28685
  1426
lemma [code]:
haftmann@28685
  1427
  "False \<le> b \<longleftrightarrow> True"
haftmann@28685
  1428
  "True \<le> b \<longleftrightarrow> b"
haftmann@28685
  1429
  "False < b \<longleftrightarrow> b"
haftmann@28685
  1430
  "True < b \<longleftrightarrow> False"
haftmann@41080
  1431
  by simp_all
haftmann@28685
  1432
haftmann@28685
  1433
haftmann@46631
  1434
subsection {* Order on @{typ "_ \<Rightarrow> _"} *}
haftmann@28685
  1435
haftmann@28685
  1436
instantiation "fun" :: (type, ord) ord
haftmann@28685
  1437
begin
haftmann@28685
  1438
haftmann@28685
  1439
definition
haftmann@37767
  1440
  le_fun_def: "f \<le> g \<longleftrightarrow> (\<forall>x. f x \<le> g x)"
haftmann@28685
  1441
haftmann@28685
  1442
definition
haftmann@41080
  1443
  "(f\<Colon>'a \<Rightarrow> 'b) < g \<longleftrightarrow> f \<le> g \<and> \<not> (g \<le> f)"
haftmann@28685
  1444
haftmann@28685
  1445
instance ..
haftmann@28685
  1446
haftmann@28685
  1447
end
haftmann@28685
  1448
haftmann@28685
  1449
instance "fun" :: (type, preorder) preorder proof
haftmann@28685
  1450
qed (auto simp add: le_fun_def less_fun_def
huffman@44921
  1451
  intro: order_trans antisym)
haftmann@28685
  1452
haftmann@28685
  1453
instance "fun" :: (type, order) order proof
huffman@44921
  1454
qed (auto simp add: le_fun_def intro: antisym)
haftmann@28685
  1455
haftmann@41082
  1456
instantiation "fun" :: (type, bot) bot
haftmann@41082
  1457
begin
haftmann@41082
  1458
haftmann@41082
  1459
definition
haftmann@46631
  1460
  "\<bottom> = (\<lambda>x. \<bottom>)"
haftmann@41082
  1461
haftmann@49769
  1462
lemma bot_apply [simp, code]:
haftmann@46631
  1463
  "\<bottom> x = \<bottom>"
haftmann@41082
  1464
  by (simp add: bot_fun_def)
haftmann@41082
  1465
haftmann@41082
  1466
instance proof
noschinl@46884
  1467
qed (simp add: le_fun_def)
haftmann@41082
  1468
haftmann@41082
  1469
end
haftmann@41082
  1470
haftmann@28685
  1471
instantiation "fun" :: (type, top) top
haftmann@28685
  1472
begin
haftmann@28685
  1473
haftmann@28685
  1474
definition
haftmann@46631
  1475
  [no_atp]: "\<top> = (\<lambda>x. \<top>)"
haftmann@28685
  1476
haftmann@49769
  1477
lemma top_apply [simp, code]:
haftmann@46631
  1478
  "\<top> x = \<top>"
haftmann@41080
  1479
  by (simp add: top_fun_def)
haftmann@41080
  1480
haftmann@28685
  1481
instance proof
noschinl@46884
  1482
qed (simp add: le_fun_def)
haftmann@28685
  1483
haftmann@28685
  1484
end
haftmann@28685
  1485
haftmann@28685
  1486
lemma le_funI: "(\<And>x. f x \<le> g x) \<Longrightarrow> f \<le> g"
haftmann@28685
  1487
  unfolding le_fun_def by simp
haftmann@28685
  1488
haftmann@28685
  1489
lemma le_funE: "f \<le> g \<Longrightarrow> (f x \<le> g x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@28685
  1490
  unfolding le_fun_def by simp
haftmann@28685
  1491
haftmann@28685
  1492
lemma le_funD: "f \<le> g \<Longrightarrow> f x \<le> g x"
haftmann@28685
  1493
  unfolding le_fun_def by simp
haftmann@28685
  1494
haftmann@34250
  1495
haftmann@46631
  1496
subsection {* Order on unary and binary predicates *}
haftmann@46631
  1497
haftmann@46631
  1498
lemma predicate1I:
haftmann@46631
  1499
  assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"
haftmann@46631
  1500
  shows "P \<le> Q"
haftmann@46631
  1501
  apply (rule le_funI)
haftmann@46631
  1502
  apply (rule le_boolI)
haftmann@46631
  1503
  apply (rule PQ)
haftmann@46631
  1504
  apply assumption
haftmann@46631
  1505
  done
haftmann@46631
  1506
haftmann@46631
  1507
lemma predicate1D:
haftmann@46631
  1508
  "P \<le> Q \<Longrightarrow> P x \<Longrightarrow> Q x"
haftmann@46631
  1509
  apply (erule le_funE)
haftmann@46631
  1510
  apply (erule le_boolE)
haftmann@46631
  1511
  apply assumption+
haftmann@46631
  1512
  done
haftmann@46631
  1513
haftmann@46631
  1514
lemma rev_predicate1D:
haftmann@46631
  1515
  "P x \<Longrightarrow> P \<le> Q \<Longrightarrow> Q x"
haftmann@46631
  1516
  by (rule predicate1D)
haftmann@46631
  1517
haftmann@46631
  1518
lemma predicate2I:
haftmann@46631
  1519
  assumes PQ: "\<And>x y. P x y \<Longrightarrow> Q x y"
haftmann@46631
  1520
  shows "P \<le> Q"
haftmann@46631
  1521
  apply (rule le_funI)+
haftmann@46631
  1522
  apply (rule le_boolI)
haftmann@46631
  1523
  apply (rule PQ)
haftmann@46631
  1524
  apply assumption
haftmann@46631
  1525
  done
haftmann@46631
  1526
haftmann@46631
  1527
lemma predicate2D:
haftmann@46631
  1528
  "P \<le> Q \<Longrightarrow> P x y \<Longrightarrow> Q x y"
haftmann@46631
  1529
  apply (erule le_funE)+
haftmann@46631
  1530
  apply (erule le_boolE)
haftmann@46631
  1531
  apply assumption+
haftmann@46631
  1532
  done
haftmann@46631
  1533
haftmann@46631
  1534
lemma rev_predicate2D:
haftmann@46631
  1535
  "P x y \<Longrightarrow> P \<le> Q \<Longrightarrow> Q x y"
haftmann@46631
  1536
  by (rule predicate2D)
haftmann@46631
  1537
haftmann@46631
  1538
lemma bot1E [no_atp]: "\<bottom> x \<Longrightarrow> P"
haftmann@46631
  1539
  by (simp add: bot_fun_def)
haftmann@46631
  1540
haftmann@46631
  1541
lemma bot2E: "\<bottom> x y \<Longrightarrow> P"
haftmann@46631
  1542
  by (simp add: bot_fun_def)
haftmann@46631
  1543
haftmann@46631
  1544
lemma top1I: "\<top> x"
haftmann@46631
  1545
  by (simp add: top_fun_def)
haftmann@46631
  1546
haftmann@46631
  1547
lemma top2I: "\<top> x y"
haftmann@46631
  1548
  by (simp add: top_fun_def)
haftmann@46631
  1549
haftmann@46631
  1550
haftmann@34250
  1551
subsection {* Name duplicates *}
haftmann@34250
  1552
haftmann@34250
  1553
lemmas order_eq_refl = preorder_class.eq_refl
haftmann@34250
  1554
lemmas order_less_irrefl = preorder_class.less_irrefl
haftmann@34250
  1555
lemmas order_less_imp_le = preorder_class.less_imp_le
haftmann@34250
  1556
lemmas order_less_not_sym = preorder_class.less_not_sym
haftmann@34250
  1557
lemmas order_less_asym = preorder_class.less_asym
haftmann@34250
  1558
lemmas order_less_trans = preorder_class.less_trans
haftmann@34250
  1559
lemmas order_le_less_trans = preorder_class.le_less_trans
haftmann@34250
  1560
lemmas order_less_le_trans = preorder_class.less_le_trans
haftmann@34250
  1561
lemmas order_less_imp_not_less = preorder_class.less_imp_not_less
haftmann@34250
  1562
lemmas order_less_imp_triv = preorder_class.less_imp_triv
haftmann@34250
  1563
lemmas order_less_asym' = preorder_class.less_asym'
haftmann@34250
  1564
haftmann@34250
  1565
lemmas order_less_le = order_class.less_le
haftmann@34250
  1566
lemmas order_le_less = order_class.le_less
haftmann@34250
  1567
lemmas order_le_imp_less_or_eq = order_class.le_imp_less_or_eq
haftmann@34250
  1568
lemmas order_less_imp_not_eq = order_class.less_imp_not_eq
haftmann@34250
  1569
lemmas order_less_imp_not_eq2 = order_class.less_imp_not_eq2
haftmann@34250
  1570
lemmas order_neq_le_trans = order_class.neq_le_trans
haftmann@34250
  1571
lemmas order_le_neq_trans = order_class.le_neq_trans
haftmann@34250
  1572
lemmas order_antisym = order_class.antisym
haftmann@34250
  1573
lemmas order_eq_iff = order_class.eq_iff
haftmann@34250
  1574
lemmas order_antisym_conv = order_class.antisym_conv
haftmann@34250
  1575
haftmann@34250
  1576
lemmas linorder_linear = linorder_class.linear
haftmann@34250
  1577
lemmas linorder_less_linear = linorder_class.less_linear
haftmann@34250
  1578
lemmas linorder_le_less_linear = linorder_class.le_less_linear
haftmann@34250
  1579
lemmas linorder_le_cases = linorder_class.le_cases
haftmann@34250
  1580
lemmas linorder_not_less = linorder_class.not_less
haftmann@34250
  1581
lemmas linorder_not_le = linorder_class.not_le
haftmann@34250
  1582
lemmas linorder_neq_iff = linorder_class.neq_iff
haftmann@34250
  1583
lemmas linorder_neqE = linorder_class.neqE
haftmann@34250
  1584
lemmas linorder_antisym_conv1 = linorder_class.antisym_conv1
haftmann@34250
  1585
lemmas linorder_antisym_conv2 = linorder_class.antisym_conv2
haftmann@34250
  1586
lemmas linorder_antisym_conv3 = linorder_class.antisym_conv3
haftmann@34250
  1587
haftmann@28685
  1588
end
haftmann@51487
  1589