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