src/HOL/Lattices.thy
author wenzelm
Sat Nov 10 23:03:52 2007 +0100 (2007-11-10)
changeset 25382 72cfe89f7b21
parent 25206 9c84ec7217a9
child 25482 4ed49eccb1eb
permissions -rw-r--r--
tuned specifications of 'notation';
     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) and
    16   less  (infix "\<sqsubset>" 50)
    17 
    18 class lower_semilattice = order +
    19   fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
    20   assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
    21   and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
    22   and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
    23 
    24 class upper_semilattice = order +
    25   fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
    26   assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
    27   and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
    28   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    29 
    30 class lattice = lower_semilattice + upper_semilattice
    31 
    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 where
   402   "top = \<Sqinter>{}"
   403 
   404 definition
   405   bot :: 'a where
   406   "bot = \<Squnion>{}"
   407 
   408 lemma top_greatest [simp]: "x \<le> top"
   409   by (unfold top_def, rule Inf_greatest, simp)
   410 
   411 lemma bot_least [simp]: "bot \<le> x"
   412   by (unfold bot_def, rule Sup_least, simp)
   413 
   414 definition
   415   SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
   416 where
   417   "SUPR A f == \<Squnion> (f ` A)"
   418 
   419 definition
   420   INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
   421 where
   422   "INFI A f == \<Sqinter> (f ` A)"
   423 
   424 end
   425 
   426 syntax
   427   "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
   428   "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
   429   "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
   430   "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
   431 
   432 translations
   433   "SUP x y. B"   == "SUP x. SUP y. B"
   434   "SUP x. B"     == "CONST SUPR UNIV (%x. B)"
   435   "SUP x. B"     == "SUP x:UNIV. B"
   436   "SUP x:A. B"   == "CONST SUPR A (%x. B)"
   437   "INF x y. B"   == "INF x. INF y. B"
   438   "INF x. B"     == "CONST INFI UNIV (%x. B)"
   439   "INF x. B"     == "INF x:UNIV. B"
   440   "INF x:A. B"   == "CONST INFI A (%x. B)"
   441 
   442 (* To avoid eta-contraction of body: *)
   443 print_translation {*
   444 let
   445   fun btr' syn (A :: Abs abs :: ts) =
   446     let val (x,t) = atomic_abs_tr' abs
   447     in list_comb (Syntax.const syn $ x $ A $ t, ts) end
   448   val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const
   449 in
   450 [(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]
   451 end
   452 *}
   453 
   454 context complete_lattice
   455 begin
   456 
   457 lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
   458   by (auto simp add: SUPR_def intro: Sup_upper)
   459 
   460 lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
   461   by (auto simp add: SUPR_def intro: Sup_least)
   462 
   463 lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
   464   by (auto simp add: INFI_def intro: Inf_lower)
   465 
   466 lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
   467   by (auto simp add: INFI_def intro: Inf_greatest)
   468 
   469 lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
   470   by (auto intro: antisym SUP_leI le_SUPI)
   471 
   472 lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
   473   by (auto intro: antisym INF_leI le_INFI)
   474 
   475 end
   476 
   477 
   478 subsection {* Bool as lattice *}
   479 
   480 instance bool :: distrib_lattice
   481   inf_bool_eq: "P \<sqinter> Q \<equiv> P \<and> Q"
   482   sup_bool_eq: "P \<squnion> Q \<equiv> P \<or> Q"
   483   by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
   484 
   485 instance bool :: complete_lattice
   486   Inf_bool_def: "\<Sqinter>A \<equiv> \<forall>x\<in>A. x"
   487   Sup_bool_def: "\<Squnion>A \<equiv> \<exists>x\<in>A. x"
   488   by intro_classes (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)
   489 
   490 lemma Inf_empty_bool [simp]:
   491   "\<Sqinter>{}"
   492   unfolding Inf_bool_def by auto
   493 
   494 lemma not_Sup_empty_bool [simp]:
   495   "\<not> Sup {}"
   496   unfolding Sup_bool_def by auto
   497 
   498 lemma top_bool_eq: "top = True"
   499   by (iprover intro!: order_antisym le_boolI top_greatest)
   500 
   501 lemma bot_bool_eq: "bot = False"
   502   by (iprover intro!: order_antisym le_boolI bot_least)
   503 
   504 
   505 subsection {* Set as lattice *}
   506 
   507 instance set :: (type) distrib_lattice
   508   inf_set_eq: "A \<sqinter> B \<equiv> A \<inter> B"
   509   sup_set_eq: "A \<squnion> B \<equiv> A \<union> B"
   510   by intro_classes (auto simp add: inf_set_eq sup_set_eq)
   511 
   512 lemmas [code func del] = inf_set_eq sup_set_eq
   513 
   514 lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
   515   apply (fold inf_set_eq sup_set_eq)
   516   apply (erule mono_inf)
   517   done
   518 
   519 lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
   520   apply (fold inf_set_eq sup_set_eq)
   521   apply (erule mono_sup)
   522   done
   523 
   524 instance set :: (type) complete_lattice
   525   Inf_set_def: "\<Sqinter>S \<equiv> \<Inter>S"
   526   Sup_set_def: "\<Squnion>S \<equiv> \<Union>S"
   527   by intro_classes (auto simp add: Inf_set_def Sup_set_def)
   528 
   529 lemmas [code func del] = Inf_set_def Sup_set_def
   530 
   531 lemma top_set_eq: "top = UNIV"
   532   by (iprover intro!: subset_antisym subset_UNIV top_greatest)
   533 
   534 lemma bot_set_eq: "bot = {}"
   535   by (iprover intro!: subset_antisym empty_subsetI bot_least)
   536 
   537 
   538 subsection {* Fun as lattice *}
   539 
   540 instance "fun" :: (type, lattice) lattice
   541   inf_fun_eq: "f \<sqinter> g \<equiv> (\<lambda>x. f x \<sqinter> g x)"
   542   sup_fun_eq: "f \<squnion> g \<equiv> (\<lambda>x. f x \<squnion> g x)"
   543 apply intro_classes
   544 unfolding inf_fun_eq sup_fun_eq
   545 apply (auto intro: le_funI)
   546 apply (rule le_funI)
   547 apply (auto dest: le_funD)
   548 apply (rule le_funI)
   549 apply (auto dest: le_funD)
   550 done
   551 
   552 lemmas [code func del] = inf_fun_eq sup_fun_eq
   553 
   554 instance "fun" :: (type, distrib_lattice) distrib_lattice
   555   by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   556 
   557 instance "fun" :: (type, complete_lattice) complete_lattice
   558   Inf_fun_def: "\<Sqinter>A \<equiv> (\<lambda>x. \<Sqinter>{y. \<exists>f\<in>A. y = f x})"
   559   Sup_fun_def: "\<Squnion>A \<equiv> (\<lambda>x. \<Squnion>{y. \<exists>f\<in>A. y = f x})"
   560   by intro_classes
   561     (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
   562       intro: Inf_lower Sup_upper Inf_greatest Sup_least)
   563 
   564 lemmas [code func del] = Inf_fun_def Sup_fun_def
   565 
   566 lemma Inf_empty_fun:
   567   "\<Sqinter>{} = (\<lambda>_. \<Sqinter>{})"
   568   by rule (auto simp add: Inf_fun_def)
   569 
   570 lemma Sup_empty_fun:
   571   "\<Squnion>{} = (\<lambda>_. \<Squnion>{})"
   572   by rule (auto simp add: Sup_fun_def)
   573 
   574 lemma top_fun_eq: "top = (\<lambda>x. top)"
   575   by (iprover intro!: order_antisym le_funI top_greatest)
   576 
   577 lemma bot_fun_eq: "bot = (\<lambda>x. bot)"
   578   by (iprover intro!: order_antisym le_funI bot_least)
   579 
   580 
   581 text {* redundant bindings *}
   582 
   583 lemmas inf_aci = inf_ACI
   584 lemmas sup_aci = sup_ACI
   585 
   586 no_notation
   587   less_eq  (infix "\<sqsubseteq>" 50) and
   588   less (infix "\<sqsubset>" 50) and
   589   inf  (infixl "\<sqinter>" 70) and
   590   sup  (infixl "\<squnion>" 65) and
   591   Inf  ("\<Sqinter>_" [900] 900) and
   592   Sup  ("\<Squnion>_" [900] 900)
   593 
   594 end