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