src/HOL/Lattices.thy
author wenzelm
Wed Apr 10 21:20:35 2013 +0200 (2013-04-10)
changeset 51692 ecd34f863242
parent 51593 d40aec502416
child 52152 b561cdce6c4c
permissions -rw-r--r--
tuned pretty layout: avoid nested Pretty.string_of, which merely happens to work with Isabelle/jEdit since formatting is delegated to Scala side;
declare command "print_case_translations" where it is actually defined;
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@51546
   474
  + inf_top!: semilattice_neutr_order inf top less_eq less
haftmann@51487
   475
proof
haftmann@51487
   476
  fix x
haftmann@51487
   477
  show "x \<sqinter> \<top> = x"
haftmann@51487
   478
    by (rule inf_absorb1) simp
haftmann@51487
   479
qed
haftmann@51487
   480
haftmann@51487
   481
class bounded_semilattice_sup_bot = semilattice_sup + bot
haftmann@51487
   482
haftmann@51487
   483
sublocale bounded_semilattice_sup_bot < sup_bot!: semilattice_neutr sup bot
haftmann@51546
   484
  + sup_bot!: semilattice_neutr_order sup bot greater_eq greater
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
kaliszyk@36352
   491
class bounded_lattice_bot = lattice + bot
haftmann@31991
   492
begin
haftmann@31991
   493
haftmann@51487
   494
subclass bounded_semilattice_sup_bot ..
haftmann@51487
   495
haftmann@31991
   496
lemma inf_bot_left [simp]:
haftmann@34007
   497
  "\<bottom> \<sqinter> x = \<bottom>"
haftmann@31991
   498
  by (rule inf_absorb1) simp
haftmann@31991
   499
haftmann@31991
   500
lemma inf_bot_right [simp]:
haftmann@34007
   501
  "x \<sqinter> \<bottom> = \<bottom>"
haftmann@31991
   502
  by (rule inf_absorb2) simp
haftmann@31991
   503
haftmann@51487
   504
lemma sup_bot_left:
kaliszyk@36352
   505
  "\<bottom> \<squnion> x = x"
haftmann@51487
   506
  by (fact sup_bot.left_neutral)
kaliszyk@36352
   507
haftmann@51487
   508
lemma sup_bot_right:
kaliszyk@36352
   509
  "x \<squnion> \<bottom> = x"
haftmann@51487
   510
  by (fact sup_bot.right_neutral)
kaliszyk@36352
   511
kaliszyk@36352
   512
lemma sup_eq_bot_iff [simp]:
kaliszyk@36352
   513
  "x \<squnion> y = \<bottom> \<longleftrightarrow> x = \<bottom> \<and> y = \<bottom>"
kaliszyk@36352
   514
  by (simp add: eq_iff)
kaliszyk@36352
   515
nipkow@51593
   516
lemma bot_eq_sup_iff [simp]:
nipkow@51593
   517
  "\<bottom> = x \<squnion> y \<longleftrightarrow> x = \<bottom> \<and> y = \<bottom>"
nipkow@51593
   518
  by (simp add: eq_iff)
nipkow@51593
   519
kaliszyk@36352
   520
end
kaliszyk@36352
   521
kaliszyk@36352
   522
class bounded_lattice_top = lattice + top
kaliszyk@36352
   523
begin
kaliszyk@36352
   524
haftmann@51487
   525
subclass bounded_semilattice_inf_top ..
haftmann@51487
   526
haftmann@31991
   527
lemma sup_top_left [simp]:
haftmann@34007
   528
  "\<top> \<squnion> x = \<top>"
haftmann@31991
   529
  by (rule sup_absorb1) simp
haftmann@31991
   530
haftmann@31991
   531
lemma sup_top_right [simp]:
haftmann@34007
   532
  "x \<squnion> \<top> = \<top>"
haftmann@31991
   533
  by (rule sup_absorb2) simp
haftmann@31991
   534
haftmann@51487
   535
lemma inf_top_left:
haftmann@34007
   536
  "\<top> \<sqinter> x = x"
haftmann@51487
   537
  by (fact inf_top.left_neutral)
haftmann@31991
   538
haftmann@51487
   539
lemma inf_top_right:
haftmann@34007
   540
  "x \<sqinter> \<top> = x"
haftmann@51487
   541
  by (fact inf_top.right_neutral)
haftmann@31991
   542
huffman@36008
   543
lemma inf_eq_top_iff [simp]:
huffman@36008
   544
  "x \<sqinter> y = \<top> \<longleftrightarrow> x = \<top> \<and> y = \<top>"
huffman@36008
   545
  by (simp add: eq_iff)
haftmann@32568
   546
kaliszyk@36352
   547
end
kaliszyk@36352
   548
haftmann@51487
   549
class bounded_lattice = lattice + bot + top
kaliszyk@36352
   550
begin
kaliszyk@36352
   551
haftmann@51487
   552
subclass bounded_lattice_bot ..
haftmann@51487
   553
subclass bounded_lattice_top ..
haftmann@51487
   554
kaliszyk@36352
   555
lemma dual_bounded_lattice:
krauss@44845
   556
  "class.bounded_lattice sup greater_eq greater inf \<top> \<bottom>"
kaliszyk@36352
   557
  by unfold_locales (auto simp add: less_le_not_le)
haftmann@32568
   558
haftmann@34007
   559
end
haftmann@34007
   560
haftmann@34007
   561
class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
haftmann@34007
   562
  assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
haftmann@34007
   563
    and sup_compl_top: "x \<squnion> - x = \<top>"
haftmann@34007
   564
  assumes diff_eq: "x - y = x \<sqinter> - y"
haftmann@34007
   565
begin
haftmann@34007
   566
haftmann@34007
   567
lemma dual_boolean_algebra:
krauss@44845
   568
  "class.boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus sup greater_eq greater inf \<top> \<bottom>"
haftmann@36635
   569
  by (rule class.boolean_algebra.intro, rule dual_bounded_lattice, rule dual_distrib_lattice)
haftmann@34007
   570
    (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
haftmann@34007
   571
noschinl@44918
   572
lemma compl_inf_bot [simp]:
haftmann@34007
   573
  "- x \<sqinter> x = \<bottom>"
haftmann@34007
   574
  by (simp add: inf_commute inf_compl_bot)
haftmann@34007
   575
noschinl@44918
   576
lemma compl_sup_top [simp]:
haftmann@34007
   577
  "- x \<squnion> x = \<top>"
haftmann@34007
   578
  by (simp add: sup_commute sup_compl_top)
haftmann@34007
   579
haftmann@31991
   580
lemma compl_unique:
haftmann@34007
   581
  assumes "x \<sqinter> y = \<bottom>"
haftmann@34007
   582
    and "x \<squnion> y = \<top>"
haftmann@31991
   583
  shows "- x = y"
haftmann@31991
   584
proof -
haftmann@31991
   585
  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
haftmann@31991
   586
    using inf_compl_bot assms(1) by simp
haftmann@31991
   587
  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
haftmann@31991
   588
    by (simp add: inf_commute)
haftmann@31991
   589
  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
haftmann@31991
   590
    by (simp add: inf_sup_distrib1)
haftmann@34007
   591
  then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
haftmann@31991
   592
    using sup_compl_top assms(2) by simp
krauss@34209
   593
  then show "- x = y" by simp
haftmann@31991
   594
qed
haftmann@31991
   595
haftmann@31991
   596
lemma double_compl [simp]:
haftmann@31991
   597
  "- (- x) = x"
haftmann@31991
   598
  using compl_inf_bot compl_sup_top by (rule compl_unique)
haftmann@31991
   599
haftmann@31991
   600
lemma compl_eq_compl_iff [simp]:
haftmann@31991
   601
  "- x = - y \<longleftrightarrow> x = y"
haftmann@31991
   602
proof
haftmann@31991
   603
  assume "- x = - y"
huffman@36008
   604
  then have "- (- x) = - (- y)" by (rule arg_cong)
haftmann@31991
   605
  then show "x = y" by simp
haftmann@31991
   606
next
haftmann@31991
   607
  assume "x = y"
haftmann@31991
   608
  then show "- x = - y" by simp
haftmann@31991
   609
qed
haftmann@31991
   610
haftmann@31991
   611
lemma compl_bot_eq [simp]:
haftmann@34007
   612
  "- \<bottom> = \<top>"
haftmann@31991
   613
proof -
haftmann@34007
   614
  from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
haftmann@31991
   615
  then show ?thesis by simp
haftmann@31991
   616
qed
haftmann@31991
   617
haftmann@31991
   618
lemma compl_top_eq [simp]:
haftmann@34007
   619
  "- \<top> = \<bottom>"
haftmann@31991
   620
proof -
haftmann@34007
   621
  from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
haftmann@31991
   622
  then show ?thesis by simp
haftmann@31991
   623
qed
haftmann@31991
   624
haftmann@31991
   625
lemma compl_inf [simp]:
haftmann@31991
   626
  "- (x \<sqinter> y) = - x \<squnion> - y"
haftmann@31991
   627
proof (rule compl_unique)
huffman@36008
   628
  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
huffman@36008
   629
    by (simp only: inf_sup_distrib inf_aci)
huffman@36008
   630
  then show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
haftmann@31991
   631
    by (simp add: inf_compl_bot)
haftmann@31991
   632
next
huffman@36008
   633
  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
huffman@36008
   634
    by (simp only: sup_inf_distrib sup_aci)
huffman@36008
   635
  then show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
haftmann@31991
   636
    by (simp add: sup_compl_top)
haftmann@31991
   637
qed
haftmann@31991
   638
haftmann@31991
   639
lemma compl_sup [simp]:
haftmann@31991
   640
  "- (x \<squnion> y) = - x \<sqinter> - y"
huffman@44921
   641
  using dual_boolean_algebra
huffman@44921
   642
  by (rule boolean_algebra.compl_inf)
haftmann@31991
   643
huffman@36008
   644
lemma compl_mono:
huffman@36008
   645
  "x \<sqsubseteq> y \<Longrightarrow> - y \<sqsubseteq> - x"
huffman@36008
   646
proof -
huffman@36008
   647
  assume "x \<sqsubseteq> y"
huffman@36008
   648
  then have "x \<squnion> y = y" by (simp only: le_iff_sup)
huffman@36008
   649
  then have "- (x \<squnion> y) = - y" by simp
huffman@36008
   650
  then have "- x \<sqinter> - y = - y" by simp
huffman@36008
   651
  then have "- y \<sqinter> - x = - y" by (simp only: inf_commute)
huffman@36008
   652
  then show "- y \<sqsubseteq> - x" by (simp only: le_iff_inf)
huffman@36008
   653
qed
huffman@36008
   654
noschinl@44918
   655
lemma compl_le_compl_iff [simp]:
haftmann@43753
   656
  "- x \<sqsubseteq> - y \<longleftrightarrow> y \<sqsubseteq> x"
haftmann@43873
   657
  by (auto dest: compl_mono)
haftmann@43873
   658
haftmann@43873
   659
lemma compl_le_swap1:
haftmann@43873
   660
  assumes "y \<sqsubseteq> - x" shows "x \<sqsubseteq> -y"
haftmann@43873
   661
proof -
haftmann@43873
   662
  from assms have "- (- x) \<sqsubseteq> - y" by (simp only: compl_le_compl_iff)
haftmann@43873
   663
  then show ?thesis by simp
haftmann@43873
   664
qed
haftmann@43873
   665
haftmann@43873
   666
lemma compl_le_swap2:
haftmann@43873
   667
  assumes "- y \<sqsubseteq> x" shows "- x \<sqsubseteq> y"
haftmann@43873
   668
proof -
haftmann@43873
   669
  from assms have "- x \<sqsubseteq> - (- y)" by (simp only: compl_le_compl_iff)
haftmann@43873
   670
  then show ?thesis by simp
haftmann@43873
   671
qed
haftmann@43873
   672
haftmann@43873
   673
lemma compl_less_compl_iff: (* TODO: declare [simp] ? *)
haftmann@43873
   674
  "- x \<sqsubset> - y \<longleftrightarrow> y \<sqsubset> x"
noschinl@44919
   675
  by (auto simp add: less_le)
haftmann@43873
   676
haftmann@43873
   677
lemma compl_less_swap1:
haftmann@43873
   678
  assumes "y \<sqsubset> - x" shows "x \<sqsubset> - y"
haftmann@43873
   679
proof -
haftmann@43873
   680
  from assms have "- (- x) \<sqsubset> - y" by (simp only: compl_less_compl_iff)
haftmann@43873
   681
  then show ?thesis by simp
haftmann@43873
   682
qed
haftmann@43873
   683
haftmann@43873
   684
lemma compl_less_swap2:
haftmann@43873
   685
  assumes "- y \<sqsubset> x" shows "- x \<sqsubset> y"
haftmann@43873
   686
proof -
haftmann@43873
   687
  from assms have "- x \<sqsubset> - (- y)" by (simp only: compl_less_compl_iff)
haftmann@43873
   688
  then show ?thesis by simp
haftmann@43873
   689
qed
huffman@36008
   690
haftmann@31991
   691
end
haftmann@31991
   692
haftmann@31991
   693
haftmann@51540
   694
subsection {* @{text "min/max"} as special case of lattice *}
haftmann@51540
   695
haftmann@51540
   696
sublocale linorder < min!: semilattice_order min less_eq less
haftmann@51540
   697
  + max!: semilattice_order max greater_eq greater
haftmann@51540
   698
  by default (auto simp add: min_def max_def)
haftmann@51540
   699
haftmann@51540
   700
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{semilattice_inf, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@51540
   701
  by (auto intro: antisym simp add: min_def fun_eq_iff)
haftmann@51540
   702
haftmann@51540
   703
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{semilattice_sup, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@51540
   704
  by (auto intro: antisym simp add: max_def fun_eq_iff)
haftmann@51540
   705
haftmann@51540
   706
haftmann@22454
   707
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   708
haftmann@35028
   709
lemma (in semilattice_inf) inf_unique:
haftmann@22454
   710
  fixes f (infixl "\<triangle>" 70)
haftmann@34007
   711
  assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
haftmann@34007
   712
  and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
haftmann@22737
   713
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   714
proof (rule antisym)
haftmann@34007
   715
  show "x \<triangle> y \<sqsubseteq> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   716
next
haftmann@34007
   717
  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
   718
  show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   719
qed
haftmann@22454
   720
haftmann@35028
   721
lemma (in semilattice_sup) sup_unique:
haftmann@22454
   722
  fixes f (infixl "\<nabla>" 70)
haftmann@34007
   723
  assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
haftmann@34007
   724
  and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
haftmann@22737
   725
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   726
proof (rule antisym)
haftmann@34007
   727
  show "x \<squnion> y \<sqsubseteq> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   728
next
haftmann@34007
   729
  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
   730
  show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   731
qed
huffman@36008
   732
haftmann@22454
   733
haftmann@46631
   734
subsection {* Lattice on @{typ bool} *}
haftmann@22454
   735
haftmann@31991
   736
instantiation bool :: boolean_algebra
haftmann@25510
   737
begin
haftmann@25510
   738
haftmann@25510
   739
definition
haftmann@41080
   740
  bool_Compl_def [simp]: "uminus = Not"
haftmann@31991
   741
haftmann@31991
   742
definition
haftmann@41080
   743
  bool_diff_def [simp]: "A - B \<longleftrightarrow> A \<and> \<not> B"
haftmann@31991
   744
haftmann@31991
   745
definition
haftmann@41080
   746
  [simp]: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
haftmann@25510
   747
haftmann@25510
   748
definition
haftmann@41080
   749
  [simp]: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
haftmann@25510
   750
haftmann@31991
   751
instance proof
haftmann@41080
   752
qed auto
haftmann@22454
   753
haftmann@25510
   754
end
haftmann@25510
   755
haftmann@32781
   756
lemma sup_boolI1:
haftmann@32781
   757
  "P \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   758
  by simp
haftmann@32781
   759
haftmann@32781
   760
lemma sup_boolI2:
haftmann@32781
   761
  "Q \<Longrightarrow> P \<squnion> Q"
haftmann@41080
   762
  by simp
haftmann@32781
   763
haftmann@32781
   764
lemma sup_boolE:
haftmann@32781
   765
  "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
haftmann@41080
   766
  by auto
haftmann@32781
   767
haftmann@23878
   768
haftmann@46631
   769
subsection {* Lattice on @{typ "_ \<Rightarrow> _"} *}
haftmann@23878
   770
nipkow@51387
   771
instantiation "fun" :: (type, semilattice_sup) semilattice_sup
haftmann@25510
   772
begin
haftmann@25510
   773
haftmann@25510
   774
definition
haftmann@41080
   775
  "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
haftmann@41080
   776
haftmann@49769
   777
lemma sup_apply [simp, code]:
haftmann@41080
   778
  "(f \<squnion> g) x = f x \<squnion> g x"
haftmann@41080
   779
  by (simp add: sup_fun_def)
haftmann@25510
   780
haftmann@32780
   781
instance proof
noschinl@46884
   782
qed (simp_all add: le_fun_def)
haftmann@23878
   783
haftmann@25510
   784
end
haftmann@23878
   785
nipkow@51387
   786
instantiation "fun" :: (type, semilattice_inf) semilattice_inf
nipkow@51387
   787
begin
nipkow@51387
   788
nipkow@51387
   789
definition
nipkow@51387
   790
  "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
nipkow@51387
   791
nipkow@51387
   792
lemma inf_apply [simp, code]:
nipkow@51387
   793
  "(f \<sqinter> g) x = f x \<sqinter> g x"
nipkow@51387
   794
  by (simp add: inf_fun_def)
nipkow@51387
   795
nipkow@51387
   796
instance proof
nipkow@51387
   797
qed (simp_all add: le_fun_def)
nipkow@51387
   798
nipkow@51387
   799
end
nipkow@51387
   800
nipkow@51387
   801
instance "fun" :: (type, lattice) lattice ..
nipkow@51387
   802
haftmann@41080
   803
instance "fun" :: (type, distrib_lattice) distrib_lattice proof
noschinl@46884
   804
qed (rule ext, simp add: sup_inf_distrib1)
haftmann@31991
   805
haftmann@34007
   806
instance "fun" :: (type, bounded_lattice) bounded_lattice ..
haftmann@34007
   807
haftmann@31991
   808
instantiation "fun" :: (type, uminus) uminus
haftmann@31991
   809
begin
haftmann@31991
   810
haftmann@31991
   811
definition
haftmann@31991
   812
  fun_Compl_def: "- A = (\<lambda>x. - A x)"
haftmann@31991
   813
haftmann@49769
   814
lemma uminus_apply [simp, code]:
haftmann@41080
   815
  "(- A) x = - (A x)"
haftmann@41080
   816
  by (simp add: fun_Compl_def)
haftmann@41080
   817
haftmann@31991
   818
instance ..
haftmann@31991
   819
haftmann@31991
   820
end
haftmann@31991
   821
haftmann@31991
   822
instantiation "fun" :: (type, minus) minus
haftmann@31991
   823
begin
haftmann@31991
   824
haftmann@31991
   825
definition
haftmann@31991
   826
  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
haftmann@31991
   827
haftmann@49769
   828
lemma minus_apply [simp, code]:
haftmann@41080
   829
  "(A - B) x = A x - B x"
haftmann@41080
   830
  by (simp add: fun_diff_def)
haftmann@41080
   831
haftmann@31991
   832
instance ..
haftmann@31991
   833
haftmann@31991
   834
end
haftmann@31991
   835
haftmann@41080
   836
instance "fun" :: (type, boolean_algebra) boolean_algebra proof
noschinl@46884
   837
qed (rule ext, simp_all add: inf_compl_bot sup_compl_top diff_eq)+
berghofe@26794
   838
haftmann@46631
   839
haftmann@46631
   840
subsection {* Lattice on unary and binary predicates *}
haftmann@46631
   841
haftmann@46631
   842
lemma inf1I: "A x \<Longrightarrow> B x \<Longrightarrow> (A \<sqinter> B) x"
haftmann@46631
   843
  by (simp add: inf_fun_def)
haftmann@46631
   844
haftmann@46631
   845
lemma inf2I: "A x y \<Longrightarrow> B x y \<Longrightarrow> (A \<sqinter> B) x y"
haftmann@46631
   846
  by (simp add: inf_fun_def)
haftmann@46631
   847
haftmann@46631
   848
lemma inf1E: "(A \<sqinter> B) x \<Longrightarrow> (A x \<Longrightarrow> B x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   849
  by (simp add: inf_fun_def)
haftmann@46631
   850
haftmann@46631
   851
lemma inf2E: "(A \<sqinter> B) x y \<Longrightarrow> (A x y \<Longrightarrow> B x y \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   852
  by (simp add: inf_fun_def)
haftmann@46631
   853
haftmann@46631
   854
lemma inf1D1: "(A \<sqinter> B) x \<Longrightarrow> A x"
haftmann@46631
   855
  by (simp add: inf_fun_def)
haftmann@46631
   856
haftmann@46631
   857
lemma inf2D1: "(A \<sqinter> B) x y \<Longrightarrow> A x y"
haftmann@46631
   858
  by (simp add: inf_fun_def)
haftmann@46631
   859
haftmann@46631
   860
lemma inf1D2: "(A \<sqinter> B) x \<Longrightarrow> B x"
haftmann@46631
   861
  by (simp add: inf_fun_def)
haftmann@46631
   862
haftmann@46631
   863
lemma inf2D2: "(A \<sqinter> B) x y \<Longrightarrow> B x y"
haftmann@46631
   864
  by (simp add: inf_fun_def)
haftmann@46631
   865
haftmann@46631
   866
lemma sup1I1: "A x \<Longrightarrow> (A \<squnion> B) x"
haftmann@46631
   867
  by (simp add: sup_fun_def)
haftmann@46631
   868
haftmann@46631
   869
lemma sup2I1: "A x y \<Longrightarrow> (A \<squnion> B) x y"
haftmann@46631
   870
  by (simp add: sup_fun_def)
haftmann@46631
   871
haftmann@46631
   872
lemma sup1I2: "B x \<Longrightarrow> (A \<squnion> B) x"
haftmann@46631
   873
  by (simp add: sup_fun_def)
haftmann@46631
   874
haftmann@46631
   875
lemma sup2I2: "B x y \<Longrightarrow> (A \<squnion> B) x y"
haftmann@46631
   876
  by (simp add: sup_fun_def)
haftmann@46631
   877
haftmann@46631
   878
lemma sup1E: "(A \<squnion> B) x \<Longrightarrow> (A x \<Longrightarrow> P) \<Longrightarrow> (B x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   879
  by (simp add: sup_fun_def) iprover
haftmann@46631
   880
haftmann@46631
   881
lemma sup2E: "(A \<squnion> B) x y \<Longrightarrow> (A x y \<Longrightarrow> P) \<Longrightarrow> (B x y \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@46631
   882
  by (simp add: sup_fun_def) iprover
haftmann@46631
   883
haftmann@46631
   884
text {*
haftmann@46631
   885
  \medskip Classical introduction rule: no commitment to @{text A} vs
haftmann@46631
   886
  @{text B}.
haftmann@46631
   887
*}
haftmann@46631
   888
haftmann@46631
   889
lemma sup1CI: "(\<not> B x \<Longrightarrow> A x) \<Longrightarrow> (A \<squnion> B) x"
haftmann@46631
   890
  by (auto simp add: sup_fun_def)
haftmann@46631
   891
haftmann@46631
   892
lemma sup2CI: "(\<not> B x y \<Longrightarrow> A x y) \<Longrightarrow> (A \<squnion> B) x y"
haftmann@46631
   893
  by (auto simp add: sup_fun_def)
haftmann@46631
   894
haftmann@46631
   895
haftmann@25062
   896
no_notation
haftmann@46691
   897
  less_eq (infix "\<sqsubseteq>" 50) and
haftmann@46691
   898
  less (infix "\<sqsubset>" 50)
haftmann@25062
   899
haftmann@21249
   900
end
haftmann@46631
   901