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