src/HOL/Conditionally_Complete_Lattices.thy
author blanchet
Tue Nov 07 15:16:42 2017 +0100 (19 months ago)
changeset 67022 49309fe530fd
parent 65466 b0f89998c2a1
child 67091 1393c2340eec
permissions -rw-r--r--
more robust parsing for THF proofs (esp. polymorphic Leo-III proofs)
wenzelm@52265
     1
(*  Title:      HOL/Conditionally_Complete_Lattices.thy
hoelzl@51518
     2
    Author:     Amine Chaieb and L C Paulson, University of Cambridge
hoelzl@51643
     3
    Author:     Johannes Hölzl, TU München
hoelzl@54258
     4
    Author:     Luke S. Serafin, Carnegie Mellon University
hoelzl@51518
     5
*)
paulson@33269
     6
wenzelm@60758
     7
section \<open>Conditionally-complete Lattices\<close>
paulson@33269
     8
hoelzl@51773
     9
theory Conditionally_Complete_Lattices
hoelzl@63331
    10
imports Finite_Set Lattices_Big Set_Interval
paulson@33269
    11
begin
paulson@33269
    12
haftmann@65466
    13
context linorder
haftmann@65466
    14
begin
haftmann@65466
    15
  
haftmann@65466
    16
lemma Sup_fin_eq_Max:
haftmann@65466
    17
  "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup_fin X = Max X"
hoelzl@51475
    18
  by (induct X rule: finite_ne_induct) (simp_all add: sup_max)
hoelzl@51475
    19
haftmann@65466
    20
lemma Inf_fin_eq_Min:
haftmann@65466
    21
  "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf_fin X = Min X"
hoelzl@51475
    22
  by (induct X rule: finite_ne_induct) (simp_all add: inf_min)
hoelzl@51475
    23
haftmann@65466
    24
end
haftmann@65466
    25
hoelzl@54258
    26
context preorder
hoelzl@54258
    27
begin
hoelzl@54258
    28
hoelzl@54258
    29
definition "bdd_above A \<longleftrightarrow> (\<exists>M. \<forall>x \<in> A. x \<le> M)"
hoelzl@54258
    30
definition "bdd_below A \<longleftrightarrow> (\<exists>m. \<forall>x \<in> A. m \<le> x)"
hoelzl@54258
    31
hoelzl@54258
    32
lemma bdd_aboveI[intro]: "(\<And>x. x \<in> A \<Longrightarrow> x \<le> M) \<Longrightarrow> bdd_above A"
hoelzl@54258
    33
  by (auto simp: bdd_above_def)
hoelzl@54258
    34
hoelzl@54258
    35
lemma bdd_belowI[intro]: "(\<And>x. x \<in> A \<Longrightarrow> m \<le> x) \<Longrightarrow> bdd_below A"
hoelzl@54258
    36
  by (auto simp: bdd_below_def)
hoelzl@54258
    37
hoelzl@54263
    38
lemma bdd_aboveI2: "(\<And>x. x \<in> A \<Longrightarrow> f x \<le> M) \<Longrightarrow> bdd_above (f`A)"
hoelzl@54263
    39
  by force
hoelzl@54263
    40
hoelzl@54263
    41
lemma bdd_belowI2: "(\<And>x. x \<in> A \<Longrightarrow> m \<le> f x) \<Longrightarrow> bdd_below (f`A)"
hoelzl@54263
    42
  by force
hoelzl@54263
    43
hoelzl@54258
    44
lemma bdd_above_empty [simp, intro]: "bdd_above {}"
hoelzl@54258
    45
  unfolding bdd_above_def by auto
hoelzl@54258
    46
hoelzl@54258
    47
lemma bdd_below_empty [simp, intro]: "bdd_below {}"
hoelzl@54258
    48
  unfolding bdd_below_def by auto
hoelzl@54258
    49
hoelzl@54258
    50
lemma bdd_above_mono: "bdd_above B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> bdd_above A"
hoelzl@54258
    51
  by (metis (full_types) bdd_above_def order_class.le_neq_trans psubsetD)
hoelzl@54258
    52
hoelzl@54258
    53
lemma bdd_below_mono: "bdd_below B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> bdd_below A"
hoelzl@54258
    54
  by (metis bdd_below_def order_class.le_neq_trans psubsetD)
hoelzl@54258
    55
hoelzl@54258
    56
lemma bdd_above_Int1 [simp]: "bdd_above A \<Longrightarrow> bdd_above (A \<inter> B)"
hoelzl@54258
    57
  using bdd_above_mono by auto
hoelzl@54258
    58
hoelzl@54258
    59
lemma bdd_above_Int2 [simp]: "bdd_above B \<Longrightarrow> bdd_above (A \<inter> B)"
hoelzl@54258
    60
  using bdd_above_mono by auto
hoelzl@54258
    61
hoelzl@54258
    62
lemma bdd_below_Int1 [simp]: "bdd_below A \<Longrightarrow> bdd_below (A \<inter> B)"
hoelzl@54258
    63
  using bdd_below_mono by auto
hoelzl@54258
    64
hoelzl@54258
    65
lemma bdd_below_Int2 [simp]: "bdd_below B \<Longrightarrow> bdd_below (A \<inter> B)"
hoelzl@54258
    66
  using bdd_below_mono by auto
hoelzl@54258
    67
hoelzl@54258
    68
lemma bdd_above_Ioo [simp, intro]: "bdd_above {a <..< b}"
hoelzl@54258
    69
  by (auto simp add: bdd_above_def intro!: exI[of _ b] less_imp_le)
hoelzl@54258
    70
hoelzl@54258
    71
lemma bdd_above_Ico [simp, intro]: "bdd_above {a ..< b}"
hoelzl@54258
    72
  by (auto simp add: bdd_above_def intro!: exI[of _ b] less_imp_le)
hoelzl@54258
    73
hoelzl@54258
    74
lemma bdd_above_Iio [simp, intro]: "bdd_above {..< b}"
hoelzl@54258
    75
  by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
hoelzl@54258
    76
hoelzl@54258
    77
lemma bdd_above_Ioc [simp, intro]: "bdd_above {a <.. b}"
hoelzl@54258
    78
  by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
hoelzl@54258
    79
hoelzl@54258
    80
lemma bdd_above_Icc [simp, intro]: "bdd_above {a .. b}"
hoelzl@54258
    81
  by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
hoelzl@54258
    82
hoelzl@54258
    83
lemma bdd_above_Iic [simp, intro]: "bdd_above {.. b}"
hoelzl@54258
    84
  by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
hoelzl@54258
    85
hoelzl@54258
    86
lemma bdd_below_Ioo [simp, intro]: "bdd_below {a <..< b}"
hoelzl@54258
    87
  by (auto simp add: bdd_below_def intro!: exI[of _ a] less_imp_le)
hoelzl@54258
    88
hoelzl@54258
    89
lemma bdd_below_Ioc [simp, intro]: "bdd_below {a <.. b}"
hoelzl@54258
    90
  by (auto simp add: bdd_below_def intro!: exI[of _ a] less_imp_le)
hoelzl@54258
    91
hoelzl@54258
    92
lemma bdd_below_Ioi [simp, intro]: "bdd_below {a <..}"
hoelzl@54258
    93
  by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
hoelzl@54258
    94
hoelzl@54258
    95
lemma bdd_below_Ico [simp, intro]: "bdd_below {a ..< b}"
hoelzl@54258
    96
  by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
hoelzl@54258
    97
hoelzl@54258
    98
lemma bdd_below_Icc [simp, intro]: "bdd_below {a .. b}"
hoelzl@54258
    99
  by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
hoelzl@54258
   100
hoelzl@54258
   101
lemma bdd_below_Ici [simp, intro]: "bdd_below {a ..}"
hoelzl@54258
   102
  by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
hoelzl@54258
   103
hoelzl@54258
   104
end
hoelzl@54258
   105
hoelzl@54261
   106
lemma (in order_top) bdd_above_top[simp, intro!]: "bdd_above A"
hoelzl@54261
   107
  by (rule bdd_aboveI[of _ top]) simp
hoelzl@54261
   108
hoelzl@54261
   109
lemma (in order_bot) bdd_above_bot[simp, intro!]: "bdd_below A"
hoelzl@54261
   110
  by (rule bdd_belowI[of _ bot]) simp
hoelzl@54261
   111
hoelzl@59452
   112
lemma bdd_above_image_mono: "mono f \<Longrightarrow> bdd_above A \<Longrightarrow> bdd_above (f`A)"
hoelzl@59452
   113
  by (auto simp: bdd_above_def mono_def)
hoelzl@59452
   114
hoelzl@59452
   115
lemma bdd_below_image_mono: "mono f \<Longrightarrow> bdd_below A \<Longrightarrow> bdd_below (f`A)"
hoelzl@59452
   116
  by (auto simp: bdd_below_def mono_def)
hoelzl@63331
   117
hoelzl@59452
   118
lemma bdd_above_image_antimono: "antimono f \<Longrightarrow> bdd_below A \<Longrightarrow> bdd_above (f`A)"
hoelzl@59452
   119
  by (auto simp: bdd_above_def bdd_below_def antimono_def)
hoelzl@54262
   120
hoelzl@59452
   121
lemma bdd_below_image_antimono: "antimono f \<Longrightarrow> bdd_above A \<Longrightarrow> bdd_below (f`A)"
hoelzl@59452
   122
  by (auto simp: bdd_above_def bdd_below_def antimono_def)
hoelzl@59452
   123
hoelzl@59452
   124
lemma
hoelzl@54262
   125
  fixes X :: "'a::ordered_ab_group_add set"
hoelzl@59452
   126
  shows bdd_above_uminus[simp]: "bdd_above (uminus ` X) \<longleftrightarrow> bdd_below X"
hoelzl@59452
   127
    and bdd_below_uminus[simp]: "bdd_below (uminus ` X) \<longleftrightarrow> bdd_above X"
hoelzl@59452
   128
  using bdd_above_image_antimono[of uminus X] bdd_below_image_antimono[of uminus "uminus`X"]
hoelzl@59452
   129
  using bdd_below_image_antimono[of uminus X] bdd_above_image_antimono[of uminus "uminus`X"]
hoelzl@59452
   130
  by (auto simp: antimono_def image_image)
hoelzl@54262
   131
hoelzl@54258
   132
context lattice
hoelzl@54258
   133
begin
hoelzl@54258
   134
hoelzl@54258
   135
lemma bdd_above_insert [simp]: "bdd_above (insert a A) = bdd_above A"
hoelzl@54258
   136
  by (auto simp: bdd_above_def intro: le_supI2 sup_ge1)
hoelzl@54258
   137
hoelzl@54258
   138
lemma bdd_below_insert [simp]: "bdd_below (insert a A) = bdd_below A"
hoelzl@54258
   139
  by (auto simp: bdd_below_def intro: le_infI2 inf_le1)
hoelzl@54258
   140
hoelzl@54258
   141
lemma bdd_finite [simp]:
hoelzl@54258
   142
  assumes "finite A" shows bdd_above_finite: "bdd_above A" and bdd_below_finite: "bdd_below A"
hoelzl@54258
   143
  using assms by (induct rule: finite_induct, auto)
hoelzl@54258
   144
hoelzl@54258
   145
lemma bdd_above_Un [simp]: "bdd_above (A \<union> B) = (bdd_above A \<and> bdd_above B)"
hoelzl@54258
   146
proof
hoelzl@54258
   147
  assume "bdd_above (A \<union> B)"
hoelzl@54258
   148
  thus "bdd_above A \<and> bdd_above B" unfolding bdd_above_def by auto
hoelzl@54258
   149
next
hoelzl@54258
   150
  assume "bdd_above A \<and> bdd_above B"
hoelzl@54258
   151
  then obtain a b where "\<forall>x\<in>A. x \<le> a" "\<forall>x\<in>B. x \<le> b" unfolding bdd_above_def by auto
hoelzl@54258
   152
  hence "\<forall>x \<in> A \<union> B. x \<le> sup a b" by (auto intro: Un_iff le_supI1 le_supI2)
hoelzl@54258
   153
  thus "bdd_above (A \<union> B)" unfolding bdd_above_def ..
hoelzl@54258
   154
qed
hoelzl@54258
   155
hoelzl@54258
   156
lemma bdd_below_Un [simp]: "bdd_below (A \<union> B) = (bdd_below A \<and> bdd_below B)"
hoelzl@54258
   157
proof
hoelzl@54258
   158
  assume "bdd_below (A \<union> B)"
hoelzl@54258
   159
  thus "bdd_below A \<and> bdd_below B" unfolding bdd_below_def by auto
hoelzl@54258
   160
next
hoelzl@54258
   161
  assume "bdd_below A \<and> bdd_below B"
hoelzl@54258
   162
  then obtain a b where "\<forall>x\<in>A. a \<le> x" "\<forall>x\<in>B. b \<le> x" unfolding bdd_below_def by auto
hoelzl@54258
   163
  hence "\<forall>x \<in> A \<union> B. inf a b \<le> x" by (auto intro: Un_iff le_infI1 le_infI2)
hoelzl@54258
   164
  thus "bdd_below (A \<union> B)" unfolding bdd_below_def ..
hoelzl@54258
   165
qed
hoelzl@54258
   166
hoelzl@54259
   167
lemma bdd_above_sup[simp]: "bdd_above ((\<lambda>x. sup (f x) (g x)) ` A) \<longleftrightarrow> bdd_above (f`A) \<and> bdd_above (g`A)"
hoelzl@54259
   168
  by (auto simp: bdd_above_def intro: le_supI1 le_supI2)
hoelzl@54259
   169
hoelzl@54259
   170
lemma bdd_below_inf[simp]: "bdd_below ((\<lambda>x. inf (f x) (g x)) ` A) \<longleftrightarrow> bdd_below (f`A) \<and> bdd_below (g`A)"
hoelzl@54259
   171
  by (auto simp: bdd_below_def intro: le_infI1 le_infI2)
hoelzl@54259
   172
hoelzl@54258
   173
end
hoelzl@54258
   174
hoelzl@54258
   175
wenzelm@60758
   176
text \<open>
hoelzl@51475
   177
hoelzl@51475
   178
To avoid name classes with the @{class complete_lattice}-class we prefix @{const Sup} and
hoelzl@51475
   179
@{const Inf} in theorem names with c.
hoelzl@51475
   180
wenzelm@60758
   181
\<close>
hoelzl@51475
   182
hoelzl@51773
   183
class conditionally_complete_lattice = lattice + Sup + Inf +
hoelzl@54258
   184
  assumes cInf_lower: "x \<in> X \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X \<le> x"
hoelzl@51475
   185
    and cInf_greatest: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> z \<le> Inf X"
hoelzl@54258
   186
  assumes cSup_upper: "x \<in> X \<Longrightarrow> bdd_above X \<Longrightarrow> x \<le> Sup X"
hoelzl@51475
   187
    and cSup_least: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X \<le> z"
paulson@33269
   188
begin
hoelzl@51475
   189
hoelzl@54259
   190
lemma cSup_upper2: "x \<in> X \<Longrightarrow> y \<le> x \<Longrightarrow> bdd_above X \<Longrightarrow> y \<le> Sup X"
hoelzl@54259
   191
  by (metis cSup_upper order_trans)
hoelzl@54259
   192
hoelzl@54259
   193
lemma cInf_lower2: "x \<in> X \<Longrightarrow> x \<le> y \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X \<le> y"
hoelzl@54259
   194
  by (metis cInf_lower order_trans)
hoelzl@54259
   195
hoelzl@54259
   196
lemma cSup_mono: "B \<noteq> {} \<Longrightarrow> bdd_above A \<Longrightarrow> (\<And>b. b \<in> B \<Longrightarrow> \<exists>a\<in>A. b \<le> a) \<Longrightarrow> Sup B \<le> Sup A"
hoelzl@54259
   197
  by (metis cSup_least cSup_upper2)
hoelzl@54259
   198
hoelzl@54259
   199
lemma cInf_mono: "B \<noteq> {} \<Longrightarrow> bdd_below A \<Longrightarrow> (\<And>b. b \<in> B \<Longrightarrow> \<exists>a\<in>A. a \<le> b) \<Longrightarrow> Inf A \<le> Inf B"
hoelzl@54259
   200
  by (metis cInf_greatest cInf_lower2)
hoelzl@54259
   201
hoelzl@54259
   202
lemma cSup_subset_mono: "A \<noteq> {} \<Longrightarrow> bdd_above B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> Sup A \<le> Sup B"
hoelzl@54259
   203
  by (metis cSup_least cSup_upper subsetD)
hoelzl@54259
   204
hoelzl@54259
   205
lemma cInf_superset_mono: "A \<noteq> {} \<Longrightarrow> bdd_below B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> Inf B \<le> Inf A"
hoelzl@54259
   206
  by (metis cInf_greatest cInf_lower subsetD)
hoelzl@54259
   207
hoelzl@54258
   208
lemma cSup_eq_maximum: "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X = z"
hoelzl@54258
   209
  by (intro antisym cSup_upper[of z X] cSup_least[of X z]) auto
hoelzl@51475
   210
hoelzl@54258
   211
lemma cInf_eq_minimum: "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X = z"
hoelzl@54258
   212
  by (intro antisym cInf_lower[of z X] cInf_greatest[of X z]) auto
hoelzl@51475
   213
hoelzl@54258
   214
lemma cSup_le_iff: "S \<noteq> {} \<Longrightarrow> bdd_above S \<Longrightarrow> Sup S \<le> a \<longleftrightarrow> (\<forall>x\<in>S. x \<le> a)"
hoelzl@51475
   215
  by (metis order_trans cSup_upper cSup_least)
hoelzl@51475
   216
hoelzl@54258
   217
lemma le_cInf_iff: "S \<noteq> {} \<Longrightarrow> bdd_below S \<Longrightarrow> a \<le> Inf S \<longleftrightarrow> (\<forall>x\<in>S. a \<le> x)"
hoelzl@51475
   218
  by (metis order_trans cInf_lower cInf_greatest)
hoelzl@51475
   219
hoelzl@51475
   220
lemma cSup_eq_non_empty:
hoelzl@51475
   221
  assumes 1: "X \<noteq> {}"
hoelzl@51475
   222
  assumes 2: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
hoelzl@51475
   223
  assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
hoelzl@51475
   224
  shows "Sup X = a"
hoelzl@51475
   225
  by (intro 3 1 antisym cSup_least) (auto intro: 2 1 cSup_upper)
hoelzl@51475
   226
hoelzl@51475
   227
lemma cInf_eq_non_empty:
hoelzl@51475
   228
  assumes 1: "X \<noteq> {}"
hoelzl@51475
   229
  assumes 2: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
hoelzl@51475
   230
  assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
hoelzl@51475
   231
  shows "Inf X = a"
hoelzl@51475
   232
  by (intro 3 1 antisym cInf_greatest) (auto intro: 2 1 cInf_lower)
hoelzl@51475
   233
hoelzl@54258
   234
lemma cInf_cSup: "S \<noteq> {} \<Longrightarrow> bdd_below S \<Longrightarrow> Inf S = Sup {x. \<forall>s\<in>S. x \<le> s}"
hoelzl@54258
   235
  by (rule cInf_eq_non_empty) (auto intro!: cSup_upper cSup_least simp: bdd_below_def)
hoelzl@51518
   236
hoelzl@54258
   237
lemma cSup_cInf: "S \<noteq> {} \<Longrightarrow> bdd_above S \<Longrightarrow> Sup S = Inf {x. \<forall>s\<in>S. s \<le> x}"
hoelzl@54258
   238
  by (rule cSup_eq_non_empty) (auto intro!: cInf_lower cInf_greatest simp: bdd_above_def)
hoelzl@54258
   239
hoelzl@54258
   240
lemma cSup_insert: "X \<noteq> {} \<Longrightarrow> bdd_above X \<Longrightarrow> Sup (insert a X) = sup a (Sup X)"
hoelzl@54258
   241
  by (intro cSup_eq_non_empty) (auto intro: le_supI2 cSup_upper cSup_least)
paulson@33269
   242
hoelzl@54258
   243
lemma cInf_insert: "X \<noteq> {} \<Longrightarrow> bdd_below X \<Longrightarrow> Inf (insert a X) = inf a (Inf X)"
hoelzl@54258
   244
  by (intro cInf_eq_non_empty) (auto intro: le_infI2 cInf_lower cInf_greatest)
hoelzl@51475
   245
hoelzl@54259
   246
lemma cSup_singleton [simp]: "Sup {x} = x"
hoelzl@54259
   247
  by (intro cSup_eq_maximum) auto
hoelzl@54259
   248
hoelzl@54259
   249
lemma cInf_singleton [simp]: "Inf {x} = x"
hoelzl@54259
   250
  by (intro cInf_eq_minimum) auto
hoelzl@54259
   251
hoelzl@54258
   252
lemma cSup_insert_If:  "bdd_above X \<Longrightarrow> Sup (insert a X) = (if X = {} then a else sup a (Sup X))"
hoelzl@54258
   253
  using cSup_insert[of X] by simp
hoelzl@51475
   254
hoelzl@54259
   255
lemma cInf_insert_If: "bdd_below X \<Longrightarrow> Inf (insert a X) = (if X = {} then a else inf a (Inf X))"
hoelzl@54258
   256
  using cInf_insert[of X] by simp
hoelzl@51475
   257
hoelzl@51475
   258
lemma le_cSup_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> x \<le> Sup X"
hoelzl@51475
   259
proof (induct X arbitrary: x rule: finite_induct)
hoelzl@51475
   260
  case (insert x X y) then show ?case
hoelzl@54258
   261
    by (cases "X = {}") (auto simp: cSup_insert intro: le_supI2)
hoelzl@51475
   262
qed simp
hoelzl@51475
   263
hoelzl@51475
   264
lemma cInf_le_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> Inf X \<le> x"
hoelzl@51475
   265
proof (induct X arbitrary: x rule: finite_induct)
hoelzl@51475
   266
  case (insert x X y) then show ?case
hoelzl@54258
   267
    by (cases "X = {}") (auto simp: cInf_insert intro: le_infI2)
hoelzl@51475
   268
qed simp
hoelzl@51475
   269
hoelzl@51475
   270
lemma cSup_eq_Sup_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Sup_fin X"
hoelzl@54258
   271
  by (induct X rule: finite_ne_induct) (simp_all add: cSup_insert)
hoelzl@51475
   272
hoelzl@51475
   273
lemma cInf_eq_Inf_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Inf_fin X"
hoelzl@54258
   274
  by (induct X rule: finite_ne_induct) (simp_all add: cInf_insert)
hoelzl@51475
   275
hoelzl@51475
   276
lemma cSup_atMost[simp]: "Sup {..x} = x"
hoelzl@51475
   277
  by (auto intro!: cSup_eq_maximum)
hoelzl@51475
   278
hoelzl@51475
   279
lemma cSup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = x"
hoelzl@51475
   280
  by (auto intro!: cSup_eq_maximum)
hoelzl@51475
   281
hoelzl@51475
   282
lemma cSup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = x"
hoelzl@51475
   283
  by (auto intro!: cSup_eq_maximum)
hoelzl@51475
   284
hoelzl@51475
   285
lemma cInf_atLeast[simp]: "Inf {x..} = x"
hoelzl@51475
   286
  by (auto intro!: cInf_eq_minimum)
hoelzl@51475
   287
hoelzl@51475
   288
lemma cInf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = y"
hoelzl@51475
   289
  by (auto intro!: cInf_eq_minimum)
hoelzl@51475
   290
hoelzl@51475
   291
lemma cInf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = y"
hoelzl@51475
   292
  by (auto intro!: cInf_eq_minimum)
hoelzl@51475
   293
haftmann@56218
   294
lemma cINF_lower: "bdd_below (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> INFIMUM A f \<le> f x"
haftmann@56166
   295
  using cInf_lower [of _ "f ` A"] by simp
hoelzl@54259
   296
haftmann@56218
   297
lemma cINF_greatest: "A \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> m \<le> f x) \<Longrightarrow> m \<le> INFIMUM A f"
haftmann@56166
   298
  using cInf_greatest [of "f ` A"] by auto
hoelzl@54259
   299
haftmann@56218
   300
lemma cSUP_upper: "x \<in> A \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> f x \<le> SUPREMUM A f"
haftmann@56166
   301
  using cSup_upper [of _ "f ` A"] by simp
hoelzl@54259
   302
haftmann@56218
   303
lemma cSUP_least: "A \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<le> M) \<Longrightarrow> SUPREMUM A f \<le> M"
haftmann@56166
   304
  using cSup_least [of "f ` A"] by auto
hoelzl@54259
   305
haftmann@56218
   306
lemma cINF_lower2: "bdd_below (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> f x \<le> u \<Longrightarrow> INFIMUM A f \<le> u"
wenzelm@63092
   307
  by (auto intro: cINF_lower order_trans)
hoelzl@54259
   308
haftmann@56218
   309
lemma cSUP_upper2: "bdd_above (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> u \<le> f x \<Longrightarrow> u \<le> SUPREMUM A f"
wenzelm@63092
   310
  by (auto intro: cSUP_upper order_trans)
hoelzl@54259
   311
lp15@60615
   312
lemma cSUP_const [simp]: "A \<noteq> {} \<Longrightarrow> (SUP x:A. c) = c"
hoelzl@54261
   313
  by (intro antisym cSUP_least) (auto intro: cSUP_upper)
hoelzl@54261
   314
lp15@60615
   315
lemma cINF_const [simp]: "A \<noteq> {} \<Longrightarrow> (INF x:A. c) = c"
hoelzl@54261
   316
  by (intro antisym cINF_greatest) (auto intro: cINF_lower)
hoelzl@54261
   317
haftmann@56218
   318
lemma le_cINF_iff: "A \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> u \<le> INFIMUM A f \<longleftrightarrow> (\<forall>x\<in>A. u \<le> f x)"
wenzelm@63092
   319
  by (metis cINF_greatest cINF_lower order_trans)
hoelzl@54259
   320
haftmann@56218
   321
lemma cSUP_le_iff: "A \<noteq> {} \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> SUPREMUM A f \<le> u \<longleftrightarrow> (\<forall>x\<in>A. f x \<le> u)"
wenzelm@63092
   322
  by (metis cSUP_least cSUP_upper order_trans)
hoelzl@54259
   323
hoelzl@54263
   324
lemma less_cINF_D: "bdd_below (f`A) \<Longrightarrow> y < (INF i:A. f i) \<Longrightarrow> i \<in> A \<Longrightarrow> y < f i"
hoelzl@54263
   325
  by (metis cINF_lower less_le_trans)
hoelzl@54263
   326
hoelzl@54263
   327
lemma cSUP_lessD: "bdd_above (f`A) \<Longrightarrow> (SUP i:A. f i) < y \<Longrightarrow> i \<in> A \<Longrightarrow> f i < y"
hoelzl@54263
   328
  by (metis cSUP_upper le_less_trans)
hoelzl@54263
   329
haftmann@56218
   330
lemma cINF_insert: "A \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> INFIMUM (insert a A) f = inf (f a) (INFIMUM A f)"
haftmann@62343
   331
  by (metis cInf_insert image_insert image_is_empty)
hoelzl@54259
   332
haftmann@56218
   333
lemma cSUP_insert: "A \<noteq> {} \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> SUPREMUM (insert a A) f = sup (f a) (SUPREMUM A f)"
haftmann@62343
   334
  by (metis cSup_insert image_insert image_is_empty)
hoelzl@54259
   335
haftmann@56218
   336
lemma cINF_mono: "B \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> (\<And>m. m \<in> B \<Longrightarrow> \<exists>n\<in>A. f n \<le> g m) \<Longrightarrow> INFIMUM A f \<le> INFIMUM B g"
haftmann@56166
   337
  using cInf_mono [of "g ` B" "f ` A"] by auto
hoelzl@54259
   338
haftmann@56218
   339
lemma cSUP_mono: "A \<noteq> {} \<Longrightarrow> bdd_above (g ` B) \<Longrightarrow> (\<And>n. n \<in> A \<Longrightarrow> \<exists>m\<in>B. f n \<le> g m) \<Longrightarrow> SUPREMUM A f \<le> SUPREMUM B g"
haftmann@56166
   340
  using cSup_mono [of "f ` A" "g ` B"] by auto
hoelzl@54259
   341
haftmann@56218
   342
lemma cINF_superset_mono: "A \<noteq> {} \<Longrightarrow> bdd_below (g ` B) \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> g x \<le> f x) \<Longrightarrow> INFIMUM B g \<le> INFIMUM A f"
hoelzl@54259
   343
  by (rule cINF_mono) auto
hoelzl@54259
   344
haftmann@56218
   345
lemma cSUP_subset_mono: "A \<noteq> {} \<Longrightarrow> bdd_above (g ` B) \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> f x \<le> g x) \<Longrightarrow> SUPREMUM A f \<le> SUPREMUM B g"
hoelzl@54259
   346
  by (rule cSUP_mono) auto
hoelzl@54259
   347
hoelzl@54259
   348
lemma less_eq_cInf_inter: "bdd_below A \<Longrightarrow> bdd_below B \<Longrightarrow> A \<inter> B \<noteq> {} \<Longrightarrow> inf (Inf A) (Inf B) \<le> Inf (A \<inter> B)"
hoelzl@54259
   349
  by (metis cInf_superset_mono lattice_class.inf_sup_ord(1) le_infI1)
hoelzl@54259
   350
hoelzl@54259
   351
lemma cSup_inter_less_eq: "bdd_above A \<Longrightarrow> bdd_above B \<Longrightarrow> A \<inter> B \<noteq> {} \<Longrightarrow> Sup (A \<inter> B) \<le> sup (Sup A) (Sup B) "
hoelzl@54259
   352
  by (metis cSup_subset_mono lattice_class.inf_sup_ord(1) le_supI1)
hoelzl@54259
   353
hoelzl@54259
   354
lemma cInf_union_distrib: "A \<noteq> {} \<Longrightarrow> bdd_below A \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_below B \<Longrightarrow> Inf (A \<union> B) = inf (Inf A) (Inf B)"
hoelzl@54259
   355
  by (intro antisym le_infI cInf_greatest cInf_lower) (auto intro: le_infI1 le_infI2 cInf_lower)
hoelzl@54259
   356
haftmann@56218
   357
lemma cINF_union: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_below (f`B) \<Longrightarrow> INFIMUM (A \<union> B) f = inf (INFIMUM A f) (INFIMUM B f)"
haftmann@56166
   358
  using cInf_union_distrib [of "f ` A" "f ` B"] by (simp add: image_Un [symmetric])
hoelzl@54259
   359
hoelzl@54259
   360
lemma cSup_union_distrib: "A \<noteq> {} \<Longrightarrow> bdd_above A \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_above B \<Longrightarrow> Sup (A \<union> B) = sup (Sup A) (Sup B)"
hoelzl@54259
   361
  by (intro antisym le_supI cSup_least cSup_upper) (auto intro: le_supI1 le_supI2 cSup_upper)
hoelzl@54259
   362
haftmann@56218
   363
lemma cSUP_union: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_above (f`B) \<Longrightarrow> SUPREMUM (A \<union> B) f = sup (SUPREMUM A f) (SUPREMUM B f)"
haftmann@56166
   364
  using cSup_union_distrib [of "f ` A" "f ` B"] by (simp add: image_Un [symmetric])
hoelzl@54259
   365
haftmann@56218
   366
lemma cINF_inf_distrib: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> bdd_below (g`A) \<Longrightarrow> inf (INFIMUM A f) (INFIMUM A g) = (INF a:A. inf (f a) (g a))"
hoelzl@54259
   367
  by (intro antisym le_infI cINF_greatest cINF_lower2)
hoelzl@54259
   368
     (auto intro: le_infI1 le_infI2 cINF_greatest cINF_lower le_infI)
hoelzl@54259
   369
haftmann@56218
   370
lemma SUP_sup_distrib: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> bdd_above (g`A) \<Longrightarrow> sup (SUPREMUM A f) (SUPREMUM A g) = (SUP a:A. sup (f a) (g a))"
hoelzl@54259
   371
  by (intro antisym le_supI cSUP_least cSUP_upper2)
hoelzl@54259
   372
     (auto intro: le_supI1 le_supI2 cSUP_least cSUP_upper le_supI)
hoelzl@54259
   373
hoelzl@57447
   374
lemma cInf_le_cSup:
hoelzl@57447
   375
  "A \<noteq> {} \<Longrightarrow> bdd_above A \<Longrightarrow> bdd_below A \<Longrightarrow> Inf A \<le> Sup A"
hoelzl@57447
   376
  by (auto intro!: cSup_upper2[of "SOME a. a \<in> A"] intro: someI cInf_lower)
hoelzl@57447
   377
paulson@33269
   378
end
paulson@33269
   379
hoelzl@51773
   380
instance complete_lattice \<subseteq> conditionally_complete_lattice
wenzelm@61169
   381
  by standard (auto intro: Sup_upper Sup_least Inf_lower Inf_greatest)
hoelzl@51475
   382
hoelzl@51475
   383
lemma cSup_eq:
hoelzl@51773
   384
  fixes a :: "'a :: {conditionally_complete_lattice, no_bot}"
hoelzl@51475
   385
  assumes upper: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
hoelzl@51475
   386
  assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
hoelzl@51475
   387
  shows "Sup X = a"
hoelzl@51475
   388
proof cases
hoelzl@51475
   389
  assume "X = {}" with lt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
hoelzl@51475
   390
qed (intro cSup_eq_non_empty assms)
hoelzl@51475
   391
hoelzl@51475
   392
lemma cInf_eq:
hoelzl@51773
   393
  fixes a :: "'a :: {conditionally_complete_lattice, no_top}"
hoelzl@51475
   394
  assumes upper: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
hoelzl@51475
   395
  assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
hoelzl@51475
   396
  shows "Inf X = a"
hoelzl@51475
   397
proof cases
hoelzl@51475
   398
  assume "X = {}" with gt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
hoelzl@51475
   399
qed (intro cInf_eq_non_empty assms)
hoelzl@51475
   400
hoelzl@51773
   401
class conditionally_complete_linorder = conditionally_complete_lattice + linorder
paulson@33269
   402
begin
hoelzl@51475
   403
hoelzl@63331
   404
lemma less_cSup_iff:
hoelzl@54258
   405
  "X \<noteq> {} \<Longrightarrow> bdd_above X \<Longrightarrow> y < Sup X \<longleftrightarrow> (\<exists>x\<in>X. y < x)"
hoelzl@51475
   406
  by (rule iffI) (metis cSup_least not_less, metis cSup_upper less_le_trans)
hoelzl@51475
   407
hoelzl@54258
   408
lemma cInf_less_iff: "X \<noteq> {} \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X < y \<longleftrightarrow> (\<exists>x\<in>X. x < y)"
hoelzl@51475
   409
  by (rule iffI) (metis cInf_greatest not_less, metis cInf_lower le_less_trans)
hoelzl@51475
   410
hoelzl@54263
   411
lemma cINF_less_iff: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> (INF i:A. f i) < a \<longleftrightarrow> (\<exists>x\<in>A. f x < a)"
haftmann@56166
   412
  using cInf_less_iff[of "f`A"] by auto
hoelzl@54263
   413
hoelzl@54263
   414
lemma less_cSUP_iff: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> a < (SUP i:A. f i) \<longleftrightarrow> (\<exists>x\<in>A. a < f x)"
haftmann@56166
   415
  using less_cSup_iff[of "f`A"] by auto
hoelzl@54263
   416
hoelzl@51475
   417
lemma less_cSupE:
hoelzl@51475
   418
  assumes "y < Sup X" "X \<noteq> {}" obtains x where "x \<in> X" "y < x"
hoelzl@51475
   419
  by (metis cSup_least assms not_le that)
hoelzl@51475
   420
hoelzl@51518
   421
lemma less_cSupD:
hoelzl@51518
   422
  "X \<noteq> {} \<Longrightarrow> z < Sup X \<Longrightarrow> \<exists>x\<in>X. z < x"
lp15@61824
   423
  by (metis less_cSup_iff not_le_imp_less bdd_above_def)
hoelzl@51518
   424
hoelzl@51518
   425
lemma cInf_lessD:
hoelzl@51518
   426
  "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x\<in>X. x < z"
lp15@61824
   427
  by (metis cInf_less_iff not_le_imp_less bdd_below_def)
hoelzl@51518
   428
hoelzl@51475
   429
lemma complete_interval:
hoelzl@51475
   430
  assumes "a < b" and "P a" and "\<not> P b"
hoelzl@51475
   431
  shows "\<exists>c. a \<le> c \<and> c \<le> b \<and> (\<forall>x. a \<le> x \<and> x < c \<longrightarrow> P x) \<and>
hoelzl@51475
   432
             (\<forall>d. (\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x) \<longrightarrow> d \<le> c)"
hoelzl@51475
   433
proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
hoelzl@51475
   434
  show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
hoelzl@54258
   435
    by (rule cSup_upper, auto simp: bdd_above_def)
wenzelm@60758
   436
       (metis \<open>a < b\<close> \<open>\<not> P b\<close> linear less_le)
hoelzl@51475
   437
next
hoelzl@51475
   438
  show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
hoelzl@63331
   439
    apply (rule cSup_least)
hoelzl@51475
   440
    apply auto
hoelzl@51475
   441
    apply (metis less_le_not_le)
wenzelm@60758
   442
    apply (metis \<open>a<b\<close> \<open>~ P b\<close> linear less_le)
hoelzl@51475
   443
    done
hoelzl@51475
   444
next
hoelzl@51475
   445
  fix x
hoelzl@51475
   446
  assume x: "a \<le> x" and lt: "x < Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
hoelzl@51475
   447
  show "P x"
hoelzl@51475
   448
    apply (rule less_cSupE [OF lt], auto)
hoelzl@51475
   449
    apply (metis less_le_not_le)
hoelzl@63331
   450
    apply (metis x)
hoelzl@51475
   451
    done
hoelzl@51475
   452
next
hoelzl@51475
   453
  fix d
hoelzl@51475
   454
    assume 0: "\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x"
hoelzl@51475
   455
    thus "d \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
hoelzl@54258
   456
      by (rule_tac cSup_upper, auto simp: bdd_above_def)
wenzelm@60758
   457
         (metis \<open>a<b\<close> \<open>~ P b\<close> linear less_le)
hoelzl@51475
   458
qed
hoelzl@51475
   459
hoelzl@51475
   460
end
hoelzl@51475
   461
hoelzl@60172
   462
instance complete_linorder < conditionally_complete_linorder
hoelzl@60172
   463
  ..
hoelzl@60172
   464
hoelzl@54259
   465
lemma cSup_eq_Max: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Max X"
hoelzl@54259
   466
  using cSup_eq_Sup_fin[of X] Sup_fin_eq_Max[of X] by simp
hoelzl@51775
   467
hoelzl@54259
   468
lemma cInf_eq_Min: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Min X"
hoelzl@54259
   469
  using cInf_eq_Inf_fin[of X] Inf_fin_eq_Min[of X] by simp
hoelzl@51775
   470
hoelzl@54257
   471
lemma cSup_lessThan[simp]: "Sup {..<x::'a::{conditionally_complete_linorder, no_bot, dense_linorder}} = x"
hoelzl@51475
   472
  by (auto intro!: cSup_eq_non_empty intro: dense_le)
hoelzl@51475
   473
hoelzl@57447
   474
lemma cSup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x::'a::{conditionally_complete_linorder, dense_linorder}} = x"
hoelzl@57447
   475
  by (auto intro!: cSup_eq_non_empty intro: dense_le_bounded)
hoelzl@51475
   476
hoelzl@57447
   477
lemma cSup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x::'a::{conditionally_complete_linorder, dense_linorder}} = x"
hoelzl@57447
   478
  by (auto intro!: cSup_eq_non_empty intro: dense_le_bounded)
hoelzl@51475
   479
hoelzl@54257
   480
lemma cInf_greaterThan[simp]: "Inf {x::'a::{conditionally_complete_linorder, no_top, dense_linorder} <..} = x"
hoelzl@57447
   481
  by (auto intro!: cInf_eq_non_empty intro: dense_ge)
hoelzl@51475
   482
hoelzl@57447
   483
lemma cInf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x::'a::{conditionally_complete_linorder, dense_linorder}} = y"
hoelzl@57447
   484
  by (auto intro!: cInf_eq_non_empty intro: dense_ge_bounded)
hoelzl@51475
   485
hoelzl@57447
   486
lemma cInf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x::'a::{conditionally_complete_linorder, dense_linorder}} = y"
hoelzl@57447
   487
  by (auto intro!: cInf_eq_non_empty intro: dense_ge_bounded)
hoelzl@51475
   488
hoelzl@54259
   489
class linear_continuum = conditionally_complete_linorder + dense_linorder +
hoelzl@54259
   490
  assumes UNIV_not_singleton: "\<exists>a b::'a. a \<noteq> b"
hoelzl@54259
   491
begin
hoelzl@54259
   492
hoelzl@54259
   493
lemma ex_gt_or_lt: "\<exists>b. a < b \<or> b < a"
hoelzl@54259
   494
  by (metis UNIV_not_singleton neq_iff)
hoelzl@54259
   495
paulson@33269
   496
end
hoelzl@54259
   497
hoelzl@54281
   498
instantiation nat :: conditionally_complete_linorder
hoelzl@54281
   499
begin
hoelzl@54281
   500
hoelzl@54281
   501
definition "Sup (X::nat set) = Max X"
hoelzl@54281
   502
definition "Inf (X::nat set) = (LEAST n. n \<in> X)"
hoelzl@54281
   503
hoelzl@54281
   504
lemma bdd_above_nat: "bdd_above X \<longleftrightarrow> finite (X::nat set)"
hoelzl@54281
   505
proof
hoelzl@54281
   506
  assume "bdd_above X"
hoelzl@54281
   507
  then obtain z where "X \<subseteq> {.. z}"
hoelzl@54281
   508
    by (auto simp: bdd_above_def)
hoelzl@54281
   509
  then show "finite X"
hoelzl@54281
   510
    by (rule finite_subset) simp
hoelzl@54281
   511
qed simp
hoelzl@54281
   512
hoelzl@54281
   513
instance
hoelzl@54281
   514
proof
wenzelm@63540
   515
  fix x :: nat
wenzelm@63540
   516
  fix X :: "nat set"
wenzelm@63540
   517
  show "Inf X \<le> x" if "x \<in> X" "bdd_below X"
wenzelm@63540
   518
    using that by (simp add: Inf_nat_def Least_le)
wenzelm@63540
   519
  show "x \<le> Inf X" if "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> x \<le> y"
wenzelm@63540
   520
    using that unfolding Inf_nat_def ex_in_conv[symmetric] by (rule LeastI2_ex)
wenzelm@63540
   521
  show "x \<le> Sup X" if "x \<in> X" "bdd_above X"
wenzelm@63540
   522
    using that by (simp add: Sup_nat_def bdd_above_nat)
wenzelm@63540
   523
  show "Sup X \<le> x" if "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> y \<le> x"
wenzelm@63540
   524
  proof -
wenzelm@63540
   525
    from that have "bdd_above X"
hoelzl@54281
   526
      by (auto simp: bdd_above_def)
wenzelm@63540
   527
    with that show ?thesis 
wenzelm@63540
   528
      by (simp add: Sup_nat_def bdd_above_nat)
wenzelm@63540
   529
  qed
hoelzl@54281
   530
qed
wenzelm@63540
   531
hoelzl@54259
   532
end
hoelzl@54281
   533
hoelzl@54281
   534
instantiation int :: conditionally_complete_linorder
hoelzl@54281
   535
begin
hoelzl@54281
   536
hoelzl@54281
   537
definition "Sup (X::int set) = (THE x. x \<in> X \<and> (\<forall>y\<in>X. y \<le> x))"
hoelzl@54281
   538
definition "Inf (X::int set) = - (Sup (uminus ` X))"
hoelzl@54281
   539
hoelzl@54281
   540
instance
hoelzl@54281
   541
proof
hoelzl@54281
   542
  { fix x :: int and X :: "int set" assume "X \<noteq> {}" "bdd_above X"
hoelzl@54281
   543
    then obtain x y where "X \<subseteq> {..y}" "x \<in> X"
hoelzl@54281
   544
      by (auto simp: bdd_above_def)
hoelzl@54281
   545
    then have *: "finite (X \<inter> {x..y})" "X \<inter> {x..y} \<noteq> {}" and "x \<le> y"
hoelzl@54281
   546
      by (auto simp: subset_eq)
hoelzl@54281
   547
    have "\<exists>!x\<in>X. (\<forall>y\<in>X. y \<le> x)"
hoelzl@54281
   548
    proof
hoelzl@54281
   549
      { fix z assume "z \<in> X"
hoelzl@54281
   550
        have "z \<le> Max (X \<inter> {x..y})"
hoelzl@54281
   551
        proof cases
wenzelm@60758
   552
          assume "x \<le> z" with \<open>z \<in> X\<close> \<open>X \<subseteq> {..y}\<close> *(1) show ?thesis
hoelzl@54281
   553
            by (auto intro!: Max_ge)
hoelzl@54281
   554
        next
hoelzl@54281
   555
          assume "\<not> x \<le> z"
hoelzl@54281
   556
          then have "z < x" by simp
hoelzl@54281
   557
          also have "x \<le> Max (X \<inter> {x..y})"
wenzelm@60758
   558
            using \<open>x \<in> X\<close> *(1) \<open>x \<le> y\<close> by (intro Max_ge) auto
hoelzl@54281
   559
          finally show ?thesis by simp
hoelzl@54281
   560
        qed }
hoelzl@54281
   561
      note le = this
hoelzl@54281
   562
      with Max_in[OF *] show ex: "Max (X \<inter> {x..y}) \<in> X \<and> (\<forall>z\<in>X. z \<le> Max (X \<inter> {x..y}))" by auto
hoelzl@54281
   563
hoelzl@54281
   564
      fix z assume *: "z \<in> X \<and> (\<forall>y\<in>X. y \<le> z)"
hoelzl@54281
   565
      with le have "z \<le> Max (X \<inter> {x..y})"
hoelzl@54281
   566
        by auto
hoelzl@54281
   567
      moreover have "Max (X \<inter> {x..y}) \<le> z"
hoelzl@54281
   568
        using * ex by auto
hoelzl@54281
   569
      ultimately show "z = Max (X \<inter> {x..y})"
hoelzl@54281
   570
        by auto
hoelzl@54281
   571
    qed
hoelzl@54281
   572
    then have "Sup X \<in> X \<and> (\<forall>y\<in>X. y \<le> Sup X)"
hoelzl@54281
   573
      unfolding Sup_int_def by (rule theI') }
hoelzl@54281
   574
  note Sup_int = this
hoelzl@54281
   575
hoelzl@54281
   576
  { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_above X" then show "x \<le> Sup X"
hoelzl@54281
   577
      using Sup_int[of X] by auto }
hoelzl@54281
   578
  note le_Sup = this
hoelzl@54281
   579
  { fix x :: int and X :: "int set" assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> y \<le> x" then show "Sup X \<le> x"
hoelzl@54281
   580
      using Sup_int[of X] by (auto simp: bdd_above_def) }
hoelzl@54281
   581
  note Sup_le = this
hoelzl@54281
   582
hoelzl@54281
   583
  { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_below X" then show "Inf X \<le> x"
hoelzl@54281
   584
      using le_Sup[of "-x" "uminus ` X"] by (auto simp: Inf_int_def) }
hoelzl@54281
   585
  { fix x :: int and X :: "int set" assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> x \<le> y" then show "x \<le> Inf X"
hoelzl@54281
   586
      using Sup_le[of "uminus ` X" "-x"] by (force simp: Inf_int_def) }
hoelzl@54281
   587
qed
hoelzl@54281
   588
end
hoelzl@54281
   589
hoelzl@57275
   590
lemma interval_cases:
hoelzl@57275
   591
  fixes S :: "'a :: conditionally_complete_linorder set"
hoelzl@57275
   592
  assumes ivl: "\<And>a b x. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> x \<in> S"
hoelzl@57275
   593
  shows "\<exists>a b. S = {} \<or>
hoelzl@57275
   594
    S = UNIV \<or>
hoelzl@57275
   595
    S = {..<b} \<or>
hoelzl@57275
   596
    S = {..b} \<or>
hoelzl@57275
   597
    S = {a<..} \<or>
hoelzl@57275
   598
    S = {a..} \<or>
hoelzl@57275
   599
    S = {a<..<b} \<or>
hoelzl@57275
   600
    S = {a<..b} \<or>
hoelzl@57275
   601
    S = {a..<b} \<or>
hoelzl@57275
   602
    S = {a..b}"
hoelzl@57275
   603
proof -
wenzelm@63040
   604
  define lower upper where "lower = {x. \<exists>s\<in>S. s \<le> x}" and "upper = {x. \<exists>s\<in>S. x \<le> s}"
hoelzl@57275
   605
  with ivl have "S = lower \<inter> upper"
hoelzl@57275
   606
    by auto
hoelzl@63331
   607
  moreover
hoelzl@57275
   608
  have "\<exists>a. upper = UNIV \<or> upper = {} \<or> upper = {.. a} \<or> upper = {..< a}"
hoelzl@57275
   609
  proof cases
hoelzl@57275
   610
    assume *: "bdd_above S \<and> S \<noteq> {}"
hoelzl@57275
   611
    from * have "upper \<subseteq> {.. Sup S}"
hoelzl@57275
   612
      by (auto simp: upper_def intro: cSup_upper2)
hoelzl@57275
   613
    moreover from * have "{..< Sup S} \<subseteq> upper"
hoelzl@57275
   614
      by (force simp add: less_cSup_iff upper_def subset_eq Ball_def)
hoelzl@57275
   615
    ultimately have "upper = {.. Sup S} \<or> upper = {..< Sup S}"
hoelzl@57275
   616
      unfolding ivl_disj_un(2)[symmetric] by auto
hoelzl@57275
   617
    then show ?thesis by auto
hoelzl@57275
   618
  next
hoelzl@57275
   619
    assume "\<not> (bdd_above S \<and> S \<noteq> {})"
hoelzl@57275
   620
    then have "upper = UNIV \<or> upper = {}"
hoelzl@57275
   621
      by (auto simp: upper_def bdd_above_def not_le dest: less_imp_le)
hoelzl@57275
   622
    then show ?thesis
hoelzl@57275
   623
      by auto
hoelzl@57275
   624
  qed
hoelzl@57275
   625
  moreover
hoelzl@57275
   626
  have "\<exists>b. lower = UNIV \<or> lower = {} \<or> lower = {b ..} \<or> lower = {b <..}"
hoelzl@57275
   627
  proof cases
hoelzl@57275
   628
    assume *: "bdd_below S \<and> S \<noteq> {}"
hoelzl@57275
   629
    from * have "lower \<subseteq> {Inf S ..}"
hoelzl@57275
   630
      by (auto simp: lower_def intro: cInf_lower2)
hoelzl@57275
   631
    moreover from * have "{Inf S <..} \<subseteq> lower"
hoelzl@57275
   632
      by (force simp add: cInf_less_iff lower_def subset_eq Ball_def)
hoelzl@57275
   633
    ultimately have "lower = {Inf S ..} \<or> lower = {Inf S <..}"
hoelzl@57275
   634
      unfolding ivl_disj_un(1)[symmetric] by auto
hoelzl@57275
   635
    then show ?thesis by auto
hoelzl@57275
   636
  next
hoelzl@57275
   637
    assume "\<not> (bdd_below S \<and> S \<noteq> {})"
hoelzl@57275
   638
    then have "lower = UNIV \<or> lower = {}"
hoelzl@57275
   639
      by (auto simp: lower_def bdd_below_def not_le dest: less_imp_le)
hoelzl@57275
   640
    then show ?thesis
hoelzl@57275
   641
      by auto
hoelzl@57275
   642
  qed
hoelzl@57275
   643
  ultimately show ?thesis
hoelzl@57275
   644
    unfolding greaterThanAtMost_def greaterThanLessThan_def atLeastAtMost_def atLeastLessThan_def
wenzelm@63171
   645
    by (metis inf_bot_left inf_bot_right inf_top.left_neutral inf_top.right_neutral)
hoelzl@57275
   646
qed
hoelzl@57275
   647
lp15@60615
   648
lemma cSUP_eq_cINF_D:
lp15@60615
   649
  fixes f :: "_ \<Rightarrow> 'b::conditionally_complete_lattice"
lp15@60615
   650
  assumes eq: "(SUP x:A. f x) = (INF x:A. f x)"
lp15@60615
   651
     and bdd: "bdd_above (f ` A)" "bdd_below (f ` A)"
lp15@60615
   652
     and a: "a \<in> A"
lp15@60615
   653
  shows "f a = (INF x:A. f x)"
lp15@60615
   654
apply (rule antisym)
lp15@60615
   655
using a bdd
lp15@60615
   656
apply (auto simp: cINF_lower)
lp15@60615
   657
apply (metis eq cSUP_upper)
hoelzl@63331
   658
done
lp15@60615
   659
lp15@62379
   660
lemma cSUP_UNION:
lp15@62379
   661
  fixes f :: "_ \<Rightarrow> 'b::conditionally_complete_lattice"
lp15@62379
   662
  assumes ne: "A \<noteq> {}" "\<And>x. x \<in> A \<Longrightarrow> B(x) \<noteq> {}"
lp15@62379
   663
      and bdd_UN: "bdd_above (\<Union>x\<in>A. f ` B x)"
lp15@62379
   664
  shows "(SUP z : \<Union>x\<in>A. B x. f z) = (SUP x:A. SUP z:B x. f z)"
lp15@62379
   665
proof -
lp15@62379
   666
  have bdd: "\<And>x. x \<in> A \<Longrightarrow> bdd_above (f ` B x)"
lp15@62379
   667
    using bdd_UN by (meson UN_upper bdd_above_mono)
lp15@62379
   668
  obtain M where "\<And>x y. x \<in> A \<Longrightarrow> y \<in> B(x) \<Longrightarrow> f y \<le> M"
lp15@62379
   669
    using bdd_UN by (auto simp: bdd_above_def)
lp15@62379
   670
  then have bdd2: "bdd_above ((\<lambda>x. SUP z:B x. f z) ` A)"
lp15@62379
   671
    unfolding bdd_above_def by (force simp: bdd cSUP_le_iff ne(2))
lp15@62379
   672
  have "(SUP z:\<Union>x\<in>A. B x. f z) \<le> (SUP x:A. SUP z:B x. f z)"
lp15@62379
   673
    using assms by (fastforce simp add: intro!: cSUP_least intro: cSUP_upper2 simp: bdd2 bdd)
lp15@62379
   674
  moreover have "(SUP x:A. SUP z:B x. f z) \<le> (SUP z:\<Union>x\<in>A. B x. f z)"
lp15@62379
   675
    using assms by (fastforce simp add: intro!: cSUP_least intro: cSUP_upper simp: image_UN bdd_UN)
lp15@62379
   676
  ultimately show ?thesis
lp15@62379
   677
    by (rule order_antisym)
lp15@62379
   678
qed
lp15@62379
   679
lp15@62379
   680
lemma cINF_UNION:
lp15@62379
   681
  fixes f :: "_ \<Rightarrow> 'b::conditionally_complete_lattice"
lp15@62379
   682
  assumes ne: "A \<noteq> {}" "\<And>x. x \<in> A \<Longrightarrow> B(x) \<noteq> {}"
lp15@62379
   683
      and bdd_UN: "bdd_below (\<Union>x\<in>A. f ` B x)"
lp15@62379
   684
  shows "(INF z : \<Union>x\<in>A. B x. f z) = (INF x:A. INF z:B x. f z)"
lp15@62379
   685
proof -
lp15@62379
   686
  have bdd: "\<And>x. x \<in> A \<Longrightarrow> bdd_below (f ` B x)"
lp15@62379
   687
    using bdd_UN by (meson UN_upper bdd_below_mono)
lp15@62379
   688
  obtain M where "\<And>x y. x \<in> A \<Longrightarrow> y \<in> B(x) \<Longrightarrow> f y \<ge> M"
lp15@62379
   689
    using bdd_UN by (auto simp: bdd_below_def)
lp15@62379
   690
  then have bdd2: "bdd_below ((\<lambda>x. INF z:B x. f z) ` A)"
lp15@62379
   691
    unfolding bdd_below_def by (force simp: bdd le_cINF_iff ne(2))
lp15@62379
   692
  have "(INF z:\<Union>x\<in>A. B x. f z) \<le> (INF x:A. INF z:B x. f z)"
lp15@62379
   693
    using assms by (fastforce simp add: intro!: cINF_greatest intro: cINF_lower simp: bdd2 bdd)
lp15@62379
   694
  moreover have "(INF x:A. INF z:B x. f z) \<le> (INF z:\<Union>x\<in>A. B x. f z)"
lp15@62379
   695
    using assms  by (fastforce simp add: intro!: cINF_greatest intro: cINF_lower2  simp: bdd bdd_UN bdd2)
lp15@62379
   696
  ultimately show ?thesis
lp15@62379
   697
    by (rule order_antisym)
lp15@62379
   698
qed
lp15@62379
   699
hoelzl@63331
   700
lemma cSup_abs_le:
lp15@62626
   701
  fixes S :: "('a::{linordered_idom,conditionally_complete_linorder}) set"
lp15@62626
   702
  shows "S \<noteq> {} \<Longrightarrow> (\<And>x. x\<in>S \<Longrightarrow> \<bar>x\<bar> \<le> a) \<Longrightarrow> \<bar>Sup S\<bar> \<le> a"
lp15@62626
   703
  apply (auto simp add: abs_le_iff intro: cSup_least)
lp15@62626
   704
  by (metis bdd_aboveI cSup_upper neg_le_iff_le order_trans)
lp15@62626
   705
hoelzl@54281
   706
end