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