src/HOL/Lattices.thy
author haftmann
Thu Jan 28 11:48:43 2010 +0100 (2010-01-28)
changeset 34973 ae634fad947e
parent 34209 c7f621786035
child 35028 108662d50512
permissions -rw-r--r--
dropped mk_left_commute; use interpretation of locale abel_semigroup instead
haftmann@21249
     1
(*  Title:      HOL/Lattices.thy
haftmann@21249
     2
    Author:     Tobias Nipkow
haftmann@21249
     3
*)
haftmann@21249
     4
haftmann@22454
     5
header {* Abstract lattices *}
haftmann@21249
     6
haftmann@21249
     7
theory Lattices
haftmann@30302
     8
imports Orderings
haftmann@21249
     9
begin
haftmann@21249
    10
haftmann@28562
    11
subsection {* Lattices *}
haftmann@21249
    12
haftmann@25206
    13
notation
wenzelm@25382
    14
  less_eq  (infix "\<sqsubseteq>" 50) and
haftmann@32568
    15
  less  (infix "\<sqsubset>" 50) and
haftmann@32568
    16
  top ("\<top>") and
haftmann@32568
    17
  bot ("\<bottom>")
haftmann@25206
    18
haftmann@22422
    19
class lower_semilattice = order +
haftmann@21249
    20
  fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
haftmann@22737
    21
  assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
haftmann@22737
    22
  and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
nipkow@21733
    23
  and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
haftmann@21249
    24
haftmann@22422
    25
class upper_semilattice = order +
haftmann@21249
    26
  fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
haftmann@22737
    27
  assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
haftmann@22737
    28
  and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
nipkow@21733
    29
  and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
haftmann@26014
    30
begin
haftmann@26014
    31
haftmann@26014
    32
text {* Dual lattice *}
haftmann@26014
    33
haftmann@31991
    34
lemma dual_semilattice:
haftmann@26014
    35
  "lower_semilattice (op \<ge>) (op >) sup"
haftmann@27682
    36
by (rule lower_semilattice.intro, rule dual_order)
haftmann@27682
    37
  (unfold_locales, simp_all add: sup_least)
haftmann@26014
    38
haftmann@26014
    39
end
haftmann@21249
    40
haftmann@22422
    41
class lattice = lower_semilattice + upper_semilattice
haftmann@21249
    42
wenzelm@25382
    43
haftmann@28562
    44
subsubsection {* Intro and elim rules*}
nipkow@21733
    45
nipkow@21733
    46
context lower_semilattice
nipkow@21733
    47
begin
haftmann@21249
    48
haftmann@32064
    49
lemma le_infI1:
haftmann@32064
    50
  "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
haftmann@32064
    51
  by (rule order_trans) auto
haftmann@21249
    52
haftmann@32064
    53
lemma le_infI2:
haftmann@32064
    54
  "b \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
haftmann@32064
    55
  by (rule order_trans) auto
nipkow@21733
    56
haftmann@32064
    57
lemma le_infI: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
haftmann@32064
    58
  by (blast intro: inf_greatest)
haftmann@21249
    59
haftmann@32064
    60
lemma le_infE: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@32064
    61
  by (blast intro: order_trans le_infI1 le_infI2)
haftmann@21249
    62
nipkow@21734
    63
lemma le_inf_iff [simp]:
haftmann@32064
    64
  "x \<sqsubseteq> y \<sqinter> z \<longleftrightarrow> x \<sqsubseteq> y \<and> x \<sqsubseteq> z"
haftmann@32064
    65
  by (blast intro: le_infI elim: le_infE)
nipkow@21733
    66
haftmann@32064
    67
lemma le_iff_inf:
haftmann@32064
    68
  "x \<sqsubseteq> y \<longleftrightarrow> x \<sqinter> y = x"
haftmann@32064
    69
  by (auto intro: le_infI1 antisym dest: eq_iff [THEN iffD1])
haftmann@21249
    70
haftmann@25206
    71
lemma mono_inf:
haftmann@25206
    72
  fixes f :: "'a \<Rightarrow> 'b\<Colon>lower_semilattice"
haftmann@34007
    73
  shows "mono f \<Longrightarrow> f (A \<sqinter> B) \<sqsubseteq> f A \<sqinter> f B"
haftmann@25206
    74
  by (auto simp add: mono_def intro: Lattices.inf_greatest)
nipkow@21733
    75
haftmann@25206
    76
end
nipkow@21733
    77
nipkow@21733
    78
context upper_semilattice
nipkow@21733
    79
begin
haftmann@21249
    80
haftmann@32064
    81
lemma le_supI1:
haftmann@32064
    82
  "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
    83
  by (rule order_trans) auto
haftmann@21249
    84
haftmann@32064
    85
lemma le_supI2:
haftmann@32064
    86
  "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
    87
  by (rule order_trans) auto 
nipkow@21733
    88
haftmann@32064
    89
lemma le_supI:
haftmann@32064
    90
  "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
haftmann@26014
    91
  by (blast intro: sup_least)
haftmann@21249
    92
haftmann@32064
    93
lemma le_supE:
haftmann@32064
    94
  "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@32064
    95
  by (blast intro: le_supI1 le_supI2 order_trans)
haftmann@22422
    96
haftmann@32064
    97
lemma le_sup_iff [simp]:
haftmann@32064
    98
  "x \<squnion> y \<sqsubseteq> z \<longleftrightarrow> x \<sqsubseteq> z \<and> y \<sqsubseteq> z"
haftmann@32064
    99
  by (blast intro: le_supI elim: le_supE)
nipkow@21733
   100
haftmann@32064
   101
lemma le_iff_sup:
haftmann@32064
   102
  "x \<sqsubseteq> y \<longleftrightarrow> x \<squnion> y = y"
haftmann@32064
   103
  by (auto intro: le_supI2 antisym dest: eq_iff [THEN iffD1])
nipkow@21734
   104
haftmann@25206
   105
lemma mono_sup:
haftmann@25206
   106
  fixes f :: "'a \<Rightarrow> 'b\<Colon>upper_semilattice"
haftmann@34007
   107
  shows "mono f \<Longrightarrow> f A \<squnion> f B \<sqsubseteq> f (A \<squnion> B)"
haftmann@25206
   108
  by (auto simp add: mono_def intro: Lattices.sup_least)
nipkow@21733
   109
haftmann@25206
   110
end
haftmann@23878
   111
nipkow@21733
   112
haftmann@32064
   113
subsubsection {* Equational laws *}
haftmann@21249
   114
haftmann@34973
   115
sublocale lower_semilattice < inf!: semilattice inf
haftmann@34973
   116
proof
haftmann@34973
   117
  fix a b c
haftmann@34973
   118
  show "(a \<sqinter> b) \<sqinter> c = a \<sqinter> (b \<sqinter> c)"
haftmann@34973
   119
    by (rule antisym) (auto intro: le_infI1 le_infI2)
haftmann@34973
   120
  show "a \<sqinter> b = b \<sqinter> a"
haftmann@34973
   121
    by (rule antisym) auto
haftmann@34973
   122
  show "a \<sqinter> a = a"
haftmann@34973
   123
    by (rule antisym) auto
haftmann@34973
   124
qed
haftmann@34973
   125
nipkow@21733
   126
context lower_semilattice
nipkow@21733
   127
begin
nipkow@21733
   128
haftmann@34973
   129
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
haftmann@34973
   130
  by (fact inf.assoc)
nipkow@21733
   131
haftmann@34973
   132
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
haftmann@34973
   133
  by (fact inf.commute)
nipkow@21733
   134
haftmann@34973
   135
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
haftmann@34973
   136
  by (fact inf.left_commute)
nipkow@21733
   137
haftmann@34973
   138
lemma inf_idem: "x \<sqinter> x = x"
haftmann@34973
   139
  by (fact inf.idem)
haftmann@34973
   140
haftmann@34973
   141
lemma inf_left_idem: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
haftmann@34973
   142
  by (fact inf.left_idem)
nipkow@21733
   143
haftmann@32642
   144
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
haftmann@32064
   145
  by (rule antisym) auto
nipkow@21733
   146
haftmann@32642
   147
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
haftmann@32064
   148
  by (rule antisym) auto
haftmann@34973
   149
 
haftmann@32064
   150
lemmas inf_aci = inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@21733
   151
nipkow@21733
   152
end
nipkow@21733
   153
haftmann@34973
   154
sublocale upper_semilattice < sup!: semilattice sup
haftmann@34973
   155
proof
haftmann@34973
   156
  fix a b c
haftmann@34973
   157
  show "(a \<squnion> b) \<squnion> c = a \<squnion> (b \<squnion> c)"
haftmann@34973
   158
    by (rule antisym) (auto intro: le_supI1 le_supI2)
haftmann@34973
   159
  show "a \<squnion> b = b \<squnion> a"
haftmann@34973
   160
    by (rule antisym) auto
haftmann@34973
   161
  show "a \<squnion> a = a"
haftmann@34973
   162
    by (rule antisym) auto
haftmann@34973
   163
qed
haftmann@34973
   164
nipkow@21733
   165
context upper_semilattice
nipkow@21733
   166
begin
haftmann@21249
   167
haftmann@34973
   168
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
haftmann@34973
   169
  by (fact sup.assoc)
nipkow@21733
   170
haftmann@34973
   171
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
haftmann@34973
   172
  by (fact sup.commute)
nipkow@21733
   173
haftmann@34973
   174
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
haftmann@34973
   175
  by (fact sup.left_commute)
nipkow@21733
   176
haftmann@34973
   177
lemma sup_idem: "x \<squnion> x = x"
haftmann@34973
   178
  by (fact sup.idem)
haftmann@34973
   179
haftmann@34973
   180
lemma sup_left_idem: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
haftmann@34973
   181
  by (fact sup.left_idem)
nipkow@21733
   182
haftmann@32642
   183
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
haftmann@32064
   184
  by (rule antisym) auto
nipkow@21733
   185
haftmann@32642
   186
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
haftmann@32064
   187
  by (rule antisym) auto
haftmann@21249
   188
haftmann@32064
   189
lemmas sup_aci = sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@21733
   190
nipkow@21733
   191
end
haftmann@21249
   192
nipkow@21733
   193
context lattice
nipkow@21733
   194
begin
nipkow@21733
   195
haftmann@31991
   196
lemma dual_lattice:
haftmann@31991
   197
  "lattice (op \<ge>) (op >) sup inf"
haftmann@31991
   198
  by (rule lattice.intro, rule dual_semilattice, rule upper_semilattice.intro, rule dual_order)
haftmann@31991
   199
    (unfold_locales, auto)
haftmann@31991
   200
nipkow@21733
   201
lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
haftmann@25102
   202
  by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
nipkow@21733
   203
nipkow@21733
   204
lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
haftmann@25102
   205
  by (blast intro: antisym sup_ge1 sup_least inf_le1)
nipkow@21733
   206
haftmann@32064
   207
lemmas inf_sup_aci = inf_aci sup_aci
nipkow@21734
   208
haftmann@22454
   209
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
haftmann@22454
   210
nipkow@21734
   211
text{* Towards distributivity *}
haftmann@21249
   212
nipkow@21734
   213
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@32064
   214
  by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
nipkow@21734
   215
nipkow@21734
   216
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
haftmann@32064
   217
  by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
nipkow@21734
   218
nipkow@21734
   219
text{* If you have one of them, you have them all. *}
haftmann@21249
   220
nipkow@21733
   221
lemma distrib_imp1:
haftmann@21249
   222
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   223
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   224
proof-
haftmann@21249
   225
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
krauss@34209
   226
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc)
haftmann@21249
   227
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
haftmann@21249
   228
    by(simp add:inf_sup_absorb inf_commute)
haftmann@21249
   229
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   230
  finally show ?thesis .
haftmann@21249
   231
qed
haftmann@21249
   232
nipkow@21733
   233
lemma distrib_imp2:
haftmann@21249
   234
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   235
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   236
proof-
haftmann@21249
   237
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
krauss@34209
   238
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc)
haftmann@21249
   239
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
haftmann@21249
   240
    by(simp add:sup_inf_absorb sup_commute)
haftmann@21249
   241
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   242
  finally show ?thesis .
haftmann@21249
   243
qed
haftmann@21249
   244
nipkow@21733
   245
end
haftmann@21249
   246
haftmann@32568
   247
subsubsection {* Strict order *}
haftmann@32568
   248
haftmann@32568
   249
context lower_semilattice
haftmann@32568
   250
begin
haftmann@32568
   251
haftmann@32568
   252
lemma less_infI1:
haftmann@32568
   253
  "a \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   254
  by (auto simp add: less_le inf_absorb1 intro: le_infI1)
haftmann@32568
   255
haftmann@32568
   256
lemma less_infI2:
haftmann@32568
   257
  "b \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   258
  by (auto simp add: less_le inf_absorb2 intro: le_infI2)
haftmann@32568
   259
haftmann@32568
   260
end
haftmann@32568
   261
haftmann@32568
   262
context upper_semilattice
haftmann@32568
   263
begin
haftmann@32568
   264
haftmann@32568
   265
lemma less_supI1:
haftmann@34007
   266
  "x \<sqsubset> a \<Longrightarrow> x \<sqsubset> a \<squnion> b"
haftmann@32568
   267
proof -
haftmann@32568
   268
  interpret dual: lower_semilattice "op \<ge>" "op >" sup
haftmann@32568
   269
    by (fact dual_semilattice)
haftmann@34007
   270
  assume "x \<sqsubset> a"
haftmann@34007
   271
  then show "x \<sqsubset> a \<squnion> b"
haftmann@32568
   272
    by (fact dual.less_infI1)
haftmann@32568
   273
qed
haftmann@32568
   274
haftmann@32568
   275
lemma less_supI2:
haftmann@34007
   276
  "x \<sqsubset> b \<Longrightarrow> x \<sqsubset> a \<squnion> b"
haftmann@32568
   277
proof -
haftmann@32568
   278
  interpret dual: lower_semilattice "op \<ge>" "op >" sup
haftmann@32568
   279
    by (fact dual_semilattice)
haftmann@34007
   280
  assume "x \<sqsubset> b"
haftmann@34007
   281
  then show "x \<sqsubset> a \<squnion> b"
haftmann@32568
   282
    by (fact dual.less_infI2)
haftmann@32568
   283
qed
haftmann@32568
   284
haftmann@32568
   285
end
haftmann@32568
   286
haftmann@21249
   287
haftmann@24164
   288
subsection {* Distributive lattices *}
haftmann@21249
   289
haftmann@22454
   290
class distrib_lattice = lattice +
haftmann@21249
   291
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   292
nipkow@21733
   293
context distrib_lattice
nipkow@21733
   294
begin
nipkow@21733
   295
nipkow@21733
   296
lemma sup_inf_distrib2:
haftmann@21249
   297
 "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
haftmann@32064
   298
by(simp add: inf_sup_aci sup_inf_distrib1)
haftmann@21249
   299
nipkow@21733
   300
lemma inf_sup_distrib1:
haftmann@21249
   301
 "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   302
by(rule distrib_imp2[OF sup_inf_distrib1])
haftmann@21249
   303
nipkow@21733
   304
lemma inf_sup_distrib2:
haftmann@21249
   305
 "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
haftmann@32064
   306
by(simp add: inf_sup_aci inf_sup_distrib1)
haftmann@21249
   307
haftmann@31991
   308
lemma dual_distrib_lattice:
haftmann@31991
   309
  "distrib_lattice (op \<ge>) (op >) sup inf"
haftmann@31991
   310
  by (rule distrib_lattice.intro, rule dual_lattice)
haftmann@31991
   311
    (unfold_locales, fact inf_sup_distrib1)
haftmann@31991
   312
nipkow@21733
   313
lemmas distrib =
haftmann@21249
   314
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   315
nipkow@21733
   316
end
nipkow@21733
   317
haftmann@21249
   318
haftmann@34007
   319
subsection {* Bounded lattices and boolean algebras *}
haftmann@31991
   320
haftmann@34007
   321
class bounded_lattice = lattice + top + bot
haftmann@31991
   322
begin
haftmann@31991
   323
haftmann@34007
   324
lemma dual_bounded_lattice:
haftmann@34007
   325
  "bounded_lattice (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom>"
haftmann@34007
   326
  by (rule bounded_lattice.intro, rule dual_lattice)
haftmann@34007
   327
    (unfold_locales, auto simp add: less_le_not_le)
haftmann@31991
   328
haftmann@31991
   329
lemma inf_bot_left [simp]:
haftmann@34007
   330
  "\<bottom> \<sqinter> x = \<bottom>"
haftmann@31991
   331
  by (rule inf_absorb1) simp
haftmann@31991
   332
haftmann@31991
   333
lemma inf_bot_right [simp]:
haftmann@34007
   334
  "x \<sqinter> \<bottom> = \<bottom>"
haftmann@31991
   335
  by (rule inf_absorb2) simp
haftmann@31991
   336
haftmann@31991
   337
lemma sup_top_left [simp]:
haftmann@34007
   338
  "\<top> \<squnion> x = \<top>"
haftmann@31991
   339
  by (rule sup_absorb1) simp
haftmann@31991
   340
haftmann@31991
   341
lemma sup_top_right [simp]:
haftmann@34007
   342
  "x \<squnion> \<top> = \<top>"
haftmann@31991
   343
  by (rule sup_absorb2) simp
haftmann@31991
   344
haftmann@31991
   345
lemma inf_top_left [simp]:
haftmann@34007
   346
  "\<top> \<sqinter> x = x"
haftmann@31991
   347
  by (rule inf_absorb2) simp
haftmann@31991
   348
haftmann@31991
   349
lemma inf_top_right [simp]:
haftmann@34007
   350
  "x \<sqinter> \<top> = x"
haftmann@31991
   351
  by (rule inf_absorb1) simp
haftmann@31991
   352
haftmann@31991
   353
lemma sup_bot_left [simp]:
haftmann@34007
   354
  "\<bottom> \<squnion> x = x"
haftmann@31991
   355
  by (rule sup_absorb2) simp
haftmann@31991
   356
haftmann@31991
   357
lemma sup_bot_right [simp]:
haftmann@34007
   358
  "x \<squnion> \<bottom> = x"
haftmann@31991
   359
  by (rule sup_absorb1) simp
haftmann@31991
   360
haftmann@32568
   361
lemma inf_eq_top_eq1:
haftmann@32568
   362
  assumes "A \<sqinter> B = \<top>"
haftmann@32568
   363
  shows "A = \<top>"
haftmann@32568
   364
proof (cases "B = \<top>")
haftmann@32568
   365
  case True with assms show ?thesis by simp
haftmann@32568
   366
next
haftmann@34007
   367
  case False with top_greatest have "B \<sqsubset> \<top>" by (auto intro: neq_le_trans)
haftmann@34007
   368
  then have "A \<sqinter> B \<sqsubset> \<top>" by (rule less_infI2)
haftmann@32568
   369
  with assms show ?thesis by simp
haftmann@32568
   370
qed
haftmann@32568
   371
haftmann@32568
   372
lemma inf_eq_top_eq2:
haftmann@32568
   373
  assumes "A \<sqinter> B = \<top>"
haftmann@32568
   374
  shows "B = \<top>"
haftmann@32568
   375
  by (rule inf_eq_top_eq1, unfold inf_commute [of B]) (fact assms)
haftmann@32568
   376
haftmann@32568
   377
lemma sup_eq_bot_eq1:
haftmann@32568
   378
  assumes "A \<squnion> B = \<bottom>"
haftmann@32568
   379
  shows "A = \<bottom>"
haftmann@32568
   380
proof -
haftmann@34007
   381
  interpret dual: bounded_lattice "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
haftmann@34007
   382
    by (rule dual_bounded_lattice)
haftmann@32568
   383
  from dual.inf_eq_top_eq1 assms show ?thesis .
haftmann@32568
   384
qed
haftmann@32568
   385
haftmann@32568
   386
lemma sup_eq_bot_eq2:
haftmann@32568
   387
  assumes "A \<squnion> B = \<bottom>"
haftmann@32568
   388
  shows "B = \<bottom>"
haftmann@32568
   389
proof -
haftmann@34007
   390
  interpret dual: bounded_lattice "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
haftmann@34007
   391
    by (rule dual_bounded_lattice)
haftmann@32568
   392
  from dual.inf_eq_top_eq2 assms show ?thesis .
haftmann@32568
   393
qed
haftmann@32568
   394
haftmann@34007
   395
end
haftmann@34007
   396
haftmann@34007
   397
class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
haftmann@34007
   398
  assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
haftmann@34007
   399
    and sup_compl_top: "x \<squnion> - x = \<top>"
haftmann@34007
   400
  assumes diff_eq: "x - y = x \<sqinter> - y"
haftmann@34007
   401
begin
haftmann@34007
   402
haftmann@34007
   403
lemma dual_boolean_algebra:
haftmann@34007
   404
  "boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom>"
haftmann@34007
   405
  by (rule boolean_algebra.intro, rule dual_bounded_lattice, rule dual_distrib_lattice)
haftmann@34007
   406
    (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
haftmann@34007
   407
haftmann@34007
   408
lemma compl_inf_bot:
haftmann@34007
   409
  "- x \<sqinter> x = \<bottom>"
haftmann@34007
   410
  by (simp add: inf_commute inf_compl_bot)
haftmann@34007
   411
haftmann@34007
   412
lemma compl_sup_top:
haftmann@34007
   413
  "- x \<squnion> x = \<top>"
haftmann@34007
   414
  by (simp add: sup_commute sup_compl_top)
haftmann@34007
   415
haftmann@31991
   416
lemma compl_unique:
haftmann@34007
   417
  assumes "x \<sqinter> y = \<bottom>"
haftmann@34007
   418
    and "x \<squnion> y = \<top>"
haftmann@31991
   419
  shows "- x = y"
haftmann@31991
   420
proof -
haftmann@31991
   421
  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
haftmann@31991
   422
    using inf_compl_bot assms(1) by simp
haftmann@31991
   423
  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
haftmann@31991
   424
    by (simp add: inf_commute)
haftmann@31991
   425
  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
haftmann@31991
   426
    by (simp add: inf_sup_distrib1)
haftmann@34007
   427
  then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
haftmann@31991
   428
    using sup_compl_top assms(2) by simp
krauss@34209
   429
  then show "- x = y" by simp
haftmann@31991
   430
qed
haftmann@31991
   431
haftmann@31991
   432
lemma double_compl [simp]:
haftmann@31991
   433
  "- (- x) = x"
haftmann@31991
   434
  using compl_inf_bot compl_sup_top by (rule compl_unique)
haftmann@31991
   435
haftmann@31991
   436
lemma compl_eq_compl_iff [simp]:
haftmann@31991
   437
  "- x = - y \<longleftrightarrow> x = y"
haftmann@31991
   438
proof
haftmann@31991
   439
  assume "- x = - y"
haftmann@34007
   440
  then have "- x \<sqinter> y = \<bottom>"
haftmann@34007
   441
    and "- x \<squnion> y = \<top>"
haftmann@31991
   442
    by (simp_all add: compl_inf_bot compl_sup_top)
haftmann@31991
   443
  then have "- (- x) = y" by (rule compl_unique)
haftmann@31991
   444
  then show "x = y" by simp
haftmann@31991
   445
next
haftmann@31991
   446
  assume "x = y"
haftmann@31991
   447
  then show "- x = - y" by simp
haftmann@31991
   448
qed
haftmann@31991
   449
haftmann@31991
   450
lemma compl_bot_eq [simp]:
haftmann@34007
   451
  "- \<bottom> = \<top>"
haftmann@31991
   452
proof -
haftmann@34007
   453
  from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
haftmann@31991
   454
  then show ?thesis by simp
haftmann@31991
   455
qed
haftmann@31991
   456
haftmann@31991
   457
lemma compl_top_eq [simp]:
haftmann@34007
   458
  "- \<top> = \<bottom>"
haftmann@31991
   459
proof -
haftmann@34007
   460
  from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
haftmann@31991
   461
  then show ?thesis by simp
haftmann@31991
   462
qed
haftmann@31991
   463
haftmann@31991
   464
lemma compl_inf [simp]:
haftmann@31991
   465
  "- (x \<sqinter> y) = - x \<squnion> - y"
haftmann@31991
   466
proof (rule compl_unique)
haftmann@31991
   467
  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = ((x \<sqinter> y) \<sqinter> - x) \<squnion> ((x \<sqinter> y) \<sqinter> - y)"
haftmann@31991
   468
    by (rule inf_sup_distrib1)
haftmann@31991
   469
  also have "... = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
haftmann@31991
   470
    by (simp only: inf_commute inf_assoc inf_left_commute)
haftmann@34007
   471
  finally show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
haftmann@31991
   472
    by (simp add: inf_compl_bot)
haftmann@31991
   473
next
haftmann@31991
   474
  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (x \<squnion> (- x \<squnion> - y)) \<sqinter> (y \<squnion> (- x \<squnion> - y))"
haftmann@31991
   475
    by (rule sup_inf_distrib2)
haftmann@31991
   476
  also have "... = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
haftmann@31991
   477
    by (simp only: sup_commute sup_assoc sup_left_commute)
haftmann@34007
   478
  finally show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
haftmann@31991
   479
    by (simp add: sup_compl_top)
haftmann@31991
   480
qed
haftmann@31991
   481
haftmann@31991
   482
lemma compl_sup [simp]:
haftmann@31991
   483
  "- (x \<squnion> y) = - x \<sqinter> - y"
haftmann@31991
   484
proof -
haftmann@34007
   485
  interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
haftmann@31991
   486
    by (rule dual_boolean_algebra)
haftmann@31991
   487
  then show ?thesis by simp
haftmann@31991
   488
qed
haftmann@31991
   489
haftmann@31991
   490
end
haftmann@31991
   491
haftmann@31991
   492
haftmann@22454
   493
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   494
haftmann@22737
   495
lemma (in lower_semilattice) inf_unique:
haftmann@22454
   496
  fixes f (infixl "\<triangle>" 70)
haftmann@34007
   497
  assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
haftmann@34007
   498
  and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
haftmann@22737
   499
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   500
proof (rule antisym)
haftmann@34007
   501
  show "x \<triangle> y \<sqsubseteq> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   502
next
haftmann@34007
   503
  have leI: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z" by (blast intro: greatest)
haftmann@34007
   504
  show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   505
qed
haftmann@22454
   506
haftmann@22737
   507
lemma (in upper_semilattice) sup_unique:
haftmann@22454
   508
  fixes f (infixl "\<nabla>" 70)
haftmann@34007
   509
  assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
haftmann@34007
   510
  and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
haftmann@22737
   511
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   512
proof (rule antisym)
haftmann@34007
   513
  show "x \<squnion> y \<sqsubseteq> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   514
next
haftmann@34007
   515
  have leI: "\<And>x y z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<nabla> y \<sqsubseteq> z" by (blast intro: least)
haftmann@34007
   516
  show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   517
qed
haftmann@22454
   518
  
haftmann@22454
   519
haftmann@22916
   520
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   521
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   522
haftmann@32512
   523
sublocale linorder < min_max!: distrib_lattice less_eq less min max
haftmann@28823
   524
proof
haftmann@22916
   525
  fix x y z
haftmann@32512
   526
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@32512
   527
    by (auto simp add: min_def max_def)
haftmann@22916
   528
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   529
haftmann@22454
   530
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   531
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   532
haftmann@22454
   533
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   534
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   535
haftmann@21249
   536
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   537
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   538
 
haftmann@34973
   539
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@34973
   540
  min_max.inf.left_commute
haftmann@21249
   541
haftmann@34973
   542
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@34973
   543
  min_max.sup.left_commute
haftmann@34973
   544
haftmann@21249
   545
haftmann@22454
   546
haftmann@22454
   547
subsection {* Bool as lattice *}
haftmann@22454
   548
haftmann@31991
   549
instantiation bool :: boolean_algebra
haftmann@25510
   550
begin
haftmann@25510
   551
haftmann@25510
   552
definition
haftmann@31991
   553
  bool_Compl_def: "uminus = Not"
haftmann@31991
   554
haftmann@31991
   555
definition
haftmann@31991
   556
  bool_diff_def: "A - B \<longleftrightarrow> A \<and> \<not> B"
haftmann@31991
   557
haftmann@31991
   558
definition
haftmann@25510
   559
  inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
haftmann@25510
   560
haftmann@25510
   561
definition
haftmann@25510
   562
  sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
haftmann@25510
   563
haftmann@31991
   564
instance proof
haftmann@31991
   565
qed (simp_all add: inf_bool_eq sup_bool_eq le_bool_def
haftmann@31991
   566
  bot_bool_eq top_bool_eq bool_Compl_def bool_diff_def, auto)
haftmann@22454
   567
haftmann@25510
   568
end
haftmann@25510
   569
haftmann@32781
   570
lemma sup_boolI1:
haftmann@32781
   571
  "P \<Longrightarrow> P \<squnion> Q"
haftmann@32781
   572
  by (simp add: sup_bool_eq)
haftmann@32781
   573
haftmann@32781
   574
lemma sup_boolI2:
haftmann@32781
   575
  "Q \<Longrightarrow> P \<squnion> Q"
haftmann@32781
   576
  by (simp add: sup_bool_eq)
haftmann@32781
   577
haftmann@32781
   578
lemma sup_boolE:
haftmann@32781
   579
  "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@32781
   580
  by (auto simp add: sup_bool_eq)
haftmann@32781
   581
haftmann@23878
   582
haftmann@23878
   583
subsection {* Fun as lattice *}
haftmann@23878
   584
haftmann@25510
   585
instantiation "fun" :: (type, lattice) lattice
haftmann@25510
   586
begin
haftmann@25510
   587
haftmann@25510
   588
definition
haftmann@28562
   589
  inf_fun_eq [code del]: "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
haftmann@25510
   590
haftmann@25510
   591
definition
haftmann@28562
   592
  sup_fun_eq [code del]: "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
haftmann@25510
   593
haftmann@32780
   594
instance proof
haftmann@32780
   595
qed (simp_all add: le_fun_def inf_fun_eq sup_fun_eq)
haftmann@23878
   596
haftmann@25510
   597
end
haftmann@23878
   598
haftmann@23878
   599
instance "fun" :: (type, distrib_lattice) distrib_lattice
haftmann@31991
   600
proof
haftmann@32780
   601
qed (simp_all add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
haftmann@31991
   602
haftmann@34007
   603
instance "fun" :: (type, bounded_lattice) bounded_lattice ..
haftmann@34007
   604
haftmann@31991
   605
instantiation "fun" :: (type, uminus) uminus
haftmann@31991
   606
begin
haftmann@31991
   607
haftmann@31991
   608
definition
haftmann@31991
   609
  fun_Compl_def: "- A = (\<lambda>x. - A x)"
haftmann@31991
   610
haftmann@31991
   611
instance ..
haftmann@31991
   612
haftmann@31991
   613
end
haftmann@31991
   614
haftmann@31991
   615
instantiation "fun" :: (type, minus) minus
haftmann@31991
   616
begin
haftmann@31991
   617
haftmann@31991
   618
definition
haftmann@31991
   619
  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
haftmann@31991
   620
haftmann@31991
   621
instance ..
haftmann@31991
   622
haftmann@31991
   623
end
haftmann@31991
   624
haftmann@31991
   625
instance "fun" :: (type, boolean_algebra) boolean_algebra
haftmann@31991
   626
proof
haftmann@31991
   627
qed (simp_all add: inf_fun_eq sup_fun_eq bot_fun_eq top_fun_eq fun_Compl_def fun_diff_def
haftmann@31991
   628
  inf_compl_bot sup_compl_top diff_eq)
haftmann@23878
   629
berghofe@26794
   630
haftmann@25062
   631
no_notation
wenzelm@25382
   632
  less_eq  (infix "\<sqsubseteq>" 50) and
wenzelm@25382
   633
  less (infix "\<sqsubset>" 50) and
wenzelm@25382
   634
  inf  (infixl "\<sqinter>" 70) and
haftmann@32568
   635
  sup  (infixl "\<squnion>" 65) and
haftmann@32568
   636
  top ("\<top>") and
haftmann@32568
   637
  bot ("\<bottom>")
haftmann@25062
   638
haftmann@21249
   639
end