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