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