src/HOL/Lattices.thy
author haftmann
Wed Dec 08 14:52:23 2010 +0100 (2010-12-08)
changeset 41080 294956ff285b
parent 41075 4bed56dc95fb
child 41082 9ff94e7cc3b3
permissions -rw-r--r--
nice syntax for lattice INFI, SUPR;
various *_apply rules for lattice operations on fun;
more default simplification rules
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@36635
    70
  "class.semilattice_inf (op \<ge>) (op >) sup"
haftmann@36635
    71
by (rule class.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"
huffman@36008
    93
  by (rule inf_greatest) (* FIXME: duplicate lemma *)
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"
huffman@36008
    96
  by (blast intro: order_trans inf_le1 inf_le2)
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
huffman@36008
   106
lemma inf_mono: "a \<sqsubseteq> c \<Longrightarrow> b \<le> d \<Longrightarrow> a \<sqinter> b \<sqsubseteq> c \<sqinter> d"
huffman@36008
   107
  by (fast intro: inf_greatest le_infI1 le_infI2)
huffman@36008
   108
haftmann@25206
   109
lemma mono_inf:
haftmann@35028
   110
  fixes f :: "'a \<Rightarrow> 'b\<Colon>semilattice_inf"
haftmann@34007
   111
  shows "mono f \<Longrightarrow> f (A \<sqinter> B) \<sqsubseteq> f A \<sqinter> f B"
haftmann@25206
   112
  by (auto simp add: mono_def intro: Lattices.inf_greatest)
nipkow@21733
   113
haftmann@25206
   114
end
nipkow@21733
   115
haftmann@35028
   116
context semilattice_sup
nipkow@21733
   117
begin
haftmann@21249
   118
haftmann@32064
   119
lemma le_supI1:
haftmann@32064
   120
  "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
   121
  by (rule order_trans) auto
haftmann@21249
   122
haftmann@32064
   123
lemma le_supI2:
haftmann@32064
   124
  "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
   125
  by (rule order_trans) auto 
nipkow@21733
   126
haftmann@32064
   127
lemma le_supI:
haftmann@32064
   128
  "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
huffman@36008
   129
  by (rule sup_least) (* FIXME: duplicate lemma *)
haftmann@21249
   130
haftmann@32064
   131
lemma le_supE:
haftmann@32064
   132
  "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
huffman@36008
   133
  by (blast intro: order_trans sup_ge1 sup_ge2)
haftmann@22422
   134
haftmann@32064
   135
lemma le_sup_iff [simp]:
haftmann@32064
   136
  "x \<squnion> y \<sqsubseteq> z \<longleftrightarrow> x \<sqsubseteq> z \<and> y \<sqsubseteq> z"
haftmann@32064
   137
  by (blast intro: le_supI elim: le_supE)
nipkow@21733
   138
haftmann@32064
   139
lemma le_iff_sup:
haftmann@32064
   140
  "x \<sqsubseteq> y \<longleftrightarrow> x \<squnion> y = y"
haftmann@32064
   141
  by (auto intro: le_supI2 antisym dest: eq_iff [THEN iffD1])
nipkow@21734
   142
huffman@36008
   143
lemma sup_mono: "a \<sqsubseteq> c \<Longrightarrow> b \<le> d \<Longrightarrow> a \<squnion> b \<sqsubseteq> c \<squnion> d"
huffman@36008
   144
  by (fast intro: sup_least le_supI1 le_supI2)
huffman@36008
   145
haftmann@25206
   146
lemma mono_sup:
haftmann@35028
   147
  fixes f :: "'a \<Rightarrow> 'b\<Colon>semilattice_sup"
haftmann@34007
   148
  shows "mono f \<Longrightarrow> f A \<squnion> f B \<sqsubseteq> f (A \<squnion> B)"
haftmann@25206
   149
  by (auto simp add: mono_def intro: Lattices.sup_least)
nipkow@21733
   150
haftmann@25206
   151
end
haftmann@23878
   152
nipkow@21733
   153
haftmann@32064
   154
subsubsection {* Equational laws *}
haftmann@21249
   155
haftmann@35028
   156
sublocale semilattice_inf < inf!: semilattice inf
haftmann@34973
   157
proof
haftmann@34973
   158
  fix a b c
haftmann@34973
   159
  show "(a \<sqinter> b) \<sqinter> c = a \<sqinter> (b \<sqinter> c)"
haftmann@34973
   160
    by (rule antisym) (auto intro: le_infI1 le_infI2)
haftmann@34973
   161
  show "a \<sqinter> b = b \<sqinter> a"
haftmann@34973
   162
    by (rule antisym) auto
haftmann@34973
   163
  show "a \<sqinter> a = a"
haftmann@34973
   164
    by (rule antisym) auto
haftmann@34973
   165
qed
haftmann@34973
   166
haftmann@35028
   167
context semilattice_inf
nipkow@21733
   168
begin
nipkow@21733
   169
haftmann@34973
   170
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
haftmann@34973
   171
  by (fact inf.assoc)
nipkow@21733
   172
haftmann@34973
   173
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
haftmann@34973
   174
  by (fact inf.commute)
nipkow@21733
   175
haftmann@34973
   176
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
haftmann@34973
   177
  by (fact inf.left_commute)
nipkow@21733
   178
haftmann@34973
   179
lemma inf_idem: "x \<sqinter> x = x"
haftmann@34973
   180
  by (fact inf.idem)
haftmann@34973
   181
haftmann@34973
   182
lemma inf_left_idem: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
haftmann@34973
   183
  by (fact inf.left_idem)
nipkow@21733
   184
haftmann@32642
   185
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
haftmann@32064
   186
  by (rule antisym) auto
nipkow@21733
   187
haftmann@32642
   188
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
haftmann@32064
   189
  by (rule antisym) auto
haftmann@34973
   190
 
haftmann@32064
   191
lemmas inf_aci = inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@21733
   192
nipkow@21733
   193
end
nipkow@21733
   194
haftmann@35028
   195
sublocale semilattice_sup < sup!: semilattice sup
haftmann@34973
   196
proof
haftmann@34973
   197
  fix a b c
haftmann@34973
   198
  show "(a \<squnion> b) \<squnion> c = a \<squnion> (b \<squnion> c)"
haftmann@34973
   199
    by (rule antisym) (auto intro: le_supI1 le_supI2)
haftmann@34973
   200
  show "a \<squnion> b = b \<squnion> a"
haftmann@34973
   201
    by (rule antisym) auto
haftmann@34973
   202
  show "a \<squnion> a = a"
haftmann@34973
   203
    by (rule antisym) auto
haftmann@34973
   204
qed
haftmann@34973
   205
haftmann@35028
   206
context semilattice_sup
nipkow@21733
   207
begin
haftmann@21249
   208
haftmann@34973
   209
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
haftmann@34973
   210
  by (fact sup.assoc)
nipkow@21733
   211
haftmann@34973
   212
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
haftmann@34973
   213
  by (fact sup.commute)
nipkow@21733
   214
haftmann@34973
   215
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
haftmann@34973
   216
  by (fact sup.left_commute)
nipkow@21733
   217
haftmann@34973
   218
lemma sup_idem: "x \<squnion> x = x"
haftmann@34973
   219
  by (fact sup.idem)
haftmann@34973
   220
haftmann@34973
   221
lemma sup_left_idem: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
haftmann@34973
   222
  by (fact sup.left_idem)
nipkow@21733
   223
haftmann@32642
   224
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
haftmann@32064
   225
  by (rule antisym) auto
nipkow@21733
   226
haftmann@32642
   227
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
haftmann@32064
   228
  by (rule antisym) auto
haftmann@21249
   229
haftmann@32064
   230
lemmas sup_aci = sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@21733
   231
nipkow@21733
   232
end
haftmann@21249
   233
nipkow@21733
   234
context lattice
nipkow@21733
   235
begin
nipkow@21733
   236
haftmann@31991
   237
lemma dual_lattice:
haftmann@36635
   238
  "class.lattice (op \<ge>) (op >) sup inf"
haftmann@36635
   239
  by (rule class.lattice.intro, rule dual_semilattice, rule class.semilattice_sup.intro, rule dual_order)
haftmann@31991
   240
    (unfold_locales, auto)
haftmann@31991
   241
nipkow@21733
   242
lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
haftmann@25102
   243
  by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
nipkow@21733
   244
nipkow@21733
   245
lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
haftmann@25102
   246
  by (blast intro: antisym sup_ge1 sup_least inf_le1)
nipkow@21733
   247
haftmann@32064
   248
lemmas inf_sup_aci = inf_aci sup_aci
nipkow@21734
   249
haftmann@22454
   250
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
haftmann@22454
   251
nipkow@21734
   252
text{* Towards distributivity *}
haftmann@21249
   253
nipkow@21734
   254
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@32064
   255
  by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
nipkow@21734
   256
nipkow@21734
   257
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
haftmann@32064
   258
  by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
nipkow@21734
   259
nipkow@21734
   260
text{* If you have one of them, you have them all. *}
haftmann@21249
   261
nipkow@21733
   262
lemma distrib_imp1:
haftmann@21249
   263
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   264
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   265
proof-
haftmann@21249
   266
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
krauss@34209
   267
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc)
haftmann@21249
   268
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
haftmann@21249
   269
    by(simp add:inf_sup_absorb inf_commute)
haftmann@21249
   270
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   271
  finally show ?thesis .
haftmann@21249
   272
qed
haftmann@21249
   273
nipkow@21733
   274
lemma distrib_imp2:
haftmann@21249
   275
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   276
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   277
proof-
haftmann@21249
   278
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
krauss@34209
   279
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc)
haftmann@21249
   280
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
haftmann@21249
   281
    by(simp add:sup_inf_absorb sup_commute)
haftmann@21249
   282
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   283
  finally show ?thesis .
haftmann@21249
   284
qed
haftmann@21249
   285
nipkow@21733
   286
end
haftmann@21249
   287
haftmann@32568
   288
subsubsection {* Strict order *}
haftmann@32568
   289
haftmann@35028
   290
context semilattice_inf
haftmann@32568
   291
begin
haftmann@32568
   292
haftmann@32568
   293
lemma less_infI1:
haftmann@32568
   294
  "a \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   295
  by (auto simp add: less_le inf_absorb1 intro: le_infI1)
haftmann@32568
   296
haftmann@32568
   297
lemma less_infI2:
haftmann@32568
   298
  "b \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   299
  by (auto simp add: less_le inf_absorb2 intro: le_infI2)
haftmann@32568
   300
haftmann@32568
   301
end
haftmann@32568
   302
haftmann@35028
   303
context semilattice_sup
haftmann@32568
   304
begin
haftmann@32568
   305
haftmann@32568
   306
lemma less_supI1:
haftmann@34007
   307
  "x \<sqsubset> a \<Longrightarrow> x \<sqsubset> a \<squnion> b"
haftmann@32568
   308
proof -
haftmann@35028
   309
  interpret dual: semilattice_inf "op \<ge>" "op >" sup
haftmann@32568
   310
    by (fact dual_semilattice)
haftmann@34007
   311
  assume "x \<sqsubset> a"
haftmann@34007
   312
  then show "x \<sqsubset> a \<squnion> b"
haftmann@32568
   313
    by (fact dual.less_infI1)
haftmann@32568
   314
qed
haftmann@32568
   315
haftmann@32568
   316
lemma less_supI2:
haftmann@34007
   317
  "x \<sqsubset> b \<Longrightarrow> x \<sqsubset> a \<squnion> b"
haftmann@32568
   318
proof -
haftmann@35028
   319
  interpret dual: semilattice_inf "op \<ge>" "op >" sup
haftmann@32568
   320
    by (fact dual_semilattice)
haftmann@34007
   321
  assume "x \<sqsubset> b"
haftmann@34007
   322
  then show "x \<sqsubset> a \<squnion> b"
haftmann@32568
   323
    by (fact dual.less_infI2)
haftmann@32568
   324
qed
haftmann@32568
   325
haftmann@32568
   326
end
haftmann@32568
   327
haftmann@21249
   328
haftmann@24164
   329
subsection {* Distributive lattices *}
haftmann@21249
   330
haftmann@22454
   331
class distrib_lattice = lattice +
haftmann@21249
   332
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   333
nipkow@21733
   334
context distrib_lattice
nipkow@21733
   335
begin
nipkow@21733
   336
nipkow@21733
   337
lemma sup_inf_distrib2:
haftmann@21249
   338
 "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
haftmann@32064
   339
by(simp add: inf_sup_aci sup_inf_distrib1)
haftmann@21249
   340
nipkow@21733
   341
lemma inf_sup_distrib1:
haftmann@21249
   342
 "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   343
by(rule distrib_imp2[OF sup_inf_distrib1])
haftmann@21249
   344
nipkow@21733
   345
lemma inf_sup_distrib2:
haftmann@21249
   346
 "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
haftmann@32064
   347
by(simp add: inf_sup_aci inf_sup_distrib1)
haftmann@21249
   348
haftmann@31991
   349
lemma dual_distrib_lattice:
haftmann@36635
   350
  "class.distrib_lattice (op \<ge>) (op >) sup inf"
haftmann@36635
   351
  by (rule class.distrib_lattice.intro, rule dual_lattice)
haftmann@31991
   352
    (unfold_locales, fact inf_sup_distrib1)
haftmann@31991
   353
huffman@36008
   354
lemmas sup_inf_distrib =
huffman@36008
   355
  sup_inf_distrib1 sup_inf_distrib2
huffman@36008
   356
huffman@36008
   357
lemmas inf_sup_distrib =
huffman@36008
   358
  inf_sup_distrib1 inf_sup_distrib2
huffman@36008
   359
nipkow@21733
   360
lemmas distrib =
haftmann@21249
   361
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   362
nipkow@21733
   363
end
nipkow@21733
   364
haftmann@21249
   365
haftmann@34007
   366
subsection {* Bounded lattices and boolean algebras *}
haftmann@31991
   367
kaliszyk@36352
   368
class bounded_lattice_bot = lattice + bot
haftmann@31991
   369
begin
haftmann@31991
   370
haftmann@31991
   371
lemma inf_bot_left [simp]:
haftmann@34007
   372
  "\<bottom> \<sqinter> x = \<bottom>"
haftmann@31991
   373
  by (rule inf_absorb1) simp
haftmann@31991
   374
haftmann@31991
   375
lemma inf_bot_right [simp]:
haftmann@34007
   376
  "x \<sqinter> \<bottom> = \<bottom>"
haftmann@31991
   377
  by (rule inf_absorb2) simp
haftmann@31991
   378
kaliszyk@36352
   379
lemma sup_bot_left [simp]:
kaliszyk@36352
   380
  "\<bottom> \<squnion> x = x"
kaliszyk@36352
   381
  by (rule sup_absorb2) simp
kaliszyk@36352
   382
kaliszyk@36352
   383
lemma sup_bot_right [simp]:
kaliszyk@36352
   384
  "x \<squnion> \<bottom> = x"
kaliszyk@36352
   385
  by (rule sup_absorb1) simp
kaliszyk@36352
   386
kaliszyk@36352
   387
lemma sup_eq_bot_iff [simp]:
kaliszyk@36352
   388
  "x \<squnion> y = \<bottom> \<longleftrightarrow> x = \<bottom> \<and> y = \<bottom>"
kaliszyk@36352
   389
  by (simp add: eq_iff)
kaliszyk@36352
   390
kaliszyk@36352
   391
end
kaliszyk@36352
   392
kaliszyk@36352
   393
class bounded_lattice_top = lattice + top
kaliszyk@36352
   394
begin
kaliszyk@36352
   395
haftmann@31991
   396
lemma sup_top_left [simp]:
haftmann@34007
   397
  "\<top> \<squnion> x = \<top>"
haftmann@31991
   398
  by (rule sup_absorb1) simp
haftmann@31991
   399
haftmann@31991
   400
lemma sup_top_right [simp]:
haftmann@34007
   401
  "x \<squnion> \<top> = \<top>"
haftmann@31991
   402
  by (rule sup_absorb2) simp
haftmann@31991
   403
haftmann@31991
   404
lemma inf_top_left [simp]:
haftmann@34007
   405
  "\<top> \<sqinter> x = x"
haftmann@31991
   406
  by (rule inf_absorb2) simp
haftmann@31991
   407
haftmann@31991
   408
lemma inf_top_right [simp]:
haftmann@34007
   409
  "x \<sqinter> \<top> = x"
haftmann@31991
   410
  by (rule inf_absorb1) simp
haftmann@31991
   411
huffman@36008
   412
lemma inf_eq_top_iff [simp]:
huffman@36008
   413
  "x \<sqinter> y = \<top> \<longleftrightarrow> x = \<top> \<and> y = \<top>"
huffman@36008
   414
  by (simp add: eq_iff)
haftmann@32568
   415
kaliszyk@36352
   416
end
kaliszyk@36352
   417
kaliszyk@36352
   418
class bounded_lattice = bounded_lattice_bot + bounded_lattice_top
kaliszyk@36352
   419
begin
kaliszyk@36352
   420
kaliszyk@36352
   421
lemma dual_bounded_lattice:
haftmann@36635
   422
  "class.bounded_lattice (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom>"
kaliszyk@36352
   423
  by unfold_locales (auto simp add: less_le_not_le)
haftmann@32568
   424
haftmann@34007
   425
end
haftmann@34007
   426
haftmann@34007
   427
class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
haftmann@34007
   428
  assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
haftmann@34007
   429
    and sup_compl_top: "x \<squnion> - x = \<top>"
haftmann@34007
   430
  assumes diff_eq: "x - y = x \<sqinter> - y"
haftmann@34007
   431
begin
haftmann@34007
   432
haftmann@34007
   433
lemma dual_boolean_algebra:
haftmann@36635
   434
  "class.boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom>"
haftmann@36635
   435
  by (rule class.boolean_algebra.intro, rule dual_bounded_lattice, rule dual_distrib_lattice)
haftmann@34007
   436
    (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
haftmann@34007
   437
haftmann@34007
   438
lemma compl_inf_bot:
haftmann@34007
   439
  "- x \<sqinter> x = \<bottom>"
haftmann@34007
   440
  by (simp add: inf_commute inf_compl_bot)
haftmann@34007
   441
haftmann@34007
   442
lemma compl_sup_top:
haftmann@34007
   443
  "- x \<squnion> x = \<top>"
haftmann@34007
   444
  by (simp add: sup_commute sup_compl_top)
haftmann@34007
   445
haftmann@31991
   446
lemma compl_unique:
haftmann@34007
   447
  assumes "x \<sqinter> y = \<bottom>"
haftmann@34007
   448
    and "x \<squnion> y = \<top>"
haftmann@31991
   449
  shows "- x = y"
haftmann@31991
   450
proof -
haftmann@31991
   451
  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
haftmann@31991
   452
    using inf_compl_bot assms(1) by simp
haftmann@31991
   453
  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
haftmann@31991
   454
    by (simp add: inf_commute)
haftmann@31991
   455
  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
haftmann@31991
   456
    by (simp add: inf_sup_distrib1)
haftmann@34007
   457
  then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
haftmann@31991
   458
    using sup_compl_top assms(2) by simp
krauss@34209
   459
  then show "- x = y" by simp
haftmann@31991
   460
qed
haftmann@31991
   461
haftmann@31991
   462
lemma double_compl [simp]:
haftmann@31991
   463
  "- (- x) = x"
haftmann@31991
   464
  using compl_inf_bot compl_sup_top by (rule compl_unique)
haftmann@31991
   465
haftmann@31991
   466
lemma compl_eq_compl_iff [simp]:
haftmann@31991
   467
  "- x = - y \<longleftrightarrow> x = y"
haftmann@31991
   468
proof
haftmann@31991
   469
  assume "- x = - y"
huffman@36008
   470
  then have "- (- x) = - (- y)" by (rule arg_cong)
haftmann@31991
   471
  then show "x = y" by simp
haftmann@31991
   472
next
haftmann@31991
   473
  assume "x = y"
haftmann@31991
   474
  then show "- x = - y" by simp
haftmann@31991
   475
qed
haftmann@31991
   476
haftmann@31991
   477
lemma compl_bot_eq [simp]:
haftmann@34007
   478
  "- \<bottom> = \<top>"
haftmann@31991
   479
proof -
haftmann@34007
   480
  from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
haftmann@31991
   481
  then show ?thesis by simp
haftmann@31991
   482
qed
haftmann@31991
   483
haftmann@31991
   484
lemma compl_top_eq [simp]:
haftmann@34007
   485
  "- \<top> = \<bottom>"
haftmann@31991
   486
proof -
haftmann@34007
   487
  from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
haftmann@31991
   488
  then show ?thesis by simp
haftmann@31991
   489
qed
haftmann@31991
   490
haftmann@31991
   491
lemma compl_inf [simp]:
haftmann@31991
   492
  "- (x \<sqinter> y) = - x \<squnion> - y"
haftmann@31991
   493
proof (rule compl_unique)
huffman@36008
   494
  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
huffman@36008
   495
    by (simp only: inf_sup_distrib inf_aci)
huffman@36008
   496
  then show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
haftmann@31991
   497
    by (simp add: inf_compl_bot)
haftmann@31991
   498
next
huffman@36008
   499
  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
huffman@36008
   500
    by (simp only: sup_inf_distrib sup_aci)
huffman@36008
   501
  then show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
haftmann@31991
   502
    by (simp add: sup_compl_top)
haftmann@31991
   503
qed
haftmann@31991
   504
haftmann@31991
   505
lemma compl_sup [simp]:
haftmann@31991
   506
  "- (x \<squnion> y) = - x \<sqinter> - y"
haftmann@31991
   507
proof -
haftmann@34007
   508
  interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
haftmann@31991
   509
    by (rule dual_boolean_algebra)
haftmann@31991
   510
  then show ?thesis by simp
haftmann@31991
   511
qed
haftmann@31991
   512
huffman@36008
   513
lemma compl_mono:
huffman@36008
   514
  "x \<sqsubseteq> y \<Longrightarrow> - y \<sqsubseteq> - x"
huffman@36008
   515
proof -
huffman@36008
   516
  assume "x \<sqsubseteq> y"
huffman@36008
   517
  then have "x \<squnion> y = y" by (simp only: le_iff_sup)
huffman@36008
   518
  then have "- (x \<squnion> y) = - y" by simp
huffman@36008
   519
  then have "- x \<sqinter> - y = - y" by simp
huffman@36008
   520
  then have "- y \<sqinter> - x = - y" by (simp only: inf_commute)
huffman@36008
   521
  then show "- y \<sqsubseteq> - x" by (simp only: le_iff_inf)
huffman@36008
   522
qed
huffman@36008
   523
huffman@36008
   524
lemma compl_le_compl_iff: (* TODO: declare [simp] ? *)
huffman@36008
   525
  "- x \<le> - y \<longleftrightarrow> y \<le> x"
huffman@36008
   526
by (auto dest: compl_mono)
huffman@36008
   527
haftmann@31991
   528
end
haftmann@31991
   529
haftmann@31991
   530
haftmann@22454
   531
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   532
haftmann@35028
   533
lemma (in semilattice_inf) inf_unique:
haftmann@22454
   534
  fixes f (infixl "\<triangle>" 70)
haftmann@34007
   535
  assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
haftmann@34007
   536
  and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
haftmann@22737
   537
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   538
proof (rule antisym)
haftmann@34007
   539
  show "x \<triangle> y \<sqsubseteq> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   540
next
haftmann@34007
   541
  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
   542
  show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   543
qed
haftmann@22454
   544
haftmann@35028
   545
lemma (in semilattice_sup) sup_unique:
haftmann@22454
   546
  fixes f (infixl "\<nabla>" 70)
haftmann@34007
   547
  assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
haftmann@34007
   548
  and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
haftmann@22737
   549
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   550
proof (rule antisym)
haftmann@34007
   551
  show "x \<squnion> y \<sqsubseteq> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   552
next
haftmann@34007
   553
  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
   554
  show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   555
qed
huffman@36008
   556
haftmann@22454
   557
haftmann@22916
   558
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   559
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   560
haftmann@32512
   561
sublocale linorder < min_max!: distrib_lattice less_eq less min max
haftmann@28823
   562
proof
haftmann@22916
   563
  fix x y z
haftmann@32512
   564
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@32512
   565
    by (auto simp add: min_def max_def)
haftmann@22916
   566
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   567
haftmann@35028
   568
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{semilattice_inf, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   569
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   570
haftmann@35028
   571
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{semilattice_sup, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   572
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   573
haftmann@21249
   574
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   575
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   576
 
haftmann@34973
   577
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@34973
   578
  min_max.inf.left_commute
haftmann@21249
   579
haftmann@34973
   580
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@34973
   581
  min_max.sup.left_commute
haftmann@34973
   582
haftmann@21249
   583
haftmann@22454
   584
subsection {* Bool as lattice *}
haftmann@22454
   585
haftmann@31991
   586
instantiation bool :: boolean_algebra
haftmann@25510
   587
begin
haftmann@25510
   588
haftmann@25510
   589
definition
haftmann@41080
   590
  bool_Compl_def [simp]: "uminus = Not"
haftmann@31991
   591
haftmann@31991
   592
definition
haftmann@41080
   593
  bool_diff_def [simp]: "A - B \<longleftrightarrow> A \<and> \<not> B"
haftmann@31991
   594
haftmann@31991
   595
definition
haftmann@41080
   596
  [simp]: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
haftmann@25510
   597
haftmann@25510
   598
definition
haftmann@41080
   599
  [simp]: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
haftmann@25510
   600
haftmann@31991
   601
instance proof
haftmann@41080
   602
qed auto
haftmann@22454
   603
haftmann@25510
   604
end
haftmann@25510
   605
haftmann@32781
   606
lemma sup_boolI1:
haftmann@32781
   607
  "P \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   608
  by simp
haftmann@32781
   609
haftmann@32781
   610
lemma sup_boolI2:
haftmann@32781
   611
  "Q \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   612
  by simp
haftmann@32781
   613
haftmann@32781
   614
lemma sup_boolE:
haftmann@32781
   615
  "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@41080
   616
  by auto
haftmann@32781
   617
haftmann@23878
   618
haftmann@23878
   619
subsection {* Fun as lattice *}
haftmann@23878
   620
haftmann@25510
   621
instantiation "fun" :: (type, lattice) lattice
haftmann@25510
   622
begin
haftmann@25510
   623
haftmann@25510
   624
definition
haftmann@41080
   625
  "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
haftmann@41080
   626
haftmann@41080
   627
lemma inf_apply:
haftmann@41080
   628
  "(f \<sqinter> g) x = f x \<sqinter> g x"
haftmann@41080
   629
  by (simp add: inf_fun_def)
haftmann@25510
   630
haftmann@25510
   631
definition
haftmann@41080
   632
  "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
haftmann@41080
   633
haftmann@41080
   634
lemma sup_apply:
haftmann@41080
   635
  "(f \<squnion> g) x = f x \<squnion> g x"
haftmann@41080
   636
  by (simp add: sup_fun_def)
haftmann@25510
   637
haftmann@32780
   638
instance proof
haftmann@41080
   639
qed (simp_all add: le_fun_def inf_apply sup_apply)
haftmann@23878
   640
haftmann@25510
   641
end
haftmann@23878
   642
haftmann@41080
   643
instance "fun" :: (type, distrib_lattice) distrib_lattice proof
haftmann@41080
   644
qed (rule ext, simp add: sup_inf_distrib1 inf_apply sup_apply)
haftmann@31991
   645
haftmann@34007
   646
instance "fun" :: (type, bounded_lattice) bounded_lattice ..
haftmann@34007
   647
haftmann@31991
   648
instantiation "fun" :: (type, uminus) uminus
haftmann@31991
   649
begin
haftmann@31991
   650
haftmann@31991
   651
definition
haftmann@31991
   652
  fun_Compl_def: "- A = (\<lambda>x. - A x)"
haftmann@31991
   653
haftmann@41080
   654
lemma uminus_apply:
haftmann@41080
   655
  "(- A) x = - (A x)"
haftmann@41080
   656
  by (simp add: fun_Compl_def)
haftmann@41080
   657
haftmann@31991
   658
instance ..
haftmann@31991
   659
haftmann@31991
   660
end
haftmann@31991
   661
haftmann@31991
   662
instantiation "fun" :: (type, minus) minus
haftmann@31991
   663
begin
haftmann@31991
   664
haftmann@31991
   665
definition
haftmann@31991
   666
  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
haftmann@31991
   667
haftmann@41080
   668
lemma minus_apply:
haftmann@41080
   669
  "(A - B) x = A x - B x"
haftmann@41080
   670
  by (simp add: fun_diff_def)
haftmann@41080
   671
haftmann@31991
   672
instance ..
haftmann@31991
   673
haftmann@31991
   674
end
haftmann@31991
   675
haftmann@41080
   676
instance "fun" :: (type, boolean_algebra) boolean_algebra proof
haftmann@41080
   677
qed (rule ext, simp_all add: inf_apply sup_apply bot_apply top_apply uminus_apply minus_apply inf_compl_bot sup_compl_top diff_eq)+
berghofe@26794
   678
haftmann@25062
   679
no_notation
wenzelm@25382
   680
  less_eq  (infix "\<sqsubseteq>" 50) and
wenzelm@25382
   681
  less (infix "\<sqsubset>" 50) and
wenzelm@25382
   682
  inf  (infixl "\<sqinter>" 70) and
haftmann@32568
   683
  sup  (infixl "\<squnion>" 65) and
haftmann@32568
   684
  top ("\<top>") and
haftmann@32568
   685
  bot ("\<bottom>")
haftmann@25062
   686
haftmann@21249
   687
end