src/HOL/Ring_and_Field.thy
author wenzelm
Thu Jun 14 18:33:31 2007 +0200 (2007-06-14)
changeset 23389 aaca6a8e5414
parent 23326 71e99443e17d
child 23398 0b5a400c7595
permissions -rw-r--r--
tuned proofs: avoid implicit prems;
     1 (*  Title:   HOL/Ring_and_Field.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) Rings and Fields *}
     8 
     9 theory Ring_and_Field
    10 imports OrderedGroup
    11 begin
    12 
    13 text {*
    14   The theory of partially ordered rings is taken from the books:
    15   \begin{itemize}
    16   \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
    17   \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
    18   \end{itemize}
    19   Most of the used notions can also be looked up in 
    20   \begin{itemize}
    21   \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
    22   \item \emph{Algebra I} by van der Waerden, Springer.
    23   \end{itemize}
    24 *}
    25 
    26 class semiring = ab_semigroup_add + semigroup_mult +
    27   assumes left_distrib: "(a \<^loc>+ b) \<^loc>* c = a \<^loc>* c \<^loc>+ b \<^loc>* c"
    28   assumes right_distrib: "a \<^loc>* (b \<^loc>+ c) = a \<^loc>* b \<^loc>+ a \<^loc>* c"
    29 
    30 class mult_zero = times + zero +
    31   assumes mult_zero_left [simp]: "\<^loc>0 \<^loc>* a = \<^loc>0"
    32   assumes mult_zero_right [simp]: "a \<^loc>* \<^loc>0 = \<^loc>0"
    33 
    34 class semiring_0 = semiring + comm_monoid_add + mult_zero
    35 
    36 class semiring_0_cancel = semiring + comm_monoid_add + cancel_ab_semigroup_add
    37 
    38 instance semiring_0_cancel \<subseteq> semiring_0
    39 proof
    40   fix a :: 'a
    41   have "0 * a + 0 * a = 0 * a + 0"
    42     by (simp add: left_distrib [symmetric])
    43   thus "0 * a = 0"
    44     by (simp only: add_left_cancel)
    45 
    46   have "a * 0 + a * 0 = a * 0 + 0"
    47     by (simp add: right_distrib [symmetric])
    48   thus "a * 0 = 0"
    49     by (simp only: add_left_cancel)
    50 qed
    51 
    52 class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
    53   assumes distrib: "(a \<^loc>+ b) \<^loc>* c = a \<^loc>* c \<^loc>+ b \<^loc>* c"
    54 
    55 instance comm_semiring \<subseteq> semiring
    56 proof
    57   fix a b c :: 'a
    58   show "(a + b) * c = a * c + b * c" by (simp add: distrib)
    59   have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
    60   also have "... = b * a + c * a" by (simp only: distrib)
    61   also have "... = a * b + a * c" by (simp add: mult_ac)
    62   finally show "a * (b + c) = a * b + a * c" by blast
    63 qed
    64 
    65 class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
    66 
    67 instance comm_semiring_0 \<subseteq> semiring_0 ..
    68 
    69 class comm_semiring_0_cancel = comm_semiring + comm_monoid_add + cancel_ab_semigroup_add
    70 
    71 instance comm_semiring_0_cancel \<subseteq> semiring_0_cancel ..
    72 
    73 instance comm_semiring_0_cancel \<subseteq> comm_semiring_0 ..
    74 
    75 class zero_neq_one = zero + one +
    76   assumes zero_neq_one [simp]: "\<^loc>0 \<noteq> \<^loc>1"
    77 
    78 class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
    79 
    80 class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult
    81   (*previously almost_semiring*)
    82 
    83 instance comm_semiring_1 \<subseteq> semiring_1 ..
    84 
    85 class no_zero_divisors = zero + times +
    86   assumes no_zero_divisors: "a \<noteq> \<^loc>0 \<Longrightarrow> b \<noteq> \<^loc>0 \<Longrightarrow> a \<^loc>* b \<noteq> \<^loc>0"
    87 
    88 class semiring_1_cancel = semiring + comm_monoid_add + zero_neq_one
    89   + cancel_ab_semigroup_add + monoid_mult
    90 
    91 instance semiring_1_cancel \<subseteq> semiring_0_cancel ..
    92 
    93 instance semiring_1_cancel \<subseteq> semiring_1 ..
    94 
    95 class comm_semiring_1_cancel = comm_semiring + comm_monoid_add + comm_monoid_mult
    96   + zero_neq_one + cancel_ab_semigroup_add
    97 
    98 instance comm_semiring_1_cancel \<subseteq> semiring_1_cancel ..
    99 
   100 instance comm_semiring_1_cancel \<subseteq> comm_semiring_0_cancel ..
   101 
   102 instance comm_semiring_1_cancel \<subseteq> comm_semiring_1 ..
   103 
   104 class ring = semiring + ab_group_add
   105 
   106 instance ring \<subseteq> semiring_0_cancel ..
   107 
   108 class comm_ring = comm_semiring + ab_group_add
   109 
   110 instance comm_ring \<subseteq> ring ..
   111 
   112 instance comm_ring \<subseteq> comm_semiring_0_cancel ..
   113 
   114 class ring_1 = ring + zero_neq_one + monoid_mult
   115 
   116 instance ring_1 \<subseteq> semiring_1_cancel ..
   117 
   118 class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
   119   (*previously ring*)
   120 
   121 instance comm_ring_1 \<subseteq> ring_1 ..
   122 
   123 instance comm_ring_1 \<subseteq> comm_semiring_1_cancel ..
   124 
   125 class ring_no_zero_divisors = ring + no_zero_divisors
   126 
   127 class dom = ring_1 + ring_no_zero_divisors
   128 hide const dom
   129 
   130 class idom = comm_ring_1 + no_zero_divisors
   131 
   132 instance idom \<subseteq> dom ..
   133 
   134 class division_ring = ring_1 + inverse +
   135   assumes left_inverse [simp]:  "a \<noteq> \<^loc>0 \<Longrightarrow> inverse a \<^loc>* a = \<^loc>1"
   136   assumes right_inverse [simp]: "a \<noteq> \<^loc>0 \<Longrightarrow> a \<^loc>* inverse a = \<^loc>1"
   137 
   138 instance division_ring \<subseteq> dom
   139 proof
   140   fix a b :: 'a
   141   assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
   142   show "a * b \<noteq> 0"
   143   proof
   144     assume ab: "a * b = 0"
   145     hence "0 = inverse a * (a * b) * inverse b"
   146       by simp
   147     also have "\<dots> = (inverse a * a) * (b * inverse b)"
   148       by (simp only: mult_assoc)
   149     also have "\<dots> = 1"
   150       using a b by simp
   151     finally show False
   152       by simp
   153   qed
   154 qed
   155 
   156 class field = comm_ring_1 + inverse +
   157   assumes field_inverse:  "a \<noteq> 0 \<Longrightarrow> inverse a \<^loc>* a = \<^loc>1"
   158   assumes divide_inverse: "a \<^loc>/ b = a \<^loc>* inverse b"
   159 
   160 instance field \<subseteq> division_ring
   161 proof
   162   fix a :: 'a
   163   assume "a \<noteq> 0"
   164   thus "inverse a * a = 1" by (rule field_inverse)
   165   thus "a * inverse a = 1" by (simp only: mult_commute)
   166 qed
   167 
   168 instance field \<subseteq> idom ..
   169 
   170 class division_by_zero = zero + inverse +
   171   assumes inverse_zero [simp]: "inverse \<^loc>0 = \<^loc>0"
   172 
   173 
   174 subsection {* Distribution rules *}
   175 
   176 theorems ring_distrib = right_distrib left_distrib
   177 
   178 text{*For the @{text combine_numerals} simproc*}
   179 lemma combine_common_factor:
   180      "a*e + (b*e + c) = (a+b)*e + (c::'a::semiring)"
   181 by (simp add: left_distrib add_ac)
   182 
   183 lemma minus_mult_left: "- (a * b) = (-a) * (b::'a::ring)"
   184 apply (rule equals_zero_I)
   185 apply (simp add: left_distrib [symmetric]) 
   186 done
   187 
   188 lemma minus_mult_right: "- (a * b) = a * -(b::'a::ring)"
   189 apply (rule equals_zero_I)
   190 apply (simp add: right_distrib [symmetric]) 
   191 done
   192 
   193 lemma minus_mult_minus [simp]: "(- a) * (- b) = a * (b::'a::ring)"
   194   by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
   195 
   196 lemma minus_mult_commute: "(- a) * b = a * (- b::'a::ring)"
   197   by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
   198 
   199 lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)"
   200 by (simp add: right_distrib diff_minus 
   201               minus_mult_left [symmetric] minus_mult_right [symmetric]) 
   202 
   203 lemma left_diff_distrib: "(a - b) * c = a * c - b * (c::'a::ring)"
   204 by (simp add: left_distrib diff_minus 
   205               minus_mult_left [symmetric] minus_mult_right [symmetric]) 
   206 
   207 class mult_mono = times + zero + ord +
   208   assumes mult_left_mono: "a \<sqsubseteq> b \<Longrightarrow> \<^loc>0 \<sqsubseteq> c \<Longrightarrow> c \<^loc>* a \<sqsubseteq> c \<^loc>* b"
   209   assumes mult_right_mono: "a \<sqsubseteq> b \<Longrightarrow> \<^loc>0 \<sqsubseteq> c \<Longrightarrow> a \<^loc>* c \<sqsubseteq> b \<^loc>* c"
   210 
   211 class pordered_semiring = mult_mono + semiring_0 + pordered_ab_semigroup_add 
   212 
   213 class pordered_cancel_semiring = mult_mono + pordered_ab_semigroup_add
   214   + semiring + comm_monoid_add + cancel_ab_semigroup_add
   215 
   216 instance pordered_cancel_semiring \<subseteq> semiring_0_cancel ..
   217 
   218 instance pordered_cancel_semiring \<subseteq> pordered_semiring .. 
   219 
   220 class ordered_semiring_strict = semiring + comm_monoid_add + ordered_cancel_ab_semigroup_add +
   221   assumes mult_strict_left_mono: "a \<sqsubset> b \<Longrightarrow> \<^loc>0 \<sqsubset> c \<Longrightarrow> c \<^loc>* a \<sqsubset> c \<^loc>* b"
   222   assumes mult_strict_right_mono: "a \<sqsubset> b \<Longrightarrow> \<^loc>0 \<sqsubset> c \<Longrightarrow> a \<^loc>* c \<sqsubset> b \<^loc>* c"
   223 
   224 instance ordered_semiring_strict \<subseteq> semiring_0_cancel ..
   225 
   226 instance ordered_semiring_strict \<subseteq> pordered_cancel_semiring
   227 apply intro_classes
   228 apply (cases "a < b & 0 < c")
   229 apply (auto simp add: mult_strict_left_mono order_less_le)
   230 apply (auto simp add: mult_strict_left_mono order_le_less)
   231 apply (simp add: mult_strict_right_mono)
   232 done
   233 
   234 class mult_mono1 = times + zero + ord +
   235   assumes mult_mono: "a \<sqsubseteq> b \<Longrightarrow> \<^loc>0 \<sqsubseteq> c \<Longrightarrow> c \<^loc>* a \<sqsubseteq> c \<^loc>* b"
   236 
   237 class pordered_comm_semiring = comm_semiring_0
   238   + pordered_ab_semigroup_add + mult_mono1
   239 
   240 class pordered_cancel_comm_semiring = comm_semiring_0_cancel
   241   + pordered_ab_semigroup_add + mult_mono1
   242   
   243 instance pordered_cancel_comm_semiring \<subseteq> pordered_comm_semiring ..
   244 
   245 class ordered_comm_semiring_strict = comm_semiring_0 + ordered_cancel_ab_semigroup_add +
   246   assumes mult_strict_mono: "a \<sqsubset> b \<Longrightarrow> \<^loc>0 \<sqsubset> c \<Longrightarrow> c \<^loc>* a \<sqsubset> c \<^loc>* b"
   247 
   248 instance pordered_comm_semiring \<subseteq> pordered_semiring
   249 proof
   250   fix a b c :: 'a
   251   assume A: "a <= b" "0 <= c"
   252   with mult_mono show "c * a <= c * b" .
   253 
   254   from mult_commute have "a * c = c * a" ..
   255   also from mult_mono A have "\<dots> <= c * b" .
   256   also from mult_commute have "c * b = b * c" ..
   257   finally show "a * c <= b * c" .
   258 qed
   259 
   260 instance pordered_cancel_comm_semiring \<subseteq> pordered_cancel_semiring ..
   261 
   262 instance ordered_comm_semiring_strict \<subseteq> ordered_semiring_strict
   263 by (intro_classes, insert mult_strict_mono, simp_all add: mult_commute, blast+)
   264 
   265 instance ordered_comm_semiring_strict \<subseteq> pordered_cancel_comm_semiring
   266 apply (intro_classes)
   267 apply (cases "a < b & 0 < c")
   268 apply (auto simp add: mult_strict_left_mono order_less_le)
   269 apply (auto simp add: mult_strict_left_mono order_le_less)
   270 done
   271 
   272 class pordered_ring = ring + pordered_cancel_semiring 
   273 
   274 instance pordered_ring \<subseteq> pordered_ab_group_add ..
   275 
   276 class lordered_ring = pordered_ring + lordered_ab_group_abs
   277 
   278 instance lordered_ring \<subseteq> lordered_ab_group_meet ..
   279 
   280 instance lordered_ring \<subseteq> lordered_ab_group_join ..
   281 
   282 class abs_if = minus + ord + zero +
   283   assumes abs_if: "abs a = (if a \<sqsubset> 0 then (uminus a) else a)"
   284 
   285 class ordered_ring_strict = ring + ordered_semiring_strict + abs_if + lordered_ab_group
   286 
   287 instance ordered_ring_strict \<subseteq> lordered_ring
   288   by intro_classes (simp add: abs_if sup_eq_if)
   289 
   290 class pordered_comm_ring = comm_ring + pordered_comm_semiring
   291 
   292 instance pordered_comm_ring \<subseteq> pordered_cancel_comm_semiring ..
   293 
   294 class ordered_semidom = comm_semiring_1_cancel + ordered_comm_semiring_strict +
   295   (*previously ordered_semiring*)
   296   assumes zero_less_one [simp]: "\<^loc>0 \<sqsubset> \<^loc>1"
   297 
   298 class ordered_idom = comm_ring_1 + ordered_comm_semiring_strict + abs_if + lordered_ab_group
   299   (*previously ordered_ring*)
   300 
   301 instance ordered_idom \<subseteq> ordered_ring_strict ..
   302 
   303 instance ordered_idom \<subseteq> pordered_comm_ring ..
   304 
   305 class ordered_field = field + ordered_idom
   306 
   307 lemmas linorder_neqE_ordered_idom =
   308  linorder_neqE[where 'a = "?'b::ordered_idom"]
   309 
   310 lemma eq_add_iff1:
   311      "(a*e + c = b*e + d) = ((a-b)*e + c = (d::'a::ring))"
   312 apply (simp add: diff_minus left_distrib)
   313 apply (simp add: diff_minus left_distrib add_ac)
   314 apply (simp add: compare_rls minus_mult_left [symmetric])
   315 done
   316 
   317 lemma eq_add_iff2:
   318      "(a*e + c = b*e + d) = (c = (b-a)*e + (d::'a::ring))"
   319 apply (simp add: diff_minus left_distrib add_ac)
   320 apply (simp add: compare_rls minus_mult_left [symmetric]) 
   321 done
   322 
   323 lemma less_add_iff1:
   324      "(a*e + c < b*e + d) = ((a-b)*e + c < (d::'a::pordered_ring))"
   325 apply (simp add: diff_minus left_distrib add_ac)
   326 apply (simp add: compare_rls minus_mult_left [symmetric]) 
   327 done
   328 
   329 lemma less_add_iff2:
   330      "(a*e + c < b*e + d) = (c < (b-a)*e + (d::'a::pordered_ring))"
   331 apply (simp add: diff_minus left_distrib add_ac)
   332 apply (simp add: compare_rls minus_mult_left [symmetric]) 
   333 done
   334 
   335 lemma le_add_iff1:
   336      "(a*e + c \<le> b*e + d) = ((a-b)*e + c \<le> (d::'a::pordered_ring))"
   337 apply (simp add: diff_minus left_distrib add_ac)
   338 apply (simp add: compare_rls minus_mult_left [symmetric]) 
   339 done
   340 
   341 lemma le_add_iff2:
   342      "(a*e + c \<le> b*e + d) = (c \<le> (b-a)*e + (d::'a::pordered_ring))"
   343 apply (simp add: diff_minus left_distrib add_ac)
   344 apply (simp add: compare_rls minus_mult_left [symmetric]) 
   345 done
   346 
   347 
   348 subsection {* Ordering Rules for Multiplication *}
   349 
   350 lemma mult_left_le_imp_le:
   351      "[|c*a \<le> c*b; 0 < c|] ==> a \<le> (b::'a::ordered_semiring_strict)"
   352   by (force simp add: mult_strict_left_mono linorder_not_less [symmetric])
   353  
   354 lemma mult_right_le_imp_le:
   355      "[|a*c \<le> b*c; 0 < c|] ==> a \<le> (b::'a::ordered_semiring_strict)"
   356   by (force simp add: mult_strict_right_mono linorder_not_less [symmetric])
   357 
   358 lemma mult_left_less_imp_less:
   359      "[|c*a < c*b; 0 \<le> c|] ==> a < (b::'a::ordered_semiring_strict)"
   360   by (force simp add: mult_left_mono linorder_not_le [symmetric])
   361  
   362 lemma mult_right_less_imp_less:
   363      "[|a*c < b*c; 0 \<le> c|] ==> a < (b::'a::ordered_semiring_strict)"
   364   by (force simp add: mult_right_mono linorder_not_le [symmetric])
   365 
   366 lemma mult_strict_left_mono_neg:
   367      "[|b < a; c < 0|] ==> c * a < c * (b::'a::ordered_ring_strict)"
   368 apply (drule mult_strict_left_mono [of _ _ "-c"])
   369 apply (simp_all add: minus_mult_left [symmetric]) 
   370 done
   371 
   372 lemma mult_left_mono_neg:
   373      "[|b \<le> a; c \<le> 0|] ==> c * a \<le>  c * (b::'a::pordered_ring)"
   374 apply (drule mult_left_mono [of _ _ "-c"])
   375 apply (simp_all add: minus_mult_left [symmetric]) 
   376 done
   377 
   378 lemma mult_strict_right_mono_neg:
   379      "[|b < a; c < 0|] ==> a * c < b * (c::'a::ordered_ring_strict)"
   380 apply (drule mult_strict_right_mono [of _ _ "-c"])
   381 apply (simp_all add: minus_mult_right [symmetric]) 
   382 done
   383 
   384 lemma mult_right_mono_neg:
   385      "[|b \<le> a; c \<le> 0|] ==> a * c \<le>  (b::'a::pordered_ring) * c"
   386 apply (drule mult_right_mono [of _ _ "-c"])
   387 apply (simp)
   388 apply (simp_all add: minus_mult_right [symmetric]) 
   389 done
   390 
   391 
   392 subsection{* Products of Signs *}
   393 
   394 lemma mult_pos_pos: "[| (0::'a::ordered_semiring_strict) < a; 0 < b |] ==> 0 < a*b"
   395 by (drule mult_strict_left_mono [of 0 b], auto)
   396 
   397 lemma mult_nonneg_nonneg: "[| (0::'a::pordered_cancel_semiring) \<le> a; 0 \<le> b |] ==> 0 \<le> a*b"
   398 by (drule mult_left_mono [of 0 b], auto)
   399 
   400 lemma mult_pos_neg: "[| (0::'a::ordered_semiring_strict) < a; b < 0 |] ==> a*b < 0"
   401 by (drule mult_strict_left_mono [of b 0], auto)
   402 
   403 lemma mult_nonneg_nonpos: "[| (0::'a::pordered_cancel_semiring) \<le> a; b \<le> 0 |] ==> a*b \<le> 0"
   404 by (drule mult_left_mono [of b 0], auto)
   405 
   406 lemma mult_pos_neg2: "[| (0::'a::ordered_semiring_strict) < a; b < 0 |] ==> b*a < 0" 
   407 by (drule mult_strict_right_mono[of b 0], auto)
   408 
   409 lemma mult_nonneg_nonpos2: "[| (0::'a::pordered_cancel_semiring) \<le> a; b \<le> 0 |] ==> b*a \<le> 0" 
   410 by (drule mult_right_mono[of b 0], auto)
   411 
   412 lemma mult_neg_neg: "[| a < (0::'a::ordered_ring_strict); b < 0 |] ==> 0 < a*b"
   413 by (drule mult_strict_right_mono_neg, auto)
   414 
   415 lemma mult_nonpos_nonpos: "[| a \<le> (0::'a::pordered_ring); b \<le> 0 |] ==> 0 \<le> a*b"
   416 by (drule mult_right_mono_neg[of a 0 b ], auto)
   417 
   418 lemma zero_less_mult_pos:
   419      "[| 0 < a*b; 0 < a|] ==> 0 < (b::'a::ordered_semiring_strict)"
   420 apply (cases "b\<le>0") 
   421  apply (auto simp add: order_le_less linorder_not_less)
   422 apply (drule_tac mult_pos_neg [of a b]) 
   423  apply (auto dest: order_less_not_sym)
   424 done
   425 
   426 lemma zero_less_mult_pos2:
   427      "[| 0 < b*a; 0 < a|] ==> 0 < (b::'a::ordered_semiring_strict)"
   428 apply (cases "b\<le>0") 
   429  apply (auto simp add: order_le_less linorder_not_less)
   430 apply (drule_tac mult_pos_neg2 [of a b]) 
   431  apply (auto dest: order_less_not_sym)
   432 done
   433 
   434 lemma zero_less_mult_iff:
   435      "((0::'a::ordered_ring_strict) < a*b) = (0 < a & 0 < b | a < 0 & b < 0)"
   436 apply (auto simp add: order_le_less linorder_not_less mult_pos_pos 
   437   mult_neg_neg)
   438 apply (blast dest: zero_less_mult_pos) 
   439 apply (blast dest: zero_less_mult_pos2)
   440 done
   441 
   442 lemma mult_eq_0_iff [simp]:
   443   fixes a b :: "'a::ring_no_zero_divisors"
   444   shows "(a * b = 0) = (a = 0 \<or> b = 0)"
   445 by (cases "a = 0 \<or> b = 0", auto dest: no_zero_divisors)
   446 
   447 instance ordered_ring_strict \<subseteq> ring_no_zero_divisors
   448 apply intro_classes
   449 apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff)
   450 apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+
   451 done
   452 
   453 lemma zero_le_mult_iff:
   454      "((0::'a::ordered_ring_strict) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
   455 by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less
   456                    zero_less_mult_iff)
   457 
   458 lemma mult_less_0_iff:
   459      "(a*b < (0::'a::ordered_ring_strict)) = (0 < a & b < 0 | a < 0 & 0 < b)"
   460 apply (insert zero_less_mult_iff [of "-a" b]) 
   461 apply (force simp add: minus_mult_left[symmetric]) 
   462 done
   463 
   464 lemma mult_le_0_iff:
   465      "(a*b \<le> (0::'a::ordered_ring_strict)) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
   466 apply (insert zero_le_mult_iff [of "-a" b]) 
   467 apply (force simp add: minus_mult_left[symmetric]) 
   468 done
   469 
   470 lemma split_mult_pos_le: "(0 \<le> a & 0 \<le> b) | (a \<le> 0 & b \<le> 0) \<Longrightarrow> 0 \<le> a * (b::_::pordered_ring)"
   471 by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
   472 
   473 lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> (0::_::pordered_cancel_semiring)" 
   474 by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
   475 
   476 lemma zero_le_square[simp]: "(0::'a::ordered_ring_strict) \<le> a*a"
   477 by (simp add: zero_le_mult_iff linorder_linear)
   478 
   479 lemma not_square_less_zero[simp]: "\<not> (a * a < (0::'a::ordered_ring_strict))"
   480 by (simp add: not_less)
   481 
   482 text{*Proving axiom @{text zero_less_one} makes all @{text ordered_semidom}
   483       theorems available to members of @{term ordered_idom} *}
   484 
   485 instance ordered_idom \<subseteq> ordered_semidom
   486 proof
   487   have "(0::'a) \<le> 1*1" by (rule zero_le_square)
   488   thus "(0::'a) < 1" by (simp add: order_le_less) 
   489 qed
   490 
   491 instance ordered_idom \<subseteq> idom ..
   492 
   493 text{*All three types of comparision involving 0 and 1 are covered.*}
   494 
   495 lemmas one_neq_zero = zero_neq_one [THEN not_sym]
   496 declare one_neq_zero [simp]
   497 
   498 lemma zero_le_one [simp]: "(0::'a::ordered_semidom) \<le> 1"
   499   by (rule zero_less_one [THEN order_less_imp_le]) 
   500 
   501 lemma not_one_le_zero [simp]: "~ (1::'a::ordered_semidom) \<le> 0"
   502 by (simp add: linorder_not_le) 
   503 
   504 lemma not_one_less_zero [simp]: "~ (1::'a::ordered_semidom) < 0"
   505 by (simp add: linorder_not_less) 
   506 
   507 
   508 subsection{*More Monotonicity*}
   509 
   510 text{*Strict monotonicity in both arguments*}
   511 lemma mult_strict_mono:
   512      "[|a<b; c<d; 0<b; 0\<le>c|] ==> a * c < b * (d::'a::ordered_semiring_strict)"
   513 apply (cases "c=0")
   514  apply (simp add: mult_pos_pos) 
   515 apply (erule mult_strict_right_mono [THEN order_less_trans])
   516  apply (force simp add: order_le_less) 
   517 apply (erule mult_strict_left_mono, assumption)
   518 done
   519 
   520 text{*This weaker variant has more natural premises*}
   521 lemma mult_strict_mono':
   522      "[| a<b; c<d; 0 \<le> a; 0 \<le> c|] ==> a * c < b * (d::'a::ordered_semiring_strict)"
   523 apply (rule mult_strict_mono)
   524 apply (blast intro: order_le_less_trans)+
   525 done
   526 
   527 lemma mult_mono:
   528      "[|a \<le> b; c \<le> d; 0 \<le> b; 0 \<le> c|] 
   529       ==> a * c  \<le>  b * (d::'a::pordered_semiring)"
   530 apply (erule mult_right_mono [THEN order_trans], assumption)
   531 apply (erule mult_left_mono, assumption)
   532 done
   533 
   534 lemma mult_mono':
   535      "[|a \<le> b; c \<le> d; 0 \<le> a; 0 \<le> c|] 
   536       ==> a * c  \<le>  b * (d::'a::pordered_semiring)"
   537 apply (rule mult_mono)
   538 apply (fast intro: order_trans)+
   539 done
   540 
   541 lemma less_1_mult: "[| 1 < m; 1 < n |] ==> 1 < m*(n::'a::ordered_semidom)"
   542 apply (insert mult_strict_mono [of 1 m 1 n]) 
   543 apply (simp add:  order_less_trans [OF zero_less_one]) 
   544 done
   545 
   546 lemma mult_less_le_imp_less: "(a::'a::ordered_semiring_strict) < b ==>
   547     c <= d ==> 0 <= a ==> 0 < c ==> a * c < b * d"
   548   apply (subgoal_tac "a * c < b * c")
   549   apply (erule order_less_le_trans)
   550   apply (erule mult_left_mono)
   551   apply simp
   552   apply (erule mult_strict_right_mono)
   553   apply assumption
   554 done
   555 
   556 lemma mult_le_less_imp_less: "(a::'a::ordered_semiring_strict) <= b ==>
   557     c < d ==> 0 < a ==> 0 <= c ==> a * c < b * d"
   558   apply (subgoal_tac "a * c <= b * c")
   559   apply (erule order_le_less_trans)
   560   apply (erule mult_strict_left_mono)
   561   apply simp
   562   apply (erule mult_right_mono)
   563   apply simp
   564 done
   565 
   566 
   567 subsection{*Cancellation Laws for Relationships With a Common Factor*}
   568 
   569 text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
   570    also with the relations @{text "\<le>"} and equality.*}
   571 
   572 text{*These ``disjunction'' versions produce two cases when the comparison is
   573  an assumption, but effectively four when the comparison is a goal.*}
   574 
   575 lemma mult_less_cancel_right_disj:
   576     "(a*c < b*c) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring_strict)))"
   577 apply (cases "c = 0")
   578 apply (auto simp add: linorder_neq_iff mult_strict_right_mono 
   579                       mult_strict_right_mono_neg)
   580 apply (auto simp add: linorder_not_less 
   581                       linorder_not_le [symmetric, of "a*c"]
   582                       linorder_not_le [symmetric, of a])
   583 apply (erule_tac [!] notE)
   584 apply (auto simp add: order_less_imp_le mult_right_mono 
   585                       mult_right_mono_neg)
   586 done
   587 
   588 lemma mult_less_cancel_left_disj:
   589     "(c*a < c*b) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring_strict)))"
   590 apply (cases "c = 0")
   591 apply (auto simp add: linorder_neq_iff mult_strict_left_mono 
   592                       mult_strict_left_mono_neg)
   593 apply (auto simp add: linorder_not_less 
   594                       linorder_not_le [symmetric, of "c*a"]
   595                       linorder_not_le [symmetric, of a])
   596 apply (erule_tac [!] notE)
   597 apply (auto simp add: order_less_imp_le mult_left_mono 
   598                       mult_left_mono_neg)
   599 done
   600 
   601 
   602 text{*The ``conjunction of implication'' lemmas produce two cases when the
   603 comparison is a goal, but give four when the comparison is an assumption.*}
   604 
   605 lemma mult_less_cancel_right:
   606   fixes c :: "'a :: ordered_ring_strict"
   607   shows      "(a*c < b*c) = ((0 \<le> c --> a < b) & (c \<le> 0 --> b < a))"
   608 by (insert mult_less_cancel_right_disj [of a c b], auto)
   609 
   610 lemma mult_less_cancel_left:
   611   fixes c :: "'a :: ordered_ring_strict"
   612   shows      "(c*a < c*b) = ((0 \<le> c --> a < b) & (c \<le> 0 --> b < a))"
   613 by (insert mult_less_cancel_left_disj [of c a b], auto)
   614 
   615 lemma mult_le_cancel_right:
   616      "(a*c \<le> b*c) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring_strict)))"
   617 by (simp add: linorder_not_less [symmetric] mult_less_cancel_right_disj)
   618 
   619 lemma mult_le_cancel_left:
   620      "(c*a \<le> c*b) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring_strict)))"
   621 by (simp add: linorder_not_less [symmetric] mult_less_cancel_left_disj)
   622 
   623 lemma mult_less_imp_less_left:
   624       assumes less: "c*a < c*b" and nonneg: "0 \<le> c"
   625       shows "a < (b::'a::ordered_semiring_strict)"
   626 proof (rule ccontr)
   627   assume "~ a < b"
   628   hence "b \<le> a" by (simp add: linorder_not_less)
   629   hence "c*b \<le> c*a" using nonneg by (rule mult_left_mono)
   630   with this and less show False 
   631     by (simp add: linorder_not_less [symmetric])
   632 qed
   633 
   634 lemma mult_less_imp_less_right:
   635   assumes less: "a*c < b*c" and nonneg: "0 <= c"
   636   shows "a < (b::'a::ordered_semiring_strict)"
   637 proof (rule ccontr)
   638   assume "~ a < b"
   639   hence "b \<le> a" by (simp add: linorder_not_less)
   640   hence "b*c \<le> a*c" using nonneg by (rule mult_right_mono)
   641   with this and less show False 
   642     by (simp add: linorder_not_less [symmetric])
   643 qed  
   644 
   645 text{*Cancellation of equalities with a common factor*}
   646 lemma mult_cancel_right [simp]:
   647   fixes a b c :: "'a::ring_no_zero_divisors"
   648   shows "(a * c = b * c) = (c = 0 \<or> a = b)"
   649 proof -
   650   have "(a * c = b * c) = ((a - b) * c = 0)"
   651     by (simp add: left_diff_distrib)
   652   thus ?thesis
   653     by (simp add: disj_commute)
   654 qed
   655 
   656 lemma mult_cancel_left [simp]:
   657   fixes a b c :: "'a::ring_no_zero_divisors"
   658   shows "(c * a = c * b) = (c = 0 \<or> a = b)"
   659 proof -
   660   have "(c * a = c * b) = (c * (a - b) = 0)"
   661     by (simp add: right_diff_distrib)
   662   thus ?thesis
   663     by simp
   664 qed
   665 
   666 
   667 subsubsection{*Special Cancellation Simprules for Multiplication*}
   668 
   669 text{*These also produce two cases when the comparison is a goal.*}
   670 
   671 lemma mult_le_cancel_right1:
   672   fixes c :: "'a :: ordered_idom"
   673   shows "(c \<le> b*c) = ((0<c --> 1\<le>b) & (c<0 --> b \<le> 1))"
   674 by (insert mult_le_cancel_right [of 1 c b], simp)
   675 
   676 lemma mult_le_cancel_right2:
   677   fixes c :: "'a :: ordered_idom"
   678   shows "(a*c \<le> c) = ((0<c --> a\<le>1) & (c<0 --> 1 \<le> a))"
   679 by (insert mult_le_cancel_right [of a c 1], simp)
   680 
   681 lemma mult_le_cancel_left1:
   682   fixes c :: "'a :: ordered_idom"
   683   shows "(c \<le> c*b) = ((0<c --> 1\<le>b) & (c<0 --> b \<le> 1))"
   684 by (insert mult_le_cancel_left [of c 1 b], simp)
   685 
   686 lemma mult_le_cancel_left2:
   687   fixes c :: "'a :: ordered_idom"
   688   shows "(c*a \<le> c) = ((0<c --> a\<le>1) & (c<0 --> 1 \<le> a))"
   689 by (insert mult_le_cancel_left [of c a 1], simp)
   690 
   691 lemma mult_less_cancel_right1:
   692   fixes c :: "'a :: ordered_idom"
   693   shows "(c < b*c) = ((0 \<le> c --> 1<b) & (c \<le> 0 --> b < 1))"
   694 by (insert mult_less_cancel_right [of 1 c b], simp)
   695 
   696 lemma mult_less_cancel_right2:
   697   fixes c :: "'a :: ordered_idom"
   698   shows "(a*c < c) = ((0 \<le> c --> a<1) & (c \<le> 0 --> 1 < a))"
   699 by (insert mult_less_cancel_right [of a c 1], simp)
   700 
   701 lemma mult_less_cancel_left1:
   702   fixes c :: "'a :: ordered_idom"
   703   shows "(c < c*b) = ((0 \<le> c --> 1<b) & (c \<le> 0 --> b < 1))"
   704 by (insert mult_less_cancel_left [of c 1 b], simp)
   705 
   706 lemma mult_less_cancel_left2:
   707   fixes c :: "'a :: ordered_idom"
   708   shows "(c*a < c) = ((0 \<le> c --> a<1) & (c \<le> 0 --> 1 < a))"
   709 by (insert mult_less_cancel_left [of c a 1], simp)
   710 
   711 lemma mult_cancel_right1 [simp]:
   712   fixes c :: "'a :: dom"
   713   shows "(c = b*c) = (c = 0 | b=1)"
   714 by (insert mult_cancel_right [of 1 c b], force)
   715 
   716 lemma mult_cancel_right2 [simp]:
   717   fixes c :: "'a :: dom"
   718   shows "(a*c = c) = (c = 0 | a=1)"
   719 by (insert mult_cancel_right [of a c 1], simp)
   720  
   721 lemma mult_cancel_left1 [simp]:
   722   fixes c :: "'a :: dom"
   723   shows "(c = c*b) = (c = 0 | b=1)"
   724 by (insert mult_cancel_left [of c 1 b], force)
   725 
   726 lemma mult_cancel_left2 [simp]:
   727   fixes c :: "'a :: dom"
   728   shows "(c*a = c) = (c = 0 | a=1)"
   729 by (insert mult_cancel_left [of c a 1], simp)
   730 
   731 
   732 text{*Simprules for comparisons where common factors can be cancelled.*}
   733 lemmas mult_compare_simps =
   734     mult_le_cancel_right mult_le_cancel_left
   735     mult_le_cancel_right1 mult_le_cancel_right2
   736     mult_le_cancel_left1 mult_le_cancel_left2
   737     mult_less_cancel_right mult_less_cancel_left
   738     mult_less_cancel_right1 mult_less_cancel_right2
   739     mult_less_cancel_left1 mult_less_cancel_left2
   740     mult_cancel_right mult_cancel_left
   741     mult_cancel_right1 mult_cancel_right2
   742     mult_cancel_left1 mult_cancel_left2
   743 
   744 
   745 text{*This list of rewrites decides ring equalities by ordered rewriting.*}
   746 lemmas ring_eq_simps =  
   747 (*  mult_ac*)
   748   left_distrib right_distrib left_diff_distrib right_diff_distrib
   749   group_eq_simps
   750 (*  add_ac
   751   add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
   752   diff_eq_eq eq_diff_eq *)
   753     
   754 
   755 subsection {* Fields *}
   756 
   757 lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
   758 proof
   759   assume neq: "b \<noteq> 0"
   760   {
   761     hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
   762     also assume "a / b = 1"
   763     finally show "a = b" by simp
   764   next
   765     assume "a = b"
   766     with neq show "a / b = 1" by (simp add: divide_inverse)
   767   }
   768 qed
   769 
   770 lemma nonzero_inverse_eq_divide: "a \<noteq> 0 ==> inverse (a::'a::field) = 1/a"
   771 by (simp add: divide_inverse)
   772 
   773 lemma divide_self: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
   774   by (simp add: divide_inverse)
   775 
   776 lemma divide_zero [simp]: "a / 0 = (0::'a::{field,division_by_zero})"
   777 by (simp add: divide_inverse)
   778 
   779 lemma divide_self_if [simp]:
   780      "a / (a::'a::{field,division_by_zero}) = (if a=0 then 0 else 1)"
   781   by (simp add: divide_self)
   782 
   783 lemma divide_zero_left [simp]: "0/a = (0::'a::field)"
   784 by (simp add: divide_inverse)
   785 
   786 lemma inverse_eq_divide: "inverse (a::'a::field) = 1/a"
   787 by (simp add: divide_inverse)
   788 
   789 lemma add_divide_distrib: "(a+b)/(c::'a::field) = a/c + b/c"
   790 by (simp add: divide_inverse left_distrib) 
   791 
   792 
   793 text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
   794       of an ordering.*}
   795 lemma field_mult_eq_0_iff [simp]:
   796   "(a*b = (0::'a::division_ring)) = (a = 0 | b = 0)"
   797 by simp
   798 
   799 text{*Cancellation of equalities with a common factor*}
   800 lemma field_mult_cancel_right_lemma:
   801       assumes cnz: "c \<noteq> (0::'a::division_ring)"
   802          and eq:  "a*c = b*c"
   803         shows "a=b"
   804 proof -
   805   have "(a * c) * inverse c = (b * c) * inverse c"
   806     by (simp add: eq)
   807   thus "a=b"
   808     by (simp add: mult_assoc cnz)
   809 qed
   810 
   811 lemma field_mult_cancel_right [simp]:
   812      "(a*c = b*c) = (c = (0::'a::division_ring) | a=b)"
   813 by simp
   814 
   815 lemma field_mult_cancel_left [simp]:
   816      "(c*a = c*b) = (c = (0::'a::division_ring) | a=b)"
   817 by simp
   818 
   819 lemma nonzero_imp_inverse_nonzero:
   820   "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::division_ring)"
   821 proof
   822   assume ianz: "inverse a = 0"
   823   assume "a \<noteq> 0"
   824   hence "1 = a * inverse a" by simp
   825   also have "... = 0" by (simp add: ianz)
   826   finally have "1 = (0::'a::division_ring)" .
   827   thus False by (simp add: eq_commute)
   828 qed
   829 
   830 
   831 subsection{*Basic Properties of @{term inverse}*}
   832 
   833 lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::division_ring)"
   834 apply (rule ccontr) 
   835 apply (blast dest: nonzero_imp_inverse_nonzero) 
   836 done
   837 
   838 lemma inverse_nonzero_imp_nonzero:
   839    "inverse a = 0 ==> a = (0::'a::division_ring)"
   840 apply (rule ccontr) 
   841 apply (blast dest: nonzero_imp_inverse_nonzero) 
   842 done
   843 
   844 lemma inverse_nonzero_iff_nonzero [simp]:
   845    "(inverse a = 0) = (a = (0::'a::{division_ring,division_by_zero}))"
   846 by (force dest: inverse_nonzero_imp_nonzero) 
   847 
   848 lemma nonzero_inverse_minus_eq:
   849       assumes [simp]: "a\<noteq>0"
   850       shows "inverse(-a) = -inverse(a::'a::division_ring)"
   851 proof -
   852   have "-a * inverse (- a) = -a * - inverse a"
   853     by simp
   854   thus ?thesis 
   855     by (simp only: field_mult_cancel_left, simp)
   856 qed
   857 
   858 lemma inverse_minus_eq [simp]:
   859    "inverse(-a) = -inverse(a::'a::{division_ring,division_by_zero})"
   860 proof cases
   861   assume "a=0" thus ?thesis by (simp add: inverse_zero)
   862 next
   863   assume "a\<noteq>0" 
   864   thus ?thesis by (simp add: nonzero_inverse_minus_eq)
   865 qed
   866 
   867 lemma nonzero_inverse_eq_imp_eq:
   868       assumes inveq: "inverse a = inverse b"
   869 	  and anz:  "a \<noteq> 0"
   870 	  and bnz:  "b \<noteq> 0"
   871 	 shows "a = (b::'a::division_ring)"
   872 proof -
   873   have "a * inverse b = a * inverse a"
   874     by (simp add: inveq)
   875   hence "(a * inverse b) * b = (a * inverse a) * b"
   876     by simp
   877   thus "a = b"
   878     by (simp add: mult_assoc anz bnz)
   879 qed
   880 
   881 lemma inverse_eq_imp_eq:
   882   "inverse a = inverse b ==> a = (b::'a::{division_ring,division_by_zero})"
   883 apply (cases "a=0 | b=0") 
   884  apply (force dest!: inverse_zero_imp_zero
   885               simp add: eq_commute [of "0::'a"])
   886 apply (force dest!: nonzero_inverse_eq_imp_eq) 
   887 done
   888 
   889 lemma inverse_eq_iff_eq [simp]:
   890   "(inverse a = inverse b) = (a = (b::'a::{division_ring,division_by_zero}))"
   891 by (force dest!: inverse_eq_imp_eq)
   892 
   893 lemma nonzero_inverse_inverse_eq:
   894       assumes [simp]: "a \<noteq> 0"
   895       shows "inverse(inverse (a::'a::division_ring)) = a"
   896   proof -
   897   have "(inverse (inverse a) * inverse a) * a = a" 
   898     by (simp add: nonzero_imp_inverse_nonzero)
   899   thus ?thesis
   900     by (simp add: mult_assoc)
   901   qed
   902 
   903 lemma inverse_inverse_eq [simp]:
   904      "inverse(inverse (a::'a::{division_ring,division_by_zero})) = a"
   905   proof cases
   906     assume "a=0" thus ?thesis by simp
   907   next
   908     assume "a\<noteq>0" 
   909     thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
   910   qed
   911 
   912 lemma inverse_1 [simp]: "inverse 1 = (1::'a::division_ring)"
   913   proof -
   914   have "inverse 1 * 1 = (1::'a::division_ring)" 
   915     by (rule left_inverse [OF zero_neq_one [symmetric]])
   916   thus ?thesis  by simp
   917   qed
   918 
   919 lemma inverse_unique: 
   920   assumes ab: "a*b = 1"
   921   shows "inverse a = (b::'a::division_ring)"
   922 proof -
   923   have "a \<noteq> 0" using ab by auto
   924   moreover have "inverse a * (a * b) = inverse a" by (simp add: ab) 
   925   ultimately show ?thesis by (simp add: mult_assoc [symmetric]) 
   926 qed
   927 
   928 lemma nonzero_inverse_mult_distrib: 
   929       assumes anz: "a \<noteq> 0"
   930           and bnz: "b \<noteq> 0"
   931       shows "inverse(a*b) = inverse(b) * inverse(a::'a::division_ring)"
   932   proof -
   933   have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
   934     by (simp add: field_mult_eq_0_iff anz bnz)
   935   hence "inverse(a*b) * a = inverse(b)" 
   936     by (simp add: mult_assoc bnz)
   937   hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
   938     by simp
   939   thus ?thesis
   940     by (simp add: mult_assoc anz)
   941   qed
   942 
   943 text{*This version builds in division by zero while also re-orienting
   944       the right-hand side.*}
   945 lemma inverse_mult_distrib [simp]:
   946      "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
   947   proof cases
   948     assume "a \<noteq> 0 & b \<noteq> 0" 
   949     thus ?thesis
   950       by (simp add: nonzero_inverse_mult_distrib mult_commute)
   951   next
   952     assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
   953     thus ?thesis
   954       by force
   955   qed
   956 
   957 lemma division_ring_inverse_add:
   958   "[|(a::'a::division_ring) \<noteq> 0; b \<noteq> 0|]
   959    ==> inverse a + inverse b = inverse a * (a+b) * inverse b"
   960   by (simp add: right_distrib left_distrib mult_assoc)
   961 
   962 lemma division_ring_inverse_diff:
   963   "[|(a::'a::division_ring) \<noteq> 0; b \<noteq> 0|]
   964    ==> inverse a - inverse b = inverse a * (b-a) * inverse b"
   965 by (simp add: right_diff_distrib left_diff_distrib mult_assoc)
   966 
   967 text{*There is no slick version using division by zero.*}
   968 lemma inverse_add:
   969      "[|a \<noteq> 0;  b \<noteq> 0|]
   970       ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
   971 by (simp add: division_ring_inverse_add mult_ac)
   972 
   973 lemma inverse_divide [simp]:
   974       "inverse (a/b) = b / (a::'a::{field,division_by_zero})"
   975   by (simp add: divide_inverse mult_commute)
   976 
   977 
   978 subsection {* Calculations with fractions *}
   979 
   980 lemma nonzero_mult_divide_cancel_left:
   981   assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" 
   982     shows "(c*a)/(c*b) = a/(b::'a::field)"
   983 proof -
   984   have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
   985     by (simp add: field_mult_eq_0_iff divide_inverse 
   986                   nonzero_inverse_mult_distrib)
   987   also have "... =  a * inverse b * (inverse c * c)"
   988     by (simp only: mult_ac)
   989   also have "... =  a * inverse b"
   990     by simp
   991     finally show ?thesis 
   992     by (simp add: divide_inverse)
   993 qed
   994 
   995 lemma mult_divide_cancel_left:
   996      "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
   997 apply (cases "b = 0")
   998 apply (simp_all add: nonzero_mult_divide_cancel_left)
   999 done
  1000 
  1001 lemma nonzero_mult_divide_cancel_right:
  1002      "[|b\<noteq>0; c\<noteq>0|] ==> (a*c) / (b*c) = a/(b::'a::field)"
  1003 by (simp add: mult_commute [of _ c] nonzero_mult_divide_cancel_left) 
  1004 
  1005 lemma mult_divide_cancel_right:
  1006      "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
  1007 apply (cases "b = 0")
  1008 apply (simp_all add: nonzero_mult_divide_cancel_right)
  1009 done
  1010 
  1011 (*For ExtractCommonTerm*)
  1012 lemma mult_divide_cancel_eq_if:
  1013      "(c*a) / (c*b) = 
  1014       (if c=0 then 0 else a / (b::'a::{field,division_by_zero}))"
  1015   by (simp add: mult_divide_cancel_left)
  1016 
  1017 lemma divide_1 [simp]: "a/1 = (a::'a::field)"
  1018   by (simp add: divide_inverse)
  1019 
  1020 lemma times_divide_eq_right: "a * (b/c) = (a*b) / (c::'a::field)"
  1021 by (simp add: divide_inverse mult_assoc)
  1022 
  1023 lemma times_divide_eq_left: "(b/c) * a = (b*a) / (c::'a::field)"
  1024 by (simp add: divide_inverse mult_ac)
  1025 
  1026 lemma divide_divide_eq_right [simp]:
  1027      "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
  1028 by (simp add: divide_inverse mult_ac)
  1029 
  1030 lemma divide_divide_eq_left [simp]:
  1031      "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
  1032 by (simp add: divide_inverse mult_assoc)
  1033 
  1034 lemma add_frac_eq: "(y::'a::field) ~= 0 ==> z ~= 0 ==>
  1035     x / y + w / z = (x * z + w * y) / (y * z)"
  1036   apply (subgoal_tac "x / y = (x * z) / (y * z)")
  1037   apply (erule ssubst)
  1038   apply (subgoal_tac "w / z = (w * y) / (y * z)")
  1039   apply (erule ssubst)
  1040   apply (rule add_divide_distrib [THEN sym])
  1041   apply (subst mult_commute)
  1042   apply (erule nonzero_mult_divide_cancel_left [THEN sym])
  1043   apply assumption
  1044   apply (erule nonzero_mult_divide_cancel_right [THEN sym])
  1045   apply assumption
  1046 done
  1047 
  1048 
  1049 subsubsection{*Special Cancellation Simprules for Division*}
  1050 
  1051 lemma mult_divide_cancel_left_if [simp]:
  1052   fixes c :: "'a :: {field,division_by_zero}"
  1053   shows "(c*a) / (c*b) = (if c=0 then 0 else a/b)"
  1054 by (simp add: mult_divide_cancel_left)
  1055 
  1056 lemma mult_divide_cancel_right_if [simp]:
  1057   fixes c :: "'a :: {field,division_by_zero}"
  1058   shows "(a*c) / (b*c) = (if c=0 then 0 else a/b)"
  1059 by (simp add: mult_divide_cancel_right)
  1060 
  1061 lemma mult_divide_cancel_left_if1 [simp]:
  1062   fixes c :: "'a :: {field,division_by_zero}"
  1063   shows "c / (c*b) = (if c=0 then 0 else 1/b)"
  1064 apply (insert mult_divide_cancel_left_if [of c 1 b]) 
  1065 apply (simp del: mult_divide_cancel_left_if)
  1066 done
  1067 
  1068 lemma mult_divide_cancel_left_if2 [simp]:
  1069   fixes c :: "'a :: {field,division_by_zero}"
  1070   shows "(c*a) / c = (if c=0 then 0 else a)" 
  1071 apply (insert mult_divide_cancel_left_if [of c a 1]) 
  1072 apply (simp del: mult_divide_cancel_left_if)
  1073 done
  1074 
  1075 lemma mult_divide_cancel_right_if1 [simp]:
  1076   fixes c :: "'a :: {field,division_by_zero}"
  1077   shows "c / (b*c) = (if c=0 then 0 else 1/b)"
  1078 apply (insert mult_divide_cancel_right_if [of 1 c b]) 
  1079 apply (simp del: mult_divide_cancel_right_if)
  1080 done
  1081 
  1082 lemma mult_divide_cancel_right_if2 [simp]:
  1083   fixes c :: "'a :: {field,division_by_zero}"
  1084   shows "(a*c) / c = (if c=0 then 0 else a)" 
  1085 apply (insert mult_divide_cancel_right_if [of a c 1]) 
  1086 apply (simp del: mult_divide_cancel_right_if)
  1087 done
  1088 
  1089 text{*Two lemmas for cancelling the denominator*}
  1090 
  1091 lemma times_divide_self_right [simp]: 
  1092   fixes a :: "'a :: {field,division_by_zero}"
  1093   shows "a * (b/a) = (if a=0 then 0 else b)"
  1094 by (simp add: times_divide_eq_right)
  1095 
  1096 lemma times_divide_self_left [simp]: 
  1097   fixes a :: "'a :: {field,division_by_zero}"
  1098   shows "(b/a) * a = (if a=0 then 0 else b)"
  1099 by (simp add: times_divide_eq_left)
  1100 
  1101 
  1102 subsection {* Division and Unary Minus *}
  1103 
  1104 lemma nonzero_minus_divide_left: "b \<noteq> 0 ==> - (a/b) = (-a) / (b::'a::field)"
  1105 by (simp add: divide_inverse minus_mult_left)
  1106 
  1107 lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a/b) = a / -(b::'a::field)"
  1108 by (simp add: divide_inverse nonzero_inverse_minus_eq minus_mult_right)
  1109 
  1110 lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a)/(-b) = a / (b::'a::field)"
  1111 by (simp add: divide_inverse nonzero_inverse_minus_eq)
  1112 
  1113 lemma minus_divide_left: "- (a/b) = (-a) / (b::'a::field)"
  1114 by (simp add: divide_inverse minus_mult_left [symmetric])
  1115 
  1116 lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
  1117 by (simp add: divide_inverse minus_mult_right [symmetric])
  1118 
  1119 
  1120 text{*The effect is to extract signs from divisions*}
  1121 lemmas divide_minus_left = minus_divide_left [symmetric]
  1122 lemmas divide_minus_right = minus_divide_right [symmetric]
  1123 declare divide_minus_left [simp]   divide_minus_right [simp]
  1124 
  1125 text{*Also, extract signs from products*}
  1126 lemmas mult_minus_left = minus_mult_left [symmetric]
  1127 lemmas mult_minus_right = minus_mult_right [symmetric]
  1128 declare mult_minus_left [simp]   mult_minus_right [simp]
  1129 
  1130 lemma minus_divide_divide [simp]:
  1131      "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
  1132 apply (cases "b=0", simp) 
  1133 apply (simp add: nonzero_minus_divide_divide) 
  1134 done
  1135 
  1136 lemma diff_divide_distrib: "(a-b)/(c::'a::field) = a/c - b/c"
  1137 by (simp add: diff_minus add_divide_distrib) 
  1138 
  1139 lemma diff_frac_eq: "(y::'a::field) ~= 0 ==> z ~= 0 ==>
  1140     x / y - w / z = (x * z - w * y) / (y * z)"
  1141   apply (subst diff_def)+
  1142   apply (subst minus_divide_left)
  1143   apply (subst add_frac_eq)
  1144   apply simp_all
  1145 done
  1146 
  1147 
  1148 subsection {* Ordered Fields *}
  1149 
  1150 lemma positive_imp_inverse_positive: 
  1151       assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
  1152   proof -
  1153   have "0 < a * inverse a" 
  1154     by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
  1155   thus "0 < inverse a" 
  1156     by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
  1157   qed
  1158 
  1159 lemma negative_imp_inverse_negative:
  1160      "a < 0 ==> inverse a < (0::'a::ordered_field)"
  1161   by (insert positive_imp_inverse_positive [of "-a"], 
  1162       simp add: nonzero_inverse_minus_eq order_less_imp_not_eq) 
  1163 
  1164 lemma inverse_le_imp_le:
  1165       assumes invle: "inverse a \<le> inverse b"
  1166 	  and apos:  "0 < a"
  1167 	 shows "b \<le> (a::'a::ordered_field)"
  1168   proof (rule classical)
  1169   assume "~ b \<le> a"
  1170   hence "a < b"
  1171     by (simp add: linorder_not_le)
  1172   hence bpos: "0 < b"
  1173     by (blast intro: apos order_less_trans)
  1174   hence "a * inverse a \<le> a * inverse b"
  1175     by (simp add: apos invle order_less_imp_le mult_left_mono)
  1176   hence "(a * inverse a) * b \<le> (a * inverse b) * b"
  1177     by (simp add: bpos order_less_imp_le mult_right_mono)
  1178   thus "b \<le> a"
  1179     by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
  1180   qed
  1181 
  1182 lemma inverse_positive_imp_positive:
  1183   assumes inv_gt_0: "0 < inverse a"
  1184     and nz: "a \<noteq> 0"
  1185   shows "0 < (a::'a::ordered_field)"
  1186 proof -
  1187   have "0 < inverse (inverse a)"
  1188     using inv_gt_0 by (rule positive_imp_inverse_positive)
  1189   thus "0 < a"
  1190     using nz by (simp add: nonzero_inverse_inverse_eq)
  1191 qed
  1192 
  1193 lemma inverse_positive_iff_positive [simp]:
  1194       "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
  1195 apply (cases "a = 0", simp)
  1196 apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
  1197 done
  1198 
  1199 lemma inverse_negative_imp_negative:
  1200   assumes inv_less_0: "inverse a < 0"
  1201     and nz:  "a \<noteq> 0"
  1202   shows "a < (0::'a::ordered_field)"
  1203 proof -
  1204   have "inverse (inverse a) < 0"
  1205     using inv_less_0 by (rule negative_imp_inverse_negative)
  1206   thus "a < 0"
  1207     using nz by (simp add: nonzero_inverse_inverse_eq)
  1208 qed
  1209 
  1210 lemma inverse_negative_iff_negative [simp]:
  1211       "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
  1212 apply (cases "a = 0", simp)
  1213 apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
  1214 done
  1215 
  1216 lemma inverse_nonnegative_iff_nonnegative [simp]:
  1217       "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
  1218 by (simp add: linorder_not_less [symmetric])
  1219 
  1220 lemma inverse_nonpositive_iff_nonpositive [simp]:
  1221       "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
  1222 by (simp add: linorder_not_less [symmetric])
  1223 
  1224 
  1225 subsection{*Anti-Monotonicity of @{term inverse}*}
  1226 
  1227 lemma less_imp_inverse_less:
  1228       assumes less: "a < b"
  1229 	  and apos:  "0 < a"
  1230 	shows "inverse b < inverse (a::'a::ordered_field)"
  1231   proof (rule ccontr)
  1232   assume "~ inverse b < inverse a"
  1233   hence "inverse a \<le> inverse b"
  1234     by (simp add: linorder_not_less)
  1235   hence "~ (a < b)"
  1236     by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
  1237   thus False
  1238     by (rule notE [OF _ less])
  1239   qed
  1240 
  1241 lemma inverse_less_imp_less:
  1242    "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
  1243 apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
  1244 apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
  1245 done
  1246 
  1247 text{*Both premises are essential. Consider -1 and 1.*}
  1248 lemma inverse_less_iff_less [simp]:
  1249      "[|0 < a; 0 < b|] 
  1250       ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
  1251 by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
  1252 
  1253 lemma le_imp_inverse_le:
  1254    "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
  1255   by (force simp add: order_le_less less_imp_inverse_less)
  1256 
  1257 lemma inverse_le_iff_le [simp]:
  1258      "[|0 < a; 0 < b|] 
  1259       ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
  1260 by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
  1261 
  1262 
  1263 text{*These results refer to both operands being negative.  The opposite-sign
  1264 case is trivial, since inverse preserves signs.*}
  1265 lemma inverse_le_imp_le_neg:
  1266    "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
  1267   apply (rule classical) 
  1268   apply (subgoal_tac "a < 0") 
  1269    prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
  1270   apply (insert inverse_le_imp_le [of "-b" "-a"])
  1271   apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
  1272   done
  1273 
  1274 lemma less_imp_inverse_less_neg:
  1275    "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
  1276   apply (subgoal_tac "a < 0") 
  1277    prefer 2 apply (blast intro: order_less_trans) 
  1278   apply (insert less_imp_inverse_less [of "-b" "-a"])
  1279   apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
  1280   done
  1281 
  1282 lemma inverse_less_imp_less_neg:
  1283    "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
  1284   apply (rule classical) 
  1285   apply (subgoal_tac "a < 0") 
  1286    prefer 2
  1287    apply (force simp add: linorder_not_less intro: order_le_less_trans) 
  1288   apply (insert inverse_less_imp_less [of "-b" "-a"])
  1289   apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
  1290   done
  1291 
  1292 lemma inverse_less_iff_less_neg [simp]:
  1293      "[|a < 0; b < 0|] 
  1294       ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
  1295   apply (insert inverse_less_iff_less [of "-b" "-a"])
  1296   apply (simp del: inverse_less_iff_less 
  1297 	      add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
  1298   done
  1299 
  1300 lemma le_imp_inverse_le_neg:
  1301    "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
  1302   by (force simp add: order_le_less less_imp_inverse_less_neg)
  1303 
  1304 lemma inverse_le_iff_le_neg [simp]:
  1305      "[|a < 0; b < 0|] 
  1306       ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
  1307 by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
  1308 
  1309 
  1310 subsection{*Inverses and the Number One*}
  1311 
  1312 lemma one_less_inverse_iff:
  1313     "(1 < inverse x) = (0 < x & x < (1::'a::{ordered_field,division_by_zero}))"proof cases
  1314   assume "0 < x"
  1315     with inverse_less_iff_less [OF zero_less_one, of x]
  1316     show ?thesis by simp
  1317 next
  1318   assume notless: "~ (0 < x)"
  1319   have "~ (1 < inverse x)"
  1320   proof
  1321     assume "1 < inverse x"
  1322     also with notless have "... \<le> 0" by (simp add: linorder_not_less)
  1323     also have "... < 1" by (rule zero_less_one) 
  1324     finally show False by auto
  1325   qed
  1326   with notless show ?thesis by simp
  1327 qed
  1328 
  1329 lemma inverse_eq_1_iff [simp]:
  1330     "(inverse x = 1) = (x = (1::'a::{field,division_by_zero}))"
  1331 by (insert inverse_eq_iff_eq [of x 1], simp) 
  1332 
  1333 lemma one_le_inverse_iff:
  1334    "(1 \<le> inverse x) = (0 < x & x \<le> (1::'a::{ordered_field,division_by_zero}))"
  1335 by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
  1336                     eq_commute [of 1]) 
  1337 
  1338 lemma inverse_less_1_iff:
  1339    "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{ordered_field,division_by_zero}))"
  1340 by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
  1341 
  1342 lemma inverse_le_1_iff:
  1343    "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{ordered_field,division_by_zero}))"
  1344 by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
  1345 
  1346 
  1347 subsection{*Simplification of Inequalities Involving Literal Divisors*}
  1348 
  1349 lemma pos_le_divide_eq: "0 < (c::'a::ordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
  1350 proof -
  1351   assume less: "0<c"
  1352   hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
  1353     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
  1354   also have "... = (a*c \<le> b)"
  1355     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
  1356   finally show ?thesis .
  1357 qed
  1358 
  1359 lemma neg_le_divide_eq: "c < (0::'a::ordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
  1360 proof -
  1361   assume less: "c<0"
  1362   hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
  1363     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
  1364   also have "... = (b \<le> a*c)"
  1365     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
  1366   finally show ?thesis .
  1367 qed
  1368 
  1369 lemma le_divide_eq:
  1370   "(a \<le> b/c) = 
  1371    (if 0 < c then a*c \<le> b
  1372              else if c < 0 then b \<le> a*c
  1373              else  a \<le> (0::'a::{ordered_field,division_by_zero}))"
  1374 apply (cases "c=0", simp) 
  1375 apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
  1376 done
  1377 
  1378 lemma pos_divide_le_eq: "0 < (c::'a::ordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
  1379 proof -
  1380   assume less: "0<c"
  1381   hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
  1382     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
  1383   also have "... = (b \<le> a*c)"
  1384     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
  1385   finally show ?thesis .
  1386 qed
  1387 
  1388 lemma neg_divide_le_eq: "c < (0::'a::ordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
  1389 proof -
  1390   assume less: "c<0"
  1391   hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
  1392     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
  1393   also have "... = (a*c \<le> b)"
  1394     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
  1395   finally show ?thesis .
  1396 qed
  1397 
  1398 lemma divide_le_eq:
  1399   "(b/c \<le> a) = 
  1400    (if 0 < c then b \<le> a*c
  1401              else if c < 0 then a*c \<le> b
  1402              else 0 \<le> (a::'a::{ordered_field,division_by_zero}))"
  1403 apply (cases "c=0", simp) 
  1404 apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
  1405 done
  1406 
  1407 lemma pos_less_divide_eq:
  1408      "0 < (c::'a::ordered_field) ==> (a < b/c) = (a*c < b)"
  1409 proof -
  1410   assume less: "0<c"
  1411   hence "(a < b/c) = (a*c < (b/c)*c)"
  1412     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
  1413   also have "... = (a*c < b)"
  1414     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
  1415   finally show ?thesis .
  1416 qed
  1417 
  1418 lemma neg_less_divide_eq:
  1419  "c < (0::'a::ordered_field) ==> (a < b/c) = (b < a*c)"
  1420 proof -
  1421   assume less: "c<0"
  1422   hence "(a < b/c) = ((b/c)*c < a*c)"
  1423     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
  1424   also have "... = (b < a*c)"
  1425     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
  1426   finally show ?thesis .
  1427 qed
  1428 
  1429 lemma less_divide_eq:
  1430   "(a < b/c) = 
  1431    (if 0 < c then a*c < b
  1432              else if c < 0 then b < a*c
  1433              else  a < (0::'a::{ordered_field,division_by_zero}))"
  1434 apply (cases "c=0", simp) 
  1435 apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
  1436 done
  1437 
  1438 lemma pos_divide_less_eq:
  1439      "0 < (c::'a::ordered_field) ==> (b/c < a) = (b < a*c)"
  1440 proof -
  1441   assume less: "0<c"
  1442   hence "(b/c < a) = ((b/c)*c < a*c)"
  1443     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
  1444   also have "... = (b < a*c)"
  1445     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
  1446   finally show ?thesis .
  1447 qed
  1448 
  1449 lemma neg_divide_less_eq:
  1450  "c < (0::'a::ordered_field) ==> (b/c < a) = (a*c < b)"
  1451 proof -
  1452   assume less: "c<0"
  1453   hence "(b/c < a) = (a*c < (b/c)*c)"
  1454     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
  1455   also have "... = (a*c < b)"
  1456     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
  1457   finally show ?thesis .
  1458 qed
  1459 
  1460 lemma divide_less_eq:
  1461   "(b/c < a) = 
  1462    (if 0 < c then b < a*c
  1463              else if c < 0 then a*c < b
  1464              else 0 < (a::'a::{ordered_field,division_by_zero}))"
  1465 apply (cases "c=0", simp) 
  1466 apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
  1467 done
  1468 
  1469 lemma nonzero_eq_divide_eq: "c\<noteq>0 ==> ((a::'a::field) = b/c) = (a*c = b)"
  1470 proof -
  1471   assume [simp]: "c\<noteq>0"
  1472   have "(a = b/c) = (a*c = (b/c)*c)"
  1473     by (simp add: field_mult_cancel_right)
  1474   also have "... = (a*c = b)"
  1475     by (simp add: divide_inverse mult_assoc) 
  1476   finally show ?thesis .
  1477 qed
  1478 
  1479 lemma eq_divide_eq:
  1480   "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
  1481 by (simp add: nonzero_eq_divide_eq) 
  1482 
  1483 lemma nonzero_divide_eq_eq: "c\<noteq>0 ==> (b/c = (a::'a::field)) = (b = a*c)"
  1484 proof -
  1485   assume [simp]: "c\<noteq>0"
  1486   have "(b/c = a) = ((b/c)*c = a*c)"
  1487     by (simp add: field_mult_cancel_right)
  1488   also have "... = (b = a*c)"
  1489     by (simp add: divide_inverse mult_assoc) 
  1490   finally show ?thesis .
  1491 qed
  1492 
  1493 lemma divide_eq_eq:
  1494   "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
  1495 by (force simp add: nonzero_divide_eq_eq) 
  1496 
  1497 lemma divide_eq_imp: "(c::'a::{division_by_zero,field}) ~= 0 ==>
  1498     b = a * c ==> b / c = a"
  1499   by (subst divide_eq_eq, simp)
  1500 
  1501 lemma eq_divide_imp: "(c::'a::{division_by_zero,field}) ~= 0 ==>
  1502     a * c = b ==> a = b / c"
  1503   by (subst eq_divide_eq, simp)
  1504 
  1505 lemma frac_eq_eq: "(y::'a::field) ~= 0 ==> z ~= 0 ==>
  1506     (x / y = w / z) = (x * z = w * y)"
  1507   apply (subst nonzero_eq_divide_eq)
  1508   apply assumption
  1509   apply (subst times_divide_eq_left)
  1510   apply (erule nonzero_divide_eq_eq) 
  1511 done
  1512 
  1513 
  1514 subsection{*Division and Signs*}
  1515 
  1516 lemma zero_less_divide_iff:
  1517      "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
  1518 by (simp add: divide_inverse zero_less_mult_iff)
  1519 
  1520 lemma divide_less_0_iff:
  1521      "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
  1522       (0 < a & b < 0 | a < 0 & 0 < b)"
  1523 by (simp add: divide_inverse mult_less_0_iff)
  1524 
  1525 lemma zero_le_divide_iff:
  1526      "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
  1527       (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
  1528 by (simp add: divide_inverse zero_le_mult_iff)
  1529 
  1530 lemma divide_le_0_iff:
  1531      "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) =
  1532       (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
  1533 by (simp add: divide_inverse mult_le_0_iff)
  1534 
  1535 lemma divide_eq_0_iff [simp]:
  1536      "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
  1537 by (simp add: divide_inverse field_mult_eq_0_iff)
  1538 
  1539 lemma divide_pos_pos: "0 < (x::'a::ordered_field) ==> 
  1540     0 < y ==> 0 < x / y"
  1541   apply (subst pos_less_divide_eq)
  1542   apply assumption
  1543   apply simp
  1544 done
  1545 
  1546 lemma divide_nonneg_pos: "0 <= (x::'a::ordered_field) ==> 0 < y ==> 
  1547     0 <= x / y"
  1548   apply (subst pos_le_divide_eq)
  1549   apply assumption
  1550   apply simp
  1551 done
  1552 
  1553 lemma divide_neg_pos: "(x::'a::ordered_field) < 0 ==> 0 < y ==> x / y < 0"
  1554   apply (subst pos_divide_less_eq)
  1555   apply assumption
  1556   apply simp
  1557 done
  1558 
  1559 lemma divide_nonpos_pos: "(x::'a::ordered_field) <= 0 ==> 
  1560     0 < y ==> x / y <= 0"
  1561   apply (subst pos_divide_le_eq)
  1562   apply assumption
  1563   apply simp
  1564 done
  1565 
  1566 lemma divide_pos_neg: "0 < (x::'a::ordered_field) ==> y < 0 ==> x / y < 0"
  1567   apply (subst neg_divide_less_eq)
  1568   apply assumption
  1569   apply simp
  1570 done
  1571 
  1572 lemma divide_nonneg_neg: "0 <= (x::'a::ordered_field) ==> 
  1573     y < 0 ==> x / y <= 0"
  1574   apply (subst neg_divide_le_eq)
  1575   apply assumption
  1576   apply simp
  1577 done
  1578 
  1579 lemma divide_neg_neg: "(x::'a::ordered_field) < 0 ==> y < 0 ==> 0 < x / y"
  1580   apply (subst neg_less_divide_eq)
  1581   apply assumption
  1582   apply simp
  1583 done
  1584 
  1585 lemma divide_nonpos_neg: "(x::'a::ordered_field) <= 0 ==> y < 0 ==> 
  1586     0 <= x / y"
  1587   apply (subst neg_le_divide_eq)
  1588   apply assumption
  1589   apply simp
  1590 done
  1591 
  1592 
  1593 subsection{*Cancellation Laws for Division*}
  1594 
  1595 lemma divide_cancel_right [simp]:
  1596      "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
  1597 apply (cases "c=0", simp) 
  1598 apply (simp add: divide_inverse field_mult_cancel_right) 
  1599 done
  1600 
  1601 lemma divide_cancel_left [simp]:
  1602      "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
  1603 apply (cases "c=0", simp) 
  1604 apply (simp add: divide_inverse field_mult_cancel_left) 
  1605 done
  1606 
  1607 
  1608 subsection {* Division and the Number One *}
  1609 
  1610 text{*Simplify expressions equated with 1*}
  1611 lemma divide_eq_1_iff [simp]:
  1612      "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
  1613 apply (cases "b=0", simp) 
  1614 apply (simp add: right_inverse_eq) 
  1615 done
  1616 
  1617 lemma one_eq_divide_iff [simp]:
  1618      "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
  1619 by (simp add: eq_commute [of 1])  
  1620 
  1621 lemma zero_eq_1_divide_iff [simp]:
  1622      "((0::'a::{ordered_field,division_by_zero}) = 1/a) = (a = 0)"
  1623 apply (cases "a=0", simp) 
  1624 apply (auto simp add: nonzero_eq_divide_eq) 
  1625 done
  1626 
  1627 lemma one_divide_eq_0_iff [simp]:
  1628      "(1/a = (0::'a::{ordered_field,division_by_zero})) = (a = 0)"
  1629 apply (cases "a=0", simp) 
  1630 apply (insert zero_neq_one [THEN not_sym]) 
  1631 apply (auto simp add: nonzero_divide_eq_eq) 
  1632 done
  1633 
  1634 text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
  1635 lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
  1636 lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
  1637 lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
  1638 lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
  1639 
  1640 declare zero_less_divide_1_iff [simp]
  1641 declare divide_less_0_1_iff [simp]
  1642 declare zero_le_divide_1_iff [simp]
  1643 declare divide_le_0_1_iff [simp]
  1644 
  1645 
  1646 subsection {* Ordering Rules for Division *}
  1647 
  1648 lemma divide_strict_right_mono:
  1649      "[|a < b; 0 < c|] ==> a / c < b / (c::'a::ordered_field)"
  1650 by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
  1651               positive_imp_inverse_positive) 
  1652 
  1653 lemma divide_right_mono:
  1654      "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{ordered_field,division_by_zero})"
  1655   by (force simp add: divide_strict_right_mono order_le_less) 
  1656 
  1657 lemma divide_right_mono_neg: "(a::'a::{division_by_zero,ordered_field}) <= b 
  1658     ==> c <= 0 ==> b / c <= a / c"
  1659   apply (drule divide_right_mono [of _ _ "- c"])
  1660   apply auto
  1661 done
  1662 
  1663 lemma divide_strict_right_mono_neg:
  1664      "[|b < a; c < 0|] ==> a / c < b / (c::'a::ordered_field)"
  1665 apply (drule divide_strict_right_mono [of _ _ "-c"], simp) 
  1666 apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric]) 
  1667 done
  1668 
  1669 text{*The last premise ensures that @{term a} and @{term b} 
  1670       have the same sign*}
  1671 lemma divide_strict_left_mono:
  1672        "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
  1673 by (force simp add: zero_less_mult_iff divide_inverse mult_strict_left_mono 
  1674       order_less_imp_not_eq order_less_imp_not_eq2  
  1675       less_imp_inverse_less less_imp_inverse_less_neg) 
  1676 
  1677 lemma divide_left_mono:
  1678      "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::ordered_field)"
  1679   apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
  1680    prefer 2 
  1681    apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
  1682   apply (cases "c=0", simp add: divide_inverse)
  1683   apply (force simp add: divide_strict_left_mono order_le_less) 
  1684   done
  1685 
  1686 lemma divide_left_mono_neg: "(a::'a::{division_by_zero,ordered_field}) <= b 
  1687     ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
  1688   apply (drule divide_left_mono [of _ _ "- c"])
  1689   apply (auto simp add: mult_commute)
  1690 done
  1691 
  1692 lemma divide_strict_left_mono_neg:
  1693      "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
  1694   apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
  1695    prefer 2 
  1696    apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
  1697   apply (drule divide_strict_left_mono [of _ _ "-c"]) 
  1698    apply (simp_all add: mult_commute nonzero_minus_divide_left [symmetric]) 
  1699   done
  1700 
  1701 text{*Simplify quotients that are compared with the value 1.*}
  1702 
  1703 lemma le_divide_eq_1:
  1704   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1705   shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
  1706 by (auto simp add: le_divide_eq)
  1707 
  1708 lemma divide_le_eq_1:
  1709   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1710   shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
  1711 by (auto simp add: divide_le_eq)
  1712 
  1713 lemma less_divide_eq_1:
  1714   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1715   shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
  1716 by (auto simp add: less_divide_eq)
  1717 
  1718 lemma divide_less_eq_1:
  1719   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1720   shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
  1721 by (auto simp add: divide_less_eq)
  1722 
  1723 
  1724 subsection{*Conditional Simplification Rules: No Case Splits*}
  1725 
  1726 lemma le_divide_eq_1_pos [simp]:
  1727   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1728   shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
  1729 by (auto simp add: le_divide_eq)
  1730 
  1731 lemma le_divide_eq_1_neg [simp]:
  1732   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1733   shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
  1734 by (auto simp add: le_divide_eq)
  1735 
  1736 lemma divide_le_eq_1_pos [simp]:
  1737   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1738   shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
  1739 by (auto simp add: divide_le_eq)
  1740 
  1741 lemma divide_le_eq_1_neg [simp]:
  1742   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1743   shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
  1744 by (auto simp add: divide_le_eq)
  1745 
  1746 lemma less_divide_eq_1_pos [simp]:
  1747   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1748   shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
  1749 by (auto simp add: less_divide_eq)
  1750 
  1751 lemma less_divide_eq_1_neg [simp]:
  1752   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1753   shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
  1754 by (auto simp add: less_divide_eq)
  1755 
  1756 lemma divide_less_eq_1_pos [simp]:
  1757   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1758   shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
  1759 by (auto simp add: divide_less_eq)
  1760 
  1761 lemma divide_less_eq_1_neg [simp]:
  1762   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1763   shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
  1764 by (auto simp add: divide_less_eq)
  1765 
  1766 lemma eq_divide_eq_1 [simp]:
  1767   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1768   shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
  1769 by (auto simp add: eq_divide_eq)
  1770 
  1771 lemma divide_eq_eq_1 [simp]:
  1772   fixes a :: "'a :: {ordered_field,division_by_zero}"
  1773   shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
  1774 by (auto simp add: divide_eq_eq)
  1775 
  1776 
  1777 subsection {* Reasoning about inequalities with division *}
  1778 
  1779 lemma mult_right_le_one_le: "0 <= (x::'a::ordered_idom) ==> 0 <= y ==> y <= 1
  1780     ==> x * y <= x"
  1781   by (auto simp add: mult_compare_simps);
  1782 
  1783 lemma mult_left_le_one_le: "0 <= (x::'a::ordered_idom) ==> 0 <= y ==> y <= 1
  1784     ==> y * x <= x"
  1785   by (auto simp add: mult_compare_simps);
  1786 
  1787 lemma mult_imp_div_pos_le: "0 < (y::'a::ordered_field) ==> x <= z * y ==>
  1788     x / y <= z";
  1789   by (subst pos_divide_le_eq, assumption+);
  1790 
  1791 lemma mult_imp_le_div_pos: "0 < (y::'a::ordered_field) ==> z * y <= x ==>
  1792     z <= x / y";
  1793   by (subst pos_le_divide_eq, assumption+)
  1794 
  1795 lemma mult_imp_div_pos_less: "0 < (y::'a::ordered_field) ==> x < z * y ==>
  1796     x / y < z"
  1797   by (subst pos_divide_less_eq, assumption+)
  1798 
  1799 lemma mult_imp_less_div_pos: "0 < (y::'a::ordered_field) ==> z * y < x ==>
  1800     z < x / y"
  1801   by (subst pos_less_divide_eq, assumption+)
  1802 
  1803 lemma frac_le: "(0::'a::ordered_field) <= x ==> 
  1804     x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
  1805   apply (rule mult_imp_div_pos_le)
  1806   apply simp;
  1807   apply (subst times_divide_eq_left);
  1808   apply (rule mult_imp_le_div_pos, assumption)
  1809   apply (rule mult_mono)
  1810   apply simp_all
  1811 done
  1812 
  1813 lemma frac_less: "(0::'a::ordered_field) <= x ==> 
  1814     x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
  1815   apply (rule mult_imp_div_pos_less)
  1816   apply simp;
  1817   apply (subst times_divide_eq_left);
  1818   apply (rule mult_imp_less_div_pos, assumption)
  1819   apply (erule mult_less_le_imp_less)
  1820   apply simp_all
  1821 done
  1822 
  1823 lemma frac_less2: "(0::'a::ordered_field) < x ==> 
  1824     x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
  1825   apply (rule mult_imp_div_pos_less)
  1826   apply simp_all
  1827   apply (subst times_divide_eq_left);
  1828   apply (rule mult_imp_less_div_pos, assumption)
  1829   apply (erule mult_le_less_imp_less)
  1830   apply simp_all
  1831 done
  1832 
  1833 lemmas times_divide_eq = times_divide_eq_right times_divide_eq_left
  1834 
  1835 text{*It's not obvious whether these should be simprules or not. 
  1836   Their effect is to gather terms into one big fraction, like
  1837   a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
  1838   seem to need them.*}
  1839 
  1840 declare times_divide_eq [simp]
  1841 
  1842 
  1843 subsection {* Ordered Fields are Dense *}
  1844 
  1845 lemma less_add_one: "a < (a+1::'a::ordered_semidom)"
  1846 proof -
  1847   have "a+0 < (a+1::'a::ordered_semidom)"
  1848     by (blast intro: zero_less_one add_strict_left_mono) 
  1849   thus ?thesis by simp
  1850 qed
  1851 
  1852 lemma zero_less_two: "0 < (1+1::'a::ordered_semidom)"
  1853   by (blast intro: order_less_trans zero_less_one less_add_one) 
  1854 
  1855 lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::ordered_field)"
  1856 by (simp add: zero_less_two pos_less_divide_eq right_distrib) 
  1857 
  1858 lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::ordered_field) < b"
  1859 by (simp add: zero_less_two pos_divide_less_eq right_distrib) 
  1860 
  1861 lemma dense: "a < b ==> \<exists>r::'a::ordered_field. a < r & r < b"
  1862 by (blast intro!: less_half_sum gt_half_sum)
  1863 
  1864 
  1865 subsection {* Absolute Value *}
  1866 
  1867 lemma abs_one [simp]: "abs 1 = (1::'a::ordered_idom)"
  1868   by (simp add: abs_if zero_less_one [THEN order_less_not_sym]) 
  1869 
  1870 lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lordered_ring))" 
  1871 proof -
  1872   let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
  1873   let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
  1874   have a: "(abs a) * (abs b) = ?x"
  1875     by (simp only: abs_prts[of a] abs_prts[of b] ring_eq_simps)
  1876   {
  1877     fix u v :: 'a
  1878     have bh: "\<lbrakk>u = a; v = b\<rbrakk> \<Longrightarrow> 
  1879               u * v = pprt a * pprt b + pprt a * nprt b + 
  1880                       nprt a * pprt b + nprt a * nprt b"
  1881       apply (subst prts[of u], subst prts[of v])
  1882       apply (simp add: left_distrib right_distrib add_ac) 
  1883       done
  1884   }
  1885   note b = this[OF refl[of a] refl[of b]]
  1886   note addm = add_mono[of "0::'a" _ "0::'a", simplified]
  1887   note addm2 = add_mono[of _ "0::'a" _ "0::'a", simplified]
  1888   have xy: "- ?x <= ?y"
  1889     apply (simp)
  1890     apply (rule_tac y="0::'a" in order_trans)
  1891     apply (rule addm2)
  1892     apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
  1893     apply (rule addm)
  1894     apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
  1895     done
  1896   have yx: "?y <= ?x"
  1897     apply (simp add:diff_def)
  1898     apply (rule_tac y=0 in order_trans)
  1899     apply (rule addm2, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
  1900     apply (rule addm, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
  1901     done
  1902   have i1: "a*b <= abs a * abs b" by (simp only: a b yx)
  1903   have i2: "- (abs a * abs b) <= a*b" by (simp only: a b xy)
  1904   show ?thesis
  1905     apply (rule abs_leI)
  1906     apply (simp add: i1)
  1907     apply (simp add: i2[simplified minus_le_iff])
  1908     done
  1909 qed
  1910 
  1911 lemma abs_eq_mult: 
  1912   assumes "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
  1913   shows "abs (a*b) = abs a * abs (b::'a::lordered_ring)"
  1914 proof -
  1915   have s: "(0 <= a*b) | (a*b <= 0)"
  1916     apply (auto)    
  1917     apply (rule_tac split_mult_pos_le)
  1918     apply (rule_tac contrapos_np[of "a*b <= 0"])
  1919     apply (simp)
  1920     apply (rule_tac split_mult_neg_le)
  1921     apply (insert prems)
  1922     apply (blast)
  1923     done
  1924   have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
  1925     by (simp add: prts[symmetric])
  1926   show ?thesis
  1927   proof cases
  1928     assume "0 <= a * b"
  1929     then show ?thesis
  1930       apply (simp_all add: mulprts abs_prts)
  1931       apply (insert prems)
  1932       apply (auto simp add: 
  1933 	ring_eq_simps 
  1934 	iff2imp[OF zero_le_iff_zero_nprt] iff2imp[OF le_zero_iff_zero_pprt]
  1935 	iff2imp[OF le_zero_iff_pprt_id] iff2imp[OF zero_le_iff_nprt_id])
  1936 	apply(drule (1) mult_nonneg_nonpos[of a b], simp)
  1937 	apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
  1938       done
  1939   next
  1940     assume "~(0 <= a*b)"
  1941     with s have "a*b <= 0" by simp
  1942     then show ?thesis
  1943       apply (simp_all add: mulprts abs_prts)
  1944       apply (insert prems)
  1945       apply (auto simp add: ring_eq_simps)
  1946       apply(drule (1) mult_nonneg_nonneg[of a b],simp)
  1947       apply(drule (1) mult_nonpos_nonpos[of a b],simp)
  1948       done
  1949   qed
  1950 qed
  1951 
  1952 lemma abs_mult: "abs (a * b) = abs a * abs (b::'a::ordered_idom)" 
  1953 by (simp add: abs_eq_mult linorder_linear)
  1954 
  1955 lemma abs_mult_self: "abs a * abs a = a * (a::'a::ordered_idom)"
  1956 by (simp add: abs_if) 
  1957 
  1958 lemma nonzero_abs_inverse:
  1959      "a \<noteq> 0 ==> abs (inverse (a::'a::ordered_field)) = inverse (abs a)"
  1960 apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
  1961                       negative_imp_inverse_negative)
  1962 apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
  1963 done
  1964 
  1965 lemma abs_inverse [simp]:
  1966      "abs (inverse (a::'a::{ordered_field,division_by_zero})) = 
  1967       inverse (abs a)"
  1968 apply (cases "a=0", simp) 
  1969 apply (simp add: nonzero_abs_inverse) 
  1970 done
  1971 
  1972 lemma nonzero_abs_divide:
  1973      "b \<noteq> 0 ==> abs (a / (b::'a::ordered_field)) = abs a / abs b"
  1974 by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
  1975 
  1976 lemma abs_divide [simp]:
  1977      "abs (a / (b::'a::{ordered_field,division_by_zero})) = abs a / abs b"
  1978 apply (cases "b=0", simp) 
  1979 apply (simp add: nonzero_abs_divide) 
  1980 done
  1981 
  1982 lemma abs_mult_less:
  1983      "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::ordered_idom)"
  1984 proof -
  1985   assume ac: "abs a < c"
  1986   hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
  1987   assume "abs b < d"
  1988   thus ?thesis by (simp add: ac cpos mult_strict_mono) 
  1989 qed
  1990 
  1991 lemma eq_minus_self_iff: "(a = -a) = (a = (0::'a::ordered_idom))"
  1992 by (force simp add: order_eq_iff le_minus_self_iff minus_le_self_iff)
  1993 
  1994 lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::ordered_idom))"
  1995 by (simp add: order_less_le le_minus_self_iff eq_minus_self_iff)
  1996 
  1997 lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::ordered_idom))" 
  1998 apply (simp add: order_less_le abs_le_iff)  
  1999 apply (auto simp add: abs_if minus_le_self_iff eq_minus_self_iff)
  2000 apply (simp add: le_minus_self_iff linorder_neq_iff) 
  2001 done
  2002 
  2003 lemma abs_mult_pos: "(0::'a::ordered_idom) <= x ==> 
  2004     (abs y) * x = abs (y * x)";
  2005   apply (subst abs_mult);
  2006   apply simp;
  2007 done;
  2008 
  2009 lemma abs_div_pos: "(0::'a::{division_by_zero,ordered_field}) < y ==> 
  2010     abs x / y = abs (x / y)";
  2011   apply (subst abs_divide);
  2012   apply (simp add: order_less_imp_le);
  2013 done;
  2014 
  2015 
  2016 subsection {* Bounds of products via negative and positive Part *}
  2017 
  2018 lemma mult_le_prts:
  2019   assumes
  2020   "a1 <= (a::'a::lordered_ring)"
  2021   "a <= a2"
  2022   "b1 <= b"
  2023   "b <= b2"
  2024   shows
  2025   "a * b <= pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
  2026 proof - 
  2027   have "a * b = (pprt a + nprt a) * (pprt b + nprt b)" 
  2028     apply (subst prts[symmetric])+
  2029     apply simp
  2030     done
  2031   then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
  2032     by (simp add: ring_eq_simps)
  2033   moreover have "pprt a * pprt b <= pprt a2 * pprt b2"
  2034     by (simp_all add: prems mult_mono)
  2035   moreover have "pprt a * nprt b <= pprt a1 * nprt b2"
  2036   proof -
  2037     have "pprt a * nprt b <= pprt a * nprt b2"
  2038       by (simp add: mult_left_mono prems)
  2039     moreover have "pprt a * nprt b2 <= pprt a1 * nprt b2"
  2040       by (simp add: mult_right_mono_neg prems)
  2041     ultimately show ?thesis
  2042       by simp
  2043   qed
  2044   moreover have "nprt a * pprt b <= nprt a2 * pprt b1"
  2045   proof - 
  2046     have "nprt a * pprt b <= nprt a2 * pprt b"
  2047       by (simp add: mult_right_mono prems)
  2048     moreover have "nprt a2 * pprt b <= nprt a2 * pprt b1"
  2049       by (simp add: mult_left_mono_neg prems)
  2050     ultimately show ?thesis
  2051       by simp
  2052   qed
  2053   moreover have "nprt a * nprt b <= nprt a1 * nprt b1"
  2054   proof -
  2055     have "nprt a * nprt b <= nprt a * nprt b1"
  2056       by (simp add: mult_left_mono_neg prems)
  2057     moreover have "nprt a * nprt b1 <= nprt a1 * nprt b1"
  2058       by (simp add: mult_right_mono_neg prems)
  2059     ultimately show ?thesis
  2060       by simp
  2061   qed
  2062   ultimately show ?thesis
  2063     by - (rule add_mono | simp)+
  2064 qed
  2065 
  2066 lemma mult_ge_prts:
  2067   assumes
  2068   "a1 <= (a::'a::lordered_ring)"
  2069   "a <= a2"
  2070   "b1 <= b"
  2071   "b <= b2"
  2072   shows
  2073   "a * b >= nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
  2074 proof - 
  2075   from prems have a1:"- a2 <= -a" by auto
  2076   from prems have a2: "-a <= -a1" by auto
  2077   from mult_le_prts[of "-a2" "-a" "-a1" "b1" b "b2", OF a1 a2 prems(3) prems(4), simplified nprt_neg pprt_neg] 
  2078   have le: "- (a * b) <= - nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1" by simp  
  2079   then have "-(- nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1) <= a * b"
  2080     by (simp only: minus_le_iff)
  2081   then show ?thesis by simp
  2082 qed
  2083 
  2084 
  2085 subsection {* Theorems for proof tools *}
  2086 
  2087 lemma add_mono_thms_ordered_semiring:
  2088   fixes i j k :: "'a\<Colon>pordered_ab_semigroup_add"
  2089   shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
  2090     and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
  2091     and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
  2092     and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
  2093 by (rule add_mono, clarify+)+
  2094 
  2095 lemma add_mono_thms_ordered_field:
  2096   fixes i j k :: "'a\<Colon>pordered_cancel_ab_semigroup_add"
  2097   shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
  2098     and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
  2099     and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
  2100     and "i \<le> j \<and> k < l \<Longrightarrow> i + k < j + l"
  2101     and "i < j \<and> k < l \<Longrightarrow> i + k < j + l"
  2102 by (auto intro: add_strict_right_mono add_strict_left_mono
  2103   add_less_le_mono add_le_less_mono add_strict_mono)
  2104 
  2105 end