src/HOL/Lattices.thy
author haftmann
Fri Oct 19 19:45:29 2007 +0200 (2007-10-19)
changeset 25102 db3e412c4cb1
parent 25062 af5ef0d4d655
child 25206 9c84ec7217a9
permissions -rw-r--r--
antisymmetry not a default intro rule any longer
haftmann@21249
     1
(*  Title:      HOL/Lattices.thy
haftmann@21249
     2
    ID:         $Id$
haftmann@21249
     3
    Author:     Tobias Nipkow
haftmann@21249
     4
*)
haftmann@21249
     5
haftmann@22454
     6
header {* Abstract lattices *}
haftmann@21249
     7
haftmann@21249
     8
theory Lattices
haftmann@21249
     9
imports Orderings
haftmann@21249
    10
begin
haftmann@21249
    11
haftmann@21249
    12
subsection{* Lattices *}
haftmann@21249
    13
haftmann@22422
    14
class lower_semilattice = order +
haftmann@21249
    15
  fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
haftmann@22737
    16
  assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
haftmann@22737
    17
  and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
nipkow@21733
    18
  and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
haftmann@21249
    19
haftmann@22422
    20
class upper_semilattice = order +
haftmann@21249
    21
  fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
haftmann@22737
    22
  assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
haftmann@22737
    23
  and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
nipkow@21733
    24
  and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
haftmann@21249
    25
haftmann@22422
    26
class lattice = lower_semilattice + upper_semilattice
haftmann@21249
    27
nipkow@21733
    28
subsubsection{* Intro and elim rules*}
nipkow@21733
    29
nipkow@21733
    30
context lower_semilattice
nipkow@21733
    31
begin
haftmann@21249
    32
haftmann@25062
    33
lemma le_infI1[intro]:
haftmann@25062
    34
  assumes "a \<sqsubseteq> x"
haftmann@25062
    35
  shows "a \<sqinter> b \<sqsubseteq> x"
haftmann@25062
    36
proof (rule order_trans)
haftmann@25062
    37
  show "a \<sqinter> b \<sqsubseteq> a" and "a \<sqsubseteq> x" using assms by simp
haftmann@25062
    38
qed
haftmann@22422
    39
lemmas (in -) [rule del] = le_infI1
haftmann@21249
    40
haftmann@25062
    41
lemma le_infI2[intro]:
haftmann@25062
    42
  assumes "b \<sqsubseteq> x"
haftmann@25062
    43
  shows "a \<sqinter> b \<sqsubseteq> x"
haftmann@25062
    44
proof (rule order_trans)
haftmann@25062
    45
  show "a \<sqinter> b \<sqsubseteq> b" and "b \<sqsubseteq> x" using assms by simp
haftmann@25062
    46
qed
haftmann@22422
    47
lemmas (in -) [rule del] = le_infI2
nipkow@21733
    48
nipkow@21734
    49
lemma le_infI[intro!]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
nipkow@21733
    50
by(blast intro: inf_greatest)
haftmann@22422
    51
lemmas (in -) [rule del] = le_infI
haftmann@21249
    52
haftmann@22422
    53
lemma le_infE [elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22422
    54
  by (blast intro: order_trans)
haftmann@22422
    55
lemmas (in -) [rule del] = le_infE
haftmann@21249
    56
nipkow@21734
    57
lemma le_inf_iff [simp]:
haftmann@25102
    58
  "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
nipkow@21733
    59
by blast
nipkow@21733
    60
nipkow@21734
    61
lemma le_iff_inf: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)"
haftmann@25102
    62
  by (blast intro: antisym dest: eq_iff [THEN iffD1])
haftmann@21249
    63
nipkow@21733
    64
end
nipkow@21733
    65
haftmann@23878
    66
lemma mono_inf: "mono f \<Longrightarrow> f (inf A B) \<le> inf (f A) (f B)"
haftmann@23878
    67
  by (auto simp add: mono_def)
haftmann@23878
    68
nipkow@21733
    69
nipkow@21733
    70
context upper_semilattice
nipkow@21733
    71
begin
haftmann@21249
    72
nipkow@21734
    73
lemma le_supI1[intro]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
    74
  by (rule order_trans) auto
haftmann@22422
    75
lemmas (in -) [rule del] = le_supI1
haftmann@21249
    76
nipkow@21734
    77
lemma le_supI2[intro]: "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
    78
  by (rule order_trans) auto 
haftmann@22422
    79
lemmas (in -) [rule del] = le_supI2
nipkow@21733
    80
nipkow@21734
    81
lemma le_supI[intro!]: "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
nipkow@21733
    82
by(blast intro: sup_least)
haftmann@22422
    83
lemmas (in -) [rule del] = le_supI
haftmann@21249
    84
nipkow@21734
    85
lemma le_supE[elim!]: "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22422
    86
  by (blast intro: order_trans)
haftmann@22422
    87
lemmas (in -) [rule del] = le_supE
haftmann@22422
    88
nipkow@21734
    89
lemma ge_sup_conv[simp]:
haftmann@25102
    90
  "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
nipkow@21733
    91
by blast
nipkow@21733
    92
nipkow@21734
    93
lemma le_iff_sup: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
haftmann@25102
    94
  by (blast intro: antisym dest: eq_iff [THEN iffD1])
nipkow@21734
    95
nipkow@21733
    96
end
nipkow@21733
    97
haftmann@23878
    98
lemma mono_sup: "mono f \<Longrightarrow> sup (f A) (f B) \<le> f (sup A B)"
haftmann@23878
    99
  by (auto simp add: mono_def)
haftmann@23878
   100
nipkow@21733
   101
nipkow@21733
   102
subsubsection{* Equational laws *}
haftmann@21249
   103
haftmann@21249
   104
nipkow@21733
   105
context lower_semilattice
nipkow@21733
   106
begin
nipkow@21733
   107
nipkow@21733
   108
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
haftmann@25102
   109
  by (blast intro: antisym)
nipkow@21733
   110
nipkow@21733
   111
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
haftmann@25102
   112
  by (blast intro: antisym)
nipkow@21733
   113
nipkow@21733
   114
lemma inf_idem[simp]: "x \<sqinter> x = x"
haftmann@25102
   115
  by (blast intro: antisym)
nipkow@21733
   116
nipkow@21733
   117
lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
haftmann@25102
   118
  by (blast intro: antisym)
nipkow@21733
   119
nipkow@21733
   120
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
haftmann@25102
   121
  by (blast intro: antisym)
nipkow@21733
   122
nipkow@21733
   123
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
haftmann@25102
   124
  by (blast intro: antisym)
nipkow@21733
   125
nipkow@21733
   126
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
haftmann@25102
   127
  by (blast intro: antisym)
nipkow@21733
   128
nipkow@21733
   129
lemmas inf_ACI = inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@21733
   130
nipkow@21733
   131
end
nipkow@21733
   132
nipkow@21733
   133
nipkow@21733
   134
context upper_semilattice
nipkow@21733
   135
begin
haftmann@21249
   136
nipkow@21733
   137
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
haftmann@25102
   138
  by (blast intro: antisym)
nipkow@21733
   139
nipkow@21733
   140
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
haftmann@25102
   141
  by (blast intro: antisym)
nipkow@21733
   142
nipkow@21733
   143
lemma sup_idem[simp]: "x \<squnion> x = x"
haftmann@25102
   144
  by (blast intro: antisym)
nipkow@21733
   145
nipkow@21733
   146
lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
haftmann@25102
   147
  by (blast intro: antisym)
nipkow@21733
   148
nipkow@21733
   149
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
haftmann@25102
   150
  by (blast intro: antisym)
nipkow@21733
   151
nipkow@21733
   152
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
haftmann@25102
   153
  by (blast intro: antisym)
haftmann@21249
   154
nipkow@21733
   155
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
haftmann@25102
   156
  by (blast intro: antisym)
nipkow@21733
   157
nipkow@21733
   158
lemmas sup_ACI = sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@21733
   159
nipkow@21733
   160
end
haftmann@21249
   161
nipkow@21733
   162
context lattice
nipkow@21733
   163
begin
nipkow@21733
   164
nipkow@21733
   165
lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
haftmann@25102
   166
  by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
nipkow@21733
   167
nipkow@21733
   168
lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
haftmann@25102
   169
  by (blast intro: antisym sup_ge1 sup_least inf_le1)
nipkow@21733
   170
nipkow@21734
   171
lemmas ACI = inf_ACI sup_ACI
nipkow@21734
   172
haftmann@22454
   173
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
haftmann@22454
   174
nipkow@21734
   175
text{* Towards distributivity *}
haftmann@21249
   176
nipkow@21734
   177
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@25102
   178
  by blast
nipkow@21734
   179
nipkow@21734
   180
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
haftmann@25102
   181
  by blast
nipkow@21734
   182
nipkow@21734
   183
nipkow@21734
   184
text{* If you have one of them, you have them all. *}
haftmann@21249
   185
nipkow@21733
   186
lemma distrib_imp1:
haftmann@21249
   187
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   188
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   189
proof-
haftmann@21249
   190
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
haftmann@21249
   191
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc)
haftmann@21249
   192
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
haftmann@21249
   193
    by(simp add:inf_sup_absorb inf_commute)
haftmann@21249
   194
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   195
  finally show ?thesis .
haftmann@21249
   196
qed
haftmann@21249
   197
nipkow@21733
   198
lemma distrib_imp2:
haftmann@21249
   199
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   200
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   201
proof-
haftmann@21249
   202
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
haftmann@21249
   203
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc)
haftmann@21249
   204
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
haftmann@21249
   205
    by(simp add:sup_inf_absorb sup_commute)
haftmann@21249
   206
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   207
  finally show ?thesis .
haftmann@21249
   208
qed
haftmann@21249
   209
nipkow@21734
   210
(* seems unused *)
nipkow@21734
   211
lemma modular_le: "x \<sqsubseteq> z \<Longrightarrow> x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> z"
nipkow@21734
   212
by blast
nipkow@21734
   213
nipkow@21733
   214
end
haftmann@21249
   215
haftmann@21249
   216
haftmann@24164
   217
subsection {* Distributive lattices *}
haftmann@21249
   218
haftmann@22454
   219
class distrib_lattice = lattice +
haftmann@21249
   220
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   221
nipkow@21733
   222
context distrib_lattice
nipkow@21733
   223
begin
nipkow@21733
   224
nipkow@21733
   225
lemma sup_inf_distrib2:
haftmann@21249
   226
 "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
haftmann@21249
   227
by(simp add:ACI sup_inf_distrib1)
haftmann@21249
   228
nipkow@21733
   229
lemma inf_sup_distrib1:
haftmann@21249
   230
 "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   231
by(rule distrib_imp2[OF sup_inf_distrib1])
haftmann@21249
   232
nipkow@21733
   233
lemma inf_sup_distrib2:
haftmann@21249
   234
 "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
haftmann@21249
   235
by(simp add:ACI inf_sup_distrib1)
haftmann@21249
   236
nipkow@21733
   237
lemmas distrib =
haftmann@21249
   238
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   239
nipkow@21733
   240
end
nipkow@21733
   241
haftmann@21249
   242
haftmann@22454
   243
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   244
haftmann@22737
   245
lemma (in lower_semilattice) inf_unique:
haftmann@22454
   246
  fixes f (infixl "\<triangle>" 70)
haftmann@25062
   247
  assumes le1: "\<And>x y. x \<triangle> y \<le> x" and le2: "\<And>x y. x \<triangle> y \<le> y"
haftmann@25062
   248
  and greatest: "\<And>x y z. x \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> y \<triangle> z"
haftmann@22737
   249
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   250
proof (rule antisym)
haftmann@25062
   251
  show "x \<triangle> y \<le> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   252
next
haftmann@25062
   253
  have leI: "\<And>x y z. x \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> y \<triangle> z" by (blast intro: greatest)
haftmann@25062
   254
  show "x \<sqinter> y \<le> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   255
qed
haftmann@22454
   256
haftmann@22737
   257
lemma (in upper_semilattice) sup_unique:
haftmann@22454
   258
  fixes f (infixl "\<nabla>" 70)
haftmann@25062
   259
  assumes ge1 [simp]: "\<And>x y. x \<le> x \<nabla> y" and ge2: "\<And>x y. y \<le> x \<nabla> y"
haftmann@25062
   260
  and least: "\<And>x y z. y \<le> x \<Longrightarrow> z \<le> x \<Longrightarrow> y \<nabla> z \<le> x"
haftmann@22737
   261
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   262
proof (rule antisym)
haftmann@25062
   263
  show "x \<squnion> y \<le> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   264
next
haftmann@25062
   265
  have leI: "\<And>x y z. x \<le> z \<Longrightarrow> y \<le> z \<Longrightarrow> x \<nabla> y \<le> z" by (blast intro: least)
haftmann@25062
   266
  show "x \<nabla> y \<le> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   267
qed
haftmann@22454
   268
  
haftmann@22454
   269
haftmann@22916
   270
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   271
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   272
haftmann@22916
   273
lemma (in linorder) distrib_lattice_min_max:
haftmann@25062
   274
  "distrib_lattice (op \<le>) (op <) min max"
haftmann@22916
   275
proof unfold_locales
haftmann@25062
   276
  have aux: "\<And>x y \<Colon> 'a. x < y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
haftmann@22916
   277
    by (auto simp add: less_le antisym)
haftmann@22916
   278
  fix x y z
haftmann@22916
   279
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@22916
   280
  unfolding min_def max_def
ballarin@24640
   281
  by auto
haftmann@22916
   282
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   283
haftmann@21249
   284
interpretation min_max:
haftmann@22454
   285
  distrib_lattice ["op \<le> \<Colon> 'a\<Colon>linorder \<Rightarrow> 'a \<Rightarrow> bool" "op <" min max]
haftmann@23948
   286
  by (rule distrib_lattice_min_max)
haftmann@21249
   287
haftmann@22454
   288
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   289
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   290
haftmann@22454
   291
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   292
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   293
haftmann@21249
   294
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   295
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   296
 
haftmann@21249
   297
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@22422
   298
  mk_left_commute [of max, OF min_max.sup_assoc min_max.sup_commute]
haftmann@21249
   299
haftmann@21249
   300
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@22422
   301
  mk_left_commute [of min, OF min_max.inf_assoc min_max.inf_commute]
haftmann@21249
   302
haftmann@22454
   303
text {*
haftmann@22454
   304
  Now we have inherited antisymmetry as an intro-rule on all
haftmann@22454
   305
  linear orders. This is a problem because it applies to bool, which is
haftmann@22454
   306
  undesirable.
haftmann@22454
   307
*}
haftmann@22454
   308
haftmann@25102
   309
lemmas [rule del] = min_max.le_infI min_max.le_supI
haftmann@22454
   310
  min_max.le_supE min_max.le_infE min_max.le_supI1 min_max.le_supI2
haftmann@22454
   311
  min_max.le_infI1 min_max.le_infI2
haftmann@22454
   312
haftmann@22454
   313
haftmann@23878
   314
subsection {* Complete lattices *}
haftmann@23878
   315
haftmann@23878
   316
class complete_lattice = lattice +
haftmann@23878
   317
  fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)
haftmann@24345
   318
    and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)
haftmann@23878
   319
  assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"
haftmann@24345
   320
     and Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"
haftmann@24345
   321
  assumes Sup_upper: "x \<in> A \<Longrightarrow> x \<sqsubseteq> \<Squnion>A"
haftmann@24345
   322
     and Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<sqsubseteq> z) \<Longrightarrow> \<Squnion>A \<sqsubseteq> z"
haftmann@23878
   323
begin
haftmann@23878
   324
haftmann@25062
   325
lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<le> a}"
haftmann@25102
   326
  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
haftmann@23878
   327
haftmann@25062
   328
lemma Sup_Inf:  "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<le> b}"
haftmann@25102
   329
  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
haftmann@23878
   330
haftmann@23878
   331
lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"
haftmann@24345
   332
  unfolding Sup_Inf by auto
haftmann@23878
   333
haftmann@23878
   334
lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"
haftmann@23878
   335
  unfolding Inf_Sup by auto
haftmann@23878
   336
haftmann@23878
   337
lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"
haftmann@23878
   338
  apply (rule antisym)
haftmann@23878
   339
  apply (rule le_infI)
haftmann@23878
   340
  apply (rule Inf_lower)
haftmann@23878
   341
  apply simp
haftmann@23878
   342
  apply (rule Inf_greatest)
haftmann@23878
   343
  apply (rule Inf_lower)
haftmann@23878
   344
  apply simp
haftmann@23878
   345
  apply (rule Inf_greatest)
haftmann@23878
   346
  apply (erule insertE)
haftmann@23878
   347
  apply (rule le_infI1)
haftmann@23878
   348
  apply simp
haftmann@23878
   349
  apply (rule le_infI2)
haftmann@23878
   350
  apply (erule Inf_lower)
haftmann@23878
   351
  done
haftmann@23878
   352
haftmann@24345
   353
lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"
haftmann@23878
   354
  apply (rule antisym)
haftmann@23878
   355
  apply (rule Sup_least)
haftmann@23878
   356
  apply (erule insertE)
haftmann@23878
   357
  apply (rule le_supI1)
haftmann@23878
   358
  apply simp
haftmann@23878
   359
  apply (rule le_supI2)
haftmann@23878
   360
  apply (erule Sup_upper)
haftmann@23878
   361
  apply (rule le_supI)
haftmann@23878
   362
  apply (rule Sup_upper)
haftmann@23878
   363
  apply simp
haftmann@23878
   364
  apply (rule Sup_least)
haftmann@23878
   365
  apply (rule Sup_upper)
haftmann@23878
   366
  apply simp
haftmann@23878
   367
  done
haftmann@23878
   368
haftmann@23878
   369
lemma Inf_singleton [simp]:
haftmann@23878
   370
  "\<Sqinter>{a} = a"
haftmann@23878
   371
  by (auto intro: antisym Inf_lower Inf_greatest)
haftmann@23878
   372
haftmann@24345
   373
lemma Sup_singleton [simp]:
haftmann@23878
   374
  "\<Squnion>{a} = a"
haftmann@23878
   375
  by (auto intro: antisym Sup_upper Sup_least)
haftmann@23878
   376
haftmann@23878
   377
lemma Inf_insert_simp:
haftmann@23878
   378
  "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"
haftmann@23878
   379
  by (cases "A = {}") (simp_all, simp add: Inf_insert)
haftmann@23878
   380
haftmann@23878
   381
lemma Sup_insert_simp:
haftmann@23878
   382
  "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"
haftmann@23878
   383
  by (cases "A = {}") (simp_all, simp add: Sup_insert)
haftmann@23878
   384
haftmann@23878
   385
lemma Inf_binary:
haftmann@23878
   386
  "\<Sqinter>{a, b} = a \<sqinter> b"
haftmann@23878
   387
  by (simp add: Inf_insert_simp)
haftmann@23878
   388
haftmann@23878
   389
lemma Sup_binary:
haftmann@23878
   390
  "\<Squnion>{a, b} = a \<squnion> b"
haftmann@23878
   391
  by (simp add: Sup_insert_simp)
haftmann@23878
   392
haftmann@23878
   393
definition
haftmann@24749
   394
  top :: 'a
haftmann@23878
   395
where
haftmann@23878
   396
  "top = Inf {}"
haftmann@23878
   397
haftmann@23878
   398
definition
haftmann@24749
   399
  bot :: 'a
haftmann@23878
   400
where
haftmann@23878
   401
  "bot = Sup {}"
haftmann@23878
   402
haftmann@25062
   403
lemma top_greatest [simp]: "x \<le> top"
haftmann@23878
   404
  by (unfold top_def, rule Inf_greatest, simp)
haftmann@23878
   405
haftmann@25062
   406
lemma bot_least [simp]: "bot \<le> x"
haftmann@23878
   407
  by (unfold bot_def, rule Sup_least, simp)
haftmann@23878
   408
haftmann@23878
   409
definition
haftmann@24749
   410
  SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
haftmann@23878
   411
where
haftmann@23878
   412
  "SUPR A f == Sup (f ` A)"
haftmann@23878
   413
haftmann@23878
   414
definition
haftmann@24749
   415
  INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
haftmann@23878
   416
where
haftmann@23878
   417
  "INFI A f == Inf (f ` A)"
haftmann@23878
   418
haftmann@24749
   419
end
haftmann@24749
   420
haftmann@23878
   421
syntax
haftmann@23878
   422
  "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
haftmann@23878
   423
  "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
haftmann@23878
   424
  "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
haftmann@23878
   425
  "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
haftmann@23878
   426
haftmann@23878
   427
translations
haftmann@23878
   428
  "SUP x y. B"   == "SUP x. SUP y. B"
haftmann@23878
   429
  "SUP x. B"     == "CONST SUPR UNIV (%x. B)"
haftmann@23878
   430
  "SUP x. B"     == "SUP x:UNIV. B"
haftmann@23878
   431
  "SUP x:A. B"   == "CONST SUPR A (%x. B)"
haftmann@23878
   432
  "INF x y. B"   == "INF x. INF y. B"
haftmann@23878
   433
  "INF x. B"     == "CONST INFI UNIV (%x. B)"
haftmann@23878
   434
  "INF x. B"     == "INF x:UNIV. B"
haftmann@23878
   435
  "INF x:A. B"   == "CONST INFI A (%x. B)"
haftmann@23878
   436
haftmann@23878
   437
(* To avoid eta-contraction of body: *)
haftmann@23878
   438
print_translation {*
haftmann@23878
   439
let
haftmann@23878
   440
  fun btr' syn (A :: Abs abs :: ts) =
haftmann@23878
   441
    let val (x,t) = atomic_abs_tr' abs
haftmann@23878
   442
    in list_comb (Syntax.const syn $ x $ A $ t, ts) end
haftmann@23878
   443
  val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const
haftmann@23878
   444
in
haftmann@23878
   445
[(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]
haftmann@23878
   446
end
haftmann@23878
   447
*}
haftmann@23878
   448
haftmann@25102
   449
context complete_lattice
haftmann@25102
   450
begin
haftmann@25102
   451
haftmann@23878
   452
lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
haftmann@23878
   453
  by (auto simp add: SUPR_def intro: Sup_upper)
haftmann@23878
   454
haftmann@23878
   455
lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
haftmann@23878
   456
  by (auto simp add: SUPR_def intro: Sup_least)
haftmann@23878
   457
haftmann@23878
   458
lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
haftmann@23878
   459
  by (auto simp add: INFI_def intro: Inf_lower)
haftmann@23878
   460
haftmann@23878
   461
lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
haftmann@23878
   462
  by (auto simp add: INFI_def intro: Inf_greatest)
haftmann@23878
   463
haftmann@23878
   464
lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
haftmann@25102
   465
  by (auto intro: antisym SUP_leI le_SUPI)
haftmann@23878
   466
haftmann@23878
   467
lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
haftmann@25102
   468
  by (auto intro: antisym INF_leI le_INFI)
haftmann@25102
   469
haftmann@25102
   470
end
haftmann@23878
   471
haftmann@23878
   472
haftmann@22454
   473
subsection {* Bool as lattice *}
haftmann@22454
   474
haftmann@22454
   475
instance bool :: distrib_lattice
haftmann@22454
   476
  inf_bool_eq: "inf P Q \<equiv> P \<and> Q"
haftmann@22454
   477
  sup_bool_eq: "sup P Q \<equiv> P \<or> Q"
haftmann@22454
   478
  by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
haftmann@22454
   479
haftmann@23878
   480
instance bool :: complete_lattice
haftmann@23878
   481
  Inf_bool_def: "Inf A \<equiv> \<forall>x\<in>A. x"
haftmann@24345
   482
  Sup_bool_def: "Sup A \<equiv> \<exists>x\<in>A. x"
haftmann@24345
   483
  by intro_classes (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)
haftmann@23878
   484
haftmann@23878
   485
lemma Inf_empty_bool [simp]:
haftmann@23878
   486
  "Inf {}"
haftmann@23878
   487
  unfolding Inf_bool_def by auto
haftmann@23878
   488
haftmann@23878
   489
lemma not_Sup_empty_bool [simp]:
haftmann@23878
   490
  "\<not> Sup {}"
haftmann@24345
   491
  unfolding Sup_bool_def by auto
haftmann@23878
   492
haftmann@23878
   493
lemma top_bool_eq: "top = True"
haftmann@23878
   494
  by (iprover intro!: order_antisym le_boolI top_greatest)
haftmann@23878
   495
haftmann@23878
   496
lemma bot_bool_eq: "bot = False"
haftmann@23878
   497
  by (iprover intro!: order_antisym le_boolI bot_least)
haftmann@23878
   498
haftmann@23878
   499
haftmann@23878
   500
subsection {* Set as lattice *}
haftmann@23878
   501
haftmann@23878
   502
instance set :: (type) distrib_lattice
haftmann@23878
   503
  inf_set_eq: "inf A B \<equiv> A \<inter> B"
haftmann@23878
   504
  sup_set_eq: "sup A B \<equiv> A \<union> B"
haftmann@23878
   505
  by intro_classes (auto simp add: inf_set_eq sup_set_eq)
haftmann@23878
   506
haftmann@23878
   507
lemmas [code func del] = inf_set_eq sup_set_eq
haftmann@23878
   508
wenzelm@24514
   509
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
wenzelm@24514
   510
  apply (fold inf_set_eq sup_set_eq)
wenzelm@24514
   511
  apply (erule mono_inf)
wenzelm@24514
   512
  done
haftmann@23878
   513
wenzelm@24514
   514
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
wenzelm@24514
   515
  apply (fold inf_set_eq sup_set_eq)
wenzelm@24514
   516
  apply (erule mono_sup)
wenzelm@24514
   517
  done
haftmann@23878
   518
haftmann@23878
   519
instance set :: (type) complete_lattice
haftmann@23878
   520
  Inf_set_def: "Inf S \<equiv> \<Inter>S"
haftmann@24345
   521
  Sup_set_def: "Sup S \<equiv> \<Union>S"
haftmann@24345
   522
  by intro_classes (auto simp add: Inf_set_def Sup_set_def)
haftmann@23878
   523
haftmann@24345
   524
lemmas [code func del] = Inf_set_def Sup_set_def
haftmann@23878
   525
haftmann@23878
   526
lemma top_set_eq: "top = UNIV"
haftmann@23878
   527
  by (iprover intro!: subset_antisym subset_UNIV top_greatest)
haftmann@23878
   528
haftmann@23878
   529
lemma bot_set_eq: "bot = {}"
haftmann@23878
   530
  by (iprover intro!: subset_antisym empty_subsetI bot_least)
haftmann@23878
   531
haftmann@23878
   532
haftmann@23878
   533
subsection {* Fun as lattice *}
haftmann@23878
   534
haftmann@23878
   535
instance "fun" :: (type, lattice) lattice
haftmann@23878
   536
  inf_fun_eq: "inf f g \<equiv> (\<lambda>x. inf (f x) (g x))"
haftmann@23878
   537
  sup_fun_eq: "sup f g \<equiv> (\<lambda>x. sup (f x) (g x))"
haftmann@23878
   538
apply intro_classes
haftmann@23878
   539
unfolding inf_fun_eq sup_fun_eq
haftmann@23878
   540
apply (auto intro: le_funI)
haftmann@23878
   541
apply (rule le_funI)
haftmann@23878
   542
apply (auto dest: le_funD)
haftmann@23878
   543
apply (rule le_funI)
haftmann@23878
   544
apply (auto dest: le_funD)
haftmann@23878
   545
done
haftmann@23878
   546
haftmann@23878
   547
lemmas [code func del] = inf_fun_eq sup_fun_eq
haftmann@23878
   548
haftmann@23878
   549
instance "fun" :: (type, distrib_lattice) distrib_lattice
haftmann@23878
   550
  by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
haftmann@23878
   551
haftmann@23878
   552
instance "fun" :: (type, complete_lattice) complete_lattice
haftmann@23878
   553
  Inf_fun_def: "Inf A \<equiv> (\<lambda>x. Inf {y. \<exists>f\<in>A. y = f x})"
haftmann@24345
   554
  Sup_fun_def: "Sup A \<equiv> (\<lambda>x. Sup {y. \<exists>f\<in>A. y = f x})"
haftmann@24345
   555
  by intro_classes
haftmann@24345
   556
    (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
haftmann@24345
   557
      intro: Inf_lower Sup_upper Inf_greatest Sup_least)
haftmann@23878
   558
haftmann@24345
   559
lemmas [code func del] = Inf_fun_def Sup_fun_def
haftmann@23878
   560
haftmann@23878
   561
lemma Inf_empty_fun:
haftmann@23878
   562
  "Inf {} = (\<lambda>_. Inf {})"
haftmann@23878
   563
  by rule (auto simp add: Inf_fun_def)
haftmann@23878
   564
haftmann@23878
   565
lemma Sup_empty_fun:
haftmann@23878
   566
  "Sup {} = (\<lambda>_. Sup {})"
haftmann@24345
   567
  by rule (auto simp add: Sup_fun_def)
haftmann@23878
   568
haftmann@23878
   569
lemma top_fun_eq: "top = (\<lambda>x. top)"
haftmann@23878
   570
  by (iprover intro!: order_antisym le_funI top_greatest)
haftmann@23878
   571
haftmann@23878
   572
lemma bot_fun_eq: "bot = (\<lambda>x. bot)"
haftmann@23878
   573
  by (iprover intro!: order_antisym le_funI bot_least)
haftmann@23878
   574
haftmann@23878
   575
haftmann@23878
   576
text {* redundant bindings *}
haftmann@22454
   577
haftmann@22454
   578
lemmas inf_aci = inf_ACI
haftmann@22454
   579
lemmas sup_aci = sup_ACI
haftmann@22454
   580
haftmann@25062
   581
no_notation
haftmann@25062
   582
  inf (infixl "\<sqinter>" 70)
haftmann@25062
   583
haftmann@25062
   584
no_notation
haftmann@25062
   585
  sup (infixl "\<squnion>" 65)
haftmann@25062
   586
haftmann@25062
   587
no_notation
haftmann@25062
   588
  Inf ("\<Sqinter>_" [900] 900)
haftmann@25062
   589
haftmann@25062
   590
no_notation
haftmann@25062
   591
  Sup ("\<Squnion>_" [900] 900)
haftmann@25062
   592
haftmann@21249
   593
end