src/HOL/Library/Lattice_Algebras.thy
author wenzelm
Mon Dec 28 17:43:30 2015 +0100 (2015-12-28)
changeset 61952 546958347e05
parent 61546 53bb4172c7f7
child 65151 a7394aa4d21c
permissions -rw-r--r--
prefer symbols for "Union", "Inter";
     1 (*  Author:     Steven Obua, TU Muenchen *)
     2 
     3 section \<open>Various algebraic structures combined with a lattice\<close>
     4 
     5 theory Lattice_Algebras
     6 imports Complex_Main
     7 begin
     8 
     9 class semilattice_inf_ab_group_add = ordered_ab_group_add + semilattice_inf
    10 begin
    11 
    12 lemma add_inf_distrib_left: "a + inf b c = inf (a + b) (a + c)"
    13   apply (rule antisym)
    14   apply (simp_all add: le_infI)
    15   apply (rule add_le_imp_le_left [of "uminus a"])
    16   apply (simp only: add.assoc [symmetric], simp add: diff_le_eq add.commute)
    17   done
    18 
    19 lemma add_inf_distrib_right: "inf a b + c = inf (a + c) (b + c)"
    20 proof -
    21   have "c + inf a b = inf (c + a) (c + b)"
    22     by (simp add: add_inf_distrib_left)
    23   then show ?thesis
    24     by (simp add: add.commute)
    25 qed
    26 
    27 end
    28 
    29 class semilattice_sup_ab_group_add = ordered_ab_group_add + semilattice_sup
    30 begin
    31 
    32 lemma add_sup_distrib_left: "a + sup b c = sup (a + b) (a + c)"
    33   apply (rule antisym)
    34   apply (rule add_le_imp_le_left [of "uminus a"])
    35   apply (simp only: add.assoc [symmetric], simp)
    36   apply (simp add: le_diff_eq add.commute)
    37   apply (rule le_supI)
    38   apply (rule add_le_imp_le_left [of "a"], simp only: add.assoc[symmetric], simp)+
    39   done
    40 
    41 lemma add_sup_distrib_right: "sup a b + c = sup (a + c) (b + c)"
    42 proof -
    43   have "c + sup a b = sup (c+a) (c+b)"
    44     by (simp add: add_sup_distrib_left)
    45   then show ?thesis
    46     by (simp add: add.commute)
    47 qed
    48 
    49 end
    50 
    51 class lattice_ab_group_add = ordered_ab_group_add + lattice
    52 begin
    53 
    54 subclass semilattice_inf_ab_group_add ..
    55 subclass semilattice_sup_ab_group_add ..
    56 
    57 lemmas add_sup_inf_distribs =
    58   add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
    59 
    60 lemma inf_eq_neg_sup: "inf a b = - sup (- a) (- b)"
    61 proof (rule inf_unique)
    62   fix a b c :: 'a
    63   show "- sup (- a) (- b) \<le> a"
    64     by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
    65       (simp, simp add: add_sup_distrib_left)
    66   show "- sup (-a) (-b) \<le> b"
    67     by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
    68       (simp, simp add: add_sup_distrib_left)
    69   assume "a \<le> b" "a \<le> c"
    70   then show "a \<le> - sup (-b) (-c)"
    71     by (subst neg_le_iff_le [symmetric]) (simp add: le_supI)
    72 qed
    73 
    74 lemma sup_eq_neg_inf: "sup a b = - inf (- a) (- b)"
    75 proof (rule sup_unique)
    76   fix a b c :: 'a
    77   show "a \<le> - inf (- a) (- b)"
    78     by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    79       (simp, simp add: add_inf_distrib_left)
    80   show "b \<le> - inf (- a) (- b)"
    81     by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    82       (simp, simp add: add_inf_distrib_left)
    83   assume "a \<le> c" "b \<le> c"
    84   then show "- inf (- a) (- b) \<le> c"
    85     by (subst neg_le_iff_le [symmetric]) (simp add: le_infI)
    86 qed
    87 
    88 lemma neg_inf_eq_sup: "- inf a b = sup (- a) (- b)"
    89   by (simp add: inf_eq_neg_sup)
    90 
    91 lemma diff_inf_eq_sup: "a - inf b c = a + sup (- b) (- c)"
    92   using neg_inf_eq_sup [of b c, symmetric] by simp
    93 
    94 lemma neg_sup_eq_inf: "- sup a b = inf (- a) (- b)"
    95   by (simp add: sup_eq_neg_inf)
    96 
    97 lemma diff_sup_eq_inf: "a - sup b c = a + inf (- b) (- c)"
    98   using neg_sup_eq_inf [of b c, symmetric] by simp
    99 
   100 lemma add_eq_inf_sup: "a + b = sup a b + inf a b"
   101 proof -
   102   have "0 = - inf 0 (a - b) + inf (a - b) 0"
   103     by (simp add: inf_commute)
   104   then have "0 = sup 0 (b - a) + inf (a - b) 0"
   105     by (simp add: inf_eq_neg_sup)
   106   then have "0 = (- a + sup a b) + (inf a b + (- b))"
   107     by (simp only: add_sup_distrib_left add_inf_distrib_right) simp
   108   then show ?thesis
   109     by (simp add: algebra_simps)
   110 qed
   111 
   112 
   113 subsection \<open>Positive Part, Negative Part, Absolute Value\<close>
   114 
   115 definition nprt :: "'a \<Rightarrow> 'a"
   116   where "nprt x = inf x 0"
   117 
   118 definition pprt :: "'a \<Rightarrow> 'a"
   119   where "pprt x = sup x 0"
   120 
   121 lemma pprt_neg: "pprt (- x) = - nprt x"
   122 proof -
   123   have "sup (- x) 0 = sup (- x) (- 0)"
   124     unfolding minus_zero ..
   125   also have "\<dots> = - inf x 0"
   126     unfolding neg_inf_eq_sup ..
   127   finally have "sup (- x) 0 = - inf x 0" .
   128   then show ?thesis
   129     unfolding pprt_def nprt_def .
   130 qed
   131 
   132 lemma nprt_neg: "nprt (- x) = - pprt x"
   133 proof -
   134   from pprt_neg have "pprt (- (- x)) = - nprt (- x)" .
   135   then have "pprt x = - nprt (- x)" by simp
   136   then show ?thesis by simp
   137 qed
   138 
   139 lemma prts: "a = pprt a + nprt a"
   140   by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric])
   141 
   142 lemma zero_le_pprt[simp]: "0 \<le> pprt a"
   143   by (simp add: pprt_def)
   144 
   145 lemma nprt_le_zero[simp]: "nprt a \<le> 0"
   146   by (simp add: nprt_def)
   147 
   148 lemma le_eq_neg: "a \<le> - b \<longleftrightarrow> a + b \<le> 0"
   149   (is "?l = ?r")
   150 proof
   151   assume ?l
   152   then show ?r
   153     apply -
   154     apply (rule add_le_imp_le_right[of _ "uminus b" _])
   155     apply (simp add: add.assoc)
   156     done
   157 next
   158   assume ?r
   159   then show ?l
   160     apply -
   161     apply (rule add_le_imp_le_right[of _ "b" _])
   162     apply simp
   163     done
   164 qed
   165 
   166 lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
   167 lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
   168 
   169 lemma pprt_eq_id [simp, no_atp]: "0 \<le> x \<Longrightarrow> pprt x = x"
   170   by (simp add: pprt_def sup_absorb1)
   171 
   172 lemma nprt_eq_id [simp, no_atp]: "x \<le> 0 \<Longrightarrow> nprt x = x"
   173   by (simp add: nprt_def inf_absorb1)
   174 
   175 lemma pprt_eq_0 [simp, no_atp]: "x \<le> 0 \<Longrightarrow> pprt x = 0"
   176   by (simp add: pprt_def sup_absorb2)
   177 
   178 lemma nprt_eq_0 [simp, no_atp]: "0 \<le> x \<Longrightarrow> nprt x = 0"
   179   by (simp add: nprt_def inf_absorb2)
   180 
   181 lemma sup_0_imp_0:
   182   assumes "sup a (- a) = 0"
   183   shows "a = 0"
   184 proof -
   185   have p: "0 \<le> a" if "sup a (- a) = 0" for a :: 'a
   186   proof -
   187     from that have "sup a (- a) + a = a"
   188       by simp
   189     then have "sup (a + a) 0 = a"
   190       by (simp add: add_sup_distrib_right)
   191     then have "sup (a + a) 0 \<le> a"
   192       by simp
   193     then show ?thesis
   194       by (blast intro: order_trans inf_sup_ord)
   195   qed
   196   from assms have **: "sup (-a) (-(-a)) = 0"
   197     by (simp add: sup_commute)
   198   from p[OF assms] p[OF **] show "a = 0"
   199     by simp
   200 qed
   201 
   202 lemma inf_0_imp_0: "inf a (- a) = 0 \<Longrightarrow> a = 0"
   203   apply (simp add: inf_eq_neg_sup)
   204   apply (simp add: sup_commute)
   205   apply (erule sup_0_imp_0)
   206   done
   207 
   208 lemma inf_0_eq_0 [simp, no_atp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
   209   apply rule
   210   apply (erule inf_0_imp_0)
   211   apply simp
   212   done
   213 
   214 lemma sup_0_eq_0 [simp, no_atp]: "sup a (- a) = 0 \<longleftrightarrow> a = 0"
   215   apply rule
   216   apply (erule sup_0_imp_0)
   217   apply simp
   218   done
   219 
   220 lemma zero_le_double_add_iff_zero_le_single_add [simp]: "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
   221   (is "?lhs \<longleftrightarrow> ?rhs")
   222 proof
   223   show ?rhs if ?lhs
   224   proof -
   225     from that have a: "inf (a + a) 0 = 0"
   226       by (simp add: inf_commute inf_absorb1)
   227     have "inf a 0 + inf a 0 = inf (inf (a + a) 0) a"  (is "?l = _")
   228       by (simp add: add_sup_inf_distribs inf_aci)
   229     then have "?l = 0 + inf a 0"
   230       by (simp add: a, simp add: inf_commute)
   231     then have "inf a 0 = 0"
   232       by (simp only: add_right_cancel)
   233     then show ?thesis
   234       unfolding le_iff_inf by (simp add: inf_commute)
   235   qed
   236   show ?lhs if ?rhs
   237     by (simp add: add_mono[OF that that, simplified])
   238 qed
   239 
   240 lemma double_zero [simp]: "a + a = 0 \<longleftrightarrow> a = 0"
   241   (is "?lhs \<longleftrightarrow> ?rhs")
   242 proof
   243   show ?rhs if ?lhs
   244   proof -
   245     from that have "a + a + - a = - a"
   246       by simp
   247     then have "a + (a + - a) = - a"
   248       by (simp only: add.assoc)
   249     then have a: "- a = a"
   250       by simp
   251     show ?thesis
   252       apply (rule antisym)
   253       apply (unfold neg_le_iff_le [symmetric, of a])
   254       unfolding a
   255       apply simp
   256       unfolding zero_le_double_add_iff_zero_le_single_add [symmetric, of a]
   257       unfolding that
   258       unfolding le_less
   259       apply simp_all
   260       done
   261   qed
   262   show ?lhs if ?rhs
   263     using that by simp
   264 qed
   265 
   266 lemma zero_less_double_add_iff_zero_less_single_add [simp]: "0 < a + a \<longleftrightarrow> 0 < a"
   267 proof (cases "a = 0")
   268   case True
   269   then show ?thesis by auto
   270 next
   271   case False
   272   then show ?thesis
   273     unfolding less_le
   274     apply simp
   275     apply rule
   276     apply clarify
   277     apply rule
   278     apply assumption
   279     apply (rule notI)
   280     unfolding double_zero [symmetric, of a]
   281     apply blast
   282     done
   283 qed
   284 
   285 lemma double_add_le_zero_iff_single_add_le_zero [simp]: "a + a \<le> 0 \<longleftrightarrow> a \<le> 0"
   286 proof -
   287   have "a + a \<le> 0 \<longleftrightarrow> 0 \<le> - (a + a)"
   288     by (subst le_minus_iff) simp
   289   moreover have "\<dots> \<longleftrightarrow> a \<le> 0"
   290     by (simp only: minus_add_distrib zero_le_double_add_iff_zero_le_single_add) simp
   291   ultimately show ?thesis
   292     by blast
   293 qed
   294 
   295 lemma double_add_less_zero_iff_single_less_zero [simp]: "a + a < 0 \<longleftrightarrow> a < 0"
   296 proof -
   297   have "a + a < 0 \<longleftrightarrow> 0 < - (a + a)"
   298     by (subst less_minus_iff) simp
   299   moreover have "\<dots> \<longleftrightarrow> a < 0"
   300     by (simp only: minus_add_distrib zero_less_double_add_iff_zero_less_single_add) simp
   301   ultimately show ?thesis
   302     by blast
   303 qed
   304 
   305 declare neg_inf_eq_sup [simp] neg_sup_eq_inf [simp] diff_inf_eq_sup [simp] diff_sup_eq_inf [simp]
   306 
   307 lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
   308 proof -
   309   from add_le_cancel_left [of "uminus a" "plus a a" zero]
   310   have "a \<le> - a \<longleftrightarrow> a + a \<le> 0"
   311     by (simp add: add.assoc[symmetric])
   312   then show ?thesis
   313     by simp
   314 qed
   315 
   316 lemma minus_le_self_iff: "- a \<le> a \<longleftrightarrow> 0 \<le> a"
   317 proof -
   318   have "- a \<le> a \<longleftrightarrow> 0 \<le> a + a"
   319     using add_le_cancel_left [of "uminus a" zero "plus a a"]
   320     by (simp add: add.assoc[symmetric])
   321   then show ?thesis
   322     by simp
   323 qed
   324 
   325 lemma zero_le_iff_zero_nprt: "0 \<le> a \<longleftrightarrow> nprt a = 0"
   326   unfolding le_iff_inf by (simp add: nprt_def inf_commute)
   327 
   328 lemma le_zero_iff_zero_pprt: "a \<le> 0 \<longleftrightarrow> pprt a = 0"
   329   unfolding le_iff_sup by (simp add: pprt_def sup_commute)
   330 
   331 lemma le_zero_iff_pprt_id: "0 \<le> a \<longleftrightarrow> pprt a = a"
   332   unfolding le_iff_sup by (simp add: pprt_def sup_commute)
   333 
   334 lemma zero_le_iff_nprt_id: "a \<le> 0 \<longleftrightarrow> nprt a = a"
   335   unfolding le_iff_inf by (simp add: nprt_def inf_commute)
   336 
   337 lemma pprt_mono [simp, no_atp]: "a \<le> b \<Longrightarrow> pprt a \<le> pprt b"
   338   unfolding le_iff_sup by (simp add: pprt_def sup_aci sup_assoc [symmetric, of a])
   339 
   340 lemma nprt_mono [simp, no_atp]: "a \<le> b \<Longrightarrow> nprt a \<le> nprt b"
   341   unfolding le_iff_inf by (simp add: nprt_def inf_aci inf_assoc [symmetric, of a])
   342 
   343 end
   344 
   345 lemmas add_sup_inf_distribs =
   346   add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
   347 
   348 
   349 class lattice_ab_group_add_abs = lattice_ab_group_add + abs +
   350   assumes abs_lattice: "\<bar>a\<bar> = sup a (- a)"
   351 begin
   352 
   353 lemma abs_prts: "\<bar>a\<bar> = pprt a - nprt a"
   354 proof -
   355   have "0 \<le> \<bar>a\<bar>"
   356   proof -
   357     have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>"
   358       by (auto simp add: abs_lattice)
   359     show ?thesis
   360       by (rule add_mono [OF a b, simplified])
   361   qed
   362   then have "0 \<le> sup a (- a)"
   363     unfolding abs_lattice .
   364   then have "sup (sup a (- a)) 0 = sup a (- a)"
   365     by (rule sup_absorb1)
   366   then show ?thesis
   367     by (simp add: add_sup_inf_distribs ac_simps pprt_def nprt_def abs_lattice)
   368 qed
   369 
   370 subclass ordered_ab_group_add_abs
   371 proof
   372   have abs_ge_zero [simp]: "0 \<le> \<bar>a\<bar>" for a
   373   proof -
   374     have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>"
   375       by (auto simp add: abs_lattice)
   376     show "0 \<le> \<bar>a\<bar>"
   377       by (rule add_mono [OF a b, simplified])
   378   qed
   379   have abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b" for a b
   380     by (simp add: abs_lattice le_supI)
   381   fix a b
   382   show "0 \<le> \<bar>a\<bar>"
   383     by simp
   384   show "a \<le> \<bar>a\<bar>"
   385     by (auto simp add: abs_lattice)
   386   show "\<bar>-a\<bar> = \<bar>a\<bar>"
   387     by (simp add: abs_lattice sup_commute)
   388   show "- a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b" if "a \<le> b"
   389     using that by (rule abs_leI)
   390   show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
   391   proof -
   392     have g: "\<bar>a\<bar> + \<bar>b\<bar> = sup (a + b) (sup (- a - b) (sup (- a + b) (a + (- b))))"
   393       (is "_ = sup ?m ?n")
   394       by (simp add: abs_lattice add_sup_inf_distribs ac_simps)
   395     have a: "a + b \<le> sup ?m ?n"
   396       by simp
   397     have b: "- a - b \<le> ?n"
   398       by simp
   399     have c: "?n \<le> sup ?m ?n"
   400       by simp
   401     from b c have d: "- a - b \<le> sup ?m ?n"
   402       by (rule order_trans)
   403     have e: "- a - b = - (a + b)"
   404       by simp
   405     from a d e have "\<bar>a + b\<bar> \<le> sup ?m ?n"
   406       apply -
   407       apply (drule abs_leI)
   408       apply (simp_all only: algebra_simps minus_add)
   409       apply (metis add_uminus_conv_diff d sup_commute uminus_add_conv_diff)
   410       done
   411     with g[symmetric] show ?thesis by simp
   412   qed
   413 qed
   414 
   415 end
   416 
   417 lemma sup_eq_if:
   418   fixes a :: "'a::{lattice_ab_group_add,linorder}"
   419   shows "sup a (- a) = (if a < 0 then - a else a)"
   420   using add_le_cancel_right [of a a "- a", symmetric, simplified]
   421     and add_le_cancel_right [of "-a" a a, symmetric, simplified]
   422   by (auto simp: sup_max max.absorb1 max.absorb2)
   423 
   424 lemma abs_if_lattice:
   425   fixes a :: "'a::{lattice_ab_group_add_abs,linorder}"
   426   shows "\<bar>a\<bar> = (if a < 0 then - a else a)"
   427   by auto
   428 
   429 lemma estimate_by_abs:
   430   fixes a b c :: "'a::lattice_ab_group_add_abs"
   431   assumes "a + b \<le> c"
   432   shows "a \<le> c + \<bar>b\<bar>"
   433 proof -
   434   from assms have "a \<le> c + (- b)"
   435     by (simp add: algebra_simps)
   436   have "- b \<le> \<bar>b\<bar>"
   437     by (rule abs_ge_minus_self)
   438   then have "c + (- b) \<le> c + \<bar>b\<bar>"
   439     by (rule add_left_mono)
   440   with \<open>a \<le> c + (- b)\<close> show ?thesis
   441     by (rule order_trans)
   442 qed
   443 
   444 class lattice_ring = ordered_ring + lattice_ab_group_add_abs
   445 begin
   446 
   447 subclass semilattice_inf_ab_group_add ..
   448 subclass semilattice_sup_ab_group_add ..
   449 
   450 end
   451 
   452 lemma abs_le_mult:
   453   fixes a b :: "'a::lattice_ring"
   454   shows "\<bar>a * b\<bar> \<le> \<bar>a\<bar> * \<bar>b\<bar>"
   455 proof -
   456   let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
   457   let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
   458   have a: "\<bar>a\<bar> * \<bar>b\<bar> = ?x"
   459     by (simp only: abs_prts[of a] abs_prts[of b] algebra_simps)
   460   have bh: "u = a \<Longrightarrow> v = b \<Longrightarrow>
   461             u * v = pprt a * pprt b + pprt a * nprt b +
   462                     nprt a * pprt b + nprt a * nprt b" for u v :: 'a
   463     apply (subst prts[of u], subst prts[of v])
   464     apply (simp add: algebra_simps)
   465     done
   466   note b = this[OF refl[of a] refl[of b]]
   467   have xy: "- ?x \<le> ?y"
   468     apply simp
   469     apply (metis (full_types) add_increasing add_uminus_conv_diff
   470       lattice_ab_group_add_class.minus_le_self_iff minus_add_distrib mult_nonneg_nonneg
   471       mult_nonpos_nonpos nprt_le_zero zero_le_pprt)
   472     done
   473   have yx: "?y \<le> ?x"
   474     apply simp
   475     apply (metis (full_types) add_nonpos_nonpos add_uminus_conv_diff
   476       lattice_ab_group_add_class.le_minus_self_iff minus_add_distrib mult_nonneg_nonpos
   477       mult_nonpos_nonneg nprt_le_zero zero_le_pprt)
   478     done
   479   have i1: "a * b \<le> \<bar>a\<bar> * \<bar>b\<bar>"
   480     by (simp only: a b yx)
   481   have i2: "- (\<bar>a\<bar> * \<bar>b\<bar>) \<le> a * b"
   482     by (simp only: a b xy)
   483   show ?thesis
   484     apply (rule abs_leI)
   485     apply (simp add: i1)
   486     apply (simp add: i2[simplified minus_le_iff])
   487     done
   488 qed
   489 
   490 instance lattice_ring \<subseteq> ordered_ring_abs
   491 proof
   492   fix a b :: "'a::lattice_ring"
   493   assume a: "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
   494   show "\<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
   495   proof -
   496     have s: "(0 \<le> a * b) \<or> (a * b \<le> 0)"
   497       apply auto
   498       apply (rule_tac split_mult_pos_le)
   499       apply (rule_tac contrapos_np[of "a * b \<le> 0"])
   500       apply simp
   501       apply (rule_tac split_mult_neg_le)
   502       using a
   503       apply blast
   504       done
   505     have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
   506       by (simp add: prts[symmetric])
   507     show ?thesis
   508     proof (cases "0 \<le> a * b")
   509       case True
   510       then show ?thesis
   511         apply (simp_all add: mulprts abs_prts)
   512         using a
   513         apply (auto simp add:
   514           algebra_simps
   515           iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_zero_pprt]
   516           iffD1[OF le_zero_iff_pprt_id] iffD1[OF zero_le_iff_nprt_id])
   517         apply(drule (1) mult_nonneg_nonpos[of a b], simp)
   518         apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
   519         done
   520     next
   521       case False
   522       with s have "a * b \<le> 0"
   523         by simp
   524       then show ?thesis
   525         apply (simp_all add: mulprts abs_prts)
   526         apply (insert a)
   527         apply (auto simp add: algebra_simps)
   528         apply(drule (1) mult_nonneg_nonneg[of a b],simp)
   529         apply(drule (1) mult_nonpos_nonpos[of a b],simp)
   530         done
   531     qed
   532   qed
   533 qed
   534 
   535 lemma mult_le_prts:
   536   fixes a b :: "'a::lattice_ring"
   537   assumes "a1 \<le> a"
   538     and "a \<le> a2"
   539     and "b1 \<le> b"
   540     and "b \<le> b2"
   541   shows "a * b \<le>
   542     pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
   543 proof -
   544   have "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
   545     by (subst prts[symmetric])+ simp
   546   then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
   547     by (simp add: algebra_simps)
   548   moreover have "pprt a * pprt b \<le> pprt a2 * pprt b2"
   549     by (simp_all add: assms mult_mono)
   550   moreover have "pprt a * nprt b \<le> pprt a1 * nprt b2"
   551   proof -
   552     have "pprt a * nprt b \<le> pprt a * nprt b2"
   553       by (simp add: mult_left_mono assms)
   554     moreover have "pprt a * nprt b2 \<le> pprt a1 * nprt b2"
   555       by (simp add: mult_right_mono_neg assms)
   556     ultimately show ?thesis
   557       by simp
   558   qed
   559   moreover have "nprt a * pprt b \<le> nprt a2 * pprt b1"
   560   proof -
   561     have "nprt a * pprt b \<le> nprt a2 * pprt b"
   562       by (simp add: mult_right_mono assms)
   563     moreover have "nprt a2 * pprt b \<le> nprt a2 * pprt b1"
   564       by (simp add: mult_left_mono_neg assms)
   565     ultimately show ?thesis
   566       by simp
   567   qed
   568   moreover have "nprt a * nprt b \<le> nprt a1 * nprt b1"
   569   proof -
   570     have "nprt a * nprt b \<le> nprt a * nprt b1"
   571       by (simp add: mult_left_mono_neg assms)
   572     moreover have "nprt a * nprt b1 \<le> nprt a1 * nprt b1"
   573       by (simp add: mult_right_mono_neg assms)
   574     ultimately show ?thesis
   575       by simp
   576   qed
   577   ultimately show ?thesis
   578     by - (rule add_mono | simp)+
   579 qed
   580 
   581 lemma mult_ge_prts:
   582   fixes a b :: "'a::lattice_ring"
   583   assumes "a1 \<le> a"
   584     and "a \<le> a2"
   585     and "b1 \<le> b"
   586     and "b \<le> b2"
   587   shows "a * b \<ge>
   588     nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
   589 proof -
   590   from assms have a1: "- a2 \<le> -a"
   591     by auto
   592   from assms have a2: "- a \<le> -a1"
   593     by auto
   594   from mult_le_prts[of "- a2" "- a" "- a1" "b1" b "b2",
   595     OF a1 a2 assms(3) assms(4), simplified nprt_neg pprt_neg]
   596   have le: "- (a * b) \<le>
   597     - nprt a1 * pprt b2 + - nprt a2 * nprt b2 +
   598     - pprt a1 * pprt b1 + - pprt a2 * nprt b1"
   599     by simp
   600   then have "- (- nprt a1 * pprt b2 + - nprt a2 * nprt b2 +
   601       - pprt a1 * pprt b1 + - pprt a2 * nprt b1) \<le> a * b"
   602     by (simp only: minus_le_iff)
   603   then show ?thesis
   604     by (simp add: algebra_simps)
   605 qed
   606 
   607 instance int :: lattice_ring
   608 proof
   609   fix k :: int
   610   show "\<bar>k\<bar> = sup k (- k)"
   611     by (auto simp add: sup_int_def)
   612 qed
   613 
   614 instance real :: lattice_ring
   615 proof
   616   fix a :: real
   617   show "\<bar>a\<bar> = sup a (- a)"
   618     by (auto simp add: sup_real_def)
   619 qed
   620 
   621 end