src/HOL/Lattices.thy
changeset 31991 37390299214a
parent 30729 461ee3e49ad3
child 32063 2aab4f2af536
equal deleted inserted replaced
31990:1d4d0b305f16 31991:37390299214a
    27   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    27   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    28 begin
    28 begin
    29 
    29 
    30 text {* Dual lattice *}
    30 text {* Dual lattice *}
    31 
    31 
    32 lemma dual_lattice:
    32 lemma dual_semilattice:
    33   "lower_semilattice (op \<ge>) (op >) sup"
    33   "lower_semilattice (op \<ge>) (op >) sup"
    34 by (rule lower_semilattice.intro, rule dual_order)
    34 by (rule lower_semilattice.intro, rule dual_order)
    35   (unfold_locales, simp_all add: sup_least)
    35   (unfold_locales, simp_all add: sup_least)
    36 
    36 
    37 end
    37 end
   177 
   177 
   178 end
   178 end
   179 
   179 
   180 context lattice
   180 context lattice
   181 begin
   181 begin
       
   182 
       
   183 lemma dual_lattice:
       
   184   "lattice (op \<ge>) (op >) sup inf"
       
   185   by (rule lattice.intro, rule dual_semilattice, rule upper_semilattice.intro, rule dual_order)
       
   186     (unfold_locales, auto)
   182 
   187 
   183 lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
   188 lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
   184   by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
   189   by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
   185 
   190 
   186 lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
   191 lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
   250 
   255 
   251 lemma inf_sup_distrib2:
   256 lemma inf_sup_distrib2:
   252  "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
   257  "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
   253 by(simp add:ACI inf_sup_distrib1)
   258 by(simp add:ACI inf_sup_distrib1)
   254 
   259 
       
   260 lemma dual_distrib_lattice:
       
   261   "distrib_lattice (op \<ge>) (op >) sup inf"
       
   262   by (rule distrib_lattice.intro, rule dual_lattice)
       
   263     (unfold_locales, fact inf_sup_distrib1)
       
   264 
   255 lemmas distrib =
   265 lemmas distrib =
   256   sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
   266   sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
       
   267 
       
   268 end
       
   269 
       
   270 
       
   271 subsection {* Boolean algebras *}
       
   272 
       
   273 class boolean_algebra = distrib_lattice + top + bot + minus + uminus +
       
   274   assumes inf_compl_bot: "x \<sqinter> - x = bot"
       
   275     and sup_compl_top: "x \<squnion> - x = top"
       
   276   assumes diff_eq: "x - y = x \<sqinter> - y"
       
   277 begin
       
   278 
       
   279 lemma dual_boolean_algebra:
       
   280   "boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) top bot"
       
   281   by (rule boolean_algebra.intro, rule dual_distrib_lattice)
       
   282     (unfold_locales,
       
   283       auto simp add: inf_compl_bot sup_compl_top diff_eq less_le_not_le)
       
   284 
       
   285 lemma compl_inf_bot:
       
   286   "- x \<sqinter> x = bot"
       
   287   by (simp add: inf_commute inf_compl_bot)
       
   288 
       
   289 lemma compl_sup_top:
       
   290   "- x \<squnion> x = top"
       
   291   by (simp add: sup_commute sup_compl_top)
       
   292 
       
   293 lemma inf_bot_left [simp]:
       
   294   "bot \<sqinter> x = bot"
       
   295   by (rule inf_absorb1) simp
       
   296 
       
   297 lemma inf_bot_right [simp]:
       
   298   "x \<sqinter> bot = bot"
       
   299   by (rule inf_absorb2) simp
       
   300 
       
   301 lemma sup_top_left [simp]:
       
   302   "top \<squnion> x = top"
       
   303   by (rule sup_absorb1) simp
       
   304 
       
   305 lemma sup_top_right [simp]:
       
   306   "x \<squnion> top = top"
       
   307   by (rule sup_absorb2) simp
       
   308 
       
   309 lemma inf_top_left [simp]:
       
   310   "top \<sqinter> x = x"
       
   311   by (rule inf_absorb2) simp
       
   312 
       
   313 lemma inf_top_right [simp]:
       
   314   "x \<sqinter> top = x"
       
   315   by (rule inf_absorb1) simp
       
   316 
       
   317 lemma sup_bot_left [simp]:
       
   318   "bot \<squnion> x = x"
       
   319   by (rule sup_absorb2) simp
       
   320 
       
   321 lemma sup_bot_right [simp]:
       
   322   "x \<squnion> bot = x"
       
   323   by (rule sup_absorb1) simp
       
   324 
       
   325 lemma compl_unique:
       
   326   assumes "x \<sqinter> y = bot"
       
   327     and "x \<squnion> y = top"
       
   328   shows "- x = y"
       
   329 proof -
       
   330   have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
       
   331     using inf_compl_bot assms(1) by simp
       
   332   then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
       
   333     by (simp add: inf_commute)
       
   334   then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
       
   335     by (simp add: inf_sup_distrib1)
       
   336   then have "- x \<sqinter> top = y \<sqinter> top"
       
   337     using sup_compl_top assms(2) by simp
       
   338   then show "- x = y" by (simp add: inf_top_right)
       
   339 qed
       
   340 
       
   341 lemma double_compl [simp]:
       
   342   "- (- x) = x"
       
   343   using compl_inf_bot compl_sup_top by (rule compl_unique)
       
   344 
       
   345 lemma compl_eq_compl_iff [simp]:
       
   346   "- x = - y \<longleftrightarrow> x = y"
       
   347 proof
       
   348   assume "- x = - y"
       
   349   then have "- x \<sqinter> y = bot"
       
   350     and "- x \<squnion> y = top"
       
   351     by (simp_all add: compl_inf_bot compl_sup_top)
       
   352   then have "- (- x) = y" by (rule compl_unique)
       
   353   then show "x = y" by simp
       
   354 next
       
   355   assume "x = y"
       
   356   then show "- x = - y" by simp
       
   357 qed
       
   358 
       
   359 lemma compl_bot_eq [simp]:
       
   360   "- bot = top"
       
   361 proof -
       
   362   from sup_compl_top have "bot \<squnion> - bot = top" .
       
   363   then show ?thesis by simp
       
   364 qed
       
   365 
       
   366 lemma compl_top_eq [simp]:
       
   367   "- top = bot"
       
   368 proof -
       
   369   from inf_compl_bot have "top \<sqinter> - top = bot" .
       
   370   then show ?thesis by simp
       
   371 qed
       
   372 
       
   373 lemma compl_inf [simp]:
       
   374   "- (x \<sqinter> y) = - x \<squnion> - y"
       
   375 proof (rule compl_unique)
       
   376   have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = ((x \<sqinter> y) \<sqinter> - x) \<squnion> ((x \<sqinter> y) \<sqinter> - y)"
       
   377     by (rule inf_sup_distrib1)
       
   378   also have "... = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
       
   379     by (simp only: inf_commute inf_assoc inf_left_commute)
       
   380   finally show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = bot"
       
   381     by (simp add: inf_compl_bot)
       
   382 next
       
   383   have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (x \<squnion> (- x \<squnion> - y)) \<sqinter> (y \<squnion> (- x \<squnion> - y))"
       
   384     by (rule sup_inf_distrib2)
       
   385   also have "... = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
       
   386     by (simp only: sup_commute sup_assoc sup_left_commute)
       
   387   finally show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = top"
       
   388     by (simp add: sup_compl_top)
       
   389 qed
       
   390 
       
   391 lemma compl_sup [simp]:
       
   392   "- (x \<squnion> y) = - x \<sqinter> - y"
       
   393 proof -
       
   394   interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" top bot
       
   395     by (rule dual_boolean_algebra)
       
   396   then show ?thesis by simp
       
   397 qed
   257 
   398 
   258 end
   399 end
   259 
   400 
   260 
   401 
   261 subsection {* Uniqueness of inf and sup *}
   402 subsection {* Uniqueness of inf and sup *}
   328   min_max.le_infI1 min_max.le_infI2
   469   min_max.le_infI1 min_max.le_infI2
   329 
   470 
   330 
   471 
   331 subsection {* Bool as lattice *}
   472 subsection {* Bool as lattice *}
   332 
   473 
   333 instantiation bool :: distrib_lattice
   474 instantiation bool :: boolean_algebra
   334 begin
   475 begin
       
   476 
       
   477 definition
       
   478   bool_Compl_def: "uminus = Not"
       
   479 
       
   480 definition
       
   481   bool_diff_def: "A - B \<longleftrightarrow> A \<and> \<not> B"
   335 
   482 
   336 definition
   483 definition
   337   inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
   484   inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
   338 
   485 
   339 definition
   486 definition
   340   sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
   487   sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
   341 
   488 
   342 instance
   489 instance proof
   343   by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
   490 qed (simp_all add: inf_bool_eq sup_bool_eq le_bool_def
       
   491   bot_bool_eq top_bool_eq bool_Compl_def bool_diff_def, auto)
   344 
   492 
   345 end
   493 end
   346 
   494 
   347 
   495 
   348 subsection {* Fun as lattice *}
   496 subsection {* Fun as lattice *}
   367 done
   515 done
   368 
   516 
   369 end
   517 end
   370 
   518 
   371 instance "fun" :: (type, distrib_lattice) distrib_lattice
   519 instance "fun" :: (type, distrib_lattice) distrib_lattice
   372   by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   520 proof
       
   521 qed (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
       
   522 
       
   523 instantiation "fun" :: (type, uminus) uminus
       
   524 begin
       
   525 
       
   526 definition
       
   527   fun_Compl_def: "- A = (\<lambda>x. - A x)"
       
   528 
       
   529 instance ..
       
   530 
       
   531 end
       
   532 
       
   533 instantiation "fun" :: (type, minus) minus
       
   534 begin
       
   535 
       
   536 definition
       
   537   fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
       
   538 
       
   539 instance ..
       
   540 
       
   541 end
       
   542 
       
   543 instance "fun" :: (type, boolean_algebra) boolean_algebra
       
   544 proof
       
   545 qed (simp_all add: inf_fun_eq sup_fun_eq bot_fun_eq top_fun_eq fun_Compl_def fun_diff_def
       
   546   inf_compl_bot sup_compl_top diff_eq)
   373 
   547 
   374 
   548 
   375 text {* redundant bindings *}
   549 text {* redundant bindings *}
   376 
   550 
   377 lemmas inf_aci = inf_ACI
   551 lemmas inf_aci = inf_ACI