src/HOL/Lattices.thy
author ballarin
Mon Feb 15 01:27:06 2010 +0100 (2010-02-15)
changeset 36092 8f1e60d9f7cc
parent 34209 c7f621786035
child 36096 abc6a2ea4b88
permissions -rw-r--r--
Tuned interpretation proofs.
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>"
ballarin@36092
   304
  by unfold_locales (auto simp add: less_le_not_le)
haftmann@31991
   305
haftmann@31991
   306
lemma inf_bot_left [simp]:
haftmann@34007
   307
  "\<bottom> \<sqinter> x = \<bottom>"
haftmann@31991
   308
  by (rule inf_absorb1) simp
haftmann@31991
   309
haftmann@31991
   310
lemma inf_bot_right [simp]:
haftmann@34007
   311
  "x \<sqinter> \<bottom> = \<bottom>"
haftmann@31991
   312
  by (rule inf_absorb2) simp
haftmann@31991
   313
haftmann@31991
   314
lemma sup_top_left [simp]:
haftmann@34007
   315
  "\<top> \<squnion> x = \<top>"
haftmann@31991
   316
  by (rule sup_absorb1) simp
haftmann@31991
   317
haftmann@31991
   318
lemma sup_top_right [simp]:
haftmann@34007
   319
  "x \<squnion> \<top> = \<top>"
haftmann@31991
   320
  by (rule sup_absorb2) simp
haftmann@31991
   321
haftmann@31991
   322
lemma inf_top_left [simp]:
haftmann@34007
   323
  "\<top> \<sqinter> x = x"
haftmann@31991
   324
  by (rule inf_absorb2) simp
haftmann@31991
   325
haftmann@31991
   326
lemma inf_top_right [simp]:
haftmann@34007
   327
  "x \<sqinter> \<top> = x"
haftmann@31991
   328
  by (rule inf_absorb1) simp
haftmann@31991
   329
haftmann@31991
   330
lemma sup_bot_left [simp]:
haftmann@34007
   331
  "\<bottom> \<squnion> x = x"
haftmann@31991
   332
  by (rule sup_absorb2) simp
haftmann@31991
   333
haftmann@31991
   334
lemma sup_bot_right [simp]:
haftmann@34007
   335
  "x \<squnion> \<bottom> = x"
haftmann@31991
   336
  by (rule sup_absorb1) simp
haftmann@31991
   337
haftmann@32568
   338
lemma inf_eq_top_eq1:
haftmann@32568
   339
  assumes "A \<sqinter> B = \<top>"
haftmann@32568
   340
  shows "A = \<top>"
haftmann@32568
   341
proof (cases "B = \<top>")
haftmann@32568
   342
  case True with assms show ?thesis by simp
haftmann@32568
   343
next
haftmann@34007
   344
  case False with top_greatest have "B \<sqsubset> \<top>" by (auto intro: neq_le_trans)
haftmann@34007
   345
  then have "A \<sqinter> B \<sqsubset> \<top>" by (rule less_infI2)
haftmann@32568
   346
  with assms show ?thesis by simp
haftmann@32568
   347
qed
haftmann@32568
   348
haftmann@32568
   349
lemma inf_eq_top_eq2:
haftmann@32568
   350
  assumes "A \<sqinter> B = \<top>"
haftmann@32568
   351
  shows "B = \<top>"
haftmann@32568
   352
  by (rule inf_eq_top_eq1, unfold inf_commute [of B]) (fact assms)
haftmann@32568
   353
haftmann@32568
   354
lemma sup_eq_bot_eq1:
haftmann@32568
   355
  assumes "A \<squnion> B = \<bottom>"
haftmann@32568
   356
  shows "A = \<bottom>"
haftmann@32568
   357
proof -
haftmann@34007
   358
  interpret dual: bounded_lattice "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
haftmann@34007
   359
    by (rule dual_bounded_lattice)
haftmann@32568
   360
  from dual.inf_eq_top_eq1 assms show ?thesis .
haftmann@32568
   361
qed
haftmann@32568
   362
haftmann@32568
   363
lemma sup_eq_bot_eq2:
haftmann@32568
   364
  assumes "A \<squnion> B = \<bottom>"
haftmann@32568
   365
  shows "B = \<bottom>"
haftmann@32568
   366
proof -
haftmann@34007
   367
  interpret dual: bounded_lattice "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
haftmann@34007
   368
    by (rule dual_bounded_lattice)
haftmann@32568
   369
  from dual.inf_eq_top_eq2 assms show ?thesis .
haftmann@32568
   370
qed
haftmann@32568
   371
haftmann@34007
   372
end
haftmann@34007
   373
haftmann@34007
   374
class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
haftmann@34007
   375
  assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
haftmann@34007
   376
    and sup_compl_top: "x \<squnion> - x = \<top>"
haftmann@34007
   377
  assumes diff_eq: "x - y = x \<sqinter> - y"
haftmann@34007
   378
begin
haftmann@34007
   379
haftmann@34007
   380
lemma dual_boolean_algebra:
haftmann@34007
   381
  "boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom>"
haftmann@34007
   382
  by (rule boolean_algebra.intro, rule dual_bounded_lattice, rule dual_distrib_lattice)
haftmann@34007
   383
    (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
haftmann@34007
   384
haftmann@34007
   385
lemma compl_inf_bot:
haftmann@34007
   386
  "- x \<sqinter> x = \<bottom>"
haftmann@34007
   387
  by (simp add: inf_commute inf_compl_bot)
haftmann@34007
   388
haftmann@34007
   389
lemma compl_sup_top:
haftmann@34007
   390
  "- x \<squnion> x = \<top>"
haftmann@34007
   391
  by (simp add: sup_commute sup_compl_top)
haftmann@34007
   392
haftmann@31991
   393
lemma compl_unique:
haftmann@34007
   394
  assumes "x \<sqinter> y = \<bottom>"
haftmann@34007
   395
    and "x \<squnion> y = \<top>"
haftmann@31991
   396
  shows "- x = y"
haftmann@31991
   397
proof -
haftmann@31991
   398
  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
haftmann@31991
   399
    using inf_compl_bot assms(1) by simp
haftmann@31991
   400
  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
haftmann@31991
   401
    by (simp add: inf_commute)
haftmann@31991
   402
  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
haftmann@31991
   403
    by (simp add: inf_sup_distrib1)
haftmann@34007
   404
  then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
haftmann@31991
   405
    using sup_compl_top assms(2) by simp
krauss@34209
   406
  then show "- x = y" by simp
haftmann@31991
   407
qed
haftmann@31991
   408
haftmann@31991
   409
lemma double_compl [simp]:
haftmann@31991
   410
  "- (- x) = x"
haftmann@31991
   411
  using compl_inf_bot compl_sup_top by (rule compl_unique)
haftmann@31991
   412
haftmann@31991
   413
lemma compl_eq_compl_iff [simp]:
haftmann@31991
   414
  "- x = - y \<longleftrightarrow> x = y"
haftmann@31991
   415
proof
haftmann@31991
   416
  assume "- x = - y"
haftmann@34007
   417
  then have "- x \<sqinter> y = \<bottom>"
haftmann@34007
   418
    and "- x \<squnion> y = \<top>"
haftmann@31991
   419
    by (simp_all add: compl_inf_bot compl_sup_top)
haftmann@31991
   420
  then have "- (- x) = y" by (rule compl_unique)
haftmann@31991
   421
  then show "x = y" by simp
haftmann@31991
   422
next
haftmann@31991
   423
  assume "x = y"
haftmann@31991
   424
  then show "- x = - y" by simp
haftmann@31991
   425
qed
haftmann@31991
   426
haftmann@31991
   427
lemma compl_bot_eq [simp]:
haftmann@34007
   428
  "- \<bottom> = \<top>"
haftmann@31991
   429
proof -
haftmann@34007
   430
  from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
haftmann@31991
   431
  then show ?thesis by simp
haftmann@31991
   432
qed
haftmann@31991
   433
haftmann@31991
   434
lemma compl_top_eq [simp]:
haftmann@34007
   435
  "- \<top> = \<bottom>"
haftmann@31991
   436
proof -
haftmann@34007
   437
  from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
haftmann@31991
   438
  then show ?thesis by simp
haftmann@31991
   439
qed
haftmann@31991
   440
haftmann@31991
   441
lemma compl_inf [simp]:
haftmann@31991
   442
  "- (x \<sqinter> y) = - x \<squnion> - y"
haftmann@31991
   443
proof (rule compl_unique)
haftmann@31991
   444
  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = ((x \<sqinter> y) \<sqinter> - x) \<squnion> ((x \<sqinter> y) \<sqinter> - y)"
haftmann@31991
   445
    by (rule inf_sup_distrib1)
haftmann@31991
   446
  also have "... = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
haftmann@31991
   447
    by (simp only: inf_commute inf_assoc inf_left_commute)
haftmann@34007
   448
  finally show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
haftmann@31991
   449
    by (simp add: inf_compl_bot)
haftmann@31991
   450
next
haftmann@31991
   451
  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (x \<squnion> (- x \<squnion> - y)) \<sqinter> (y \<squnion> (- x \<squnion> - y))"
haftmann@31991
   452
    by (rule sup_inf_distrib2)
haftmann@31991
   453
  also have "... = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
haftmann@31991
   454
    by (simp only: sup_commute sup_assoc sup_left_commute)
haftmann@34007
   455
  finally show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
haftmann@31991
   456
    by (simp add: sup_compl_top)
haftmann@31991
   457
qed
haftmann@31991
   458
haftmann@31991
   459
lemma compl_sup [simp]:
haftmann@31991
   460
  "- (x \<squnion> y) = - x \<sqinter> - y"
haftmann@31991
   461
proof -
haftmann@34007
   462
  interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
haftmann@31991
   463
    by (rule dual_boolean_algebra)
haftmann@31991
   464
  then show ?thesis by simp
haftmann@31991
   465
qed
haftmann@31991
   466
haftmann@31991
   467
end
haftmann@31991
   468
haftmann@31991
   469
haftmann@22454
   470
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   471
haftmann@22737
   472
lemma (in lower_semilattice) inf_unique:
haftmann@22454
   473
  fixes f (infixl "\<triangle>" 70)
haftmann@34007
   474
  assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
haftmann@34007
   475
  and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
haftmann@22737
   476
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   477
proof (rule antisym)
haftmann@34007
   478
  show "x \<triangle> y \<sqsubseteq> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   479
next
haftmann@34007
   480
  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
   481
  show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   482
qed
haftmann@22454
   483
haftmann@22737
   484
lemma (in upper_semilattice) sup_unique:
haftmann@22454
   485
  fixes f (infixl "\<nabla>" 70)
haftmann@34007
   486
  assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
haftmann@34007
   487
  and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
haftmann@22737
   488
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   489
proof (rule antisym)
haftmann@34007
   490
  show "x \<squnion> y \<sqsubseteq> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   491
next
haftmann@34007
   492
  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
   493
  show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   494
qed
haftmann@22454
   495
  
haftmann@22454
   496
haftmann@22916
   497
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   498
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   499
haftmann@32512
   500
sublocale linorder < min_max!: distrib_lattice less_eq less min max
haftmann@28823
   501
proof
haftmann@22916
   502
  fix x y z
haftmann@32512
   503
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@32512
   504
    by (auto simp add: min_def max_def)
haftmann@22916
   505
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   506
haftmann@22454
   507
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   508
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   509
haftmann@22454
   510
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   511
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   512
haftmann@21249
   513
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   514
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   515
 
haftmann@21249
   516
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@22422
   517
  mk_left_commute [of max, OF min_max.sup_assoc min_max.sup_commute]
haftmann@21249
   518
haftmann@21249
   519
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@22422
   520
  mk_left_commute [of min, OF min_max.inf_assoc min_max.inf_commute]
haftmann@21249
   521
haftmann@22454
   522
haftmann@22454
   523
subsection {* Bool as lattice *}
haftmann@22454
   524
haftmann@31991
   525
instantiation bool :: boolean_algebra
haftmann@25510
   526
begin
haftmann@25510
   527
haftmann@25510
   528
definition
haftmann@31991
   529
  bool_Compl_def: "uminus = Not"
haftmann@31991
   530
haftmann@31991
   531
definition
haftmann@31991
   532
  bool_diff_def: "A - B \<longleftrightarrow> A \<and> \<not> B"
haftmann@31991
   533
haftmann@31991
   534
definition
haftmann@25510
   535
  inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
haftmann@25510
   536
haftmann@25510
   537
definition
haftmann@25510
   538
  sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
haftmann@25510
   539
haftmann@31991
   540
instance proof
haftmann@31991
   541
qed (simp_all add: inf_bool_eq sup_bool_eq le_bool_def
haftmann@31991
   542
  bot_bool_eq top_bool_eq bool_Compl_def bool_diff_def, auto)
haftmann@22454
   543
haftmann@25510
   544
end
haftmann@25510
   545
haftmann@32781
   546
lemma sup_boolI1:
haftmann@32781
   547
  "P \<Longrightarrow> P \<squnion> Q"
haftmann@32781
   548
  by (simp add: sup_bool_eq)
haftmann@32781
   549
haftmann@32781
   550
lemma sup_boolI2:
haftmann@32781
   551
  "Q \<Longrightarrow> P \<squnion> Q"
haftmann@32781
   552
  by (simp add: sup_bool_eq)
haftmann@32781
   553
haftmann@32781
   554
lemma sup_boolE:
haftmann@32781
   555
  "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@32781
   556
  by (auto simp add: sup_bool_eq)
haftmann@32781
   557
haftmann@23878
   558
haftmann@23878
   559
subsection {* Fun as lattice *}
haftmann@23878
   560
haftmann@25510
   561
instantiation "fun" :: (type, lattice) lattice
haftmann@25510
   562
begin
haftmann@25510
   563
haftmann@25510
   564
definition
haftmann@28562
   565
  inf_fun_eq [code del]: "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
haftmann@25510
   566
haftmann@25510
   567
definition
haftmann@28562
   568
  sup_fun_eq [code del]: "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
haftmann@25510
   569
haftmann@32780
   570
instance proof
haftmann@32780
   571
qed (simp_all add: le_fun_def inf_fun_eq sup_fun_eq)
haftmann@23878
   572
haftmann@25510
   573
end
haftmann@23878
   574
haftmann@23878
   575
instance "fun" :: (type, distrib_lattice) distrib_lattice
haftmann@31991
   576
proof
haftmann@32780
   577
qed (simp_all add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
haftmann@31991
   578
haftmann@34007
   579
instance "fun" :: (type, bounded_lattice) bounded_lattice ..
haftmann@34007
   580
haftmann@31991
   581
instantiation "fun" :: (type, uminus) uminus
haftmann@31991
   582
begin
haftmann@31991
   583
haftmann@31991
   584
definition
haftmann@31991
   585
  fun_Compl_def: "- A = (\<lambda>x. - A x)"
haftmann@31991
   586
haftmann@31991
   587
instance ..
haftmann@31991
   588
haftmann@31991
   589
end
haftmann@31991
   590
haftmann@31991
   591
instantiation "fun" :: (type, minus) minus
haftmann@31991
   592
begin
haftmann@31991
   593
haftmann@31991
   594
definition
haftmann@31991
   595
  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
haftmann@31991
   596
haftmann@31991
   597
instance ..
haftmann@31991
   598
haftmann@31991
   599
end
haftmann@31991
   600
haftmann@31991
   601
instance "fun" :: (type, boolean_algebra) boolean_algebra
haftmann@31991
   602
proof
haftmann@31991
   603
qed (simp_all add: inf_fun_eq sup_fun_eq bot_fun_eq top_fun_eq fun_Compl_def fun_diff_def
haftmann@31991
   604
  inf_compl_bot sup_compl_top diff_eq)
haftmann@23878
   605
berghofe@26794
   606
haftmann@25062
   607
no_notation
wenzelm@25382
   608
  less_eq  (infix "\<sqsubseteq>" 50) and
wenzelm@25382
   609
  less (infix "\<sqsubset>" 50) and
wenzelm@25382
   610
  inf  (infixl "\<sqinter>" 70) and
haftmann@32568
   611
  sup  (infixl "\<squnion>" 65) and
haftmann@32568
   612
  top ("\<top>") and
haftmann@32568
   613
  bot ("\<bottom>")
haftmann@25062
   614
haftmann@21249
   615
end