src/HOL/Lattices.thy
author haftmann
Tue Oct 16 23:12:45 2007 +0200 (2007-10-16)
changeset 25062 af5ef0d4d655
parent 24749 151b3758f576
child 25102 db3e412c4cb1
permissions -rw-r--r--
global class syntax
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@22422
    33
lemmas antisym_intro [intro!] = antisym
haftmann@22422
    34
lemmas (in -) [rule del] = antisym_intro
haftmann@21249
    35
haftmann@25062
    36
lemma le_infI1[intro]:
haftmann@25062
    37
  assumes "a \<sqsubseteq> x"
haftmann@25062
    38
  shows "a \<sqinter> b \<sqsubseteq> x"
haftmann@25062
    39
proof (rule order_trans)
haftmann@25062
    40
  show "a \<sqinter> b \<sqsubseteq> a" and "a \<sqsubseteq> x" using assms by simp
haftmann@25062
    41
qed
haftmann@22422
    42
lemmas (in -) [rule del] = le_infI1
haftmann@21249
    43
haftmann@25062
    44
lemma le_infI2[intro]:
haftmann@25062
    45
  assumes "b \<sqsubseteq> x"
haftmann@25062
    46
  shows "a \<sqinter> b \<sqsubseteq> x"
haftmann@25062
    47
proof (rule order_trans)
haftmann@25062
    48
  show "a \<sqinter> b \<sqsubseteq> b" and "b \<sqsubseteq> x" using assms by simp
haftmann@25062
    49
qed
haftmann@22422
    50
lemmas (in -) [rule del] = le_infI2
nipkow@21733
    51
nipkow@21734
    52
lemma le_infI[intro!]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
nipkow@21733
    53
by(blast intro: inf_greatest)
haftmann@22422
    54
lemmas (in -) [rule del] = le_infI
haftmann@21249
    55
haftmann@22422
    56
lemma le_infE [elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22422
    57
  by (blast intro: order_trans)
haftmann@22422
    58
lemmas (in -) [rule del] = le_infE
haftmann@21249
    59
nipkow@21734
    60
lemma le_inf_iff [simp]:
nipkow@21733
    61
 "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
nipkow@21733
    62
by blast
nipkow@21733
    63
nipkow@21734
    64
lemma le_iff_inf: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)"
nipkow@22168
    65
by(blast dest:eq_iff[THEN iffD1])
haftmann@21249
    66
nipkow@21733
    67
end
nipkow@21733
    68
haftmann@23878
    69
lemma mono_inf: "mono f \<Longrightarrow> f (inf A B) \<le> inf (f A) (f B)"
haftmann@23878
    70
  by (auto simp add: mono_def)
haftmann@23878
    71
nipkow@21733
    72
nipkow@21733
    73
context upper_semilattice
nipkow@21733
    74
begin
haftmann@21249
    75
haftmann@22422
    76
lemmas antisym_intro [intro!] = antisym
haftmann@22422
    77
lemmas (in -) [rule del] = antisym_intro
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
haftmann@21249
    95
nipkow@21734
    96
lemma ge_sup_conv[simp]:
nipkow@21733
    97
 "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
nipkow@21733
    98
by blast
nipkow@21733
    99
nipkow@21734
   100
lemma le_iff_sup: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
nipkow@22168
   101
by(blast dest:eq_iff[THEN iffD1])
nipkow@21734
   102
nipkow@21733
   103
end
nipkow@21733
   104
haftmann@23878
   105
lemma mono_sup: "mono f \<Longrightarrow> sup (f A) (f B) \<le> f (sup A B)"
haftmann@23878
   106
  by (auto simp add: mono_def)
haftmann@23878
   107
nipkow@21733
   108
nipkow@21733
   109
subsubsection{* Equational laws *}
haftmann@21249
   110
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)"
nipkow@21733
   116
by blast
nipkow@21733
   117
nipkow@21733
   118
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
nipkow@21733
   119
by blast
nipkow@21733
   120
nipkow@21733
   121
lemma inf_idem[simp]: "x \<sqinter> x = x"
nipkow@21733
   122
by blast
nipkow@21733
   123
nipkow@21733
   124
lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
nipkow@21733
   125
by blast
nipkow@21733
   126
nipkow@21733
   127
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
nipkow@21733
   128
by blast
nipkow@21733
   129
nipkow@21733
   130
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
nipkow@21733
   131
by blast
nipkow@21733
   132
nipkow@21733
   133
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
nipkow@21733
   134
by blast
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)"
nipkow@21733
   145
by blast
nipkow@21733
   146
nipkow@21733
   147
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
nipkow@21733
   148
by blast
nipkow@21733
   149
nipkow@21733
   150
lemma sup_idem[simp]: "x \<squnion> x = x"
nipkow@21733
   151
by blast
nipkow@21733
   152
nipkow@21733
   153
lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
nipkow@21733
   154
by blast
nipkow@21733
   155
nipkow@21733
   156
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
nipkow@21733
   157
by blast
nipkow@21733
   158
nipkow@21733
   159
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
nipkow@21733
   160
by blast
haftmann@21249
   161
nipkow@21733
   162
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
nipkow@21733
   163
by blast
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"
nipkow@21733
   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"
nipkow@21733
   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)"
nipkow@21734
   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)"
nipkow@21734
   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@22454
   296
  by (rule ext)+ auto
nipkow@21733
   297
haftmann@22454
   298
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@22454
   299
  by (rule ext)+ auto
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@22454
   316
lemmas [rule del] = min_max.antisym_intro 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@24345
   333
  by (auto intro: 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@24345
   336
  by (auto intro: 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
haftmann@24749
   401
  top :: 'a
haftmann@23878
   402
where
haftmann@23878
   403
  "top = Inf {}"
haftmann@23878
   404
haftmann@23878
   405
definition
haftmann@24749
   406
  bot :: 'a
haftmann@23878
   407
where
haftmann@23878
   408
  "bot = Sup {}"
haftmann@23878
   409
haftmann@25062
   410
lemma top_greatest [simp]: "x \<le> top"
haftmann@23878
   411
  by (unfold top_def, rule Inf_greatest, simp)
haftmann@23878
   412
haftmann@25062
   413
lemma bot_least [simp]: "bot \<le> x"
haftmann@23878
   414
  by (unfold bot_def, rule Sup_least, simp)
haftmann@23878
   415
haftmann@23878
   416
definition
haftmann@24749
   417
  SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
haftmann@23878
   418
where
haftmann@23878
   419
  "SUPR A f == Sup (f ` A)"
haftmann@23878
   420
haftmann@23878
   421
definition
haftmann@24749
   422
  INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
haftmann@23878
   423
where
haftmann@23878
   424
  "INFI A f == Inf (f ` A)"
haftmann@23878
   425
haftmann@24749
   426
end
haftmann@24749
   427
haftmann@23878
   428
syntax
haftmann@23878
   429
  "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
haftmann@23878
   430
  "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
haftmann@23878
   431
  "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
haftmann@23878
   432
  "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
haftmann@23878
   433
haftmann@23878
   434
translations
haftmann@23878
   435
  "SUP x y. B"   == "SUP x. SUP y. B"
haftmann@23878
   436
  "SUP x. B"     == "CONST SUPR UNIV (%x. B)"
haftmann@23878
   437
  "SUP x. B"     == "SUP x:UNIV. B"
haftmann@23878
   438
  "SUP x:A. B"   == "CONST SUPR A (%x. B)"
haftmann@23878
   439
  "INF x y. B"   == "INF x. INF y. B"
haftmann@23878
   440
  "INF x. B"     == "CONST INFI UNIV (%x. B)"
haftmann@23878
   441
  "INF x. B"     == "INF x:UNIV. B"
haftmann@23878
   442
  "INF x:A. B"   == "CONST INFI A (%x. B)"
haftmann@23878
   443
haftmann@23878
   444
(* To avoid eta-contraction of body: *)
haftmann@23878
   445
print_translation {*
haftmann@23878
   446
let
haftmann@23878
   447
  fun btr' syn (A :: Abs abs :: ts) =
haftmann@23878
   448
    let val (x,t) = atomic_abs_tr' abs
haftmann@23878
   449
    in list_comb (Syntax.const syn $ x $ A $ t, ts) end
haftmann@23878
   450
  val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const
haftmann@23878
   451
in
haftmann@23878
   452
[(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]
haftmann@23878
   453
end
haftmann@23878
   454
*}
haftmann@23878
   455
haftmann@23878
   456
lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
haftmann@23878
   457
  by (auto simp add: SUPR_def intro: Sup_upper)
haftmann@23878
   458
haftmann@23878
   459
lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
haftmann@23878
   460
  by (auto simp add: SUPR_def intro: Sup_least)
haftmann@23878
   461
haftmann@23878
   462
lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
haftmann@23878
   463
  by (auto simp add: INFI_def intro: Inf_lower)
haftmann@23878
   464
haftmann@23878
   465
lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
haftmann@23878
   466
  by (auto simp add: INFI_def intro: Inf_greatest)
haftmann@23878
   467
haftmann@23878
   468
lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
haftmann@23878
   469
  by (auto intro: order_antisym SUP_leI le_SUPI)
haftmann@23878
   470
haftmann@23878
   471
lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
haftmann@23878
   472
  by (auto intro: order_antisym INF_leI le_INFI)
haftmann@23878
   473
haftmann@23878
   474
haftmann@22454
   475
subsection {* Bool as lattice *}
haftmann@22454
   476
haftmann@22454
   477
instance bool :: distrib_lattice
haftmann@22454
   478
  inf_bool_eq: "inf P Q \<equiv> P \<and> Q"
haftmann@22454
   479
  sup_bool_eq: "sup P Q \<equiv> P \<or> Q"
haftmann@22454
   480
  by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
haftmann@22454
   481
haftmann@23878
   482
instance bool :: complete_lattice
haftmann@23878
   483
  Inf_bool_def: "Inf A \<equiv> \<forall>x\<in>A. x"
haftmann@24345
   484
  Sup_bool_def: "Sup A \<equiv> \<exists>x\<in>A. x"
haftmann@24345
   485
  by intro_classes (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)
haftmann@23878
   486
haftmann@23878
   487
lemma Inf_empty_bool [simp]:
haftmann@23878
   488
  "Inf {}"
haftmann@23878
   489
  unfolding Inf_bool_def by auto
haftmann@23878
   490
haftmann@23878
   491
lemma not_Sup_empty_bool [simp]:
haftmann@23878
   492
  "\<not> Sup {}"
haftmann@24345
   493
  unfolding Sup_bool_def by auto
haftmann@23878
   494
haftmann@23878
   495
lemma top_bool_eq: "top = True"
haftmann@23878
   496
  by (iprover intro!: order_antisym le_boolI top_greatest)
haftmann@23878
   497
haftmann@23878
   498
lemma bot_bool_eq: "bot = False"
haftmann@23878
   499
  by (iprover intro!: order_antisym le_boolI bot_least)
haftmann@23878
   500
haftmann@23878
   501
haftmann@23878
   502
subsection {* Set as lattice *}
haftmann@23878
   503
haftmann@23878
   504
instance set :: (type) distrib_lattice
haftmann@23878
   505
  inf_set_eq: "inf A B \<equiv> A \<inter> B"
haftmann@23878
   506
  sup_set_eq: "sup A B \<equiv> A \<union> B"
haftmann@23878
   507
  by intro_classes (auto simp add: inf_set_eq sup_set_eq)
haftmann@23878
   508
haftmann@23878
   509
lemmas [code func del] = inf_set_eq sup_set_eq
haftmann@23878
   510
wenzelm@24514
   511
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
wenzelm@24514
   512
  apply (fold inf_set_eq sup_set_eq)
wenzelm@24514
   513
  apply (erule mono_inf)
wenzelm@24514
   514
  done
haftmann@23878
   515
wenzelm@24514
   516
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
wenzelm@24514
   517
  apply (fold inf_set_eq sup_set_eq)
wenzelm@24514
   518
  apply (erule mono_sup)
wenzelm@24514
   519
  done
haftmann@23878
   520
haftmann@23878
   521
instance set :: (type) complete_lattice
haftmann@23878
   522
  Inf_set_def: "Inf S \<equiv> \<Inter>S"
haftmann@24345
   523
  Sup_set_def: "Sup S \<equiv> \<Union>S"
haftmann@24345
   524
  by intro_classes (auto simp add: Inf_set_def Sup_set_def)
haftmann@23878
   525
haftmann@24345
   526
lemmas [code func del] = Inf_set_def Sup_set_def
haftmann@23878
   527
haftmann@23878
   528
lemma top_set_eq: "top = UNIV"
haftmann@23878
   529
  by (iprover intro!: subset_antisym subset_UNIV top_greatest)
haftmann@23878
   530
haftmann@23878
   531
lemma bot_set_eq: "bot = {}"
haftmann@23878
   532
  by (iprover intro!: subset_antisym empty_subsetI bot_least)
haftmann@23878
   533
haftmann@23878
   534
haftmann@23878
   535
subsection {* Fun as lattice *}
haftmann@23878
   536
haftmann@23878
   537
instance "fun" :: (type, lattice) lattice
haftmann@23878
   538
  inf_fun_eq: "inf f g \<equiv> (\<lambda>x. inf (f x) (g x))"
haftmann@23878
   539
  sup_fun_eq: "sup f g \<equiv> (\<lambda>x. sup (f x) (g x))"
haftmann@23878
   540
apply intro_classes
haftmann@23878
   541
unfolding inf_fun_eq sup_fun_eq
haftmann@23878
   542
apply (auto intro: le_funI)
haftmann@23878
   543
apply (rule le_funI)
haftmann@23878
   544
apply (auto dest: le_funD)
haftmann@23878
   545
apply (rule le_funI)
haftmann@23878
   546
apply (auto dest: le_funD)
haftmann@23878
   547
done
haftmann@23878
   548
haftmann@23878
   549
lemmas [code func del] = inf_fun_eq sup_fun_eq
haftmann@23878
   550
haftmann@23878
   551
instance "fun" :: (type, distrib_lattice) distrib_lattice
haftmann@23878
   552
  by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
haftmann@23878
   553
haftmann@23878
   554
instance "fun" :: (type, complete_lattice) complete_lattice
haftmann@23878
   555
  Inf_fun_def: "Inf A \<equiv> (\<lambda>x. Inf {y. \<exists>f\<in>A. y = f x})"
haftmann@24345
   556
  Sup_fun_def: "Sup A \<equiv> (\<lambda>x. Sup {y. \<exists>f\<in>A. y = f x})"
haftmann@24345
   557
  by intro_classes
haftmann@24345
   558
    (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
haftmann@24345
   559
      intro: Inf_lower Sup_upper Inf_greatest Sup_least)
haftmann@23878
   560
haftmann@24345
   561
lemmas [code func del] = Inf_fun_def Sup_fun_def
haftmann@23878
   562
haftmann@23878
   563
lemma Inf_empty_fun:
haftmann@23878
   564
  "Inf {} = (\<lambda>_. Inf {})"
haftmann@23878
   565
  by rule (auto simp add: Inf_fun_def)
haftmann@23878
   566
haftmann@23878
   567
lemma Sup_empty_fun:
haftmann@23878
   568
  "Sup {} = (\<lambda>_. Sup {})"
haftmann@24345
   569
  by rule (auto simp add: Sup_fun_def)
haftmann@23878
   570
haftmann@23878
   571
lemma top_fun_eq: "top = (\<lambda>x. top)"
haftmann@23878
   572
  by (iprover intro!: order_antisym le_funI top_greatest)
haftmann@23878
   573
haftmann@23878
   574
lemma bot_fun_eq: "bot = (\<lambda>x. bot)"
haftmann@23878
   575
  by (iprover intro!: order_antisym le_funI bot_least)
haftmann@23878
   576
haftmann@23878
   577
haftmann@23878
   578
text {* redundant bindings *}
haftmann@22454
   579
haftmann@22454
   580
lemmas inf_aci = inf_ACI
haftmann@22454
   581
lemmas sup_aci = sup_ACI
haftmann@22454
   582
haftmann@25062
   583
no_notation
haftmann@25062
   584
  inf (infixl "\<sqinter>" 70)
haftmann@25062
   585
haftmann@25062
   586
no_notation
haftmann@25062
   587
  sup (infixl "\<squnion>" 65)
haftmann@25062
   588
haftmann@25062
   589
no_notation
haftmann@25062
   590
  Inf ("\<Sqinter>_" [900] 900)
haftmann@25062
   591
haftmann@25062
   592
no_notation
haftmann@25062
   593
  Sup ("\<Squnion>_" [900] 900)
haftmann@25062
   594
haftmann@21249
   595
end