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