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