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