src/HOL/Ring_and_Field.thy
author paulson
Sat Dec 27 21:02:14 2003 +0100 (2003-12-27)
changeset 14331 8dbbb7cf3637
parent 14321 55c688d2eefa
child 14334 6137d24eef79
permissions -rw-r--r--
re-organized numeric lemmas
paulson@14265
     1
(*  Title:   HOL/Ring_and_Field.thy
paulson@14265
     2
    ID:      $Id$
paulson@14265
     3
    Author:  Gertrud Bauer and Markus Wenzel, TU Muenchen
paulson@14269
     4
             Lawrence C Paulson, University of Cambridge
paulson@14265
     5
    License: GPL (GNU GENERAL PUBLIC LICENSE)
paulson@14265
     6
*)
paulson@14265
     7
paulson@14265
     8
header {*
paulson@14265
     9
  \title{Ring and field structures}
paulson@14265
    10
  \author{Gertrud Bauer and Markus Wenzel}
paulson@14265
    11
*}
paulson@14265
    12
paulson@14265
    13
theory Ring_and_Field = Inductive:
paulson@14265
    14
paulson@14265
    15
text{*Lemmas and extension to semirings by L. C. Paulson*}
paulson@14265
    16
paulson@14265
    17
subsection {* Abstract algebraic structures *}
paulson@14265
    18
paulson@14265
    19
axclass semiring \<subseteq> zero, one, plus, times
paulson@14265
    20
  add_assoc: "(a + b) + c = a + (b + c)"
paulson@14265
    21
  add_commute: "a + b = b + a"
paulson@14288
    22
  add_0 [simp]: "0 + a = a"
paulson@14265
    23
paulson@14265
    24
  mult_assoc: "(a * b) * c = a * (b * c)"
paulson@14265
    25
  mult_commute: "a * b = b * a"
paulson@14267
    26
  mult_1 [simp]: "1 * a = a"
paulson@14265
    27
paulson@14265
    28
  left_distrib: "(a + b) * c = a * c + b * c"
paulson@14265
    29
  zero_neq_one [simp]: "0 \<noteq> 1"
paulson@14265
    30
paulson@14265
    31
axclass ring \<subseteq> semiring, minus
paulson@14265
    32
  left_minus [simp]: "- a + a = 0"
paulson@14265
    33
  diff_minus: "a - b = a + (-b)"
paulson@14265
    34
paulson@14265
    35
axclass ordered_semiring \<subseteq> semiring, linorder
paulson@14265
    36
  add_left_mono: "a \<le> b ==> c + a \<le> c + b"
paulson@14265
    37
  mult_strict_left_mono: "a < b ==> 0 < c ==> c * a < c * b"
paulson@14265
    38
paulson@14265
    39
axclass ordered_ring \<subseteq> ordered_semiring, ring
paulson@14265
    40
  abs_if: "\<bar>a\<bar> = (if a < 0 then -a else a)"
paulson@14265
    41
paulson@14265
    42
axclass field \<subseteq> ring, inverse
paulson@14265
    43
  left_inverse [simp]: "a \<noteq> 0 ==> inverse a * a = 1"
paulson@14265
    44
  divide_inverse:      "b \<noteq> 0 ==> a / b = a * inverse b"
paulson@14265
    45
paulson@14265
    46
axclass ordered_field \<subseteq> ordered_ring, field
paulson@14265
    47
paulson@14265
    48
axclass division_by_zero \<subseteq> zero, inverse
paulson@14268
    49
  inverse_zero [simp]: "inverse 0 = 0"
paulson@14268
    50
  divide_zero [simp]: "a / 0 = 0"
paulson@14265
    51
paulson@14265
    52
paulson@14270
    53
subsection {* Derived Rules for Addition *}
paulson@14265
    54
paulson@14288
    55
lemma add_0_right [simp]: "a + 0 = (a::'a::semiring)"
paulson@14265
    56
proof -
paulson@14265
    57
  have "a + 0 = 0 + a" by (simp only: add_commute)
paulson@14265
    58
  also have "... = a" by simp
paulson@14265
    59
  finally show ?thesis .
paulson@14265
    60
qed
paulson@14265
    61
paulson@14265
    62
lemma add_left_commute: "a + (b + c) = b + (a + (c::'a::semiring))"
paulson@14265
    63
  by (rule mk_left_commute [of "op +", OF add_assoc add_commute])
paulson@14265
    64
paulson@14265
    65
theorems add_ac = add_assoc add_commute add_left_commute
paulson@14265
    66
paulson@14265
    67
lemma right_minus [simp]: "a + -(a::'a::ring) = 0"
paulson@14265
    68
proof -
paulson@14265
    69
  have "a + -a = -a + a" by (simp add: add_ac)
paulson@14265
    70
  also have "... = 0" by simp
paulson@14265
    71
  finally show ?thesis .
paulson@14265
    72
qed
paulson@14265
    73
paulson@14265
    74
lemma right_minus_eq: "(a - b = 0) = (a = (b::'a::ring))"
paulson@14265
    75
proof
paulson@14265
    76
  have "a = a - b + b" by (simp add: diff_minus add_ac)
paulson@14265
    77
  also assume "a - b = 0"
paulson@14265
    78
  finally show "a = b" by simp
paulson@14265
    79
next
paulson@14265
    80
  assume "a = b"
paulson@14265
    81
  thus "a - b = 0" by (simp add: diff_minus)
paulson@14265
    82
qed
paulson@14265
    83
paulson@14265
    84
lemma add_left_cancel [simp]:
paulson@14265
    85
     "(a + b = a + c) = (b = (c::'a::ring))"
paulson@14265
    86
proof
paulson@14265
    87
  assume eq: "a + b = a + c"
paulson@14268
    88
  hence "(-a + a) + b = (-a + a) + c"
paulson@14265
    89
    by (simp only: eq add_assoc)
paulson@14266
    90
  thus "b = c" by simp
paulson@14265
    91
next
paulson@14265
    92
  assume eq: "b = c"
paulson@14266
    93
  thus "a + b = a + c" by simp
paulson@14265
    94
qed
paulson@14265
    95
paulson@14265
    96
lemma add_right_cancel [simp]:
paulson@14265
    97
     "(b + a = c + a) = (b = (c::'a::ring))"
paulson@14265
    98
  by (simp add: add_commute)
paulson@14265
    99
paulson@14265
   100
lemma minus_minus [simp]: "- (- (a::'a::ring)) = a"
paulson@14265
   101
  proof (rule add_left_cancel [of "-a", THEN iffD1])
paulson@14265
   102
    show "(-a + -(-a) = -a + a)"
paulson@14265
   103
    by simp
paulson@14265
   104
  qed
paulson@14265
   105
paulson@14265
   106
lemma equals_zero_I: "a+b = 0 ==> -a = (b::'a::ring)"
paulson@14265
   107
apply (rule right_minus_eq [THEN iffD1, symmetric])
paulson@14265
   108
apply (simp add: diff_minus add_commute) 
paulson@14265
   109
done
paulson@14265
   110
paulson@14265
   111
lemma minus_zero [simp]: "- 0 = (0::'a::ring)"
paulson@14265
   112
by (simp add: equals_zero_I)
paulson@14265
   113
paulson@14270
   114
lemma diff_self [simp]: "a - (a::'a::ring) = 0"
paulson@14270
   115
  by (simp add: diff_minus)
paulson@14270
   116
paulson@14270
   117
lemma diff_0 [simp]: "(0::'a::ring) - a = -a"
paulson@14270
   118
by (simp add: diff_minus)
paulson@14270
   119
paulson@14270
   120
lemma diff_0_right [simp]: "a - (0::'a::ring) = a" 
paulson@14270
   121
by (simp add: diff_minus)
paulson@14270
   122
paulson@14288
   123
lemma diff_minus_eq_add [simp]: "a - - b = a + (b::'a::ring)"
paulson@14288
   124
by (simp add: diff_minus)
paulson@14288
   125
paulson@14265
   126
lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ring))" 
paulson@14265
   127
  proof 
paulson@14265
   128
    assume "- a = - b"
paulson@14268
   129
    hence "- (- a) = - (- b)"
paulson@14265
   130
      by simp
paulson@14266
   131
    thus "a=b" by simp
paulson@14265
   132
  next
paulson@14265
   133
    assume "a=b"
paulson@14266
   134
    thus "-a = -b" by simp
paulson@14265
   135
  qed
paulson@14265
   136
paulson@14265
   137
lemma neg_equal_0_iff_equal [simp]: "(-a = 0) = (a = (0::'a::ring))"
paulson@14265
   138
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   139
paulson@14265
   140
lemma neg_0_equal_iff_equal [simp]: "(0 = -a) = (0 = (a::'a::ring))"
paulson@14265
   141
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   142
paulson@14272
   143
text{*The next two equations can make the simplifier loop!*}
paulson@14272
   144
paulson@14272
   145
lemma equation_minus_iff: "(a = - b) = (b = - (a::'a::ring))"
paulson@14272
   146
  proof -
paulson@14272
   147
  have "(- (-a) = - b) = (- a = b)" by (rule neg_equal_iff_equal)
paulson@14272
   148
  thus ?thesis by (simp add: eq_commute)
paulson@14272
   149
  qed
paulson@14272
   150
paulson@14272
   151
lemma minus_equation_iff: "(- a = b) = (- (b::'a::ring) = a)"
paulson@14272
   152
  proof -
paulson@14272
   153
  have "(- a = - (-b)) = (a = -b)" by (rule neg_equal_iff_equal)
paulson@14272
   154
  thus ?thesis by (simp add: eq_commute)
paulson@14272
   155
  qed
paulson@14272
   156
paulson@14265
   157
paulson@14265
   158
subsection {* Derived rules for multiplication *}
paulson@14265
   159
paulson@14267
   160
lemma mult_1_right [simp]: "a * (1::'a::semiring) = a"
paulson@14265
   161
proof -
paulson@14267
   162
  have "a * 1 = 1 * a" by (simp add: mult_commute)
paulson@14267
   163
  also have "... = a" by simp
paulson@14265
   164
  finally show ?thesis .
paulson@14265
   165
qed
paulson@14265
   166
paulson@14265
   167
lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::semiring))"
paulson@14265
   168
  by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute])
paulson@14265
   169
paulson@14265
   170
theorems mult_ac = mult_assoc mult_commute mult_left_commute
paulson@14265
   171
paulson@14265
   172
lemma mult_left_zero [simp]: "0 * a = (0::'a::ring)"
paulson@14265
   173
proof -
paulson@14265
   174
  have "0*a + 0*a = 0*a + 0"
paulson@14265
   175
    by (simp add: left_distrib [symmetric])
paulson@14266
   176
  thus ?thesis by (simp only: add_left_cancel)
paulson@14265
   177
qed
paulson@14265
   178
paulson@14265
   179
lemma mult_right_zero [simp]: "a * 0 = (0::'a::ring)"
paulson@14265
   180
  by (simp add: mult_commute)
paulson@14265
   181
paulson@14265
   182
paulson@14265
   183
subsection {* Distribution rules *}
paulson@14265
   184
paulson@14265
   185
lemma right_distrib: "a * (b + c) = a * b + a * (c::'a::semiring)"
paulson@14265
   186
proof -
paulson@14265
   187
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
paulson@14265
   188
  also have "... = b * a + c * a" by (simp only: left_distrib)
paulson@14265
   189
  also have "... = a * b + a * c" by (simp add: mult_ac)
paulson@14265
   190
  finally show ?thesis .
paulson@14265
   191
qed
paulson@14265
   192
paulson@14265
   193
theorems ring_distrib = right_distrib left_distrib
paulson@14265
   194
paulson@14272
   195
text{*For the @{text combine_numerals} simproc*}
paulson@14272
   196
lemma combine_common_factor: "a*e + (b*e + c) = (a+b)*e + (c::'a::semiring)"
paulson@14272
   197
by (simp add: left_distrib add_ac)
paulson@14272
   198
paulson@14265
   199
lemma minus_add_distrib [simp]: "- (a + b) = -a + -(b::'a::ring)"
paulson@14265
   200
apply (rule equals_zero_I)
paulson@14265
   201
apply (simp add: add_ac) 
paulson@14265
   202
done
paulson@14265
   203
paulson@14265
   204
lemma minus_mult_left: "- (a * b) = (-a) * (b::'a::ring)"
paulson@14265
   205
apply (rule equals_zero_I)
paulson@14265
   206
apply (simp add: left_distrib [symmetric]) 
paulson@14265
   207
done
paulson@14265
   208
paulson@14265
   209
lemma minus_mult_right: "- (a * b) = a * -(b::'a::ring)"
paulson@14265
   210
apply (rule equals_zero_I)
paulson@14265
   211
apply (simp add: right_distrib [symmetric]) 
paulson@14265
   212
done
paulson@14265
   213
paulson@14268
   214
lemma minus_mult_minus [simp]: "(- a) * (- b) = a * (b::'a::ring)"
paulson@14268
   215
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
paulson@14268
   216
paulson@14265
   217
lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)"
paulson@14265
   218
by (simp add: right_distrib diff_minus 
paulson@14265
   219
              minus_mult_left [symmetric] minus_mult_right [symmetric]) 
paulson@14265
   220
paulson@14272
   221
lemma left_diff_distrib: "(a - b) * c = a * c - b * (c::'a::ring)"
paulson@14272
   222
by (simp add: mult_commute [of _ c] right_diff_distrib) 
paulson@14272
   223
paulson@14270
   224
lemma minus_diff_eq [simp]: "- (a - b) = b - (a::'a::ring)"
paulson@14270
   225
by (simp add: diff_minus add_commute) 
paulson@14265
   226
paulson@14270
   227
paulson@14270
   228
subsection {* Ordering Rules for Addition *}
paulson@14265
   229
paulson@14265
   230
lemma add_right_mono: "a \<le> (b::'a::ordered_semiring) ==> a + c \<le> b + c"
paulson@14265
   231
by (simp add: add_commute [of _ c] add_left_mono)
paulson@14265
   232
paulson@14267
   233
text {* non-strict, in both arguments *}
paulson@14267
   234
lemma add_mono: "[|a \<le> b;  c \<le> d|] ==> a + c \<le> b + (d::'a::ordered_semiring)"
paulson@14267
   235
  apply (erule add_right_mono [THEN order_trans])
paulson@14267
   236
  apply (simp add: add_commute add_left_mono)
paulson@14267
   237
  done
paulson@14267
   238
paulson@14268
   239
lemma add_strict_left_mono:
paulson@14268
   240
     "a < b ==> c + a < c + (b::'a::ordered_ring)"
paulson@14268
   241
 by (simp add: order_less_le add_left_mono) 
paulson@14268
   242
paulson@14268
   243
lemma add_strict_right_mono:
paulson@14268
   244
     "a < b ==> a + c < b + (c::'a::ordered_ring)"
paulson@14268
   245
 by (simp add: add_commute [of _ c] add_strict_left_mono)
paulson@14268
   246
paulson@14268
   247
text{*Strict monotonicity in both arguments*}
paulson@14268
   248
lemma add_strict_mono: "[|a<b; c<d|] ==> a + c < b + (d::'a::ordered_ring)"
paulson@14268
   249
apply (erule add_strict_right_mono [THEN order_less_trans])
paulson@14268
   250
apply (erule add_strict_left_mono)
paulson@14268
   251
done
paulson@14268
   252
paulson@14270
   253
lemma add_less_imp_less_left:
paulson@14270
   254
      assumes less: "c + a < c + b"  shows "a < (b::'a::ordered_ring)"
paulson@14270
   255
  proof -
paulson@14270
   256
  have "-c + (c + a) < -c + (c + b)"
paulson@14270
   257
    by (rule add_strict_left_mono [OF less])
paulson@14270
   258
  thus "a < b" by (simp add: add_assoc [symmetric])
paulson@14270
   259
  qed
paulson@14270
   260
paulson@14270
   261
lemma add_less_imp_less_right:
paulson@14270
   262
      "a + c < b + c ==> a < (b::'a::ordered_ring)"
paulson@14270
   263
apply (rule add_less_imp_less_left [of c])
paulson@14270
   264
apply (simp add: add_commute)  
paulson@14270
   265
done
paulson@14270
   266
paulson@14270
   267
lemma add_less_cancel_left [simp]:
paulson@14270
   268
    "(c+a < c+b) = (a < (b::'a::ordered_ring))"
paulson@14270
   269
by (blast intro: add_less_imp_less_left add_strict_left_mono) 
paulson@14270
   270
paulson@14270
   271
lemma add_less_cancel_right [simp]:
paulson@14270
   272
    "(a+c < b+c) = (a < (b::'a::ordered_ring))"
paulson@14270
   273
by (blast intro: add_less_imp_less_right add_strict_right_mono)
paulson@14270
   274
paulson@14270
   275
lemma add_le_cancel_left [simp]:
paulson@14270
   276
    "(c+a \<le> c+b) = (a \<le> (b::'a::ordered_ring))"
paulson@14270
   277
by (simp add: linorder_not_less [symmetric]) 
paulson@14270
   278
paulson@14270
   279
lemma add_le_cancel_right [simp]:
paulson@14270
   280
    "(a+c \<le> b+c) = (a \<le> (b::'a::ordered_ring))"
paulson@14270
   281
by (simp add: linorder_not_less [symmetric]) 
paulson@14270
   282
paulson@14270
   283
lemma add_le_imp_le_left:
paulson@14270
   284
      "c + a \<le> c + b ==> a \<le> (b::'a::ordered_ring)"
paulson@14270
   285
by simp
paulson@14270
   286
paulson@14270
   287
lemma add_le_imp_le_right:
paulson@14270
   288
      "a + c \<le> b + c ==> a \<le> (b::'a::ordered_ring)"
paulson@14270
   289
by simp
paulson@14270
   290
paulson@14270
   291
paulson@14270
   292
subsection {* Ordering Rules for Unary Minus *}
paulson@14270
   293
paulson@14265
   294
lemma le_imp_neg_le:
paulson@14269
   295
      assumes "a \<le> (b::'a::ordered_ring)" shows "-b \<le> -a"
paulson@14265
   296
  proof -
paulson@14265
   297
  have "-a+a \<le> -a+b"
paulson@14265
   298
    by (rule add_left_mono) 
paulson@14268
   299
  hence "0 \<le> -a+b"
paulson@14265
   300
    by simp
paulson@14268
   301
  hence "0 + (-b) \<le> (-a + b) + (-b)"
paulson@14265
   302
    by (rule add_right_mono) 
paulson@14266
   303
  thus ?thesis
paulson@14265
   304
    by (simp add: add_assoc)
paulson@14265
   305
  qed
paulson@14265
   306
paulson@14265
   307
lemma neg_le_iff_le [simp]: "(-b \<le> -a) = (a \<le> (b::'a::ordered_ring))"
paulson@14265
   308
  proof 
paulson@14265
   309
    assume "- b \<le> - a"
paulson@14268
   310
    hence "- (- a) \<le> - (- b)"
paulson@14265
   311
      by (rule le_imp_neg_le)
paulson@14266
   312
    thus "a\<le>b" by simp
paulson@14265
   313
  next
paulson@14265
   314
    assume "a\<le>b"
paulson@14266
   315
    thus "-b \<le> -a" by (rule le_imp_neg_le)
paulson@14265
   316
  qed
paulson@14265
   317
paulson@14265
   318
lemma neg_le_0_iff_le [simp]: "(-a \<le> 0) = (0 \<le> (a::'a::ordered_ring))"
paulson@14265
   319
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   320
paulson@14265
   321
lemma neg_0_le_iff_le [simp]: "(0 \<le> -a) = (a \<le> (0::'a::ordered_ring))"
paulson@14265
   322
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   323
paulson@14265
   324
lemma neg_less_iff_less [simp]: "(-b < -a) = (a < (b::'a::ordered_ring))"
paulson@14265
   325
by (force simp add: order_less_le) 
paulson@14265
   326
paulson@14265
   327
lemma neg_less_0_iff_less [simp]: "(-a < 0) = (0 < (a::'a::ordered_ring))"
paulson@14265
   328
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   329
paulson@14265
   330
lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::ordered_ring))"
paulson@14265
   331
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   332
paulson@14272
   333
text{*The next several equations can make the simplifier loop!*}
paulson@14272
   334
paulson@14272
   335
lemma less_minus_iff: "(a < - b) = (b < - (a::'a::ordered_ring))"
paulson@14272
   336
  proof -
paulson@14272
   337
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
paulson@14272
   338
  thus ?thesis by simp
paulson@14272
   339
  qed
paulson@14272
   340
paulson@14272
   341
lemma minus_less_iff: "(- a < b) = (- b < (a::'a::ordered_ring))"
paulson@14272
   342
  proof -
paulson@14272
   343
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
paulson@14272
   344
  thus ?thesis by simp
paulson@14272
   345
  qed
paulson@14272
   346
paulson@14272
   347
lemma le_minus_iff: "(a \<le> - b) = (b \<le> - (a::'a::ordered_ring))"
paulson@14272
   348
apply (simp add: linorder_not_less [symmetric])
paulson@14272
   349
apply (rule minus_less_iff) 
paulson@14272
   350
done
paulson@14272
   351
paulson@14272
   352
lemma minus_le_iff: "(- a \<le> b) = (- b \<le> (a::'a::ordered_ring))"
paulson@14272
   353
apply (simp add: linorder_not_less [symmetric])
paulson@14272
   354
apply (rule less_minus_iff) 
paulson@14272
   355
done
paulson@14272
   356
paulson@14270
   357
paulson@14270
   358
subsection{*Subtraction Laws*}
paulson@14270
   359
paulson@14270
   360
lemma add_diff_eq: "a + (b - c) = (a + b) - (c::'a::ring)"
paulson@14270
   361
by (simp add: diff_minus add_ac)
paulson@14270
   362
paulson@14270
   363
lemma diff_add_eq: "(a - b) + c = (a + c) - (b::'a::ring)"
paulson@14270
   364
by (simp add: diff_minus add_ac)
paulson@14270
   365
paulson@14270
   366
lemma diff_eq_eq: "(a-b = c) = (a = c + (b::'a::ring))"
paulson@14270
   367
by (auto simp add: diff_minus add_assoc)
paulson@14270
   368
paulson@14270
   369
lemma eq_diff_eq: "(a = c-b) = (a + (b::'a::ring) = c)"
paulson@14270
   370
by (auto simp add: diff_minus add_assoc)
paulson@14270
   371
paulson@14270
   372
lemma diff_diff_eq: "(a - b) - c = a - (b + (c::'a::ring))"
paulson@14270
   373
by (simp add: diff_minus add_ac)
paulson@14270
   374
paulson@14270
   375
lemma diff_diff_eq2: "a - (b - c) = (a + c) - (b::'a::ring)"
paulson@14270
   376
by (simp add: diff_minus add_ac)
paulson@14270
   377
paulson@14270
   378
text{*Further subtraction laws for ordered rings*}
paulson@14270
   379
paulson@14272
   380
lemma less_iff_diff_less_0: "(a < b) = (a - b < (0::'a::ordered_ring))"
paulson@14270
   381
proof -
paulson@14270
   382
  have  "(a < b) = (a + (- b) < b + (-b))"  
paulson@14270
   383
    by (simp only: add_less_cancel_right)
paulson@14270
   384
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
paulson@14270
   385
  finally show ?thesis .
paulson@14270
   386
qed
paulson@14270
   387
paulson@14270
   388
lemma diff_less_eq: "(a-b < c) = (a < c + (b::'a::ordered_ring))"
paulson@14272
   389
apply (subst less_iff_diff_less_0)
paulson@14272
   390
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
paulson@14270
   391
apply (simp add: diff_minus add_ac)
paulson@14270
   392
done
paulson@14270
   393
paulson@14270
   394
lemma less_diff_eq: "(a < c-b) = (a + (b::'a::ordered_ring) < c)"
paulson@14272
   395
apply (subst less_iff_diff_less_0)
paulson@14272
   396
apply (rule less_iff_diff_less_0 [of _ "c-b", THEN ssubst])
paulson@14270
   397
apply (simp add: diff_minus add_ac)
paulson@14270
   398
done
paulson@14270
   399
paulson@14270
   400
lemma diff_le_eq: "(a-b \<le> c) = (a \<le> c + (b::'a::ordered_ring))"
paulson@14270
   401
by (simp add: linorder_not_less [symmetric] less_diff_eq)
paulson@14270
   402
paulson@14270
   403
lemma le_diff_eq: "(a \<le> c-b) = (a + (b::'a::ordered_ring) \<le> c)"
paulson@14270
   404
by (simp add: linorder_not_less [symmetric] diff_less_eq)
paulson@14270
   405
paulson@14270
   406
text{*This list of rewrites simplifies (in)equalities by bringing subtractions
paulson@14270
   407
  to the top and then moving negative terms to the other side.
paulson@14270
   408
  Use with @{text add_ac}*}
paulson@14270
   409
lemmas compare_rls =
paulson@14270
   410
       diff_minus [symmetric]
paulson@14270
   411
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
paulson@14270
   412
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
paulson@14270
   413
       diff_eq_eq eq_diff_eq
paulson@14270
   414
paulson@14270
   415
paulson@14272
   416
subsection{*Lemmas for the @{text cancel_numerals} simproc*}
paulson@14272
   417
paulson@14272
   418
lemma eq_iff_diff_eq_0: "(a = b) = (a-b = (0::'a::ring))"
paulson@14272
   419
by (simp add: compare_rls)
paulson@14272
   420
paulson@14272
   421
lemma le_iff_diff_le_0: "(a \<le> b) = (a-b \<le> (0::'a::ordered_ring))"
paulson@14272
   422
by (simp add: compare_rls)
paulson@14272
   423
paulson@14272
   424
lemma eq_add_iff1:
paulson@14272
   425
     "(a*e + c = b*e + d) = ((a-b)*e + c = (d::'a::ring))"
paulson@14272
   426
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   427
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   428
done
paulson@14272
   429
paulson@14272
   430
lemma eq_add_iff2:
paulson@14272
   431
     "(a*e + c = b*e + d) = (c = (b-a)*e + (d::'a::ring))"
paulson@14272
   432
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   433
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   434
done
paulson@14272
   435
paulson@14272
   436
lemma less_add_iff1:
paulson@14272
   437
     "(a*e + c < b*e + d) = ((a-b)*e + c < (d::'a::ordered_ring))"
paulson@14272
   438
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   439
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   440
done
paulson@14272
   441
paulson@14272
   442
lemma less_add_iff2:
paulson@14272
   443
     "(a*e + c < b*e + d) = (c < (b-a)*e + (d::'a::ordered_ring))"
paulson@14272
   444
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   445
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   446
done
paulson@14272
   447
paulson@14272
   448
lemma le_add_iff1:
paulson@14272
   449
     "(a*e + c \<le> b*e + d) = ((a-b)*e + c \<le> (d::'a::ordered_ring))"
paulson@14272
   450
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   451
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   452
done
paulson@14272
   453
paulson@14272
   454
lemma le_add_iff2:
paulson@14272
   455
     "(a*e + c \<le> b*e + d) = (c \<le> (b-a)*e + (d::'a::ordered_ring))"
paulson@14272
   456
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   457
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   458
done
paulson@14272
   459
paulson@14272
   460
paulson@14270
   461
subsection {* Ordering Rules for Multiplication *}
paulson@14270
   462
paulson@14265
   463
lemma mult_strict_right_mono:
paulson@14265
   464
     "[|a < b; 0 < c|] ==> a * c < b * (c::'a::ordered_semiring)"
paulson@14265
   465
by (simp add: mult_commute [of _ c] mult_strict_left_mono)
paulson@14265
   466
paulson@14265
   467
lemma mult_left_mono:
paulson@14267
   468
     "[|a \<le> b; 0 \<le> c|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14267
   469
  apply (case_tac "c=0", simp)
paulson@14267
   470
  apply (force simp add: mult_strict_left_mono order_le_less) 
paulson@14267
   471
  done
paulson@14265
   472
paulson@14265
   473
lemma mult_right_mono:
paulson@14267
   474
     "[|a \<le> b; 0 \<le> c|] ==> a*c \<le> b * (c::'a::ordered_ring)"
paulson@14267
   475
  by (simp add: mult_left_mono mult_commute [of _ c]) 
paulson@14265
   476
paulson@14265
   477
lemma mult_strict_left_mono_neg:
paulson@14265
   478
     "[|b < a; c < 0|] ==> c * a < c * (b::'a::ordered_ring)"
paulson@14265
   479
apply (drule mult_strict_left_mono [of _ _ "-c"])
paulson@14265
   480
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14265
   481
done
paulson@14265
   482
paulson@14265
   483
lemma mult_strict_right_mono_neg:
paulson@14265
   484
     "[|b < a; c < 0|] ==> a * c < b * (c::'a::ordered_ring)"
paulson@14265
   485
apply (drule mult_strict_right_mono [of _ _ "-c"])
paulson@14265
   486
apply (simp_all add: minus_mult_right [symmetric]) 
paulson@14265
   487
done
paulson@14265
   488
paulson@14265
   489
paulson@14265
   490
subsection{* Products of Signs *}
paulson@14265
   491
paulson@14265
   492
lemma mult_pos: "[| (0::'a::ordered_ring) < a; 0 < b |] ==> 0 < a*b"
paulson@14265
   493
by (drule mult_strict_left_mono [of 0 b], auto)
paulson@14265
   494
paulson@14265
   495
lemma mult_pos_neg: "[| (0::'a::ordered_ring) < a; b < 0 |] ==> a*b < 0"
paulson@14265
   496
by (drule mult_strict_left_mono [of b 0], auto)
paulson@14265
   497
paulson@14265
   498
lemma mult_neg: "[| a < (0::'a::ordered_ring); b < 0 |] ==> 0 < a*b"
paulson@14265
   499
by (drule mult_strict_right_mono_neg, auto)
paulson@14265
   500
paulson@14265
   501
lemma zero_less_mult_pos: "[| 0 < a*b; 0 < a|] ==> 0 < (b::'a::ordered_ring)"
paulson@14265
   502
apply (case_tac "b\<le>0") 
paulson@14265
   503
 apply (auto simp add: order_le_less linorder_not_less)
paulson@14265
   504
apply (drule_tac mult_pos_neg [of a b]) 
paulson@14265
   505
 apply (auto dest: order_less_not_sym)
paulson@14265
   506
done
paulson@14265
   507
paulson@14265
   508
lemma zero_less_mult_iff:
paulson@14265
   509
     "((0::'a::ordered_ring) < a*b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14265
   510
apply (auto simp add: order_le_less linorder_not_less mult_pos mult_neg)
paulson@14265
   511
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   512
apply (simp add: mult_commute [of a b]) 
paulson@14265
   513
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   514
done
paulson@14265
   515
paulson@14277
   516
text{*A field has no "zero divisors", so this theorem should hold without the
paulson@14277
   517
      assumption of an ordering.  See @{text field_mult_eq_0_iff} below.*}
paulson@14266
   518
lemma mult_eq_0_iff [simp]: "(a*b = (0::'a::ordered_ring)) = (a = 0 | b = 0)"
paulson@14265
   519
apply (case_tac "a < 0")
paulson@14265
   520
apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff)
paulson@14265
   521
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+
paulson@14265
   522
done
paulson@14265
   523
paulson@14265
   524
lemma zero_le_mult_iff:
paulson@14265
   525
     "((0::'a::ordered_ring) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14265
   526
by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less
paulson@14265
   527
                   zero_less_mult_iff)
paulson@14265
   528
paulson@14265
   529
lemma mult_less_0_iff:
paulson@14265
   530
     "(a*b < (0::'a::ordered_ring)) = (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14265
   531
apply (insert zero_less_mult_iff [of "-a" b]) 
paulson@14265
   532
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   533
done
paulson@14265
   534
paulson@14265
   535
lemma mult_le_0_iff:
paulson@14265
   536
     "(a*b \<le> (0::'a::ordered_ring)) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14265
   537
apply (insert zero_le_mult_iff [of "-a" b]) 
paulson@14265
   538
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   539
done
paulson@14265
   540
paulson@14265
   541
lemma zero_le_square: "(0::'a::ordered_ring) \<le> a*a"
paulson@14265
   542
by (simp add: zero_le_mult_iff linorder_linear) 
paulson@14265
   543
paulson@14265
   544
lemma zero_less_one: "(0::'a::ordered_ring) < 1"
paulson@14265
   545
apply (insert zero_le_square [of 1]) 
paulson@14265
   546
apply (simp add: order_less_le) 
paulson@14265
   547
done
paulson@14265
   548
paulson@14268
   549
lemma zero_le_one: "(0::'a::ordered_ring) \<le> 1"
paulson@14268
   550
  by (rule zero_less_one [THEN order_less_imp_le]) 
paulson@14268
   551
paulson@14268
   552
paulson@14268
   553
subsection{*More Monotonicity*}
paulson@14268
   554
paulson@14268
   555
lemma mult_left_mono_neg:
paulson@14268
   556
     "[|b \<le> a; c \<le> 0|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14268
   557
apply (drule mult_left_mono [of _ _ "-c"]) 
paulson@14268
   558
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14268
   559
done
paulson@14268
   560
paulson@14268
   561
lemma mult_right_mono_neg:
paulson@14268
   562
     "[|b \<le> a; c \<le> 0|] ==> a * c \<le> b * (c::'a::ordered_ring)"
paulson@14268
   563
  by (simp add: mult_left_mono_neg mult_commute [of _ c]) 
paulson@14268
   564
paulson@14268
   565
text{*Strict monotonicity in both arguments*}
paulson@14268
   566
lemma mult_strict_mono:
paulson@14268
   567
     "[|a<b; c<d; 0<b; 0\<le>c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   568
apply (case_tac "c=0")
paulson@14268
   569
 apply (simp add: mult_pos) 
paulson@14268
   570
apply (erule mult_strict_right_mono [THEN order_less_trans])
paulson@14268
   571
 apply (force simp add: order_le_less) 
paulson@14268
   572
apply (erule mult_strict_left_mono, assumption)
paulson@14268
   573
done
paulson@14268
   574
paulson@14268
   575
text{*This weaker variant has more natural premises*}
paulson@14268
   576
lemma mult_strict_mono':
paulson@14268
   577
     "[| a<b; c<d; 0 \<le> a; 0 \<le> c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   578
apply (rule mult_strict_mono)
paulson@14268
   579
apply (blast intro: order_le_less_trans)+
paulson@14268
   580
done
paulson@14268
   581
paulson@14268
   582
lemma mult_mono:
paulson@14268
   583
     "[|a \<le> b; c \<le> d; 0 \<le> b; 0 \<le> c|] 
paulson@14268
   584
      ==> a * c  \<le>  b * (d::'a::ordered_ring)"
paulson@14268
   585
apply (erule mult_right_mono [THEN order_trans], assumption)
paulson@14268
   586
apply (erule mult_left_mono, assumption)
paulson@14268
   587
done
paulson@14268
   588
paulson@14268
   589
paulson@14268
   590
subsection{*Cancellation Laws for Relationships With a Common Factor*}
paulson@14268
   591
paulson@14268
   592
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
paulson@14268
   593
   also with the relations @{text "\<le>"} and equality.*}
paulson@14268
   594
paulson@14268
   595
lemma mult_less_cancel_right:
paulson@14268
   596
    "(a*c < b*c) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   597
apply (case_tac "c = 0")
paulson@14268
   598
apply (auto simp add: linorder_neq_iff mult_strict_right_mono 
paulson@14268
   599
                      mult_strict_right_mono_neg)
paulson@14268
   600
apply (auto simp add: linorder_not_less 
paulson@14268
   601
                      linorder_not_le [symmetric, of "a*c"]
paulson@14268
   602
                      linorder_not_le [symmetric, of a])
paulson@14268
   603
apply (erule_tac [!] notE)
paulson@14268
   604
apply (auto simp add: order_less_imp_le mult_right_mono 
paulson@14268
   605
                      mult_right_mono_neg)
paulson@14268
   606
done
paulson@14268
   607
paulson@14268
   608
lemma mult_less_cancel_left:
paulson@14268
   609
    "(c*a < c*b) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   610
by (simp add: mult_commute [of c] mult_less_cancel_right)
paulson@14268
   611
paulson@14268
   612
lemma mult_le_cancel_right:
paulson@14268
   613
     "(a*c \<le> b*c) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   614
by (simp add: linorder_not_less [symmetric] mult_less_cancel_right)
paulson@14268
   615
paulson@14268
   616
lemma mult_le_cancel_left:
paulson@14268
   617
     "(c*a \<le> c*b) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   618
by (simp add: mult_commute [of c] mult_le_cancel_right)
paulson@14268
   619
paulson@14268
   620
lemma mult_less_imp_less_left:
paulson@14268
   621
    "[|c*a < c*b; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   622
  by (force elim: order_less_asym simp add: mult_less_cancel_left)
paulson@14268
   623
paulson@14268
   624
lemma mult_less_imp_less_right:
paulson@14268
   625
    "[|a*c < b*c; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   626
  by (force elim: order_less_asym simp add: mult_less_cancel_right)
paulson@14268
   627
paulson@14268
   628
text{*Cancellation of equalities with a common factor*}
paulson@14268
   629
lemma mult_cancel_right [simp]:
paulson@14268
   630
     "(a*c = b*c) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   631
apply (cut_tac linorder_less_linear [of 0 c])
paulson@14268
   632
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono
paulson@14268
   633
             simp add: linorder_neq_iff)
paulson@14268
   634
done
paulson@14268
   635
paulson@14268
   636
text{*These cancellation theorems require an ordering. Versions are proved
paulson@14268
   637
      below that work for fields without an ordering.*}
paulson@14268
   638
lemma mult_cancel_left [simp]:
paulson@14268
   639
     "(c*a = c*b) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   640
by (simp add: mult_commute [of c] mult_cancel_right)
paulson@14268
   641
paulson@14265
   642
paulson@14265
   643
subsection {* Fields *}
paulson@14265
   644
paulson@14288
   645
lemma right_inverse [simp]:
paulson@14288
   646
      assumes not0: "a \<noteq> 0" shows "a * inverse (a::'a::field) = 1"
paulson@14288
   647
proof -
paulson@14288
   648
  have "a * inverse a = inverse a * a" by (simp add: mult_ac)
paulson@14288
   649
  also have "... = 1" using not0 by simp
paulson@14288
   650
  finally show ?thesis .
paulson@14288
   651
qed
paulson@14288
   652
paulson@14288
   653
lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
paulson@14288
   654
proof
paulson@14288
   655
  assume neq: "b \<noteq> 0"
paulson@14288
   656
  {
paulson@14288
   657
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
paulson@14288
   658
    also assume "a / b = 1"
paulson@14288
   659
    finally show "a = b" by simp
paulson@14288
   660
  next
paulson@14288
   661
    assume "a = b"
paulson@14288
   662
    with neq show "a / b = 1" by (simp add: divide_inverse)
paulson@14288
   663
  }
paulson@14288
   664
qed
paulson@14288
   665
paulson@14288
   666
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 ==> inverse (a::'a::field) = 1/a"
paulson@14288
   667
by (simp add: divide_inverse)
paulson@14288
   668
paulson@14288
   669
lemma divide_self [simp]: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
paulson@14288
   670
  by (simp add: divide_inverse)
paulson@14288
   671
paulson@14277
   672
lemma divide_inverse_zero: "a/b = a * inverse(b::'a::{field,division_by_zero})"
paulson@14277
   673
apply (case_tac "b = 0")
paulson@14277
   674
apply (simp_all add: divide_inverse)
paulson@14277
   675
done
paulson@14277
   676
paulson@14277
   677
lemma divide_zero_left [simp]: "0/a = (0::'a::{field,division_by_zero})"
paulson@14277
   678
by (simp add: divide_inverse_zero)
paulson@14277
   679
paulson@14277
   680
lemma inverse_eq_divide: "inverse (a::'a::{field,division_by_zero}) = 1/a"
paulson@14277
   681
by (simp add: divide_inverse_zero)
paulson@14277
   682
paulson@14293
   683
lemma nonzero_add_divide_distrib: "c \<noteq> 0 ==> (a+b)/(c::'a::field) = a/c + b/c"
paulson@14293
   684
by (simp add: divide_inverse left_distrib) 
paulson@14293
   685
paulson@14293
   686
lemma add_divide_distrib: "(a+b)/(c::'a::{field,division_by_zero}) = a/c + b/c"
paulson@14293
   687
apply (case_tac "c=0", simp) 
paulson@14293
   688
apply (simp add: nonzero_add_divide_distrib) 
paulson@14293
   689
done
paulson@14293
   690
paulson@14270
   691
text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
paulson@14270
   692
      of an ordering.*}
paulson@14270
   693
lemma field_mult_eq_0_iff: "(a*b = (0::'a::field)) = (a = 0 | b = 0)"
paulson@14270
   694
  proof cases
paulson@14270
   695
    assume "a=0" thus ?thesis by simp
paulson@14270
   696
  next
paulson@14270
   697
    assume anz [simp]: "a\<noteq>0"
paulson@14270
   698
    thus ?thesis
paulson@14270
   699
    proof auto
paulson@14270
   700
      assume "a * b = 0"
paulson@14270
   701
      hence "inverse a * (a * b) = 0" by simp
paulson@14270
   702
      thus "b = 0"  by (simp (no_asm_use) add: mult_assoc [symmetric])
paulson@14270
   703
    qed
paulson@14270
   704
  qed
paulson@14270
   705
paulson@14268
   706
text{*Cancellation of equalities with a common factor*}
paulson@14268
   707
lemma field_mult_cancel_right_lemma:
paulson@14269
   708
      assumes cnz: "c \<noteq> (0::'a::field)"
paulson@14269
   709
	  and eq:  "a*c = b*c"
paulson@14269
   710
	 shows "a=b"
paulson@14268
   711
  proof -
paulson@14268
   712
  have "(a * c) * inverse c = (b * c) * inverse c"
paulson@14268
   713
    by (simp add: eq)
paulson@14268
   714
  thus "a=b"
paulson@14268
   715
    by (simp add: mult_assoc cnz)
paulson@14268
   716
  qed
paulson@14268
   717
paulson@14268
   718
lemma field_mult_cancel_right:
paulson@14268
   719
     "(a*c = b*c) = (c = (0::'a::field) | a=b)"
paulson@14269
   720
  proof cases
paulson@14268
   721
    assume "c=0" thus ?thesis by simp
paulson@14268
   722
  next
paulson@14268
   723
    assume "c\<noteq>0" 
paulson@14268
   724
    thus ?thesis by (force dest: field_mult_cancel_right_lemma)
paulson@14268
   725
  qed
paulson@14268
   726
paulson@14268
   727
lemma field_mult_cancel_left:
paulson@14268
   728
     "(c*a = c*b) = (c = (0::'a::field) | a=b)"
paulson@14268
   729
  by (simp add: mult_commute [of c] field_mult_cancel_right) 
paulson@14268
   730
paulson@14268
   731
lemma nonzero_imp_inverse_nonzero: "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::field)"
paulson@14268
   732
  proof
paulson@14268
   733
  assume ianz: "inverse a = 0"
paulson@14268
   734
  assume "a \<noteq> 0"
paulson@14268
   735
  hence "1 = a * inverse a" by simp
paulson@14268
   736
  also have "... = 0" by (simp add: ianz)
paulson@14268
   737
  finally have "1 = (0::'a::field)" .
paulson@14268
   738
  thus False by (simp add: eq_commute)
paulson@14268
   739
  qed
paulson@14268
   740
paulson@14277
   741
paulson@14277
   742
subsection{*Basic Properties of @{term inverse}*}
paulson@14277
   743
paulson@14268
   744
lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   745
apply (rule ccontr) 
paulson@14268
   746
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   747
done
paulson@14268
   748
paulson@14268
   749
lemma inverse_nonzero_imp_nonzero:
paulson@14268
   750
   "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   751
apply (rule ccontr) 
paulson@14268
   752
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   753
done
paulson@14268
   754
paulson@14268
   755
lemma inverse_nonzero_iff_nonzero [simp]:
paulson@14268
   756
   "(inverse a = 0) = (a = (0::'a::{field,division_by_zero}))"
paulson@14268
   757
by (force dest: inverse_nonzero_imp_nonzero) 
paulson@14268
   758
paulson@14268
   759
lemma nonzero_inverse_minus_eq:
paulson@14269
   760
      assumes [simp]: "a\<noteq>0"  shows "inverse(-a) = -inverse(a::'a::field)"
paulson@14268
   761
  proof -
paulson@14269
   762
    have "-a * inverse (- a) = -a * - inverse a"
paulson@14268
   763
      by simp
paulson@14268
   764
    thus ?thesis 
paulson@14269
   765
      by (simp only: field_mult_cancel_left, simp)
paulson@14268
   766
  qed
paulson@14268
   767
paulson@14268
   768
lemma inverse_minus_eq [simp]:
paulson@14268
   769
     "inverse(-a) = -inverse(a::'a::{field,division_by_zero})";
paulson@14269
   770
  proof cases
paulson@14268
   771
    assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14268
   772
  next
paulson@14268
   773
    assume "a\<noteq>0" 
paulson@14268
   774
    thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14268
   775
  qed
paulson@14268
   776
paulson@14268
   777
lemma nonzero_inverse_eq_imp_eq:
paulson@14269
   778
      assumes inveq: "inverse a = inverse b"
paulson@14269
   779
	  and anz:  "a \<noteq> 0"
paulson@14269
   780
	  and bnz:  "b \<noteq> 0"
paulson@14269
   781
	 shows "a = (b::'a::field)"
paulson@14268
   782
  proof -
paulson@14268
   783
  have "a * inverse b = a * inverse a"
paulson@14268
   784
    by (simp add: inveq)
paulson@14268
   785
  hence "(a * inverse b) * b = (a * inverse a) * b"
paulson@14268
   786
    by simp
paulson@14268
   787
  thus "a = b"
paulson@14268
   788
    by (simp add: mult_assoc anz bnz)
paulson@14268
   789
  qed
paulson@14268
   790
paulson@14268
   791
lemma inverse_eq_imp_eq:
paulson@14268
   792
     "inverse a = inverse b ==> a = (b::'a::{field,division_by_zero})"
paulson@14268
   793
apply (case_tac "a=0 | b=0") 
paulson@14268
   794
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
   795
              simp add: eq_commute [of "0::'a"])
paulson@14268
   796
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
   797
done
paulson@14268
   798
paulson@14268
   799
lemma inverse_eq_iff_eq [simp]:
paulson@14268
   800
     "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))"
paulson@14268
   801
by (force dest!: inverse_eq_imp_eq) 
paulson@14268
   802
paulson@14270
   803
lemma nonzero_inverse_inverse_eq:
paulson@14270
   804
      assumes [simp]: "a \<noteq> 0"  shows "inverse(inverse (a::'a::field)) = a"
paulson@14270
   805
  proof -
paulson@14270
   806
  have "(inverse (inverse a) * inverse a) * a = a" 
paulson@14270
   807
    by (simp add: nonzero_imp_inverse_nonzero)
paulson@14270
   808
  thus ?thesis
paulson@14270
   809
    by (simp add: mult_assoc)
paulson@14270
   810
  qed
paulson@14270
   811
paulson@14270
   812
lemma inverse_inverse_eq [simp]:
paulson@14270
   813
     "inverse(inverse (a::'a::{field,division_by_zero})) = a"
paulson@14270
   814
  proof cases
paulson@14270
   815
    assume "a=0" thus ?thesis by simp
paulson@14270
   816
  next
paulson@14270
   817
    assume "a\<noteq>0" 
paulson@14270
   818
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
   819
  qed
paulson@14270
   820
paulson@14270
   821
lemma inverse_1 [simp]: "inverse 1 = (1::'a::field)"
paulson@14270
   822
  proof -
paulson@14270
   823
  have "inverse 1 * 1 = (1::'a::field)" 
paulson@14270
   824
    by (rule left_inverse [OF zero_neq_one [symmetric]])
paulson@14270
   825
  thus ?thesis  by simp
paulson@14270
   826
  qed
paulson@14270
   827
paulson@14270
   828
lemma nonzero_inverse_mult_distrib: 
paulson@14270
   829
      assumes anz: "a \<noteq> 0"
paulson@14270
   830
          and bnz: "b \<noteq> 0"
paulson@14270
   831
      shows "inverse(a*b) = inverse(b) * inverse(a::'a::field)"
paulson@14270
   832
  proof -
paulson@14270
   833
  have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
paulson@14270
   834
    by (simp add: field_mult_eq_0_iff anz bnz)
paulson@14270
   835
  hence "inverse(a*b) * a = inverse(b)" 
paulson@14270
   836
    by (simp add: mult_assoc bnz)
paulson@14270
   837
  hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
paulson@14270
   838
    by simp
paulson@14270
   839
  thus ?thesis
paulson@14270
   840
    by (simp add: mult_assoc anz)
paulson@14270
   841
  qed
paulson@14270
   842
paulson@14270
   843
text{*This version builds in division by zero while also re-orienting
paulson@14270
   844
      the right-hand side.*}
paulson@14270
   845
lemma inverse_mult_distrib [simp]:
paulson@14270
   846
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
   847
  proof cases
paulson@14270
   848
    assume "a \<noteq> 0 & b \<noteq> 0" 
paulson@14270
   849
    thus ?thesis  by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
   850
  next
paulson@14270
   851
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
paulson@14270
   852
    thus ?thesis  by force
paulson@14270
   853
  qed
paulson@14270
   854
paulson@14270
   855
text{*There is no slick version using division by zero.*}
paulson@14270
   856
lemma inverse_add:
paulson@14270
   857
     "[|a \<noteq> 0;  b \<noteq> 0|]
paulson@14270
   858
      ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
paulson@14270
   859
apply (simp add: left_distrib mult_assoc)
paulson@14270
   860
apply (simp add: mult_commute [of "inverse a"]) 
paulson@14270
   861
apply (simp add: mult_assoc [symmetric] add_commute)
paulson@14270
   862
done
paulson@14270
   863
paulson@14277
   864
lemma nonzero_mult_divide_cancel_left:
paulson@14277
   865
  assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" 
paulson@14277
   866
    shows "(c*a)/(c*b) = a/(b::'a::field)"
paulson@14277
   867
proof -
paulson@14277
   868
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
paulson@14277
   869
    by (simp add: field_mult_eq_0_iff divide_inverse 
paulson@14277
   870
                  nonzero_inverse_mult_distrib)
paulson@14277
   871
  also have "... =  a * inverse b * (inverse c * c)"
paulson@14277
   872
    by (simp only: mult_ac)
paulson@14277
   873
  also have "... =  a * inverse b"
paulson@14277
   874
    by simp
paulson@14277
   875
    finally show ?thesis 
paulson@14277
   876
    by (simp add: divide_inverse)
paulson@14277
   877
qed
paulson@14277
   878
paulson@14277
   879
lemma mult_divide_cancel_left:
paulson@14277
   880
     "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
paulson@14277
   881
apply (case_tac "b = 0")
paulson@14277
   882
apply (simp_all add: nonzero_mult_divide_cancel_left)
paulson@14277
   883
done
paulson@14277
   884
paulson@14321
   885
lemma nonzero_mult_divide_cancel_right:
paulson@14321
   886
     "[|b\<noteq>0; c\<noteq>0|] ==> (a*c) / (b*c) = a/(b::'a::field)"
paulson@14321
   887
by (simp add: mult_commute [of _ c] nonzero_mult_divide_cancel_left) 
paulson@14321
   888
paulson@14321
   889
lemma mult_divide_cancel_right:
paulson@14321
   890
     "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
paulson@14321
   891
apply (case_tac "b = 0")
paulson@14321
   892
apply (simp_all add: nonzero_mult_divide_cancel_right)
paulson@14321
   893
done
paulson@14321
   894
paulson@14277
   895
(*For ExtractCommonTerm*)
paulson@14277
   896
lemma mult_divide_cancel_eq_if:
paulson@14277
   897
     "(c*a) / (c*b) = 
paulson@14277
   898
      (if c=0 then 0 else a / (b::'a::{field,division_by_zero}))"
paulson@14277
   899
  by (simp add: mult_divide_cancel_left)
paulson@14277
   900
paulson@14284
   901
lemma divide_1 [simp]: "a/1 = (a::'a::field)"
paulson@14284
   902
  by (simp add: divide_inverse [OF not_sym])
paulson@14284
   903
paulson@14288
   904
lemma times_divide_eq_right [simp]:
paulson@14288
   905
     "a * (b/c) = (a*b) / (c::'a::{field,division_by_zero})"
paulson@14288
   906
by (simp add: divide_inverse_zero mult_assoc)
paulson@14288
   907
paulson@14288
   908
lemma times_divide_eq_left [simp]:
paulson@14288
   909
     "(b/c) * a = (b*a) / (c::'a::{field,division_by_zero})"
paulson@14288
   910
by (simp add: divide_inverse_zero mult_ac)
paulson@14288
   911
paulson@14288
   912
lemma divide_divide_eq_right [simp]:
paulson@14288
   913
     "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
paulson@14288
   914
by (simp add: divide_inverse_zero mult_ac)
paulson@14288
   915
paulson@14288
   916
lemma divide_divide_eq_left [simp]:
paulson@14288
   917
     "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
paulson@14288
   918
by (simp add: divide_inverse_zero mult_assoc)
paulson@14288
   919
paulson@14268
   920
paulson@14293
   921
subsection {* Division and Unary Minus *}
paulson@14293
   922
paulson@14293
   923
lemma nonzero_minus_divide_left: "b \<noteq> 0 ==> - (a/b) = (-a) / (b::'a::field)"
paulson@14293
   924
by (simp add: divide_inverse minus_mult_left)
paulson@14293
   925
paulson@14293
   926
lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a/b) = a / -(b::'a::field)"
paulson@14293
   927
by (simp add: divide_inverse nonzero_inverse_minus_eq minus_mult_right)
paulson@14293
   928
paulson@14293
   929
lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a)/(-b) = a / (b::'a::field)"
paulson@14293
   930
by (simp add: divide_inverse nonzero_inverse_minus_eq)
paulson@14293
   931
paulson@14293
   932
lemma minus_divide_left: "- (a/b) = (-a) / (b::'a::{field,division_by_zero})"
paulson@14293
   933
apply (case_tac "b=0", simp) 
paulson@14293
   934
apply (simp add: nonzero_minus_divide_left) 
paulson@14293
   935
done
paulson@14293
   936
paulson@14293
   937
lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
paulson@14293
   938
apply (case_tac "b=0", simp) 
paulson@14293
   939
by (rule nonzero_minus_divide_right) 
paulson@14293
   940
paulson@14293
   941
text{*The effect is to extract signs from divisions*}
paulson@14293
   942
declare minus_divide_left  [symmetric, simp]
paulson@14293
   943
declare minus_divide_right [symmetric, simp]
paulson@14293
   944
paulson@14293
   945
lemma minus_divide_divide [simp]:
paulson@14293
   946
     "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
paulson@14293
   947
apply (case_tac "b=0", simp) 
paulson@14293
   948
apply (simp add: nonzero_minus_divide_divide) 
paulson@14293
   949
done
paulson@14293
   950
paulson@14293
   951
paulson@14268
   952
subsection {* Ordered Fields *}
paulson@14268
   953
paulson@14277
   954
lemma positive_imp_inverse_positive: 
paulson@14269
   955
      assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
paulson@14268
   956
  proof -
paulson@14268
   957
  have "0 < a * inverse a" 
paulson@14268
   958
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
   959
  thus "0 < inverse a" 
paulson@14268
   960
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
paulson@14268
   961
  qed
paulson@14268
   962
paulson@14277
   963
lemma negative_imp_inverse_negative:
paulson@14268
   964
     "a < 0 ==> inverse a < (0::'a::ordered_field)"
paulson@14277
   965
  by (insert positive_imp_inverse_positive [of "-a"], 
paulson@14268
   966
      simp add: nonzero_inverse_minus_eq order_less_imp_not_eq) 
paulson@14268
   967
paulson@14268
   968
lemma inverse_le_imp_le:
paulson@14269
   969
      assumes invle: "inverse a \<le> inverse b"
paulson@14269
   970
	  and apos:  "0 < a"
paulson@14269
   971
	 shows "b \<le> (a::'a::ordered_field)"
paulson@14268
   972
  proof (rule classical)
paulson@14268
   973
  assume "~ b \<le> a"
paulson@14268
   974
  hence "a < b"
paulson@14268
   975
    by (simp add: linorder_not_le)
paulson@14268
   976
  hence bpos: "0 < b"
paulson@14268
   977
    by (blast intro: apos order_less_trans)
paulson@14268
   978
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
   979
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
   980
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
   981
    by (simp add: bpos order_less_imp_le mult_right_mono)
paulson@14268
   982
  thus "b \<le> a"
paulson@14268
   983
    by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
paulson@14268
   984
  qed
paulson@14268
   985
paulson@14277
   986
lemma inverse_positive_imp_positive:
paulson@14277
   987
      assumes inv_gt_0: "0 < inverse a"
paulson@14277
   988
          and [simp]:   "a \<noteq> 0"
paulson@14277
   989
        shows "0 < (a::'a::ordered_field)"
paulson@14277
   990
  proof -
paulson@14277
   991
  have "0 < inverse (inverse a)"
paulson@14277
   992
    by (rule positive_imp_inverse_positive)
paulson@14277
   993
  thus "0 < a"
paulson@14277
   994
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
   995
  qed
paulson@14277
   996
paulson@14277
   997
lemma inverse_positive_iff_positive [simp]:
paulson@14277
   998
      "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
   999
apply (case_tac "a = 0", simp)
paulson@14277
  1000
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
  1001
done
paulson@14277
  1002
paulson@14277
  1003
lemma inverse_negative_imp_negative:
paulson@14277
  1004
      assumes inv_less_0: "inverse a < 0"
paulson@14277
  1005
          and [simp]:   "a \<noteq> 0"
paulson@14277
  1006
        shows "a < (0::'a::ordered_field)"
paulson@14277
  1007
  proof -
paulson@14277
  1008
  have "inverse (inverse a) < 0"
paulson@14277
  1009
    by (rule negative_imp_inverse_negative)
paulson@14277
  1010
  thus "a < 0"
paulson@14277
  1011
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
  1012
  qed
paulson@14277
  1013
paulson@14277
  1014
lemma inverse_negative_iff_negative [simp]:
paulson@14277
  1015
      "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1016
apply (case_tac "a = 0", simp)
paulson@14277
  1017
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
  1018
done
paulson@14277
  1019
paulson@14277
  1020
lemma inverse_nonnegative_iff_nonnegative [simp]:
paulson@14277
  1021
      "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1022
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1023
paulson@14277
  1024
lemma inverse_nonpositive_iff_nonpositive [simp]:
paulson@14277
  1025
      "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1026
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1027
paulson@14277
  1028
paulson@14277
  1029
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
  1030
paulson@14268
  1031
lemma less_imp_inverse_less:
paulson@14269
  1032
      assumes less: "a < b"
paulson@14269
  1033
	  and apos:  "0 < a"
paulson@14269
  1034
	shows "inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1035
  proof (rule ccontr)
paulson@14268
  1036
  assume "~ inverse b < inverse a"
paulson@14268
  1037
  hence "inverse a \<le> inverse b"
paulson@14268
  1038
    by (simp add: linorder_not_less)
paulson@14268
  1039
  hence "~ (a < b)"
paulson@14268
  1040
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
paulson@14268
  1041
  thus False
paulson@14268
  1042
    by (rule notE [OF _ less])
paulson@14268
  1043
  qed
paulson@14268
  1044
paulson@14268
  1045
lemma inverse_less_imp_less:
paulson@14268
  1046
   "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1047
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
  1048
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
  1049
done
paulson@14268
  1050
paulson@14268
  1051
text{*Both premises are essential. Consider -1 and 1.*}
paulson@14268
  1052
lemma inverse_less_iff_less [simp]:
paulson@14268
  1053
     "[|0 < a; 0 < b|] 
paulson@14268
  1054
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1055
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
  1056
paulson@14268
  1057
lemma le_imp_inverse_le:
paulson@14268
  1058
   "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1059
  by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
  1060
paulson@14268
  1061
lemma inverse_le_iff_le [simp]:
paulson@14268
  1062
     "[|0 < a; 0 < b|] 
paulson@14268
  1063
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1064
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
  1065
paulson@14268
  1066
paulson@14268
  1067
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
  1068
case is trivial, since inverse preserves signs.*}
paulson@14268
  1069
lemma inverse_le_imp_le_neg:
paulson@14268
  1070
   "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
paulson@14268
  1071
  apply (rule classical) 
paulson@14268
  1072
  apply (subgoal_tac "a < 0") 
paulson@14268
  1073
   prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
paulson@14268
  1074
  apply (insert inverse_le_imp_le [of "-b" "-a"])
paulson@14268
  1075
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1076
  done
paulson@14268
  1077
paulson@14268
  1078
lemma less_imp_inverse_less_neg:
paulson@14268
  1079
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1080
  apply (subgoal_tac "a < 0") 
paulson@14268
  1081
   prefer 2 apply (blast intro: order_less_trans) 
paulson@14268
  1082
  apply (insert less_imp_inverse_less [of "-b" "-a"])
paulson@14268
  1083
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1084
  done
paulson@14268
  1085
paulson@14268
  1086
lemma inverse_less_imp_less_neg:
paulson@14268
  1087
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1088
  apply (rule classical) 
paulson@14268
  1089
  apply (subgoal_tac "a < 0") 
paulson@14268
  1090
   prefer 2
paulson@14268
  1091
   apply (force simp add: linorder_not_less intro: order_le_less_trans) 
paulson@14268
  1092
  apply (insert inverse_less_imp_less [of "-b" "-a"])
paulson@14268
  1093
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1094
  done
paulson@14268
  1095
paulson@14268
  1096
lemma inverse_less_iff_less_neg [simp]:
paulson@14268
  1097
     "[|a < 0; b < 0|] 
paulson@14268
  1098
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1099
  apply (insert inverse_less_iff_less [of "-b" "-a"])
paulson@14268
  1100
  apply (simp del: inverse_less_iff_less 
paulson@14268
  1101
	      add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1102
  done
paulson@14268
  1103
paulson@14268
  1104
lemma le_imp_inverse_le_neg:
paulson@14268
  1105
   "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1106
  by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
  1107
paulson@14268
  1108
lemma inverse_le_iff_le_neg [simp]:
paulson@14268
  1109
     "[|a < 0; b < 0|] 
paulson@14268
  1110
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1111
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
  1112
paulson@14277
  1113
paulson@14277
  1114
subsection{*Division and Signs*}
paulson@14277
  1115
paulson@14277
  1116
lemma zero_less_divide_iff:
paulson@14277
  1117
     "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14277
  1118
by (simp add: divide_inverse_zero zero_less_mult_iff)
paulson@14277
  1119
paulson@14277
  1120
lemma divide_less_0_iff:
paulson@14277
  1121
     "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
paulson@14277
  1122
      (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14277
  1123
by (simp add: divide_inverse_zero mult_less_0_iff)
paulson@14277
  1124
paulson@14277
  1125
lemma zero_le_divide_iff:
paulson@14277
  1126
     "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
paulson@14277
  1127
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14277
  1128
by (simp add: divide_inverse_zero zero_le_mult_iff)
paulson@14277
  1129
paulson@14277
  1130
lemma divide_le_0_iff:
paulson@14288
  1131
     "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) =
paulson@14288
  1132
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14277
  1133
by (simp add: divide_inverse_zero mult_le_0_iff)
paulson@14277
  1134
paulson@14277
  1135
lemma divide_eq_0_iff [simp]:
paulson@14277
  1136
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
paulson@14277
  1137
by (simp add: divide_inverse_zero field_mult_eq_0_iff)
paulson@14277
  1138
paulson@14288
  1139
paulson@14288
  1140
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
  1141
paulson@14288
  1142
lemma pos_le_divide_eq: "0 < (c::'a::ordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
  1143
proof -
paulson@14288
  1144
  assume less: "0<c"
paulson@14288
  1145
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
  1146
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1147
  also have "... = (a*c \<le> b)"
paulson@14288
  1148
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1149
  finally show ?thesis .
paulson@14288
  1150
qed
paulson@14288
  1151
paulson@14288
  1152
paulson@14288
  1153
lemma neg_le_divide_eq: "c < (0::'a::ordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
  1154
proof -
paulson@14288
  1155
  assume less: "c<0"
paulson@14288
  1156
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
  1157
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1158
  also have "... = (b \<le> a*c)"
paulson@14288
  1159
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1160
  finally show ?thesis .
paulson@14288
  1161
qed
paulson@14288
  1162
paulson@14288
  1163
lemma le_divide_eq:
paulson@14288
  1164
  "(a \<le> b/c) = 
paulson@14288
  1165
   (if 0 < c then a*c \<le> b
paulson@14288
  1166
             else if c < 0 then b \<le> a*c
paulson@14288
  1167
             else  a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1168
apply (case_tac "c=0", simp) 
paulson@14288
  1169
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
  1170
done
paulson@14288
  1171
paulson@14288
  1172
lemma pos_divide_le_eq: "0 < (c::'a::ordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
  1173
proof -
paulson@14288
  1174
  assume less: "0<c"
paulson@14288
  1175
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
  1176
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1177
  also have "... = (b \<le> a*c)"
paulson@14288
  1178
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1179
  finally show ?thesis .
paulson@14288
  1180
qed
paulson@14288
  1181
paulson@14288
  1182
lemma neg_divide_le_eq: "c < (0::'a::ordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
  1183
proof -
paulson@14288
  1184
  assume less: "c<0"
paulson@14288
  1185
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
  1186
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1187
  also have "... = (a*c \<le> b)"
paulson@14288
  1188
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1189
  finally show ?thesis .
paulson@14288
  1190
qed
paulson@14288
  1191
paulson@14288
  1192
lemma divide_le_eq:
paulson@14288
  1193
  "(b/c \<le> a) = 
paulson@14288
  1194
   (if 0 < c then b \<le> a*c
paulson@14288
  1195
             else if c < 0 then a*c \<le> b
paulson@14288
  1196
             else 0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1197
apply (case_tac "c=0", simp) 
paulson@14288
  1198
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
  1199
done
paulson@14288
  1200
paulson@14288
  1201
paulson@14288
  1202
lemma pos_less_divide_eq:
paulson@14288
  1203
     "0 < (c::'a::ordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
  1204
proof -
paulson@14288
  1205
  assume less: "0<c"
paulson@14288
  1206
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@14288
  1207
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1208
  also have "... = (a*c < b)"
paulson@14288
  1209
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1210
  finally show ?thesis .
paulson@14288
  1211
qed
paulson@14288
  1212
paulson@14288
  1213
lemma neg_less_divide_eq:
paulson@14288
  1214
 "c < (0::'a::ordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
  1215
proof -
paulson@14288
  1216
  assume less: "c<0"
paulson@14288
  1217
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@14288
  1218
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1219
  also have "... = (b < a*c)"
paulson@14288
  1220
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1221
  finally show ?thesis .
paulson@14288
  1222
qed
paulson@14288
  1223
paulson@14288
  1224
lemma less_divide_eq:
paulson@14288
  1225
  "(a < b/c) = 
paulson@14288
  1226
   (if 0 < c then a*c < b
paulson@14288
  1227
             else if c < 0 then b < a*c
paulson@14288
  1228
             else  a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1229
apply (case_tac "c=0", simp) 
paulson@14288
  1230
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
  1231
done
paulson@14288
  1232
paulson@14288
  1233
lemma pos_divide_less_eq:
paulson@14288
  1234
     "0 < (c::'a::ordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
  1235
proof -
paulson@14288
  1236
  assume less: "0<c"
paulson@14288
  1237
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@14288
  1238
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1239
  also have "... = (b < a*c)"
paulson@14288
  1240
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1241
  finally show ?thesis .
paulson@14288
  1242
qed
paulson@14288
  1243
paulson@14288
  1244
lemma neg_divide_less_eq:
paulson@14288
  1245
 "c < (0::'a::ordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
  1246
proof -
paulson@14288
  1247
  assume less: "c<0"
paulson@14288
  1248
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@14288
  1249
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1250
  also have "... = (a*c < b)"
paulson@14288
  1251
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1252
  finally show ?thesis .
paulson@14288
  1253
qed
paulson@14288
  1254
paulson@14288
  1255
lemma divide_less_eq:
paulson@14288
  1256
  "(b/c < a) = 
paulson@14288
  1257
   (if 0 < c then b < a*c
paulson@14288
  1258
             else if c < 0 then a*c < b
paulson@14288
  1259
             else 0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1260
apply (case_tac "c=0", simp) 
paulson@14288
  1261
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
  1262
done
paulson@14288
  1263
paulson@14288
  1264
lemma nonzero_eq_divide_eq: "c\<noteq>0 ==> ((a::'a::field) = b/c) = (a*c = b)"
paulson@14288
  1265
proof -
paulson@14288
  1266
  assume [simp]: "c\<noteq>0"
paulson@14288
  1267
  have "(a = b/c) = (a*c = (b/c)*c)"
paulson@14288
  1268
    by (simp add: field_mult_cancel_right)
paulson@14288
  1269
  also have "... = (a*c = b)"
paulson@14288
  1270
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1271
  finally show ?thesis .
paulson@14288
  1272
qed
paulson@14288
  1273
paulson@14288
  1274
lemma eq_divide_eq:
paulson@14288
  1275
  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
paulson@14288
  1276
by (simp add: nonzero_eq_divide_eq) 
paulson@14288
  1277
paulson@14288
  1278
lemma nonzero_divide_eq_eq: "c\<noteq>0 ==> (b/c = (a::'a::field)) = (b = a*c)"
paulson@14288
  1279
proof -
paulson@14288
  1280
  assume [simp]: "c\<noteq>0"
paulson@14288
  1281
  have "(b/c = a) = ((b/c)*c = a*c)"
paulson@14288
  1282
    by (simp add: field_mult_cancel_right)
paulson@14288
  1283
  also have "... = (b = a*c)"
paulson@14288
  1284
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1285
  finally show ?thesis .
paulson@14288
  1286
qed
paulson@14288
  1287
paulson@14288
  1288
lemma divide_eq_eq:
paulson@14288
  1289
  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
paulson@14288
  1290
by (force simp add: nonzero_divide_eq_eq) 
paulson@14288
  1291
paulson@14288
  1292
subsection{*Cancellation Laws for Division*}
paulson@14288
  1293
paulson@14288
  1294
lemma divide_cancel_right [simp]:
paulson@14288
  1295
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
paulson@14288
  1296
apply (case_tac "c=0", simp) 
paulson@14288
  1297
apply (simp add: divide_inverse_zero field_mult_cancel_right) 
paulson@14288
  1298
done
paulson@14288
  1299
paulson@14288
  1300
lemma divide_cancel_left [simp]:
paulson@14288
  1301
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
paulson@14288
  1302
apply (case_tac "c=0", simp) 
paulson@14288
  1303
apply (simp add: divide_inverse_zero field_mult_cancel_left) 
paulson@14288
  1304
done
paulson@14288
  1305
paulson@14288
  1306
paulson@14293
  1307
subsection {* Ordering Rules for Division *}
paulson@14293
  1308
paulson@14293
  1309
lemma divide_strict_right_mono:
paulson@14293
  1310
     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1311
by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
paulson@14293
  1312
              positive_imp_inverse_positive) 
paulson@14293
  1313
paulson@14293
  1314
lemma divide_right_mono:
paulson@14293
  1315
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{ordered_field,division_by_zero})"
paulson@14293
  1316
  by (force simp add: divide_strict_right_mono order_le_less) 
paulson@14293
  1317
paulson@14293
  1318
paulson@14293
  1319
text{*The last premise ensures that @{term a} and @{term b} 
paulson@14293
  1320
      have the same sign*}
paulson@14293
  1321
lemma divide_strict_left_mono:
paulson@14293
  1322
       "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
paulson@14293
  1323
by (force simp add: zero_less_mult_iff divide_inverse mult_strict_left_mono 
paulson@14293
  1324
      order_less_imp_not_eq order_less_imp_not_eq2  
paulson@14293
  1325
      less_imp_inverse_less less_imp_inverse_less_neg) 
paulson@14293
  1326
paulson@14293
  1327
lemma divide_left_mono:
paulson@14293
  1328
     "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::ordered_field)"
paulson@14293
  1329
  apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
paulson@14293
  1330
   prefer 2 
paulson@14293
  1331
   apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
paulson@14293
  1332
  apply (case_tac "c=0", simp add: divide_inverse)
paulson@14293
  1333
  apply (force simp add: divide_strict_left_mono order_le_less) 
paulson@14293
  1334
  done
paulson@14293
  1335
paulson@14293
  1336
lemma divide_strict_left_mono_neg:
paulson@14293
  1337
     "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
paulson@14293
  1338
  apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
paulson@14293
  1339
   prefer 2 
paulson@14293
  1340
   apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
paulson@14293
  1341
  apply (drule divide_strict_left_mono [of _ _ "-c"]) 
paulson@14293
  1342
   apply (simp_all add: mult_commute nonzero_minus_divide_left [symmetric]) 
paulson@14293
  1343
  done
paulson@14293
  1344
paulson@14293
  1345
lemma divide_strict_right_mono_neg:
paulson@14293
  1346
     "[|b < a; c < 0|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1347
apply (drule divide_strict_right_mono [of _ _ "-c"], simp) 
paulson@14293
  1348
apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric]) 
paulson@14293
  1349
done
paulson@14293
  1350
paulson@14293
  1351
paulson@14293
  1352
subsection {* Ordered Fields are Dense *}
paulson@14293
  1353
paulson@14293
  1354
lemma zero_less_two: "0 < (1+1::'a::ordered_field)"
paulson@14293
  1355
proof -
paulson@14293
  1356
  have "0 + 0 <  (1+1::'a::ordered_field)"
paulson@14293
  1357
    by (blast intro: zero_less_one add_strict_mono) 
paulson@14293
  1358
  thus ?thesis by simp
paulson@14293
  1359
qed
paulson@14293
  1360
paulson@14293
  1361
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::ordered_field)"
paulson@14293
  1362
by (simp add: zero_less_two pos_less_divide_eq right_distrib) 
paulson@14293
  1363
paulson@14293
  1364
lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::ordered_field) < b"
paulson@14293
  1365
by (simp add: zero_less_two pos_divide_less_eq right_distrib) 
paulson@14293
  1366
paulson@14293
  1367
lemma dense: "a < b ==> \<exists>r::'a::ordered_field. a < r & r < b"
paulson@14293
  1368
by (blast intro!: less_half_sum gt_half_sum)
paulson@14293
  1369
paulson@14293
  1370
paulson@14293
  1371
subsection {* Absolute Value *}
paulson@14293
  1372
paulson@14293
  1373
lemma abs_zero [simp]: "abs 0 = (0::'a::ordered_ring)"
paulson@14293
  1374
by (simp add: abs_if)
paulson@14293
  1375
paulson@14294
  1376
lemma abs_one [simp]: "abs 1 = (1::'a::ordered_ring)"
paulson@14294
  1377
  by (simp add: abs_if zero_less_one [THEN order_less_not_sym]) 
paulson@14294
  1378
paulson@14294
  1379
lemma abs_mult: "abs (a * b) = abs a * abs (b::'a::ordered_ring)" 
paulson@14294
  1380
apply (case_tac "a=0 | b=0", force) 
paulson@14293
  1381
apply (auto elim: order_less_asym
paulson@14293
  1382
            simp add: abs_if mult_less_0_iff linorder_neq_iff
paulson@14293
  1383
                  minus_mult_left [symmetric] minus_mult_right [symmetric])  
paulson@14293
  1384
done
paulson@14293
  1385
paulson@14294
  1386
lemma abs_eq_0 [simp]: "(abs a = 0) = (a = (0::'a::ordered_ring))"
paulson@14294
  1387
by (simp add: abs_if)
paulson@14294
  1388
paulson@14294
  1389
lemma zero_less_abs_iff [simp]: "(0 < abs a) = (a \<noteq> (0::'a::ordered_ring))"
paulson@14294
  1390
by (simp add: abs_if linorder_neq_iff)
paulson@14294
  1391
paulson@14294
  1392
lemma abs_not_less_zero [simp]: "~ abs a < (0::'a::ordered_ring)"
paulson@14294
  1393
by (simp add: abs_if  order_less_not_sym [of a 0])
paulson@14294
  1394
paulson@14294
  1395
lemma abs_le_zero_iff [simp]: "(abs a \<le> (0::'a::ordered_ring)) = (a = 0)" 
paulson@14294
  1396
by (simp add: order_le_less) 
paulson@14294
  1397
paulson@14294
  1398
lemma abs_minus_cancel [simp]: "abs (-a) = abs(a::'a::ordered_ring)"
paulson@14294
  1399
apply (auto simp add: abs_if linorder_not_less order_less_not_sym [of 0 a])  
paulson@14294
  1400
apply (drule order_antisym, assumption, simp) 
paulson@14294
  1401
done
paulson@14294
  1402
paulson@14294
  1403
lemma abs_ge_zero [simp]: "(0::'a::ordered_ring) \<le> abs a"
paulson@14294
  1404
apply (simp add: abs_if order_less_imp_le)
paulson@14294
  1405
apply (simp add: linorder_not_less) 
paulson@14294
  1406
done
paulson@14294
  1407
paulson@14294
  1408
lemma abs_idempotent [simp]: "abs (abs a) = abs (a::'a::ordered_ring)"
paulson@14294
  1409
  by (force elim: order_less_asym simp add: abs_if)
paulson@14294
  1410
paulson@14305
  1411
lemma abs_zero_iff [simp]: "(abs a = 0) = (a = (0::'a::ordered_ring))"
paulson@14293
  1412
by (simp add: abs_if)
paulson@14293
  1413
paulson@14294
  1414
lemma abs_ge_self: "a \<le> abs (a::'a::ordered_ring)"
paulson@14294
  1415
apply (simp add: abs_if)
paulson@14294
  1416
apply (simp add: order_less_imp_le order_trans [of _ 0])
paulson@14294
  1417
done
paulson@14294
  1418
paulson@14294
  1419
lemma abs_ge_minus_self: "-a \<le> abs (a::'a::ordered_ring)"
paulson@14294
  1420
by (insert abs_ge_self [of "-a"], simp)
paulson@14294
  1421
paulson@14294
  1422
lemma nonzero_abs_inverse:
paulson@14294
  1423
     "a \<noteq> 0 ==> abs (inverse (a::'a::ordered_field)) = inverse (abs a)"
paulson@14294
  1424
apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
paulson@14294
  1425
                      negative_imp_inverse_negative)
paulson@14294
  1426
apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
paulson@14294
  1427
done
paulson@14294
  1428
paulson@14294
  1429
lemma abs_inverse [simp]:
paulson@14294
  1430
     "abs (inverse (a::'a::{ordered_field,division_by_zero})) = 
paulson@14294
  1431
      inverse (abs a)"
paulson@14294
  1432
apply (case_tac "a=0", simp) 
paulson@14294
  1433
apply (simp add: nonzero_abs_inverse) 
paulson@14294
  1434
done
paulson@14294
  1435
paulson@14294
  1436
paulson@14294
  1437
lemma nonzero_abs_divide:
paulson@14294
  1438
     "b \<noteq> 0 ==> abs (a / (b::'a::ordered_field)) = abs a / abs b"
paulson@14294
  1439
by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
paulson@14294
  1440
paulson@14294
  1441
lemma abs_divide:
paulson@14294
  1442
     "abs (a / (b::'a::{ordered_field,division_by_zero})) = abs a / abs b"
paulson@14294
  1443
apply (case_tac "b=0", simp) 
paulson@14294
  1444
apply (simp add: nonzero_abs_divide) 
paulson@14294
  1445
done
paulson@14294
  1446
paulson@14295
  1447
lemma abs_leI: "[|a \<le> b; -a \<le> b|] ==> abs a \<le> (b::'a::ordered_ring)"
paulson@14295
  1448
by (simp add: abs_if)
paulson@14295
  1449
paulson@14295
  1450
lemma le_minus_self_iff: "(a \<le> -a) = (a \<le> (0::'a::ordered_ring))"
paulson@14295
  1451
proof 
paulson@14295
  1452
  assume ale: "a \<le> -a"
paulson@14295
  1453
  show "a\<le>0"
paulson@14295
  1454
    apply (rule classical) 
paulson@14295
  1455
    apply (simp add: linorder_not_le) 
paulson@14295
  1456
    apply (blast intro: ale order_trans order_less_imp_le
paulson@14295
  1457
                        neg_0_le_iff_le [THEN iffD1]) 
paulson@14295
  1458
    done
paulson@14295
  1459
next
paulson@14295
  1460
  assume "a\<le>0"
paulson@14295
  1461
  hence "0 \<le> -a" by (simp only: neg_0_le_iff_le)
paulson@14295
  1462
  thus "a \<le> -a"  by (blast intro: prems order_trans) 
paulson@14295
  1463
qed
paulson@14295
  1464
paulson@14295
  1465
lemma minus_le_self_iff: "(-a \<le> a) = (0 \<le> (a::'a::ordered_ring))"
paulson@14295
  1466
by (insert le_minus_self_iff [of "-a"], simp)
paulson@14295
  1467
paulson@14295
  1468
lemma eq_minus_self_iff: "(a = -a) = (a = (0::'a::ordered_ring))"
paulson@14295
  1469
by (force simp add: order_eq_iff le_minus_self_iff minus_le_self_iff)
paulson@14295
  1470
paulson@14295
  1471
lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::ordered_ring))"
paulson@14295
  1472
by (simp add: order_less_le le_minus_self_iff eq_minus_self_iff)
paulson@14295
  1473
paulson@14295
  1474
lemma abs_le_D1: "abs a \<le> b ==> a \<le> (b::'a::ordered_ring)"
paulson@14295
  1475
apply (simp add: abs_if split: split_if_asm)
paulson@14295
  1476
apply (rule order_trans [of _ "-a"]) 
paulson@14295
  1477
 apply (simp add: less_minus_self_iff order_less_imp_le, assumption)
paulson@14295
  1478
done
paulson@14295
  1479
paulson@14295
  1480
lemma abs_le_D2: "abs a \<le> b ==> -a \<le> (b::'a::ordered_ring)"
paulson@14295
  1481
by (insert abs_le_D1 [of "-a"], simp)
paulson@14295
  1482
paulson@14295
  1483
lemma abs_le_iff: "(abs a \<le> b) = (a \<le> b & -a \<le> (b::'a::ordered_ring))"
paulson@14295
  1484
by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
paulson@14295
  1485
paulson@14295
  1486
lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::ordered_ring))" 
paulson@14295
  1487
apply (simp add: order_less_le abs_le_iff)  
paulson@14295
  1488
apply (auto simp add: abs_if minus_le_self_iff eq_minus_self_iff) 
paulson@14295
  1489
 apply (simp add:  linorder_not_less [symmetric]) 
paulson@14295
  1490
apply (simp add: le_minus_self_iff linorder_neq_iff) 
paulson@14295
  1491
apply (simp add:  linorder_not_less [symmetric]) 
paulson@14295
  1492
done
paulson@14295
  1493
paulson@14294
  1494
lemma abs_triangle_ineq: "abs (a+b) \<le> abs a + abs (b::'a::ordered_ring)"
paulson@14295
  1495
by (force simp add: abs_le_iff abs_ge_self abs_ge_minus_self add_mono)
paulson@14294
  1496
paulson@14294
  1497
lemma abs_mult_less:
paulson@14294
  1498
     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::ordered_ring)"
paulson@14294
  1499
proof -
paulson@14294
  1500
  assume ac: "abs a < c"
paulson@14294
  1501
  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
paulson@14294
  1502
  assume "abs b < d"
paulson@14294
  1503
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  1504
qed
paulson@14293
  1505
paulson@14331
  1506
ML
paulson@14331
  1507
{*
paulson@14331
  1508
val add_0_right = thm"add_0_right";
paulson@14331
  1509
val add_left_commute = thm"add_left_commute";
paulson@14331
  1510
val right_minus = thm"right_minus";
paulson@14331
  1511
val right_minus_eq = thm"right_minus_eq";
paulson@14331
  1512
val add_left_cancel = thm"add_left_cancel";
paulson@14331
  1513
val add_right_cancel = thm"add_right_cancel";
paulson@14331
  1514
val minus_minus = thm"minus_minus";
paulson@14331
  1515
val equals_zero_I = thm"equals_zero_I";
paulson@14331
  1516
val minus_zero = thm"minus_zero";
paulson@14331
  1517
val diff_self = thm"diff_self";
paulson@14331
  1518
val diff_0 = thm"diff_0";
paulson@14331
  1519
val diff_0_right = thm"diff_0_right";
paulson@14331
  1520
val diff_minus_eq_add = thm"diff_minus_eq_add";
paulson@14331
  1521
val neg_equal_iff_equal = thm"neg_equal_iff_equal";
paulson@14331
  1522
val neg_equal_0_iff_equal = thm"neg_equal_0_iff_equal";
paulson@14331
  1523
val neg_0_equal_iff_equal = thm"neg_0_equal_iff_equal";
paulson@14331
  1524
val equation_minus_iff = thm"equation_minus_iff";
paulson@14331
  1525
val minus_equation_iff = thm"minus_equation_iff";
paulson@14331
  1526
val mult_1_right = thm"mult_1_right";
paulson@14331
  1527
val mult_left_commute = thm"mult_left_commute";
paulson@14331
  1528
val mult_left_zero = thm"mult_left_zero";
paulson@14331
  1529
val mult_right_zero = thm"mult_right_zero";
paulson@14331
  1530
val right_distrib = thm"right_distrib";
paulson@14331
  1531
val combine_common_factor = thm"combine_common_factor";
paulson@14331
  1532
val minus_add_distrib = thm"minus_add_distrib";
paulson@14331
  1533
val minus_mult_left = thm"minus_mult_left";
paulson@14331
  1534
val minus_mult_right = thm"minus_mult_right";
paulson@14331
  1535
val minus_mult_minus = thm"minus_mult_minus";
paulson@14331
  1536
val right_diff_distrib = thm"right_diff_distrib";
paulson@14331
  1537
val left_diff_distrib = thm"left_diff_distrib";
paulson@14331
  1538
val minus_diff_eq = thm"minus_diff_eq";
paulson@14331
  1539
val add_right_mono = thm"add_right_mono";
paulson@14331
  1540
val add_mono = thm"add_mono";
paulson@14331
  1541
val add_strict_left_mono = thm"add_strict_left_mono";
paulson@14331
  1542
val add_strict_right_mono = thm"add_strict_right_mono";
paulson@14331
  1543
val add_strict_mono = thm"add_strict_mono";
paulson@14331
  1544
val add_less_imp_less_left = thm"add_less_imp_less_left";
paulson@14331
  1545
val add_less_imp_less_right = thm"add_less_imp_less_right";
paulson@14331
  1546
val add_less_cancel_left = thm"add_less_cancel_left";
paulson@14331
  1547
val add_less_cancel_right = thm"add_less_cancel_right";
paulson@14331
  1548
val add_le_cancel_left = thm"add_le_cancel_left";
paulson@14331
  1549
val add_le_cancel_right = thm"add_le_cancel_right";
paulson@14331
  1550
val add_le_imp_le_left = thm"add_le_imp_le_left";
paulson@14331
  1551
val add_le_imp_le_right = thm"add_le_imp_le_right";
paulson@14331
  1552
val le_imp_neg_le = thm"le_imp_neg_le";
paulson@14331
  1553
val neg_le_iff_le = thm"neg_le_iff_le";
paulson@14331
  1554
val neg_le_0_iff_le = thm"neg_le_0_iff_le";
paulson@14331
  1555
val neg_0_le_iff_le = thm"neg_0_le_iff_le";
paulson@14331
  1556
val neg_less_iff_less = thm"neg_less_iff_less";
paulson@14331
  1557
val neg_less_0_iff_less = thm"neg_less_0_iff_less";
paulson@14331
  1558
val neg_0_less_iff_less = thm"neg_0_less_iff_less";
paulson@14331
  1559
val less_minus_iff = thm"less_minus_iff";
paulson@14331
  1560
val minus_less_iff = thm"minus_less_iff";
paulson@14331
  1561
val le_minus_iff = thm"le_minus_iff";
paulson@14331
  1562
val minus_le_iff = thm"minus_le_iff";
paulson@14331
  1563
val add_diff_eq = thm"add_diff_eq";
paulson@14331
  1564
val diff_add_eq = thm"diff_add_eq";
paulson@14331
  1565
val diff_eq_eq = thm"diff_eq_eq";
paulson@14331
  1566
val eq_diff_eq = thm"eq_diff_eq";
paulson@14331
  1567
val diff_diff_eq = thm"diff_diff_eq";
paulson@14331
  1568
val diff_diff_eq2 = thm"diff_diff_eq2";
paulson@14331
  1569
val less_iff_diff_less_0 = thm"less_iff_diff_less_0";
paulson@14331
  1570
val diff_less_eq = thm"diff_less_eq";
paulson@14331
  1571
val less_diff_eq = thm"less_diff_eq";
paulson@14331
  1572
val diff_le_eq = thm"diff_le_eq";
paulson@14331
  1573
val le_diff_eq = thm"le_diff_eq";
paulson@14331
  1574
val eq_iff_diff_eq_0 = thm"eq_iff_diff_eq_0";
paulson@14331
  1575
val le_iff_diff_le_0 = thm"le_iff_diff_le_0";
paulson@14331
  1576
val eq_add_iff1 = thm"eq_add_iff1";
paulson@14331
  1577
val eq_add_iff2 = thm"eq_add_iff2";
paulson@14331
  1578
val less_add_iff1 = thm"less_add_iff1";
paulson@14331
  1579
val less_add_iff2 = thm"less_add_iff2";
paulson@14331
  1580
val le_add_iff1 = thm"le_add_iff1";
paulson@14331
  1581
val le_add_iff2 = thm"le_add_iff2";
paulson@14331
  1582
val mult_strict_right_mono = thm"mult_strict_right_mono";
paulson@14331
  1583
val mult_left_mono = thm"mult_left_mono";
paulson@14331
  1584
val mult_right_mono = thm"mult_right_mono";
paulson@14331
  1585
val mult_strict_left_mono_neg = thm"mult_strict_left_mono_neg";
paulson@14331
  1586
val mult_strict_right_mono_neg = thm"mult_strict_right_mono_neg";
paulson@14331
  1587
val mult_pos = thm"mult_pos";
paulson@14331
  1588
val mult_pos_neg = thm"mult_pos_neg";
paulson@14331
  1589
val mult_neg = thm"mult_neg";
paulson@14331
  1590
val zero_less_mult_pos = thm"zero_less_mult_pos";
paulson@14331
  1591
val zero_less_mult_iff = thm"zero_less_mult_iff";
paulson@14331
  1592
val mult_eq_0_iff = thm"mult_eq_0_iff";
paulson@14331
  1593
val zero_le_mult_iff = thm"zero_le_mult_iff";
paulson@14331
  1594
val mult_less_0_iff = thm"mult_less_0_iff";
paulson@14331
  1595
val mult_le_0_iff = thm"mult_le_0_iff";
paulson@14331
  1596
val zero_le_square = thm"zero_le_square";
paulson@14331
  1597
val zero_less_one = thm"zero_less_one";
paulson@14331
  1598
val zero_le_one = thm"zero_le_one";
paulson@14331
  1599
val mult_left_mono_neg = thm"mult_left_mono_neg";
paulson@14331
  1600
val mult_right_mono_neg = thm"mult_right_mono_neg";
paulson@14331
  1601
val mult_strict_mono = thm"mult_strict_mono";
paulson@14331
  1602
val mult_strict_mono' = thm"mult_strict_mono'";
paulson@14331
  1603
val mult_mono = thm"mult_mono";
paulson@14331
  1604
val mult_less_cancel_right = thm"mult_less_cancel_right";
paulson@14331
  1605
val mult_less_cancel_left = thm"mult_less_cancel_left";
paulson@14331
  1606
val mult_le_cancel_right = thm"mult_le_cancel_right";
paulson@14331
  1607
val mult_le_cancel_left = thm"mult_le_cancel_left";
paulson@14331
  1608
val mult_less_imp_less_left = thm"mult_less_imp_less_left";
paulson@14331
  1609
val mult_less_imp_less_right = thm"mult_less_imp_less_right";
paulson@14331
  1610
val mult_cancel_right = thm"mult_cancel_right";
paulson@14331
  1611
val mult_cancel_left = thm"mult_cancel_left";
paulson@14331
  1612
val left_inverse = thm "left_inverse";
paulson@14331
  1613
val right_inverse = thm"right_inverse";
paulson@14331
  1614
val right_inverse_eq = thm"right_inverse_eq";
paulson@14331
  1615
val nonzero_inverse_eq_divide = thm"nonzero_inverse_eq_divide";
paulson@14331
  1616
val divide_self = thm"divide_self";
paulson@14331
  1617
val divide_inverse_zero = thm"divide_inverse_zero";
paulson@14331
  1618
val divide_zero_left = thm"divide_zero_left";
paulson@14331
  1619
val inverse_eq_divide = thm"inverse_eq_divide";
paulson@14331
  1620
val nonzero_add_divide_distrib = thm"nonzero_add_divide_distrib";
paulson@14331
  1621
val add_divide_distrib = thm"add_divide_distrib";
paulson@14331
  1622
val field_mult_eq_0_iff = thm"field_mult_eq_0_iff";
paulson@14331
  1623
val field_mult_cancel_right = thm"field_mult_cancel_right";
paulson@14331
  1624
val field_mult_cancel_left = thm"field_mult_cancel_left";
paulson@14331
  1625
val nonzero_imp_inverse_nonzero = thm"nonzero_imp_inverse_nonzero";
paulson@14331
  1626
val inverse_zero_imp_zero = thm"inverse_zero_imp_zero";
paulson@14331
  1627
val inverse_nonzero_imp_nonzero = thm"inverse_nonzero_imp_nonzero";
paulson@14331
  1628
val inverse_nonzero_iff_nonzero = thm"inverse_nonzero_iff_nonzero";
paulson@14331
  1629
val nonzero_inverse_minus_eq = thm"nonzero_inverse_minus_eq";
paulson@14331
  1630
val inverse_minus_eq = thm"inverse_minus_eq";
paulson@14331
  1631
val nonzero_inverse_eq_imp_eq = thm"nonzero_inverse_eq_imp_eq";
paulson@14331
  1632
val inverse_eq_imp_eq = thm"inverse_eq_imp_eq";
paulson@14331
  1633
val inverse_eq_iff_eq = thm"inverse_eq_iff_eq";
paulson@14331
  1634
val nonzero_inverse_inverse_eq = thm"nonzero_inverse_inverse_eq";
paulson@14331
  1635
val inverse_inverse_eq = thm"inverse_inverse_eq";
paulson@14331
  1636
val inverse_1 = thm"inverse_1";
paulson@14331
  1637
val nonzero_inverse_mult_distrib = thm"nonzero_inverse_mult_distrib";
paulson@14331
  1638
val inverse_mult_distrib = thm"inverse_mult_distrib";
paulson@14331
  1639
val inverse_add = thm"inverse_add";
paulson@14331
  1640
val nonzero_mult_divide_cancel_left = thm"nonzero_mult_divide_cancel_left";
paulson@14331
  1641
val mult_divide_cancel_left = thm"mult_divide_cancel_left";
paulson@14331
  1642
val nonzero_mult_divide_cancel_right = thm"nonzero_mult_divide_cancel_right";
paulson@14331
  1643
val mult_divide_cancel_right = thm"mult_divide_cancel_right";
paulson@14331
  1644
val mult_divide_cancel_eq_if = thm"mult_divide_cancel_eq_if";
paulson@14331
  1645
val divide_1 = thm"divide_1";
paulson@14331
  1646
val times_divide_eq_right = thm"times_divide_eq_right";
paulson@14331
  1647
val times_divide_eq_left = thm"times_divide_eq_left";
paulson@14331
  1648
val divide_divide_eq_right = thm"divide_divide_eq_right";
paulson@14331
  1649
val divide_divide_eq_left = thm"divide_divide_eq_left";
paulson@14331
  1650
val nonzero_minus_divide_left = thm"nonzero_minus_divide_left";
paulson@14331
  1651
val nonzero_minus_divide_right = thm"nonzero_minus_divide_right";
paulson@14331
  1652
val nonzero_minus_divide_divide = thm"nonzero_minus_divide_divide";
paulson@14331
  1653
val minus_divide_left = thm"minus_divide_left";
paulson@14331
  1654
val minus_divide_right = thm"minus_divide_right";
paulson@14331
  1655
val minus_divide_divide = thm"minus_divide_divide";
paulson@14331
  1656
val positive_imp_inverse_positive = thm"positive_imp_inverse_positive";
paulson@14331
  1657
val negative_imp_inverse_negative = thm"negative_imp_inverse_negative";
paulson@14331
  1658
val inverse_le_imp_le = thm"inverse_le_imp_le";
paulson@14331
  1659
val inverse_positive_imp_positive = thm"inverse_positive_imp_positive";
paulson@14331
  1660
val inverse_positive_iff_positive = thm"inverse_positive_iff_positive";
paulson@14331
  1661
val inverse_negative_imp_negative = thm"inverse_negative_imp_negative";
paulson@14331
  1662
val inverse_negative_iff_negative = thm"inverse_negative_iff_negative";
paulson@14331
  1663
val inverse_nonnegative_iff_nonnegative = thm"inverse_nonnegative_iff_nonnegative";
paulson@14331
  1664
val inverse_nonpositive_iff_nonpositive = thm"inverse_nonpositive_iff_nonpositive";
paulson@14331
  1665
val less_imp_inverse_less = thm"less_imp_inverse_less";
paulson@14331
  1666
val inverse_less_imp_less = thm"inverse_less_imp_less";
paulson@14331
  1667
val inverse_less_iff_less = thm"inverse_less_iff_less";
paulson@14331
  1668
val le_imp_inverse_le = thm"le_imp_inverse_le";
paulson@14331
  1669
val inverse_le_iff_le = thm"inverse_le_iff_le";
paulson@14331
  1670
val inverse_le_imp_le_neg = thm"inverse_le_imp_le_neg";
paulson@14331
  1671
val less_imp_inverse_less_neg = thm"less_imp_inverse_less_neg";
paulson@14331
  1672
val inverse_less_imp_less_neg = thm"inverse_less_imp_less_neg";
paulson@14331
  1673
val inverse_less_iff_less_neg = thm"inverse_less_iff_less_neg";
paulson@14331
  1674
val le_imp_inverse_le_neg = thm"le_imp_inverse_le_neg";
paulson@14331
  1675
val inverse_le_iff_le_neg = thm"inverse_le_iff_le_neg";
paulson@14331
  1676
val zero_less_divide_iff = thm"zero_less_divide_iff";
paulson@14331
  1677
val divide_less_0_iff = thm"divide_less_0_iff";
paulson@14331
  1678
val zero_le_divide_iff = thm"zero_le_divide_iff";
paulson@14331
  1679
val divide_le_0_iff = thm"divide_le_0_iff";
paulson@14331
  1680
val divide_eq_0_iff = thm"divide_eq_0_iff";
paulson@14331
  1681
val pos_le_divide_eq = thm"pos_le_divide_eq";
paulson@14331
  1682
val neg_le_divide_eq = thm"neg_le_divide_eq";
paulson@14331
  1683
val le_divide_eq = thm"le_divide_eq";
paulson@14331
  1684
val pos_divide_le_eq = thm"pos_divide_le_eq";
paulson@14331
  1685
val neg_divide_le_eq = thm"neg_divide_le_eq";
paulson@14331
  1686
val divide_le_eq = thm"divide_le_eq";
paulson@14331
  1687
val pos_less_divide_eq = thm"pos_less_divide_eq";
paulson@14331
  1688
val neg_less_divide_eq = thm"neg_less_divide_eq";
paulson@14331
  1689
val less_divide_eq = thm"less_divide_eq";
paulson@14331
  1690
val pos_divide_less_eq = thm"pos_divide_less_eq";
paulson@14331
  1691
val neg_divide_less_eq = thm"neg_divide_less_eq";
paulson@14331
  1692
val divide_less_eq = thm"divide_less_eq";
paulson@14331
  1693
val nonzero_eq_divide_eq = thm"nonzero_eq_divide_eq";
paulson@14331
  1694
val eq_divide_eq = thm"eq_divide_eq";
paulson@14331
  1695
val nonzero_divide_eq_eq = thm"nonzero_divide_eq_eq";
paulson@14331
  1696
val divide_eq_eq = thm"divide_eq_eq";
paulson@14331
  1697
val divide_cancel_right = thm"divide_cancel_right";
paulson@14331
  1698
val divide_cancel_left = thm"divide_cancel_left";
paulson@14331
  1699
val divide_strict_right_mono = thm"divide_strict_right_mono";
paulson@14331
  1700
val divide_right_mono = thm"divide_right_mono";
paulson@14331
  1701
val divide_strict_left_mono = thm"divide_strict_left_mono";
paulson@14331
  1702
val divide_left_mono = thm"divide_left_mono";
paulson@14331
  1703
val divide_strict_left_mono_neg = thm"divide_strict_left_mono_neg";
paulson@14331
  1704
val divide_strict_right_mono_neg = thm"divide_strict_right_mono_neg";
paulson@14331
  1705
val zero_less_two = thm"zero_less_two";
paulson@14331
  1706
val less_half_sum = thm"less_half_sum";
paulson@14331
  1707
val gt_half_sum = thm"gt_half_sum";
paulson@14331
  1708
val dense = thm"dense";
paulson@14331
  1709
val abs_zero = thm"abs_zero";
paulson@14331
  1710
val abs_one = thm"abs_one";
paulson@14331
  1711
val abs_mult = thm"abs_mult";
paulson@14331
  1712
val abs_eq_0 = thm"abs_eq_0";
paulson@14331
  1713
val zero_less_abs_iff = thm"zero_less_abs_iff";
paulson@14331
  1714
val abs_not_less_zero = thm"abs_not_less_zero";
paulson@14331
  1715
val abs_le_zero_iff = thm"abs_le_zero_iff";
paulson@14331
  1716
val abs_minus_cancel = thm"abs_minus_cancel";
paulson@14331
  1717
val abs_ge_zero = thm"abs_ge_zero";
paulson@14331
  1718
val abs_idempotent = thm"abs_idempotent";
paulson@14331
  1719
val abs_zero_iff = thm"abs_zero_iff";
paulson@14331
  1720
val abs_ge_self = thm"abs_ge_self";
paulson@14331
  1721
val abs_ge_minus_self = thm"abs_ge_minus_self";
paulson@14331
  1722
val nonzero_abs_inverse = thm"nonzero_abs_inverse";
paulson@14331
  1723
val abs_inverse = thm"abs_inverse";
paulson@14331
  1724
val nonzero_abs_divide = thm"nonzero_abs_divide";
paulson@14331
  1725
val abs_divide = thm"abs_divide";
paulson@14331
  1726
val abs_leI = thm"abs_leI";
paulson@14331
  1727
val le_minus_self_iff = thm"le_minus_self_iff";
paulson@14331
  1728
val minus_le_self_iff = thm"minus_le_self_iff";
paulson@14331
  1729
val eq_minus_self_iff = thm"eq_minus_self_iff";
paulson@14331
  1730
val less_minus_self_iff = thm"less_minus_self_iff";
paulson@14331
  1731
val abs_le_D1 = thm"abs_le_D1";
paulson@14331
  1732
val abs_le_D2 = thm"abs_le_D2";
paulson@14331
  1733
val abs_le_iff = thm"abs_le_iff";
paulson@14331
  1734
val abs_less_iff = thm"abs_less_iff";
paulson@14331
  1735
val abs_triangle_ineq = thm"abs_triangle_ineq";
paulson@14331
  1736
val abs_mult_less = thm"abs_mult_less";
paulson@14331
  1737
paulson@14331
  1738
val compare_rls = thms"compare_rls";
paulson@14331
  1739
*}
paulson@14331
  1740
paulson@14293
  1741
paulson@14265
  1742
end