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