separate library theory for type classes combining lattices with various algebraic structures; c.f. cs. 7efe662e41b4
authorhaftmann
Mon Feb 08 15:25:00 2010 +0100 (2010-02-08)
changeset 35040e42e7f133d94
parent 35039 e682bb587071
child 35052 ca23d57b94ec
separate library theory for type classes combining lattices with various algebraic structures; c.f. cs. 7efe662e41b4
src/HOL/Library/Lattice_Algebras.thy
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Lattice_Algebras.thy	Mon Feb 08 15:25:00 2010 +0100
     1.3 @@ -0,0 +1,557 @@
     1.4 +(* Author: Steven Obua, TU Muenchen *)
     1.5 +
     1.6 +header {* Various algebraic structures combined with a lattice *}
     1.7 +
     1.8 +theory Lattice_Algebras
     1.9 +imports Complex_Main
    1.10 +begin
    1.11 +
    1.12 +class semilattice_inf_ab_group_add = ordered_ab_group_add + semilattice_inf
    1.13 +begin
    1.14 +
    1.15 +lemma add_inf_distrib_left:
    1.16 +  "a + inf b c = inf (a + b) (a + c)"
    1.17 +apply (rule antisym)
    1.18 +apply (simp_all add: le_infI)
    1.19 +apply (rule add_le_imp_le_left [of "uminus a"])
    1.20 +apply (simp only: add_assoc [symmetric], simp)
    1.21 +apply rule
    1.22 +apply (rule add_le_imp_le_left[of "a"], simp only: add_assoc[symmetric], simp)+
    1.23 +done
    1.24 +
    1.25 +lemma add_inf_distrib_right:
    1.26 +  "inf a b + c = inf (a + c) (b + c)"
    1.27 +proof -
    1.28 +  have "c + inf a b = inf (c+a) (c+b)" by (simp add: add_inf_distrib_left)
    1.29 +  thus ?thesis by (simp add: add_commute)
    1.30 +qed
    1.31 +
    1.32 +end
    1.33 +
    1.34 +class semilattice_sup_ab_group_add = ordered_ab_group_add + semilattice_sup
    1.35 +begin
    1.36 +
    1.37 +lemma add_sup_distrib_left:
    1.38 +  "a + sup b c = sup (a + b) (a + c)" 
    1.39 +apply (rule antisym)
    1.40 +apply (rule add_le_imp_le_left [of "uminus a"])
    1.41 +apply (simp only: add_assoc[symmetric], simp)
    1.42 +apply rule
    1.43 +apply (rule add_le_imp_le_left [of "a"], simp only: add_assoc[symmetric], simp)+
    1.44 +apply (rule le_supI)
    1.45 +apply (simp_all)
    1.46 +done
    1.47 +
    1.48 +lemma add_sup_distrib_right:
    1.49 +  "sup a b + c = sup (a+c) (b+c)"
    1.50 +proof -
    1.51 +  have "c + sup a b = sup (c+a) (c+b)" by (simp add: add_sup_distrib_left)
    1.52 +  thus ?thesis by (simp add: add_commute)
    1.53 +qed
    1.54 +
    1.55 +end
    1.56 +
    1.57 +class lattice_ab_group_add = ordered_ab_group_add + lattice
    1.58 +begin
    1.59 +
    1.60 +subclass semilattice_inf_ab_group_add ..
    1.61 +subclass semilattice_sup_ab_group_add ..
    1.62 +
    1.63 +lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
    1.64 +
    1.65 +lemma inf_eq_neg_sup: "inf a b = - sup (-a) (-b)"
    1.66 +proof (rule inf_unique)
    1.67 +  fix a b :: 'a
    1.68 +  show "- sup (-a) (-b) \<le> a"
    1.69 +    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
    1.70 +      (simp, simp add: add_sup_distrib_left)
    1.71 +next
    1.72 +  fix a b :: 'a
    1.73 +  show "- sup (-a) (-b) \<le> b"
    1.74 +    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
    1.75 +      (simp, simp add: add_sup_distrib_left)
    1.76 +next
    1.77 +  fix a b c :: 'a
    1.78 +  assume "a \<le> b" "a \<le> c"
    1.79 +  then show "a \<le> - sup (-b) (-c)" by (subst neg_le_iff_le [symmetric])
    1.80 +    (simp add: le_supI)
    1.81 +qed
    1.82 +  
    1.83 +lemma sup_eq_neg_inf: "sup a b = - inf (-a) (-b)"
    1.84 +proof (rule sup_unique)
    1.85 +  fix a b :: 'a
    1.86 +  show "a \<le> - inf (-a) (-b)"
    1.87 +    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    1.88 +      (simp, simp add: add_inf_distrib_left)
    1.89 +next
    1.90 +  fix a b :: 'a
    1.91 +  show "b \<le> - inf (-a) (-b)"
    1.92 +    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    1.93 +      (simp, simp add: add_inf_distrib_left)
    1.94 +next
    1.95 +  fix a b c :: 'a
    1.96 +  assume "a \<le> c" "b \<le> c"
    1.97 +  then show "- inf (-a) (-b) \<le> c" by (subst neg_le_iff_le [symmetric])
    1.98 +    (simp add: le_infI)
    1.99 +qed
   1.100 +
   1.101 +lemma neg_inf_eq_sup: "- inf a b = sup (-a) (-b)"
   1.102 +by (simp add: inf_eq_neg_sup)
   1.103 +
   1.104 +lemma neg_sup_eq_inf: "- sup a b = inf (-a) (-b)"
   1.105 +by (simp add: sup_eq_neg_inf)
   1.106 +
   1.107 +lemma add_eq_inf_sup: "a + b = sup a b + inf a b"
   1.108 +proof -
   1.109 +  have "0 = - inf 0 (a-b) + inf (a-b) 0" by (simp add: inf_commute)
   1.110 +  hence "0 = sup 0 (b-a) + inf (a-b) 0" by (simp add: inf_eq_neg_sup)
   1.111 +  hence "0 = (-a + sup a b) + (inf a b + (-b))"
   1.112 +    by (simp add: add_sup_distrib_left add_inf_distrib_right)
   1.113 +       (simp add: algebra_simps)
   1.114 +  thus ?thesis by (simp add: algebra_simps)
   1.115 +qed
   1.116 +
   1.117 +subsection {* Positive Part, Negative Part, Absolute Value *}
   1.118 +
   1.119 +definition
   1.120 +  nprt :: "'a \<Rightarrow> 'a" where
   1.121 +  "nprt x = inf x 0"
   1.122 +
   1.123 +definition
   1.124 +  pprt :: "'a \<Rightarrow> 'a" where
   1.125 +  "pprt x = sup x 0"
   1.126 +
   1.127 +lemma pprt_neg: "pprt (- x) = - nprt x"
   1.128 +proof -
   1.129 +  have "sup (- x) 0 = sup (- x) (- 0)" unfolding minus_zero ..
   1.130 +  also have "\<dots> = - inf x 0" unfolding neg_inf_eq_sup ..
   1.131 +  finally have "sup (- x) 0 = - inf x 0" .
   1.132 +  then show ?thesis unfolding pprt_def nprt_def .
   1.133 +qed
   1.134 +
   1.135 +lemma nprt_neg: "nprt (- x) = - pprt x"
   1.136 +proof -
   1.137 +  from pprt_neg have "pprt (- (- x)) = - nprt (- x)" .
   1.138 +  then have "pprt x = - nprt (- x)" by simp
   1.139 +  then show ?thesis by simp
   1.140 +qed
   1.141 +
   1.142 +lemma prts: "a = pprt a + nprt a"
   1.143 +by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric])
   1.144 +
   1.145 +lemma zero_le_pprt[simp]: "0 \<le> pprt a"
   1.146 +by (simp add: pprt_def)
   1.147 +
   1.148 +lemma nprt_le_zero[simp]: "nprt a \<le> 0"
   1.149 +by (simp add: nprt_def)
   1.150 +
   1.151 +lemma le_eq_neg: "a \<le> - b \<longleftrightarrow> a + b \<le> 0" (is "?l = ?r")
   1.152 +proof -
   1.153 +  have a: "?l \<longrightarrow> ?r"
   1.154 +    apply (auto)
   1.155 +    apply (rule add_le_imp_le_right[of _ "uminus b" _])
   1.156 +    apply (simp add: add_assoc)
   1.157 +    done
   1.158 +  have b: "?r \<longrightarrow> ?l"
   1.159 +    apply (auto)
   1.160 +    apply (rule add_le_imp_le_right[of _ "b" _])
   1.161 +    apply (simp)
   1.162 +    done
   1.163 +  from a b show ?thesis by blast
   1.164 +qed
   1.165 +
   1.166 +lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
   1.167 +lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
   1.168 +
   1.169 +lemma pprt_eq_id [simp, noatp]: "0 \<le> x \<Longrightarrow> pprt x = x"
   1.170 +  by (simp add: pprt_def sup_aci sup_absorb1)
   1.171 +
   1.172 +lemma nprt_eq_id [simp, noatp]: "x \<le> 0 \<Longrightarrow> nprt x = x"
   1.173 +  by (simp add: nprt_def inf_aci inf_absorb1)
   1.174 +
   1.175 +lemma pprt_eq_0 [simp, noatp]: "x \<le> 0 \<Longrightarrow> pprt x = 0"
   1.176 +  by (simp add: pprt_def sup_aci sup_absorb2)
   1.177 +
   1.178 +lemma nprt_eq_0 [simp, noatp]: "0 \<le> x \<Longrightarrow> nprt x = 0"
   1.179 +  by (simp add: nprt_def inf_aci inf_absorb2)
   1.180 +
   1.181 +lemma sup_0_imp_0: "sup a (- a) = 0 \<Longrightarrow> a = 0"
   1.182 +proof -
   1.183 +  {
   1.184 +    fix a::'a
   1.185 +    assume hyp: "sup a (-a) = 0"
   1.186 +    hence "sup a (-a) + a = a" by (simp)
   1.187 +    hence "sup (a+a) 0 = a" by (simp add: add_sup_distrib_right) 
   1.188 +    hence "sup (a+a) 0 <= a" by (simp)
   1.189 +    hence "0 <= a" by (blast intro: order_trans inf_sup_ord)
   1.190 +  }
   1.191 +  note p = this
   1.192 +  assume hyp:"sup a (-a) = 0"
   1.193 +  hence hyp2:"sup (-a) (-(-a)) = 0" by (simp add: sup_commute)
   1.194 +  from p[OF hyp] p[OF hyp2] show "a = 0" by simp
   1.195 +qed
   1.196 +
   1.197 +lemma inf_0_imp_0: "inf a (-a) = 0 \<Longrightarrow> a = 0"
   1.198 +apply (simp add: inf_eq_neg_sup)
   1.199 +apply (simp add: sup_commute)
   1.200 +apply (erule sup_0_imp_0)
   1.201 +done
   1.202 +
   1.203 +lemma inf_0_eq_0 [simp, noatp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
   1.204 +by (rule, erule inf_0_imp_0) simp
   1.205 +
   1.206 +lemma sup_0_eq_0 [simp, noatp]: "sup a (- a) = 0 \<longleftrightarrow> a = 0"
   1.207 +by (rule, erule sup_0_imp_0) simp
   1.208 +
   1.209 +lemma zero_le_double_add_iff_zero_le_single_add [simp]:
   1.210 +  "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
   1.211 +proof
   1.212 +  assume "0 <= a + a"
   1.213 +  hence a:"inf (a+a) 0 = 0" by (simp add: inf_commute inf_absorb1)
   1.214 +  have "(inf a 0)+(inf a 0) = inf (inf (a+a) 0) a" (is "?l=_")
   1.215 +    by (simp add: add_sup_inf_distribs inf_aci)
   1.216 +  hence "?l = 0 + inf a 0" by (simp add: a, simp add: inf_commute)
   1.217 +  hence "inf a 0 = 0" by (simp only: add_right_cancel)
   1.218 +  then show "0 <= a" unfolding le_iff_inf by (simp add: inf_commute)
   1.219 +next
   1.220 +  assume a: "0 <= a"
   1.221 +  show "0 <= a + a" by (simp add: add_mono[OF a a, simplified])
   1.222 +qed
   1.223 +
   1.224 +lemma double_zero [simp]:
   1.225 +  "a + a = 0 \<longleftrightarrow> a = 0"
   1.226 +proof
   1.227 +  assume assm: "a + a = 0"
   1.228 +  then have "a + a + - a = - a" by simp
   1.229 +  then have "a + (a + - a) = - a" by (simp only: add_assoc)
   1.230 +  then have a: "- a = a" by simp
   1.231 +  show "a = 0" apply (rule antisym)
   1.232 +  apply (unfold neg_le_iff_le [symmetric, of a])
   1.233 +  unfolding a apply simp
   1.234 +  unfolding zero_le_double_add_iff_zero_le_single_add [symmetric, of a]
   1.235 +  unfolding assm unfolding le_less apply simp_all done
   1.236 +next
   1.237 +  assume "a = 0" then show "a + a = 0" by simp
   1.238 +qed
   1.239 +
   1.240 +lemma zero_less_double_add_iff_zero_less_single_add [simp]:
   1.241 +  "0 < a + a \<longleftrightarrow> 0 < a"
   1.242 +proof (cases "a = 0")
   1.243 +  case True then show ?thesis by auto
   1.244 +next
   1.245 +  case False then show ?thesis (*FIXME tune proof*)
   1.246 +  unfolding less_le apply simp apply rule
   1.247 +  apply clarify
   1.248 +  apply rule
   1.249 +  apply assumption
   1.250 +  apply (rule notI)
   1.251 +  unfolding double_zero [symmetric, of a] apply simp
   1.252 +  done
   1.253 +qed
   1.254 +
   1.255 +lemma double_add_le_zero_iff_single_add_le_zero [simp]:
   1.256 +  "a + a \<le> 0 \<longleftrightarrow> a \<le> 0" 
   1.257 +proof -
   1.258 +  have "a + a \<le> 0 \<longleftrightarrow> 0 \<le> - (a + a)" by (subst le_minus_iff, simp)
   1.259 +  moreover have "\<dots> \<longleftrightarrow> a \<le> 0" by (simp add: zero_le_double_add_iff_zero_le_single_add)
   1.260 +  ultimately show ?thesis by blast
   1.261 +qed
   1.262 +
   1.263 +lemma double_add_less_zero_iff_single_less_zero [simp]:
   1.264 +  "a + a < 0 \<longleftrightarrow> a < 0"
   1.265 +proof -
   1.266 +  have "a + a < 0 \<longleftrightarrow> 0 < - (a + a)" by (subst less_minus_iff, simp)
   1.267 +  moreover have "\<dots> \<longleftrightarrow> a < 0" by (simp add: zero_less_double_add_iff_zero_less_single_add)
   1.268 +  ultimately show ?thesis by blast
   1.269 +qed
   1.270 +
   1.271 +declare neg_inf_eq_sup [simp] neg_sup_eq_inf [simp]
   1.272 +
   1.273 +lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
   1.274 +proof -
   1.275 +  from add_le_cancel_left [of "uminus a" "plus a a" zero]
   1.276 +  have "(a <= -a) = (a+a <= 0)" 
   1.277 +    by (simp add: add_assoc[symmetric])
   1.278 +  thus ?thesis by simp
   1.279 +qed
   1.280 +
   1.281 +lemma minus_le_self_iff: "- a \<le> a \<longleftrightarrow> 0 \<le> a"
   1.282 +proof -
   1.283 +  from add_le_cancel_left [of "uminus a" zero "plus a a"]
   1.284 +  have "(-a <= a) = (0 <= a+a)" 
   1.285 +    by (simp add: add_assoc[symmetric])
   1.286 +  thus ?thesis by simp
   1.287 +qed
   1.288 +
   1.289 +lemma zero_le_iff_zero_nprt: "0 \<le> a \<longleftrightarrow> nprt a = 0"
   1.290 +unfolding le_iff_inf by (simp add: nprt_def inf_commute)
   1.291 +
   1.292 +lemma le_zero_iff_zero_pprt: "a \<le> 0 \<longleftrightarrow> pprt a = 0"
   1.293 +unfolding le_iff_sup by (simp add: pprt_def sup_commute)
   1.294 +
   1.295 +lemma le_zero_iff_pprt_id: "0 \<le> a \<longleftrightarrow> pprt a = a"
   1.296 +unfolding le_iff_sup by (simp add: pprt_def sup_commute)
   1.297 +
   1.298 +lemma zero_le_iff_nprt_id: "a \<le> 0 \<longleftrightarrow> nprt a = a"
   1.299 +unfolding le_iff_inf by (simp add: nprt_def inf_commute)
   1.300 +
   1.301 +lemma pprt_mono [simp, noatp]: "a \<le> b \<Longrightarrow> pprt a \<le> pprt b"
   1.302 +unfolding le_iff_sup by (simp add: pprt_def sup_aci sup_assoc [symmetric, of a])
   1.303 +
   1.304 +lemma nprt_mono [simp, noatp]: "a \<le> b \<Longrightarrow> nprt a \<le> nprt b"
   1.305 +unfolding le_iff_inf by (simp add: nprt_def inf_aci inf_assoc [symmetric, of a])
   1.306 +
   1.307 +end
   1.308 +
   1.309 +lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
   1.310 +
   1.311 +
   1.312 +class lattice_ab_group_add_abs = lattice_ab_group_add + abs +
   1.313 +  assumes abs_lattice: "\<bar>a\<bar> = sup a (- a)"
   1.314 +begin
   1.315 +
   1.316 +lemma abs_prts: "\<bar>a\<bar> = pprt a - nprt a"
   1.317 +proof -
   1.318 +  have "0 \<le> \<bar>a\<bar>"
   1.319 +  proof -
   1.320 +    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>" by (auto simp add: abs_lattice)
   1.321 +    show ?thesis by (rule add_mono [OF a b, simplified])
   1.322 +  qed
   1.323 +  then have "0 \<le> sup a (- a)" unfolding abs_lattice .
   1.324 +  then have "sup (sup a (- a)) 0 = sup a (- a)" by (rule sup_absorb1)
   1.325 +  then show ?thesis
   1.326 +    by (simp add: add_sup_inf_distribs sup_aci
   1.327 +      pprt_def nprt_def diff_minus abs_lattice)
   1.328 +qed
   1.329 +
   1.330 +subclass ordered_ab_group_add_abs
   1.331 +proof
   1.332 +  have abs_ge_zero [simp]: "\<And>a. 0 \<le> \<bar>a\<bar>"
   1.333 +  proof -
   1.334 +    fix a b
   1.335 +    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>" by (auto simp add: abs_lattice)
   1.336 +    show "0 \<le> \<bar>a\<bar>" by (rule add_mono [OF a b, simplified])
   1.337 +  qed
   1.338 +  have abs_leI: "\<And>a b. a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
   1.339 +    by (simp add: abs_lattice le_supI)
   1.340 +  fix a b
   1.341 +  show "0 \<le> \<bar>a\<bar>" by simp
   1.342 +  show "a \<le> \<bar>a\<bar>"
   1.343 +    by (auto simp add: abs_lattice)
   1.344 +  show "\<bar>-a\<bar> = \<bar>a\<bar>"
   1.345 +    by (simp add: abs_lattice sup_commute)
   1.346 +  show "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b" by (fact abs_leI)
   1.347 +  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
   1.348 +  proof -
   1.349 +    have g:"abs a + abs b = sup (a+b) (sup (-a-b) (sup (-a+b) (a + (-b))))" (is "_=sup ?m ?n")
   1.350 +      by (simp add: abs_lattice add_sup_inf_distribs sup_aci diff_minus)
   1.351 +    have a:"a+b <= sup ?m ?n" by (simp)
   1.352 +    have b:"-a-b <= ?n" by (simp) 
   1.353 +    have c:"?n <= sup ?m ?n" by (simp)
   1.354 +    from b c have d: "-a-b <= sup ?m ?n" by(rule order_trans)
   1.355 +    have e:"-a-b = -(a+b)" by (simp add: diff_minus)
   1.356 +    from a d e have "abs(a+b) <= sup ?m ?n" 
   1.357 +      by (drule_tac abs_leI, auto)
   1.358 +    with g[symmetric] show ?thesis by simp
   1.359 +  qed
   1.360 +qed
   1.361 +
   1.362 +end
   1.363 +
   1.364 +lemma sup_eq_if:
   1.365 +  fixes a :: "'a\<Colon>{lattice_ab_group_add, linorder}"
   1.366 +  shows "sup a (- a) = (if a < 0 then - a else a)"
   1.367 +proof -
   1.368 +  note add_le_cancel_right [of a a "- a", symmetric, simplified]
   1.369 +  moreover note add_le_cancel_right [of "-a" a a, symmetric, simplified]
   1.370 +  then show ?thesis by (auto simp: sup_max min_max.sup_absorb1 min_max.sup_absorb2)
   1.371 +qed
   1.372 +
   1.373 +lemma abs_if_lattice:
   1.374 +  fixes a :: "'a\<Colon>{lattice_ab_group_add_abs, linorder}"
   1.375 +  shows "\<bar>a\<bar> = (if a < 0 then - a else a)"
   1.376 +by auto
   1.377 +
   1.378 +lemma estimate_by_abs:
   1.379 +  "a + b <= (c::'a::lattice_ab_group_add_abs) \<Longrightarrow> a <= c + abs b" 
   1.380 +proof -
   1.381 +  assume "a+b <= c"
   1.382 +  hence 2: "a <= c+(-b)" by (simp add: algebra_simps)
   1.383 +  have 3: "(-b) <= abs b" by (rule abs_ge_minus_self)
   1.384 +  show ?thesis by (rule le_add_right_mono[OF 2 3])
   1.385 +qed
   1.386 +
   1.387 +class lattice_ring = ordered_ring + lattice_ab_group_add_abs
   1.388 +begin
   1.389 +
   1.390 +subclass semilattice_inf_ab_group_add ..
   1.391 +subclass semilattice_sup_ab_group_add ..
   1.392 +
   1.393 +end
   1.394 +
   1.395 +lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lattice_ring))" 
   1.396 +proof -
   1.397 +  let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
   1.398 +  let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
   1.399 +  have a: "(abs a) * (abs b) = ?x"
   1.400 +    by (simp only: abs_prts[of a] abs_prts[of b] algebra_simps)
   1.401 +  {
   1.402 +    fix u v :: 'a
   1.403 +    have bh: "\<lbrakk>u = a; v = b\<rbrakk> \<Longrightarrow> 
   1.404 +              u * v = pprt a * pprt b + pprt a * nprt b + 
   1.405 +                      nprt a * pprt b + nprt a * nprt b"
   1.406 +      apply (subst prts[of u], subst prts[of v])
   1.407 +      apply (simp add: algebra_simps) 
   1.408 +      done
   1.409 +  }
   1.410 +  note b = this[OF refl[of a] refl[of b]]
   1.411 +  note addm = add_mono[of "0::'a" _ "0::'a", simplified]
   1.412 +  note addm2 = add_mono[of _ "0::'a" _ "0::'a", simplified]
   1.413 +  have xy: "- ?x <= ?y"
   1.414 +    apply (simp)
   1.415 +    apply (rule_tac y="0::'a" in order_trans)
   1.416 +    apply (rule addm2)
   1.417 +    apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
   1.418 +    apply (rule addm)
   1.419 +    apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
   1.420 +    done
   1.421 +  have yx: "?y <= ?x"
   1.422 +    apply (simp add:diff_def)
   1.423 +    apply (rule_tac y=0 in order_trans)
   1.424 +    apply (rule addm2, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
   1.425 +    apply (rule addm, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
   1.426 +    done
   1.427 +  have i1: "a*b <= abs a * abs b" by (simp only: a b yx)
   1.428 +  have i2: "- (abs a * abs b) <= a*b" by (simp only: a b xy)
   1.429 +  show ?thesis
   1.430 +    apply (rule abs_leI)
   1.431 +    apply (simp add: i1)
   1.432 +    apply (simp add: i2[simplified minus_le_iff])
   1.433 +    done
   1.434 +qed
   1.435 +
   1.436 +instance lattice_ring \<subseteq> ordered_ring_abs
   1.437 +proof
   1.438 +  fix a b :: "'a\<Colon> lattice_ring"
   1.439 +  assume "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
   1.440 +  show "abs (a*b) = abs a * abs b"
   1.441 +  proof -
   1.442 +    have s: "(0 <= a*b) | (a*b <= 0)"
   1.443 +      apply (auto)    
   1.444 +      apply (rule_tac split_mult_pos_le)
   1.445 +      apply (rule_tac contrapos_np[of "a*b <= 0"])
   1.446 +      apply (simp)
   1.447 +      apply (rule_tac split_mult_neg_le)
   1.448 +      apply (insert prems)
   1.449 +      apply (blast)
   1.450 +      done
   1.451 +    have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
   1.452 +      by (simp add: prts[symmetric])
   1.453 +    show ?thesis
   1.454 +    proof cases
   1.455 +      assume "0 <= a * b"
   1.456 +      then show ?thesis
   1.457 +        apply (simp_all add: mulprts abs_prts)
   1.458 +        apply (insert prems)
   1.459 +        apply (auto simp add: 
   1.460 +          algebra_simps 
   1.461 +          iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_zero_pprt]
   1.462 +          iffD1[OF le_zero_iff_pprt_id] iffD1[OF zero_le_iff_nprt_id])
   1.463 +          apply(drule (1) mult_nonneg_nonpos[of a b], simp)
   1.464 +          apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
   1.465 +        done
   1.466 +    next
   1.467 +      assume "~(0 <= a*b)"
   1.468 +      with s have "a*b <= 0" by simp
   1.469 +      then show ?thesis
   1.470 +        apply (simp_all add: mulprts abs_prts)
   1.471 +        apply (insert prems)
   1.472 +        apply (auto simp add: algebra_simps)
   1.473 +        apply(drule (1) mult_nonneg_nonneg[of a b],simp)
   1.474 +        apply(drule (1) mult_nonpos_nonpos[of a b],simp)
   1.475 +        done
   1.476 +    qed
   1.477 +  qed
   1.478 +qed
   1.479 +
   1.480 +lemma mult_le_prts:
   1.481 +  assumes
   1.482 +  "a1 <= (a::'a::lattice_ring)"
   1.483 +  "a <= a2"
   1.484 +  "b1 <= b"
   1.485 +  "b <= b2"
   1.486 +  shows
   1.487 +  "a * b <= pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
   1.488 +proof - 
   1.489 +  have "a * b = (pprt a + nprt a) * (pprt b + nprt b)" 
   1.490 +    apply (subst prts[symmetric])+
   1.491 +    apply simp
   1.492 +    done
   1.493 +  then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
   1.494 +    by (simp add: algebra_simps)
   1.495 +  moreover have "pprt a * pprt b <= pprt a2 * pprt b2"
   1.496 +    by (simp_all add: prems mult_mono)
   1.497 +  moreover have "pprt a * nprt b <= pprt a1 * nprt b2"
   1.498 +  proof -
   1.499 +    have "pprt a * nprt b <= pprt a * nprt b2"
   1.500 +      by (simp add: mult_left_mono prems)
   1.501 +    moreover have "pprt a * nprt b2 <= pprt a1 * nprt b2"
   1.502 +      by (simp add: mult_right_mono_neg prems)
   1.503 +    ultimately show ?thesis
   1.504 +      by simp
   1.505 +  qed
   1.506 +  moreover have "nprt a * pprt b <= nprt a2 * pprt b1"
   1.507 +  proof - 
   1.508 +    have "nprt a * pprt b <= nprt a2 * pprt b"
   1.509 +      by (simp add: mult_right_mono prems)
   1.510 +    moreover have "nprt a2 * pprt b <= nprt a2 * pprt b1"
   1.511 +      by (simp add: mult_left_mono_neg prems)
   1.512 +    ultimately show ?thesis
   1.513 +      by simp
   1.514 +  qed
   1.515 +  moreover have "nprt a * nprt b <= nprt a1 * nprt b1"
   1.516 +  proof -
   1.517 +    have "nprt a * nprt b <= nprt a * nprt b1"
   1.518 +      by (simp add: mult_left_mono_neg prems)
   1.519 +    moreover have "nprt a * nprt b1 <= nprt a1 * nprt b1"
   1.520 +      by (simp add: mult_right_mono_neg prems)
   1.521 +    ultimately show ?thesis
   1.522 +      by simp
   1.523 +  qed
   1.524 +  ultimately show ?thesis
   1.525 +    by - (rule add_mono | simp)+
   1.526 +qed
   1.527 +
   1.528 +lemma mult_ge_prts:
   1.529 +  assumes
   1.530 +  "a1 <= (a::'a::lattice_ring)"
   1.531 +  "a <= a2"
   1.532 +  "b1 <= b"
   1.533 +  "b <= b2"
   1.534 +  shows
   1.535 +  "a * b >= nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
   1.536 +proof - 
   1.537 +  from prems have a1:"- a2 <= -a" by auto
   1.538 +  from prems have a2: "-a <= -a1" by auto
   1.539 +  from mult_le_prts[of "-a2" "-a" "-a1" "b1" b "b2", OF a1 a2 prems(3) prems(4), simplified nprt_neg pprt_neg] 
   1.540 +  have le: "- (a * b) <= - nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1" by simp  
   1.541 +  then have "-(- nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1) <= a * b"
   1.542 +    by (simp only: minus_le_iff)
   1.543 +  then show ?thesis by simp
   1.544 +qed
   1.545 +
   1.546 +instance int :: lattice_ring
   1.547 +proof  
   1.548 +  fix k :: int
   1.549 +  show "abs k = sup k (- k)"
   1.550 +    by (auto simp add: sup_int_def)
   1.551 +qed
   1.552 +
   1.553 +instance real :: lattice_ring
   1.554 +proof
   1.555 +  fix a :: real
   1.556 +  show "abs a = sup a (- a)"
   1.557 +    by (auto simp add: sup_real_def)
   1.558 +qed
   1.559 +
   1.560 +end