src/HOL/OrderedGroup.thy
author haftmann
Fri Mar 16 21:32:08 2007 +0100 (2007-03-16)
changeset 22452 8a86fd2a1bf0
parent 22422 ee19cdb07528
child 22482 8fc3d7237e03
permissions -rw-r--r--
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
     1 (*  Title:   HOL/OrderedGroup.thy
     2     ID:      $Id$
     3     Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson, and Markus Wenzel,
     4              with contributions by Jeremy Avigad
     5 *)
     6 
     7 header {* Ordered Groups *}
     8 
     9 theory OrderedGroup
    10 imports Lattices
    11 uses "~~/src/Provers/Arith/abel_cancel.ML"
    12 begin
    13 
    14 text {*
    15   The theory of partially ordered groups is taken from the books:
    16   \begin{itemize}
    17   \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
    18   \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
    19   \end{itemize}
    20   Most of the used notions can also be looked up in 
    21   \begin{itemize}
    22   \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
    23   \item \emph{Algebra I} by van der Waerden, Springer.
    24   \end{itemize}
    25 *}
    26 
    27 subsection {* Semigroups, Groups *}
    28 
    29 class semigroup_add = plus +
    30   assumes add_assoc: "(a \<^loc>+ b) \<^loc>+ c = a \<^loc>+ (b \<^loc>+ c)"
    31 
    32 class ab_semigroup_add = semigroup_add +
    33   assumes add_commute: "a \<^loc>+ b = b \<^loc>+ a"
    34 
    35 lemma add_left_commute: "a + (b + c) = b + (a + (c::'a::ab_semigroup_add))"
    36   by (rule mk_left_commute [of "op +", OF add_assoc add_commute])
    37 
    38 theorems add_ac = add_assoc add_commute add_left_commute
    39 
    40 class semigroup_mult = times +
    41   assumes mult_assoc: "(a \<^loc>* b) \<^loc>* c = a \<^loc>* (b \<^loc>* c)"
    42 
    43 class ab_semigroup_mult = semigroup_mult +
    44   assumes mult_commute: "a \<^loc>* b = b \<^loc>* a"
    45 
    46 lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::ab_semigroup_mult))"
    47   by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute])
    48 
    49 theorems mult_ac = mult_assoc mult_commute mult_left_commute
    50 
    51 class comm_monoid_add = zero + ab_semigroup_add +
    52   assumes add_0 [simp]: "\<^loc>0 \<^loc>+ a = a"
    53 
    54 class monoid_mult = one + semigroup_mult +
    55   assumes mult_1_left [simp]: "\<^loc>1 \<^loc>* a  = a"
    56   assumes mult_1_right [simp]: "a \<^loc>* \<^loc>1 = a"
    57 
    58 class comm_monoid_mult = one + ab_semigroup_mult +
    59   assumes mult_1: "\<^loc>1 \<^loc>* a = a"
    60 
    61 instance comm_monoid_mult \<subseteq> monoid_mult
    62   by intro_classes (insert mult_1, simp_all add: mult_commute, auto)
    63 
    64 class cancel_semigroup_add = semigroup_add +
    65   assumes add_left_imp_eq: "a \<^loc>+ b = a \<^loc>+ c \<Longrightarrow> b = c"
    66   assumes add_right_imp_eq: "b \<^loc>+ a = c \<^loc>+ a \<Longrightarrow> b = c"
    67 
    68 class cancel_ab_semigroup_add = ab_semigroup_add +
    69   assumes add_imp_eq: "a \<^loc>+ b = a \<^loc>+ c \<Longrightarrow> b = c"
    70 
    71 instance cancel_ab_semigroup_add \<subseteq> cancel_semigroup_add
    72 proof intro_classes
    73   fix a b c :: 'a
    74   assume "a + b = a + c" 
    75   then show "b = c" by (rule add_imp_eq)
    76 next
    77   fix a b c :: 'a
    78   assume "b + a = c + a"
    79   then have "a + b = a + c" by (simp only: add_commute)
    80   then show "b = c" by (rule add_imp_eq)
    81 qed
    82 
    83 class ab_group_add = minus + comm_monoid_add +
    84   assumes left_minus [simp]: "uminus a \<^loc>+ a = \<^loc>0"
    85   assumes diff_minus: "a \<^loc>- b = a \<^loc>+ (uminus b)"
    86 
    87 instance ab_group_add \<subseteq> cancel_ab_semigroup_add
    88 proof intro_classes
    89   fix a b c :: 'a
    90   assume "a + b = a + c"
    91   then have "uminus a + a + b = uminus a + a + c" unfolding add_assoc by simp
    92   then show "b = c" by simp 
    93 qed
    94 
    95 lemma add_0_right [simp]: "a + 0 = (a::'a::comm_monoid_add)"
    96 proof -
    97   have "a + 0 = 0 + a" by (simp only: add_commute)
    98   also have "... = a" by simp
    99   finally show ?thesis .
   100 qed
   101 
   102 lemmas add_zero_left = add_0
   103   and add_zero_right = add_0_right
   104 
   105 lemma add_left_cancel [simp]:
   106   "a + b = a + c \<longleftrightarrow> b = (c \<Colon> 'a\<Colon>cancel_semigroup_add)"
   107   by (blast dest: add_left_imp_eq) 
   108 
   109 lemma add_right_cancel [simp]:
   110   "b + a = c + a \<longleftrightarrow> b = (c \<Colon> 'a\<Colon>cancel_semigroup_add)"
   111   by (blast dest: add_right_imp_eq)
   112 
   113 lemma right_minus [simp]: "a + -(a::'a::ab_group_add) = 0"
   114 proof -
   115   have "a + -a = -a + a" by (simp add: add_ac)
   116   also have "... = 0" by simp
   117   finally show ?thesis .
   118 qed
   119 
   120 lemma right_minus_eq: "(a - b = 0) = (a = (b::'a::ab_group_add))"
   121 proof
   122   have "a = a - b + b" by (simp add: diff_minus add_ac)
   123   also assume "a - b = 0"
   124   finally show "a = b" by simp
   125 next
   126   assume "a = b"
   127   thus "a - b = 0" by (simp add: diff_minus)
   128 qed
   129 
   130 lemma minus_minus [simp]: "- (- (a::'a::ab_group_add)) = a"
   131 proof (rule add_left_cancel [of "-a", THEN iffD1])
   132   show "(-a + -(-a) = -a + a)"
   133   by simp
   134 qed
   135 
   136 lemma equals_zero_I: "a+b = 0 ==> -a = (b::'a::ab_group_add)"
   137 apply (rule right_minus_eq [THEN iffD1, symmetric])
   138 apply (simp add: diff_minus add_commute) 
   139 done
   140 
   141 lemma minus_zero [simp]: "- 0 = (0::'a::ab_group_add)"
   142 by (simp add: equals_zero_I)
   143 
   144 lemma diff_self [simp]: "a - (a::'a::ab_group_add) = 0"
   145   by (simp add: diff_minus)
   146 
   147 lemma diff_0 [simp]: "(0::'a::ab_group_add) - a = -a"
   148 by (simp add: diff_minus)
   149 
   150 lemma diff_0_right [simp]: "a - (0::'a::ab_group_add) = a" 
   151 by (simp add: diff_minus)
   152 
   153 lemma diff_minus_eq_add [simp]: "a - - b = a + (b::'a::ab_group_add)"
   154 by (simp add: diff_minus)
   155 
   156 lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ab_group_add))" 
   157 proof 
   158   assume "- a = - b"
   159   hence "- (- a) = - (- b)"
   160     by simp
   161   thus "a=b" by simp
   162 next
   163   assume "a=b"
   164   thus "-a = -b" by simp
   165 qed
   166 
   167 lemma neg_equal_0_iff_equal [simp]: "(-a = 0) = (a = (0::'a::ab_group_add))"
   168 by (subst neg_equal_iff_equal [symmetric], simp)
   169 
   170 lemma neg_0_equal_iff_equal [simp]: "(0 = -a) = (0 = (a::'a::ab_group_add))"
   171 by (subst neg_equal_iff_equal [symmetric], simp)
   172 
   173 text{*The next two equations can make the simplifier loop!*}
   174 
   175 lemma equation_minus_iff: "(a = - b) = (b = - (a::'a::ab_group_add))"
   176 proof -
   177   have "(- (-a) = - b) = (- a = b)" by (rule neg_equal_iff_equal)
   178   thus ?thesis by (simp add: eq_commute)
   179 qed
   180 
   181 lemma minus_equation_iff: "(- a = b) = (- (b::'a::ab_group_add) = a)"
   182 proof -
   183   have "(- a = - (-b)) = (a = -b)" by (rule neg_equal_iff_equal)
   184   thus ?thesis by (simp add: eq_commute)
   185 qed
   186 
   187 lemma minus_add_distrib [simp]: "- (a + b) = -a + -(b::'a::ab_group_add)"
   188 apply (rule equals_zero_I)
   189 apply (simp add: add_ac) 
   190 done
   191 
   192 lemma minus_diff_eq [simp]: "- (a - b) = b - (a::'a::ab_group_add)"
   193 by (simp add: diff_minus add_commute)
   194 
   195 subsection {* (Partially) Ordered Groups *} 
   196 
   197 class pordered_ab_semigroup_add = order + ab_semigroup_add +
   198   assumes add_left_mono: "a \<sqsubseteq> b \<Longrightarrow> c \<^loc>+ a \<sqsubseteq> c \<^loc>+ b"
   199 
   200 class pordered_cancel_ab_semigroup_add =
   201   pordered_ab_semigroup_add + cancel_ab_semigroup_add
   202 
   203 instance pordered_cancel_ab_semigroup_add \<subseteq> pordered_ab_semigroup_add ..
   204 
   205 class pordered_ab_semigroup_add_imp_le = pordered_cancel_ab_semigroup_add +
   206   assumes add_le_imp_le_left: "c \<^loc>+ a \<sqsubseteq> c \<^loc>+ b \<Longrightarrow> a \<sqsubseteq> b"
   207 
   208 class pordered_ab_group_add = ab_group_add + pordered_ab_semigroup_add
   209 
   210 instance pordered_ab_group_add \<subseteq> pordered_ab_semigroup_add_imp_le
   211 proof
   212   fix a b c :: 'a
   213   assume "c + a \<le> c + b"
   214   hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
   215   hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
   216   thus "a \<le> b" by simp
   217 qed
   218 
   219 class ordered_cancel_ab_semigroup_add = pordered_cancel_ab_semigroup_add + linorder
   220 
   221 instance ordered_cancel_ab_semigroup_add \<subseteq> pordered_ab_semigroup_add_imp_le
   222 proof
   223   fix a b c :: 'a
   224   assume le: "c + a <= c + b"  
   225   show "a <= b"
   226   proof (rule ccontr)
   227     assume w: "~ a \<le> b"
   228     hence "b <= a" by (simp add: linorder_not_le)
   229     hence le2: "c+b <= c+a" by (rule add_left_mono)
   230     have "a = b" 
   231       apply (insert le)
   232       apply (insert le2)
   233       apply (drule order_antisym, simp_all)
   234       done
   235     with w  show False 
   236       by (simp add: linorder_not_le [symmetric])
   237   qed
   238 qed
   239 
   240 lemma add_right_mono: "a \<le> (b::'a::pordered_ab_semigroup_add) ==> a + c \<le> b + c"
   241   by (simp add: add_commute [of _ c] add_left_mono)
   242 
   243 text {* non-strict, in both arguments *}
   244 lemma add_mono:
   245      "[|a \<le> b;  c \<le> d|] ==> a + c \<le> b + (d::'a::pordered_ab_semigroup_add)"
   246   apply (erule add_right_mono [THEN order_trans])
   247   apply (simp add: add_commute add_left_mono)
   248   done
   249 
   250 lemma add_strict_left_mono:
   251      "a < b ==> c + a < c + (b::'a::pordered_cancel_ab_semigroup_add)"
   252  by (simp add: order_less_le add_left_mono) 
   253 
   254 lemma add_strict_right_mono:
   255      "a < b ==> a + c < b + (c::'a::pordered_cancel_ab_semigroup_add)"
   256  by (simp add: add_commute [of _ c] add_strict_left_mono)
   257 
   258 text{*Strict monotonicity in both arguments*}
   259 lemma add_strict_mono: "[|a<b; c<d|] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)"
   260 apply (erule add_strict_right_mono [THEN order_less_trans])
   261 apply (erule add_strict_left_mono)
   262 done
   263 
   264 lemma add_less_le_mono:
   265      "[| a<b; c\<le>d |] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)"
   266 apply (erule add_strict_right_mono [THEN order_less_le_trans])
   267 apply (erule add_left_mono) 
   268 done
   269 
   270 lemma add_le_less_mono:
   271      "[| a\<le>b; c<d |] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)"
   272 apply (erule add_right_mono [THEN order_le_less_trans])
   273 apply (erule add_strict_left_mono) 
   274 done
   275 
   276 lemma add_less_imp_less_left:
   277       assumes less: "c + a < c + b"  shows "a < (b::'a::pordered_ab_semigroup_add_imp_le)"
   278 proof -
   279   from less have le: "c + a <= c + b" by (simp add: order_le_less)
   280   have "a <= b" 
   281     apply (insert le)
   282     apply (drule add_le_imp_le_left)
   283     by (insert le, drule add_le_imp_le_left, assumption)
   284   moreover have "a \<noteq> b"
   285   proof (rule ccontr)
   286     assume "~(a \<noteq> b)"
   287     then have "a = b" by simp
   288     then have "c + a = c + b" by simp
   289     with less show "False"by simp
   290   qed
   291   ultimately show "a < b" by (simp add: order_le_less)
   292 qed
   293 
   294 lemma add_less_imp_less_right:
   295       "a + c < b + c ==> a < (b::'a::pordered_ab_semigroup_add_imp_le)"
   296 apply (rule add_less_imp_less_left [of c])
   297 apply (simp add: add_commute)  
   298 done
   299 
   300 lemma add_less_cancel_left [simp]:
   301     "(c+a < c+b) = (a < (b::'a::pordered_ab_semigroup_add_imp_le))"
   302 by (blast intro: add_less_imp_less_left add_strict_left_mono) 
   303 
   304 lemma add_less_cancel_right [simp]:
   305     "(a+c < b+c) = (a < (b::'a::pordered_ab_semigroup_add_imp_le))"
   306 by (blast intro: add_less_imp_less_right add_strict_right_mono)
   307 
   308 lemma add_le_cancel_left [simp]:
   309     "(c+a \<le> c+b) = (a \<le> (b::'a::pordered_ab_semigroup_add_imp_le))"
   310 by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 
   311 
   312 lemma add_le_cancel_right [simp]:
   313     "(a+c \<le> b+c) = (a \<le> (b::'a::pordered_ab_semigroup_add_imp_le))"
   314 by (simp add: add_commute[of a c] add_commute[of b c])
   315 
   316 lemma add_le_imp_le_right:
   317       "a + c \<le> b + c ==> a \<le> (b::'a::pordered_ab_semigroup_add_imp_le)"
   318 by simp
   319 
   320 lemma add_increasing:
   321   fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   322   shows  "[|0\<le>a; b\<le>c|] ==> b \<le> a + c"
   323 by (insert add_mono [of 0 a b c], simp)
   324 
   325 lemma add_increasing2:
   326   fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   327   shows  "[|0\<le>c; b\<le>a|] ==> b \<le> a + c"
   328 by (simp add:add_increasing add_commute[of a])
   329 
   330 lemma add_strict_increasing:
   331   fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   332   shows "[|0<a; b\<le>c|] ==> b < a + c"
   333 by (insert add_less_le_mono [of 0 a b c], simp)
   334 
   335 lemma add_strict_increasing2:
   336   fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   337   shows "[|0\<le>a; b<c|] ==> b < a + c"
   338 by (insert add_le_less_mono [of 0 a b c], simp)
   339 
   340 lemma max_add_distrib_left:
   341   fixes z :: "'a::pordered_ab_semigroup_add_imp_le"
   342   shows  "(max x y) + z = max (x+z) (y+z)"
   343 by (rule max_of_mono [THEN sym], rule add_le_cancel_right)
   344 
   345 lemma min_add_distrib_left:
   346   fixes z :: "'a::pordered_ab_semigroup_add_imp_le"
   347   shows  "(min x y) + z = min (x+z) (y+z)"
   348 by (rule min_of_mono [THEN sym], rule add_le_cancel_right)
   349 
   350 lemma max_diff_distrib_left:
   351   fixes z :: "'a::pordered_ab_group_add"
   352   shows  "(max x y) - z = max (x-z) (y-z)"
   353 by (simp add: diff_minus, rule max_add_distrib_left) 
   354 
   355 lemma min_diff_distrib_left:
   356   fixes z :: "'a::pordered_ab_group_add"
   357   shows  "(min x y) - z = min (x-z) (y-z)"
   358 by (simp add: diff_minus, rule min_add_distrib_left) 
   359 
   360 
   361 subsection {* Ordering Rules for Unary Minus *}
   362 
   363 lemma le_imp_neg_le:
   364       assumes "a \<le> (b::'a::{pordered_ab_semigroup_add_imp_le, ab_group_add})" shows "-b \<le> -a"
   365 proof -
   366   have "-a+a \<le> -a+b"
   367     by (rule add_left_mono) 
   368   hence "0 \<le> -a+b"
   369     by simp
   370   hence "0 + (-b) \<le> (-a + b) + (-b)"
   371     by (rule add_right_mono) 
   372   thus ?thesis
   373     by (simp add: add_assoc)
   374 qed
   375 
   376 lemma neg_le_iff_le [simp]: "(-b \<le> -a) = (a \<le> (b::'a::pordered_ab_group_add))"
   377 proof 
   378   assume "- b \<le> - a"
   379   hence "- (- a) \<le> - (- b)"
   380     by (rule le_imp_neg_le)
   381   thus "a\<le>b" by simp
   382 next
   383   assume "a\<le>b"
   384   thus "-b \<le> -a" by (rule le_imp_neg_le)
   385 qed
   386 
   387 lemma neg_le_0_iff_le [simp]: "(-a \<le> 0) = (0 \<le> (a::'a::pordered_ab_group_add))"
   388 by (subst neg_le_iff_le [symmetric], simp)
   389 
   390 lemma neg_0_le_iff_le [simp]: "(0 \<le> -a) = (a \<le> (0::'a::pordered_ab_group_add))"
   391 by (subst neg_le_iff_le [symmetric], simp)
   392 
   393 lemma neg_less_iff_less [simp]: "(-b < -a) = (a < (b::'a::pordered_ab_group_add))"
   394 by (force simp add: order_less_le) 
   395 
   396 lemma neg_less_0_iff_less [simp]: "(-a < 0) = (0 < (a::'a::pordered_ab_group_add))"
   397 by (subst neg_less_iff_less [symmetric], simp)
   398 
   399 lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::pordered_ab_group_add))"
   400 by (subst neg_less_iff_less [symmetric], simp)
   401 
   402 text{*The next several equations can make the simplifier loop!*}
   403 
   404 lemma less_minus_iff: "(a < - b) = (b < - (a::'a::pordered_ab_group_add))"
   405 proof -
   406   have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
   407   thus ?thesis by simp
   408 qed
   409 
   410 lemma minus_less_iff: "(- a < b) = (- b < (a::'a::pordered_ab_group_add))"
   411 proof -
   412   have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
   413   thus ?thesis by simp
   414 qed
   415 
   416 lemma le_minus_iff: "(a \<le> - b) = (b \<le> - (a::'a::pordered_ab_group_add))"
   417 proof -
   418   have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
   419   have "(- (- a) <= -b) = (b <= - a)" 
   420     apply (auto simp only: order_le_less)
   421     apply (drule mm)
   422     apply (simp_all)
   423     apply (drule mm[simplified], assumption)
   424     done
   425   then show ?thesis by simp
   426 qed
   427 
   428 lemma minus_le_iff: "(- a \<le> b) = (- b \<le> (a::'a::pordered_ab_group_add))"
   429 by (auto simp add: order_le_less minus_less_iff)
   430 
   431 lemma add_diff_eq: "a + (b - c) = (a + b) - (c::'a::ab_group_add)"
   432 by (simp add: diff_minus add_ac)
   433 
   434 lemma diff_add_eq: "(a - b) + c = (a + c) - (b::'a::ab_group_add)"
   435 by (simp add: diff_minus add_ac)
   436 
   437 lemma diff_eq_eq: "(a-b = c) = (a = c + (b::'a::ab_group_add))"
   438 by (auto simp add: diff_minus add_assoc)
   439 
   440 lemma eq_diff_eq: "(a = c-b) = (a + (b::'a::ab_group_add) = c)"
   441 by (auto simp add: diff_minus add_assoc)
   442 
   443 lemma diff_diff_eq: "(a - b) - c = a - (b + (c::'a::ab_group_add))"
   444 by (simp add: diff_minus add_ac)
   445 
   446 lemma diff_diff_eq2: "a - (b - c) = (a + c) - (b::'a::ab_group_add)"
   447 by (simp add: diff_minus add_ac)
   448 
   449 lemma diff_add_cancel: "a - b + b = (a::'a::ab_group_add)"
   450 by (simp add: diff_minus add_ac)
   451 
   452 lemma add_diff_cancel: "a + b - b = (a::'a::ab_group_add)"
   453 by (simp add: diff_minus add_ac)
   454 
   455 text{*Further subtraction laws*}
   456 
   457 lemma less_iff_diff_less_0: "(a < b) = (a - b < (0::'a::pordered_ab_group_add))"
   458 proof -
   459   have  "(a < b) = (a + (- b) < b + (-b))"  
   460     by (simp only: add_less_cancel_right)
   461   also have "... =  (a - b < 0)" by (simp add: diff_minus)
   462   finally show ?thesis .
   463 qed
   464 
   465 lemma diff_less_eq: "(a-b < c) = (a < c + (b::'a::pordered_ab_group_add))"
   466 apply (subst less_iff_diff_less_0 [of a])
   467 apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
   468 apply (simp add: diff_minus add_ac)
   469 done
   470 
   471 lemma less_diff_eq: "(a < c-b) = (a + (b::'a::pordered_ab_group_add) < c)"
   472 apply (subst less_iff_diff_less_0 [of "a+b"])
   473 apply (subst less_iff_diff_less_0 [of a])
   474 apply (simp add: diff_minus add_ac)
   475 done
   476 
   477 lemma diff_le_eq: "(a-b \<le> c) = (a \<le> c + (b::'a::pordered_ab_group_add))"
   478 by (auto simp add: order_le_less diff_less_eq diff_add_cancel add_diff_cancel)
   479 
   480 lemma le_diff_eq: "(a \<le> c-b) = (a + (b::'a::pordered_ab_group_add) \<le> c)"
   481 by (auto simp add: order_le_less less_diff_eq diff_add_cancel add_diff_cancel)
   482 
   483 text{*This list of rewrites simplifies (in)equalities by bringing subtractions
   484   to the top and then moving negative terms to the other side.
   485   Use with @{text add_ac}*}
   486 lemmas compare_rls =
   487        diff_minus [symmetric]
   488        add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
   489        diff_less_eq less_diff_eq diff_le_eq le_diff_eq
   490        diff_eq_eq eq_diff_eq
   491 
   492 subsection {* Support for reasoning about signs *}
   493 
   494 lemma add_pos_pos: "0 < 
   495     (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
   496       ==> 0 < y ==> 0 < x + y"
   497 apply (subgoal_tac "0 + 0 < x + y")
   498 apply simp
   499 apply (erule add_less_le_mono)
   500 apply (erule order_less_imp_le)
   501 done
   502 
   503 lemma add_pos_nonneg: "0 < 
   504     (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
   505       ==> 0 <= y ==> 0 < x + y"
   506 apply (subgoal_tac "0 + 0 < x + y")
   507 apply simp
   508 apply (erule add_less_le_mono, assumption)
   509 done
   510 
   511 lemma add_nonneg_pos: "0 <= 
   512     (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
   513       ==> 0 < y ==> 0 < x + y"
   514 apply (subgoal_tac "0 + 0 < x + y")
   515 apply simp
   516 apply (erule add_le_less_mono, assumption)
   517 done
   518 
   519 lemma add_nonneg_nonneg: "0 <= 
   520     (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
   521       ==> 0 <= y ==> 0 <= x + y"
   522 apply (subgoal_tac "0 + 0 <= x + y")
   523 apply simp
   524 apply (erule add_mono, assumption)
   525 done
   526 
   527 lemma add_neg_neg: "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add})
   528     < 0 ==> y < 0 ==> x + y < 0"
   529 apply (subgoal_tac "x + y < 0 + 0")
   530 apply simp
   531 apply (erule add_less_le_mono)
   532 apply (erule order_less_imp_le)
   533 done
   534 
   535 lemma add_neg_nonpos: 
   536     "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) < 0 
   537       ==> y <= 0 ==> x + y < 0"
   538 apply (subgoal_tac "x + y < 0 + 0")
   539 apply simp
   540 apply (erule add_less_le_mono, assumption)
   541 done
   542 
   543 lemma add_nonpos_neg: 
   544     "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
   545       ==> y < 0 ==> x + y < 0"
   546 apply (subgoal_tac "x + y < 0 + 0")
   547 apply simp
   548 apply (erule add_le_less_mono, assumption)
   549 done
   550 
   551 lemma add_nonpos_nonpos: 
   552     "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
   553       ==> y <= 0 ==> x + y <= 0"
   554 apply (subgoal_tac "x + y <= 0 + 0")
   555 apply simp
   556 apply (erule add_mono, assumption)
   557 done
   558 
   559 subsection{*Lemmas for the @{text cancel_numerals} simproc*}
   560 
   561 lemma eq_iff_diff_eq_0: "(a = b) = (a-b = (0::'a::ab_group_add))"
   562 by (simp add: compare_rls)
   563 
   564 lemma le_iff_diff_le_0: "(a \<le> b) = (a-b \<le> (0::'a::pordered_ab_group_add))"
   565 by (simp add: compare_rls)
   566 
   567 
   568 subsection {* Lattice Ordered (Abelian) Groups *}
   569 
   570 class lordered_ab_group_meet = pordered_ab_group_add + lower_semilattice
   571 
   572 class lordered_ab_group_join = pordered_ab_group_add + upper_semilattice
   573 
   574 class lordered_ab_group = pordered_ab_group_add + lattice
   575 
   576 instance lordered_ab_group \<subseteq> lordered_ab_group_meet by default
   577 instance lordered_ab_group \<subseteq> lordered_ab_group_join by default
   578 
   579 lemma add_inf_distrib_left: "a + inf b c = inf (a + b) (a + (c::'a::{pordered_ab_group_add, lower_semilattice}))"
   580 apply (rule order_antisym)
   581 apply (simp_all add: le_infI)
   582 apply (rule add_le_imp_le_left [of "-a"])
   583 apply (simp only: add_assoc[symmetric], simp)
   584 apply rule
   585 apply (rule add_le_imp_le_left[of "a"], simp only: add_assoc[symmetric], simp)+
   586 done
   587 
   588 lemma add_sup_distrib_left: "a + sup b c = sup (a + b) (a+ (c::'a::{pordered_ab_group_add, upper_semilattice}))" 
   589 apply (rule order_antisym)
   590 apply (rule add_le_imp_le_left [of "-a"])
   591 apply (simp only: add_assoc[symmetric], simp)
   592 apply rule
   593 apply (rule add_le_imp_le_left [of "a"], simp only: add_assoc[symmetric], simp)+
   594 apply (rule le_supI)
   595 apply (simp_all)
   596 done
   597 
   598 lemma add_inf_distrib_right: "inf a b + (c::'a::lordered_ab_group) = inf (a+c) (b+c)"
   599 proof -
   600   have "c + inf a b = inf (c+a) (c+b)" by (simp add: add_inf_distrib_left)
   601   thus ?thesis by (simp add: add_commute)
   602 qed
   603 
   604 lemma add_sup_distrib_right: "sup a b + (c::'a::lordered_ab_group) = sup (a+c) (b+c)"
   605 proof -
   606   have "c + sup a b = sup (c+a) (c+b)" by (simp add: add_sup_distrib_left)
   607   thus ?thesis by (simp add: add_commute)
   608 qed
   609 
   610 lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
   611 
   612 lemma inf_eq_neg_sup: "inf a (b\<Colon>'a\<Colon>lordered_ab_group) = - sup (-a) (-b)"
   613 proof (rule inf_unique)
   614   fix a b :: 'a
   615   show "- sup (-a) (-b) \<le> a" by (rule add_le_imp_le_right [of _ "sup (-a) (-b)"])
   616     (simp, simp add: add_sup_distrib_left)
   617 next
   618   fix a b :: 'a
   619   show "- sup (-a) (-b) \<le> b" by (rule add_le_imp_le_right [of _ "sup (-a) (-b)"])
   620     (simp, simp add: add_sup_distrib_left)
   621 next
   622   fix a b c :: 'a
   623   assume "a \<le> b" "a \<le> c"
   624   then show "a \<le> - sup (-b) (-c)" by (subst neg_le_iff_le [symmetric])
   625     (simp add: le_supI)
   626 qed
   627   
   628 lemma sup_eq_neg_inf: "sup a (b\<Colon>'a\<Colon>lordered_ab_group) = - inf (-a) (-b)"
   629 proof (rule sup_unique)
   630   fix a b :: 'a
   631   show "a \<le> - inf (-a) (-b)" by (rule add_le_imp_le_right [of _ "inf (-a) (-b)"])
   632     (simp, simp add: add_inf_distrib_left)
   633 next
   634   fix a b :: 'a
   635   show "b \<le> - inf (-a) (-b)" by (rule add_le_imp_le_right [of _ "inf (-a) (-b)"])
   636     (simp, simp add: add_inf_distrib_left)
   637 next
   638   fix a b c :: 'a
   639   assume "a \<le> c" "b \<le> c"
   640   then show "- inf (-a) (-b) \<le> c" by (subst neg_le_iff_le [symmetric])
   641     (simp add: le_infI)
   642 qed
   643 
   644 lemma add_eq_inf_sup: "a + b = sup a b + inf a (b\<Colon>'a\<Colon>lordered_ab_group)"
   645 proof -
   646   have "0 = - inf 0 (a-b) + inf (a-b) 0" by (simp add: inf_commute)
   647   hence "0 = sup 0 (b-a) + inf (a-b) 0" by (simp add: inf_eq_neg_sup)
   648   hence "0 = (-a + sup a b) + (inf a b + (-b))"
   649     apply (simp add: add_sup_distrib_left add_inf_distrib_right)
   650     by (simp add: diff_minus add_commute)
   651   thus ?thesis
   652     apply (simp add: compare_rls)
   653     apply (subst add_left_cancel[symmetric, of "a+b" "sup a b + inf a b" "-a"])
   654     apply (simp only: add_assoc, simp add: add_assoc[symmetric])
   655     done
   656 qed
   657 
   658 subsection {* Positive Part, Negative Part, Absolute Value *}
   659 
   660 definition
   661   nprt :: "'a \<Rightarrow> ('a::lordered_ab_group)" where
   662   "nprt x = inf x 0"
   663 
   664 definition
   665   pprt :: "'a \<Rightarrow> ('a::lordered_ab_group)" where
   666   "pprt x = sup x 0"
   667 
   668 lemma prts: "a = pprt a + nprt a"
   669 by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric])
   670 
   671 lemma zero_le_pprt[simp]: "0 \<le> pprt a"
   672 by (simp add: pprt_def)
   673 
   674 lemma nprt_le_zero[simp]: "nprt a \<le> 0"
   675 by (simp add: nprt_def)
   676 
   677 lemma le_eq_neg: "(a \<le> -b) = (a + b \<le> (0::_::lordered_ab_group))" (is "?l = ?r")
   678 proof -
   679   have a: "?l \<longrightarrow> ?r"
   680     apply (auto)
   681     apply (rule add_le_imp_le_right[of _ "-b" _])
   682     apply (simp add: add_assoc)
   683     done
   684   have b: "?r \<longrightarrow> ?l"
   685     apply (auto)
   686     apply (rule add_le_imp_le_right[of _ "b" _])
   687     apply (simp)
   688     done
   689   from a b show ?thesis by blast
   690 qed
   691 
   692 lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
   693 lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
   694 
   695 lemma pprt_eq_id[simp]: "0 <= x \<Longrightarrow> pprt x = x"
   696   by (simp add: pprt_def le_iff_sup sup_aci)
   697 
   698 lemma nprt_eq_id[simp]: "x <= 0 \<Longrightarrow> nprt x = x"
   699   by (simp add: nprt_def le_iff_inf inf_aci)
   700 
   701 lemma pprt_eq_0[simp]: "x <= 0 \<Longrightarrow> pprt x = 0"
   702   by (simp add: pprt_def le_iff_sup sup_aci)
   703 
   704 lemma nprt_eq_0[simp]: "0 <= x \<Longrightarrow> nprt x = 0"
   705   by (simp add: nprt_def le_iff_inf inf_aci)
   706 
   707 lemma sup_0_imp_0: "sup a (-a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)"
   708 proof -
   709   {
   710     fix a::'a
   711     assume hyp: "sup a (-a) = 0"
   712     hence "sup a (-a) + a = a" by (simp)
   713     hence "sup (a+a) 0 = a" by (simp add: add_sup_distrib_right) 
   714     hence "sup (a+a) 0 <= a" by (simp)
   715     hence "0 <= a" by (blast intro: order_trans inf_sup_ord)
   716   }
   717   note p = this
   718   assume hyp:"sup a (-a) = 0"
   719   hence hyp2:"sup (-a) (-(-a)) = 0" by (simp add: sup_commute)
   720   from p[OF hyp] p[OF hyp2] show "a = 0" by simp
   721 qed
   722 
   723 lemma inf_0_imp_0: "inf a (-a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)"
   724 apply (simp add: inf_eq_neg_sup)
   725 apply (simp add: sup_commute)
   726 apply (erule sup_0_imp_0)
   727 done
   728 
   729 lemma inf_0_eq_0[simp]: "(inf a (-a) = 0) = (a = (0::'a::lordered_ab_group))"
   730 by (auto, erule inf_0_imp_0)
   731 
   732 lemma sup_0_eq_0[simp]: "(sup a (-a) = 0) = (a = (0::'a::lordered_ab_group))"
   733 by (auto, erule sup_0_imp_0)
   734 
   735 lemma zero_le_double_add_iff_zero_le_single_add[simp]: "(0 \<le> a + a) = (0 \<le> (a::'a::lordered_ab_group))"
   736 proof
   737   assume "0 <= a + a"
   738   hence a:"inf (a+a) 0 = 0" by (simp add: le_iff_inf inf_commute)
   739   have "(inf a 0)+(inf a 0) = inf (inf (a+a) 0) a" (is "?l=_") by (simp add: add_sup_inf_distribs inf_aci)
   740   hence "?l = 0 + inf a 0" by (simp add: a, simp add: inf_commute)
   741   hence "inf a 0 = 0" by (simp only: add_right_cancel)
   742   then show "0 <= a" by (simp add: le_iff_inf inf_commute)    
   743 next  
   744   assume a: "0 <= a"
   745   show "0 <= a + a" by (simp add: add_mono[OF a a, simplified])
   746 qed
   747 
   748 lemma double_add_le_zero_iff_single_add_le_zero[simp]: "(a + a <= 0) = ((a::'a::lordered_ab_group) <= 0)" 
   749 proof -
   750   have "(a + a <= 0) = (0 <= -(a+a))" by (subst le_minus_iff, simp)
   751   moreover have "\<dots> = (a <= 0)" by (simp add: zero_le_double_add_iff_zero_le_single_add)
   752   ultimately show ?thesis by blast
   753 qed
   754 
   755 lemma double_add_less_zero_iff_single_less_zero[simp]: "(a+a<0) = ((a::'a::{pordered_ab_group_add,linorder}) < 0)" (is ?s)
   756 proof cases
   757   assume a: "a < 0"
   758   thus ?s by (simp add:  add_strict_mono[OF a a, simplified])
   759 next
   760   assume "~(a < 0)" 
   761   hence a:"0 <= a" by (simp)
   762   hence "0 <= a+a" by (simp add: add_mono[OF a a, simplified])
   763   hence "~(a+a < 0)" by simp
   764   with a show ?thesis by simp 
   765 qed
   766 
   767 class lordered_ab_group_abs = lordered_ab_group +
   768   assumes abs_lattice: "abs x = sup x (uminus x)"
   769 
   770 lemma abs_zero[simp]: "abs 0 = (0::'a::lordered_ab_group_abs)"
   771 by (simp add: abs_lattice)
   772 
   773 lemma abs_eq_0[simp]: "(abs a = 0) = (a = (0::'a::lordered_ab_group_abs))"
   774 by (simp add: abs_lattice)
   775 
   776 lemma abs_0_eq[simp]: "(0 = abs a) = (a = (0::'a::lordered_ab_group_abs))"
   777 proof -
   778   have "(0 = abs a) = (abs a = 0)" by (simp only: eq_ac)
   779   thus ?thesis by simp
   780 qed
   781 
   782 lemma neg_inf_eq_sup[simp]: "- inf a (b::_::lordered_ab_group) = sup (-a) (-b)"
   783 by (simp add: inf_eq_neg_sup)
   784 
   785 lemma neg_sup_eq_inf[simp]: "- sup a (b::_::lordered_ab_group) = inf (-a) (-b)"
   786 by (simp del: neg_inf_eq_sup add: sup_eq_neg_inf)
   787 
   788 lemma sup_eq_if: "sup a (-a) = (if a < 0 then -a else (a::'a::{lordered_ab_group, linorder}))"
   789 proof -
   790   note b = add_le_cancel_right[of a a "-a",symmetric,simplified]
   791   have c: "a + a = 0 \<Longrightarrow> -a = a" by (rule add_right_imp_eq[of _ a], simp)
   792   show ?thesis by (auto simp add: max_def b linorder_not_less sup_max)
   793 qed
   794 
   795 lemma abs_if_lattice: "\<bar>a\<bar> = (if a < 0 then -a else (a::'a::{lordered_ab_group_abs, linorder}))"
   796 proof -
   797   show ?thesis by (simp add: abs_lattice sup_eq_if)
   798 qed
   799 
   800 lemma abs_ge_zero[simp]: "0 \<le> abs (a::'a::lordered_ab_group_abs)"
   801 proof -
   802   have a:"a <= abs a" and b:"-a <= abs a" by (auto simp add: abs_lattice)
   803   show ?thesis by (rule add_mono[OF a b, simplified])
   804 qed
   805   
   806 lemma abs_le_zero_iff [simp]: "(abs a \<le> (0::'a::lordered_ab_group_abs)) = (a = 0)" 
   807 proof
   808   assume "abs a <= 0"
   809   hence "abs a = 0" by (auto dest: order_antisym)
   810   thus "a = 0" by simp
   811 next
   812   assume "a = 0"
   813   thus "abs a <= 0" by simp
   814 qed
   815 
   816 lemma zero_less_abs_iff [simp]: "(0 < abs a) = (a \<noteq> (0::'a::lordered_ab_group_abs))"
   817 by (simp add: order_less_le)
   818 
   819 lemma abs_not_less_zero [simp]: "~ abs a < (0::'a::lordered_ab_group_abs)"
   820 proof -
   821   have a:"!! x (y::_::order). x <= y \<Longrightarrow> ~(y < x)" by auto
   822   show ?thesis by (simp add: a)
   823 qed
   824 
   825 lemma abs_ge_self: "a \<le> abs (a::'a::lordered_ab_group_abs)"
   826 by (simp add: abs_lattice)
   827 
   828 lemma abs_ge_minus_self: "-a \<le> abs (a::'a::lordered_ab_group_abs)"
   829 by (simp add: abs_lattice)
   830 
   831 lemma abs_prts: "abs (a::_::lordered_ab_group_abs) = pprt a - nprt a"
   832 apply (simp add: pprt_def nprt_def diff_minus)
   833 apply (simp add: add_sup_inf_distribs sup_aci abs_lattice[symmetric])
   834 apply (subst sup_absorb2, auto)
   835 done
   836 
   837 lemma abs_minus_cancel [simp]: "abs (-a) = abs(a::'a::lordered_ab_group_abs)"
   838 by (simp add: abs_lattice sup_commute)
   839 
   840 lemma abs_idempotent [simp]: "abs (abs a) = abs (a::'a::lordered_ab_group_abs)"
   841 apply (simp add: abs_lattice[of "abs a"])
   842 apply (subst sup_absorb1)
   843 apply (rule order_trans[of _ 0])
   844 by auto
   845 
   846 lemma abs_minus_commute: 
   847   fixes a :: "'a::lordered_ab_group_abs"
   848   shows "abs (a-b) = abs(b-a)"
   849 proof -
   850   have "abs (a-b) = abs (- (a-b))" by (simp only: abs_minus_cancel)
   851   also have "... = abs(b-a)" by simp
   852   finally show ?thesis .
   853 qed
   854 
   855 lemma zero_le_iff_zero_nprt: "(0 \<le> a) = (nprt a = 0)"
   856 by (simp add: le_iff_inf nprt_def inf_commute)
   857 
   858 lemma le_zero_iff_zero_pprt: "(a \<le> 0) = (pprt a = 0)"
   859 by (simp add: le_iff_sup pprt_def sup_commute)
   860 
   861 lemma le_zero_iff_pprt_id: "(0 \<le> a) = (pprt a = a)"
   862 by (simp add: le_iff_sup pprt_def sup_commute)
   863 
   864 lemma zero_le_iff_nprt_id: "(a \<le> 0) = (nprt a = a)"
   865 by (simp add: le_iff_inf nprt_def inf_commute)
   866 
   867 lemma pprt_mono[simp]: "(a::_::lordered_ab_group) <= b \<Longrightarrow> pprt a <= pprt b"
   868   by (simp add: le_iff_sup pprt_def sup_aci)
   869 
   870 lemma nprt_mono[simp]: "(a::_::lordered_ab_group) <= b \<Longrightarrow> nprt a <= nprt b"
   871   by (simp add: le_iff_inf nprt_def inf_aci)
   872 
   873 lemma pprt_neg: "pprt (-x) = - nprt x"
   874   by (simp add: pprt_def nprt_def)
   875 
   876 lemma nprt_neg: "nprt (-x) = - pprt x"
   877   by (simp add: pprt_def nprt_def)
   878 
   879 lemma iff2imp: "(A=B) \<Longrightarrow> (A \<Longrightarrow> B)"
   880 by (simp)
   881 
   882 lemma abs_of_nonneg [simp]: "0 \<le> a \<Longrightarrow> abs a = (a::'a::lordered_ab_group_abs)"
   883 by (simp add: iff2imp[OF zero_le_iff_zero_nprt] iff2imp[OF le_zero_iff_pprt_id] abs_prts)
   884 
   885 lemma abs_of_pos: "0 < (x::'a::lordered_ab_group_abs) ==> abs x = x";
   886 by (rule abs_of_nonneg, rule order_less_imp_le);
   887 
   888 lemma abs_of_nonpos [simp]: "a \<le> 0 \<Longrightarrow> abs a = -(a::'a::lordered_ab_group_abs)"
   889 by (simp add: iff2imp[OF le_zero_iff_zero_pprt] iff2imp[OF zero_le_iff_nprt_id] abs_prts)
   890 
   891 lemma abs_of_neg: "(x::'a::lordered_ab_group_abs) <  0 ==> 
   892   abs x = - x"
   893 by (rule abs_of_nonpos, rule order_less_imp_le)
   894 
   895 lemma abs_leI: "[|a \<le> b; -a \<le> b|] ==> abs a \<le> (b::'a::lordered_ab_group_abs)"
   896 by (simp add: abs_lattice le_supI)
   897 
   898 lemma le_minus_self_iff: "(a \<le> -a) = (a \<le> (0::'a::lordered_ab_group))"
   899 proof -
   900   from add_le_cancel_left[of "-a" "a+a" "0"] have "(a <= -a) = (a+a <= 0)" 
   901     by (simp add: add_assoc[symmetric])
   902   thus ?thesis by simp
   903 qed
   904 
   905 lemma minus_le_self_iff: "(-a \<le> a) = (0 \<le> (a::'a::lordered_ab_group))"
   906 proof -
   907   from add_le_cancel_left[of "-a" "0" "a+a"] have "(-a <= a) = (0 <= a+a)" 
   908     by (simp add: add_assoc[symmetric])
   909   thus ?thesis by simp
   910 qed
   911 
   912 lemma abs_le_D1: "abs a \<le> b ==> a \<le> (b::'a::lordered_ab_group_abs)"
   913 by (insert abs_ge_self, blast intro: order_trans)
   914 
   915 lemma abs_le_D2: "abs a \<le> b ==> -a \<le> (b::'a::lordered_ab_group_abs)"
   916 by (insert abs_le_D1 [of "-a"], simp)
   917 
   918 lemma abs_le_iff: "(abs a \<le> b) = (a \<le> b & -a \<le> (b::'a::lordered_ab_group_abs))"
   919 by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
   920 
   921 lemma abs_triangle_ineq: "abs(a+b) \<le> abs a + abs(b::'a::lordered_ab_group_abs)"
   922 proof -
   923   have g:"abs a + abs b = sup (a+b) (sup (-a-b) (sup (-a+b) (a + (-b))))" (is "_=sup ?m ?n")
   924     by (simp add: abs_lattice add_sup_inf_distribs sup_aci diff_minus)
   925   have a:"a+b <= sup ?m ?n" by (simp)
   926   have b:"-a-b <= ?n" by (simp) 
   927   have c:"?n <= sup ?m ?n" by (simp)
   928   from b c have d: "-a-b <= sup ?m ?n" by(rule order_trans)
   929   have e:"-a-b = -(a+b)" by (simp add: diff_minus)
   930   from a d e have "abs(a+b) <= sup ?m ?n" 
   931     by (drule_tac abs_leI, auto)
   932   with g[symmetric] show ?thesis by simp
   933 qed
   934 
   935 lemma abs_triangle_ineq2: "abs (a::'a::lordered_ab_group_abs) - 
   936     abs b <= abs (a - b)"
   937   apply (simp add: compare_rls)
   938   apply (subgoal_tac "abs a = abs (a - b + b)")
   939   apply (erule ssubst)
   940   apply (rule abs_triangle_ineq)
   941   apply (rule arg_cong);back;
   942   apply (simp add: compare_rls)
   943 done
   944 
   945 lemma abs_triangle_ineq3: 
   946     "abs(abs (a::'a::lordered_ab_group_abs) - abs b) <= abs (a - b)"
   947   apply (subst abs_le_iff)
   948   apply auto
   949   apply (rule abs_triangle_ineq2)
   950   apply (subst abs_minus_commute)
   951   apply (rule abs_triangle_ineq2)
   952 done
   953 
   954 lemma abs_triangle_ineq4: "abs ((a::'a::lordered_ab_group_abs) - b) <= 
   955     abs a + abs b"
   956 proof -;
   957   have "abs(a - b) = abs(a + - b)"
   958     by (subst diff_minus, rule refl)
   959   also have "... <= abs a + abs (- b)"
   960     by (rule abs_triangle_ineq)
   961   finally show ?thesis
   962     by simp
   963 qed
   964 
   965 lemma abs_diff_triangle_ineq:
   966      "\<bar>(a::'a::lordered_ab_group_abs) + b - (c+d)\<bar> \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>"
   967 proof -
   968   have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
   969   also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
   970   finally show ?thesis .
   971 qed
   972 
   973 lemma abs_add_abs[simp]:
   974 fixes a:: "'a::{lordered_ab_group_abs}"
   975 shows "abs(abs a + abs b) = abs a + abs b" (is "?L = ?R")
   976 proof (rule order_antisym)
   977   show "?L \<ge> ?R" by(rule abs_ge_self)
   978 next
   979   have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq)
   980   also have "\<dots> = ?R" by simp
   981   finally show "?L \<le> ?R" .
   982 qed
   983 
   984 text {* Needed for abelian cancellation simprocs: *}
   985 
   986 lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
   987 apply (subst add_left_commute)
   988 apply (subst add_left_cancel)
   989 apply simp
   990 done
   991 
   992 lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
   993 apply (subst add_cancel_21[of _ _ _ 0, simplified])
   994 apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
   995 done
   996 
   997 lemma less_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
   998 by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
   999 
  1000 lemma le_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
  1001 apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
  1002 apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
  1003 done
  1004 
  1005 lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
  1006 by (simp add: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
  1007 
  1008 lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
  1009 by (simp add: diff_minus)
  1010 
  1011 lemma add_minus_cancel: "(a::'a::ab_group_add) + (-a + b) = b"
  1012 by (simp add: add_assoc[symmetric])
  1013 
  1014 lemma minus_add_cancel: "-(a::'a::ab_group_add) + (a + b) = b"
  1015 by (simp add: add_assoc[symmetric])
  1016 
  1017 lemma  le_add_right_mono: 
  1018   assumes 
  1019   "a <= b + (c::'a::pordered_ab_group_add)"
  1020   "c <= d"    
  1021   shows "a <= b + d"
  1022   apply (rule_tac order_trans[where y = "b+c"])
  1023   apply (simp_all add: prems)
  1024   done
  1025 
  1026 lemmas group_eq_simps =
  1027   mult_ac
  1028   add_ac
  1029   add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
  1030   diff_eq_eq eq_diff_eq
  1031 
  1032 lemma estimate_by_abs:
  1033 "a + b <= (c::'a::lordered_ab_group_abs) \<Longrightarrow> a <= c + abs b" 
  1034 proof -
  1035   assume 1: "a+b <= c"
  1036   have 2: "a <= c+(-b)"
  1037     apply (insert 1)
  1038     apply (drule_tac add_right_mono[where c="-b"])
  1039     apply (simp add: group_eq_simps)
  1040     done
  1041   have 3: "(-b) <= abs b" by (rule abs_ge_minus_self)
  1042   show ?thesis by (rule le_add_right_mono[OF 2 3])
  1043 qed
  1044 
  1045 text{*Simplification of @{term "x-y < 0"}, etc.*}
  1046 lemmas diff_less_0_iff_less = less_iff_diff_less_0 [symmetric]
  1047 lemmas diff_eq_0_iff_eq = eq_iff_diff_eq_0 [symmetric]
  1048 lemmas diff_le_0_iff_le = le_iff_diff_le_0 [symmetric]
  1049 declare diff_less_0_iff_less [simp]
  1050 declare diff_eq_0_iff_eq [simp]
  1051 declare diff_le_0_iff_le [simp]
  1052 
  1053 
  1054 ML {*
  1055 val add_assoc = thm "add_assoc";
  1056 val add_commute = thm "add_commute";
  1057 val add_left_commute = thm "add_left_commute";
  1058 val add_ac = thms "add_ac";
  1059 val mult_assoc = thm "mult_assoc";
  1060 val mult_commute = thm "mult_commute";
  1061 val mult_left_commute = thm "mult_left_commute";
  1062 val mult_ac = thms "mult_ac";
  1063 val add_0 = thm "add_0";
  1064 val mult_1_left = thm "mult_1_left";
  1065 val mult_1_right = thm "mult_1_right";
  1066 val mult_1 = thm "mult_1";
  1067 val add_left_imp_eq = thm "add_left_imp_eq";
  1068 val add_right_imp_eq = thm "add_right_imp_eq";
  1069 val add_imp_eq = thm "add_imp_eq";
  1070 val left_minus = thm "left_minus";
  1071 val diff_minus = thm "diff_minus";
  1072 val add_0_right = thm "add_0_right";
  1073 val add_left_cancel = thm "add_left_cancel";
  1074 val add_right_cancel = thm "add_right_cancel";
  1075 val right_minus = thm "right_minus";
  1076 val right_minus_eq = thm "right_minus_eq";
  1077 val minus_minus = thm "minus_minus";
  1078 val equals_zero_I = thm "equals_zero_I";
  1079 val minus_zero = thm "minus_zero";
  1080 val diff_self = thm "diff_self";
  1081 val diff_0 = thm "diff_0";
  1082 val diff_0_right = thm "diff_0_right";
  1083 val diff_minus_eq_add = thm "diff_minus_eq_add";
  1084 val neg_equal_iff_equal = thm "neg_equal_iff_equal";
  1085 val neg_equal_0_iff_equal = thm "neg_equal_0_iff_equal";
  1086 val neg_0_equal_iff_equal = thm "neg_0_equal_iff_equal";
  1087 val equation_minus_iff = thm "equation_minus_iff";
  1088 val minus_equation_iff = thm "minus_equation_iff";
  1089 val minus_add_distrib = thm "minus_add_distrib";
  1090 val minus_diff_eq = thm "minus_diff_eq";
  1091 val add_left_mono = thm "add_left_mono";
  1092 val add_le_imp_le_left = thm "add_le_imp_le_left";
  1093 val add_right_mono = thm "add_right_mono";
  1094 val add_mono = thm "add_mono";
  1095 val add_strict_left_mono = thm "add_strict_left_mono";
  1096 val add_strict_right_mono = thm "add_strict_right_mono";
  1097 val add_strict_mono = thm "add_strict_mono";
  1098 val add_less_le_mono = thm "add_less_le_mono";
  1099 val add_le_less_mono = thm "add_le_less_mono";
  1100 val add_less_imp_less_left = thm "add_less_imp_less_left";
  1101 val add_less_imp_less_right = thm "add_less_imp_less_right";
  1102 val add_less_cancel_left = thm "add_less_cancel_left";
  1103 val add_less_cancel_right = thm "add_less_cancel_right";
  1104 val add_le_cancel_left = thm "add_le_cancel_left";
  1105 val add_le_cancel_right = thm "add_le_cancel_right";
  1106 val add_le_imp_le_right = thm "add_le_imp_le_right";
  1107 val add_increasing = thm "add_increasing";
  1108 val le_imp_neg_le = thm "le_imp_neg_le";
  1109 val neg_le_iff_le = thm "neg_le_iff_le";
  1110 val neg_le_0_iff_le = thm "neg_le_0_iff_le";
  1111 val neg_0_le_iff_le = thm "neg_0_le_iff_le";
  1112 val neg_less_iff_less = thm "neg_less_iff_less";
  1113 val neg_less_0_iff_less = thm "neg_less_0_iff_less";
  1114 val neg_0_less_iff_less = thm "neg_0_less_iff_less";
  1115 val less_minus_iff = thm "less_minus_iff";
  1116 val minus_less_iff = thm "minus_less_iff";
  1117 val le_minus_iff = thm "le_minus_iff";
  1118 val minus_le_iff = thm "minus_le_iff";
  1119 val add_diff_eq = thm "add_diff_eq";
  1120 val diff_add_eq = thm "diff_add_eq";
  1121 val diff_eq_eq = thm "diff_eq_eq";
  1122 val eq_diff_eq = thm "eq_diff_eq";
  1123 val diff_diff_eq = thm "diff_diff_eq";
  1124 val diff_diff_eq2 = thm "diff_diff_eq2";
  1125 val diff_add_cancel = thm "diff_add_cancel";
  1126 val add_diff_cancel = thm "add_diff_cancel";
  1127 val less_iff_diff_less_0 = thm "less_iff_diff_less_0";
  1128 val diff_less_eq = thm "diff_less_eq";
  1129 val less_diff_eq = thm "less_diff_eq";
  1130 val diff_le_eq = thm "diff_le_eq";
  1131 val le_diff_eq = thm "le_diff_eq";
  1132 val compare_rls = thms "compare_rls";
  1133 val eq_iff_diff_eq_0 = thm "eq_iff_diff_eq_0";
  1134 val le_iff_diff_le_0 = thm "le_iff_diff_le_0";
  1135 val add_inf_distrib_left = thm "add_inf_distrib_left";
  1136 val add_sup_distrib_left = thm "add_sup_distrib_left";
  1137 val add_sup_distrib_right = thm "add_sup_distrib_right";
  1138 val add_inf_distrib_right = thm "add_inf_distrib_right";
  1139 val add_sup_inf_distribs = thms "add_sup_inf_distribs";
  1140 val sup_eq_neg_inf = thm "sup_eq_neg_inf";
  1141 val inf_eq_neg_sup = thm "inf_eq_neg_sup";
  1142 val add_eq_inf_sup = thm "add_eq_inf_sup";
  1143 val prts = thm "prts";
  1144 val zero_le_pprt = thm "zero_le_pprt";
  1145 val nprt_le_zero = thm "nprt_le_zero";
  1146 val le_eq_neg = thm "le_eq_neg";
  1147 val sup_0_imp_0 = thm "sup_0_imp_0";
  1148 val inf_0_imp_0 = thm "inf_0_imp_0";
  1149 val sup_0_eq_0 = thm "sup_0_eq_0";
  1150 val inf_0_eq_0 = thm "inf_0_eq_0";
  1151 val zero_le_double_add_iff_zero_le_single_add = thm "zero_le_double_add_iff_zero_le_single_add";
  1152 val double_add_le_zero_iff_single_add_le_zero = thm "double_add_le_zero_iff_single_add_le_zero";
  1153 val double_add_less_zero_iff_single_less_zero = thm "double_add_less_zero_iff_single_less_zero";
  1154 val abs_lattice = thm "abs_lattice";
  1155 val abs_zero = thm "abs_zero";
  1156 val abs_eq_0 = thm "abs_eq_0";
  1157 val abs_0_eq = thm "abs_0_eq";
  1158 val neg_inf_eq_sup = thm "neg_inf_eq_sup";
  1159 val neg_sup_eq_inf = thm "neg_sup_eq_inf";
  1160 val sup_eq_if = thm "sup_eq_if";
  1161 val abs_if_lattice = thm "abs_if_lattice";
  1162 val abs_ge_zero = thm "abs_ge_zero";
  1163 val abs_le_zero_iff = thm "abs_le_zero_iff";
  1164 val zero_less_abs_iff = thm "zero_less_abs_iff";
  1165 val abs_not_less_zero = thm "abs_not_less_zero";
  1166 val abs_ge_self = thm "abs_ge_self";
  1167 val abs_ge_minus_self = thm "abs_ge_minus_self";
  1168 val le_imp_join_eq = thm "sup_absorb2";
  1169 val ge_imp_join_eq = thm "sup_absorb1";
  1170 val le_imp_meet_eq = thm "inf_absorb1";
  1171 val ge_imp_meet_eq = thm "inf_absorb2";
  1172 val abs_prts = thm "abs_prts";
  1173 val abs_minus_cancel = thm "abs_minus_cancel";
  1174 val abs_idempotent = thm "abs_idempotent";
  1175 val zero_le_iff_zero_nprt = thm "zero_le_iff_zero_nprt";
  1176 val le_zero_iff_zero_pprt = thm "le_zero_iff_zero_pprt";
  1177 val le_zero_iff_pprt_id = thm "le_zero_iff_pprt_id";
  1178 val zero_le_iff_nprt_id = thm "zero_le_iff_nprt_id";
  1179 val iff2imp = thm "iff2imp";
  1180 val abs_leI = thm "abs_leI";
  1181 val le_minus_self_iff = thm "le_minus_self_iff";
  1182 val minus_le_self_iff = thm "minus_le_self_iff";
  1183 val abs_le_D1 = thm "abs_le_D1";
  1184 val abs_le_D2 = thm "abs_le_D2";
  1185 val abs_le_iff = thm "abs_le_iff";
  1186 val abs_triangle_ineq = thm "abs_triangle_ineq";
  1187 val abs_diff_triangle_ineq = thm "abs_diff_triangle_ineq";
  1188 *}
  1189 
  1190 end