src/HOL/Lattices.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 44921 58eef4843641
child 46553 50a7e97fe653
permissions -rw-r--r--
Quotient_Info stores only relation maps
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
huffman@44921
   183
lemma inf_idem: "x \<sqinter> x = x"
huffman@44921
   184
  by (fact inf.idem) (* already simp *)
haftmann@34973
   185
noschinl@44918
   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
huffman@44921
   222
lemma sup_idem: "x \<squnion> x = x"
huffman@44921
   223
  by (fact sup.idem) (* already simp *)
haftmann@34973
   224
noschinl@44918
   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
noschinl@44918
   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
noschinl@44918
   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-
noschinl@44918
   270
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by simp
noschinl@44918
   271
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))"
noschinl@44918
   272
    by (simp add: D inf_commute sup_assoc del: sup_inf_absorb)
haftmann@21249
   273
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
noschinl@44919
   274
    by(simp add: inf_commute)
haftmann@21249
   275
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   276
  finally show ?thesis .
haftmann@21249
   277
qed
haftmann@21249
   278
nipkow@21733
   279
lemma distrib_imp2:
haftmann@21249
   280
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   281
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   282
proof-
noschinl@44918
   283
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by simp
noschinl@44918
   284
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))"
noschinl@44918
   285
    by (simp add: D sup_commute inf_assoc del: inf_sup_absorb)
haftmann@21249
   286
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
noschinl@44919
   287
    by(simp add: sup_commute)
haftmann@21249
   288
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   289
  finally show ?thesis .
haftmann@21249
   290
qed
haftmann@21249
   291
nipkow@21733
   292
end
haftmann@21249
   293
haftmann@32568
   294
subsubsection {* Strict order *}
haftmann@32568
   295
haftmann@35028
   296
context semilattice_inf
haftmann@32568
   297
begin
haftmann@32568
   298
haftmann@32568
   299
lemma less_infI1:
haftmann@32568
   300
  "a \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   301
  by (auto simp add: less_le inf_absorb1 intro: le_infI1)
haftmann@32568
   302
haftmann@32568
   303
lemma less_infI2:
haftmann@32568
   304
  "b \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   305
  by (auto simp add: less_le inf_absorb2 intro: le_infI2)
haftmann@32568
   306
haftmann@32568
   307
end
haftmann@32568
   308
haftmann@35028
   309
context semilattice_sup
haftmann@32568
   310
begin
haftmann@32568
   311
haftmann@32568
   312
lemma less_supI1:
haftmann@34007
   313
  "x \<sqsubset> a \<Longrightarrow> x \<sqsubset> a \<squnion> b"
huffman@44921
   314
  using dual_semilattice
huffman@44921
   315
  by (rule semilattice_inf.less_infI1)
haftmann@32568
   316
haftmann@32568
   317
lemma less_supI2:
haftmann@34007
   318
  "x \<sqsubset> b \<Longrightarrow> x \<sqsubset> a \<squnion> b"
huffman@44921
   319
  using dual_semilattice
huffman@44921
   320
  by (rule semilattice_inf.less_infI2)
haftmann@32568
   321
haftmann@32568
   322
end
haftmann@32568
   323
haftmann@21249
   324
haftmann@24164
   325
subsection {* Distributive lattices *}
haftmann@21249
   326
haftmann@22454
   327
class distrib_lattice = lattice +
haftmann@21249
   328
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   329
nipkow@21733
   330
context distrib_lattice
nipkow@21733
   331
begin
nipkow@21733
   332
nipkow@21733
   333
lemma sup_inf_distrib2:
huffman@44921
   334
  "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
huffman@44921
   335
  by (simp add: sup_commute sup_inf_distrib1)
haftmann@21249
   336
nipkow@21733
   337
lemma inf_sup_distrib1:
huffman@44921
   338
  "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
huffman@44921
   339
  by (rule distrib_imp2 [OF sup_inf_distrib1])
haftmann@21249
   340
nipkow@21733
   341
lemma inf_sup_distrib2:
huffman@44921
   342
  "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
huffman@44921
   343
  by (simp add: inf_commute inf_sup_distrib1)
haftmann@21249
   344
haftmann@31991
   345
lemma dual_distrib_lattice:
krauss@44845
   346
  "class.distrib_lattice sup (op \<ge>) (op >) inf"
haftmann@36635
   347
  by (rule class.distrib_lattice.intro, rule dual_lattice)
haftmann@31991
   348
    (unfold_locales, fact inf_sup_distrib1)
haftmann@31991
   349
huffman@36008
   350
lemmas sup_inf_distrib =
huffman@36008
   351
  sup_inf_distrib1 sup_inf_distrib2
huffman@36008
   352
huffman@36008
   353
lemmas inf_sup_distrib =
huffman@36008
   354
  inf_sup_distrib1 inf_sup_distrib2
huffman@36008
   355
nipkow@21733
   356
lemmas distrib =
haftmann@21249
   357
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   358
nipkow@21733
   359
end
nipkow@21733
   360
haftmann@21249
   361
haftmann@34007
   362
subsection {* Bounded lattices and boolean algebras *}
haftmann@31991
   363
kaliszyk@36352
   364
class bounded_lattice_bot = lattice + bot
haftmann@31991
   365
begin
haftmann@31991
   366
haftmann@31991
   367
lemma inf_bot_left [simp]:
haftmann@34007
   368
  "\<bottom> \<sqinter> x = \<bottom>"
haftmann@31991
   369
  by (rule inf_absorb1) simp
haftmann@31991
   370
haftmann@31991
   371
lemma inf_bot_right [simp]:
haftmann@34007
   372
  "x \<sqinter> \<bottom> = \<bottom>"
haftmann@31991
   373
  by (rule inf_absorb2) simp
haftmann@31991
   374
kaliszyk@36352
   375
lemma sup_bot_left [simp]:
kaliszyk@36352
   376
  "\<bottom> \<squnion> x = x"
kaliszyk@36352
   377
  by (rule sup_absorb2) simp
kaliszyk@36352
   378
kaliszyk@36352
   379
lemma sup_bot_right [simp]:
kaliszyk@36352
   380
  "x \<squnion> \<bottom> = x"
kaliszyk@36352
   381
  by (rule sup_absorb1) simp
kaliszyk@36352
   382
kaliszyk@36352
   383
lemma sup_eq_bot_iff [simp]:
kaliszyk@36352
   384
  "x \<squnion> y = \<bottom> \<longleftrightarrow> x = \<bottom> \<and> y = \<bottom>"
kaliszyk@36352
   385
  by (simp add: eq_iff)
kaliszyk@36352
   386
kaliszyk@36352
   387
end
kaliszyk@36352
   388
kaliszyk@36352
   389
class bounded_lattice_top = lattice + top
kaliszyk@36352
   390
begin
kaliszyk@36352
   391
haftmann@31991
   392
lemma sup_top_left [simp]:
haftmann@34007
   393
  "\<top> \<squnion> x = \<top>"
haftmann@31991
   394
  by (rule sup_absorb1) simp
haftmann@31991
   395
haftmann@31991
   396
lemma sup_top_right [simp]:
haftmann@34007
   397
  "x \<squnion> \<top> = \<top>"
haftmann@31991
   398
  by (rule sup_absorb2) simp
haftmann@31991
   399
haftmann@31991
   400
lemma inf_top_left [simp]:
haftmann@34007
   401
  "\<top> \<sqinter> x = x"
haftmann@31991
   402
  by (rule inf_absorb2) simp
haftmann@31991
   403
haftmann@31991
   404
lemma inf_top_right [simp]:
haftmann@34007
   405
  "x \<sqinter> \<top> = x"
haftmann@31991
   406
  by (rule inf_absorb1) simp
haftmann@31991
   407
huffman@36008
   408
lemma inf_eq_top_iff [simp]:
huffman@36008
   409
  "x \<sqinter> y = \<top> \<longleftrightarrow> x = \<top> \<and> y = \<top>"
huffman@36008
   410
  by (simp add: eq_iff)
haftmann@32568
   411
kaliszyk@36352
   412
end
kaliszyk@36352
   413
kaliszyk@36352
   414
class bounded_lattice = bounded_lattice_bot + bounded_lattice_top
kaliszyk@36352
   415
begin
kaliszyk@36352
   416
kaliszyk@36352
   417
lemma dual_bounded_lattice:
krauss@44845
   418
  "class.bounded_lattice sup greater_eq greater inf \<top> \<bottom>"
kaliszyk@36352
   419
  by unfold_locales (auto simp add: less_le_not_le)
haftmann@32568
   420
haftmann@34007
   421
end
haftmann@34007
   422
haftmann@34007
   423
class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
haftmann@34007
   424
  assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
haftmann@34007
   425
    and sup_compl_top: "x \<squnion> - x = \<top>"
haftmann@34007
   426
  assumes diff_eq: "x - y = x \<sqinter> - y"
haftmann@34007
   427
begin
haftmann@34007
   428
haftmann@34007
   429
lemma dual_boolean_algebra:
krauss@44845
   430
  "class.boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus sup greater_eq greater inf \<top> \<bottom>"
haftmann@36635
   431
  by (rule class.boolean_algebra.intro, rule dual_bounded_lattice, rule dual_distrib_lattice)
haftmann@34007
   432
    (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
haftmann@34007
   433
noschinl@44918
   434
lemma compl_inf_bot [simp]:
haftmann@34007
   435
  "- x \<sqinter> x = \<bottom>"
haftmann@34007
   436
  by (simp add: inf_commute inf_compl_bot)
haftmann@34007
   437
noschinl@44918
   438
lemma compl_sup_top [simp]:
haftmann@34007
   439
  "- x \<squnion> x = \<top>"
haftmann@34007
   440
  by (simp add: sup_commute sup_compl_top)
haftmann@34007
   441
haftmann@31991
   442
lemma compl_unique:
haftmann@34007
   443
  assumes "x \<sqinter> y = \<bottom>"
haftmann@34007
   444
    and "x \<squnion> y = \<top>"
haftmann@31991
   445
  shows "- x = y"
haftmann@31991
   446
proof -
haftmann@31991
   447
  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
haftmann@31991
   448
    using inf_compl_bot assms(1) by simp
haftmann@31991
   449
  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
haftmann@31991
   450
    by (simp add: inf_commute)
haftmann@31991
   451
  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
haftmann@31991
   452
    by (simp add: inf_sup_distrib1)
haftmann@34007
   453
  then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
haftmann@31991
   454
    using sup_compl_top assms(2) by simp
krauss@34209
   455
  then show "- x = y" by simp
haftmann@31991
   456
qed
haftmann@31991
   457
haftmann@31991
   458
lemma double_compl [simp]:
haftmann@31991
   459
  "- (- x) = x"
haftmann@31991
   460
  using compl_inf_bot compl_sup_top by (rule compl_unique)
haftmann@31991
   461
haftmann@31991
   462
lemma compl_eq_compl_iff [simp]:
haftmann@31991
   463
  "- x = - y \<longleftrightarrow> x = y"
haftmann@31991
   464
proof
haftmann@31991
   465
  assume "- x = - y"
huffman@36008
   466
  then have "- (- x) = - (- y)" by (rule arg_cong)
haftmann@31991
   467
  then show "x = y" by simp
haftmann@31991
   468
next
haftmann@31991
   469
  assume "x = y"
haftmann@31991
   470
  then show "- x = - y" by simp
haftmann@31991
   471
qed
haftmann@31991
   472
haftmann@31991
   473
lemma compl_bot_eq [simp]:
haftmann@34007
   474
  "- \<bottom> = \<top>"
haftmann@31991
   475
proof -
haftmann@34007
   476
  from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
haftmann@31991
   477
  then show ?thesis by simp
haftmann@31991
   478
qed
haftmann@31991
   479
haftmann@31991
   480
lemma compl_top_eq [simp]:
haftmann@34007
   481
  "- \<top> = \<bottom>"
haftmann@31991
   482
proof -
haftmann@34007
   483
  from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
haftmann@31991
   484
  then show ?thesis by simp
haftmann@31991
   485
qed
haftmann@31991
   486
haftmann@31991
   487
lemma compl_inf [simp]:
haftmann@31991
   488
  "- (x \<sqinter> y) = - x \<squnion> - y"
haftmann@31991
   489
proof (rule compl_unique)
huffman@36008
   490
  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
huffman@36008
   491
    by (simp only: inf_sup_distrib inf_aci)
huffman@36008
   492
  then show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
haftmann@31991
   493
    by (simp add: inf_compl_bot)
haftmann@31991
   494
next
huffman@36008
   495
  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
huffman@36008
   496
    by (simp only: sup_inf_distrib sup_aci)
huffman@36008
   497
  then show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
haftmann@31991
   498
    by (simp add: sup_compl_top)
haftmann@31991
   499
qed
haftmann@31991
   500
haftmann@31991
   501
lemma compl_sup [simp]:
haftmann@31991
   502
  "- (x \<squnion> y) = - x \<sqinter> - y"
huffman@44921
   503
  using dual_boolean_algebra
huffman@44921
   504
  by (rule boolean_algebra.compl_inf)
haftmann@31991
   505
huffman@36008
   506
lemma compl_mono:
huffman@36008
   507
  "x \<sqsubseteq> y \<Longrightarrow> - y \<sqsubseteq> - x"
huffman@36008
   508
proof -
huffman@36008
   509
  assume "x \<sqsubseteq> y"
huffman@36008
   510
  then have "x \<squnion> y = y" by (simp only: le_iff_sup)
huffman@36008
   511
  then have "- (x \<squnion> y) = - y" by simp
huffman@36008
   512
  then have "- x \<sqinter> - y = - y" by simp
huffman@36008
   513
  then have "- y \<sqinter> - x = - y" by (simp only: inf_commute)
huffman@36008
   514
  then show "- y \<sqsubseteq> - x" by (simp only: le_iff_inf)
huffman@36008
   515
qed
huffman@36008
   516
noschinl@44918
   517
lemma compl_le_compl_iff [simp]:
haftmann@43753
   518
  "- x \<sqsubseteq> - y \<longleftrightarrow> y \<sqsubseteq> x"
haftmann@43873
   519
  by (auto dest: compl_mono)
haftmann@43873
   520
haftmann@43873
   521
lemma compl_le_swap1:
haftmann@43873
   522
  assumes "y \<sqsubseteq> - x" shows "x \<sqsubseteq> -y"
haftmann@43873
   523
proof -
haftmann@43873
   524
  from assms have "- (- x) \<sqsubseteq> - y" by (simp only: compl_le_compl_iff)
haftmann@43873
   525
  then show ?thesis by simp
haftmann@43873
   526
qed
haftmann@43873
   527
haftmann@43873
   528
lemma compl_le_swap2:
haftmann@43873
   529
  assumes "- y \<sqsubseteq> x" shows "- x \<sqsubseteq> y"
haftmann@43873
   530
proof -
haftmann@43873
   531
  from assms have "- x \<sqsubseteq> - (- y)" by (simp only: compl_le_compl_iff)
haftmann@43873
   532
  then show ?thesis by simp
haftmann@43873
   533
qed
haftmann@43873
   534
haftmann@43873
   535
lemma compl_less_compl_iff: (* TODO: declare [simp] ? *)
haftmann@43873
   536
  "- x \<sqsubset> - y \<longleftrightarrow> y \<sqsubset> x"
noschinl@44919
   537
  by (auto simp add: less_le)
haftmann@43873
   538
haftmann@43873
   539
lemma compl_less_swap1:
haftmann@43873
   540
  assumes "y \<sqsubset> - x" shows "x \<sqsubset> - y"
haftmann@43873
   541
proof -
haftmann@43873
   542
  from assms have "- (- x) \<sqsubset> - y" by (simp only: compl_less_compl_iff)
haftmann@43873
   543
  then show ?thesis by simp
haftmann@43873
   544
qed
haftmann@43873
   545
haftmann@43873
   546
lemma compl_less_swap2:
haftmann@43873
   547
  assumes "- y \<sqsubset> x" shows "- x \<sqsubset> y"
haftmann@43873
   548
proof -
haftmann@43873
   549
  from assms have "- x \<sqsubset> - (- y)" by (simp only: compl_less_compl_iff)
haftmann@43873
   550
  then show ?thesis by simp
haftmann@43873
   551
qed
huffman@36008
   552
haftmann@31991
   553
end
haftmann@31991
   554
haftmann@31991
   555
haftmann@22454
   556
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   557
haftmann@35028
   558
lemma (in semilattice_inf) inf_unique:
haftmann@22454
   559
  fixes f (infixl "\<triangle>" 70)
haftmann@34007
   560
  assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
haftmann@34007
   561
  and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
haftmann@22737
   562
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   563
proof (rule antisym)
haftmann@34007
   564
  show "x \<triangle> y \<sqsubseteq> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   565
next
haftmann@34007
   566
  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
   567
  show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   568
qed
haftmann@22454
   569
haftmann@35028
   570
lemma (in semilattice_sup) sup_unique:
haftmann@22454
   571
  fixes f (infixl "\<nabla>" 70)
haftmann@34007
   572
  assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
haftmann@34007
   573
  and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
haftmann@22737
   574
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   575
proof (rule antisym)
haftmann@34007
   576
  show "x \<squnion> y \<sqsubseteq> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   577
next
haftmann@34007
   578
  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
   579
  show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   580
qed
huffman@36008
   581
haftmann@22454
   582
haftmann@22916
   583
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   584
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   585
krauss@44845
   586
sublocale linorder < min_max!: distrib_lattice min less_eq less max
haftmann@28823
   587
proof
haftmann@22916
   588
  fix x y z
haftmann@32512
   589
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@32512
   590
    by (auto simp add: min_def max_def)
haftmann@22916
   591
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   592
haftmann@35028
   593
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{semilattice_inf, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   594
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   595
haftmann@35028
   596
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{semilattice_sup, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   597
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   598
haftmann@21249
   599
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   600
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   601
 
haftmann@34973
   602
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@34973
   603
  min_max.inf.left_commute
haftmann@21249
   604
haftmann@34973
   605
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@34973
   606
  min_max.sup.left_commute
haftmann@34973
   607
haftmann@21249
   608
haftmann@22454
   609
subsection {* Bool as lattice *}
haftmann@22454
   610
haftmann@31991
   611
instantiation bool :: boolean_algebra
haftmann@25510
   612
begin
haftmann@25510
   613
haftmann@25510
   614
definition
haftmann@41080
   615
  bool_Compl_def [simp]: "uminus = Not"
haftmann@31991
   616
haftmann@31991
   617
definition
haftmann@41080
   618
  bool_diff_def [simp]: "A - B \<longleftrightarrow> A \<and> \<not> B"
haftmann@31991
   619
haftmann@31991
   620
definition
haftmann@41080
   621
  [simp]: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
haftmann@25510
   622
haftmann@25510
   623
definition
haftmann@41080
   624
  [simp]: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
haftmann@25510
   625
haftmann@31991
   626
instance proof
haftmann@41080
   627
qed auto
haftmann@22454
   628
haftmann@25510
   629
end
haftmann@25510
   630
haftmann@32781
   631
lemma sup_boolI1:
haftmann@32781
   632
  "P \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   633
  by simp
haftmann@32781
   634
haftmann@32781
   635
lemma sup_boolI2:
haftmann@32781
   636
  "Q \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   637
  by simp
haftmann@32781
   638
haftmann@32781
   639
lemma sup_boolE:
haftmann@32781
   640
  "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@41080
   641
  by auto
haftmann@32781
   642
haftmann@23878
   643
haftmann@23878
   644
subsection {* Fun as lattice *}
haftmann@23878
   645
haftmann@25510
   646
instantiation "fun" :: (type, lattice) lattice
haftmann@25510
   647
begin
haftmann@25510
   648
haftmann@25510
   649
definition
haftmann@41080
   650
  "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
haftmann@41080
   651
haftmann@41080
   652
lemma inf_apply:
haftmann@41080
   653
  "(f \<sqinter> g) x = f x \<sqinter> g x"
haftmann@41080
   654
  by (simp add: inf_fun_def)
haftmann@25510
   655
haftmann@25510
   656
definition
haftmann@41080
   657
  "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
haftmann@41080
   658
haftmann@41080
   659
lemma sup_apply:
haftmann@41080
   660
  "(f \<squnion> g) x = f x \<squnion> g x"
haftmann@41080
   661
  by (simp add: sup_fun_def)
haftmann@25510
   662
haftmann@32780
   663
instance proof
haftmann@41080
   664
qed (simp_all add: le_fun_def inf_apply sup_apply)
haftmann@23878
   665
haftmann@25510
   666
end
haftmann@23878
   667
haftmann@41080
   668
instance "fun" :: (type, distrib_lattice) distrib_lattice proof
haftmann@41080
   669
qed (rule ext, simp add: sup_inf_distrib1 inf_apply sup_apply)
haftmann@31991
   670
haftmann@34007
   671
instance "fun" :: (type, bounded_lattice) bounded_lattice ..
haftmann@34007
   672
haftmann@31991
   673
instantiation "fun" :: (type, uminus) uminus
haftmann@31991
   674
begin
haftmann@31991
   675
haftmann@31991
   676
definition
haftmann@31991
   677
  fun_Compl_def: "- A = (\<lambda>x. - A x)"
haftmann@31991
   678
haftmann@41080
   679
lemma uminus_apply:
haftmann@41080
   680
  "(- A) x = - (A x)"
haftmann@41080
   681
  by (simp add: fun_Compl_def)
haftmann@41080
   682
haftmann@31991
   683
instance ..
haftmann@31991
   684
haftmann@31991
   685
end
haftmann@31991
   686
haftmann@31991
   687
instantiation "fun" :: (type, minus) minus
haftmann@31991
   688
begin
haftmann@31991
   689
haftmann@31991
   690
definition
haftmann@31991
   691
  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
haftmann@31991
   692
haftmann@41080
   693
lemma minus_apply:
haftmann@41080
   694
  "(A - B) x = A x - B x"
haftmann@41080
   695
  by (simp add: fun_diff_def)
haftmann@41080
   696
haftmann@31991
   697
instance ..
haftmann@31991
   698
haftmann@31991
   699
end
haftmann@31991
   700
haftmann@41080
   701
instance "fun" :: (type, boolean_algebra) boolean_algebra proof
haftmann@41080
   702
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
   703
haftmann@25062
   704
no_notation
wenzelm@25382
   705
  less_eq  (infix "\<sqsubseteq>" 50) and
wenzelm@25382
   706
  less (infix "\<sqsubset>" 50) and
wenzelm@25382
   707
  inf  (infixl "\<sqinter>" 70) and
haftmann@32568
   708
  sup  (infixl "\<squnion>" 65) and
haftmann@32568
   709
  top ("\<top>") and
haftmann@32568
   710
  bot ("\<bottom>")
haftmann@25062
   711
haftmann@21249
   712
end