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