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