src/HOL/Ring_and_Field.thy
author krauss
Tue Nov 07 09:33:47 2006 +0100 (2006-11-07)
changeset 21199 2d83f93c3580
parent 20633 e98f59806244
child 21258 62f25a96f0c1
permissions -rw-r--r--
* Added annihilation axioms ("x * 0 = 0") to axclass semiring_0.
Richer structures do not inherit from semiring_0 anymore, because
anihilation is a theorem there, not an axiom.

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