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