src/HOL/Lattices.thy
author haftmann
Fri Mar 02 15:43:15 2007 +0100 (2007-03-02)
changeset 22384 33a46e6c7f04
parent 22168 627e7aee1b82
child 22422 ee19cdb07528
permissions -rw-r--r--
prefix of class interpretation not mandatory any longer
haftmann@21249
     1
(*  Title:      HOL/Lattices.thy
haftmann@21249
     2
    ID:         $Id$
haftmann@21249
     3
    Author:     Tobias Nipkow
haftmann@21249
     4
*)
haftmann@21249
     5
nipkow@21733
     6
header {* Lattices via Locales *}
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@21249
    14
text{* This theory of lattice locales only defines binary sup and inf
haftmann@21249
    15
operations. The extension to finite sets is done in theory @{text
haftmann@21249
    16
Finite_Set}. In the longer term it may be better to define arbitrary
haftmann@21249
    17
sups and infs via @{text THE}. *}
haftmann@21249
    18
haftmann@22068
    19
locale lower_semilattice = order +
haftmann@21249
    20
  fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
nipkow@21312
    21
  assumes inf_le1[simp]: "x \<sqinter> y \<sqsubseteq> x" and inf_le2[simp]: "x \<sqinter> y \<sqsubseteq> y"
nipkow@21733
    22
  and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
haftmann@21249
    23
haftmann@22068
    24
locale upper_semilattice = order +
haftmann@21249
    25
  fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
nipkow@21312
    26
  assumes sup_ge1[simp]: "x \<sqsubseteq> x \<squnion> y" and sup_ge2[simp]: "y \<sqsubseteq> x \<squnion> y"
nipkow@21733
    27
  and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
haftmann@21249
    28
haftmann@21249
    29
locale lattice = lower_semilattice + upper_semilattice
haftmann@21249
    30
nipkow@21733
    31
subsubsection{* Intro and elim rules*}
nipkow@21733
    32
nipkow@21733
    33
context lower_semilattice
nipkow@21733
    34
begin
haftmann@21249
    35
nipkow@21733
    36
lemmas antisym_intro[intro!] = antisym
haftmann@21249
    37
nipkow@21734
    38
lemma le_infI1[intro]: "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
nipkow@21733
    39
apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> a")
haftmann@22384
    40
 apply(blast intro: order_trans)
nipkow@21733
    41
apply simp
nipkow@21733
    42
done
haftmann@21249
    43
nipkow@21734
    44
lemma le_infI2[intro]: "b \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
nipkow@21733
    45
apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> b")
haftmann@22384
    46
 apply(blast intro: order_trans)
nipkow@21733
    47
apply simp
nipkow@21733
    48
done
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@21249
    52
nipkow@21734
    53
lemma le_infE[elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22384
    54
by(blast intro: order_trans)
haftmann@21249
    55
nipkow@21734
    56
lemma le_inf_iff [simp]:
nipkow@21733
    57
 "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
nipkow@21733
    58
by blast
nipkow@21733
    59
nipkow@21734
    60
lemma le_iff_inf: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)"
nipkow@22168
    61
by(blast dest:eq_iff[THEN iffD1])
haftmann@21249
    62
nipkow@21733
    63
end
nipkow@21733
    64
nipkow@21733
    65
nipkow@21733
    66
context upper_semilattice
nipkow@21733
    67
begin
haftmann@21249
    68
nipkow@21733
    69
lemmas antisym_intro[intro!] = antisym
haftmann@21249
    70
nipkow@21734
    71
lemma le_supI1[intro]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
nipkow@21733
    72
apply(subgoal_tac "a \<sqsubseteq> a \<squnion> b")
haftmann@22384
    73
 apply(blast intro: order_trans)
nipkow@21733
    74
apply simp
nipkow@21733
    75
done
haftmann@21249
    76
nipkow@21734
    77
lemma le_supI2[intro]: "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
nipkow@21733
    78
apply(subgoal_tac "b \<sqsubseteq> a \<squnion> b")
haftmann@22384
    79
 apply(blast intro: order_trans)
nipkow@21733
    80
apply simp
nipkow@21733
    81
done
nipkow@21733
    82
nipkow@21734
    83
lemma le_supI[intro!]: "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
nipkow@21733
    84
by(blast intro: sup_least)
haftmann@21249
    85
nipkow@21734
    86
lemma le_supE[elim!]: "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@22384
    87
by(blast intro: order_trans)
haftmann@21249
    88
nipkow@21734
    89
lemma ge_sup_conv[simp]:
nipkow@21733
    90
 "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
nipkow@21733
    91
by blast
nipkow@21733
    92
nipkow@21734
    93
lemma le_iff_sup: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
nipkow@22168
    94
by(blast dest:eq_iff[THEN iffD1])
nipkow@21734
    95
nipkow@21733
    96
end
nipkow@21733
    97
nipkow@21733
    98
nipkow@21733
    99
subsubsection{* Equational laws *}
haftmann@21249
   100
haftmann@21249
   101
nipkow@21733
   102
context lower_semilattice
nipkow@21733
   103
begin
nipkow@21733
   104
nipkow@21733
   105
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
nipkow@21733
   106
by blast
nipkow@21733
   107
nipkow@21733
   108
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
nipkow@21733
   109
by blast
nipkow@21733
   110
nipkow@21733
   111
lemma inf_idem[simp]: "x \<sqinter> x = x"
nipkow@21733
   112
by blast
nipkow@21733
   113
nipkow@21733
   114
lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
nipkow@21733
   115
by blast
nipkow@21733
   116
nipkow@21733
   117
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
nipkow@21733
   118
by blast
nipkow@21733
   119
nipkow@21733
   120
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
nipkow@21733
   121
by blast
nipkow@21733
   122
nipkow@21733
   123
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
nipkow@21733
   124
by blast
nipkow@21733
   125
nipkow@21733
   126
lemmas inf_ACI = inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@21733
   127
nipkow@21733
   128
end
nipkow@21733
   129
nipkow@21733
   130
nipkow@21733
   131
context upper_semilattice
nipkow@21733
   132
begin
haftmann@21249
   133
nipkow@21733
   134
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
nipkow@21733
   135
by blast
nipkow@21733
   136
nipkow@21733
   137
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
nipkow@21733
   138
by blast
nipkow@21733
   139
nipkow@21733
   140
lemma sup_idem[simp]: "x \<squnion> x = x"
nipkow@21733
   141
by blast
nipkow@21733
   142
nipkow@21733
   143
lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
nipkow@21733
   144
by blast
nipkow@21733
   145
nipkow@21733
   146
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
nipkow@21733
   147
by blast
nipkow@21733
   148
nipkow@21733
   149
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
nipkow@21733
   150
by blast
haftmann@21249
   151
nipkow@21733
   152
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
nipkow@21733
   153
by blast
nipkow@21733
   154
nipkow@21733
   155
lemmas sup_ACI = sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@21733
   156
nipkow@21733
   157
end
haftmann@21249
   158
nipkow@21733
   159
context lattice
nipkow@21733
   160
begin
nipkow@21733
   161
nipkow@21733
   162
lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
nipkow@21733
   163
by(blast intro: antisym inf_le1 inf_greatest sup_ge1)
nipkow@21733
   164
nipkow@21733
   165
lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
nipkow@21733
   166
by(blast intro: antisym sup_ge1 sup_least inf_le1)
nipkow@21733
   167
nipkow@21734
   168
lemmas ACI = inf_ACI sup_ACI
nipkow@21734
   169
nipkow@21734
   170
text{* Towards distributivity *}
haftmann@21249
   171
nipkow@21734
   172
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
nipkow@21734
   173
by blast
nipkow@21734
   174
nipkow@21734
   175
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
nipkow@21734
   176
by blast
nipkow@21734
   177
nipkow@21734
   178
nipkow@21734
   179
text{* If you have one of them, you have them all. *}
haftmann@21249
   180
nipkow@21733
   181
lemma distrib_imp1:
haftmann@21249
   182
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   183
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   184
proof-
haftmann@21249
   185
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
haftmann@21249
   186
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc)
haftmann@21249
   187
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
haftmann@21249
   188
    by(simp add:inf_sup_absorb inf_commute)
haftmann@21249
   189
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
haftmann@21249
   190
  finally show ?thesis .
haftmann@21249
   191
qed
haftmann@21249
   192
nipkow@21733
   193
lemma distrib_imp2:
haftmann@21249
   194
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   195
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   196
proof-
haftmann@21249
   197
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
haftmann@21249
   198
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc)
haftmann@21249
   199
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
haftmann@21249
   200
    by(simp add:sup_inf_absorb sup_commute)
haftmann@21249
   201
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
haftmann@21249
   202
  finally show ?thesis .
haftmann@21249
   203
qed
haftmann@21249
   204
nipkow@21734
   205
(* seems unused *)
nipkow@21734
   206
lemma modular_le: "x \<sqsubseteq> z \<Longrightarrow> x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> z"
nipkow@21734
   207
by blast
nipkow@21734
   208
nipkow@21733
   209
end
haftmann@21249
   210
haftmann@21249
   211
haftmann@21249
   212
subsection{* Distributive lattices *}
haftmann@21249
   213
haftmann@21249
   214
locale distrib_lattice = lattice +
haftmann@21249
   215
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
haftmann@21249
   216
nipkow@21733
   217
context distrib_lattice
nipkow@21733
   218
begin
nipkow@21733
   219
nipkow@21733
   220
lemma sup_inf_distrib2:
haftmann@21249
   221
 "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
haftmann@21249
   222
by(simp add:ACI sup_inf_distrib1)
haftmann@21249
   223
nipkow@21733
   224
lemma inf_sup_distrib1:
haftmann@21249
   225
 "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
haftmann@21249
   226
by(rule distrib_imp2[OF sup_inf_distrib1])
haftmann@21249
   227
nipkow@21733
   228
lemma inf_sup_distrib2:
haftmann@21249
   229
 "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
haftmann@21249
   230
by(simp add:ACI inf_sup_distrib1)
haftmann@21249
   231
nipkow@21733
   232
lemmas distrib =
haftmann@21249
   233
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
haftmann@21249
   234
nipkow@21733
   235
end
nipkow@21733
   236
haftmann@21249
   237
haftmann@21381
   238
subsection {* min/max on linear orders as special case of inf/sup *}
haftmann@21249
   239
haftmann@21249
   240
interpretation min_max:
haftmann@21381
   241
  distrib_lattice ["op \<le>" "op <" "min \<Colon> 'a\<Colon>linorder \<Rightarrow> 'a \<Rightarrow> 'a" "max"]
haftmann@21249
   242
apply unfold_locales
haftmann@21381
   243
apply (simp add: min_def linorder_not_le order_less_imp_le)
haftmann@21381
   244
apply (simp add: min_def linorder_not_le order_less_imp_le)
haftmann@21381
   245
apply (simp add: min_def linorder_not_le order_less_imp_le)
haftmann@21381
   246
apply (simp add: max_def linorder_not_le order_less_imp_le)
haftmann@21381
   247
apply (simp add: max_def linorder_not_le order_less_imp_le)
haftmann@21381
   248
unfolding min_def max_def by auto
haftmann@21249
   249
nipkow@21733
   250
text{* Now we have inherited antisymmetry as an intro-rule on all
nipkow@21733
   251
linear orders. This is a problem because it applies to bool, which is
nipkow@21733
   252
undesirable. *}
nipkow@21733
   253
nipkow@21733
   254
declare
nipkow@21733
   255
 min_max.antisym_intro[rule del]
nipkow@21734
   256
 min_max.le_infI[rule del] min_max.le_supI[rule del]
nipkow@21734
   257
 min_max.le_supE[rule del] min_max.le_infE[rule del]
nipkow@21734
   258
 min_max.le_supI1[rule del] min_max.le_supI2[rule del]
nipkow@21734
   259
 min_max.le_infI1[rule del] min_max.le_infI2[rule del]
nipkow@21733
   260
haftmann@21249
   261
lemmas le_maxI1 = min_max.sup_ge1
haftmann@21249
   262
lemmas le_maxI2 = min_max.sup_ge2
haftmann@21381
   263
 
haftmann@21249
   264
lemmas max_ac = min_max.sup_assoc min_max.sup_commute
haftmann@21249
   265
               mk_left_commute[of max,OF min_max.sup_assoc min_max.sup_commute]
haftmann@21249
   266
haftmann@21249
   267
lemmas min_ac = min_max.inf_assoc min_max.inf_commute
haftmann@21249
   268
               mk_left_commute[of min,OF min_max.inf_assoc min_max.inf_commute]
haftmann@21249
   269
nipkow@21733
   270
text {* ML legacy bindings *}
nipkow@21733
   271
nipkow@21733
   272
ML {*
wenzelm@22139
   273
val Least_def = @{thm Least_def}
wenzelm@22139
   274
val Least_equality = @{thm Least_equality}
wenzelm@22139
   275
val min_def = @{thm min_def}
wenzelm@22139
   276
val min_of_mono = @{thm min_of_mono}
wenzelm@22139
   277
val max_def = @{thm max_def}
wenzelm@22139
   278
val max_of_mono = @{thm max_of_mono}
wenzelm@22139
   279
val min_leastL = @{thm min_leastL}
wenzelm@22139
   280
val max_leastL = @{thm max_leastL}
wenzelm@22139
   281
val min_leastR = @{thm min_leastR}
wenzelm@22139
   282
val max_leastR = @{thm max_leastR}
wenzelm@22139
   283
val le_max_iff_disj = @{thm le_max_iff_disj}
wenzelm@22139
   284
val le_maxI1 = @{thm le_maxI1}
wenzelm@22139
   285
val le_maxI2 = @{thm le_maxI2}
wenzelm@22139
   286
val less_max_iff_disj = @{thm less_max_iff_disj}
wenzelm@22139
   287
val max_less_iff_conj = @{thm max_less_iff_conj}
wenzelm@22139
   288
val min_less_iff_conj = @{thm min_less_iff_conj}
wenzelm@22139
   289
val min_le_iff_disj = @{thm min_le_iff_disj}
wenzelm@22139
   290
val min_less_iff_disj = @{thm min_less_iff_disj}
wenzelm@22139
   291
val split_min = @{thm split_min}
wenzelm@22139
   292
val split_max = @{thm split_max}
nipkow@21733
   293
*}
nipkow@21733
   294
haftmann@21249
   295
end