src/HOL/Rings.thy
author haftmann
Sun Sep 07 09:49:01 2014 +0200 (2014-09-07)
changeset 58198 099ca49b5231
parent 58195 1fee63e0377d
child 58647 fce800afeec7
permissions -rw-r--r--
generalized
     1 (*  Title:      HOL/Rings.thy
     2     Author:     Gertrud Bauer
     3     Author:     Steven Obua
     4     Author:     Tobias Nipkow
     5     Author:     Lawrence C Paulson
     6     Author:     Markus Wenzel
     7     Author:     Jeremy Avigad
     8 *)
     9 
    10 header {* Rings *}
    11 
    12 theory Rings
    13 imports Groups
    14 begin
    15 
    16 class semiring = ab_semigroup_add + semigroup_mult +
    17   assumes distrib_right[algebra_simps, field_simps]: "(a + b) * c = a * c + b * c"
    18   assumes distrib_left[algebra_simps, field_simps]: "a * (b + c) = a * b + a * c"
    19 begin
    20 
    21 text{*For the @{text combine_numerals} simproc*}
    22 lemma combine_common_factor:
    23   "a * e + (b * e + c) = (a + b) * e + c"
    24 by (simp add: distrib_right ac_simps)
    25 
    26 end
    27 
    28 class mult_zero = times + zero +
    29   assumes mult_zero_left [simp]: "0 * a = 0"
    30   assumes mult_zero_right [simp]: "a * 0 = 0"
    31 begin
    32 
    33 lemma mult_not_zero:
    34   "a * b \<noteq> 0 \<Longrightarrow> a \<noteq> 0 \<and> b \<noteq> 0"
    35   by auto
    36 
    37 end
    38 
    39 class semiring_0 = semiring + comm_monoid_add + mult_zero
    40 
    41 class semiring_0_cancel = semiring + cancel_comm_monoid_add
    42 begin
    43 
    44 subclass semiring_0
    45 proof
    46   fix a :: 'a
    47   have "0 * a + 0 * a = 0 * a + 0" by (simp add: distrib_right [symmetric])
    48   thus "0 * a = 0" by (simp only: add_left_cancel)
    49 next
    50   fix a :: 'a
    51   have "a * 0 + a * 0 = a * 0 + 0" by (simp add: distrib_left [symmetric])
    52   thus "a * 0 = 0" by (simp only: add_left_cancel)
    53 qed
    54 
    55 end
    56 
    57 class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
    58   assumes distrib: "(a + b) * c = a * c + b * c"
    59 begin
    60 
    61 subclass semiring
    62 proof
    63   fix a b c :: 'a
    64   show "(a + b) * c = a * c + b * c" by (simp add: distrib)
    65   have "a * (b + c) = (b + c) * a" by (simp add: ac_simps)
    66   also have "... = b * a + c * a" by (simp only: distrib)
    67   also have "... = a * b + a * c" by (simp add: ac_simps)
    68   finally show "a * (b + c) = a * b + a * c" by blast
    69 qed
    70 
    71 end
    72 
    73 class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
    74 begin
    75 
    76 subclass semiring_0 ..
    77 
    78 end
    79 
    80 class comm_semiring_0_cancel = comm_semiring + cancel_comm_monoid_add
    81 begin
    82 
    83 subclass semiring_0_cancel ..
    84 
    85 subclass comm_semiring_0 ..
    86 
    87 end
    88 
    89 class zero_neq_one = zero + one +
    90   assumes zero_neq_one [simp]: "0 \<noteq> 1"
    91 begin
    92 
    93 lemma one_neq_zero [simp]: "1 \<noteq> 0"
    94 by (rule not_sym) (rule zero_neq_one)
    95 
    96 definition of_bool :: "bool \<Rightarrow> 'a"
    97 where
    98   "of_bool p = (if p then 1 else 0)" 
    99 
   100 lemma of_bool_eq [simp, code]:
   101   "of_bool False = 0"
   102   "of_bool True = 1"
   103   by (simp_all add: of_bool_def)
   104 
   105 lemma of_bool_eq_iff:
   106   "of_bool p = of_bool q \<longleftrightarrow> p = q"
   107   by (simp add: of_bool_def)
   108 
   109 lemma split_of_bool [split]:
   110   "P (of_bool p) \<longleftrightarrow> (p \<longrightarrow> P 1) \<and> (\<not> p \<longrightarrow> P 0)"
   111   by (cases p) simp_all
   112 
   113 lemma split_of_bool_asm:
   114   "P (of_bool p) \<longleftrightarrow> \<not> (p \<and> \<not> P 1 \<or> \<not> p \<and> \<not> P 0)"
   115   by (cases p) simp_all
   116   
   117 end  
   118 
   119 class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
   120 
   121 text {* Abstract divisibility *}
   122 
   123 class dvd = times
   124 begin
   125 
   126 definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "dvd" 50) where
   127   "b dvd a \<longleftrightarrow> (\<exists>k. a = b * k)"
   128 
   129 lemma dvdI [intro?]: "a = b * k \<Longrightarrow> b dvd a"
   130   unfolding dvd_def ..
   131 
   132 lemma dvdE [elim?]: "b dvd a \<Longrightarrow> (\<And>k. a = b * k \<Longrightarrow> P) \<Longrightarrow> P"
   133   unfolding dvd_def by blast 
   134 
   135 end
   136 
   137 class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult + dvd
   138   (*previously almost_semiring*)
   139 begin
   140 
   141 subclass semiring_1 ..
   142 
   143 lemma dvd_refl[simp]: "a dvd a"
   144 proof
   145   show "a = a * 1" by simp
   146 qed
   147 
   148 lemma dvd_trans:
   149   assumes "a dvd b" and "b dvd c"
   150   shows "a dvd c"
   151 proof -
   152   from assms obtain v where "b = a * v" by (auto elim!: dvdE)
   153   moreover from assms obtain w where "c = b * w" by (auto elim!: dvdE)
   154   ultimately have "c = a * (v * w)" by (simp add: mult.assoc)
   155   then show ?thesis ..
   156 qed
   157 
   158 lemma dvd_0_left_iff [simp]: "0 dvd a \<longleftrightarrow> a = 0"
   159 by (auto intro: dvd_refl elim!: dvdE)
   160 
   161 lemma dvd_0_right [iff]: "a dvd 0"
   162 proof
   163   show "0 = a * 0" by simp
   164 qed
   165 
   166 lemma one_dvd [simp]: "1 dvd a"
   167 by (auto intro!: dvdI)
   168 
   169 lemma dvd_mult[simp]: "a dvd c \<Longrightarrow> a dvd (b * c)"
   170 by (auto intro!: mult.left_commute dvdI elim!: dvdE)
   171 
   172 lemma dvd_mult2[simp]: "a dvd b \<Longrightarrow> a dvd (b * c)"
   173   apply (subst mult.commute)
   174   apply (erule dvd_mult)
   175   done
   176 
   177 lemma dvd_triv_right [simp]: "a dvd b * a"
   178 by (rule dvd_mult) (rule dvd_refl)
   179 
   180 lemma dvd_triv_left [simp]: "a dvd a * b"
   181 by (rule dvd_mult2) (rule dvd_refl)
   182 
   183 lemma mult_dvd_mono:
   184   assumes "a dvd b"
   185     and "c dvd d"
   186   shows "a * c dvd b * d"
   187 proof -
   188   from `a dvd b` obtain b' where "b = a * b'" ..
   189   moreover from `c dvd d` obtain d' where "d = c * d'" ..
   190   ultimately have "b * d = (a * c) * (b' * d')" by (simp add: ac_simps)
   191   then show ?thesis ..
   192 qed
   193 
   194 lemma dvd_mult_left: "a * b dvd c \<Longrightarrow> a dvd c"
   195 by (simp add: dvd_def mult.assoc, blast)
   196 
   197 lemma dvd_mult_right: "a * b dvd c \<Longrightarrow> b dvd c"
   198   unfolding mult.commute [of a] by (rule dvd_mult_left)
   199 
   200 lemma dvd_0_left: "0 dvd a \<Longrightarrow> a = 0"
   201 by simp
   202 
   203 lemma dvd_add[simp]:
   204   assumes "a dvd b" and "a dvd c" shows "a dvd (b + c)"
   205 proof -
   206   from `a dvd b` obtain b' where "b = a * b'" ..
   207   moreover from `a dvd c` obtain c' where "c = a * c'" ..
   208   ultimately have "b + c = a * (b' + c')" by (simp add: distrib_left)
   209   then show ?thesis ..
   210 qed
   211 
   212 end
   213 
   214 class no_zero_divisors = zero + times +
   215   assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
   216 begin
   217 
   218 lemma divisors_zero:
   219   assumes "a * b = 0"
   220   shows "a = 0 \<or> b = 0"
   221 proof (rule classical)
   222   assume "\<not> (a = 0 \<or> b = 0)"
   223   then have "a \<noteq> 0" and "b \<noteq> 0" by auto
   224   with no_zero_divisors have "a * b \<noteq> 0" by blast
   225   with assms show ?thesis by simp
   226 qed
   227 
   228 end
   229 
   230 class semiring_1_cancel = semiring + cancel_comm_monoid_add
   231   + zero_neq_one + monoid_mult
   232 begin
   233 
   234 subclass semiring_0_cancel ..
   235 
   236 subclass semiring_1 ..
   237 
   238 end
   239 
   240 class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
   241   + zero_neq_one + comm_monoid_mult
   242 begin
   243 
   244 subclass semiring_1_cancel ..
   245 subclass comm_semiring_0_cancel ..
   246 subclass comm_semiring_1 ..
   247 
   248 end
   249 
   250 class ring = semiring + ab_group_add
   251 begin
   252 
   253 subclass semiring_0_cancel ..
   254 
   255 text {* Distribution rules *}
   256 
   257 lemma minus_mult_left: "- (a * b) = - a * b"
   258 by (rule minus_unique) (simp add: distrib_right [symmetric]) 
   259 
   260 lemma minus_mult_right: "- (a * b) = a * - b"
   261 by (rule minus_unique) (simp add: distrib_left [symmetric]) 
   262 
   263 text{*Extract signs from products*}
   264 lemmas mult_minus_left [simp] = minus_mult_left [symmetric]
   265 lemmas mult_minus_right [simp] = minus_mult_right [symmetric]
   266 
   267 lemma minus_mult_minus [simp]: "- a * - b = a * b"
   268 by simp
   269 
   270 lemma minus_mult_commute: "- a * b = a * - b"
   271 by simp
   272 
   273 lemma right_diff_distrib [algebra_simps, field_simps]:
   274   "a * (b - c) = a * b - a * c"
   275   using distrib_left [of a b "-c "] by simp
   276 
   277 lemma left_diff_distrib [algebra_simps, field_simps]:
   278   "(a - b) * c = a * c - b * c"
   279   using distrib_right [of a "- b" c] by simp
   280 
   281 lemmas ring_distribs =
   282   distrib_left distrib_right left_diff_distrib right_diff_distrib
   283 
   284 lemma eq_add_iff1:
   285   "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
   286 by (simp add: algebra_simps)
   287 
   288 lemma eq_add_iff2:
   289   "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
   290 by (simp add: algebra_simps)
   291 
   292 end
   293 
   294 lemmas ring_distribs =
   295   distrib_left distrib_right left_diff_distrib right_diff_distrib
   296 
   297 class comm_ring = comm_semiring + ab_group_add
   298 begin
   299 
   300 subclass ring ..
   301 subclass comm_semiring_0_cancel ..
   302 
   303 lemma square_diff_square_factored:
   304   "x * x - y * y = (x + y) * (x - y)"
   305   by (simp add: algebra_simps)
   306 
   307 end
   308 
   309 class ring_1 = ring + zero_neq_one + monoid_mult
   310 begin
   311 
   312 subclass semiring_1_cancel ..
   313 
   314 lemma square_diff_one_factored:
   315   "x * x - 1 = (x + 1) * (x - 1)"
   316   by (simp add: algebra_simps)
   317 
   318 end
   319 
   320 class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
   321   (*previously ring*)
   322 begin
   323 
   324 subclass ring_1 ..
   325 subclass comm_semiring_1_cancel ..
   326 
   327 lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
   328 proof
   329   assume "x dvd - y"
   330   then have "x dvd - 1 * - y" by (rule dvd_mult)
   331   then show "x dvd y" by simp
   332 next
   333   assume "x dvd y"
   334   then have "x dvd - 1 * y" by (rule dvd_mult)
   335   then show "x dvd - y" by simp
   336 qed
   337 
   338 lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
   339 proof
   340   assume "- x dvd y"
   341   then obtain k where "y = - x * k" ..
   342   then have "y = x * - k" by simp
   343   then show "x dvd y" ..
   344 next
   345   assume "x dvd y"
   346   then obtain k where "y = x * k" ..
   347   then have "y = - x * - k" by simp
   348   then show "- x dvd y" ..
   349 qed
   350 
   351 lemma dvd_diff [simp]:
   352   "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
   353   using dvd_add [of x y "- z"] by simp
   354 
   355 end
   356 
   357 class ring_no_zero_divisors = ring + no_zero_divisors
   358 begin
   359 
   360 lemma mult_eq_0_iff [simp]:
   361   shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
   362 proof (cases "a = 0 \<or> b = 0")
   363   case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
   364     then show ?thesis using no_zero_divisors by simp
   365 next
   366   case True then show ?thesis by auto
   367 qed
   368 
   369 text{*Cancellation of equalities with a common factor*}
   370 lemma mult_cancel_right [simp]:
   371   "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
   372 proof -
   373   have "(a * c = b * c) = ((a - b) * c = 0)"
   374     by (simp add: algebra_simps)
   375   thus ?thesis by (simp add: disj_commute)
   376 qed
   377 
   378 lemma mult_cancel_left [simp]:
   379   "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
   380 proof -
   381   have "(c * a = c * b) = (c * (a - b) = 0)"
   382     by (simp add: algebra_simps)
   383   thus ?thesis by simp
   384 qed
   385 
   386 lemma mult_left_cancel: "c \<noteq> 0 \<Longrightarrow> (c*a=c*b) = (a=b)"
   387 by simp 
   388 
   389 lemma mult_right_cancel: "c \<noteq> 0 \<Longrightarrow> (a*c=b*c) = (a=b)"
   390 by simp 
   391 
   392 end
   393 
   394 class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
   395 begin
   396 
   397 lemma square_eq_1_iff:
   398   "x * x = 1 \<longleftrightarrow> x = 1 \<or> x = - 1"
   399 proof -
   400   have "(x - 1) * (x + 1) = x * x - 1"
   401     by (simp add: algebra_simps)
   402   hence "x * x = 1 \<longleftrightarrow> (x - 1) * (x + 1) = 0"
   403     by simp
   404   thus ?thesis
   405     by (simp add: eq_neg_iff_add_eq_0)
   406 qed
   407 
   408 lemma mult_cancel_right1 [simp]:
   409   "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
   410 by (insert mult_cancel_right [of 1 c b], force)
   411 
   412 lemma mult_cancel_right2 [simp]:
   413   "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
   414 by (insert mult_cancel_right [of a c 1], simp)
   415  
   416 lemma mult_cancel_left1 [simp]:
   417   "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
   418 by (insert mult_cancel_left [of c 1 b], force)
   419 
   420 lemma mult_cancel_left2 [simp]:
   421   "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
   422 by (insert mult_cancel_left [of c a 1], simp)
   423 
   424 end
   425 
   426 class idom = comm_ring_1 + no_zero_divisors
   427 begin
   428 
   429 subclass ring_1_no_zero_divisors ..
   430 
   431 lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
   432 proof
   433   assume "a * a = b * b"
   434   then have "(a - b) * (a + b) = 0"
   435     by (simp add: algebra_simps)
   436   then show "a = b \<or> a = - b"
   437     by (simp add: eq_neg_iff_add_eq_0)
   438 next
   439   assume "a = b \<or> a = - b"
   440   then show "a * a = b * b" by auto
   441 qed
   442 
   443 lemma dvd_mult_cancel_right [simp]:
   444   "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
   445 proof -
   446   have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
   447     unfolding dvd_def by (simp add: ac_simps)
   448   also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
   449     unfolding dvd_def by simp
   450   finally show ?thesis .
   451 qed
   452 
   453 lemma dvd_mult_cancel_left [simp]:
   454   "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
   455 proof -
   456   have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
   457     unfolding dvd_def by (simp add: ac_simps)
   458   also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
   459     unfolding dvd_def by simp
   460   finally show ?thesis .
   461 qed
   462 
   463 end
   464 
   465 text {*
   466   The theory of partially ordered rings is taken from the books:
   467   \begin{itemize}
   468   \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
   469   \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
   470   \end{itemize}
   471   Most of the used notions can also be looked up in 
   472   \begin{itemize}
   473   \item @{url "http://www.mathworld.com"} by Eric Weisstein et. al.
   474   \item \emph{Algebra I} by van der Waerden, Springer.
   475   \end{itemize}
   476 *}
   477 
   478 class ordered_semiring = semiring + comm_monoid_add + ordered_ab_semigroup_add +
   479   assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
   480   assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
   481 begin
   482 
   483 lemma mult_mono:
   484   "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
   485 apply (erule mult_right_mono [THEN order_trans], assumption)
   486 apply (erule mult_left_mono, assumption)
   487 done
   488 
   489 lemma mult_mono':
   490   "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
   491 apply (rule mult_mono)
   492 apply (fast intro: order_trans)+
   493 done
   494 
   495 end
   496 
   497 class ordered_cancel_semiring = ordered_semiring + cancel_comm_monoid_add
   498 begin
   499 
   500 subclass semiring_0_cancel ..
   501 
   502 lemma mult_nonneg_nonneg[simp]: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
   503 using mult_left_mono [of 0 b a] by simp
   504 
   505 lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
   506 using mult_left_mono [of b 0 a] by simp
   507 
   508 lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
   509 using mult_right_mono [of a 0 b] by simp
   510 
   511 text {* Legacy - use @{text mult_nonpos_nonneg} *}
   512 lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
   513 by (drule mult_right_mono [of b 0], auto)
   514 
   515 lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
   516 by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
   517 
   518 end
   519 
   520 class linordered_semiring = ordered_semiring + linordered_cancel_ab_semigroup_add
   521 begin
   522 
   523 subclass ordered_cancel_semiring ..
   524 
   525 subclass ordered_comm_monoid_add ..
   526 
   527 lemma mult_left_less_imp_less:
   528   "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
   529 by (force simp add: mult_left_mono not_le [symmetric])
   530  
   531 lemma mult_right_less_imp_less:
   532   "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
   533 by (force simp add: mult_right_mono not_le [symmetric])
   534 
   535 end
   536 
   537 class linordered_semiring_1 = linordered_semiring + semiring_1
   538 begin
   539 
   540 lemma convex_bound_le:
   541   assumes "x \<le> a" "y \<le> a" "0 \<le> u" "0 \<le> v" "u + v = 1"
   542   shows "u * x + v * y \<le> a"
   543 proof-
   544   from assms have "u * x + v * y \<le> u * a + v * a"
   545     by (simp add: add_mono mult_left_mono)
   546   thus ?thesis using assms unfolding distrib_right[symmetric] by simp
   547 qed
   548 
   549 end
   550 
   551 class linordered_semiring_strict = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add +
   552   assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
   553   assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
   554 begin
   555 
   556 subclass semiring_0_cancel ..
   557 
   558 subclass linordered_semiring
   559 proof
   560   fix a b c :: 'a
   561   assume A: "a \<le> b" "0 \<le> c"
   562   from A show "c * a \<le> c * b"
   563     unfolding le_less
   564     using mult_strict_left_mono by (cases "c = 0") auto
   565   from A show "a * c \<le> b * c"
   566     unfolding le_less
   567     using mult_strict_right_mono by (cases "c = 0") auto
   568 qed
   569 
   570 lemma mult_left_le_imp_le:
   571   "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
   572 by (force simp add: mult_strict_left_mono _not_less [symmetric])
   573  
   574 lemma mult_right_le_imp_le:
   575   "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
   576 by (force simp add: mult_strict_right_mono not_less [symmetric])
   577 
   578 lemma mult_pos_pos[simp]: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
   579 using mult_strict_left_mono [of 0 b a] by simp
   580 
   581 lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
   582 using mult_strict_left_mono [of b 0 a] by simp
   583 
   584 lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
   585 using mult_strict_right_mono [of a 0 b] by simp
   586 
   587 text {* Legacy - use @{text mult_neg_pos} *}
   588 lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
   589 by (drule mult_strict_right_mono [of b 0], auto)
   590 
   591 lemma zero_less_mult_pos:
   592   "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
   593 apply (cases "b\<le>0")
   594  apply (auto simp add: le_less not_less)
   595 apply (drule_tac mult_pos_neg [of a b])
   596  apply (auto dest: less_not_sym)
   597 done
   598 
   599 lemma zero_less_mult_pos2:
   600   "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
   601 apply (cases "b\<le>0")
   602  apply (auto simp add: le_less not_less)
   603 apply (drule_tac mult_pos_neg2 [of a b])
   604  apply (auto dest: less_not_sym)
   605 done
   606 
   607 text{*Strict monotonicity in both arguments*}
   608 lemma mult_strict_mono:
   609   assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
   610   shows "a * c < b * d"
   611   using assms apply (cases "c=0")
   612   apply (simp)
   613   apply (erule mult_strict_right_mono [THEN less_trans])
   614   apply (force simp add: le_less)
   615   apply (erule mult_strict_left_mono, assumption)
   616   done
   617 
   618 text{*This weaker variant has more natural premises*}
   619 lemma mult_strict_mono':
   620   assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
   621   shows "a * c < b * d"
   622 by (rule mult_strict_mono) (insert assms, auto)
   623 
   624 lemma mult_less_le_imp_less:
   625   assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
   626   shows "a * c < b * d"
   627   using assms apply (subgoal_tac "a * c < b * c")
   628   apply (erule less_le_trans)
   629   apply (erule mult_left_mono)
   630   apply simp
   631   apply (erule mult_strict_right_mono)
   632   apply assumption
   633   done
   634 
   635 lemma mult_le_less_imp_less:
   636   assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
   637   shows "a * c < b * d"
   638   using assms apply (subgoal_tac "a * c \<le> b * c")
   639   apply (erule le_less_trans)
   640   apply (erule mult_strict_left_mono)
   641   apply simp
   642   apply (erule mult_right_mono)
   643   apply simp
   644   done
   645 
   646 lemma mult_less_imp_less_left:
   647   assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
   648   shows "a < b"
   649 proof (rule ccontr)
   650   assume "\<not>  a < b"
   651   hence "b \<le> a" by (simp add: linorder_not_less)
   652   hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
   653   with this and less show False by (simp add: not_less [symmetric])
   654 qed
   655 
   656 lemma mult_less_imp_less_right:
   657   assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
   658   shows "a < b"
   659 proof (rule ccontr)
   660   assume "\<not> a < b"
   661   hence "b \<le> a" by (simp add: linorder_not_less)
   662   hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
   663   with this and less show False by (simp add: not_less [symmetric])
   664 qed  
   665 
   666 end
   667 
   668 class linordered_semiring_1_strict = linordered_semiring_strict + semiring_1
   669 begin
   670 
   671 subclass linordered_semiring_1 ..
   672 
   673 lemma convex_bound_lt:
   674   assumes "x < a" "y < a" "0 \<le> u" "0 \<le> v" "u + v = 1"
   675   shows "u * x + v * y < a"
   676 proof -
   677   from assms have "u * x + v * y < u * a + v * a"
   678     by (cases "u = 0")
   679        (auto intro!: add_less_le_mono mult_strict_left_mono mult_left_mono)
   680   thus ?thesis using assms unfolding distrib_right[symmetric] by simp
   681 qed
   682 
   683 end
   684 
   685 class ordered_comm_semiring = comm_semiring_0 + ordered_ab_semigroup_add + 
   686   assumes comm_mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
   687 begin
   688 
   689 subclass ordered_semiring
   690 proof
   691   fix a b c :: 'a
   692   assume "a \<le> b" "0 \<le> c"
   693   thus "c * a \<le> c * b" by (rule comm_mult_left_mono)
   694   thus "a * c \<le> b * c" by (simp only: mult.commute)
   695 qed
   696 
   697 end
   698 
   699 class ordered_cancel_comm_semiring = ordered_comm_semiring + cancel_comm_monoid_add
   700 begin
   701 
   702 subclass comm_semiring_0_cancel ..
   703 subclass ordered_comm_semiring ..
   704 subclass ordered_cancel_semiring ..
   705 
   706 end
   707 
   708 class linordered_comm_semiring_strict = comm_semiring_0 + linordered_cancel_ab_semigroup_add +
   709   assumes comm_mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
   710 begin
   711 
   712 subclass linordered_semiring_strict
   713 proof
   714   fix a b c :: 'a
   715   assume "a < b" "0 < c"
   716   thus "c * a < c * b" by (rule comm_mult_strict_left_mono)
   717   thus "a * c < b * c" by (simp only: mult.commute)
   718 qed
   719 
   720 subclass ordered_cancel_comm_semiring
   721 proof
   722   fix a b c :: 'a
   723   assume "a \<le> b" "0 \<le> c"
   724   thus "c * a \<le> c * b"
   725     unfolding le_less
   726     using mult_strict_left_mono by (cases "c = 0") auto
   727 qed
   728 
   729 end
   730 
   731 class ordered_ring = ring + ordered_cancel_semiring 
   732 begin
   733 
   734 subclass ordered_ab_group_add ..
   735 
   736 lemma less_add_iff1:
   737   "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
   738 by (simp add: algebra_simps)
   739 
   740 lemma less_add_iff2:
   741   "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
   742 by (simp add: algebra_simps)
   743 
   744 lemma le_add_iff1:
   745   "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
   746 by (simp add: algebra_simps)
   747 
   748 lemma le_add_iff2:
   749   "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
   750 by (simp add: algebra_simps)
   751 
   752 lemma mult_left_mono_neg:
   753   "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
   754   apply (drule mult_left_mono [of _ _ "- c"])
   755   apply simp_all
   756   done
   757 
   758 lemma mult_right_mono_neg:
   759   "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
   760   apply (drule mult_right_mono [of _ _ "- c"])
   761   apply simp_all
   762   done
   763 
   764 lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
   765 using mult_right_mono_neg [of a 0 b] by simp
   766 
   767 lemma split_mult_pos_le:
   768   "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
   769 by (auto simp add: mult_nonpos_nonpos)
   770 
   771 end
   772 
   773 class linordered_ring = ring + linordered_semiring + linordered_ab_group_add + abs_if
   774 begin
   775 
   776 subclass ordered_ring ..
   777 
   778 subclass ordered_ab_group_add_abs
   779 proof
   780   fix a b
   781   show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
   782     by (auto simp add: abs_if not_le not_less algebra_simps simp del: add.commute dest: add_neg_neg add_nonneg_nonneg)
   783 qed (auto simp add: abs_if)
   784 
   785 lemma zero_le_square [simp]: "0 \<le> a * a"
   786   using linear [of 0 a]
   787   by (auto simp add: mult_nonpos_nonpos)
   788 
   789 lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
   790   by (simp add: not_less)
   791 
   792 end
   793 
   794 (* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
   795    Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
   796  *)
   797 class linordered_ring_strict = ring + linordered_semiring_strict
   798   + ordered_ab_group_add + abs_if
   799 begin
   800 
   801 subclass linordered_ring ..
   802 
   803 lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
   804 using mult_strict_left_mono [of b a "- c"] by simp
   805 
   806 lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
   807 using mult_strict_right_mono [of b a "- c"] by simp
   808 
   809 lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
   810 using mult_strict_right_mono_neg [of a 0 b] by simp
   811 
   812 subclass ring_no_zero_divisors
   813 proof
   814   fix a b
   815   assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
   816   assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
   817   have "a * b < 0 \<or> 0 < a * b"
   818   proof (cases "a < 0")
   819     case True note A' = this
   820     show ?thesis proof (cases "b < 0")
   821       case True with A'
   822       show ?thesis by (auto dest: mult_neg_neg)
   823     next
   824       case False with B have "0 < b" by auto
   825       with A' show ?thesis by (auto dest: mult_strict_right_mono)
   826     qed
   827   next
   828     case False with A have A': "0 < a" by auto
   829     show ?thesis proof (cases "b < 0")
   830       case True with A'
   831       show ?thesis by (auto dest: mult_strict_right_mono_neg)
   832     next
   833       case False with B have "0 < b" by auto
   834       with A' show ?thesis by auto
   835     qed
   836   qed
   837   then show "a * b \<noteq> 0" by (simp add: neq_iff)
   838 qed
   839 
   840 lemma zero_less_mult_iff: "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
   841   by (cases a 0 b 0 rule: linorder_cases[case_product linorder_cases])
   842      (auto simp add: mult_neg_neg not_less le_less dest: zero_less_mult_pos zero_less_mult_pos2)
   843 
   844 lemma zero_le_mult_iff: "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
   845   by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
   846 
   847 lemma mult_less_0_iff:
   848   "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
   849   apply (insert zero_less_mult_iff [of "-a" b])
   850   apply force
   851   done
   852 
   853 lemma mult_le_0_iff:
   854   "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
   855   apply (insert zero_le_mult_iff [of "-a" b]) 
   856   apply force
   857   done
   858 
   859 text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
   860    also with the relations @{text "\<le>"} and equality.*}
   861 
   862 text{*These ``disjunction'' versions produce two cases when the comparison is
   863  an assumption, but effectively four when the comparison is a goal.*}
   864 
   865 lemma mult_less_cancel_right_disj:
   866   "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
   867   apply (cases "c = 0")
   868   apply (auto simp add: neq_iff mult_strict_right_mono 
   869                       mult_strict_right_mono_neg)
   870   apply (auto simp add: not_less 
   871                       not_le [symmetric, of "a*c"]
   872                       not_le [symmetric, of a])
   873   apply (erule_tac [!] notE)
   874   apply (auto simp add: less_imp_le mult_right_mono 
   875                       mult_right_mono_neg)
   876   done
   877 
   878 lemma mult_less_cancel_left_disj:
   879   "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
   880   apply (cases "c = 0")
   881   apply (auto simp add: neq_iff mult_strict_left_mono 
   882                       mult_strict_left_mono_neg)
   883   apply (auto simp add: not_less 
   884                       not_le [symmetric, of "c*a"]
   885                       not_le [symmetric, of a])
   886   apply (erule_tac [!] notE)
   887   apply (auto simp add: less_imp_le mult_left_mono 
   888                       mult_left_mono_neg)
   889   done
   890 
   891 text{*The ``conjunction of implication'' lemmas produce two cases when the
   892 comparison is a goal, but give four when the comparison is an assumption.*}
   893 
   894 lemma mult_less_cancel_right:
   895   "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
   896   using mult_less_cancel_right_disj [of a c b] by auto
   897 
   898 lemma mult_less_cancel_left:
   899   "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
   900   using mult_less_cancel_left_disj [of c a b] by auto
   901 
   902 lemma mult_le_cancel_right:
   903    "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
   904 by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
   905 
   906 lemma mult_le_cancel_left:
   907   "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
   908 by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
   909 
   910 lemma mult_le_cancel_left_pos:
   911   "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
   912 by (auto simp: mult_le_cancel_left)
   913 
   914 lemma mult_le_cancel_left_neg:
   915   "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
   916 by (auto simp: mult_le_cancel_left)
   917 
   918 lemma mult_less_cancel_left_pos:
   919   "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
   920 by (auto simp: mult_less_cancel_left)
   921 
   922 lemma mult_less_cancel_left_neg:
   923   "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
   924 by (auto simp: mult_less_cancel_left)
   925 
   926 end
   927 
   928 lemmas mult_sign_intros =
   929   mult_nonneg_nonneg mult_nonneg_nonpos
   930   mult_nonpos_nonneg mult_nonpos_nonpos
   931   mult_pos_pos mult_pos_neg
   932   mult_neg_pos mult_neg_neg
   933 
   934 class ordered_comm_ring = comm_ring + ordered_comm_semiring
   935 begin
   936 
   937 subclass ordered_ring ..
   938 subclass ordered_cancel_comm_semiring ..
   939 
   940 end
   941 
   942 class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
   943   (*previously linordered_semiring*)
   944   assumes zero_less_one [simp]: "0 < 1"
   945 begin
   946 
   947 lemma pos_add_strict:
   948   shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
   949   using add_strict_mono [of 0 a b c] by simp
   950 
   951 lemma zero_le_one [simp]: "0 \<le> 1"
   952 by (rule zero_less_one [THEN less_imp_le]) 
   953 
   954 lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
   955 by (simp add: not_le) 
   956 
   957 lemma not_one_less_zero [simp]: "\<not> 1 < 0"
   958 by (simp add: not_less) 
   959 
   960 lemma less_1_mult:
   961   assumes "1 < m" and "1 < n"
   962   shows "1 < m * n"
   963   using assms mult_strict_mono [of 1 m 1 n]
   964     by (simp add:  less_trans [OF zero_less_one]) 
   965 
   966 end
   967 
   968 class linordered_idom = comm_ring_1 +
   969   linordered_comm_semiring_strict + ordered_ab_group_add +
   970   abs_if + sgn_if
   971   (*previously linordered_ring*)
   972 begin
   973 
   974 subclass linordered_semiring_1_strict ..
   975 subclass linordered_ring_strict ..
   976 subclass ordered_comm_ring ..
   977 subclass idom ..
   978 
   979 subclass linordered_semidom
   980 proof
   981   have "0 \<le> 1 * 1" by (rule zero_le_square)
   982   thus "0 < 1" by (simp add: le_less)
   983 qed 
   984 
   985 lemma linorder_neqE_linordered_idom:
   986   assumes "x \<noteq> y" obtains "x < y" | "y < x"
   987   using assms by (rule neqE)
   988 
   989 text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
   990 
   991 lemma mult_le_cancel_right1:
   992   "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
   993 by (insert mult_le_cancel_right [of 1 c b], simp)
   994 
   995 lemma mult_le_cancel_right2:
   996   "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
   997 by (insert mult_le_cancel_right [of a c 1], simp)
   998 
   999 lemma mult_le_cancel_left1:
  1000   "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
  1001 by (insert mult_le_cancel_left [of c 1 b], simp)
  1002 
  1003 lemma mult_le_cancel_left2:
  1004   "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
  1005 by (insert mult_le_cancel_left [of c a 1], simp)
  1006 
  1007 lemma mult_less_cancel_right1:
  1008   "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
  1009 by (insert mult_less_cancel_right [of 1 c b], simp)
  1010 
  1011 lemma mult_less_cancel_right2:
  1012   "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
  1013 by (insert mult_less_cancel_right [of a c 1], simp)
  1014 
  1015 lemma mult_less_cancel_left1:
  1016   "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
  1017 by (insert mult_less_cancel_left [of c 1 b], simp)
  1018 
  1019 lemma mult_less_cancel_left2:
  1020   "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
  1021 by (insert mult_less_cancel_left [of c a 1], simp)
  1022 
  1023 lemma sgn_sgn [simp]:
  1024   "sgn (sgn a) = sgn a"
  1025 unfolding sgn_if by simp
  1026 
  1027 lemma sgn_0_0:
  1028   "sgn a = 0 \<longleftrightarrow> a = 0"
  1029 unfolding sgn_if by simp
  1030 
  1031 lemma sgn_1_pos:
  1032   "sgn a = 1 \<longleftrightarrow> a > 0"
  1033 unfolding sgn_if by simp
  1034 
  1035 lemma sgn_1_neg:
  1036   "sgn a = - 1 \<longleftrightarrow> a < 0"
  1037 unfolding sgn_if by auto
  1038 
  1039 lemma sgn_pos [simp]:
  1040   "0 < a \<Longrightarrow> sgn a = 1"
  1041 unfolding sgn_1_pos .
  1042 
  1043 lemma sgn_neg [simp]:
  1044   "a < 0 \<Longrightarrow> sgn a = - 1"
  1045 unfolding sgn_1_neg .
  1046 
  1047 lemma sgn_times:
  1048   "sgn (a * b) = sgn a * sgn b"
  1049 by (auto simp add: sgn_if zero_less_mult_iff)
  1050 
  1051 lemma abs_sgn: "\<bar>k\<bar> = k * sgn k"
  1052 unfolding sgn_if abs_if by auto
  1053 
  1054 lemma sgn_greater [simp]:
  1055   "0 < sgn a \<longleftrightarrow> 0 < a"
  1056   unfolding sgn_if by auto
  1057 
  1058 lemma sgn_less [simp]:
  1059   "sgn a < 0 \<longleftrightarrow> a < 0"
  1060   unfolding sgn_if by auto
  1061 
  1062 lemma abs_dvd_iff [simp]: "\<bar>m\<bar> dvd k \<longleftrightarrow> m dvd k"
  1063   by (simp add: abs_if)
  1064 
  1065 lemma dvd_abs_iff [simp]: "m dvd \<bar>k\<bar> \<longleftrightarrow> m dvd k"
  1066   by (simp add: abs_if)
  1067 
  1068 lemma dvd_if_abs_eq:
  1069   "\<bar>l\<bar> = \<bar>k\<bar> \<Longrightarrow> l dvd k"
  1070 by(subst abs_dvd_iff[symmetric]) simp
  1071 
  1072 text {* The following lemmas can be proven in more general structures, but
  1073 are dangerous as simp rules in absence of @{thm neg_equal_zero}, 
  1074 @{thm neg_less_pos}, @{thm neg_less_eq_nonneg}. *}
  1075 
  1076 lemma equation_minus_iff_1 [simp, no_atp]:
  1077   "1 = - a \<longleftrightarrow> a = - 1"
  1078   by (fact equation_minus_iff)
  1079 
  1080 lemma minus_equation_iff_1 [simp, no_atp]:
  1081   "- a = 1 \<longleftrightarrow> a = - 1"
  1082   by (subst minus_equation_iff, auto)
  1083 
  1084 lemma le_minus_iff_1 [simp, no_atp]:
  1085   "1 \<le> - b \<longleftrightarrow> b \<le> - 1"
  1086   by (fact le_minus_iff)
  1087 
  1088 lemma minus_le_iff_1 [simp, no_atp]:
  1089   "- a \<le> 1 \<longleftrightarrow> - 1 \<le> a"
  1090   by (fact minus_le_iff)
  1091 
  1092 lemma less_minus_iff_1 [simp, no_atp]:
  1093   "1 < - b \<longleftrightarrow> b < - 1"
  1094   by (fact less_minus_iff)
  1095 
  1096 lemma minus_less_iff_1 [simp, no_atp]:
  1097   "- a < 1 \<longleftrightarrow> - 1 < a"
  1098   by (fact minus_less_iff)
  1099 
  1100 end
  1101 
  1102 text {* Simprules for comparisons where common factors can be cancelled. *}
  1103 
  1104 lemmas mult_compare_simps =
  1105     mult_le_cancel_right mult_le_cancel_left
  1106     mult_le_cancel_right1 mult_le_cancel_right2
  1107     mult_le_cancel_left1 mult_le_cancel_left2
  1108     mult_less_cancel_right mult_less_cancel_left
  1109     mult_less_cancel_right1 mult_less_cancel_right2
  1110     mult_less_cancel_left1 mult_less_cancel_left2
  1111     mult_cancel_right mult_cancel_left
  1112     mult_cancel_right1 mult_cancel_right2
  1113     mult_cancel_left1 mult_cancel_left2
  1114 
  1115 text {* Reasoning about inequalities with division *}
  1116 
  1117 context linordered_semidom
  1118 begin
  1119 
  1120 lemma less_add_one: "a < a + 1"
  1121 proof -
  1122   have "a + 0 < a + 1"
  1123     by (blast intro: zero_less_one add_strict_left_mono)
  1124   thus ?thesis by simp
  1125 qed
  1126 
  1127 lemma zero_less_two: "0 < 1 + 1"
  1128 by (blast intro: less_trans zero_less_one less_add_one)
  1129 
  1130 end
  1131 
  1132 context linordered_idom
  1133 begin
  1134 
  1135 lemma mult_right_le_one_le:
  1136   "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> x * y \<le> x"
  1137   by (auto simp add: mult_le_cancel_left2)
  1138 
  1139 lemma mult_left_le_one_le:
  1140   "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> y * x \<le> x"
  1141   by (auto simp add: mult_le_cancel_right2)
  1142 
  1143 end
  1144 
  1145 text {* Absolute Value *}
  1146 
  1147 context linordered_idom
  1148 begin
  1149 
  1150 lemma mult_sgn_abs:
  1151   "sgn x * \<bar>x\<bar> = x"
  1152   unfolding abs_if sgn_if by auto
  1153 
  1154 lemma abs_one [simp]:
  1155   "\<bar>1\<bar> = 1"
  1156   by (simp add: abs_if)
  1157 
  1158 end
  1159 
  1160 class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
  1161   assumes abs_eq_mult:
  1162     "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0) \<Longrightarrow> \<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
  1163 
  1164 context linordered_idom
  1165 begin
  1166 
  1167 subclass ordered_ring_abs proof
  1168 qed (auto simp add: abs_if not_less mult_less_0_iff)
  1169 
  1170 lemma abs_mult:
  1171   "\<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>" 
  1172   by (rule abs_eq_mult) auto
  1173 
  1174 lemma abs_mult_self:
  1175   "\<bar>a\<bar> * \<bar>a\<bar> = a * a"
  1176   by (simp add: abs_if) 
  1177 
  1178 lemma abs_mult_less:
  1179   "\<bar>a\<bar> < c \<Longrightarrow> \<bar>b\<bar> < d \<Longrightarrow> \<bar>a\<bar> * \<bar>b\<bar> < c * d"
  1180 proof -
  1181   assume ac: "\<bar>a\<bar> < c"
  1182   hence cpos: "0<c" by (blast intro: le_less_trans abs_ge_zero)
  1183   assume "\<bar>b\<bar> < d"
  1184   thus ?thesis by (simp add: ac cpos mult_strict_mono) 
  1185 qed
  1186 
  1187 lemma abs_less_iff:
  1188   "\<bar>a\<bar> < b \<longleftrightarrow> a < b \<and> - a < b" 
  1189   by (simp add: less_le abs_le_iff) (auto simp add: abs_if)
  1190 
  1191 lemma abs_mult_pos:
  1192   "0 \<le> x \<Longrightarrow> \<bar>y\<bar> * x = \<bar>y * x\<bar>"
  1193   by (simp add: abs_mult)
  1194 
  1195 lemma abs_diff_less_iff:
  1196   "\<bar>x - a\<bar> < r \<longleftrightarrow> a - r < x \<and> x < a + r"
  1197   by (auto simp add: diff_less_eq ac_simps abs_less_iff)
  1198 
  1199 end
  1200 
  1201 code_identifier
  1202   code_module Rings \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
  1203 
  1204 end
  1205