src/HOL/Lattices.thy
author haftmann
Sat Mar 23 17:11:06 2013 +0100 (2013-03-23)
changeset 51487 f4bfdee99304
parent 51387 dbc4a77488b2
child 51489 f738e6dbd844
permissions -rw-r--r--
locales for abstract orders
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@51487
    14
  These 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@51487
    19
no_notation times (infixl "*" 70)
haftmann@51487
    20
no_notation Groups.one ("1")
haftmann@51487
    21
haftmann@35301
    22
locale semilattice = abel_semigroup +
haftmann@51487
    23
  assumes idem [simp]: "a * a = a"
haftmann@35301
    24
begin
haftmann@35301
    25
haftmann@51487
    26
lemma left_idem [simp]: "a * (a * b) = a * b"
nipkow@50615
    27
by (simp add: assoc [symmetric])
nipkow@50615
    28
haftmann@51487
    29
lemma right_idem [simp]: "(a * b) * b = a * b"
nipkow@50615
    30
by (simp add: assoc)
haftmann@35301
    31
haftmann@35301
    32
end
haftmann@35301
    33
haftmann@51487
    34
locale semilattice_neutr = semilattice + comm_monoid
haftmann@35301
    35
haftmann@51487
    36
locale semilattice_order = semilattice +
haftmann@51487
    37
  fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<preceq>" 50)
haftmann@51487
    38
    and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<prec>" 50)
haftmann@51487
    39
  assumes order_iff: "a \<preceq> b \<longleftrightarrow> a = a * b"
haftmann@51487
    40
    and semilattice_strict_iff_order: "a \<prec> b \<longleftrightarrow> a \<preceq> b \<and> a \<noteq> b"
haftmann@51487
    41
begin
haftmann@51487
    42
haftmann@51487
    43
lemma orderI:
haftmann@51487
    44
  "a = a * b \<Longrightarrow> a \<preceq> b"
haftmann@51487
    45
  by (simp add: order_iff)
haftmann@51487
    46
haftmann@51487
    47
lemma orderE:
haftmann@51487
    48
  assumes "a \<preceq> b"
haftmann@51487
    49
  obtains "a = a * b"
haftmann@51487
    50
  using assms by (unfold order_iff)
haftmann@51487
    51
haftmann@51487
    52
end
haftmann@35301
    53
haftmann@51487
    54
sublocale semilattice_order < ordering less_eq less
haftmann@51487
    55
proof
haftmann@51487
    56
  fix a b
haftmann@51487
    57
  show "a \<prec> b \<longleftrightarrow> a \<preceq> b \<and> a \<noteq> b"
haftmann@51487
    58
    by (fact semilattice_strict_iff_order)
haftmann@51487
    59
next
haftmann@51487
    60
  fix a
haftmann@51487
    61
  show "a \<preceq> a"
haftmann@51487
    62
    by (simp add: order_iff)
haftmann@51487
    63
next
haftmann@51487
    64
  fix a b
haftmann@51487
    65
  assume "a \<preceq> b" "b \<preceq> a"
haftmann@51487
    66
  then have "a = a * b" "a * b = b"
haftmann@51487
    67
    by (simp_all add: order_iff commute)
haftmann@51487
    68
  then show "a = b" by simp
haftmann@51487
    69
next
haftmann@51487
    70
  fix a b c
haftmann@51487
    71
  assume "a \<preceq> b" "b \<preceq> c"
haftmann@51487
    72
  then have "a = a * b" "b = b * c"
haftmann@51487
    73
    by (simp_all add: order_iff commute)
haftmann@51487
    74
  then have "a = a * (b * c)"
haftmann@51487
    75
    by simp
haftmann@51487
    76
  then have "a = (a * b) * c"
haftmann@51487
    77
    by (simp add: assoc)
haftmann@51487
    78
  with `a = a * b` [symmetric] have "a = a * c" by simp
haftmann@51487
    79
  then show "a \<preceq> c" by (rule orderI)
haftmann@51487
    80
qed
haftmann@35301
    81
haftmann@51487
    82
context semilattice_order
haftmann@35301
    83
begin
haftmann@35301
    84
haftmann@51487
    85
lemma cobounded1 [simp]:
haftmann@51487
    86
  "a * b \<preceq> a"
haftmann@51487
    87
  by (simp add: order_iff commute)  
haftmann@51487
    88
haftmann@51487
    89
lemma cobounded2 [simp]:
haftmann@51487
    90
  "a * b \<preceq> b"
haftmann@51487
    91
  by (simp add: order_iff)
haftmann@51487
    92
haftmann@51487
    93
lemma boundedI:
haftmann@51487
    94
  assumes "a \<preceq> b" and "a \<preceq> c"
haftmann@51487
    95
  shows "a \<preceq> b * c"
haftmann@51487
    96
proof (rule orderI)
haftmann@51487
    97
  from assms obtain "a * b = a" and "a * c = a" by (auto elim!: orderE)
haftmann@51487
    98
  then show "a = a * (b * c)" by (simp add: assoc [symmetric])
haftmann@51487
    99
qed
haftmann@51487
   100
haftmann@51487
   101
lemma boundedE:
haftmann@51487
   102
  assumes "a \<preceq> b * c"
haftmann@51487
   103
  obtains "a \<preceq> b" and "a \<preceq> c"
haftmann@51487
   104
  using assms by (blast intro: trans cobounded1 cobounded2)
haftmann@51487
   105
haftmann@51487
   106
lemma bounded_iff:
haftmann@51487
   107
  "a \<preceq> b * c \<longleftrightarrow> a \<preceq> b \<and> a \<preceq> c"
haftmann@51487
   108
  by (blast intro: boundedI elim: boundedE)
haftmann@51487
   109
haftmann@51487
   110
lemma strict_boundedE:
haftmann@51487
   111
  assumes "a \<prec> b * c"
haftmann@51487
   112
  obtains "a \<prec> b" and "a \<prec> c"
haftmann@51487
   113
  using assms by (auto simp add: commute strict_iff_order bounded_iff elim: orderE intro!: that)+
haftmann@51487
   114
haftmann@51487
   115
lemma coboundedI1:
haftmann@51487
   116
  "a \<preceq> c \<Longrightarrow> a * b \<preceq> c"
haftmann@51487
   117
  by (rule trans) auto
haftmann@51487
   118
haftmann@51487
   119
lemma coboundedI2:
haftmann@51487
   120
  "b \<preceq> c \<Longrightarrow> a * b \<preceq> c"
haftmann@51487
   121
  by (rule trans) auto
haftmann@51487
   122
haftmann@51487
   123
lemma mono: "a \<preceq> c \<Longrightarrow> b \<preceq> d \<Longrightarrow> a * b \<preceq> c * d"
haftmann@51487
   124
  by (blast intro: boundedI coboundedI1 coboundedI2)
haftmann@51487
   125
haftmann@51487
   126
lemma absorb1: "a \<preceq> b \<Longrightarrow> a * b = a"
haftmann@51487
   127
  by (rule antisym) (auto simp add: refl bounded_iff)
haftmann@51487
   128
haftmann@51487
   129
lemma absorb2: "b \<preceq> a \<Longrightarrow> a * b = b"
haftmann@51487
   130
  by (rule antisym) (auto simp add: refl bounded_iff)
haftmann@35301
   131
haftmann@35301
   132
end
haftmann@35301
   133
haftmann@51487
   134
locale semilattice_neutr_order = semilattice_neutr + semilattice_order
haftmann@51487
   135
haftmann@51487
   136
sublocale semilattice_neutr_order < ordering_top less_eq less 1
haftmann@51487
   137
  by default (simp add: order_iff)
haftmann@51487
   138
haftmann@51487
   139
notation times (infixl "*" 70)
haftmann@51487
   140
notation Groups.one ("1")
haftmann@51487
   141
haftmann@35301
   142
haftmann@46691
   143
subsection {* Syntactic infimum and supremum operations *}
haftmann@41082
   144
krauss@44845
   145
class inf =
krauss@44845
   146
  fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
haftmann@25206
   147
krauss@44845
   148
class sup = 
krauss@44845
   149
  fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
krauss@44845
   150
haftmann@46691
   151
haftmann@46691
   152
subsection {* Concrete lattices *}
haftmann@46691
   153
haftmann@46691
   154
notation
haftmann@46691
   155
  less_eq  (infix "\<sqsubseteq>" 50) and
haftmann@46691
   156
  less  (infix "\<sqsubset>" 50)
haftmann@46691
   157
krauss@44845
   158
class semilattice_inf =  order + inf +
haftmann@22737
   159
  assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
haftmann@22737
   160
  and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
nipkow@21733
   161
  and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
haftmann@21249
   162
krauss@44845
   163
class semilattice_sup = order + sup +
haftmann@22737
   164
  assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
haftmann@22737
   165
  and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
nipkow@21733
   166
  and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
haftmann@26014
   167
begin
haftmann@26014
   168
haftmann@26014
   169
text {* Dual lattice *}
haftmann@26014
   170
haftmann@31991
   171
lemma dual_semilattice:
krauss@44845
   172
  "class.semilattice_inf sup greater_eq greater"
haftmann@36635
   173
by (rule class.semilattice_inf.intro, rule dual_order)
haftmann@27682
   174
  (unfold_locales, simp_all add: sup_least)
haftmann@26014
   175
haftmann@26014
   176
end
haftmann@21249
   177
haftmann@35028
   178
class lattice = semilattice_inf + semilattice_sup
haftmann@21249
   179
wenzelm@25382
   180
haftmann@28562
   181
subsubsection {* Intro and elim rules*}
nipkow@21733
   182
haftmann@35028
   183
context semilattice_inf
nipkow@21733
   184
begin
haftmann@21249
   185
haftmann@32064
   186
lemma le_infI1:
haftmann@32064
   187
  "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
haftmann@32064
   188
  by (rule order_trans) auto
haftmann@21249
   189
haftmann@32064
   190
lemma le_infI2:
haftmann@32064
   191
  "b \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
haftmann@32064
   192
  by (rule order_trans) auto
nipkow@21733
   193
haftmann@32064
   194
lemma le_infI: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
huffman@36008
   195
  by (rule inf_greatest) (* FIXME: duplicate lemma *)
haftmann@21249
   196
haftmann@32064
   197
lemma le_infE: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
huffman@36008
   198
  by (blast intro: order_trans inf_le1 inf_le2)
haftmann@21249
   199
nipkow@21734
   200
lemma le_inf_iff [simp]:
haftmann@32064
   201
  "x \<sqsubseteq> y \<sqinter> z \<longleftrightarrow> x \<sqsubseteq> y \<and> x \<sqsubseteq> z"
haftmann@32064
   202
  by (blast intro: le_infI elim: le_infE)
nipkow@21733
   203
haftmann@32064
   204
lemma le_iff_inf:
haftmann@32064
   205
  "x \<sqsubseteq> y \<longleftrightarrow> x \<sqinter> y = x"
haftmann@32064
   206
  by (auto intro: le_infI1 antisym dest: eq_iff [THEN iffD1])
haftmann@21249
   207
haftmann@43753
   208
lemma inf_mono: "a \<sqsubseteq> c \<Longrightarrow> b \<sqsubseteq> d \<Longrightarrow> a \<sqinter> b \<sqsubseteq> c \<sqinter> d"
huffman@36008
   209
  by (fast intro: inf_greatest le_infI1 le_infI2)
huffman@36008
   210
haftmann@25206
   211
lemma mono_inf:
haftmann@35028
   212
  fixes f :: "'a \<Rightarrow> 'b\<Colon>semilattice_inf"
haftmann@34007
   213
  shows "mono f \<Longrightarrow> f (A \<sqinter> B) \<sqsubseteq> f A \<sqinter> f B"
haftmann@25206
   214
  by (auto simp add: mono_def intro: Lattices.inf_greatest)
nipkow@21733
   215
haftmann@25206
   216
end
nipkow@21733
   217
haftmann@35028
   218
context semilattice_sup
nipkow@21733
   219
begin
haftmann@21249
   220
haftmann@32064
   221
lemma le_supI1:
haftmann@32064
   222
  "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
   223
  by (rule order_trans) auto
haftmann@21249
   224
haftmann@32064
   225
lemma le_supI2:
haftmann@32064
   226
  "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
haftmann@25062
   227
  by (rule order_trans) auto 
nipkow@21733
   228
haftmann@32064
   229
lemma le_supI:
haftmann@32064
   230
  "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
huffman@36008
   231
  by (rule sup_least) (* FIXME: duplicate lemma *)
haftmann@21249
   232
haftmann@32064
   233
lemma le_supE:
haftmann@32064
   234
  "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
huffman@36008
   235
  by (blast intro: order_trans sup_ge1 sup_ge2)
haftmann@22422
   236
haftmann@32064
   237
lemma le_sup_iff [simp]:
haftmann@32064
   238
  "x \<squnion> y \<sqsubseteq> z \<longleftrightarrow> x \<sqsubseteq> z \<and> y \<sqsubseteq> z"
haftmann@32064
   239
  by (blast intro: le_supI elim: le_supE)
nipkow@21733
   240
haftmann@32064
   241
lemma le_iff_sup:
haftmann@32064
   242
  "x \<sqsubseteq> y \<longleftrightarrow> x \<squnion> y = y"
haftmann@32064
   243
  by (auto intro: le_supI2 antisym dest: eq_iff [THEN iffD1])
nipkow@21734
   244
haftmann@43753
   245
lemma sup_mono: "a \<sqsubseteq> c \<Longrightarrow> b \<sqsubseteq> d \<Longrightarrow> a \<squnion> b \<sqsubseteq> c \<squnion> d"
huffman@36008
   246
  by (fast intro: sup_least le_supI1 le_supI2)
huffman@36008
   247
haftmann@25206
   248
lemma mono_sup:
haftmann@35028
   249
  fixes f :: "'a \<Rightarrow> 'b\<Colon>semilattice_sup"
haftmann@34007
   250
  shows "mono f \<Longrightarrow> f A \<squnion> f B \<sqsubseteq> f (A \<squnion> B)"
haftmann@25206
   251
  by (auto simp add: mono_def intro: Lattices.sup_least)
nipkow@21733
   252
haftmann@25206
   253
end
haftmann@23878
   254
nipkow@21733
   255
haftmann@32064
   256
subsubsection {* Equational laws *}
haftmann@21249
   257
haftmann@35028
   258
sublocale semilattice_inf < inf!: semilattice inf
haftmann@34973
   259
proof
haftmann@34973
   260
  fix a b c
haftmann@34973
   261
  show "(a \<sqinter> b) \<sqinter> c = a \<sqinter> (b \<sqinter> c)"
haftmann@34973
   262
    by (rule antisym) (auto intro: le_infI1 le_infI2)
haftmann@34973
   263
  show "a \<sqinter> b = b \<sqinter> a"
haftmann@34973
   264
    by (rule antisym) auto
haftmann@34973
   265
  show "a \<sqinter> a = a"
haftmann@34973
   266
    by (rule antisym) auto
haftmann@34973
   267
qed
haftmann@34973
   268
haftmann@51487
   269
sublocale semilattice_sup < sup!: semilattice sup
haftmann@51487
   270
proof
haftmann@51487
   271
  fix a b c
haftmann@51487
   272
  show "(a \<squnion> b) \<squnion> c = a \<squnion> (b \<squnion> c)"
haftmann@51487
   273
    by (rule antisym) (auto intro: le_supI1 le_supI2)
haftmann@51487
   274
  show "a \<squnion> b = b \<squnion> a"
haftmann@51487
   275
    by (rule antisym) auto
haftmann@51487
   276
  show "a \<squnion> a = a"
haftmann@51487
   277
    by (rule antisym) auto
haftmann@51487
   278
qed
haftmann@51487
   279
haftmann@51487
   280
sublocale semilattice_inf < inf!: semilattice_order inf less_eq less
haftmann@51487
   281
  by default (auto simp add: le_iff_inf less_le)
haftmann@51487
   282
haftmann@51487
   283
sublocale semilattice_sup < sup!: semilattice_order sup greater_eq greater
haftmann@51487
   284
  by default (auto simp add: le_iff_sup sup.commute less_le)
haftmann@51487
   285
haftmann@35028
   286
context semilattice_inf
nipkow@21733
   287
begin
nipkow@21733
   288
haftmann@34973
   289
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
haftmann@34973
   290
  by (fact inf.assoc)
nipkow@21733
   291
haftmann@34973
   292
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
haftmann@34973
   293
  by (fact inf.commute)
nipkow@21733
   294
haftmann@34973
   295
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
haftmann@34973
   296
  by (fact inf.left_commute)
nipkow@21733
   297
huffman@44921
   298
lemma inf_idem: "x \<sqinter> x = x"
huffman@44921
   299
  by (fact inf.idem) (* already simp *)
haftmann@34973
   300
nipkow@50615
   301
lemma inf_left_idem: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
nipkow@50615
   302
  by (fact inf.left_idem) (* already simp *)
nipkow@50615
   303
nipkow@50615
   304
lemma inf_right_idem: "(x \<sqinter> y) \<sqinter> y = x \<sqinter> y"
nipkow@50615
   305
  by (fact inf.right_idem) (* already simp *)
nipkow@21733
   306
haftmann@32642
   307
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
haftmann@32064
   308
  by (rule antisym) auto
nipkow@21733
   309
haftmann@32642
   310
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
haftmann@32064
   311
  by (rule antisym) auto
haftmann@34973
   312
 
haftmann@32064
   313
lemmas inf_aci = inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@21733
   314
nipkow@21733
   315
end
nipkow@21733
   316
haftmann@35028
   317
context semilattice_sup
nipkow@21733
   318
begin
haftmann@21249
   319
haftmann@34973
   320
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
haftmann@34973
   321
  by (fact sup.assoc)
nipkow@21733
   322
haftmann@34973
   323
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
haftmann@34973
   324
  by (fact sup.commute)
nipkow@21733
   325
haftmann@34973
   326
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
haftmann@34973
   327
  by (fact sup.left_commute)
nipkow@21733
   328
huffman@44921
   329
lemma sup_idem: "x \<squnion> x = x"
huffman@44921
   330
  by (fact sup.idem) (* already simp *)
haftmann@34973
   331
noschinl@44918
   332
lemma sup_left_idem [simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
haftmann@34973
   333
  by (fact sup.left_idem)
nipkow@21733
   334
haftmann@32642
   335
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
haftmann@32064
   336
  by (rule antisym) auto
nipkow@21733
   337
haftmann@32642
   338
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
haftmann@32064
   339
  by (rule antisym) auto
haftmann@21249
   340
haftmann@32064
   341
lemmas sup_aci = sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@21733
   342
nipkow@21733
   343
end
haftmann@21249
   344
nipkow@21733
   345
context lattice
nipkow@21733
   346
begin
nipkow@21733
   347
haftmann@31991
   348
lemma dual_lattice:
krauss@44845
   349
  "class.lattice sup (op \<ge>) (op >) inf"
haftmann@36635
   350
  by (rule class.lattice.intro, rule dual_semilattice, rule class.semilattice_sup.intro, rule dual_order)
haftmann@31991
   351
    (unfold_locales, auto)
haftmann@31991
   352
noschinl@44918
   353
lemma inf_sup_absorb [simp]: "x \<sqinter> (x \<squnion> y) = x"
haftmann@25102
   354
  by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
nipkow@21733
   355
noschinl@44918
   356
lemma sup_inf_absorb [simp]: "x \<squnion> (x \<sqinter> y) = x"
haftmann@25102
   357
  by (blast intro: antisym sup_ge1 sup_least inf_le1)
nipkow@21733
   358
haftmann@32064
   359
lemmas inf_sup_aci = inf_aci sup_aci
nipkow@21734
   360
haftmann@22454
   361
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
haftmann@22454
   362
nipkow@21734
   363
text{* Towards distributivity *}
haftmann@21249
   364
nipkow@21734
   365
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@32064
   366
  by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
nipkow@21734
   367
nipkow@21734
   368
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
haftmann@32064
   369
  by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
nipkow@21734
   370
nipkow@21734
   371
text{* If you have one of them, you have them all. *}
haftmann@21249
   372
nipkow@21733
   373
lemma distrib_imp1:
haftmann@21249
   374
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   375
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   376
proof-
noschinl@44918
   377
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by simp
noschinl@44918
   378
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))"
noschinl@44918
   379
    by (simp add: D inf_commute sup_assoc del: sup_inf_absorb)
haftmann@21249
   380
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
noschinl@44919
   381
    by(simp add: inf_commute)
haftmann@21249
   382
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   383
  finally show ?thesis .
haftmann@21249
   384
qed
haftmann@21249
   385
nipkow@21733
   386
lemma distrib_imp2:
haftmann@21249
   387
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   388
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   389
proof-
noschinl@44918
   390
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by simp
noschinl@44918
   391
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))"
noschinl@44918
   392
    by (simp add: D sup_commute inf_assoc del: inf_sup_absorb)
haftmann@21249
   393
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
noschinl@44919
   394
    by(simp add: sup_commute)
haftmann@21249
   395
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   396
  finally show ?thesis .
haftmann@21249
   397
qed
haftmann@21249
   398
nipkow@21733
   399
end
haftmann@21249
   400
haftmann@32568
   401
subsubsection {* Strict order *}
haftmann@32568
   402
haftmann@35028
   403
context semilattice_inf
haftmann@32568
   404
begin
haftmann@32568
   405
haftmann@32568
   406
lemma less_infI1:
haftmann@32568
   407
  "a \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   408
  by (auto simp add: less_le inf_absorb1 intro: le_infI1)
haftmann@32568
   409
haftmann@32568
   410
lemma less_infI2:
haftmann@32568
   411
  "b \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
haftmann@32642
   412
  by (auto simp add: less_le inf_absorb2 intro: le_infI2)
haftmann@32568
   413
haftmann@32568
   414
end
haftmann@32568
   415
haftmann@35028
   416
context semilattice_sup
haftmann@32568
   417
begin
haftmann@32568
   418
haftmann@32568
   419
lemma less_supI1:
haftmann@34007
   420
  "x \<sqsubset> a \<Longrightarrow> x \<sqsubset> a \<squnion> b"
huffman@44921
   421
  using dual_semilattice
huffman@44921
   422
  by (rule semilattice_inf.less_infI1)
haftmann@32568
   423
haftmann@32568
   424
lemma less_supI2:
haftmann@34007
   425
  "x \<sqsubset> b \<Longrightarrow> x \<sqsubset> a \<squnion> b"
huffman@44921
   426
  using dual_semilattice
huffman@44921
   427
  by (rule semilattice_inf.less_infI2)
haftmann@32568
   428
haftmann@32568
   429
end
haftmann@32568
   430
haftmann@21249
   431
haftmann@24164
   432
subsection {* Distributive lattices *}
haftmann@21249
   433
haftmann@22454
   434
class distrib_lattice = lattice +
haftmann@21249
   435
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   436
nipkow@21733
   437
context distrib_lattice
nipkow@21733
   438
begin
nipkow@21733
   439
nipkow@21733
   440
lemma sup_inf_distrib2:
huffman@44921
   441
  "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
huffman@44921
   442
  by (simp add: sup_commute sup_inf_distrib1)
haftmann@21249
   443
nipkow@21733
   444
lemma inf_sup_distrib1:
huffman@44921
   445
  "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
huffman@44921
   446
  by (rule distrib_imp2 [OF sup_inf_distrib1])
haftmann@21249
   447
nipkow@21733
   448
lemma inf_sup_distrib2:
huffman@44921
   449
  "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
huffman@44921
   450
  by (simp add: inf_commute inf_sup_distrib1)
haftmann@21249
   451
haftmann@31991
   452
lemma dual_distrib_lattice:
krauss@44845
   453
  "class.distrib_lattice sup (op \<ge>) (op >) inf"
haftmann@36635
   454
  by (rule class.distrib_lattice.intro, rule dual_lattice)
haftmann@31991
   455
    (unfold_locales, fact inf_sup_distrib1)
haftmann@31991
   456
huffman@36008
   457
lemmas sup_inf_distrib =
huffman@36008
   458
  sup_inf_distrib1 sup_inf_distrib2
huffman@36008
   459
huffman@36008
   460
lemmas inf_sup_distrib =
huffman@36008
   461
  inf_sup_distrib1 inf_sup_distrib2
huffman@36008
   462
nipkow@21733
   463
lemmas distrib =
haftmann@21249
   464
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   465
nipkow@21733
   466
end
nipkow@21733
   467
haftmann@21249
   468
haftmann@34007
   469
subsection {* Bounded lattices and boolean algebras *}
haftmann@31991
   470
haftmann@51487
   471
class bounded_semilattice_inf_top = semilattice_inf + top
haftmann@51487
   472
haftmann@51487
   473
sublocale bounded_semilattice_inf_top < inf_top!: semilattice_neutr inf top
haftmann@51487
   474
proof
haftmann@51487
   475
  fix x
haftmann@51487
   476
  show "x \<sqinter> \<top> = x"
haftmann@51487
   477
    by (rule inf_absorb1) simp
haftmann@51487
   478
qed
haftmann@51487
   479
haftmann@51487
   480
sublocale bounded_semilattice_inf_top < inf_top!: semilattice_neutr_order inf top less_eq less ..
haftmann@51487
   481
haftmann@51487
   482
class bounded_semilattice_sup_bot = semilattice_sup + bot
haftmann@51487
   483
haftmann@51487
   484
sublocale bounded_semilattice_sup_bot < sup_bot!: semilattice_neutr sup bot
haftmann@51487
   485
proof
haftmann@51487
   486
  fix x
haftmann@51487
   487
  show "x \<squnion> \<bottom> = x"
haftmann@51487
   488
    by (rule sup_absorb1) simp
haftmann@51487
   489
qed
haftmann@51487
   490
haftmann@51487
   491
sublocale bounded_semilattice_sup_bot < sup_bot!: semilattice_neutr_order sup bot greater_eq greater ..
haftmann@51487
   492
kaliszyk@36352
   493
class bounded_lattice_bot = lattice + bot
haftmann@31991
   494
begin
haftmann@31991
   495
haftmann@51487
   496
subclass bounded_semilattice_sup_bot ..
haftmann@51487
   497
haftmann@31991
   498
lemma inf_bot_left [simp]:
haftmann@34007
   499
  "\<bottom> \<sqinter> x = \<bottom>"
haftmann@31991
   500
  by (rule inf_absorb1) simp
haftmann@31991
   501
haftmann@31991
   502
lemma inf_bot_right [simp]:
haftmann@34007
   503
  "x \<sqinter> \<bottom> = \<bottom>"
haftmann@31991
   504
  by (rule inf_absorb2) simp
haftmann@31991
   505
haftmann@51487
   506
lemma sup_bot_left:
kaliszyk@36352
   507
  "\<bottom> \<squnion> x = x"
haftmann@51487
   508
  by (fact sup_bot.left_neutral)
kaliszyk@36352
   509
haftmann@51487
   510
lemma sup_bot_right:
kaliszyk@36352
   511
  "x \<squnion> \<bottom> = x"
haftmann@51487
   512
  by (fact sup_bot.right_neutral)
kaliszyk@36352
   513
kaliszyk@36352
   514
lemma sup_eq_bot_iff [simp]:
kaliszyk@36352
   515
  "x \<squnion> y = \<bottom> \<longleftrightarrow> x = \<bottom> \<and> y = \<bottom>"
kaliszyk@36352
   516
  by (simp add: eq_iff)
kaliszyk@36352
   517
kaliszyk@36352
   518
end
kaliszyk@36352
   519
kaliszyk@36352
   520
class bounded_lattice_top = lattice + top
kaliszyk@36352
   521
begin
kaliszyk@36352
   522
haftmann@51487
   523
subclass bounded_semilattice_inf_top ..
haftmann@51487
   524
haftmann@31991
   525
lemma sup_top_left [simp]:
haftmann@34007
   526
  "\<top> \<squnion> x = \<top>"
haftmann@31991
   527
  by (rule sup_absorb1) simp
haftmann@31991
   528
haftmann@31991
   529
lemma sup_top_right [simp]:
haftmann@34007
   530
  "x \<squnion> \<top> = \<top>"
haftmann@31991
   531
  by (rule sup_absorb2) simp
haftmann@31991
   532
haftmann@51487
   533
lemma inf_top_left:
haftmann@34007
   534
  "\<top> \<sqinter> x = x"
haftmann@51487
   535
  by (fact inf_top.left_neutral)
haftmann@31991
   536
haftmann@51487
   537
lemma inf_top_right:
haftmann@34007
   538
  "x \<sqinter> \<top> = x"
haftmann@51487
   539
  by (fact inf_top.right_neutral)
haftmann@31991
   540
huffman@36008
   541
lemma inf_eq_top_iff [simp]:
huffman@36008
   542
  "x \<sqinter> y = \<top> \<longleftrightarrow> x = \<top> \<and> y = \<top>"
huffman@36008
   543
  by (simp add: eq_iff)
haftmann@32568
   544
kaliszyk@36352
   545
end
kaliszyk@36352
   546
haftmann@51487
   547
class bounded_lattice = lattice + bot + top
kaliszyk@36352
   548
begin
kaliszyk@36352
   549
haftmann@51487
   550
subclass bounded_lattice_bot ..
haftmann@51487
   551
subclass bounded_lattice_top ..
haftmann@51487
   552
kaliszyk@36352
   553
lemma dual_bounded_lattice:
krauss@44845
   554
  "class.bounded_lattice sup greater_eq greater inf \<top> \<bottom>"
kaliszyk@36352
   555
  by unfold_locales (auto simp add: less_le_not_le)
haftmann@32568
   556
haftmann@34007
   557
end
haftmann@34007
   558
haftmann@34007
   559
class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
haftmann@34007
   560
  assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
haftmann@34007
   561
    and sup_compl_top: "x \<squnion> - x = \<top>"
haftmann@34007
   562
  assumes diff_eq: "x - y = x \<sqinter> - y"
haftmann@34007
   563
begin
haftmann@34007
   564
haftmann@34007
   565
lemma dual_boolean_algebra:
krauss@44845
   566
  "class.boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus sup greater_eq greater inf \<top> \<bottom>"
haftmann@36635
   567
  by (rule class.boolean_algebra.intro, rule dual_bounded_lattice, rule dual_distrib_lattice)
haftmann@34007
   568
    (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
haftmann@34007
   569
noschinl@44918
   570
lemma compl_inf_bot [simp]:
haftmann@34007
   571
  "- x \<sqinter> x = \<bottom>"
haftmann@34007
   572
  by (simp add: inf_commute inf_compl_bot)
haftmann@34007
   573
noschinl@44918
   574
lemma compl_sup_top [simp]:
haftmann@34007
   575
  "- x \<squnion> x = \<top>"
haftmann@34007
   576
  by (simp add: sup_commute sup_compl_top)
haftmann@34007
   577
haftmann@31991
   578
lemma compl_unique:
haftmann@34007
   579
  assumes "x \<sqinter> y = \<bottom>"
haftmann@34007
   580
    and "x \<squnion> y = \<top>"
haftmann@31991
   581
  shows "- x = y"
haftmann@31991
   582
proof -
haftmann@31991
   583
  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
haftmann@31991
   584
    using inf_compl_bot assms(1) by simp
haftmann@31991
   585
  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
haftmann@31991
   586
    by (simp add: inf_commute)
haftmann@31991
   587
  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
haftmann@31991
   588
    by (simp add: inf_sup_distrib1)
haftmann@34007
   589
  then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
haftmann@31991
   590
    using sup_compl_top assms(2) by simp
krauss@34209
   591
  then show "- x = y" by simp
haftmann@31991
   592
qed
haftmann@31991
   593
haftmann@31991
   594
lemma double_compl [simp]:
haftmann@31991
   595
  "- (- x) = x"
haftmann@31991
   596
  using compl_inf_bot compl_sup_top by (rule compl_unique)
haftmann@31991
   597
haftmann@31991
   598
lemma compl_eq_compl_iff [simp]:
haftmann@31991
   599
  "- x = - y \<longleftrightarrow> x = y"
haftmann@31991
   600
proof
haftmann@31991
   601
  assume "- x = - y"
huffman@36008
   602
  then have "- (- x) = - (- y)" by (rule arg_cong)
haftmann@31991
   603
  then show "x = y" by simp
haftmann@31991
   604
next
haftmann@31991
   605
  assume "x = y"
haftmann@31991
   606
  then show "- x = - y" by simp
haftmann@31991
   607
qed
haftmann@31991
   608
haftmann@31991
   609
lemma compl_bot_eq [simp]:
haftmann@34007
   610
  "- \<bottom> = \<top>"
haftmann@31991
   611
proof -
haftmann@34007
   612
  from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
haftmann@31991
   613
  then show ?thesis by simp
haftmann@31991
   614
qed
haftmann@31991
   615
haftmann@31991
   616
lemma compl_top_eq [simp]:
haftmann@34007
   617
  "- \<top> = \<bottom>"
haftmann@31991
   618
proof -
haftmann@34007
   619
  from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
haftmann@31991
   620
  then show ?thesis by simp
haftmann@31991
   621
qed
haftmann@31991
   622
haftmann@31991
   623
lemma compl_inf [simp]:
haftmann@31991
   624
  "- (x \<sqinter> y) = - x \<squnion> - y"
haftmann@31991
   625
proof (rule compl_unique)
huffman@36008
   626
  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
huffman@36008
   627
    by (simp only: inf_sup_distrib inf_aci)
huffman@36008
   628
  then show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
haftmann@31991
   629
    by (simp add: inf_compl_bot)
haftmann@31991
   630
next
huffman@36008
   631
  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
huffman@36008
   632
    by (simp only: sup_inf_distrib sup_aci)
huffman@36008
   633
  then show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
haftmann@31991
   634
    by (simp add: sup_compl_top)
haftmann@31991
   635
qed
haftmann@31991
   636
haftmann@31991
   637
lemma compl_sup [simp]:
haftmann@31991
   638
  "- (x \<squnion> y) = - x \<sqinter> - y"
huffman@44921
   639
  using dual_boolean_algebra
huffman@44921
   640
  by (rule boolean_algebra.compl_inf)
haftmann@31991
   641
huffman@36008
   642
lemma compl_mono:
huffman@36008
   643
  "x \<sqsubseteq> y \<Longrightarrow> - y \<sqsubseteq> - x"
huffman@36008
   644
proof -
huffman@36008
   645
  assume "x \<sqsubseteq> y"
huffman@36008
   646
  then have "x \<squnion> y = y" by (simp only: le_iff_sup)
huffman@36008
   647
  then have "- (x \<squnion> y) = - y" by simp
huffman@36008
   648
  then have "- x \<sqinter> - y = - y" by simp
huffman@36008
   649
  then have "- y \<sqinter> - x = - y" by (simp only: inf_commute)
huffman@36008
   650
  then show "- y \<sqsubseteq> - x" by (simp only: le_iff_inf)
huffman@36008
   651
qed
huffman@36008
   652
noschinl@44918
   653
lemma compl_le_compl_iff [simp]:
haftmann@43753
   654
  "- x \<sqsubseteq> - y \<longleftrightarrow> y \<sqsubseteq> x"
haftmann@43873
   655
  by (auto dest: compl_mono)
haftmann@43873
   656
haftmann@43873
   657
lemma compl_le_swap1:
haftmann@43873
   658
  assumes "y \<sqsubseteq> - x" shows "x \<sqsubseteq> -y"
haftmann@43873
   659
proof -
haftmann@43873
   660
  from assms have "- (- x) \<sqsubseteq> - y" by (simp only: compl_le_compl_iff)
haftmann@43873
   661
  then show ?thesis by simp
haftmann@43873
   662
qed
haftmann@43873
   663
haftmann@43873
   664
lemma compl_le_swap2:
haftmann@43873
   665
  assumes "- y \<sqsubseteq> x" shows "- x \<sqsubseteq> y"
haftmann@43873
   666
proof -
haftmann@43873
   667
  from assms have "- x \<sqsubseteq> - (- y)" by (simp only: compl_le_compl_iff)
haftmann@43873
   668
  then show ?thesis by simp
haftmann@43873
   669
qed
haftmann@43873
   670
haftmann@43873
   671
lemma compl_less_compl_iff: (* TODO: declare [simp] ? *)
haftmann@43873
   672
  "- x \<sqsubset> - y \<longleftrightarrow> y \<sqsubset> x"
noschinl@44919
   673
  by (auto simp add: less_le)
haftmann@43873
   674
haftmann@43873
   675
lemma compl_less_swap1:
haftmann@43873
   676
  assumes "y \<sqsubset> - x" shows "x \<sqsubset> - y"
haftmann@43873
   677
proof -
haftmann@43873
   678
  from assms have "- (- x) \<sqsubset> - y" by (simp only: compl_less_compl_iff)
haftmann@43873
   679
  then show ?thesis by simp
haftmann@43873
   680
qed
haftmann@43873
   681
haftmann@43873
   682
lemma compl_less_swap2:
haftmann@43873
   683
  assumes "- y \<sqsubset> x" shows "- x \<sqsubset> y"
haftmann@43873
   684
proof -
haftmann@43873
   685
  from assms have "- x \<sqsubset> - (- y)" by (simp only: compl_less_compl_iff)
haftmann@43873
   686
  then show ?thesis by simp
haftmann@43873
   687
qed
huffman@36008
   688
haftmann@31991
   689
end
haftmann@31991
   690
haftmann@31991
   691
haftmann@22454
   692
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   693
haftmann@35028
   694
lemma (in semilattice_inf) inf_unique:
haftmann@22454
   695
  fixes f (infixl "\<triangle>" 70)
haftmann@34007
   696
  assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
haftmann@34007
   697
  and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
haftmann@22737
   698
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   699
proof (rule antisym)
haftmann@34007
   700
  show "x \<triangle> y \<sqsubseteq> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   701
next
haftmann@34007
   702
  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
   703
  show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   704
qed
haftmann@22454
   705
haftmann@35028
   706
lemma (in semilattice_sup) sup_unique:
haftmann@22454
   707
  fixes f (infixl "\<nabla>" 70)
haftmann@34007
   708
  assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
haftmann@34007
   709
  and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
haftmann@22737
   710
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   711
proof (rule antisym)
haftmann@34007
   712
  show "x \<squnion> y \<sqsubseteq> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   713
next
haftmann@34007
   714
  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
   715
  show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   716
qed
huffman@36008
   717
haftmann@22454
   718
haftmann@22916
   719
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   720
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   721
krauss@44845
   722
sublocale linorder < min_max!: distrib_lattice min less_eq less max
haftmann@28823
   723
proof
haftmann@22916
   724
  fix x y z
haftmann@32512
   725
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@32512
   726
    by (auto simp add: min_def max_def)
haftmann@22916
   727
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   728
haftmann@35028
   729
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{semilattice_inf, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   730
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   731
haftmann@35028
   732
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{semilattice_sup, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@25102
   733
  by (rule ext)+ (auto intro: antisym)
nipkow@21733
   734
haftmann@21249
   735
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   736
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   737
 
haftmann@34973
   738
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@34973
   739
  min_max.inf.left_commute
haftmann@21249
   740
haftmann@34973
   741
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@34973
   742
  min_max.sup.left_commute
haftmann@34973
   743
haftmann@21249
   744
haftmann@46631
   745
subsection {* Lattice on @{typ bool} *}
haftmann@22454
   746
haftmann@31991
   747
instantiation bool :: boolean_algebra
haftmann@25510
   748
begin
haftmann@25510
   749
haftmann@25510
   750
definition
haftmann@41080
   751
  bool_Compl_def [simp]: "uminus = Not"
haftmann@31991
   752
haftmann@31991
   753
definition
haftmann@41080
   754
  bool_diff_def [simp]: "A - B \<longleftrightarrow> A \<and> \<not> B"
haftmann@31991
   755
haftmann@31991
   756
definition
haftmann@41080
   757
  [simp]: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
haftmann@25510
   758
haftmann@25510
   759
definition
haftmann@41080
   760
  [simp]: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
haftmann@25510
   761
haftmann@31991
   762
instance proof
haftmann@41080
   763
qed auto
haftmann@22454
   764
haftmann@25510
   765
end
haftmann@25510
   766
haftmann@32781
   767
lemma sup_boolI1:
haftmann@32781
   768
  "P \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   769
  by simp
haftmann@32781
   770
haftmann@32781
   771
lemma sup_boolI2:
haftmann@32781
   772
  "Q \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   773
  by simp
haftmann@32781
   774
haftmann@32781
   775
lemma sup_boolE:
haftmann@32781
   776
  "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@41080
   777
  by auto
haftmann@32781
   778
haftmann@23878
   779
haftmann@46631
   780
subsection {* Lattice on @{typ "_ \<Rightarrow> _"} *}
haftmann@23878
   781
nipkow@51387
   782
instantiation "fun" :: (type, semilattice_sup) semilattice_sup
haftmann@25510
   783
begin
haftmann@25510
   784
haftmann@25510
   785
definition
haftmann@41080
   786
  "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
haftmann@41080
   787
haftmann@49769
   788
lemma sup_apply [simp, code]:
haftmann@41080
   789
  "(f \<squnion> g) x = f x \<squnion> g x"
haftmann@41080
   790
  by (simp add: sup_fun_def)
haftmann@25510
   791
haftmann@32780
   792
instance proof
noschinl@46884
   793
qed (simp_all add: le_fun_def)
haftmann@23878
   794
haftmann@25510
   795
end
haftmann@23878
   796
nipkow@51387
   797
instantiation "fun" :: (type, semilattice_inf) semilattice_inf
nipkow@51387
   798
begin
nipkow@51387
   799
nipkow@51387
   800
definition
nipkow@51387
   801
  "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
nipkow@51387
   802
nipkow@51387
   803
lemma inf_apply [simp, code]:
nipkow@51387
   804
  "(f \<sqinter> g) x = f x \<sqinter> g x"
nipkow@51387
   805
  by (simp add: inf_fun_def)
nipkow@51387
   806
nipkow@51387
   807
instance proof
nipkow@51387
   808
qed (simp_all add: le_fun_def)
nipkow@51387
   809
nipkow@51387
   810
end
nipkow@51387
   811
nipkow@51387
   812
instance "fun" :: (type, lattice) lattice ..
nipkow@51387
   813
haftmann@41080
   814
instance "fun" :: (type, distrib_lattice) distrib_lattice proof
noschinl@46884
   815
qed (rule ext, simp add: sup_inf_distrib1)
haftmann@31991
   816
haftmann@34007
   817
instance "fun" :: (type, bounded_lattice) bounded_lattice ..
haftmann@34007
   818
haftmann@31991
   819
instantiation "fun" :: (type, uminus) uminus
haftmann@31991
   820
begin
haftmann@31991
   821
haftmann@31991
   822
definition
haftmann@31991
   823
  fun_Compl_def: "- A = (\<lambda>x. - A x)"
haftmann@31991
   824
haftmann@49769
   825
lemma uminus_apply [simp, code]:
haftmann@41080
   826
  "(- A) x = - (A x)"
haftmann@41080
   827
  by (simp add: fun_Compl_def)
haftmann@41080
   828
haftmann@31991
   829
instance ..
haftmann@31991
   830
haftmann@31991
   831
end
haftmann@31991
   832
haftmann@31991
   833
instantiation "fun" :: (type, minus) minus
haftmann@31991
   834
begin
haftmann@31991
   835
haftmann@31991
   836
definition
haftmann@31991
   837
  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
haftmann@31991
   838
haftmann@49769
   839
lemma minus_apply [simp, code]:
haftmann@41080
   840
  "(A - B) x = A x - B x"
haftmann@41080
   841
  by (simp add: fun_diff_def)
haftmann@41080
   842
haftmann@31991
   843
instance ..
haftmann@31991
   844
haftmann@31991
   845
end
haftmann@31991
   846
haftmann@41080
   847
instance "fun" :: (type, boolean_algebra) boolean_algebra proof
noschinl@46884
   848
qed (rule ext, simp_all add: inf_compl_bot sup_compl_top diff_eq)+
berghofe@26794
   849
haftmann@46631
   850
haftmann@46631
   851
subsection {* Lattice on unary and binary predicates *}
haftmann@46631
   852
haftmann@46631
   853
lemma inf1I: "A x \<Longrightarrow> B x \<Longrightarrow> (A \<sqinter> B) x"
haftmann@46631
   854
  by (simp add: inf_fun_def)
haftmann@46631
   855
haftmann@46631
   856
lemma inf2I: "A x y \<Longrightarrow> B x y \<Longrightarrow> (A \<sqinter> B) x y"
haftmann@46631
   857
  by (simp add: inf_fun_def)
haftmann@46631
   858
haftmann@46631
   859
lemma inf1E: "(A \<sqinter> B) x \<Longrightarrow> (A x \<Longrightarrow> B x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   860
  by (simp add: inf_fun_def)
haftmann@46631
   861
haftmann@46631
   862
lemma inf2E: "(A \<sqinter> B) x y \<Longrightarrow> (A x y \<Longrightarrow> B x y \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   863
  by (simp add: inf_fun_def)
haftmann@46631
   864
haftmann@46631
   865
lemma inf1D1: "(A \<sqinter> B) x \<Longrightarrow> A x"
haftmann@46631
   866
  by (simp add: inf_fun_def)
haftmann@46631
   867
haftmann@46631
   868
lemma inf2D1: "(A \<sqinter> B) x y \<Longrightarrow> A x y"
haftmann@46631
   869
  by (simp add: inf_fun_def)
haftmann@46631
   870
haftmann@46631
   871
lemma inf1D2: "(A \<sqinter> B) x \<Longrightarrow> B x"
haftmann@46631
   872
  by (simp add: inf_fun_def)
haftmann@46631
   873
haftmann@46631
   874
lemma inf2D2: "(A \<sqinter> B) x y \<Longrightarrow> B x y"
haftmann@46631
   875
  by (simp add: inf_fun_def)
haftmann@46631
   876
haftmann@46631
   877
lemma sup1I1: "A x \<Longrightarrow> (A \<squnion> B) x"
haftmann@46631
   878
  by (simp add: sup_fun_def)
haftmann@46631
   879
haftmann@46631
   880
lemma sup2I1: "A x y \<Longrightarrow> (A \<squnion> B) x y"
haftmann@46631
   881
  by (simp add: sup_fun_def)
haftmann@46631
   882
haftmann@46631
   883
lemma sup1I2: "B x \<Longrightarrow> (A \<squnion> B) x"
haftmann@46631
   884
  by (simp add: sup_fun_def)
haftmann@46631
   885
haftmann@46631
   886
lemma sup2I2: "B x y \<Longrightarrow> (A \<squnion> B) x y"
haftmann@46631
   887
  by (simp add: sup_fun_def)
haftmann@46631
   888
haftmann@46631
   889
lemma sup1E: "(A \<squnion> B) x \<Longrightarrow> (A x \<Longrightarrow> P) \<Longrightarrow> (B x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   890
  by (simp add: sup_fun_def) iprover
haftmann@46631
   891
haftmann@46631
   892
lemma sup2E: "(A \<squnion> B) x y \<Longrightarrow> (A x y \<Longrightarrow> P) \<Longrightarrow> (B x y \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   893
  by (simp add: sup_fun_def) iprover
haftmann@46631
   894
haftmann@46631
   895
text {*
haftmann@46631
   896
  \medskip Classical introduction rule: no commitment to @{text A} vs
haftmann@46631
   897
  @{text B}.
haftmann@46631
   898
*}
haftmann@46631
   899
haftmann@46631
   900
lemma sup1CI: "(\<not> B x \<Longrightarrow> A x) \<Longrightarrow> (A \<squnion> B) x"
haftmann@46631
   901
  by (auto simp add: sup_fun_def)
haftmann@46631
   902
haftmann@46631
   903
lemma sup2CI: "(\<not> B x y \<Longrightarrow> A x y) \<Longrightarrow> (A \<squnion> B) x y"
haftmann@46631
   904
  by (auto simp add: sup_fun_def)
haftmann@46631
   905
haftmann@46631
   906
haftmann@25062
   907
no_notation
haftmann@46691
   908
  less_eq (infix "\<sqsubseteq>" 50) and
haftmann@46691
   909
  less (infix "\<sqsubset>" 50)
haftmann@25062
   910
haftmann@21249
   911
end
haftmann@46631
   912