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