src/HOL/Lattices.thy
author haftmann
Tue Aug 07 09:38:47 2007 +0200 (2007-08-07)
changeset 24164 911b46812018
parent 23948 261bd4678076
child 24345 86a3557a9ebb
permissions -rw-r--r--
tuned
haftmann@21249
     1
(*  Title:      HOL/Lattices.thy
haftmann@21249
     2
    ID:         $Id$
haftmann@21249
     3
    Author:     Tobias Nipkow
haftmann@21249
     4
*)
haftmann@21249
     5
haftmann@22454
     6
header {* Abstract lattices *}
haftmann@21249
     7
haftmann@21249
     8
theory Lattices
haftmann@21249
     9
imports Orderings
haftmann@21249
    10
begin
haftmann@21249
    11
haftmann@21249
    12
subsection{* Lattices *}
haftmann@21249
    13
haftmann@22422
    14
class lower_semilattice = order +
haftmann@21249
    15
  fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
haftmann@22737
    16
  assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
haftmann@22737
    17
  and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
nipkow@21733
    18
  and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
haftmann@21249
    19
haftmann@22422
    20
class upper_semilattice = order +
haftmann@21249
    21
  fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
haftmann@22737
    22
  assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
haftmann@22737
    23
  and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
nipkow@21733
    24
  and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
haftmann@21249
    25
haftmann@22422
    26
class lattice = lower_semilattice + upper_semilattice
haftmann@21249
    27
nipkow@21733
    28
subsubsection{* Intro and elim rules*}
nipkow@21733
    29
nipkow@21733
    30
context lower_semilattice
nipkow@21733
    31
begin
haftmann@21249
    32
haftmann@22422
    33
lemmas antisym_intro [intro!] = antisym
haftmann@22422
    34
lemmas (in -) [rule del] = antisym_intro
haftmann@21249
    35
nipkow@21734
    36
lemma le_infI1[intro]: "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
nipkow@21733
    37
apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> a")
haftmann@22384
    38
 apply(blast intro: order_trans)
nipkow@21733
    39
apply simp
nipkow@21733
    40
done
haftmann@22422
    41
lemmas (in -) [rule del] = le_infI1
haftmann@21249
    42
nipkow@21734
    43
lemma le_infI2[intro]: "b \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
nipkow@21733
    44
apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> b")
haftmann@22384
    45
 apply(blast intro: order_trans)
nipkow@21733
    46
apply simp
nipkow@21733
    47
done
haftmann@22422
    48
lemmas (in -) [rule del] = le_infI2
nipkow@21733
    49
nipkow@21734
    50
lemma le_infI[intro!]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
nipkow@21733
    51
by(blast intro: inf_greatest)
haftmann@22422
    52
lemmas (in -) [rule del] = le_infI
haftmann@21249
    53
haftmann@22422
    54
lemma le_infE [elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22422
    55
  by (blast intro: order_trans)
haftmann@22422
    56
lemmas (in -) [rule del] = le_infE
haftmann@21249
    57
nipkow@21734
    58
lemma le_inf_iff [simp]:
nipkow@21733
    59
 "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
nipkow@21733
    60
by blast
nipkow@21733
    61
nipkow@21734
    62
lemma le_iff_inf: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)"
nipkow@22168
    63
by(blast dest:eq_iff[THEN iffD1])
haftmann@21249
    64
nipkow@21733
    65
end
nipkow@21733
    66
haftmann@23878
    67
lemma mono_inf: "mono f \<Longrightarrow> f (inf A B) \<le> inf (f A) (f B)"
haftmann@23878
    68
  by (auto simp add: mono_def)
haftmann@23878
    69
nipkow@21733
    70
nipkow@21733
    71
context upper_semilattice
nipkow@21733
    72
begin
haftmann@21249
    73
haftmann@22422
    74
lemmas antisym_intro [intro!] = antisym
haftmann@22422
    75
lemmas (in -) [rule del] = antisym_intro
haftmann@21249
    76
nipkow@21734
    77
lemma le_supI1[intro]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
nipkow@21733
    78
apply(subgoal_tac "a \<sqsubseteq> a \<squnion> b")
haftmann@22384
    79
 apply(blast intro: order_trans)
nipkow@21733
    80
apply simp
nipkow@21733
    81
done
haftmann@22422
    82
lemmas (in -) [rule del] = le_supI1
haftmann@21249
    83
nipkow@21734
    84
lemma le_supI2[intro]: "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
nipkow@21733
    85
apply(subgoal_tac "b \<sqsubseteq> a \<squnion> b")
haftmann@22384
    86
 apply(blast intro: order_trans)
nipkow@21733
    87
apply simp
nipkow@21733
    88
done
haftmann@22422
    89
lemmas (in -) [rule del] = le_supI2
nipkow@21733
    90
nipkow@21734
    91
lemma le_supI[intro!]: "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
nipkow@21733
    92
by(blast intro: sup_least)
haftmann@22422
    93
lemmas (in -) [rule del] = le_supI
haftmann@21249
    94
nipkow@21734
    95
lemma le_supE[elim!]: "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22422
    96
  by (blast intro: order_trans)
haftmann@22422
    97
lemmas (in -) [rule del] = le_supE
haftmann@22422
    98
haftmann@21249
    99
nipkow@21734
   100
lemma ge_sup_conv[simp]:
nipkow@21733
   101
 "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
nipkow@21733
   102
by blast
nipkow@21733
   103
nipkow@21734
   104
lemma le_iff_sup: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
nipkow@22168
   105
by(blast dest:eq_iff[THEN iffD1])
nipkow@21734
   106
nipkow@21733
   107
end
nipkow@21733
   108
haftmann@23878
   109
lemma mono_sup: "mono f \<Longrightarrow> sup (f A) (f B) \<le> f (sup A B)"
haftmann@23878
   110
  by (auto simp add: mono_def)
haftmann@23878
   111
nipkow@21733
   112
nipkow@21733
   113
subsubsection{* Equational laws *}
haftmann@21249
   114
haftmann@21249
   115
nipkow@21733
   116
context lower_semilattice
nipkow@21733
   117
begin
nipkow@21733
   118
nipkow@21733
   119
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
nipkow@21733
   120
by blast
nipkow@21733
   121
nipkow@21733
   122
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
nipkow@21733
   123
by blast
nipkow@21733
   124
nipkow@21733
   125
lemma inf_idem[simp]: "x \<sqinter> x = x"
nipkow@21733
   126
by blast
nipkow@21733
   127
nipkow@21733
   128
lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
nipkow@21733
   129
by blast
nipkow@21733
   130
nipkow@21733
   131
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
nipkow@21733
   132
by blast
nipkow@21733
   133
nipkow@21733
   134
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
nipkow@21733
   135
by blast
nipkow@21733
   136
nipkow@21733
   137
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
nipkow@21733
   138
by blast
nipkow@21733
   139
nipkow@21733
   140
lemmas inf_ACI = inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@21733
   141
nipkow@21733
   142
end
nipkow@21733
   143
nipkow@21733
   144
nipkow@21733
   145
context upper_semilattice
nipkow@21733
   146
begin
haftmann@21249
   147
nipkow@21733
   148
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
nipkow@21733
   149
by blast
nipkow@21733
   150
nipkow@21733
   151
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
nipkow@21733
   152
by blast
nipkow@21733
   153
nipkow@21733
   154
lemma sup_idem[simp]: "x \<squnion> x = x"
nipkow@21733
   155
by blast
nipkow@21733
   156
nipkow@21733
   157
lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
nipkow@21733
   158
by blast
nipkow@21733
   159
nipkow@21733
   160
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
nipkow@21733
   161
by blast
nipkow@21733
   162
nipkow@21733
   163
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
nipkow@21733
   164
by blast
haftmann@21249
   165
nipkow@21733
   166
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
nipkow@21733
   167
by blast
nipkow@21733
   168
nipkow@21733
   169
lemmas sup_ACI = sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@21733
   170
nipkow@21733
   171
end
haftmann@21249
   172
nipkow@21733
   173
context lattice
nipkow@21733
   174
begin
nipkow@21733
   175
nipkow@21733
   176
lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
nipkow@21733
   177
by(blast intro: antisym inf_le1 inf_greatest sup_ge1)
nipkow@21733
   178
nipkow@21733
   179
lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
nipkow@21733
   180
by(blast intro: antisym sup_ge1 sup_least inf_le1)
nipkow@21733
   181
nipkow@21734
   182
lemmas ACI = inf_ACI sup_ACI
nipkow@21734
   183
haftmann@22454
   184
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
haftmann@22454
   185
nipkow@21734
   186
text{* Towards distributivity *}
haftmann@21249
   187
nipkow@21734
   188
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
nipkow@21734
   189
by blast
nipkow@21734
   190
nipkow@21734
   191
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
nipkow@21734
   192
by blast
nipkow@21734
   193
nipkow@21734
   194
nipkow@21734
   195
text{* If you have one of them, you have them all. *}
haftmann@21249
   196
nipkow@21733
   197
lemma distrib_imp1:
haftmann@21249
   198
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   199
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   200
proof-
haftmann@21249
   201
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
haftmann@21249
   202
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc)
haftmann@21249
   203
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
haftmann@21249
   204
    by(simp add:inf_sup_absorb inf_commute)
haftmann@21249
   205
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   206
  finally show ?thesis .
haftmann@21249
   207
qed
haftmann@21249
   208
nipkow@21733
   209
lemma distrib_imp2:
haftmann@21249
   210
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   211
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   212
proof-
haftmann@21249
   213
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
haftmann@21249
   214
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc)
haftmann@21249
   215
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
haftmann@21249
   216
    by(simp add:sup_inf_absorb sup_commute)
haftmann@21249
   217
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   218
  finally show ?thesis .
haftmann@21249
   219
qed
haftmann@21249
   220
nipkow@21734
   221
(* seems unused *)
nipkow@21734
   222
lemma modular_le: "x \<sqsubseteq> z \<Longrightarrow> x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> z"
nipkow@21734
   223
by blast
nipkow@21734
   224
nipkow@21733
   225
end
haftmann@21249
   226
haftmann@21249
   227
haftmann@24164
   228
subsection {* Distributive lattices *}
haftmann@21249
   229
haftmann@22454
   230
class distrib_lattice = lattice +
haftmann@21249
   231
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   232
nipkow@21733
   233
context distrib_lattice
nipkow@21733
   234
begin
nipkow@21733
   235
nipkow@21733
   236
lemma sup_inf_distrib2:
haftmann@21249
   237
 "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
haftmann@21249
   238
by(simp add:ACI sup_inf_distrib1)
haftmann@21249
   239
nipkow@21733
   240
lemma inf_sup_distrib1:
haftmann@21249
   241
 "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   242
by(rule distrib_imp2[OF sup_inf_distrib1])
haftmann@21249
   243
nipkow@21733
   244
lemma inf_sup_distrib2:
haftmann@21249
   245
 "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
haftmann@21249
   246
by(simp add:ACI inf_sup_distrib1)
haftmann@21249
   247
nipkow@21733
   248
lemmas distrib =
haftmann@21249
   249
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   250
nipkow@21733
   251
end
nipkow@21733
   252
haftmann@21249
   253
haftmann@22454
   254
subsection {* Uniqueness of inf and sup *}
haftmann@22454
   255
haftmann@22737
   256
lemma (in lower_semilattice) inf_unique:
haftmann@22454
   257
  fixes f (infixl "\<triangle>" 70)
haftmann@22737
   258
  assumes le1: "\<And>x y. x \<triangle> y \<^loc>\<le> x" and le2: "\<And>x y. x \<triangle> y \<^loc>\<le> y"
haftmann@22737
   259
  and greatest: "\<And>x y z. x \<^loc>\<le> y \<Longrightarrow> x \<^loc>\<le> z \<Longrightarrow> x \<^loc>\<le> y \<triangle> z"
haftmann@22737
   260
  shows "x \<sqinter> y = x \<triangle> y"
haftmann@22454
   261
proof (rule antisym)
wenzelm@23389
   262
  show "x \<triangle> y \<^loc>\<le> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
haftmann@22454
   263
next
haftmann@22737
   264
  have leI: "\<And>x y z. x \<^loc>\<le> y \<Longrightarrow> x \<^loc>\<le> z \<Longrightarrow> x \<^loc>\<le> y \<triangle> z" by (blast intro: greatest)
haftmann@22737
   265
  show "x \<sqinter> y \<^loc>\<le> x \<triangle> y" by (rule leI) simp_all
haftmann@22454
   266
qed
haftmann@22454
   267
haftmann@22737
   268
lemma (in upper_semilattice) sup_unique:
haftmann@22454
   269
  fixes f (infixl "\<nabla>" 70)
haftmann@22737
   270
  assumes ge1 [simp]: "\<And>x y. x \<^loc>\<le> x \<nabla> y" and ge2: "\<And>x y. y \<^loc>\<le> x \<nabla> y"
haftmann@22737
   271
  and least: "\<And>x y z. y \<^loc>\<le> x \<Longrightarrow> z \<^loc>\<le> x \<Longrightarrow> y \<nabla> z \<^loc>\<le> x"
haftmann@22737
   272
  shows "x \<squnion> y = x \<nabla> y"
haftmann@22454
   273
proof (rule antisym)
wenzelm@23389
   274
  show "x \<squnion> y \<^loc>\<le> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
haftmann@22454
   275
next
haftmann@22737
   276
  have leI: "\<And>x y z. x \<^loc>\<le> z \<Longrightarrow> y \<^loc>\<le> z \<Longrightarrow> x \<nabla> y \<^loc>\<le> z" by (blast intro: least)
haftmann@22737
   277
  show "x \<nabla> y \<^loc>\<le> x \<squnion> y" by (rule leI) simp_all
haftmann@22454
   278
qed
haftmann@22454
   279
  
haftmann@22454
   280
haftmann@22916
   281
subsection {* @{const min}/@{const max} on linear orders as
haftmann@22916
   282
  special case of @{const inf}/@{const sup} *}
haftmann@22916
   283
haftmann@22916
   284
lemma (in linorder) distrib_lattice_min_max:
haftmann@23018
   285
  "distrib_lattice (op \<^loc>\<le>) (op \<^loc><) min max"
haftmann@22916
   286
proof unfold_locales
haftmann@22916
   287
  have aux: "\<And>x y \<Colon> 'a. x \<^loc>< y \<Longrightarrow> y \<^loc>\<le> x \<Longrightarrow> x = y"
haftmann@22916
   288
    by (auto simp add: less_le antisym)
haftmann@22916
   289
  fix x y z
haftmann@22916
   290
  show "max x (min y z) = min (max x y) (max x z)"
haftmann@22916
   291
  unfolding min_def max_def
haftmann@22916
   292
    by (auto simp add: intro: antisym, unfold not_le,
haftmann@22916
   293
      auto intro: less_trans le_less_trans aux)
haftmann@22916
   294
qed (auto simp add: min_def max_def not_le less_imp_le)
haftmann@21249
   295
haftmann@21249
   296
interpretation min_max:
haftmann@22454
   297
  distrib_lattice ["op \<le> \<Colon> 'a\<Colon>linorder \<Rightarrow> 'a \<Rightarrow> bool" "op <" min max]
haftmann@23948
   298
  by (rule distrib_lattice_min_max)
haftmann@21249
   299
haftmann@22454
   300
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@22454
   301
  by (rule ext)+ auto
nipkow@21733
   302
haftmann@22454
   303
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
haftmann@22454
   304
  by (rule ext)+ auto
nipkow@21733
   305
haftmann@21249
   306
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   307
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   308
 
haftmann@21249
   309
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@22422
   310
  mk_left_commute [of max, OF min_max.sup_assoc min_max.sup_commute]
haftmann@21249
   311
haftmann@21249
   312
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@22422
   313
  mk_left_commute [of min, OF min_max.inf_assoc min_max.inf_commute]
haftmann@21249
   314
haftmann@22454
   315
text {*
haftmann@22454
   316
  Now we have inherited antisymmetry as an intro-rule on all
haftmann@22454
   317
  linear orders. This is a problem because it applies to bool, which is
haftmann@22454
   318
  undesirable.
haftmann@22454
   319
*}
haftmann@22454
   320
haftmann@22454
   321
lemmas [rule del] = min_max.antisym_intro min_max.le_infI min_max.le_supI
haftmann@22454
   322
  min_max.le_supE min_max.le_infE min_max.le_supI1 min_max.le_supI2
haftmann@22454
   323
  min_max.le_infI1 min_max.le_infI2
haftmann@22454
   324
haftmann@22454
   325
haftmann@23878
   326
subsection {* Complete lattices *}
haftmann@23878
   327
haftmann@23878
   328
class complete_lattice = lattice +
haftmann@23878
   329
  fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)
haftmann@23878
   330
  assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"
haftmann@23878
   331
  assumes Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"
haftmann@23878
   332
begin
haftmann@23878
   333
haftmann@23878
   334
definition
haftmann@23878
   335
  Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)
haftmann@23878
   336
where
haftmann@23878
   337
  "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<^loc>\<le> b}"
haftmann@23878
   338
haftmann@23878
   339
lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<^loc>\<le> a}"
haftmann@23878
   340
  unfolding Sup_def by (auto intro: Inf_greatest Inf_lower)
haftmann@23878
   341
haftmann@23878
   342
lemma Sup_upper: "x \<in> A \<Longrightarrow> x \<^loc>\<le> \<Squnion>A"
haftmann@23878
   343
  by (auto simp: Sup_def intro: Inf_greatest)
haftmann@23878
   344
haftmann@23878
   345
lemma Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<^loc>\<le> z) \<Longrightarrow> \<Squnion>A \<^loc>\<le> z"
haftmann@23878
   346
  by (auto simp: Sup_def intro: Inf_lower)
haftmann@23878
   347
haftmann@23878
   348
lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"
haftmann@23878
   349
  unfolding Sup_def by auto
haftmann@23878
   350
haftmann@23878
   351
lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"
haftmann@23878
   352
  unfolding Inf_Sup by auto
haftmann@23878
   353
haftmann@23878
   354
lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"
haftmann@23878
   355
  apply (rule antisym)
haftmann@23878
   356
  apply (rule le_infI)
haftmann@23878
   357
  apply (rule Inf_lower)
haftmann@23878
   358
  apply simp
haftmann@23878
   359
  apply (rule Inf_greatest)
haftmann@23878
   360
  apply (rule Inf_lower)
haftmann@23878
   361
  apply simp
haftmann@23878
   362
  apply (rule Inf_greatest)
haftmann@23878
   363
  apply (erule insertE)
haftmann@23878
   364
  apply (rule le_infI1)
haftmann@23878
   365
  apply simp
haftmann@23878
   366
  apply (rule le_infI2)
haftmann@23878
   367
  apply (erule Inf_lower)
haftmann@23878
   368
  done
haftmann@23878
   369
haftmann@23948
   370
lemma Sup_insert [code func]: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"
haftmann@23878
   371
  apply (rule antisym)
haftmann@23878
   372
  apply (rule Sup_least)
haftmann@23878
   373
  apply (erule insertE)
haftmann@23878
   374
  apply (rule le_supI1)
haftmann@23878
   375
  apply simp
haftmann@23878
   376
  apply (rule le_supI2)
haftmann@23878
   377
  apply (erule Sup_upper)
haftmann@23878
   378
  apply (rule le_supI)
haftmann@23878
   379
  apply (rule Sup_upper)
haftmann@23878
   380
  apply simp
haftmann@23878
   381
  apply (rule Sup_least)
haftmann@23878
   382
  apply (rule Sup_upper)
haftmann@23878
   383
  apply simp
haftmann@23878
   384
  done
haftmann@23878
   385
haftmann@23878
   386
lemma Inf_singleton [simp]:
haftmann@23878
   387
  "\<Sqinter>{a} = a"
haftmann@23878
   388
  by (auto intro: antisym Inf_lower Inf_greatest)
haftmann@23878
   389
haftmann@23948
   390
lemma Sup_singleton [simp, code func]:
haftmann@23878
   391
  "\<Squnion>{a} = a"
haftmann@23878
   392
  by (auto intro: antisym Sup_upper Sup_least)
haftmann@23878
   393
haftmann@23878
   394
lemma Inf_insert_simp:
haftmann@23878
   395
  "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"
haftmann@23878
   396
  by (cases "A = {}") (simp_all, simp add: Inf_insert)
haftmann@23878
   397
haftmann@23878
   398
lemma Sup_insert_simp:
haftmann@23878
   399
  "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"
haftmann@23878
   400
  by (cases "A = {}") (simp_all, simp add: Sup_insert)
haftmann@23878
   401
haftmann@23878
   402
lemma Inf_binary:
haftmann@23878
   403
  "\<Sqinter>{a, b} = a \<sqinter> b"
haftmann@23878
   404
  by (simp add: Inf_insert_simp)
haftmann@23878
   405
haftmann@23878
   406
lemma Sup_binary:
haftmann@23878
   407
  "\<Squnion>{a, b} = a \<squnion> b"
haftmann@23878
   408
  by (simp add: Sup_insert_simp)
haftmann@23878
   409
haftmann@23878
   410
end
haftmann@23878
   411
haftmann@23878
   412
definition
haftmann@23878
   413
  top :: "'a::complete_lattice"
haftmann@23878
   414
where
haftmann@23878
   415
  "top = Inf {}"
haftmann@23878
   416
haftmann@23878
   417
definition
haftmann@23878
   418
  bot :: "'a::complete_lattice"
haftmann@23878
   419
where
haftmann@23878
   420
  "bot = Sup {}"
haftmann@23878
   421
haftmann@23878
   422
lemma top_greatest [simp]: "x \<le> top"
haftmann@23878
   423
  by (unfold top_def, rule Inf_greatest, simp)
haftmann@23878
   424
haftmann@23878
   425
lemma bot_least [simp]: "bot \<le> x"
haftmann@23878
   426
  by (unfold bot_def, rule Sup_least, simp)
haftmann@23878
   427
haftmann@23878
   428
definition
haftmann@23878
   429
  SUPR :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b::complete_lattice) \<Rightarrow> 'b"
haftmann@23878
   430
where
haftmann@23878
   431
  "SUPR A f == Sup (f ` A)"
haftmann@23878
   432
haftmann@23878
   433
definition
haftmann@23878
   434
  INFI :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b::complete_lattice) \<Rightarrow> 'b"
haftmann@23878
   435
where
haftmann@23878
   436
  "INFI A f == Inf (f ` A)"
haftmann@23878
   437
haftmann@23878
   438
syntax
haftmann@23878
   439
  "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
haftmann@23878
   440
  "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
haftmann@23878
   441
  "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
haftmann@23878
   442
  "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
haftmann@23878
   443
haftmann@23878
   444
translations
haftmann@23878
   445
  "SUP x y. B"   == "SUP x. SUP y. B"
haftmann@23878
   446
  "SUP x. B"     == "CONST SUPR UNIV (%x. B)"
haftmann@23878
   447
  "SUP x. B"     == "SUP x:UNIV. B"
haftmann@23878
   448
  "SUP x:A. B"   == "CONST SUPR A (%x. B)"
haftmann@23878
   449
  "INF x y. B"   == "INF x. INF y. B"
haftmann@23878
   450
  "INF x. B"     == "CONST INFI UNIV (%x. B)"
haftmann@23878
   451
  "INF x. B"     == "INF x:UNIV. B"
haftmann@23878
   452
  "INF x:A. B"   == "CONST INFI A (%x. B)"
haftmann@23878
   453
haftmann@23878
   454
(* To avoid eta-contraction of body: *)
haftmann@23878
   455
print_translation {*
haftmann@23878
   456
let
haftmann@23878
   457
  fun btr' syn (A :: Abs abs :: ts) =
haftmann@23878
   458
    let val (x,t) = atomic_abs_tr' abs
haftmann@23878
   459
    in list_comb (Syntax.const syn $ x $ A $ t, ts) end
haftmann@23878
   460
  val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const
haftmann@23878
   461
in
haftmann@23878
   462
[(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]
haftmann@23878
   463
end
haftmann@23878
   464
*}
haftmann@23878
   465
haftmann@23878
   466
lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
haftmann@23878
   467
  by (auto simp add: SUPR_def intro: Sup_upper)
haftmann@23878
   468
haftmann@23878
   469
lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
haftmann@23878
   470
  by (auto simp add: SUPR_def intro: Sup_least)
haftmann@23878
   471
haftmann@23878
   472
lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
haftmann@23878
   473
  by (auto simp add: INFI_def intro: Inf_lower)
haftmann@23878
   474
haftmann@23878
   475
lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
haftmann@23878
   476
  by (auto simp add: INFI_def intro: Inf_greatest)
haftmann@23878
   477
haftmann@23878
   478
lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
haftmann@23878
   479
  by (auto intro: order_antisym SUP_leI le_SUPI)
haftmann@23878
   480
haftmann@23878
   481
lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
haftmann@23878
   482
  by (auto intro: order_antisym INF_leI le_INFI)
haftmann@23878
   483
haftmann@23878
   484
haftmann@22454
   485
subsection {* Bool as lattice *}
haftmann@22454
   486
haftmann@22454
   487
instance bool :: distrib_lattice
haftmann@22454
   488
  inf_bool_eq: "inf P Q \<equiv> P \<and> Q"
haftmann@22454
   489
  sup_bool_eq: "sup P Q \<equiv> P \<or> Q"
haftmann@22454
   490
  by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
haftmann@22454
   491
haftmann@23878
   492
instance bool :: complete_lattice
haftmann@23878
   493
  Inf_bool_def: "Inf A \<equiv> \<forall>x\<in>A. x"
haftmann@23878
   494
  apply intro_classes
haftmann@23878
   495
  apply (unfold Inf_bool_def)
haftmann@23878
   496
  apply (iprover intro!: le_boolI elim: ballE)
haftmann@23878
   497
  apply (iprover intro!: ballI le_boolI elim: ballE le_boolE)
haftmann@23878
   498
  done
haftmann@22454
   499
haftmann@23878
   500
theorem Sup_bool_eq: "Sup A \<longleftrightarrow> (\<exists>x\<in>A. x)"
haftmann@23878
   501
  apply (rule order_antisym)
haftmann@23878
   502
  apply (rule Sup_least)
haftmann@23878
   503
  apply (rule le_boolI)
haftmann@23878
   504
  apply (erule bexI, assumption)
haftmann@23878
   505
  apply (rule le_boolI)
haftmann@23878
   506
  apply (erule bexE)
haftmann@23878
   507
  apply (rule le_boolE)
haftmann@23878
   508
  apply (rule Sup_upper)
haftmann@23878
   509
  apply assumption+
haftmann@23878
   510
  done
haftmann@23878
   511
haftmann@23878
   512
lemma Inf_empty_bool [simp]:
haftmann@23878
   513
  "Inf {}"
haftmann@23878
   514
  unfolding Inf_bool_def by auto
haftmann@23878
   515
haftmann@23878
   516
lemma not_Sup_empty_bool [simp]:
haftmann@23878
   517
  "\<not> Sup {}"
haftmann@23878
   518
  unfolding Sup_def Inf_bool_def by auto
haftmann@23878
   519
haftmann@23878
   520
lemma top_bool_eq: "top = True"
haftmann@23878
   521
  by (iprover intro!: order_antisym le_boolI top_greatest)
haftmann@23878
   522
haftmann@23878
   523
lemma bot_bool_eq: "bot = False"
haftmann@23878
   524
  by (iprover intro!: order_antisym le_boolI bot_least)
haftmann@23878
   525
haftmann@23878
   526
haftmann@23878
   527
subsection {* Set as lattice *}
haftmann@23878
   528
haftmann@23878
   529
instance set :: (type) distrib_lattice
haftmann@23878
   530
  inf_set_eq: "inf A B \<equiv> A \<inter> B"
haftmann@23878
   531
  sup_set_eq: "sup A B \<equiv> A \<union> B"
haftmann@23878
   532
  by intro_classes (auto simp add: inf_set_eq sup_set_eq)
haftmann@23878
   533
haftmann@23878
   534
lemmas [code func del] = inf_set_eq sup_set_eq
haftmann@23878
   535
haftmann@23878
   536
lemmas mono_Int = mono_inf
haftmann@23878
   537
  [where ?'a="?'a set", where ?'b="?'b set", unfolded inf_set_eq sup_set_eq]
haftmann@23878
   538
haftmann@23878
   539
lemmas mono_Un = mono_sup
haftmann@23878
   540
  [where ?'a="?'a set", where ?'b="?'b set", unfolded inf_set_eq sup_set_eq]
haftmann@23878
   541
haftmann@23878
   542
instance set :: (type) complete_lattice
haftmann@23878
   543
  Inf_set_def: "Inf S \<equiv> \<Inter>S"
haftmann@23878
   544
  by intro_classes (auto simp add: Inf_set_def)
haftmann@23878
   545
haftmann@23878
   546
lemmas [code func del] = Inf_set_def
haftmann@23878
   547
haftmann@23878
   548
theorem Sup_set_eq: "Sup S = \<Union>S"
haftmann@23878
   549
  apply (rule subset_antisym)
haftmann@23878
   550
  apply (rule Sup_least)
haftmann@23878
   551
  apply (erule Union_upper)
haftmann@23878
   552
  apply (rule Union_least)
haftmann@23878
   553
  apply (erule Sup_upper)
haftmann@23878
   554
  done
haftmann@23878
   555
haftmann@23878
   556
lemma top_set_eq: "top = UNIV"
haftmann@23878
   557
  by (iprover intro!: subset_antisym subset_UNIV top_greatest)
haftmann@23878
   558
haftmann@23878
   559
lemma bot_set_eq: "bot = {}"
haftmann@23878
   560
  by (iprover intro!: subset_antisym empty_subsetI bot_least)
haftmann@23878
   561
haftmann@23878
   562
haftmann@23878
   563
subsection {* Fun as lattice *}
haftmann@23878
   564
haftmann@23878
   565
instance "fun" :: (type, lattice) lattice
haftmann@23878
   566
  inf_fun_eq: "inf f g \<equiv> (\<lambda>x. inf (f x) (g x))"
haftmann@23878
   567
  sup_fun_eq: "sup f g \<equiv> (\<lambda>x. sup (f x) (g x))"
haftmann@23878
   568
apply intro_classes
haftmann@23878
   569
unfolding inf_fun_eq sup_fun_eq
haftmann@23878
   570
apply (auto intro: le_funI)
haftmann@23878
   571
apply (rule le_funI)
haftmann@23878
   572
apply (auto dest: le_funD)
haftmann@23878
   573
apply (rule le_funI)
haftmann@23878
   574
apply (auto dest: le_funD)
haftmann@23878
   575
done
haftmann@23878
   576
haftmann@23878
   577
lemmas [code func del] = inf_fun_eq sup_fun_eq
haftmann@23878
   578
haftmann@23878
   579
instance "fun" :: (type, distrib_lattice) distrib_lattice
haftmann@23878
   580
  by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
haftmann@23878
   581
haftmann@23878
   582
instance "fun" :: (type, complete_lattice) complete_lattice
haftmann@23878
   583
  Inf_fun_def: "Inf A \<equiv> (\<lambda>x. Inf {y. \<exists>f\<in>A. y = f x})"
haftmann@23878
   584
  apply intro_classes
haftmann@23878
   585
  apply (unfold Inf_fun_def)
haftmann@23878
   586
  apply (rule le_funI)
haftmann@23878
   587
  apply (rule Inf_lower)
haftmann@23878
   588
  apply (rule CollectI)
haftmann@23878
   589
  apply (rule bexI)
haftmann@23878
   590
  apply (rule refl)
haftmann@23878
   591
  apply assumption
haftmann@23878
   592
  apply (rule le_funI)
haftmann@23878
   593
  apply (rule Inf_greatest)
haftmann@23878
   594
  apply (erule CollectE)
haftmann@23878
   595
  apply (erule bexE)
haftmann@23878
   596
  apply (iprover elim: le_funE)
haftmann@23878
   597
  done
haftmann@23878
   598
haftmann@23878
   599
lemmas [code func del] = Inf_fun_def
haftmann@23878
   600
haftmann@23878
   601
theorem Sup_fun_eq: "Sup A = (\<lambda>x. Sup {y. \<exists>f\<in>A. y = f x})"
haftmann@23878
   602
  apply (rule order_antisym)
haftmann@23878
   603
  apply (rule Sup_least)
haftmann@23878
   604
  apply (rule le_funI)
haftmann@23878
   605
  apply (rule Sup_upper)
haftmann@23878
   606
  apply fast
haftmann@23878
   607
  apply (rule le_funI)
haftmann@23878
   608
  apply (rule Sup_least)
haftmann@23878
   609
  apply (erule CollectE)
haftmann@23878
   610
  apply (erule bexE)
haftmann@23878
   611
  apply (drule le_funD [OF Sup_upper])
haftmann@23878
   612
  apply simp
haftmann@23878
   613
  done
haftmann@23878
   614
haftmann@23878
   615
lemma Inf_empty_fun:
haftmann@23878
   616
  "Inf {} = (\<lambda>_. Inf {})"
haftmann@23878
   617
  by rule (auto simp add: Inf_fun_def)
haftmann@23878
   618
haftmann@23878
   619
lemma Sup_empty_fun:
haftmann@23878
   620
  "Sup {} = (\<lambda>_. Sup {})"
haftmann@23878
   621
proof -
haftmann@23878
   622
  have aux: "\<And>x. {y. \<exists>f. y = f x} = UNIV" by auto
haftmann@23878
   623
  show ?thesis
haftmann@23878
   624
  by (auto simp add: Sup_def Inf_fun_def Inf_binary inf_bool_eq aux)
haftmann@23878
   625
qed
haftmann@23878
   626
haftmann@23878
   627
lemma top_fun_eq: "top = (\<lambda>x. top)"
haftmann@23878
   628
  by (iprover intro!: order_antisym le_funI top_greatest)
haftmann@23878
   629
haftmann@23878
   630
lemma bot_fun_eq: "bot = (\<lambda>x. bot)"
haftmann@23878
   631
  by (iprover intro!: order_antisym le_funI bot_least)
haftmann@23878
   632
haftmann@23878
   633
haftmann@23878
   634
text {* redundant bindings *}
haftmann@22454
   635
haftmann@22454
   636
lemmas inf_aci = inf_ACI
haftmann@22454
   637
lemmas sup_aci = sup_ACI
haftmann@22454
   638
haftmann@23878
   639
ML {*
haftmann@23878
   640
val sup_fun_eq = @{thm sup_fun_eq}
haftmann@23878
   641
val sup_bool_eq = @{thm sup_bool_eq}
haftmann@23878
   642
*}
haftmann@23878
   643
haftmann@21249
   644
end