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