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