src/HOL/Lattices.thy
author haftmann
Sat Dec 05 20:02:21 2009 +0100 (2009-12-05)
changeset 34007 aea892559fc5
parent 32781 19c01bd7f6ae
child 34209 c7f621786035
permissions -rw-r--r--
tuned lattices theory fragements; generlized some lemmas from sets to lattices
     1 (*  Title:      HOL/Lattices.thy
     2     Author:     Tobias Nipkow
     3 *)
     4 
     5 header {* Abstract lattices *}
     6 
     7 theory Lattices
     8 imports Orderings
     9 begin
    10 
    11 subsection {* Lattices *}
    12 
    13 notation
    14   less_eq  (infix "\<sqsubseteq>" 50) and
    15   less  (infix "\<sqsubset>" 50) and
    16   top ("\<top>") and
    17   bot ("\<bottom>")
    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 begin
    31 
    32 text {* Dual lattice *}
    33 
    34 lemma dual_semilattice:
    35   "lower_semilattice (op \<ge>) (op >) sup"
    36 by (rule lower_semilattice.intro, rule dual_order)
    37   (unfold_locales, simp_all add: sup_least)
    38 
    39 end
    40 
    41 class lattice = lower_semilattice + upper_semilattice
    42 
    43 
    44 subsubsection {* Intro and elim rules*}
    45 
    46 context lower_semilattice
    47 begin
    48 
    49 lemma le_infI1:
    50   "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
    51   by (rule order_trans) auto
    52 
    53 lemma le_infI2:
    54   "b \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
    55   by (rule order_trans) auto
    56 
    57 lemma le_infI: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
    58   by (blast intro: inf_greatest)
    59 
    60 lemma le_infE: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
    61   by (blast intro: order_trans le_infI1 le_infI2)
    62 
    63 lemma le_inf_iff [simp]:
    64   "x \<sqsubseteq> y \<sqinter> z \<longleftrightarrow> x \<sqsubseteq> y \<and> x \<sqsubseteq> z"
    65   by (blast intro: le_infI elim: le_infE)
    66 
    67 lemma le_iff_inf:
    68   "x \<sqsubseteq> y \<longleftrightarrow> x \<sqinter> y = x"
    69   by (auto intro: le_infI1 antisym dest: eq_iff [THEN iffD1])
    70 
    71 lemma mono_inf:
    72   fixes f :: "'a \<Rightarrow> 'b\<Colon>lower_semilattice"
    73   shows "mono f \<Longrightarrow> f (A \<sqinter> B) \<sqsubseteq> f A \<sqinter> f B"
    74   by (auto simp add: mono_def intro: Lattices.inf_greatest)
    75 
    76 end
    77 
    78 context upper_semilattice
    79 begin
    80 
    81 lemma le_supI1:
    82   "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
    83   by (rule order_trans) auto
    84 
    85 lemma le_supI2:
    86   "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
    87   by (rule order_trans) auto 
    88 
    89 lemma le_supI:
    90   "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
    91   by (blast intro: sup_least)
    92 
    93 lemma le_supE:
    94   "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
    95   by (blast intro: le_supI1 le_supI2 order_trans)
    96 
    97 lemma le_sup_iff [simp]:
    98   "x \<squnion> y \<sqsubseteq> z \<longleftrightarrow> x \<sqsubseteq> z \<and> y \<sqsubseteq> z"
    99   by (blast intro: le_supI elim: le_supE)
   100 
   101 lemma le_iff_sup:
   102   "x \<sqsubseteq> y \<longleftrightarrow> x \<squnion> y = y"
   103   by (auto intro: le_supI2 antisym dest: eq_iff [THEN iffD1])
   104 
   105 lemma mono_sup:
   106   fixes f :: "'a \<Rightarrow> 'b\<Colon>upper_semilattice"
   107   shows "mono f \<Longrightarrow> f A \<squnion> f B \<sqsubseteq> f (A \<squnion> B)"
   108   by (auto simp add: mono_def intro: Lattices.sup_least)
   109 
   110 end
   111 
   112 
   113 subsubsection {* Equational laws *}
   114 
   115 context lower_semilattice
   116 begin
   117 
   118 lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
   119   by (rule antisym) auto
   120 
   121 lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
   122   by (rule antisym) (auto intro: le_infI1 le_infI2)
   123 
   124 lemma inf_idem[simp]: "x \<sqinter> x = x"
   125   by (rule antisym) auto
   126 
   127 lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
   128   by (rule antisym) (auto intro: le_infI2)
   129 
   130 lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
   131   by (rule antisym) auto
   132 
   133 lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
   134   by (rule antisym) auto
   135 
   136 lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
   137   by (rule mk_left_commute [of inf]) (fact inf_assoc inf_commute)+
   138   
   139 lemmas inf_aci = inf_commute inf_assoc inf_left_commute inf_left_idem
   140 
   141 end
   142 
   143 context upper_semilattice
   144 begin
   145 
   146 lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
   147   by (rule antisym) auto
   148 
   149 lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
   150   by (rule antisym) (auto intro: le_supI1 le_supI2)
   151 
   152 lemma sup_idem[simp]: "x \<squnion> x = x"
   153   by (rule antisym) auto
   154 
   155 lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
   156   by (rule antisym) (auto intro: le_supI2)
   157 
   158 lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
   159   by (rule antisym) auto
   160 
   161 lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
   162   by (rule antisym) auto
   163 
   164 lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
   165   by (rule mk_left_commute [of sup]) (fact sup_assoc sup_commute)+
   166 
   167 lemmas sup_aci = sup_commute sup_assoc sup_left_commute sup_left_idem
   168 
   169 end
   170 
   171 context lattice
   172 begin
   173 
   174 lemma dual_lattice:
   175   "lattice (op \<ge>) (op >) sup inf"
   176   by (rule lattice.intro, rule dual_semilattice, rule upper_semilattice.intro, rule dual_order)
   177     (unfold_locales, auto)
   178 
   179 lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
   180   by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
   181 
   182 lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
   183   by (blast intro: antisym sup_ge1 sup_least inf_le1)
   184 
   185 lemmas inf_sup_aci = inf_aci sup_aci
   186 
   187 lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
   188 
   189 text{* Towards distributivity *}
   190 
   191 lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   192   by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
   193 
   194 lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
   195   by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
   196 
   197 text{* If you have one of them, you have them all. *}
   198 
   199 lemma distrib_imp1:
   200 assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   201 shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   202 proof-
   203   have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
   204   also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc del:sup_absorb1)
   205   also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
   206     by(simp add:inf_sup_absorb inf_commute)
   207   also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
   208   finally show ?thesis .
   209 qed
   210 
   211 lemma distrib_imp2:
   212 assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   213 shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   214 proof-
   215   have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
   216   also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc del:inf_absorb1)
   217   also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
   218     by(simp add:sup_inf_absorb sup_commute)
   219   also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
   220   finally show ?thesis .
   221 qed
   222 
   223 end
   224 
   225 subsubsection {* Strict order *}
   226 
   227 context lower_semilattice
   228 begin
   229 
   230 lemma less_infI1:
   231   "a \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
   232   by (auto simp add: less_le inf_absorb1 intro: le_infI1)
   233 
   234 lemma less_infI2:
   235   "b \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
   236   by (auto simp add: less_le inf_absorb2 intro: le_infI2)
   237 
   238 end
   239 
   240 context upper_semilattice
   241 begin
   242 
   243 lemma less_supI1:
   244   "x \<sqsubset> a \<Longrightarrow> x \<sqsubset> a \<squnion> b"
   245 proof -
   246   interpret dual: lower_semilattice "op \<ge>" "op >" sup
   247     by (fact dual_semilattice)
   248   assume "x \<sqsubset> a"
   249   then show "x \<sqsubset> a \<squnion> b"
   250     by (fact dual.less_infI1)
   251 qed
   252 
   253 lemma less_supI2:
   254   "x \<sqsubset> b \<Longrightarrow> x \<sqsubset> a \<squnion> b"
   255 proof -
   256   interpret dual: lower_semilattice "op \<ge>" "op >" sup
   257     by (fact dual_semilattice)
   258   assume "x \<sqsubset> b"
   259   then show "x \<sqsubset> a \<squnion> b"
   260     by (fact dual.less_infI2)
   261 qed
   262 
   263 end
   264 
   265 
   266 subsection {* Distributive lattices *}
   267 
   268 class distrib_lattice = lattice +
   269   assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   270 
   271 context distrib_lattice
   272 begin
   273 
   274 lemma sup_inf_distrib2:
   275  "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
   276 by(simp add: inf_sup_aci sup_inf_distrib1)
   277 
   278 lemma inf_sup_distrib1:
   279  "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   280 by(rule distrib_imp2[OF sup_inf_distrib1])
   281 
   282 lemma inf_sup_distrib2:
   283  "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
   284 by(simp add: inf_sup_aci inf_sup_distrib1)
   285 
   286 lemma dual_distrib_lattice:
   287   "distrib_lattice (op \<ge>) (op >) sup inf"
   288   by (rule distrib_lattice.intro, rule dual_lattice)
   289     (unfold_locales, fact inf_sup_distrib1)
   290 
   291 lemmas distrib =
   292   sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
   293 
   294 end
   295 
   296 
   297 subsection {* Bounded lattices and boolean algebras *}
   298 
   299 class bounded_lattice = lattice + top + bot
   300 begin
   301 
   302 lemma dual_bounded_lattice:
   303   "bounded_lattice (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom>"
   304   by (rule bounded_lattice.intro, rule dual_lattice)
   305     (unfold_locales, auto simp add: less_le_not_le)
   306 
   307 lemma inf_bot_left [simp]:
   308   "\<bottom> \<sqinter> x = \<bottom>"
   309   by (rule inf_absorb1) simp
   310 
   311 lemma inf_bot_right [simp]:
   312   "x \<sqinter> \<bottom> = \<bottom>"
   313   by (rule inf_absorb2) simp
   314 
   315 lemma sup_top_left [simp]:
   316   "\<top> \<squnion> x = \<top>"
   317   by (rule sup_absorb1) simp
   318 
   319 lemma sup_top_right [simp]:
   320   "x \<squnion> \<top> = \<top>"
   321   by (rule sup_absorb2) simp
   322 
   323 lemma inf_top_left [simp]:
   324   "\<top> \<sqinter> x = x"
   325   by (rule inf_absorb2) simp
   326 
   327 lemma inf_top_right [simp]:
   328   "x \<sqinter> \<top> = x"
   329   by (rule inf_absorb1) simp
   330 
   331 lemma sup_bot_left [simp]:
   332   "\<bottom> \<squnion> x = x"
   333   by (rule sup_absorb2) simp
   334 
   335 lemma sup_bot_right [simp]:
   336   "x \<squnion> \<bottom> = x"
   337   by (rule sup_absorb1) simp
   338 
   339 lemma inf_eq_top_eq1:
   340   assumes "A \<sqinter> B = \<top>"
   341   shows "A = \<top>"
   342 proof (cases "B = \<top>")
   343   case True with assms show ?thesis by simp
   344 next
   345   case False with top_greatest have "B \<sqsubset> \<top>" by (auto intro: neq_le_trans)
   346   then have "A \<sqinter> B \<sqsubset> \<top>" by (rule less_infI2)
   347   with assms show ?thesis by simp
   348 qed
   349 
   350 lemma inf_eq_top_eq2:
   351   assumes "A \<sqinter> B = \<top>"
   352   shows "B = \<top>"
   353   by (rule inf_eq_top_eq1, unfold inf_commute [of B]) (fact assms)
   354 
   355 lemma sup_eq_bot_eq1:
   356   assumes "A \<squnion> B = \<bottom>"
   357   shows "A = \<bottom>"
   358 proof -
   359   interpret dual: bounded_lattice "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
   360     by (rule dual_bounded_lattice)
   361   from dual.inf_eq_top_eq1 assms show ?thesis .
   362 qed
   363 
   364 lemma sup_eq_bot_eq2:
   365   assumes "A \<squnion> B = \<bottom>"
   366   shows "B = \<bottom>"
   367 proof -
   368   interpret dual: bounded_lattice "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
   369     by (rule dual_bounded_lattice)
   370   from dual.inf_eq_top_eq2 assms show ?thesis .
   371 qed
   372 
   373 end
   374 
   375 class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
   376   assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
   377     and sup_compl_top: "x \<squnion> - x = \<top>"
   378   assumes diff_eq: "x - y = x \<sqinter> - y"
   379 begin
   380 
   381 lemma dual_boolean_algebra:
   382   "boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom>"
   383   by (rule boolean_algebra.intro, rule dual_bounded_lattice, rule dual_distrib_lattice)
   384     (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
   385 
   386 lemma compl_inf_bot:
   387   "- x \<sqinter> x = \<bottom>"
   388   by (simp add: inf_commute inf_compl_bot)
   389 
   390 lemma compl_sup_top:
   391   "- x \<squnion> x = \<top>"
   392   by (simp add: sup_commute sup_compl_top)
   393 
   394 lemma compl_unique:
   395   assumes "x \<sqinter> y = \<bottom>"
   396     and "x \<squnion> y = \<top>"
   397   shows "- x = y"
   398 proof -
   399   have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
   400     using inf_compl_bot assms(1) by simp
   401   then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
   402     by (simp add: inf_commute)
   403   then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
   404     by (simp add: inf_sup_distrib1)
   405   then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
   406     using sup_compl_top assms(2) by simp
   407   then show "- x = y" by (simp add: inf_top_right)
   408 qed
   409 
   410 lemma double_compl [simp]:
   411   "- (- x) = x"
   412   using compl_inf_bot compl_sup_top by (rule compl_unique)
   413 
   414 lemma compl_eq_compl_iff [simp]:
   415   "- x = - y \<longleftrightarrow> x = y"
   416 proof
   417   assume "- x = - y"
   418   then have "- x \<sqinter> y = \<bottom>"
   419     and "- x \<squnion> y = \<top>"
   420     by (simp_all add: compl_inf_bot compl_sup_top)
   421   then have "- (- x) = y" by (rule compl_unique)
   422   then show "x = y" by simp
   423 next
   424   assume "x = y"
   425   then show "- x = - y" by simp
   426 qed
   427 
   428 lemma compl_bot_eq [simp]:
   429   "- \<bottom> = \<top>"
   430 proof -
   431   from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
   432   then show ?thesis by simp
   433 qed
   434 
   435 lemma compl_top_eq [simp]:
   436   "- \<top> = \<bottom>"
   437 proof -
   438   from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
   439   then show ?thesis by simp
   440 qed
   441 
   442 lemma compl_inf [simp]:
   443   "- (x \<sqinter> y) = - x \<squnion> - y"
   444 proof (rule compl_unique)
   445   have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = ((x \<sqinter> y) \<sqinter> - x) \<squnion> ((x \<sqinter> y) \<sqinter> - y)"
   446     by (rule inf_sup_distrib1)
   447   also have "... = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
   448     by (simp only: inf_commute inf_assoc inf_left_commute)
   449   finally show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
   450     by (simp add: inf_compl_bot)
   451 next
   452   have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (x \<squnion> (- x \<squnion> - y)) \<sqinter> (y \<squnion> (- x \<squnion> - y))"
   453     by (rule sup_inf_distrib2)
   454   also have "... = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
   455     by (simp only: sup_commute sup_assoc sup_left_commute)
   456   finally show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
   457     by (simp add: sup_compl_top)
   458 qed
   459 
   460 lemma compl_sup [simp]:
   461   "- (x \<squnion> y) = - x \<sqinter> - y"
   462 proof -
   463   interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" \<top> \<bottom>
   464     by (rule dual_boolean_algebra)
   465   then show ?thesis by simp
   466 qed
   467 
   468 end
   469 
   470 
   471 subsection {* Uniqueness of inf and sup *}
   472 
   473 lemma (in lower_semilattice) inf_unique:
   474   fixes f (infixl "\<triangle>" 70)
   475   assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
   476   and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
   477   shows "x \<sqinter> y = x \<triangle> y"
   478 proof (rule antisym)
   479   show "x \<triangle> y \<sqsubseteq> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2)
   480 next
   481   have leI: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z" by (blast intro: greatest)
   482   show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
   483 qed
   484 
   485 lemma (in upper_semilattice) sup_unique:
   486   fixes f (infixl "\<nabla>" 70)
   487   assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
   488   and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
   489   shows "x \<squnion> y = x \<nabla> y"
   490 proof (rule antisym)
   491   show "x \<squnion> y \<sqsubseteq> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2)
   492 next
   493   have leI: "\<And>x y z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<nabla> y \<sqsubseteq> z" by (blast intro: least)
   494   show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
   495 qed
   496   
   497 
   498 subsection {* @{const min}/@{const max} on linear orders as
   499   special case of @{const inf}/@{const sup} *}
   500 
   501 sublocale linorder < min_max!: distrib_lattice less_eq less min max
   502 proof
   503   fix x y z
   504   show "max x (min y z) = min (max x y) (max x z)"
   505     by (auto simp add: min_def max_def)
   506 qed (auto simp add: min_def max_def not_le less_imp_le)
   507 
   508 lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   509   by (rule ext)+ (auto intro: antisym)
   510 
   511 lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   512   by (rule ext)+ (auto intro: antisym)
   513 
   514 lemmas le_maxI1 = min_max.sup_ge1
   515 lemmas le_maxI2 = min_max.sup_ge2
   516  
   517 lemmas max_ac = min_max.sup_assoc min_max.sup_commute
   518   mk_left_commute [of max, OF min_max.sup_assoc min_max.sup_commute]
   519 
   520 lemmas min_ac = min_max.inf_assoc min_max.inf_commute
   521   mk_left_commute [of min, OF min_max.inf_assoc min_max.inf_commute]
   522 
   523 
   524 subsection {* Bool as lattice *}
   525 
   526 instantiation bool :: boolean_algebra
   527 begin
   528 
   529 definition
   530   bool_Compl_def: "uminus = Not"
   531 
   532 definition
   533   bool_diff_def: "A - B \<longleftrightarrow> A \<and> \<not> B"
   534 
   535 definition
   536   inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
   537 
   538 definition
   539   sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
   540 
   541 instance proof
   542 qed (simp_all add: inf_bool_eq sup_bool_eq le_bool_def
   543   bot_bool_eq top_bool_eq bool_Compl_def bool_diff_def, auto)
   544 
   545 end
   546 
   547 lemma sup_boolI1:
   548   "P \<Longrightarrow> P \<squnion> Q"
   549   by (simp add: sup_bool_eq)
   550 
   551 lemma sup_boolI2:
   552   "Q \<Longrightarrow> P \<squnion> Q"
   553   by (simp add: sup_bool_eq)
   554 
   555 lemma sup_boolE:
   556   "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
   557   by (auto simp add: sup_bool_eq)
   558 
   559 
   560 subsection {* Fun as lattice *}
   561 
   562 instantiation "fun" :: (type, lattice) lattice
   563 begin
   564 
   565 definition
   566   inf_fun_eq [code del]: "f \<sqinter> g = (\<lambda>x. f x \<sqinter> g x)"
   567 
   568 definition
   569   sup_fun_eq [code del]: "f \<squnion> g = (\<lambda>x. f x \<squnion> g x)"
   570 
   571 instance proof
   572 qed (simp_all add: le_fun_def inf_fun_eq sup_fun_eq)
   573 
   574 end
   575 
   576 instance "fun" :: (type, distrib_lattice) distrib_lattice
   577 proof
   578 qed (simp_all add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   579 
   580 instance "fun" :: (type, bounded_lattice) bounded_lattice ..
   581 
   582 instantiation "fun" :: (type, uminus) uminus
   583 begin
   584 
   585 definition
   586   fun_Compl_def: "- A = (\<lambda>x. - A x)"
   587 
   588 instance ..
   589 
   590 end
   591 
   592 instantiation "fun" :: (type, minus) minus
   593 begin
   594 
   595 definition
   596   fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
   597 
   598 instance ..
   599 
   600 end
   601 
   602 instance "fun" :: (type, boolean_algebra) boolean_algebra
   603 proof
   604 qed (simp_all add: inf_fun_eq sup_fun_eq bot_fun_eq top_fun_eq fun_Compl_def fun_diff_def
   605   inf_compl_bot sup_compl_top diff_eq)
   606 
   607 
   608 no_notation
   609   less_eq  (infix "\<sqsubseteq>" 50) and
   610   less (infix "\<sqsubset>" 50) and
   611   inf  (infixl "\<sqinter>" 70) and
   612   sup  (infixl "\<squnion>" 65) and
   613   top ("\<top>") and
   614   bot ("\<bottom>")
   615 
   616 end