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