src/HOL/Ring_and_Field.thy
author paulson
Fri Dec 05 18:10:59 2003 +0100 (2003-12-05)
changeset 14277 ad66687ece6e
parent 14272 5efbb548107d
child 14284 f1abe67c448a
permissions -rw-r--r--
more field division lemmas transferred from Real to Ring_and_Field
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@14265
    22
  left_zero [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@14265
    55
lemma right_zero [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@14265
   123
lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ring))" 
paulson@14265
   124
  proof 
paulson@14265
   125
    assume "- a = - b"
paulson@14268
   126
    hence "- (- a) = - (- b)"
paulson@14265
   127
      by simp
paulson@14266
   128
    thus "a=b" by simp
paulson@14265
   129
  next
paulson@14265
   130
    assume "a=b"
paulson@14266
   131
    thus "-a = -b" by simp
paulson@14265
   132
  qed
paulson@14265
   133
paulson@14265
   134
lemma neg_equal_0_iff_equal [simp]: "(-a = 0) = (a = (0::'a::ring))"
paulson@14265
   135
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   136
paulson@14265
   137
lemma neg_0_equal_iff_equal [simp]: "(0 = -a) = (0 = (a::'a::ring))"
paulson@14265
   138
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   139
paulson@14272
   140
text{*The next two equations can make the simplifier loop!*}
paulson@14272
   141
paulson@14272
   142
lemma equation_minus_iff: "(a = - b) = (b = - (a::'a::ring))"
paulson@14272
   143
  proof -
paulson@14272
   144
  have "(- (-a) = - b) = (- a = b)" by (rule neg_equal_iff_equal)
paulson@14272
   145
  thus ?thesis by (simp add: eq_commute)
paulson@14272
   146
  qed
paulson@14272
   147
paulson@14272
   148
lemma minus_equation_iff: "(- a = b) = (- (b::'a::ring) = a)"
paulson@14272
   149
  proof -
paulson@14272
   150
  have "(- a = - (-b)) = (a = -b)" by (rule neg_equal_iff_equal)
paulson@14272
   151
  thus ?thesis by (simp add: eq_commute)
paulson@14272
   152
  qed
paulson@14272
   153
paulson@14265
   154
paulson@14265
   155
subsection {* Derived rules for multiplication *}
paulson@14265
   156
paulson@14267
   157
lemma mult_1_right [simp]: "a * (1::'a::semiring) = a"
paulson@14265
   158
proof -
paulson@14267
   159
  have "a * 1 = 1 * a" by (simp add: mult_commute)
paulson@14267
   160
  also have "... = a" by simp
paulson@14265
   161
  finally show ?thesis .
paulson@14265
   162
qed
paulson@14265
   163
paulson@14265
   164
lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::semiring))"
paulson@14265
   165
  by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute])
paulson@14265
   166
paulson@14265
   167
theorems mult_ac = mult_assoc mult_commute mult_left_commute
paulson@14265
   168
paulson@14269
   169
lemma right_inverse [simp]:
paulson@14270
   170
      assumes not0: "a \<noteq> 0" shows "a * inverse (a::'a::field) = 1"
paulson@14265
   171
proof -
paulson@14265
   172
  have "a * inverse a = inverse a * a" by (simp add: mult_ac)
paulson@14269
   173
  also have "... = 1" using not0 by simp
paulson@14265
   174
  finally show ?thesis .
paulson@14265
   175
qed
paulson@14265
   176
paulson@14265
   177
lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
paulson@14265
   178
proof
paulson@14265
   179
  assume neq: "b \<noteq> 0"
paulson@14265
   180
  {
paulson@14265
   181
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
paulson@14265
   182
    also assume "a / b = 1"
paulson@14265
   183
    finally show "a = b" by simp
paulson@14265
   184
  next
paulson@14265
   185
    assume "a = b"
paulson@14265
   186
    with neq show "a / b = 1" by (simp add: divide_inverse)
paulson@14265
   187
  }
paulson@14265
   188
qed
paulson@14265
   189
paulson@14277
   190
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 ==> inverse (a::'a::field) = 1/a"
paulson@14277
   191
by (simp add: divide_inverse)
paulson@14277
   192
paulson@14265
   193
lemma divide_self [simp]: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
paulson@14265
   194
  by (simp add: divide_inverse)
paulson@14265
   195
paulson@14265
   196
lemma mult_left_zero [simp]: "0 * a = (0::'a::ring)"
paulson@14265
   197
proof -
paulson@14265
   198
  have "0*a + 0*a = 0*a + 0"
paulson@14265
   199
    by (simp add: left_distrib [symmetric])
paulson@14266
   200
  thus ?thesis by (simp only: add_left_cancel)
paulson@14265
   201
qed
paulson@14265
   202
paulson@14265
   203
lemma mult_right_zero [simp]: "a * 0 = (0::'a::ring)"
paulson@14265
   204
  by (simp add: mult_commute)
paulson@14265
   205
paulson@14265
   206
paulson@14265
   207
subsection {* Distribution rules *}
paulson@14265
   208
paulson@14265
   209
lemma right_distrib: "a * (b + c) = a * b + a * (c::'a::semiring)"
paulson@14265
   210
proof -
paulson@14265
   211
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
paulson@14265
   212
  also have "... = b * a + c * a" by (simp only: left_distrib)
paulson@14265
   213
  also have "... = a * b + a * c" by (simp add: mult_ac)
paulson@14265
   214
  finally show ?thesis .
paulson@14265
   215
qed
paulson@14265
   216
paulson@14265
   217
theorems ring_distrib = right_distrib left_distrib
paulson@14265
   218
paulson@14272
   219
text{*For the @{text combine_numerals} simproc*}
paulson@14272
   220
lemma combine_common_factor: "a*e + (b*e + c) = (a+b)*e + (c::'a::semiring)"
paulson@14272
   221
by (simp add: left_distrib add_ac)
paulson@14272
   222
paulson@14265
   223
lemma minus_add_distrib [simp]: "- (a + b) = -a + -(b::'a::ring)"
paulson@14265
   224
apply (rule equals_zero_I)
paulson@14265
   225
apply (simp add: add_ac) 
paulson@14265
   226
done
paulson@14265
   227
paulson@14265
   228
lemma minus_mult_left: "- (a * b) = (-a) * (b::'a::ring)"
paulson@14265
   229
apply (rule equals_zero_I)
paulson@14265
   230
apply (simp add: left_distrib [symmetric]) 
paulson@14265
   231
done
paulson@14265
   232
paulson@14265
   233
lemma minus_mult_right: "- (a * b) = a * -(b::'a::ring)"
paulson@14265
   234
apply (rule equals_zero_I)
paulson@14265
   235
apply (simp add: right_distrib [symmetric]) 
paulson@14265
   236
done
paulson@14265
   237
paulson@14268
   238
lemma minus_mult_minus [simp]: "(- a) * (- b) = a * (b::'a::ring)"
paulson@14268
   239
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
paulson@14268
   240
paulson@14265
   241
lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)"
paulson@14265
   242
by (simp add: right_distrib diff_minus 
paulson@14265
   243
              minus_mult_left [symmetric] minus_mult_right [symmetric]) 
paulson@14265
   244
paulson@14272
   245
lemma left_diff_distrib: "(a - b) * c = a * c - b * (c::'a::ring)"
paulson@14272
   246
by (simp add: mult_commute [of _ c] right_diff_distrib) 
paulson@14272
   247
paulson@14270
   248
lemma minus_diff_eq [simp]: "- (a - b) = b - (a::'a::ring)"
paulson@14270
   249
by (simp add: diff_minus add_commute) 
paulson@14265
   250
paulson@14270
   251
paulson@14270
   252
subsection {* Ordering Rules for Addition *}
paulson@14265
   253
paulson@14265
   254
lemma add_right_mono: "a \<le> (b::'a::ordered_semiring) ==> a + c \<le> b + c"
paulson@14265
   255
by (simp add: add_commute [of _ c] add_left_mono)
paulson@14265
   256
paulson@14267
   257
text {* non-strict, in both arguments *}
paulson@14267
   258
lemma add_mono: "[|a \<le> b;  c \<le> d|] ==> a + c \<le> b + (d::'a::ordered_semiring)"
paulson@14267
   259
  apply (erule add_right_mono [THEN order_trans])
paulson@14267
   260
  apply (simp add: add_commute add_left_mono)
paulson@14267
   261
  done
paulson@14267
   262
paulson@14268
   263
lemma add_strict_left_mono:
paulson@14268
   264
     "a < b ==> c + a < c + (b::'a::ordered_ring)"
paulson@14268
   265
 by (simp add: order_less_le add_left_mono) 
paulson@14268
   266
paulson@14268
   267
lemma add_strict_right_mono:
paulson@14268
   268
     "a < b ==> a + c < b + (c::'a::ordered_ring)"
paulson@14268
   269
 by (simp add: add_commute [of _ c] add_strict_left_mono)
paulson@14268
   270
paulson@14268
   271
text{*Strict monotonicity in both arguments*}
paulson@14268
   272
lemma add_strict_mono: "[|a<b; c<d|] ==> a + c < b + (d::'a::ordered_ring)"
paulson@14268
   273
apply (erule add_strict_right_mono [THEN order_less_trans])
paulson@14268
   274
apply (erule add_strict_left_mono)
paulson@14268
   275
done
paulson@14268
   276
paulson@14270
   277
lemma add_less_imp_less_left:
paulson@14270
   278
      assumes less: "c + a < c + b"  shows "a < (b::'a::ordered_ring)"
paulson@14270
   279
  proof -
paulson@14270
   280
  have "-c + (c + a) < -c + (c + b)"
paulson@14270
   281
    by (rule add_strict_left_mono [OF less])
paulson@14270
   282
  thus "a < b" by (simp add: add_assoc [symmetric])
paulson@14270
   283
  qed
paulson@14270
   284
paulson@14270
   285
lemma add_less_imp_less_right:
paulson@14270
   286
      "a + c < b + c ==> a < (b::'a::ordered_ring)"
paulson@14270
   287
apply (rule add_less_imp_less_left [of c])
paulson@14270
   288
apply (simp add: add_commute)  
paulson@14270
   289
done
paulson@14270
   290
paulson@14270
   291
lemma add_less_cancel_left [simp]:
paulson@14270
   292
    "(c+a < c+b) = (a < (b::'a::ordered_ring))"
paulson@14270
   293
by (blast intro: add_less_imp_less_left add_strict_left_mono) 
paulson@14270
   294
paulson@14270
   295
lemma add_less_cancel_right [simp]:
paulson@14270
   296
    "(a+c < b+c) = (a < (b::'a::ordered_ring))"
paulson@14270
   297
by (blast intro: add_less_imp_less_right add_strict_right_mono)
paulson@14270
   298
paulson@14270
   299
lemma add_le_cancel_left [simp]:
paulson@14270
   300
    "(c+a \<le> c+b) = (a \<le> (b::'a::ordered_ring))"
paulson@14270
   301
by (simp add: linorder_not_less [symmetric]) 
paulson@14270
   302
paulson@14270
   303
lemma add_le_cancel_right [simp]:
paulson@14270
   304
    "(a+c \<le> b+c) = (a \<le> (b::'a::ordered_ring))"
paulson@14270
   305
by (simp add: linorder_not_less [symmetric]) 
paulson@14270
   306
paulson@14270
   307
lemma add_le_imp_le_left:
paulson@14270
   308
      "c + a \<le> c + b ==> a \<le> (b::'a::ordered_ring)"
paulson@14270
   309
by simp
paulson@14270
   310
paulson@14270
   311
lemma add_le_imp_le_right:
paulson@14270
   312
      "a + c \<le> b + c ==> a \<le> (b::'a::ordered_ring)"
paulson@14270
   313
by simp
paulson@14270
   314
paulson@14270
   315
paulson@14270
   316
subsection {* Ordering Rules for Unary Minus *}
paulson@14270
   317
paulson@14265
   318
lemma le_imp_neg_le:
paulson@14269
   319
      assumes "a \<le> (b::'a::ordered_ring)" shows "-b \<le> -a"
paulson@14265
   320
  proof -
paulson@14265
   321
  have "-a+a \<le> -a+b"
paulson@14265
   322
    by (rule add_left_mono) 
paulson@14268
   323
  hence "0 \<le> -a+b"
paulson@14265
   324
    by simp
paulson@14268
   325
  hence "0 + (-b) \<le> (-a + b) + (-b)"
paulson@14265
   326
    by (rule add_right_mono) 
paulson@14266
   327
  thus ?thesis
paulson@14265
   328
    by (simp add: add_assoc)
paulson@14265
   329
  qed
paulson@14265
   330
paulson@14265
   331
lemma neg_le_iff_le [simp]: "(-b \<le> -a) = (a \<le> (b::'a::ordered_ring))"
paulson@14265
   332
  proof 
paulson@14265
   333
    assume "- b \<le> - a"
paulson@14268
   334
    hence "- (- a) \<le> - (- b)"
paulson@14265
   335
      by (rule le_imp_neg_le)
paulson@14266
   336
    thus "a\<le>b" by simp
paulson@14265
   337
  next
paulson@14265
   338
    assume "a\<le>b"
paulson@14266
   339
    thus "-b \<le> -a" by (rule le_imp_neg_le)
paulson@14265
   340
  qed
paulson@14265
   341
paulson@14265
   342
lemma neg_le_0_iff_le [simp]: "(-a \<le> 0) = (0 \<le> (a::'a::ordered_ring))"
paulson@14265
   343
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   344
paulson@14265
   345
lemma neg_0_le_iff_le [simp]: "(0 \<le> -a) = (a \<le> (0::'a::ordered_ring))"
paulson@14265
   346
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   347
paulson@14265
   348
lemma neg_less_iff_less [simp]: "(-b < -a) = (a < (b::'a::ordered_ring))"
paulson@14265
   349
by (force simp add: order_less_le) 
paulson@14265
   350
paulson@14265
   351
lemma neg_less_0_iff_less [simp]: "(-a < 0) = (0 < (a::'a::ordered_ring))"
paulson@14265
   352
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   353
paulson@14265
   354
lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::ordered_ring))"
paulson@14265
   355
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   356
paulson@14272
   357
text{*The next several equations can make the simplifier loop!*}
paulson@14272
   358
paulson@14272
   359
lemma less_minus_iff: "(a < - b) = (b < - (a::'a::ordered_ring))"
paulson@14272
   360
  proof -
paulson@14272
   361
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
paulson@14272
   362
  thus ?thesis by simp
paulson@14272
   363
  qed
paulson@14272
   364
paulson@14272
   365
lemma minus_less_iff: "(- a < b) = (- b < (a::'a::ordered_ring))"
paulson@14272
   366
  proof -
paulson@14272
   367
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
paulson@14272
   368
  thus ?thesis by simp
paulson@14272
   369
  qed
paulson@14272
   370
paulson@14272
   371
lemma le_minus_iff: "(a \<le> - b) = (b \<le> - (a::'a::ordered_ring))"
paulson@14272
   372
apply (simp add: linorder_not_less [symmetric])
paulson@14272
   373
apply (rule minus_less_iff) 
paulson@14272
   374
done
paulson@14272
   375
paulson@14272
   376
lemma minus_le_iff: "(- a \<le> b) = (- b \<le> (a::'a::ordered_ring))"
paulson@14272
   377
apply (simp add: linorder_not_less [symmetric])
paulson@14272
   378
apply (rule less_minus_iff) 
paulson@14272
   379
done
paulson@14272
   380
paulson@14270
   381
paulson@14270
   382
subsection{*Subtraction Laws*}
paulson@14270
   383
paulson@14270
   384
lemma add_diff_eq: "a + (b - c) = (a + b) - (c::'a::ring)"
paulson@14270
   385
by (simp add: diff_minus add_ac)
paulson@14270
   386
paulson@14270
   387
lemma diff_add_eq: "(a - b) + c = (a + c) - (b::'a::ring)"
paulson@14270
   388
by (simp add: diff_minus add_ac)
paulson@14270
   389
paulson@14270
   390
lemma diff_eq_eq: "(a-b = c) = (a = c + (b::'a::ring))"
paulson@14270
   391
by (auto simp add: diff_minus add_assoc)
paulson@14270
   392
paulson@14270
   393
lemma eq_diff_eq: "(a = c-b) = (a + (b::'a::ring) = c)"
paulson@14270
   394
by (auto simp add: diff_minus add_assoc)
paulson@14270
   395
paulson@14270
   396
lemma diff_diff_eq: "(a - b) - c = a - (b + (c::'a::ring))"
paulson@14270
   397
by (simp add: diff_minus add_ac)
paulson@14270
   398
paulson@14270
   399
lemma diff_diff_eq2: "a - (b - c) = (a + c) - (b::'a::ring)"
paulson@14270
   400
by (simp add: diff_minus add_ac)
paulson@14270
   401
paulson@14270
   402
text{*Further subtraction laws for ordered rings*}
paulson@14270
   403
paulson@14272
   404
lemma less_iff_diff_less_0: "(a < b) = (a - b < (0::'a::ordered_ring))"
paulson@14270
   405
proof -
paulson@14270
   406
  have  "(a < b) = (a + (- b) < b + (-b))"  
paulson@14270
   407
    by (simp only: add_less_cancel_right)
paulson@14270
   408
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
paulson@14270
   409
  finally show ?thesis .
paulson@14270
   410
qed
paulson@14270
   411
paulson@14270
   412
lemma diff_less_eq: "(a-b < c) = (a < c + (b::'a::ordered_ring))"
paulson@14272
   413
apply (subst less_iff_diff_less_0)
paulson@14272
   414
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
paulson@14270
   415
apply (simp add: diff_minus add_ac)
paulson@14270
   416
done
paulson@14270
   417
paulson@14270
   418
lemma less_diff_eq: "(a < c-b) = (a + (b::'a::ordered_ring) < c)"
paulson@14272
   419
apply (subst less_iff_diff_less_0)
paulson@14272
   420
apply (rule less_iff_diff_less_0 [of _ "c-b", THEN ssubst])
paulson@14270
   421
apply (simp add: diff_minus add_ac)
paulson@14270
   422
done
paulson@14270
   423
paulson@14270
   424
lemma diff_le_eq: "(a-b \<le> c) = (a \<le> c + (b::'a::ordered_ring))"
paulson@14270
   425
by (simp add: linorder_not_less [symmetric] less_diff_eq)
paulson@14270
   426
paulson@14270
   427
lemma le_diff_eq: "(a \<le> c-b) = (a + (b::'a::ordered_ring) \<le> c)"
paulson@14270
   428
by (simp add: linorder_not_less [symmetric] diff_less_eq)
paulson@14270
   429
paulson@14270
   430
text{*This list of rewrites simplifies (in)equalities by bringing subtractions
paulson@14270
   431
  to the top and then moving negative terms to the other side.
paulson@14270
   432
  Use with @{text add_ac}*}
paulson@14270
   433
lemmas compare_rls =
paulson@14270
   434
       diff_minus [symmetric]
paulson@14270
   435
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
paulson@14270
   436
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
paulson@14270
   437
       diff_eq_eq eq_diff_eq
paulson@14270
   438
paulson@14270
   439
paulson@14272
   440
subsection{*Lemmas for the @{text cancel_numerals} simproc*}
paulson@14272
   441
paulson@14272
   442
lemma eq_iff_diff_eq_0: "(a = b) = (a-b = (0::'a::ring))"
paulson@14272
   443
by (simp add: compare_rls)
paulson@14272
   444
paulson@14272
   445
lemma le_iff_diff_le_0: "(a \<le> b) = (a-b \<le> (0::'a::ordered_ring))"
paulson@14272
   446
by (simp add: compare_rls)
paulson@14272
   447
paulson@14272
   448
lemma eq_add_iff1:
paulson@14272
   449
     "(a*e + c = b*e + d) = ((a-b)*e + c = (d::'a::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 eq_add_iff2:
paulson@14272
   455
     "(a*e + c = b*e + d) = (c = (b-a)*e + (d::'a::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
lemma less_add_iff1:
paulson@14272
   461
     "(a*e + c < b*e + d) = ((a-b)*e + c < (d::'a::ordered_ring))"
paulson@14272
   462
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   463
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   464
done
paulson@14272
   465
paulson@14272
   466
lemma less_add_iff2:
paulson@14272
   467
     "(a*e + c < b*e + d) = (c < (b-a)*e + (d::'a::ordered_ring))"
paulson@14272
   468
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   469
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   470
done
paulson@14272
   471
paulson@14272
   472
lemma le_add_iff1:
paulson@14272
   473
     "(a*e + c \<le> b*e + d) = ((a-b)*e + c \<le> (d::'a::ordered_ring))"
paulson@14272
   474
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   475
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   476
done
paulson@14272
   477
paulson@14272
   478
lemma le_add_iff2:
paulson@14272
   479
     "(a*e + c \<le> b*e + d) = (c \<le> (b-a)*e + (d::'a::ordered_ring))"
paulson@14272
   480
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   481
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   482
done
paulson@14272
   483
paulson@14272
   484
paulson@14270
   485
subsection {* Ordering Rules for Multiplication *}
paulson@14270
   486
paulson@14265
   487
lemma mult_strict_right_mono:
paulson@14265
   488
     "[|a < b; 0 < c|] ==> a * c < b * (c::'a::ordered_semiring)"
paulson@14265
   489
by (simp add: mult_commute [of _ c] mult_strict_left_mono)
paulson@14265
   490
paulson@14265
   491
lemma mult_left_mono:
paulson@14267
   492
     "[|a \<le> b; 0 \<le> c|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14267
   493
  apply (case_tac "c=0", simp)
paulson@14267
   494
  apply (force simp add: mult_strict_left_mono order_le_less) 
paulson@14267
   495
  done
paulson@14265
   496
paulson@14265
   497
lemma mult_right_mono:
paulson@14267
   498
     "[|a \<le> b; 0 \<le> c|] ==> a*c \<le> b * (c::'a::ordered_ring)"
paulson@14267
   499
  by (simp add: mult_left_mono mult_commute [of _ c]) 
paulson@14265
   500
paulson@14265
   501
lemma mult_strict_left_mono_neg:
paulson@14265
   502
     "[|b < a; c < 0|] ==> c * a < c * (b::'a::ordered_ring)"
paulson@14265
   503
apply (drule mult_strict_left_mono [of _ _ "-c"])
paulson@14265
   504
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14265
   505
done
paulson@14265
   506
paulson@14265
   507
lemma mult_strict_right_mono_neg:
paulson@14265
   508
     "[|b < a; c < 0|] ==> a * c < b * (c::'a::ordered_ring)"
paulson@14265
   509
apply (drule mult_strict_right_mono [of _ _ "-c"])
paulson@14265
   510
apply (simp_all add: minus_mult_right [symmetric]) 
paulson@14265
   511
done
paulson@14265
   512
paulson@14265
   513
paulson@14265
   514
subsection{* Products of Signs *}
paulson@14265
   515
paulson@14265
   516
lemma mult_pos: "[| (0::'a::ordered_ring) < a; 0 < b |] ==> 0 < a*b"
paulson@14265
   517
by (drule mult_strict_left_mono [of 0 b], auto)
paulson@14265
   518
paulson@14265
   519
lemma mult_pos_neg: "[| (0::'a::ordered_ring) < a; b < 0 |] ==> a*b < 0"
paulson@14265
   520
by (drule mult_strict_left_mono [of b 0], auto)
paulson@14265
   521
paulson@14265
   522
lemma mult_neg: "[| a < (0::'a::ordered_ring); b < 0 |] ==> 0 < a*b"
paulson@14265
   523
by (drule mult_strict_right_mono_neg, auto)
paulson@14265
   524
paulson@14265
   525
lemma zero_less_mult_pos: "[| 0 < a*b; 0 < a|] ==> 0 < (b::'a::ordered_ring)"
paulson@14265
   526
apply (case_tac "b\<le>0") 
paulson@14265
   527
 apply (auto simp add: order_le_less linorder_not_less)
paulson@14265
   528
apply (drule_tac mult_pos_neg [of a b]) 
paulson@14265
   529
 apply (auto dest: order_less_not_sym)
paulson@14265
   530
done
paulson@14265
   531
paulson@14265
   532
lemma zero_less_mult_iff:
paulson@14265
   533
     "((0::'a::ordered_ring) < a*b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14265
   534
apply (auto simp add: order_le_less linorder_not_less mult_pos mult_neg)
paulson@14265
   535
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   536
apply (simp add: mult_commute [of a b]) 
paulson@14265
   537
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   538
done
paulson@14265
   539
paulson@14277
   540
text{*A field has no "zero divisors", so this theorem should hold without the
paulson@14277
   541
      assumption of an ordering.  See @{text field_mult_eq_0_iff} below.*}
paulson@14266
   542
lemma mult_eq_0_iff [simp]: "(a*b = (0::'a::ordered_ring)) = (a = 0 | b = 0)"
paulson@14265
   543
apply (case_tac "a < 0")
paulson@14265
   544
apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff)
paulson@14265
   545
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+
paulson@14265
   546
done
paulson@14265
   547
paulson@14265
   548
lemma zero_le_mult_iff:
paulson@14265
   549
     "((0::'a::ordered_ring) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14265
   550
by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less
paulson@14265
   551
                   zero_less_mult_iff)
paulson@14265
   552
paulson@14265
   553
lemma mult_less_0_iff:
paulson@14265
   554
     "(a*b < (0::'a::ordered_ring)) = (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14265
   555
apply (insert zero_less_mult_iff [of "-a" b]) 
paulson@14265
   556
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   557
done
paulson@14265
   558
paulson@14265
   559
lemma mult_le_0_iff:
paulson@14265
   560
     "(a*b \<le> (0::'a::ordered_ring)) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14265
   561
apply (insert zero_le_mult_iff [of "-a" b]) 
paulson@14265
   562
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   563
done
paulson@14265
   564
paulson@14265
   565
lemma zero_le_square: "(0::'a::ordered_ring) \<le> a*a"
paulson@14265
   566
by (simp add: zero_le_mult_iff linorder_linear) 
paulson@14265
   567
paulson@14265
   568
lemma zero_less_one: "(0::'a::ordered_ring) < 1"
paulson@14265
   569
apply (insert zero_le_square [of 1]) 
paulson@14265
   570
apply (simp add: order_less_le) 
paulson@14265
   571
done
paulson@14265
   572
paulson@14268
   573
lemma zero_le_one: "(0::'a::ordered_ring) \<le> 1"
paulson@14268
   574
  by (rule zero_less_one [THEN order_less_imp_le]) 
paulson@14268
   575
paulson@14268
   576
paulson@14268
   577
subsection{*More Monotonicity*}
paulson@14268
   578
paulson@14268
   579
lemma mult_left_mono_neg:
paulson@14268
   580
     "[|b \<le> a; c \<le> 0|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14268
   581
apply (drule mult_left_mono [of _ _ "-c"]) 
paulson@14268
   582
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14268
   583
done
paulson@14268
   584
paulson@14268
   585
lemma mult_right_mono_neg:
paulson@14268
   586
     "[|b \<le> a; c \<le> 0|] ==> a * c \<le> b * (c::'a::ordered_ring)"
paulson@14268
   587
  by (simp add: mult_left_mono_neg mult_commute [of _ c]) 
paulson@14268
   588
paulson@14268
   589
text{*Strict monotonicity in both arguments*}
paulson@14268
   590
lemma mult_strict_mono:
paulson@14268
   591
     "[|a<b; c<d; 0<b; 0\<le>c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   592
apply (case_tac "c=0")
paulson@14268
   593
 apply (simp add: mult_pos) 
paulson@14268
   594
apply (erule mult_strict_right_mono [THEN order_less_trans])
paulson@14268
   595
 apply (force simp add: order_le_less) 
paulson@14268
   596
apply (erule mult_strict_left_mono, assumption)
paulson@14268
   597
done
paulson@14268
   598
paulson@14268
   599
text{*This weaker variant has more natural premises*}
paulson@14268
   600
lemma mult_strict_mono':
paulson@14268
   601
     "[| a<b; c<d; 0 \<le> a; 0 \<le> c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   602
apply (rule mult_strict_mono)
paulson@14268
   603
apply (blast intro: order_le_less_trans)+
paulson@14268
   604
done
paulson@14268
   605
paulson@14268
   606
lemma mult_mono:
paulson@14268
   607
     "[|a \<le> b; c \<le> d; 0 \<le> b; 0 \<le> c|] 
paulson@14268
   608
      ==> a * c  \<le>  b * (d::'a::ordered_ring)"
paulson@14268
   609
apply (erule mult_right_mono [THEN order_trans], assumption)
paulson@14268
   610
apply (erule mult_left_mono, assumption)
paulson@14268
   611
done
paulson@14268
   612
paulson@14268
   613
paulson@14268
   614
subsection{*Cancellation Laws for Relationships With a Common Factor*}
paulson@14268
   615
paulson@14268
   616
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
paulson@14268
   617
   also with the relations @{text "\<le>"} and equality.*}
paulson@14268
   618
paulson@14268
   619
lemma mult_less_cancel_right:
paulson@14268
   620
    "(a*c < b*c) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   621
apply (case_tac "c = 0")
paulson@14268
   622
apply (auto simp add: linorder_neq_iff mult_strict_right_mono 
paulson@14268
   623
                      mult_strict_right_mono_neg)
paulson@14268
   624
apply (auto simp add: linorder_not_less 
paulson@14268
   625
                      linorder_not_le [symmetric, of "a*c"]
paulson@14268
   626
                      linorder_not_le [symmetric, of a])
paulson@14268
   627
apply (erule_tac [!] notE)
paulson@14268
   628
apply (auto simp add: order_less_imp_le mult_right_mono 
paulson@14268
   629
                      mult_right_mono_neg)
paulson@14268
   630
done
paulson@14268
   631
paulson@14268
   632
lemma mult_less_cancel_left:
paulson@14268
   633
    "(c*a < c*b) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   634
by (simp add: mult_commute [of c] mult_less_cancel_right)
paulson@14268
   635
paulson@14268
   636
lemma mult_le_cancel_right:
paulson@14268
   637
     "(a*c \<le> b*c) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   638
by (simp add: linorder_not_less [symmetric] mult_less_cancel_right)
paulson@14268
   639
paulson@14268
   640
lemma mult_le_cancel_left:
paulson@14268
   641
     "(c*a \<le> c*b) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   642
by (simp add: mult_commute [of c] mult_le_cancel_right)
paulson@14268
   643
paulson@14268
   644
lemma mult_less_imp_less_left:
paulson@14268
   645
    "[|c*a < c*b; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   646
  by (force elim: order_less_asym simp add: mult_less_cancel_left)
paulson@14268
   647
paulson@14268
   648
lemma mult_less_imp_less_right:
paulson@14268
   649
    "[|a*c < b*c; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   650
  by (force elim: order_less_asym simp add: mult_less_cancel_right)
paulson@14268
   651
paulson@14268
   652
text{*Cancellation of equalities with a common factor*}
paulson@14268
   653
lemma mult_cancel_right [simp]:
paulson@14268
   654
     "(a*c = b*c) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   655
apply (cut_tac linorder_less_linear [of 0 c])
paulson@14268
   656
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono
paulson@14268
   657
             simp add: linorder_neq_iff)
paulson@14268
   658
done
paulson@14268
   659
paulson@14268
   660
text{*These cancellation theorems require an ordering. Versions are proved
paulson@14268
   661
      below that work for fields without an ordering.*}
paulson@14268
   662
lemma mult_cancel_left [simp]:
paulson@14268
   663
     "(c*a = c*b) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   664
by (simp add: mult_commute [of c] mult_cancel_right)
paulson@14268
   665
paulson@14265
   666
paulson@14265
   667
subsection {* Absolute Value *}
paulson@14265
   668
paulson@14265
   669
text{*But is it really better than just rewriting with @{text abs_if}?*}
paulson@14265
   670
lemma abs_split:
paulson@14265
   671
     "P(abs(a::'a::ordered_ring)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
paulson@14265
   672
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
paulson@14265
   673
paulson@14265
   674
lemma abs_zero [simp]: "abs 0 = (0::'a::ordered_ring)"
paulson@14265
   675
by (simp add: abs_if)
paulson@14265
   676
paulson@14265
   677
lemma abs_mult: "abs (x * y) = abs x * abs (y::'a::ordered_ring)" 
paulson@14265
   678
apply (case_tac "x=0 | y=0", force) 
paulson@14265
   679
apply (auto elim: order_less_asym
paulson@14265
   680
            simp add: abs_if mult_less_0_iff linorder_neq_iff
paulson@14265
   681
                  minus_mult_left [symmetric] minus_mult_right [symmetric])  
paulson@14265
   682
done
paulson@14265
   683
paulson@14266
   684
lemma abs_eq_0 [simp]: "(abs x = 0) = (x = (0::'a::ordered_ring))"
paulson@14265
   685
by (simp add: abs_if)
paulson@14265
   686
paulson@14266
   687
lemma zero_less_abs_iff [simp]: "(0 < abs x) = (x ~= (0::'a::ordered_ring))"
paulson@14265
   688
by (simp add: abs_if linorder_neq_iff)
paulson@14265
   689
paulson@14265
   690
paulson@14265
   691
subsection {* Fields *}
paulson@14265
   692
paulson@14277
   693
lemma divide_inverse_zero: "a/b = a * inverse(b::'a::{field,division_by_zero})"
paulson@14277
   694
apply (case_tac "b = 0")
paulson@14277
   695
apply (simp_all add: divide_inverse)
paulson@14277
   696
done
paulson@14277
   697
paulson@14277
   698
lemma divide_zero_left [simp]: "0/a = (0::'a::{field,division_by_zero})"
paulson@14277
   699
by (simp add: divide_inverse_zero)
paulson@14277
   700
paulson@14277
   701
lemma inverse_eq_divide: "inverse (a::'a::{field,division_by_zero}) = 1/a"
paulson@14277
   702
by (simp add: divide_inverse_zero)
paulson@14277
   703
paulson@14270
   704
text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
paulson@14270
   705
      of an ordering.*}
paulson@14270
   706
lemma field_mult_eq_0_iff: "(a*b = (0::'a::field)) = (a = 0 | b = 0)"
paulson@14270
   707
  proof cases
paulson@14270
   708
    assume "a=0" thus ?thesis by simp
paulson@14270
   709
  next
paulson@14270
   710
    assume anz [simp]: "a\<noteq>0"
paulson@14270
   711
    thus ?thesis
paulson@14270
   712
    proof auto
paulson@14270
   713
      assume "a * b = 0"
paulson@14270
   714
      hence "inverse a * (a * b) = 0" by simp
paulson@14270
   715
      thus "b = 0"  by (simp (no_asm_use) add: mult_assoc [symmetric])
paulson@14270
   716
    qed
paulson@14270
   717
  qed
paulson@14270
   718
paulson@14268
   719
text{*Cancellation of equalities with a common factor*}
paulson@14268
   720
lemma field_mult_cancel_right_lemma:
paulson@14269
   721
      assumes cnz: "c \<noteq> (0::'a::field)"
paulson@14269
   722
	  and eq:  "a*c = b*c"
paulson@14269
   723
	 shows "a=b"
paulson@14268
   724
  proof -
paulson@14268
   725
  have "(a * c) * inverse c = (b * c) * inverse c"
paulson@14268
   726
    by (simp add: eq)
paulson@14268
   727
  thus "a=b"
paulson@14268
   728
    by (simp add: mult_assoc cnz)
paulson@14268
   729
  qed
paulson@14268
   730
paulson@14268
   731
lemma field_mult_cancel_right:
paulson@14268
   732
     "(a*c = b*c) = (c = (0::'a::field) | a=b)"
paulson@14269
   733
  proof cases
paulson@14268
   734
    assume "c=0" thus ?thesis by simp
paulson@14268
   735
  next
paulson@14268
   736
    assume "c\<noteq>0" 
paulson@14268
   737
    thus ?thesis by (force dest: field_mult_cancel_right_lemma)
paulson@14268
   738
  qed
paulson@14268
   739
paulson@14268
   740
lemma field_mult_cancel_left:
paulson@14268
   741
     "(c*a = c*b) = (c = (0::'a::field) | a=b)"
paulson@14268
   742
  by (simp add: mult_commute [of c] field_mult_cancel_right) 
paulson@14268
   743
paulson@14268
   744
lemma nonzero_imp_inverse_nonzero: "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::field)"
paulson@14268
   745
  proof
paulson@14268
   746
  assume ianz: "inverse a = 0"
paulson@14268
   747
  assume "a \<noteq> 0"
paulson@14268
   748
  hence "1 = a * inverse a" by simp
paulson@14268
   749
  also have "... = 0" by (simp add: ianz)
paulson@14268
   750
  finally have "1 = (0::'a::field)" .
paulson@14268
   751
  thus False by (simp add: eq_commute)
paulson@14268
   752
  qed
paulson@14268
   753
paulson@14277
   754
paulson@14277
   755
subsection{*Basic Properties of @{term inverse}*}
paulson@14277
   756
paulson@14268
   757
lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   758
apply (rule ccontr) 
paulson@14268
   759
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   760
done
paulson@14268
   761
paulson@14268
   762
lemma inverse_nonzero_imp_nonzero:
paulson@14268
   763
   "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   764
apply (rule ccontr) 
paulson@14268
   765
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   766
done
paulson@14268
   767
paulson@14268
   768
lemma inverse_nonzero_iff_nonzero [simp]:
paulson@14268
   769
   "(inverse a = 0) = (a = (0::'a::{field,division_by_zero}))"
paulson@14268
   770
by (force dest: inverse_nonzero_imp_nonzero) 
paulson@14268
   771
paulson@14268
   772
lemma nonzero_inverse_minus_eq:
paulson@14269
   773
      assumes [simp]: "a\<noteq>0"  shows "inverse(-a) = -inverse(a::'a::field)"
paulson@14268
   774
  proof -
paulson@14269
   775
    have "-a * inverse (- a) = -a * - inverse a"
paulson@14268
   776
      by simp
paulson@14268
   777
    thus ?thesis 
paulson@14269
   778
      by (simp only: field_mult_cancel_left, simp)
paulson@14268
   779
  qed
paulson@14268
   780
paulson@14268
   781
lemma inverse_minus_eq [simp]:
paulson@14268
   782
     "inverse(-a) = -inverse(a::'a::{field,division_by_zero})";
paulson@14269
   783
  proof cases
paulson@14268
   784
    assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14268
   785
  next
paulson@14268
   786
    assume "a\<noteq>0" 
paulson@14268
   787
    thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14268
   788
  qed
paulson@14268
   789
paulson@14268
   790
lemma nonzero_inverse_eq_imp_eq:
paulson@14269
   791
      assumes inveq: "inverse a = inverse b"
paulson@14269
   792
	  and anz:  "a \<noteq> 0"
paulson@14269
   793
	  and bnz:  "b \<noteq> 0"
paulson@14269
   794
	 shows "a = (b::'a::field)"
paulson@14268
   795
  proof -
paulson@14268
   796
  have "a * inverse b = a * inverse a"
paulson@14268
   797
    by (simp add: inveq)
paulson@14268
   798
  hence "(a * inverse b) * b = (a * inverse a) * b"
paulson@14268
   799
    by simp
paulson@14268
   800
  thus "a = b"
paulson@14268
   801
    by (simp add: mult_assoc anz bnz)
paulson@14268
   802
  qed
paulson@14268
   803
paulson@14268
   804
lemma inverse_eq_imp_eq:
paulson@14268
   805
     "inverse a = inverse b ==> a = (b::'a::{field,division_by_zero})"
paulson@14268
   806
apply (case_tac "a=0 | b=0") 
paulson@14268
   807
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
   808
              simp add: eq_commute [of "0::'a"])
paulson@14268
   809
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
   810
done
paulson@14268
   811
paulson@14268
   812
lemma inverse_eq_iff_eq [simp]:
paulson@14268
   813
     "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))"
paulson@14268
   814
by (force dest!: inverse_eq_imp_eq) 
paulson@14268
   815
paulson@14270
   816
lemma nonzero_inverse_inverse_eq:
paulson@14270
   817
      assumes [simp]: "a \<noteq> 0"  shows "inverse(inverse (a::'a::field)) = a"
paulson@14270
   818
  proof -
paulson@14270
   819
  have "(inverse (inverse a) * inverse a) * a = a" 
paulson@14270
   820
    by (simp add: nonzero_imp_inverse_nonzero)
paulson@14270
   821
  thus ?thesis
paulson@14270
   822
    by (simp add: mult_assoc)
paulson@14270
   823
  qed
paulson@14270
   824
paulson@14270
   825
lemma inverse_inverse_eq [simp]:
paulson@14270
   826
     "inverse(inverse (a::'a::{field,division_by_zero})) = a"
paulson@14270
   827
  proof cases
paulson@14270
   828
    assume "a=0" thus ?thesis by simp
paulson@14270
   829
  next
paulson@14270
   830
    assume "a\<noteq>0" 
paulson@14270
   831
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
   832
  qed
paulson@14270
   833
paulson@14270
   834
lemma inverse_1 [simp]: "inverse 1 = (1::'a::field)"
paulson@14270
   835
  proof -
paulson@14270
   836
  have "inverse 1 * 1 = (1::'a::field)" 
paulson@14270
   837
    by (rule left_inverse [OF zero_neq_one [symmetric]])
paulson@14270
   838
  thus ?thesis  by simp
paulson@14270
   839
  qed
paulson@14270
   840
paulson@14270
   841
lemma nonzero_inverse_mult_distrib: 
paulson@14270
   842
      assumes anz: "a \<noteq> 0"
paulson@14270
   843
          and bnz: "b \<noteq> 0"
paulson@14270
   844
      shows "inverse(a*b) = inverse(b) * inverse(a::'a::field)"
paulson@14270
   845
  proof -
paulson@14270
   846
  have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
paulson@14270
   847
    by (simp add: field_mult_eq_0_iff anz bnz)
paulson@14270
   848
  hence "inverse(a*b) * a = inverse(b)" 
paulson@14270
   849
    by (simp add: mult_assoc bnz)
paulson@14270
   850
  hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
paulson@14270
   851
    by simp
paulson@14270
   852
  thus ?thesis
paulson@14270
   853
    by (simp add: mult_assoc anz)
paulson@14270
   854
  qed
paulson@14270
   855
paulson@14270
   856
text{*This version builds in division by zero while also re-orienting
paulson@14270
   857
      the right-hand side.*}
paulson@14270
   858
lemma inverse_mult_distrib [simp]:
paulson@14270
   859
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
   860
  proof cases
paulson@14270
   861
    assume "a \<noteq> 0 & b \<noteq> 0" 
paulson@14270
   862
    thus ?thesis  by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
   863
  next
paulson@14270
   864
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
paulson@14270
   865
    thus ?thesis  by force
paulson@14270
   866
  qed
paulson@14270
   867
paulson@14270
   868
text{*There is no slick version using division by zero.*}
paulson@14270
   869
lemma inverse_add:
paulson@14270
   870
     "[|a \<noteq> 0;  b \<noteq> 0|]
paulson@14270
   871
      ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
paulson@14270
   872
apply (simp add: left_distrib mult_assoc)
paulson@14270
   873
apply (simp add: mult_commute [of "inverse a"]) 
paulson@14270
   874
apply (simp add: mult_assoc [symmetric] add_commute)
paulson@14270
   875
done
paulson@14270
   876
paulson@14277
   877
lemma nonzero_mult_divide_cancel_left:
paulson@14277
   878
  assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" 
paulson@14277
   879
    shows "(c*a)/(c*b) = a/(b::'a::field)"
paulson@14277
   880
proof -
paulson@14277
   881
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
paulson@14277
   882
    by (simp add: field_mult_eq_0_iff divide_inverse 
paulson@14277
   883
                  nonzero_inverse_mult_distrib)
paulson@14277
   884
  also have "... =  a * inverse b * (inverse c * c)"
paulson@14277
   885
    by (simp only: mult_ac)
paulson@14277
   886
  also have "... =  a * inverse b"
paulson@14277
   887
    by simp
paulson@14277
   888
    finally show ?thesis 
paulson@14277
   889
    by (simp add: divide_inverse)
paulson@14277
   890
qed
paulson@14277
   891
paulson@14277
   892
lemma mult_divide_cancel_left:
paulson@14277
   893
     "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
paulson@14277
   894
apply (case_tac "b = 0")
paulson@14277
   895
apply (simp_all add: nonzero_mult_divide_cancel_left)
paulson@14277
   896
done
paulson@14277
   897
paulson@14277
   898
(*For ExtractCommonTerm*)
paulson@14277
   899
lemma mult_divide_cancel_eq_if:
paulson@14277
   900
     "(c*a) / (c*b) = 
paulson@14277
   901
      (if c=0 then 0 else a / (b::'a::{field,division_by_zero}))"
paulson@14277
   902
  by (simp add: mult_divide_cancel_left)
paulson@14277
   903
paulson@14268
   904
paulson@14268
   905
subsection {* Ordered Fields *}
paulson@14268
   906
paulson@14277
   907
lemma positive_imp_inverse_positive: 
paulson@14269
   908
      assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
paulson@14268
   909
  proof -
paulson@14268
   910
  have "0 < a * inverse a" 
paulson@14268
   911
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
   912
  thus "0 < inverse a" 
paulson@14268
   913
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
paulson@14268
   914
  qed
paulson@14268
   915
paulson@14277
   916
lemma negative_imp_inverse_negative:
paulson@14268
   917
     "a < 0 ==> inverse a < (0::'a::ordered_field)"
paulson@14277
   918
  by (insert positive_imp_inverse_positive [of "-a"], 
paulson@14268
   919
      simp add: nonzero_inverse_minus_eq order_less_imp_not_eq) 
paulson@14268
   920
paulson@14268
   921
lemma inverse_le_imp_le:
paulson@14269
   922
      assumes invle: "inverse a \<le> inverse b"
paulson@14269
   923
	  and apos:  "0 < a"
paulson@14269
   924
	 shows "b \<le> (a::'a::ordered_field)"
paulson@14268
   925
  proof (rule classical)
paulson@14268
   926
  assume "~ b \<le> a"
paulson@14268
   927
  hence "a < b"
paulson@14268
   928
    by (simp add: linorder_not_le)
paulson@14268
   929
  hence bpos: "0 < b"
paulson@14268
   930
    by (blast intro: apos order_less_trans)
paulson@14268
   931
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
   932
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
   933
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
   934
    by (simp add: bpos order_less_imp_le mult_right_mono)
paulson@14268
   935
  thus "b \<le> a"
paulson@14268
   936
    by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
paulson@14268
   937
  qed
paulson@14268
   938
paulson@14277
   939
lemma inverse_positive_imp_positive:
paulson@14277
   940
      assumes inv_gt_0: "0 < inverse a"
paulson@14277
   941
          and [simp]:   "a \<noteq> 0"
paulson@14277
   942
        shows "0 < (a::'a::ordered_field)"
paulson@14277
   943
  proof -
paulson@14277
   944
  have "0 < inverse (inverse a)"
paulson@14277
   945
    by (rule positive_imp_inverse_positive)
paulson@14277
   946
  thus "0 < a"
paulson@14277
   947
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
   948
  qed
paulson@14277
   949
paulson@14277
   950
lemma inverse_positive_iff_positive [simp]:
paulson@14277
   951
      "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
   952
apply (case_tac "a = 0", simp)
paulson@14277
   953
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
   954
done
paulson@14277
   955
paulson@14277
   956
lemma inverse_negative_imp_negative:
paulson@14277
   957
      assumes inv_less_0: "inverse a < 0"
paulson@14277
   958
          and [simp]:   "a \<noteq> 0"
paulson@14277
   959
        shows "a < (0::'a::ordered_field)"
paulson@14277
   960
  proof -
paulson@14277
   961
  have "inverse (inverse a) < 0"
paulson@14277
   962
    by (rule negative_imp_inverse_negative)
paulson@14277
   963
  thus "a < 0"
paulson@14277
   964
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
   965
  qed
paulson@14277
   966
paulson@14277
   967
lemma inverse_negative_iff_negative [simp]:
paulson@14277
   968
      "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
   969
apply (case_tac "a = 0", simp)
paulson@14277
   970
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
   971
done
paulson@14277
   972
paulson@14277
   973
lemma inverse_nonnegative_iff_nonnegative [simp]:
paulson@14277
   974
      "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
   975
by (simp add: linorder_not_less [symmetric])
paulson@14277
   976
paulson@14277
   977
lemma inverse_nonpositive_iff_nonpositive [simp]:
paulson@14277
   978
      "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
   979
by (simp add: linorder_not_less [symmetric])
paulson@14277
   980
paulson@14277
   981
paulson@14277
   982
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
   983
paulson@14268
   984
lemma less_imp_inverse_less:
paulson@14269
   985
      assumes less: "a < b"
paulson@14269
   986
	  and apos:  "0 < a"
paulson@14269
   987
	shows "inverse b < inverse (a::'a::ordered_field)"
paulson@14268
   988
  proof (rule ccontr)
paulson@14268
   989
  assume "~ inverse b < inverse a"
paulson@14268
   990
  hence "inverse a \<le> inverse b"
paulson@14268
   991
    by (simp add: linorder_not_less)
paulson@14268
   992
  hence "~ (a < b)"
paulson@14268
   993
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
paulson@14268
   994
  thus False
paulson@14268
   995
    by (rule notE [OF _ less])
paulson@14268
   996
  qed
paulson@14268
   997
paulson@14268
   998
lemma inverse_less_imp_less:
paulson@14268
   999
   "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1000
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
  1001
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
  1002
done
paulson@14268
  1003
paulson@14268
  1004
text{*Both premises are essential. Consider -1 and 1.*}
paulson@14268
  1005
lemma inverse_less_iff_less [simp]:
paulson@14268
  1006
     "[|0 < a; 0 < b|] 
paulson@14268
  1007
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1008
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
  1009
paulson@14268
  1010
lemma le_imp_inverse_le:
paulson@14268
  1011
   "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1012
  by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
  1013
paulson@14268
  1014
lemma inverse_le_iff_le [simp]:
paulson@14268
  1015
     "[|0 < a; 0 < b|] 
paulson@14268
  1016
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1017
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
  1018
paulson@14268
  1019
paulson@14268
  1020
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
  1021
case is trivial, since inverse preserves signs.*}
paulson@14268
  1022
lemma inverse_le_imp_le_neg:
paulson@14268
  1023
   "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
paulson@14268
  1024
  apply (rule classical) 
paulson@14268
  1025
  apply (subgoal_tac "a < 0") 
paulson@14268
  1026
   prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
paulson@14268
  1027
  apply (insert inverse_le_imp_le [of "-b" "-a"])
paulson@14268
  1028
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1029
  done
paulson@14268
  1030
paulson@14268
  1031
lemma less_imp_inverse_less_neg:
paulson@14268
  1032
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1033
  apply (subgoal_tac "a < 0") 
paulson@14268
  1034
   prefer 2 apply (blast intro: order_less_trans) 
paulson@14268
  1035
  apply (insert less_imp_inverse_less [of "-b" "-a"])
paulson@14268
  1036
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1037
  done
paulson@14268
  1038
paulson@14268
  1039
lemma inverse_less_imp_less_neg:
paulson@14268
  1040
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1041
  apply (rule classical) 
paulson@14268
  1042
  apply (subgoal_tac "a < 0") 
paulson@14268
  1043
   prefer 2
paulson@14268
  1044
   apply (force simp add: linorder_not_less intro: order_le_less_trans) 
paulson@14268
  1045
  apply (insert inverse_less_imp_less [of "-b" "-a"])
paulson@14268
  1046
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1047
  done
paulson@14268
  1048
paulson@14268
  1049
lemma inverse_less_iff_less_neg [simp]:
paulson@14268
  1050
     "[|a < 0; b < 0|] 
paulson@14268
  1051
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1052
  apply (insert inverse_less_iff_less [of "-b" "-a"])
paulson@14268
  1053
  apply (simp del: inverse_less_iff_less 
paulson@14268
  1054
	      add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1055
  done
paulson@14268
  1056
paulson@14268
  1057
lemma le_imp_inverse_le_neg:
paulson@14268
  1058
   "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1059
  by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
  1060
paulson@14268
  1061
lemma inverse_le_iff_le_neg [simp]:
paulson@14268
  1062
     "[|a < 0; b < 0|] 
paulson@14268
  1063
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1064
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
  1065
paulson@14277
  1066
paulson@14277
  1067
subsection{*Division and Signs*}
paulson@14277
  1068
paulson@14277
  1069
lemma zero_less_divide_iff:
paulson@14277
  1070
     "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14277
  1071
by (simp add: divide_inverse_zero zero_less_mult_iff)
paulson@14277
  1072
paulson@14277
  1073
lemma divide_less_0_iff:
paulson@14277
  1074
     "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
paulson@14277
  1075
      (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14277
  1076
by (simp add: divide_inverse_zero mult_less_0_iff)
paulson@14277
  1077
paulson@14277
  1078
lemma zero_le_divide_iff:
paulson@14277
  1079
     "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
paulson@14277
  1080
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14277
  1081
by (simp add: divide_inverse_zero zero_le_mult_iff)
paulson@14277
  1082
paulson@14277
  1083
lemma divide_le_0_iff:
paulson@14277
  1084
     "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14277
  1085
by (simp add: divide_inverse_zero mult_le_0_iff)
paulson@14277
  1086
paulson@14277
  1087
lemma divide_eq_0_iff [simp]:
paulson@14277
  1088
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
paulson@14277
  1089
by (simp add: divide_inverse_zero field_mult_eq_0_iff)
paulson@14277
  1090
paulson@14277
  1091
paulson@14265
  1092
end