src/HOL/Lattices.thy
author haftmann
Tue Oct 16 23:12:45 2007 +0200 (2007-10-16)
changeset 25062 af5ef0d4d655
parent 24749 151b3758f576
child 25102 db3e412c4cb1
permissions -rw-r--r--
global class 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 class lower_semilattice = order +
    15   fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
    16   assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
    17   and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
    18   and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
    19 
    20 class upper_semilattice = order +
    21   fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
    22   assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
    23   and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
    24   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    25 
    26 class lattice = lower_semilattice + upper_semilattice
    27 
    28 subsubsection{* Intro and elim rules*}
    29 
    30 context lower_semilattice
    31 begin
    32 
    33 lemmas antisym_intro [intro!] = antisym
    34 lemmas (in -) [rule del] = antisym_intro
    35 
    36 lemma le_infI1[intro]:
    37   assumes "a \<sqsubseteq> x"
    38   shows "a \<sqinter> b \<sqsubseteq> x"
    39 proof (rule order_trans)
    40   show "a \<sqinter> b \<sqsubseteq> a" and "a \<sqsubseteq> x" using assms by simp
    41 qed
    42 lemmas (in -) [rule del] = le_infI1
    43 
    44 lemma le_infI2[intro]:
    45   assumes "b \<sqsubseteq> x"
    46   shows "a \<sqinter> b \<sqsubseteq> x"
    47 proof (rule order_trans)
    48   show "a \<sqinter> b \<sqsubseteq> b" and "b \<sqsubseteq> x" using assms by simp
    49 qed
    50 lemmas (in -) [rule del] = le_infI2
    51 
    52 lemma le_infI[intro!]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
    53 by(blast intro: inf_greatest)
    54 lemmas (in -) [rule del] = le_infI
    55 
    56 lemma le_infE [elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
    57   by (blast intro: order_trans)
    58 lemmas (in -) [rule del] = le_infE
    59 
    60 lemma le_inf_iff [simp]:
    61  "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
    62 by blast
    63 
    64 lemma le_iff_inf: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)"
    65 by(blast dest:eq_iff[THEN iffD1])
    66 
    67 end
    68 
    69 lemma mono_inf: "mono f \<Longrightarrow> f (inf A B) \<le> inf (f A) (f B)"
    70   by (auto simp add: mono_def)
    71 
    72 
    73 context upper_semilattice
    74 begin
    75 
    76 lemmas antisym_intro [intro!] = antisym
    77 lemmas (in -) [rule del] = antisym_intro
    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 
    96 lemma ge_sup_conv[simp]:
    97  "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
    98 by blast
    99 
   100 lemma le_iff_sup: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
   101 by(blast dest:eq_iff[THEN iffD1])
   102 
   103 end
   104 
   105 lemma mono_sup: "mono f \<Longrightarrow> sup (f A) (f B) \<le> f (sup A B)"
   106   by (auto simp add: mono_def)
   107 
   108 
   109 subsubsection{* Equational laws *}
   110 
   111 
   112 context lower_semilattice
   113 begin
   114 
   115 lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
   116 by blast
   117 
   118 lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
   119 by blast
   120 
   121 lemma inf_idem[simp]: "x \<sqinter> x = x"
   122 by blast
   123 
   124 lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
   125 by blast
   126 
   127 lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
   128 by blast
   129 
   130 lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
   131 by blast
   132 
   133 lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
   134 by blast
   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
   146 
   147 lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
   148 by blast
   149 
   150 lemma sup_idem[simp]: "x \<squnion> x = x"
   151 by blast
   152 
   153 lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
   154 by blast
   155 
   156 lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
   157 by blast
   158 
   159 lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
   160 by blast
   161 
   162 lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
   163 by blast
   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
   297 
   298 lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   299   by (rule ext)+ auto
   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.antisym_intro 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: 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: 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 = Inf {}"
   404 
   405 definition
   406   bot :: 'a
   407 where
   408   "bot = Sup {}"
   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 == Sup (f ` A)"
   420 
   421 definition
   422   INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
   423 where
   424   "INFI A f == Inf (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 lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
   457   by (auto simp add: SUPR_def intro: Sup_upper)
   458 
   459 lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
   460   by (auto simp add: SUPR_def intro: Sup_least)
   461 
   462 lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
   463   by (auto simp add: INFI_def intro: Inf_lower)
   464 
   465 lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
   466   by (auto simp add: INFI_def intro: Inf_greatest)
   467 
   468 lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
   469   by (auto intro: order_antisym SUP_leI le_SUPI)
   470 
   471 lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
   472   by (auto intro: order_antisym INF_leI le_INFI)
   473 
   474 
   475 subsection {* Bool as lattice *}
   476 
   477 instance bool :: distrib_lattice
   478   inf_bool_eq: "inf P Q \<equiv> P \<and> Q"
   479   sup_bool_eq: "sup P Q \<equiv> P \<or> Q"
   480   by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
   481 
   482 instance bool :: complete_lattice
   483   Inf_bool_def: "Inf A \<equiv> \<forall>x\<in>A. x"
   484   Sup_bool_def: "Sup A \<equiv> \<exists>x\<in>A. x"
   485   by intro_classes (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)
   486 
   487 lemma Inf_empty_bool [simp]:
   488   "Inf {}"
   489   unfolding Inf_bool_def by auto
   490 
   491 lemma not_Sup_empty_bool [simp]:
   492   "\<not> Sup {}"
   493   unfolding Sup_bool_def by auto
   494 
   495 lemma top_bool_eq: "top = True"
   496   by (iprover intro!: order_antisym le_boolI top_greatest)
   497 
   498 lemma bot_bool_eq: "bot = False"
   499   by (iprover intro!: order_antisym le_boolI bot_least)
   500 
   501 
   502 subsection {* Set as lattice *}
   503 
   504 instance set :: (type) distrib_lattice
   505   inf_set_eq: "inf A B \<equiv> A \<inter> B"
   506   sup_set_eq: "sup A B \<equiv> A \<union> B"
   507   by intro_classes (auto simp add: inf_set_eq sup_set_eq)
   508 
   509 lemmas [code func del] = inf_set_eq sup_set_eq
   510 
   511 lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
   512   apply (fold inf_set_eq sup_set_eq)
   513   apply (erule mono_inf)
   514   done
   515 
   516 lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
   517   apply (fold inf_set_eq sup_set_eq)
   518   apply (erule mono_sup)
   519   done
   520 
   521 instance set :: (type) complete_lattice
   522   Inf_set_def: "Inf S \<equiv> \<Inter>S"
   523   Sup_set_def: "Sup S \<equiv> \<Union>S"
   524   by intro_classes (auto simp add: Inf_set_def Sup_set_def)
   525 
   526 lemmas [code func del] = Inf_set_def Sup_set_def
   527 
   528 lemma top_set_eq: "top = UNIV"
   529   by (iprover intro!: subset_antisym subset_UNIV top_greatest)
   530 
   531 lemma bot_set_eq: "bot = {}"
   532   by (iprover intro!: subset_antisym empty_subsetI bot_least)
   533 
   534 
   535 subsection {* Fun as lattice *}
   536 
   537 instance "fun" :: (type, lattice) lattice
   538   inf_fun_eq: "inf f g \<equiv> (\<lambda>x. inf (f x) (g x))"
   539   sup_fun_eq: "sup f g \<equiv> (\<lambda>x. sup (f x) (g x))"
   540 apply intro_classes
   541 unfolding inf_fun_eq sup_fun_eq
   542 apply (auto intro: le_funI)
   543 apply (rule le_funI)
   544 apply (auto dest: le_funD)
   545 apply (rule le_funI)
   546 apply (auto dest: le_funD)
   547 done
   548 
   549 lemmas [code func del] = inf_fun_eq sup_fun_eq
   550 
   551 instance "fun" :: (type, distrib_lattice) distrib_lattice
   552   by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   553 
   554 instance "fun" :: (type, complete_lattice) complete_lattice
   555   Inf_fun_def: "Inf A \<equiv> (\<lambda>x. Inf {y. \<exists>f\<in>A. y = f x})"
   556   Sup_fun_def: "Sup A \<equiv> (\<lambda>x. Sup {y. \<exists>f\<in>A. y = f x})"
   557   by intro_classes
   558     (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
   559       intro: Inf_lower Sup_upper Inf_greatest Sup_least)
   560 
   561 lemmas [code func del] = Inf_fun_def Sup_fun_def
   562 
   563 lemma Inf_empty_fun:
   564   "Inf {} = (\<lambda>_. Inf {})"
   565   by rule (auto simp add: Inf_fun_def)
   566 
   567 lemma Sup_empty_fun:
   568   "Sup {} = (\<lambda>_. Sup {})"
   569   by rule (auto simp add: Sup_fun_def)
   570 
   571 lemma top_fun_eq: "top = (\<lambda>x. top)"
   572   by (iprover intro!: order_antisym le_funI top_greatest)
   573 
   574 lemma bot_fun_eq: "bot = (\<lambda>x. bot)"
   575   by (iprover intro!: order_antisym le_funI bot_least)
   576 
   577 
   578 text {* redundant bindings *}
   579 
   580 lemmas inf_aci = inf_ACI
   581 lemmas sup_aci = sup_ACI
   582 
   583 no_notation
   584   inf (infixl "\<sqinter>" 70)
   585 
   586 no_notation
   587   sup (infixl "\<squnion>" 65)
   588 
   589 no_notation
   590   Inf ("\<Sqinter>_" [900] 900)
   591 
   592 no_notation
   593   Sup ("\<Squnion>_" [900] 900)
   594 
   595 end