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