src/HOL/Library/Lattice_Algebras.thy
 author haftmann Mon Feb 08 15:25:00 2010 +0100 (2010-02-08) changeset 35040 e42e7f133d94 child 35828 46cfc4b8112e permissions -rw-r--r--
separate library theory for type classes combining lattices with various algebraic structures; c.f. cs. 7efe662e41b4
```     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, noatp]: "0 \<le> x \<Longrightarrow> pprt x = x"
```
```   167   by (simp add: pprt_def sup_aci sup_absorb1)
```
```   168
```
```   169 lemma nprt_eq_id [simp, noatp]: "x \<le> 0 \<Longrightarrow> nprt x = x"
```
```   170   by (simp add: nprt_def inf_aci inf_absorb1)
```
```   171
```
```   172 lemma pprt_eq_0 [simp, noatp]: "x \<le> 0 \<Longrightarrow> pprt x = 0"
```
```   173   by (simp add: pprt_def sup_aci sup_absorb2)
```
```   174
```
```   175 lemma nprt_eq_0 [simp, noatp]: "0 \<le> x \<Longrightarrow> nprt x = 0"
```
```   176   by (simp add: nprt_def inf_aci 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, noatp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
```
```   201 by (rule, erule inf_0_imp_0) simp
```
```   202
```
```   203 lemma sup_0_eq_0 [simp, noatp]: "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 add: zero_le_double_add_iff_zero_le_single_add)
```
```   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 add: zero_less_double_add_iff_zero_less_single_add)
```
```   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, noatp]: "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, noatp]: "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   hence 2: "a <= c+(-b)" by (simp add: algebra_simps)
```
```   380   have 3: "(-b) <= abs b" by (rule abs_ge_minus_self)
```
```   381   show ?thesis by (rule le_add_right_mono[OF 2 3])
```
```   382 qed
```
```   383
```
```   384 class lattice_ring = ordered_ring + lattice_ab_group_add_abs
```
```   385 begin
```
```   386
```
```   387 subclass semilattice_inf_ab_group_add ..
```
```   388 subclass semilattice_sup_ab_group_add ..
```
```   389
```
```   390 end
```
```   391
```
```   392 lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lattice_ring))"
```
```   393 proof -
```
```   394   let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
```
```   395   let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
```
```   396   have a: "(abs a) * (abs b) = ?x"
```
```   397     by (simp only: abs_prts[of a] abs_prts[of b] algebra_simps)
```
```   398   {
```
```   399     fix u v :: 'a
```
```   400     have bh: "\<lbrakk>u = a; v = b\<rbrakk> \<Longrightarrow>
```
```   401               u * v = pprt a * pprt b + pprt a * nprt b +
```
```   402                       nprt a * pprt b + nprt a * nprt b"
```
```   403       apply (subst prts[of u], subst prts[of v])
```
```   404       apply (simp add: algebra_simps)
```
```   405       done
```
```   406   }
```
```   407   note b = this[OF refl[of a] refl[of b]]
```
```   408   note addm = add_mono[of "0::'a" _ "0::'a", simplified]
```
```   409   note addm2 = add_mono[of _ "0::'a" _ "0::'a", simplified]
```
```   410   have xy: "- ?x <= ?y"
```
```   411     apply (simp)
```
```   412     apply (rule_tac y="0::'a" in order_trans)
```
```   413     apply (rule addm2)
```
```   414     apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
```
```   415     apply (rule addm)
```
```   416     apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
```
```   417     done
```
```   418   have yx: "?y <= ?x"
```
```   419     apply (simp add:diff_def)
```
```   420     apply (rule_tac y=0 in order_trans)
```
```   421     apply (rule addm2, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
```
```   422     apply (rule addm, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
```
```   423     done
```
```   424   have i1: "a*b <= abs a * abs b" by (simp only: a b yx)
```
```   425   have i2: "- (abs a * abs b) <= a*b" by (simp only: a b xy)
```
```   426   show ?thesis
```
```   427     apply (rule abs_leI)
```
```   428     apply (simp add: i1)
```
```   429     apply (simp add: i2[simplified minus_le_iff])
```
```   430     done
```
```   431 qed
```
```   432
```
```   433 instance lattice_ring \<subseteq> ordered_ring_abs
```
```   434 proof
```
```   435   fix a b :: "'a\<Colon> lattice_ring"
```
```   436   assume "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
```
```   437   show "abs (a*b) = abs a * abs b"
```
```   438   proof -
```
```   439     have s: "(0 <= a*b) | (a*b <= 0)"
```
```   440       apply (auto)
```
```   441       apply (rule_tac split_mult_pos_le)
```
```   442       apply (rule_tac contrapos_np[of "a*b <= 0"])
```
```   443       apply (simp)
```
```   444       apply (rule_tac split_mult_neg_le)
```
```   445       apply (insert prems)
```
```   446       apply (blast)
```
```   447       done
```
```   448     have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
```
```   449       by (simp add: prts[symmetric])
```
```   450     show ?thesis
```
```   451     proof cases
```
```   452       assume "0 <= a * b"
```
```   453       then show ?thesis
```
```   454         apply (simp_all add: mulprts abs_prts)
```
```   455         apply (insert prems)
```
```   456         apply (auto simp add:
```
```   457           algebra_simps
```
```   458           iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_zero_pprt]
```
```   459           iffD1[OF le_zero_iff_pprt_id] iffD1[OF zero_le_iff_nprt_id])
```
```   460           apply(drule (1) mult_nonneg_nonpos[of a b], simp)
```
```   461           apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
```
```   462         done
```
```   463     next
```
```   464       assume "~(0 <= a*b)"
```
```   465       with s have "a*b <= 0" by simp
```
```   466       then show ?thesis
```
```   467         apply (simp_all add: mulprts abs_prts)
```
```   468         apply (insert prems)
```
```   469         apply (auto simp add: algebra_simps)
```
```   470         apply(drule (1) mult_nonneg_nonneg[of a b],simp)
```
```   471         apply(drule (1) mult_nonpos_nonpos[of a b],simp)
```
```   472         done
```
```   473     qed
```
```   474   qed
```
```   475 qed
```
```   476
```
```   477 lemma mult_le_prts:
```
```   478   assumes
```
```   479   "a1 <= (a::'a::lattice_ring)"
```
```   480   "a <= a2"
```
```   481   "b1 <= b"
```
```   482   "b <= b2"
```
```   483   shows
```
```   484   "a * b <= pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
```
```   485 proof -
```
```   486   have "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
```
```   487     apply (subst prts[symmetric])+
```
```   488     apply simp
```
```   489     done
```
```   490   then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
```
```   491     by (simp add: algebra_simps)
```
```   492   moreover have "pprt a * pprt b <= pprt a2 * pprt b2"
```
```   493     by (simp_all add: prems mult_mono)
```
```   494   moreover have "pprt a * nprt b <= pprt a1 * nprt b2"
```
```   495   proof -
```
```   496     have "pprt a * nprt b <= pprt a * nprt b2"
```
```   497       by (simp add: mult_left_mono prems)
```
```   498     moreover have "pprt a * nprt b2 <= pprt a1 * nprt b2"
```
```   499       by (simp add: mult_right_mono_neg prems)
```
```   500     ultimately show ?thesis
```
```   501       by simp
```
```   502   qed
```
```   503   moreover have "nprt a * pprt b <= nprt a2 * pprt b1"
```
```   504   proof -
```
```   505     have "nprt a * pprt b <= nprt a2 * pprt b"
```
```   506       by (simp add: mult_right_mono prems)
```
```   507     moreover have "nprt a2 * pprt b <= nprt a2 * pprt b1"
```
```   508       by (simp add: mult_left_mono_neg prems)
```
```   509     ultimately show ?thesis
```
```   510       by simp
```
```   511   qed
```
```   512   moreover have "nprt a * nprt b <= nprt a1 * nprt b1"
```
```   513   proof -
```
```   514     have "nprt a * nprt b <= nprt a * nprt b1"
```
```   515       by (simp add: mult_left_mono_neg prems)
```
```   516     moreover have "nprt a * nprt b1 <= nprt a1 * nprt b1"
```
```   517       by (simp add: mult_right_mono_neg prems)
```
```   518     ultimately show ?thesis
```
```   519       by simp
```
```   520   qed
```
```   521   ultimately show ?thesis
```
```   522     by - (rule add_mono | simp)+
```
```   523 qed
```
```   524
```
```   525 lemma mult_ge_prts:
```
```   526   assumes
```
```   527   "a1 <= (a::'a::lattice_ring)"
```
```   528   "a <= a2"
```
```   529   "b1 <= b"
```
```   530   "b <= b2"
```
```   531   shows
```
```   532   "a * b >= nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
```
```   533 proof -
```
```   534   from prems have a1:"- a2 <= -a" by auto
```
```   535   from prems have a2: "-a <= -a1" by auto
```
```   536   from mult_le_prts[of "-a2" "-a" "-a1" "b1" b "b2", OF a1 a2 prems(3) prems(4), simplified nprt_neg pprt_neg]
```
```   537   have le: "- (a * b) <= - nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1" by simp
```
```   538   then have "-(- nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1) <= a * b"
```
```   539     by (simp only: minus_le_iff)
```
```   540   then show ?thesis by simp
```
```   541 qed
```
```   542
```
```   543 instance int :: lattice_ring
```
```   544 proof
```
```   545   fix k :: int
```
```   546   show "abs k = sup k (- k)"
```
```   547     by (auto simp add: sup_int_def)
```
```   548 qed
```
```   549
```
```   550 instance real :: lattice_ring
```
```   551 proof
```
```   552   fix a :: real
```
```   553   show "abs a = sup a (- a)"
```
```   554     by (auto simp add: sup_real_def)
```
```   555 qed
```
```   556
```
```   557 end
```