src/HOL/Library/Lattice_Algebras.thy
author wenzelm
Tue Aug 05 12:56:15 2014 +0200 (2014-08-05)
changeset 57862 8f074e6e22fc
parent 57512 cc97b347b301
child 58881 b9556a055632
permissions -rw-r--r--
tuned proofs;
     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   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 {* Positive Part, Negative Part, Absolute Value *}
   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" (is "?l = ?r")
   149 proof
   150   assume ?l
   151   then show ?r
   152     apply -
   153     apply (rule add_le_imp_le_right[of _ "uminus b" _])
   154     apply (simp add: add.assoc)
   155     done
   156 next
   157   assume ?r
   158   then show ?l
   159     apply -
   160     apply (rule add_le_imp_le_right[of _ "b" _])
   161     apply simp
   162     done
   163 qed
   164 
   165 lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
   166 lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
   167 
   168 lemma pprt_eq_id [simp, no_atp]: "0 \<le> x \<Longrightarrow> pprt x = x"
   169   by (simp add: pprt_def sup_absorb1)
   170 
   171 lemma nprt_eq_id [simp, no_atp]: "x \<le> 0 \<Longrightarrow> nprt x = x"
   172   by (simp add: nprt_def inf_absorb1)
   173 
   174 lemma pprt_eq_0 [simp, no_atp]: "x \<le> 0 \<Longrightarrow> pprt x = 0"
   175   by (simp add: pprt_def sup_absorb2)
   176 
   177 lemma nprt_eq_0 [simp, no_atp]: "0 \<le> x \<Longrightarrow> nprt x = 0"
   178   by (simp add: nprt_def inf_absorb2)
   179 
   180 lemma sup_0_imp_0: "sup a (- a) = 0 \<Longrightarrow> a = 0"
   181 proof -
   182   {
   183     fix a :: 'a
   184     assume hyp: "sup a (- a) = 0"
   185     then have "sup a (- a) + a = a"
   186       by simp
   187     then have "sup (a + a) 0 = a"
   188       by (simp add: add_sup_distrib_right)
   189     then have "sup (a + a) 0 \<le> a"
   190       by simp
   191     then have "0 \<le> a"
   192       by (blast intro: order_trans inf_sup_ord)
   193   }
   194   note p = this
   195   assume hyp:"sup a (-a) = 0"
   196   then have hyp2:"sup (-a) (-(-a)) = 0"
   197     by (simp add: sup_commute)
   198   from p[OF hyp] p[OF hyp2] 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]:
   221   "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
   222 proof
   223   assume "0 \<le> a + a"
   224   then have a: "inf (a + a) 0 = 0"
   225     by (simp add: inf_commute inf_absorb1)
   226   have "inf a 0 + inf a 0 = inf (inf (a + a) 0) a"  (is "?l=_")
   227     by (simp add: add_sup_inf_distribs inf_aci)
   228   then have "?l = 0 + inf a 0"
   229     by (simp add: a, simp add: inf_commute)
   230   then have "inf a 0 = 0"
   231     by (simp only: add_right_cancel)
   232   then show "0 \<le> a"
   233     unfolding le_iff_inf by (simp add: inf_commute)
   234 next
   235   assume a: "0 \<le> a"
   236   show "0 \<le> a + a"
   237     by (simp add: add_mono[OF a a, simplified])
   238 qed
   239 
   240 lemma double_zero [simp]: "a + a = 0 \<longleftrightarrow> a = 0"
   241 proof
   242   assume assm: "a + a = 0"
   243   then have "a + a + - a = - a"
   244     by simp
   245   then have "a + (a + - a) = - a"
   246     by (simp only: add.assoc)
   247   then have a: "- a = a"
   248     by simp
   249   show "a = 0"
   250     apply (rule antisym)
   251     apply (unfold neg_le_iff_le [symmetric, of a])
   252     unfolding a
   253     apply simp
   254     unfolding zero_le_double_add_iff_zero_le_single_add [symmetric, of a]
   255     unfolding assm
   256     unfolding le_less
   257     apply simp_all
   258     done
   259 next
   260   assume "a = 0"
   261   then show "a + a = 0"
   262     by simp
   263 qed
   264 
   265 lemma zero_less_double_add_iff_zero_less_single_add [simp]: "0 < a + a \<longleftrightarrow> 0 < a"
   266 proof (cases "a = 0")
   267   case True
   268   then show ?thesis by auto
   269 next
   270   case False
   271   then show ?thesis
   272     unfolding less_le
   273     apply simp
   274     apply rule
   275     apply clarify
   276     apply rule
   277     apply assumption
   278     apply (rule notI)
   279     unfolding double_zero [symmetric, of a]
   280     apply blast
   281     done
   282 qed
   283 
   284 lemma double_add_le_zero_iff_single_add_le_zero [simp]:
   285   "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]:
   296   "a + a < 0 \<longleftrightarrow> a < 0"
   297 proof -
   298   have "a + a < 0 \<longleftrightarrow> 0 < - (a + a)"
   299     by (subst less_minus_iff) simp
   300   moreover have "\<dots> \<longleftrightarrow> a < 0"
   301     by (simp only: minus_add_distrib zero_less_double_add_iff_zero_less_single_add) simp
   302   ultimately show ?thesis
   303     by blast
   304 qed
   305 
   306 declare neg_inf_eq_sup [simp] neg_sup_eq_inf [simp] diff_inf_eq_sup [simp] diff_sup_eq_inf [simp]
   307 
   308 lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
   309 proof -
   310   from add_le_cancel_left [of "uminus a" "plus a a" zero]
   311   have "a \<le> - a \<longleftrightarrow> a + a \<le> 0"
   312     by (simp add: add.assoc[symmetric])
   313   then show ?thesis
   314     by simp
   315 qed
   316 
   317 lemma minus_le_self_iff: "- a \<le> a \<longleftrightarrow> 0 \<le> a"
   318 proof -
   319   from add_le_cancel_left [of "uminus a" zero "plus a a"]
   320   have "- a \<le> a \<longleftrightarrow> 0 \<le> a + a"
   321     by (simp add: add.assoc[symmetric])
   322   then show ?thesis
   323     by simp
   324 qed
   325 
   326 lemma zero_le_iff_zero_nprt: "0 \<le> a \<longleftrightarrow> nprt a = 0"
   327   unfolding le_iff_inf by (simp add: nprt_def inf_commute)
   328 
   329 lemma le_zero_iff_zero_pprt: "a \<le> 0 \<longleftrightarrow> pprt a = 0"
   330   unfolding le_iff_sup by (simp add: pprt_def sup_commute)
   331 
   332 lemma le_zero_iff_pprt_id: "0 \<le> a \<longleftrightarrow> pprt a = a"
   333   unfolding le_iff_sup by (simp add: pprt_def sup_commute)
   334 
   335 lemma zero_le_iff_nprt_id: "a \<le> 0 \<longleftrightarrow> nprt a = a"
   336   unfolding le_iff_inf by (simp add: nprt_def inf_commute)
   337 
   338 lemma pprt_mono [simp, no_atp]: "a \<le> b \<Longrightarrow> pprt a \<le> pprt b"
   339   unfolding le_iff_sup by (simp add: pprt_def sup_aci sup_assoc [symmetric, of a])
   340 
   341 lemma nprt_mono [simp, no_atp]: "a \<le> b \<Longrightarrow> nprt a \<le> nprt b"
   342   unfolding le_iff_inf by (simp add: nprt_def inf_aci inf_assoc [symmetric, of a])
   343 
   344 end
   345 
   346 lemmas add_sup_inf_distribs =
   347   add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
   348 
   349 
   350 class lattice_ab_group_add_abs = lattice_ab_group_add + abs +
   351   assumes abs_lattice: "\<bar>a\<bar> = sup a (- a)"
   352 begin
   353 
   354 lemma abs_prts: "\<bar>a\<bar> = pprt a - nprt a"
   355 proof -
   356   have "0 \<le> \<bar>a\<bar>"
   357   proof -
   358     have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>"
   359       by (auto simp add: abs_lattice)
   360     show ?thesis
   361       by (rule add_mono [OF a b, simplified])
   362   qed
   363   then have "0 \<le> sup a (- a)"
   364     unfolding abs_lattice .
   365   then have "sup (sup a (- a)) 0 = sup a (- a)"
   366     by (rule sup_absorb1)
   367   then show ?thesis
   368     by (simp add: add_sup_inf_distribs ac_simps pprt_def nprt_def abs_lattice)
   369 qed
   370 
   371 subclass ordered_ab_group_add_abs
   372 proof
   373   have abs_ge_zero [simp]: "\<And>a. 0 \<le> \<bar>a\<bar>"
   374   proof -
   375     fix a b
   376     have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>"
   377       by (auto simp add: abs_lattice)
   378     show "0 \<le> \<bar>a\<bar>"
   379       by (rule add_mono [OF a b, simplified])
   380   qed
   381   have abs_leI: "\<And>a b. a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
   382     by (simp add: abs_lattice le_supI)
   383   fix a b
   384   show "0 \<le> \<bar>a\<bar>"
   385     by simp
   386   show "a \<le> \<bar>a\<bar>"
   387     by (auto simp add: abs_lattice)
   388   show "\<bar>-a\<bar> = \<bar>a\<bar>"
   389     by (simp add: abs_lattice sup_commute)
   390   {
   391     assume "a \<le> b"
   392     then show "- a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
   393       by (rule abs_leI)
   394   }
   395   show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
   396   proof -
   397     have g: "\<bar>a\<bar> + \<bar>b\<bar> = sup (a + b) (sup (- a - b) (sup (- a + b) (a + (- b))))"
   398       (is "_=sup ?m ?n")
   399       by (simp add: abs_lattice add_sup_inf_distribs ac_simps)
   400     have a: "a + b \<le> sup ?m ?n"
   401       by simp
   402     have b: "- a - b \<le> ?n"
   403       by simp
   404     have c: "?n \<le> sup ?m ?n"
   405       by simp
   406     from b c have d: "- a - b \<le> sup ?m ?n"
   407       by (rule order_trans)
   408     have e: "- a - b = - (a + b)"
   409       by simp
   410     from a d e have "\<bar>a + b\<bar> \<le> sup ?m ?n"
   411       apply -
   412       apply (drule abs_leI)
   413       apply (simp_all only: algebra_simps minus_add)
   414       apply (metis add_uminus_conv_diff d sup_commute uminus_add_conv_diff)
   415       done
   416     with g[symmetric] show ?thesis by simp
   417   qed
   418 qed
   419 
   420 end
   421 
   422 lemma sup_eq_if:
   423   fixes a :: "'a::{lattice_ab_group_add, linorder}"
   424   shows "sup a (- a) = (if a < 0 then - a else a)"
   425 proof -
   426   note add_le_cancel_right [of a a "- a", symmetric, simplified]
   427   moreover note add_le_cancel_right [of "-a" a a, symmetric, simplified]
   428   then show ?thesis by (auto simp: sup_max max.absorb1 max.absorb2)
   429 qed
   430 
   431 lemma abs_if_lattice:
   432   fixes a :: "'a::{lattice_ab_group_add_abs, linorder}"
   433   shows "\<bar>a\<bar> = (if a < 0 then - a else a)"
   434   by auto
   435 
   436 lemma estimate_by_abs:
   437   fixes a b c :: "'a::lattice_ab_group_add_abs"
   438   shows "a + b \<le> c \<Longrightarrow> a \<le> c + \<bar>b\<bar>"
   439 proof -
   440   assume "a + b \<le> c"
   441   then have "a \<le> c + (- b)"
   442     by (simp add: algebra_simps)
   443   have "- b \<le> \<bar>b\<bar>"
   444     by (rule abs_ge_minus_self)
   445   then have "c + (- b) \<le> c + \<bar>b\<bar>"
   446     by (rule add_left_mono)
   447   with `a \<le> c + (- b)` show ?thesis
   448     by (rule order_trans)
   449 qed
   450 
   451 class lattice_ring = ordered_ring + lattice_ab_group_add_abs
   452 begin
   453 
   454 subclass semilattice_inf_ab_group_add ..
   455 subclass semilattice_sup_ab_group_add ..
   456 
   457 end
   458 
   459 lemma abs_le_mult:
   460   fixes a b :: "'a::lattice_ring"
   461   shows "\<bar>a * b\<bar> \<le> \<bar>a\<bar> * \<bar>b\<bar>"
   462 proof -
   463   let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
   464   let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
   465   have a: "\<bar>a\<bar> * \<bar>b\<bar> = ?x"
   466     by (simp only: abs_prts[of a] abs_prts[of b] algebra_simps)
   467   {
   468     fix u v :: 'a
   469     have bh: "u = a \<Longrightarrow> v = b \<Longrightarrow>
   470               u * v = pprt a * pprt b + pprt a * nprt b +
   471                       nprt a * pprt b + nprt a * nprt b"
   472       apply (subst prts[of u], subst prts[of v])
   473       apply (simp add: algebra_simps)
   474       done
   475   }
   476   note b = this[OF refl[of a] refl[of b]]
   477   have xy: "- ?x \<le> ?y"
   478     apply simp
   479     apply (metis (full_types) add_increasing add_uminus_conv_diff
   480       lattice_ab_group_add_class.minus_le_self_iff minus_add_distrib mult_nonneg_nonneg
   481       mult_nonpos_nonpos nprt_le_zero zero_le_pprt)
   482     done
   483   have yx: "?y \<le> ?x"
   484     apply simp
   485     apply (metis (full_types) add_nonpos_nonpos add_uminus_conv_diff
   486       lattice_ab_group_add_class.le_minus_self_iff minus_add_distrib mult_nonneg_nonpos
   487       mult_nonpos_nonneg nprt_le_zero zero_le_pprt)
   488     done
   489   have i1: "a * b \<le> \<bar>a\<bar> * \<bar>b\<bar>"
   490     by (simp only: a b yx)
   491   have i2: "- (\<bar>a\<bar> * \<bar>b\<bar>) \<le> a * b"
   492     by (simp only: a b xy)
   493   show ?thesis
   494     apply (rule abs_leI)
   495     apply (simp add: i1)
   496     apply (simp add: i2[simplified minus_le_iff])
   497     done
   498 qed
   499 
   500 instance lattice_ring \<subseteq> ordered_ring_abs
   501 proof
   502   fix a b :: "'a::lattice_ring"
   503   assume a: "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
   504   show "\<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
   505   proof -
   506     have s: "(0 \<le> a * b) \<or> (a * b \<le> 0)"
   507       apply auto
   508       apply (rule_tac split_mult_pos_le)
   509       apply (rule_tac contrapos_np[of "a * b \<le> 0"])
   510       apply simp
   511       apply (rule_tac split_mult_neg_le)
   512       using a
   513       apply blast
   514       done
   515     have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
   516       by (simp add: prts[symmetric])
   517     show ?thesis
   518     proof (cases "0 \<le> a * b")
   519       case True
   520       then show ?thesis
   521         apply (simp_all add: mulprts abs_prts)
   522         using a
   523         apply (auto simp add:
   524           algebra_simps
   525           iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_zero_pprt]
   526           iffD1[OF le_zero_iff_pprt_id] iffD1[OF zero_le_iff_nprt_id])
   527         apply(drule (1) mult_nonneg_nonpos[of a b], simp)
   528         apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
   529         done
   530     next
   531       case False
   532       with s have "a * b \<le> 0"
   533         by simp
   534       then show ?thesis
   535         apply (simp_all add: mulprts abs_prts)
   536         apply (insert a)
   537         apply (auto simp add: algebra_simps)
   538         apply(drule (1) mult_nonneg_nonneg[of a b],simp)
   539         apply(drule (1) mult_nonpos_nonpos[of a b],simp)
   540         done
   541     qed
   542   qed
   543 qed
   544 
   545 lemma mult_le_prts:
   546   fixes a b :: "'a::lattice_ring"
   547   assumes "a1 \<le> a"
   548     and "a \<le> a2"
   549     and "b1 \<le> b"
   550     and "b \<le> b2"
   551   shows "a * b \<le>
   552     pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
   553 proof -
   554   have "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
   555     apply (subst prts[symmetric])+
   556     apply simp
   557     done
   558   then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
   559     by (simp add: algebra_simps)
   560   moreover have "pprt a * pprt b \<le> pprt a2 * pprt b2"
   561     by (simp_all add: assms mult_mono)
   562   moreover have "pprt a * nprt b \<le> pprt a1 * nprt b2"
   563   proof -
   564     have "pprt a * nprt b \<le> pprt a * nprt b2"
   565       by (simp add: mult_left_mono assms)
   566     moreover have "pprt a * nprt b2 \<le> pprt a1 * nprt b2"
   567       by (simp add: mult_right_mono_neg assms)
   568     ultimately show ?thesis
   569       by simp
   570   qed
   571   moreover have "nprt a * pprt b \<le> nprt a2 * pprt b1"
   572   proof -
   573     have "nprt a * pprt b \<le> nprt a2 * pprt b"
   574       by (simp add: mult_right_mono assms)
   575     moreover have "nprt a2 * pprt b \<le> nprt a2 * pprt b1"
   576       by (simp add: mult_left_mono_neg assms)
   577     ultimately show ?thesis
   578       by simp
   579   qed
   580   moreover have "nprt a * nprt b \<le> nprt a1 * nprt b1"
   581   proof -
   582     have "nprt a * nprt b \<le> nprt a * nprt b1"
   583       by (simp add: mult_left_mono_neg assms)
   584     moreover have "nprt a * nprt b1 \<le> nprt a1 * nprt b1"
   585       by (simp add: mult_right_mono_neg assms)
   586     ultimately show ?thesis
   587       by simp
   588   qed
   589   ultimately show ?thesis
   590     apply -
   591     apply (rule add_mono | simp)+
   592     done
   593 qed
   594 
   595 lemma mult_ge_prts:
   596   fixes a b :: "'a::lattice_ring"
   597   assumes "a1 \<le> a"
   598     and "a \<le> a2"
   599     and "b1 \<le> b"
   600     and "b \<le> b2"
   601   shows "a * b \<ge>
   602     nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
   603 proof -
   604   from assms have a1: "- a2 \<le> -a"
   605     by auto
   606   from assms have a2: "- a \<le> -a1"
   607     by auto
   608   from mult_le_prts[of "- a2" "- a" "- a1" "b1" b "b2",
   609     OF a1 a2 assms(3) assms(4), simplified nprt_neg pprt_neg]
   610   have le: "- (a * b) \<le> - nprt a1 * pprt b2 + - nprt a2 * nprt b2 +
   611     - pprt a1 * pprt b1 + - pprt a2 * nprt b1"
   612     by simp
   613   then have "- (- nprt a1 * pprt b2 + - nprt a2 * nprt b2 +
   614       - pprt a1 * pprt b1 + - pprt a2 * nprt b1) \<le> a * b"
   615     by (simp only: minus_le_iff)
   616   then show ?thesis
   617     by (simp add: algebra_simps)
   618 qed
   619 
   620 instance int :: lattice_ring
   621 proof
   622   fix k :: int
   623   show "\<bar>k\<bar> = sup k (- k)"
   624     by (auto simp add: sup_int_def)
   625 qed
   626 
   627 instance real :: lattice_ring
   628 proof
   629   fix a :: real
   630   show "\<bar>a\<bar> = sup a (- a)"
   631     by (auto simp add: sup_real_def)
   632 qed
   633 
   634 end
   635