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