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