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