src/HOL/Lattices.thy
author haftmann
Sat Jul 11 21:33:01 2009 +0200 (2009-07-11)
changeset 31991 37390299214a
parent 30729 461ee3e49ad3
child 32063 2aab4f2af536
permissions -rw-r--r--
added boolean_algebra type class; tuned lattice duals
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
wenzelm@25382
    15
  less  (infix "\<sqsubset>" 50)
haftmann@25206
    16
haftmann@22422
    17
class lower_semilattice = order +
haftmann@21249
    18
  fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
haftmann@22737
    19
  assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
haftmann@22737
    20
  and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
nipkow@21733
    21
  and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
haftmann@21249
    22
haftmann@22422
    23
class upper_semilattice = order +
haftmann@21249
    24
  fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
haftmann@22737
    25
  assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
haftmann@22737
    26
  and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
nipkow@21733
    27
  and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
haftmann@26014
    28
begin
haftmann@26014
    29
haftmann@26014
    30
text {* Dual lattice *}
haftmann@26014
    31
haftmann@31991
    32
lemma dual_semilattice:
haftmann@26014
    33
  "lower_semilattice (op \<ge>) (op >) sup"
haftmann@27682
    34
by (rule lower_semilattice.intro, rule dual_order)
haftmann@27682
    35
  (unfold_locales, simp_all add: sup_least)
haftmann@26014
    36
haftmann@26014
    37
end
haftmann@21249
    38
haftmann@22422
    39
class lattice = lower_semilattice + upper_semilattice
haftmann@21249
    40
wenzelm@25382
    41
haftmann@28562
    42
subsubsection {* Intro and elim rules*}
nipkow@21733
    43
nipkow@21733
    44
context lower_semilattice
nipkow@21733
    45
begin
haftmann@21249
    46
haftmann@25062
    47
lemma le_infI1[intro]:
haftmann@25062
    48
  assumes "a \<sqsubseteq> x"
haftmann@25062
    49
  shows "a \<sqinter> b \<sqsubseteq> x"
haftmann@25062
    50
proof (rule order_trans)
haftmann@25482
    51
  from assms show "a \<sqsubseteq> x" .
haftmann@25482
    52
  show "a \<sqinter> b \<sqsubseteq> a" by simp 
haftmann@25062
    53
qed
haftmann@22422
    54
lemmas (in -) [rule del] = le_infI1
haftmann@21249
    55
haftmann@25062
    56
lemma le_infI2[intro]:
haftmann@25062
    57
  assumes "b \<sqsubseteq> x"
haftmann@25062
    58
  shows "a \<sqinter> b \<sqsubseteq> x"
haftmann@25062
    59
proof (rule order_trans)
haftmann@25482
    60
  from assms show "b \<sqsubseteq> x" .
haftmann@25482
    61
  show "a \<sqinter> b \<sqsubseteq> b" by simp
haftmann@25062
    62
qed
haftmann@22422
    63
lemmas (in -) [rule del] = le_infI2
nipkow@21733
    64
nipkow@21734
    65
lemma le_infI[intro!]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
nipkow@21733
    66
by(blast intro: inf_greatest)
haftmann@22422
    67
lemmas (in -) [rule del] = le_infI
haftmann@21249
    68
haftmann@22422
    69
lemma le_infE [elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22422
    70
  by (blast intro: order_trans)
haftmann@22422
    71
lemmas (in -) [rule del] = le_infE
haftmann@21249
    72
nipkow@21734
    73
lemma le_inf_iff [simp]:
haftmann@25102
    74
  "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
nipkow@21733
    75
by blast
nipkow@21733
    76
nipkow@21734
    77
lemma le_iff_inf: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)"
haftmann@25102
    78
  by (blast intro: antisym dest: eq_iff [THEN iffD1])
haftmann@21249
    79
haftmann@25206
    80
lemma mono_inf:
haftmann@25206
    81
  fixes f :: "'a \<Rightarrow> 'b\<Colon>lower_semilattice"
haftmann@25206
    82
  shows "mono f \<Longrightarrow> f (A \<sqinter> B) \<le> f A \<sqinter> f B"
haftmann@25206
    83
  by (auto simp add: mono_def intro: Lattices.inf_greatest)
nipkow@21733
    84
haftmann@25206
    85
end
nipkow@21733
    86
nipkow@21733
    87
context upper_semilattice
nipkow@21733
    88
begin
haftmann@21249
    89
nipkow@21734
    90
lemma le_supI1[intro]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
    91
  by (rule order_trans) auto
haftmann@22422
    92
lemmas (in -) [rule del] = le_supI1
haftmann@21249
    93
nipkow@21734
    94
lemma le_supI2[intro]: "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
    95
  by (rule order_trans) auto 
haftmann@22422
    96
lemmas (in -) [rule del] = le_supI2
nipkow@21733
    97
nipkow@21734
    98
lemma le_supI[intro!]: "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
haftmann@26014
    99
  by (blast intro: sup_least)
haftmann@22422
   100
lemmas (in -) [rule del] = le_supI
haftmann@21249
   101
nipkow@21734
   102
lemma le_supE[elim!]: "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22422
   103
  by (blast intro: order_trans)
haftmann@22422
   104
lemmas (in -) [rule del] = le_supE
haftmann@22422
   105
nipkow@21734
   106
lemma ge_sup_conv[simp]:
haftmann@25102
   107
  "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
nipkow@21733
   108
by blast
nipkow@21733
   109
nipkow@21734
   110
lemma le_iff_sup: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
haftmann@25102
   111
  by (blast intro: antisym dest: eq_iff [THEN iffD1])
nipkow@21734
   112
haftmann@25206
   113
lemma mono_sup:
haftmann@25206
   114
  fixes f :: "'a \<Rightarrow> 'b\<Colon>upper_semilattice"
haftmann@25206
   115
  shows "mono f \<Longrightarrow> f A \<squnion> f B \<le> f (A \<squnion> B)"
haftmann@25206
   116
  by (auto simp add: mono_def intro: Lattices.sup_least)
nipkow@21733
   117
haftmann@25206
   118
end
haftmann@23878
   119
nipkow@21733
   120
nipkow@21733
   121
subsubsection{* Equational laws *}
haftmann@21249
   122
nipkow@21733
   123
context lower_semilattice
nipkow@21733
   124
begin
nipkow@21733
   125
nipkow@21733
   126
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
haftmann@25102
   127
  by (blast intro: antisym)
nipkow@21733
   128
nipkow@21733
   129
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
haftmann@25102
   130
  by (blast intro: antisym)
nipkow@21733
   131
nipkow@21733
   132
lemma inf_idem[simp]: "x \<sqinter> x = x"
haftmann@25102
   133
  by (blast intro: antisym)
nipkow@21733
   134
nipkow@21733
   135
lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
haftmann@25102
   136
  by (blast intro: antisym)
nipkow@21733
   137
nipkow@21733
   138
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
haftmann@25102
   139
  by (blast intro: antisym)
nipkow@21733
   140
nipkow@21733
   141
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
haftmann@25102
   142
  by (blast intro: antisym)
nipkow@21733
   143
nipkow@21733
   144
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
haftmann@25102
   145
  by (blast intro: antisym)
nipkow@21733
   146
nipkow@21733
   147
lemmas inf_ACI = inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@21733
   148
nipkow@21733
   149
end
nipkow@21733
   150
nipkow@21733
   151
nipkow@21733
   152
context upper_semilattice
nipkow@21733
   153
begin
haftmann@21249
   154
nipkow@21733
   155
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
haftmann@25102
   156
  by (blast intro: antisym)
nipkow@21733
   157
nipkow@21733
   158
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
haftmann@25102
   159
  by (blast intro: antisym)
nipkow@21733
   160
nipkow@21733
   161
lemma sup_idem[simp]: "x \<squnion> x = x"
haftmann@25102
   162
  by (blast intro: antisym)
nipkow@21733
   163
nipkow@21733
   164
lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
haftmann@25102
   165
  by (blast intro: antisym)
nipkow@21733
   166
nipkow@21733
   167
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
haftmann@25102
   168
  by (blast intro: antisym)
nipkow@21733
   169
nipkow@21733
   170
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
haftmann@25102
   171
  by (blast intro: antisym)
haftmann@21249
   172
nipkow@21733
   173
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
haftmann@25102
   174
  by (blast intro: antisym)
nipkow@21733
   175
nipkow@21733
   176
lemmas sup_ACI = sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@21733
   177
nipkow@21733
   178
end
haftmann@21249
   179
nipkow@21733
   180
context lattice
nipkow@21733
   181
begin
nipkow@21733
   182
haftmann@31991
   183
lemma dual_lattice:
haftmann@31991
   184
  "lattice (op \<ge>) (op >) sup inf"
haftmann@31991
   185
  by (rule lattice.intro, rule dual_semilattice, rule upper_semilattice.intro, rule dual_order)
haftmann@31991
   186
    (unfold_locales, auto)
haftmann@31991
   187
nipkow@21733
   188
lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
haftmann@25102
   189
  by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
nipkow@21733
   190
nipkow@21733
   191
lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
haftmann@25102
   192
  by (blast intro: antisym sup_ge1 sup_least inf_le1)
nipkow@21733
   193
nipkow@21734
   194
lemmas ACI = inf_ACI sup_ACI
nipkow@21734
   195
haftmann@22454
   196
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
haftmann@22454
   197
nipkow@21734
   198
text{* Towards distributivity *}
haftmann@21249
   199
nipkow@21734
   200
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@25102
   201
  by blast
nipkow@21734
   202
nipkow@21734
   203
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
haftmann@25102
   204
  by blast
nipkow@21734
   205
nipkow@21734
   206
nipkow@21734
   207
text{* If you have one of them, you have them all. *}
haftmann@21249
   208
nipkow@21733
   209
lemma distrib_imp1:
haftmann@21249
   210
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   211
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   212
proof-
haftmann@21249
   213
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
haftmann@21249
   214
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc)
haftmann@21249
   215
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
haftmann@21249
   216
    by(simp add:inf_sup_absorb inf_commute)
haftmann@21249
   217
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   218
  finally show ?thesis .
haftmann@21249
   219
qed
haftmann@21249
   220
nipkow@21733
   221
lemma distrib_imp2:
haftmann@21249
   222
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   223
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   224
proof-
haftmann@21249
   225
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
haftmann@21249
   226
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc)
haftmann@21249
   227
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
haftmann@21249
   228
    by(simp add:sup_inf_absorb sup_commute)
haftmann@21249
   229
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   230
  finally show ?thesis .
haftmann@21249
   231
qed
haftmann@21249
   232
nipkow@21734
   233
(* seems unused *)
nipkow@21734
   234
lemma modular_le: "x \<sqsubseteq> z \<Longrightarrow> x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> z"
nipkow@21734
   235
by blast
nipkow@21734
   236
nipkow@21733
   237
end
haftmann@21249
   238
haftmann@21249
   239
haftmann@24164
   240
subsection {* Distributive lattices *}
haftmann@21249
   241
haftmann@22454
   242
class distrib_lattice = lattice +
haftmann@21249
   243
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   244
nipkow@21733
   245
context distrib_lattice
nipkow@21733
   246
begin
nipkow@21733
   247
nipkow@21733
   248
lemma sup_inf_distrib2:
haftmann@21249
   249
 "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
haftmann@21249
   250
by(simp add:ACI sup_inf_distrib1)
haftmann@21249
   251
nipkow@21733
   252
lemma inf_sup_distrib1:
haftmann@21249
   253
 "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   254
by(rule distrib_imp2[OF sup_inf_distrib1])
haftmann@21249
   255
nipkow@21733
   256
lemma inf_sup_distrib2:
haftmann@21249
   257
 "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
haftmann@21249
   258
by(simp add:ACI inf_sup_distrib1)
haftmann@21249
   259
haftmann@31991
   260
lemma dual_distrib_lattice:
haftmann@31991
   261
  "distrib_lattice (op \<ge>) (op >) sup inf"
haftmann@31991
   262
  by (rule distrib_lattice.intro, rule dual_lattice)
haftmann@31991
   263
    (unfold_locales, fact inf_sup_distrib1)
haftmann@31991
   264
nipkow@21733
   265
lemmas distrib =
haftmann@21249
   266
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   267
nipkow@21733
   268
end
nipkow@21733
   269
haftmann@21249
   270
haftmann@31991
   271
subsection {* Boolean algebras *}
haftmann@31991
   272
haftmann@31991
   273
class boolean_algebra = distrib_lattice + top + bot + minus + uminus +
haftmann@31991
   274
  assumes inf_compl_bot: "x \<sqinter> - x = bot"
haftmann@31991
   275
    and sup_compl_top: "x \<squnion> - x = top"
haftmann@31991
   276
  assumes diff_eq: "x - y = x \<sqinter> - y"
haftmann@31991
   277
begin
haftmann@31991
   278
haftmann@31991
   279
lemma dual_boolean_algebra:
haftmann@31991
   280
  "boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) top bot"
haftmann@31991
   281
  by (rule boolean_algebra.intro, rule dual_distrib_lattice)
haftmann@31991
   282
    (unfold_locales,
haftmann@31991
   283
      auto simp add: inf_compl_bot sup_compl_top diff_eq less_le_not_le)
haftmann@31991
   284
haftmann@31991
   285
lemma compl_inf_bot:
haftmann@31991
   286
  "- x \<sqinter> x = bot"
haftmann@31991
   287
  by (simp add: inf_commute inf_compl_bot)
haftmann@31991
   288
haftmann@31991
   289
lemma compl_sup_top:
haftmann@31991
   290
  "- x \<squnion> x = top"
haftmann@31991
   291
  by (simp add: sup_commute sup_compl_top)
haftmann@31991
   292
haftmann@31991
   293
lemma inf_bot_left [simp]:
haftmann@31991
   294
  "bot \<sqinter> x = bot"
haftmann@31991
   295
  by (rule inf_absorb1) simp
haftmann@31991
   296
haftmann@31991
   297
lemma inf_bot_right [simp]:
haftmann@31991
   298
  "x \<sqinter> bot = bot"
haftmann@31991
   299
  by (rule inf_absorb2) simp
haftmann@31991
   300
haftmann@31991
   301
lemma sup_top_left [simp]:
haftmann@31991
   302
  "top \<squnion> x = top"
haftmann@31991
   303
  by (rule sup_absorb1) simp
haftmann@31991
   304
haftmann@31991
   305
lemma sup_top_right [simp]:
haftmann@31991
   306
  "x \<squnion> top = top"
haftmann@31991
   307
  by (rule sup_absorb2) simp
haftmann@31991
   308
haftmann@31991
   309
lemma inf_top_left [simp]:
haftmann@31991
   310
  "top \<sqinter> x = x"
haftmann@31991
   311
  by (rule inf_absorb2) simp
haftmann@31991
   312
haftmann@31991
   313
lemma inf_top_right [simp]:
haftmann@31991
   314
  "x \<sqinter> top = x"
haftmann@31991
   315
  by (rule inf_absorb1) simp
haftmann@31991
   316
haftmann@31991
   317
lemma sup_bot_left [simp]:
haftmann@31991
   318
  "bot \<squnion> x = x"
haftmann@31991
   319
  by (rule sup_absorb2) simp
haftmann@31991
   320
haftmann@31991
   321
lemma sup_bot_right [simp]:
haftmann@31991
   322
  "x \<squnion> bot = x"
haftmann@31991
   323
  by (rule sup_absorb1) simp
haftmann@31991
   324
haftmann@31991
   325
lemma compl_unique:
haftmann@31991
   326
  assumes "x \<sqinter> y = bot"
haftmann@31991
   327
    and "x \<squnion> y = top"
haftmann@31991
   328
  shows "- x = y"
haftmann@31991
   329
proof -
haftmann@31991
   330
  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
haftmann@31991
   331
    using inf_compl_bot assms(1) by simp
haftmann@31991
   332
  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
haftmann@31991
   333
    by (simp add: inf_commute)
haftmann@31991
   334
  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
haftmann@31991
   335
    by (simp add: inf_sup_distrib1)
haftmann@31991
   336
  then have "- x \<sqinter> top = y \<sqinter> top"
haftmann@31991
   337
    using sup_compl_top assms(2) by simp
haftmann@31991
   338
  then show "- x = y" by (simp add: inf_top_right)
haftmann@31991
   339
qed
haftmann@31991
   340
haftmann@31991
   341
lemma double_compl [simp]:
haftmann@31991
   342
  "- (- x) = x"
haftmann@31991
   343
  using compl_inf_bot compl_sup_top by (rule compl_unique)
haftmann@31991
   344
haftmann@31991
   345
lemma compl_eq_compl_iff [simp]:
haftmann@31991
   346
  "- x = - y \<longleftrightarrow> x = y"
haftmann@31991
   347
proof
haftmann@31991
   348
  assume "- x = - y"
haftmann@31991
   349
  then have "- x \<sqinter> y = bot"
haftmann@31991
   350
    and "- x \<squnion> y = top"
haftmann@31991
   351
    by (simp_all add: compl_inf_bot compl_sup_top)
haftmann@31991
   352
  then have "- (- x) = y" by (rule compl_unique)
haftmann@31991
   353
  then show "x = y" by simp
haftmann@31991
   354
next
haftmann@31991
   355
  assume "x = y"
haftmann@31991
   356
  then show "- x = - y" by simp
haftmann@31991
   357
qed
haftmann@31991
   358
haftmann@31991
   359
lemma compl_bot_eq [simp]:
haftmann@31991
   360
  "- bot = top"
haftmann@31991
   361
proof -
haftmann@31991
   362
  from sup_compl_top have "bot \<squnion> - bot = top" .
haftmann@31991
   363
  then show ?thesis by simp
haftmann@31991
   364
qed
haftmann@31991
   365
haftmann@31991
   366
lemma compl_top_eq [simp]:
haftmann@31991
   367
  "- top = bot"
haftmann@31991
   368
proof -
haftmann@31991
   369
  from inf_compl_bot have "top \<sqinter> - top = bot" .
haftmann@31991
   370
  then show ?thesis by simp
haftmann@31991
   371
qed
haftmann@31991
   372
haftmann@31991
   373
lemma compl_inf [simp]:
haftmann@31991
   374
  "- (x \<sqinter> y) = - x \<squnion> - y"
haftmann@31991
   375
proof (rule compl_unique)
haftmann@31991
   376
  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = ((x \<sqinter> y) \<sqinter> - x) \<squnion> ((x \<sqinter> y) \<sqinter> - y)"
haftmann@31991
   377
    by (rule inf_sup_distrib1)
haftmann@31991
   378
  also have "... = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
haftmann@31991
   379
    by (simp only: inf_commute inf_assoc inf_left_commute)
haftmann@31991
   380
  finally show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = bot"
haftmann@31991
   381
    by (simp add: inf_compl_bot)
haftmann@31991
   382
next
haftmann@31991
   383
  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (x \<squnion> (- x \<squnion> - y)) \<sqinter> (y \<squnion> (- x \<squnion> - y))"
haftmann@31991
   384
    by (rule sup_inf_distrib2)
haftmann@31991
   385
  also have "... = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
haftmann@31991
   386
    by (simp only: sup_commute sup_assoc sup_left_commute)
haftmann@31991
   387
  finally show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = top"
haftmann@31991
   388
    by (simp add: sup_compl_top)
haftmann@31991
   389
qed
haftmann@31991
   390
haftmann@31991
   391
lemma compl_sup [simp]:
haftmann@31991
   392
  "- (x \<squnion> y) = - x \<sqinter> - y"
haftmann@31991
   393
proof -
haftmann@31991
   394
  interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" top bot
haftmann@31991
   395
    by (rule dual_boolean_algebra)
haftmann@31991
   396
  then show ?thesis by simp
haftmann@31991
   397
qed
haftmann@31991
   398
haftmann@31991
   399
end
haftmann@31991
   400
haftmann@31991
   401
haftmann@22454
   402
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   403
haftmann@22737
   404
lemma (in lower_semilattice) inf_unique:
haftmann@22454
   405
  fixes f (infixl "\<triangle>" 70)
haftmann@25062
   406
  assumes le1: "\<And>x y. x \<triangle> y \<le> x" and le2: "\<And>x y. x \<triangle> y \<le> y"
haftmann@25062
   407
  and greatest: "\<And>x y z. x \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> y \<triangle> z"
haftmann@22737
   408
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   409
proof (rule antisym)
haftmann@25062
   410
  show "x \<triangle> y \<le> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   411
next
haftmann@25062
   412
  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
   413
  show "x \<sqinter> y \<le> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   414
qed
haftmann@22454
   415
haftmann@22737
   416
lemma (in upper_semilattice) sup_unique:
haftmann@22454
   417
  fixes f (infixl "\<nabla>" 70)
haftmann@25062
   418
  assumes ge1 [simp]: "\<And>x y. x \<le> x \<nabla> y" and ge2: "\<And>x y. y \<le> x \<nabla> y"
haftmann@25062
   419
  and least: "\<And>x y z. y \<le> x \<Longrightarrow> z \<le> x \<Longrightarrow> y \<nabla> z \<le> x"
haftmann@22737
   420
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   421
proof (rule antisym)
haftmann@25062
   422
  show "x \<squnion> y \<le> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   423
next
haftmann@25062
   424
  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
   425
  show "x \<nabla> y \<le> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   426
qed
haftmann@22454
   427
  
haftmann@22454
   428
haftmann@22916
   429
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   430
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   431
haftmann@22916
   432
lemma (in linorder) distrib_lattice_min_max:
haftmann@25062
   433
  "distrib_lattice (op \<le>) (op <) min max"
haftmann@28823
   434
proof
haftmann@25062
   435
  have aux: "\<And>x y \<Colon> 'a. x < y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
haftmann@22916
   436
    by (auto simp add: less_le antisym)
haftmann@22916
   437
  fix x y z
haftmann@22916
   438
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@22916
   439
  unfolding min_def max_def
ballarin@24640
   440
  by auto
haftmann@22916
   441
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   442
wenzelm@30729
   443
interpretation min_max: distrib_lattice "op \<le> :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> bool" "op <" min max
haftmann@23948
   444
  by (rule distrib_lattice_min_max)
haftmann@21249
   445
haftmann@22454
   446
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   447
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   448
haftmann@22454
   449
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   450
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   451
haftmann@21249
   452
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   453
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   454
 
haftmann@21249
   455
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@22422
   456
  mk_left_commute [of max, OF min_max.sup_assoc min_max.sup_commute]
haftmann@21249
   457
haftmann@21249
   458
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@22422
   459
  mk_left_commute [of min, OF min_max.inf_assoc min_max.inf_commute]
haftmann@21249
   460
haftmann@22454
   461
text {*
haftmann@22454
   462
  Now we have inherited antisymmetry as an intro-rule on all
haftmann@22454
   463
  linear orders. This is a problem because it applies to bool, which is
haftmann@22454
   464
  undesirable.
haftmann@22454
   465
*}
haftmann@22454
   466
haftmann@25102
   467
lemmas [rule del] = min_max.le_infI min_max.le_supI
haftmann@22454
   468
  min_max.le_supE min_max.le_infE min_max.le_supI1 min_max.le_supI2
haftmann@22454
   469
  min_max.le_infI1 min_max.le_infI2
haftmann@22454
   470
haftmann@22454
   471
haftmann@22454
   472
subsection {* Bool as lattice *}
haftmann@22454
   473
haftmann@31991
   474
instantiation bool :: boolean_algebra
haftmann@25510
   475
begin
haftmann@25510
   476
haftmann@25510
   477
definition
haftmann@31991
   478
  bool_Compl_def: "uminus = Not"
haftmann@31991
   479
haftmann@31991
   480
definition
haftmann@31991
   481
  bool_diff_def: "A - B \<longleftrightarrow> A \<and> \<not> B"
haftmann@31991
   482
haftmann@31991
   483
definition
haftmann@25510
   484
  inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
haftmann@25510
   485
haftmann@25510
   486
definition
haftmann@25510
   487
  sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
haftmann@25510
   488
haftmann@31991
   489
instance proof
haftmann@31991
   490
qed (simp_all add: inf_bool_eq sup_bool_eq le_bool_def
haftmann@31991
   491
  bot_bool_eq top_bool_eq bool_Compl_def bool_diff_def, auto)
haftmann@22454
   492
haftmann@25510
   493
end
haftmann@25510
   494
haftmann@23878
   495
haftmann@23878
   496
subsection {* Fun as lattice *}
haftmann@23878
   497
haftmann@25510
   498
instantiation "fun" :: (type, lattice) lattice
haftmann@25510
   499
begin
haftmann@25510
   500
haftmann@25510
   501
definition
haftmann@28562
   502
  inf_fun_eq [code del]: "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
haftmann@25510
   503
haftmann@25510
   504
definition
haftmann@28562
   505
  sup_fun_eq [code del]: "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
haftmann@25510
   506
haftmann@25510
   507
instance
haftmann@23878
   508
apply intro_classes
haftmann@23878
   509
unfolding inf_fun_eq sup_fun_eq
haftmann@23878
   510
apply (auto intro: le_funI)
haftmann@23878
   511
apply (rule le_funI)
haftmann@23878
   512
apply (auto dest: le_funD)
haftmann@23878
   513
apply (rule le_funI)
haftmann@23878
   514
apply (auto dest: le_funD)
haftmann@23878
   515
done
haftmann@23878
   516
haftmann@25510
   517
end
haftmann@23878
   518
haftmann@23878
   519
instance "fun" :: (type, distrib_lattice) distrib_lattice
haftmann@31991
   520
proof
haftmann@31991
   521
qed (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
haftmann@31991
   522
haftmann@31991
   523
instantiation "fun" :: (type, uminus) uminus
haftmann@31991
   524
begin
haftmann@31991
   525
haftmann@31991
   526
definition
haftmann@31991
   527
  fun_Compl_def: "- A = (\<lambda>x. - A x)"
haftmann@31991
   528
haftmann@31991
   529
instance ..
haftmann@31991
   530
haftmann@31991
   531
end
haftmann@31991
   532
haftmann@31991
   533
instantiation "fun" :: (type, minus) minus
haftmann@31991
   534
begin
haftmann@31991
   535
haftmann@31991
   536
definition
haftmann@31991
   537
  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
haftmann@31991
   538
haftmann@31991
   539
instance ..
haftmann@31991
   540
haftmann@31991
   541
end
haftmann@31991
   542
haftmann@31991
   543
instance "fun" :: (type, boolean_algebra) boolean_algebra
haftmann@31991
   544
proof
haftmann@31991
   545
qed (simp_all add: inf_fun_eq sup_fun_eq bot_fun_eq top_fun_eq fun_Compl_def fun_diff_def
haftmann@31991
   546
  inf_compl_bot sup_compl_top diff_eq)
haftmann@23878
   547
berghofe@26794
   548
haftmann@23878
   549
text {* redundant bindings *}
haftmann@22454
   550
haftmann@22454
   551
lemmas inf_aci = inf_ACI
haftmann@22454
   552
lemmas sup_aci = sup_ACI
haftmann@22454
   553
haftmann@25062
   554
no_notation
wenzelm@25382
   555
  less_eq  (infix "\<sqsubseteq>" 50) and
wenzelm@25382
   556
  less (infix "\<sqsubset>" 50) and
wenzelm@25382
   557
  inf  (infixl "\<sqinter>" 70) and
haftmann@30302
   558
  sup  (infixl "\<squnion>" 65)
haftmann@25062
   559
haftmann@21249
   560
end