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