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