src/HOL/Ring_and_Field.thy
author paulson
Fri Dec 12 15:05:18 2003 +0100 (2003-12-12)
changeset 14293 22542982bffd
parent 14288 d149e3cbdb39
child 14294 f4d806fd72ce
permissions -rw-r--r--
moving some division theorems 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@14288
    22
  add_0 [simp]: "0 + a = a"
paulson@14265
    23
paulson@14265
    24
  mult_assoc: "(a * b) * c = a * (b * c)"
paulson@14265
    25
  mult_commute: "a * b = b * a"
paulson@14267
    26
  mult_1 [simp]: "1 * a = a"
paulson@14265
    27
paulson@14265
    28
  left_distrib: "(a + b) * c = a * c + b * c"
paulson@14265
    29
  zero_neq_one [simp]: "0 \<noteq> 1"
paulson@14265
    30
paulson@14265
    31
axclass ring \<subseteq> semiring, minus
paulson@14265
    32
  left_minus [simp]: "- a + a = 0"
paulson@14265
    33
  diff_minus: "a - b = a + (-b)"
paulson@14265
    34
paulson@14265
    35
axclass ordered_semiring \<subseteq> semiring, linorder
paulson@14265
    36
  add_left_mono: "a \<le> b ==> c + a \<le> c + b"
paulson@14265
    37
  mult_strict_left_mono: "a < b ==> 0 < c ==> c * a < c * b"
paulson@14265
    38
paulson@14265
    39
axclass ordered_ring \<subseteq> ordered_semiring, ring
paulson@14265
    40
  abs_if: "\<bar>a\<bar> = (if a < 0 then -a else a)"
paulson@14265
    41
paulson@14265
    42
axclass field \<subseteq> ring, inverse
paulson@14265
    43
  left_inverse [simp]: "a \<noteq> 0 ==> inverse a * a = 1"
paulson@14265
    44
  divide_inverse:      "b \<noteq> 0 ==> a / b = a * inverse b"
paulson@14265
    45
paulson@14265
    46
axclass ordered_field \<subseteq> ordered_ring, field
paulson@14265
    47
paulson@14265
    48
axclass division_by_zero \<subseteq> zero, inverse
paulson@14268
    49
  inverse_zero [simp]: "inverse 0 = 0"
paulson@14268
    50
  divide_zero [simp]: "a / 0 = 0"
paulson@14265
    51
paulson@14265
    52
paulson@14270
    53
subsection {* Derived Rules for Addition *}
paulson@14265
    54
paulson@14288
    55
lemma add_0_right [simp]: "a + 0 = (a::'a::semiring)"
paulson@14265
    56
proof -
paulson@14265
    57
  have "a + 0 = 0 + a" by (simp only: add_commute)
paulson@14265
    58
  also have "... = a" by simp
paulson@14265
    59
  finally show ?thesis .
paulson@14265
    60
qed
paulson@14265
    61
paulson@14265
    62
lemma add_left_commute: "a + (b + c) = b + (a + (c::'a::semiring))"
paulson@14265
    63
  by (rule mk_left_commute [of "op +", OF add_assoc add_commute])
paulson@14265
    64
paulson@14265
    65
theorems add_ac = add_assoc add_commute add_left_commute
paulson@14265
    66
paulson@14265
    67
lemma right_minus [simp]: "a + -(a::'a::ring) = 0"
paulson@14265
    68
proof -
paulson@14265
    69
  have "a + -a = -a + a" by (simp add: add_ac)
paulson@14265
    70
  also have "... = 0" by simp
paulson@14265
    71
  finally show ?thesis .
paulson@14265
    72
qed
paulson@14265
    73
paulson@14265
    74
lemma right_minus_eq: "(a - b = 0) = (a = (b::'a::ring))"
paulson@14265
    75
proof
paulson@14265
    76
  have "a = a - b + b" by (simp add: diff_minus add_ac)
paulson@14265
    77
  also assume "a - b = 0"
paulson@14265
    78
  finally show "a = b" by simp
paulson@14265
    79
next
paulson@14265
    80
  assume "a = b"
paulson@14265
    81
  thus "a - b = 0" by (simp add: diff_minus)
paulson@14265
    82
qed
paulson@14265
    83
paulson@14265
    84
lemma add_left_cancel [simp]:
paulson@14265
    85
     "(a + b = a + c) = (b = (c::'a::ring))"
paulson@14265
    86
proof
paulson@14265
    87
  assume eq: "a + b = a + c"
paulson@14268
    88
  hence "(-a + a) + b = (-a + a) + c"
paulson@14265
    89
    by (simp only: eq add_assoc)
paulson@14266
    90
  thus "b = c" by simp
paulson@14265
    91
next
paulson@14265
    92
  assume eq: "b = c"
paulson@14266
    93
  thus "a + b = a + c" by simp
paulson@14265
    94
qed
paulson@14265
    95
paulson@14265
    96
lemma add_right_cancel [simp]:
paulson@14265
    97
     "(b + a = c + a) = (b = (c::'a::ring))"
paulson@14265
    98
  by (simp add: add_commute)
paulson@14265
    99
paulson@14265
   100
lemma minus_minus [simp]: "- (- (a::'a::ring)) = a"
paulson@14265
   101
  proof (rule add_left_cancel [of "-a", THEN iffD1])
paulson@14265
   102
    show "(-a + -(-a) = -a + a)"
paulson@14265
   103
    by simp
paulson@14265
   104
  qed
paulson@14265
   105
paulson@14265
   106
lemma equals_zero_I: "a+b = 0 ==> -a = (b::'a::ring)"
paulson@14265
   107
apply (rule right_minus_eq [THEN iffD1, symmetric])
paulson@14265
   108
apply (simp add: diff_minus add_commute) 
paulson@14265
   109
done
paulson@14265
   110
paulson@14265
   111
lemma minus_zero [simp]: "- 0 = (0::'a::ring)"
paulson@14265
   112
by (simp add: equals_zero_I)
paulson@14265
   113
paulson@14270
   114
lemma diff_self [simp]: "a - (a::'a::ring) = 0"
paulson@14270
   115
  by (simp add: diff_minus)
paulson@14270
   116
paulson@14270
   117
lemma diff_0 [simp]: "(0::'a::ring) - a = -a"
paulson@14270
   118
by (simp add: diff_minus)
paulson@14270
   119
paulson@14270
   120
lemma diff_0_right [simp]: "a - (0::'a::ring) = a" 
paulson@14270
   121
by (simp add: diff_minus)
paulson@14270
   122
paulson@14288
   123
lemma diff_minus_eq_add [simp]: "a - - b = a + (b::'a::ring)"
paulson@14288
   124
by (simp add: diff_minus)
paulson@14288
   125
paulson@14265
   126
lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ring))" 
paulson@14265
   127
  proof 
paulson@14265
   128
    assume "- a = - b"
paulson@14268
   129
    hence "- (- a) = - (- b)"
paulson@14265
   130
      by simp
paulson@14266
   131
    thus "a=b" by simp
paulson@14265
   132
  next
paulson@14265
   133
    assume "a=b"
paulson@14266
   134
    thus "-a = -b" by simp
paulson@14265
   135
  qed
paulson@14265
   136
paulson@14265
   137
lemma neg_equal_0_iff_equal [simp]: "(-a = 0) = (a = (0::'a::ring))"
paulson@14265
   138
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   139
paulson@14265
   140
lemma neg_0_equal_iff_equal [simp]: "(0 = -a) = (0 = (a::'a::ring))"
paulson@14265
   141
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   142
paulson@14272
   143
text{*The next two equations can make the simplifier loop!*}
paulson@14272
   144
paulson@14272
   145
lemma equation_minus_iff: "(a = - b) = (b = - (a::'a::ring))"
paulson@14272
   146
  proof -
paulson@14272
   147
  have "(- (-a) = - b) = (- a = b)" by (rule neg_equal_iff_equal)
paulson@14272
   148
  thus ?thesis by (simp add: eq_commute)
paulson@14272
   149
  qed
paulson@14272
   150
paulson@14272
   151
lemma minus_equation_iff: "(- a = b) = (- (b::'a::ring) = a)"
paulson@14272
   152
  proof -
paulson@14272
   153
  have "(- a = - (-b)) = (a = -b)" by (rule neg_equal_iff_equal)
paulson@14272
   154
  thus ?thesis by (simp add: eq_commute)
paulson@14272
   155
  qed
paulson@14272
   156
paulson@14265
   157
paulson@14265
   158
subsection {* Derived rules for multiplication *}
paulson@14265
   159
paulson@14267
   160
lemma mult_1_right [simp]: "a * (1::'a::semiring) = a"
paulson@14265
   161
proof -
paulson@14267
   162
  have "a * 1 = 1 * a" by (simp add: mult_commute)
paulson@14267
   163
  also have "... = a" by simp
paulson@14265
   164
  finally show ?thesis .
paulson@14265
   165
qed
paulson@14265
   166
paulson@14265
   167
lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::semiring))"
paulson@14265
   168
  by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute])
paulson@14265
   169
paulson@14265
   170
theorems mult_ac = mult_assoc mult_commute mult_left_commute
paulson@14265
   171
paulson@14265
   172
lemma mult_left_zero [simp]: "0 * a = (0::'a::ring)"
paulson@14265
   173
proof -
paulson@14265
   174
  have "0*a + 0*a = 0*a + 0"
paulson@14265
   175
    by (simp add: left_distrib [symmetric])
paulson@14266
   176
  thus ?thesis by (simp only: add_left_cancel)
paulson@14265
   177
qed
paulson@14265
   178
paulson@14265
   179
lemma mult_right_zero [simp]: "a * 0 = (0::'a::ring)"
paulson@14265
   180
  by (simp add: mult_commute)
paulson@14265
   181
paulson@14265
   182
paulson@14265
   183
subsection {* Distribution rules *}
paulson@14265
   184
paulson@14265
   185
lemma right_distrib: "a * (b + c) = a * b + a * (c::'a::semiring)"
paulson@14265
   186
proof -
paulson@14265
   187
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
paulson@14265
   188
  also have "... = b * a + c * a" by (simp only: left_distrib)
paulson@14265
   189
  also have "... = a * b + a * c" by (simp add: mult_ac)
paulson@14265
   190
  finally show ?thesis .
paulson@14265
   191
qed
paulson@14265
   192
paulson@14265
   193
theorems ring_distrib = right_distrib left_distrib
paulson@14265
   194
paulson@14272
   195
text{*For the @{text combine_numerals} simproc*}
paulson@14272
   196
lemma combine_common_factor: "a*e + (b*e + c) = (a+b)*e + (c::'a::semiring)"
paulson@14272
   197
by (simp add: left_distrib add_ac)
paulson@14272
   198
paulson@14265
   199
lemma minus_add_distrib [simp]: "- (a + b) = -a + -(b::'a::ring)"
paulson@14265
   200
apply (rule equals_zero_I)
paulson@14265
   201
apply (simp add: add_ac) 
paulson@14265
   202
done
paulson@14265
   203
paulson@14265
   204
lemma minus_mult_left: "- (a * b) = (-a) * (b::'a::ring)"
paulson@14265
   205
apply (rule equals_zero_I)
paulson@14265
   206
apply (simp add: left_distrib [symmetric]) 
paulson@14265
   207
done
paulson@14265
   208
paulson@14265
   209
lemma minus_mult_right: "- (a * b) = a * -(b::'a::ring)"
paulson@14265
   210
apply (rule equals_zero_I)
paulson@14265
   211
apply (simp add: right_distrib [symmetric]) 
paulson@14265
   212
done
paulson@14265
   213
paulson@14268
   214
lemma minus_mult_minus [simp]: "(- a) * (- b) = a * (b::'a::ring)"
paulson@14268
   215
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
paulson@14268
   216
paulson@14265
   217
lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)"
paulson@14265
   218
by (simp add: right_distrib diff_minus 
paulson@14265
   219
              minus_mult_left [symmetric] minus_mult_right [symmetric]) 
paulson@14265
   220
paulson@14272
   221
lemma left_diff_distrib: "(a - b) * c = a * c - b * (c::'a::ring)"
paulson@14272
   222
by (simp add: mult_commute [of _ c] right_diff_distrib) 
paulson@14272
   223
paulson@14270
   224
lemma minus_diff_eq [simp]: "- (a - b) = b - (a::'a::ring)"
paulson@14270
   225
by (simp add: diff_minus add_commute) 
paulson@14265
   226
paulson@14270
   227
paulson@14270
   228
subsection {* Ordering Rules for Addition *}
paulson@14265
   229
paulson@14265
   230
lemma add_right_mono: "a \<le> (b::'a::ordered_semiring) ==> a + c \<le> b + c"
paulson@14265
   231
by (simp add: add_commute [of _ c] add_left_mono)
paulson@14265
   232
paulson@14267
   233
text {* non-strict, in both arguments *}
paulson@14267
   234
lemma add_mono: "[|a \<le> b;  c \<le> d|] ==> a + c \<le> b + (d::'a::ordered_semiring)"
paulson@14267
   235
  apply (erule add_right_mono [THEN order_trans])
paulson@14267
   236
  apply (simp add: add_commute add_left_mono)
paulson@14267
   237
  done
paulson@14267
   238
paulson@14268
   239
lemma add_strict_left_mono:
paulson@14268
   240
     "a < b ==> c + a < c + (b::'a::ordered_ring)"
paulson@14268
   241
 by (simp add: order_less_le add_left_mono) 
paulson@14268
   242
paulson@14268
   243
lemma add_strict_right_mono:
paulson@14268
   244
     "a < b ==> a + c < b + (c::'a::ordered_ring)"
paulson@14268
   245
 by (simp add: add_commute [of _ c] add_strict_left_mono)
paulson@14268
   246
paulson@14268
   247
text{*Strict monotonicity in both arguments*}
paulson@14268
   248
lemma add_strict_mono: "[|a<b; c<d|] ==> a + c < b + (d::'a::ordered_ring)"
paulson@14268
   249
apply (erule add_strict_right_mono [THEN order_less_trans])
paulson@14268
   250
apply (erule add_strict_left_mono)
paulson@14268
   251
done
paulson@14268
   252
paulson@14270
   253
lemma add_less_imp_less_left:
paulson@14270
   254
      assumes less: "c + a < c + b"  shows "a < (b::'a::ordered_ring)"
paulson@14270
   255
  proof -
paulson@14270
   256
  have "-c + (c + a) < -c + (c + b)"
paulson@14270
   257
    by (rule add_strict_left_mono [OF less])
paulson@14270
   258
  thus "a < b" by (simp add: add_assoc [symmetric])
paulson@14270
   259
  qed
paulson@14270
   260
paulson@14270
   261
lemma add_less_imp_less_right:
paulson@14270
   262
      "a + c < b + c ==> a < (b::'a::ordered_ring)"
paulson@14270
   263
apply (rule add_less_imp_less_left [of c])
paulson@14270
   264
apply (simp add: add_commute)  
paulson@14270
   265
done
paulson@14270
   266
paulson@14270
   267
lemma add_less_cancel_left [simp]:
paulson@14270
   268
    "(c+a < c+b) = (a < (b::'a::ordered_ring))"
paulson@14270
   269
by (blast intro: add_less_imp_less_left add_strict_left_mono) 
paulson@14270
   270
paulson@14270
   271
lemma add_less_cancel_right [simp]:
paulson@14270
   272
    "(a+c < b+c) = (a < (b::'a::ordered_ring))"
paulson@14270
   273
by (blast intro: add_less_imp_less_right add_strict_right_mono)
paulson@14270
   274
paulson@14270
   275
lemma add_le_cancel_left [simp]:
paulson@14270
   276
    "(c+a \<le> c+b) = (a \<le> (b::'a::ordered_ring))"
paulson@14270
   277
by (simp add: linorder_not_less [symmetric]) 
paulson@14270
   278
paulson@14270
   279
lemma add_le_cancel_right [simp]:
paulson@14270
   280
    "(a+c \<le> b+c) = (a \<le> (b::'a::ordered_ring))"
paulson@14270
   281
by (simp add: linorder_not_less [symmetric]) 
paulson@14270
   282
paulson@14270
   283
lemma add_le_imp_le_left:
paulson@14270
   284
      "c + a \<le> c + b ==> a \<le> (b::'a::ordered_ring)"
paulson@14270
   285
by simp
paulson@14270
   286
paulson@14270
   287
lemma add_le_imp_le_right:
paulson@14270
   288
      "a + c \<le> b + c ==> a \<le> (b::'a::ordered_ring)"
paulson@14270
   289
by simp
paulson@14270
   290
paulson@14270
   291
paulson@14270
   292
subsection {* Ordering Rules for Unary Minus *}
paulson@14270
   293
paulson@14265
   294
lemma le_imp_neg_le:
paulson@14269
   295
      assumes "a \<le> (b::'a::ordered_ring)" shows "-b \<le> -a"
paulson@14265
   296
  proof -
paulson@14265
   297
  have "-a+a \<le> -a+b"
paulson@14265
   298
    by (rule add_left_mono) 
paulson@14268
   299
  hence "0 \<le> -a+b"
paulson@14265
   300
    by simp
paulson@14268
   301
  hence "0 + (-b) \<le> (-a + b) + (-b)"
paulson@14265
   302
    by (rule add_right_mono) 
paulson@14266
   303
  thus ?thesis
paulson@14265
   304
    by (simp add: add_assoc)
paulson@14265
   305
  qed
paulson@14265
   306
paulson@14265
   307
lemma neg_le_iff_le [simp]: "(-b \<le> -a) = (a \<le> (b::'a::ordered_ring))"
paulson@14265
   308
  proof 
paulson@14265
   309
    assume "- b \<le> - a"
paulson@14268
   310
    hence "- (- a) \<le> - (- b)"
paulson@14265
   311
      by (rule le_imp_neg_le)
paulson@14266
   312
    thus "a\<le>b" by simp
paulson@14265
   313
  next
paulson@14265
   314
    assume "a\<le>b"
paulson@14266
   315
    thus "-b \<le> -a" by (rule le_imp_neg_le)
paulson@14265
   316
  qed
paulson@14265
   317
paulson@14265
   318
lemma neg_le_0_iff_le [simp]: "(-a \<le> 0) = (0 \<le> (a::'a::ordered_ring))"
paulson@14265
   319
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   320
paulson@14265
   321
lemma neg_0_le_iff_le [simp]: "(0 \<le> -a) = (a \<le> (0::'a::ordered_ring))"
paulson@14265
   322
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   323
paulson@14265
   324
lemma neg_less_iff_less [simp]: "(-b < -a) = (a < (b::'a::ordered_ring))"
paulson@14265
   325
by (force simp add: order_less_le) 
paulson@14265
   326
paulson@14265
   327
lemma neg_less_0_iff_less [simp]: "(-a < 0) = (0 < (a::'a::ordered_ring))"
paulson@14265
   328
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   329
paulson@14265
   330
lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::ordered_ring))"
paulson@14265
   331
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   332
paulson@14272
   333
text{*The next several equations can make the simplifier loop!*}
paulson@14272
   334
paulson@14272
   335
lemma less_minus_iff: "(a < - b) = (b < - (a::'a::ordered_ring))"
paulson@14272
   336
  proof -
paulson@14272
   337
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
paulson@14272
   338
  thus ?thesis by simp
paulson@14272
   339
  qed
paulson@14272
   340
paulson@14272
   341
lemma minus_less_iff: "(- a < b) = (- b < (a::'a::ordered_ring))"
paulson@14272
   342
  proof -
paulson@14272
   343
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
paulson@14272
   344
  thus ?thesis by simp
paulson@14272
   345
  qed
paulson@14272
   346
paulson@14272
   347
lemma le_minus_iff: "(a \<le> - b) = (b \<le> - (a::'a::ordered_ring))"
paulson@14272
   348
apply (simp add: linorder_not_less [symmetric])
paulson@14272
   349
apply (rule minus_less_iff) 
paulson@14272
   350
done
paulson@14272
   351
paulson@14272
   352
lemma minus_le_iff: "(- a \<le> b) = (- b \<le> (a::'a::ordered_ring))"
paulson@14272
   353
apply (simp add: linorder_not_less [symmetric])
paulson@14272
   354
apply (rule less_minus_iff) 
paulson@14272
   355
done
paulson@14272
   356
paulson@14270
   357
paulson@14270
   358
subsection{*Subtraction Laws*}
paulson@14270
   359
paulson@14270
   360
lemma add_diff_eq: "a + (b - c) = (a + b) - (c::'a::ring)"
paulson@14270
   361
by (simp add: diff_minus add_ac)
paulson@14270
   362
paulson@14270
   363
lemma diff_add_eq: "(a - b) + c = (a + c) - (b::'a::ring)"
paulson@14270
   364
by (simp add: diff_minus add_ac)
paulson@14270
   365
paulson@14270
   366
lemma diff_eq_eq: "(a-b = c) = (a = c + (b::'a::ring))"
paulson@14270
   367
by (auto simp add: diff_minus add_assoc)
paulson@14270
   368
paulson@14270
   369
lemma eq_diff_eq: "(a = c-b) = (a + (b::'a::ring) = c)"
paulson@14270
   370
by (auto simp add: diff_minus add_assoc)
paulson@14270
   371
paulson@14270
   372
lemma diff_diff_eq: "(a - b) - c = a - (b + (c::'a::ring))"
paulson@14270
   373
by (simp add: diff_minus add_ac)
paulson@14270
   374
paulson@14270
   375
lemma diff_diff_eq2: "a - (b - c) = (a + c) - (b::'a::ring)"
paulson@14270
   376
by (simp add: diff_minus add_ac)
paulson@14270
   377
paulson@14270
   378
text{*Further subtraction laws for ordered rings*}
paulson@14270
   379
paulson@14272
   380
lemma less_iff_diff_less_0: "(a < b) = (a - b < (0::'a::ordered_ring))"
paulson@14270
   381
proof -
paulson@14270
   382
  have  "(a < b) = (a + (- b) < b + (-b))"  
paulson@14270
   383
    by (simp only: add_less_cancel_right)
paulson@14270
   384
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
paulson@14270
   385
  finally show ?thesis .
paulson@14270
   386
qed
paulson@14270
   387
paulson@14270
   388
lemma diff_less_eq: "(a-b < c) = (a < c + (b::'a::ordered_ring))"
paulson@14272
   389
apply (subst less_iff_diff_less_0)
paulson@14272
   390
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
paulson@14270
   391
apply (simp add: diff_minus add_ac)
paulson@14270
   392
done
paulson@14270
   393
paulson@14270
   394
lemma less_diff_eq: "(a < c-b) = (a + (b::'a::ordered_ring) < c)"
paulson@14272
   395
apply (subst less_iff_diff_less_0)
paulson@14272
   396
apply (rule less_iff_diff_less_0 [of _ "c-b", THEN ssubst])
paulson@14270
   397
apply (simp add: diff_minus add_ac)
paulson@14270
   398
done
paulson@14270
   399
paulson@14270
   400
lemma diff_le_eq: "(a-b \<le> c) = (a \<le> c + (b::'a::ordered_ring))"
paulson@14270
   401
by (simp add: linorder_not_less [symmetric] less_diff_eq)
paulson@14270
   402
paulson@14270
   403
lemma le_diff_eq: "(a \<le> c-b) = (a + (b::'a::ordered_ring) \<le> c)"
paulson@14270
   404
by (simp add: linorder_not_less [symmetric] diff_less_eq)
paulson@14270
   405
paulson@14270
   406
text{*This list of rewrites simplifies (in)equalities by bringing subtractions
paulson@14270
   407
  to the top and then moving negative terms to the other side.
paulson@14270
   408
  Use with @{text add_ac}*}
paulson@14270
   409
lemmas compare_rls =
paulson@14270
   410
       diff_minus [symmetric]
paulson@14270
   411
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
paulson@14270
   412
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
paulson@14270
   413
       diff_eq_eq eq_diff_eq
paulson@14270
   414
paulson@14270
   415
paulson@14272
   416
subsection{*Lemmas for the @{text cancel_numerals} simproc*}
paulson@14272
   417
paulson@14272
   418
lemma eq_iff_diff_eq_0: "(a = b) = (a-b = (0::'a::ring))"
paulson@14272
   419
by (simp add: compare_rls)
paulson@14272
   420
paulson@14272
   421
lemma le_iff_diff_le_0: "(a \<le> b) = (a-b \<le> (0::'a::ordered_ring))"
paulson@14272
   422
by (simp add: compare_rls)
paulson@14272
   423
paulson@14272
   424
lemma eq_add_iff1:
paulson@14272
   425
     "(a*e + c = b*e + d) = ((a-b)*e + c = (d::'a::ring))"
paulson@14272
   426
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   427
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   428
done
paulson@14272
   429
paulson@14272
   430
lemma eq_add_iff2:
paulson@14272
   431
     "(a*e + c = b*e + d) = (c = (b-a)*e + (d::'a::ring))"
paulson@14272
   432
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   433
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   434
done
paulson@14272
   435
paulson@14272
   436
lemma less_add_iff1:
paulson@14272
   437
     "(a*e + c < b*e + d) = ((a-b)*e + c < (d::'a::ordered_ring))"
paulson@14272
   438
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   439
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   440
done
paulson@14272
   441
paulson@14272
   442
lemma less_add_iff2:
paulson@14272
   443
     "(a*e + c < b*e + d) = (c < (b-a)*e + (d::'a::ordered_ring))"
paulson@14272
   444
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   445
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   446
done
paulson@14272
   447
paulson@14272
   448
lemma le_add_iff1:
paulson@14272
   449
     "(a*e + c \<le> b*e + d) = ((a-b)*e + c \<le> (d::'a::ordered_ring))"
paulson@14272
   450
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   451
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   452
done
paulson@14272
   453
paulson@14272
   454
lemma le_add_iff2:
paulson@14272
   455
     "(a*e + c \<le> b*e + d) = (c \<le> (b-a)*e + (d::'a::ordered_ring))"
paulson@14272
   456
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   457
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   458
done
paulson@14272
   459
paulson@14272
   460
paulson@14270
   461
subsection {* Ordering Rules for Multiplication *}
paulson@14270
   462
paulson@14265
   463
lemma mult_strict_right_mono:
paulson@14265
   464
     "[|a < b; 0 < c|] ==> a * c < b * (c::'a::ordered_semiring)"
paulson@14265
   465
by (simp add: mult_commute [of _ c] mult_strict_left_mono)
paulson@14265
   466
paulson@14265
   467
lemma mult_left_mono:
paulson@14267
   468
     "[|a \<le> b; 0 \<le> c|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14267
   469
  apply (case_tac "c=0", simp)
paulson@14267
   470
  apply (force simp add: mult_strict_left_mono order_le_less) 
paulson@14267
   471
  done
paulson@14265
   472
paulson@14265
   473
lemma mult_right_mono:
paulson@14267
   474
     "[|a \<le> b; 0 \<le> c|] ==> a*c \<le> b * (c::'a::ordered_ring)"
paulson@14267
   475
  by (simp add: mult_left_mono mult_commute [of _ c]) 
paulson@14265
   476
paulson@14265
   477
lemma mult_strict_left_mono_neg:
paulson@14265
   478
     "[|b < a; c < 0|] ==> c * a < c * (b::'a::ordered_ring)"
paulson@14265
   479
apply (drule mult_strict_left_mono [of _ _ "-c"])
paulson@14265
   480
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14265
   481
done
paulson@14265
   482
paulson@14265
   483
lemma mult_strict_right_mono_neg:
paulson@14265
   484
     "[|b < a; c < 0|] ==> a * c < b * (c::'a::ordered_ring)"
paulson@14265
   485
apply (drule mult_strict_right_mono [of _ _ "-c"])
paulson@14265
   486
apply (simp_all add: minus_mult_right [symmetric]) 
paulson@14265
   487
done
paulson@14265
   488
paulson@14265
   489
paulson@14265
   490
subsection{* Products of Signs *}
paulson@14265
   491
paulson@14265
   492
lemma mult_pos: "[| (0::'a::ordered_ring) < a; 0 < b |] ==> 0 < a*b"
paulson@14265
   493
by (drule mult_strict_left_mono [of 0 b], auto)
paulson@14265
   494
paulson@14265
   495
lemma mult_pos_neg: "[| (0::'a::ordered_ring) < a; b < 0 |] ==> a*b < 0"
paulson@14265
   496
by (drule mult_strict_left_mono [of b 0], auto)
paulson@14265
   497
paulson@14265
   498
lemma mult_neg: "[| a < (0::'a::ordered_ring); b < 0 |] ==> 0 < a*b"
paulson@14265
   499
by (drule mult_strict_right_mono_neg, auto)
paulson@14265
   500
paulson@14265
   501
lemma zero_less_mult_pos: "[| 0 < a*b; 0 < a|] ==> 0 < (b::'a::ordered_ring)"
paulson@14265
   502
apply (case_tac "b\<le>0") 
paulson@14265
   503
 apply (auto simp add: order_le_less linorder_not_less)
paulson@14265
   504
apply (drule_tac mult_pos_neg [of a b]) 
paulson@14265
   505
 apply (auto dest: order_less_not_sym)
paulson@14265
   506
done
paulson@14265
   507
paulson@14265
   508
lemma zero_less_mult_iff:
paulson@14265
   509
     "((0::'a::ordered_ring) < a*b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14265
   510
apply (auto simp add: order_le_less linorder_not_less mult_pos mult_neg)
paulson@14265
   511
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   512
apply (simp add: mult_commute [of a b]) 
paulson@14265
   513
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   514
done
paulson@14265
   515
paulson@14277
   516
text{*A field has no "zero divisors", so this theorem should hold without the
paulson@14277
   517
      assumption of an ordering.  See @{text field_mult_eq_0_iff} below.*}
paulson@14266
   518
lemma mult_eq_0_iff [simp]: "(a*b = (0::'a::ordered_ring)) = (a = 0 | b = 0)"
paulson@14265
   519
apply (case_tac "a < 0")
paulson@14265
   520
apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff)
paulson@14265
   521
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+
paulson@14265
   522
done
paulson@14265
   523
paulson@14265
   524
lemma zero_le_mult_iff:
paulson@14265
   525
     "((0::'a::ordered_ring) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14265
   526
by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less
paulson@14265
   527
                   zero_less_mult_iff)
paulson@14265
   528
paulson@14265
   529
lemma mult_less_0_iff:
paulson@14265
   530
     "(a*b < (0::'a::ordered_ring)) = (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14265
   531
apply (insert zero_less_mult_iff [of "-a" b]) 
paulson@14265
   532
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   533
done
paulson@14265
   534
paulson@14265
   535
lemma mult_le_0_iff:
paulson@14265
   536
     "(a*b \<le> (0::'a::ordered_ring)) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14265
   537
apply (insert zero_le_mult_iff [of "-a" b]) 
paulson@14265
   538
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   539
done
paulson@14265
   540
paulson@14265
   541
lemma zero_le_square: "(0::'a::ordered_ring) \<le> a*a"
paulson@14265
   542
by (simp add: zero_le_mult_iff linorder_linear) 
paulson@14265
   543
paulson@14265
   544
lemma zero_less_one: "(0::'a::ordered_ring) < 1"
paulson@14265
   545
apply (insert zero_le_square [of 1]) 
paulson@14265
   546
apply (simp add: order_less_le) 
paulson@14265
   547
done
paulson@14265
   548
paulson@14268
   549
lemma zero_le_one: "(0::'a::ordered_ring) \<le> 1"
paulson@14268
   550
  by (rule zero_less_one [THEN order_less_imp_le]) 
paulson@14268
   551
paulson@14268
   552
paulson@14268
   553
subsection{*More Monotonicity*}
paulson@14268
   554
paulson@14268
   555
lemma mult_left_mono_neg:
paulson@14268
   556
     "[|b \<le> a; c \<le> 0|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14268
   557
apply (drule mult_left_mono [of _ _ "-c"]) 
paulson@14268
   558
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14268
   559
done
paulson@14268
   560
paulson@14268
   561
lemma mult_right_mono_neg:
paulson@14268
   562
     "[|b \<le> a; c \<le> 0|] ==> a * c \<le> b * (c::'a::ordered_ring)"
paulson@14268
   563
  by (simp add: mult_left_mono_neg mult_commute [of _ c]) 
paulson@14268
   564
paulson@14268
   565
text{*Strict monotonicity in both arguments*}
paulson@14268
   566
lemma mult_strict_mono:
paulson@14268
   567
     "[|a<b; c<d; 0<b; 0\<le>c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   568
apply (case_tac "c=0")
paulson@14268
   569
 apply (simp add: mult_pos) 
paulson@14268
   570
apply (erule mult_strict_right_mono [THEN order_less_trans])
paulson@14268
   571
 apply (force simp add: order_le_less) 
paulson@14268
   572
apply (erule mult_strict_left_mono, assumption)
paulson@14268
   573
done
paulson@14268
   574
paulson@14268
   575
text{*This weaker variant has more natural premises*}
paulson@14268
   576
lemma mult_strict_mono':
paulson@14268
   577
     "[| a<b; c<d; 0 \<le> a; 0 \<le> c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   578
apply (rule mult_strict_mono)
paulson@14268
   579
apply (blast intro: order_le_less_trans)+
paulson@14268
   580
done
paulson@14268
   581
paulson@14268
   582
lemma mult_mono:
paulson@14268
   583
     "[|a \<le> b; c \<le> d; 0 \<le> b; 0 \<le> c|] 
paulson@14268
   584
      ==> a * c  \<le>  b * (d::'a::ordered_ring)"
paulson@14268
   585
apply (erule mult_right_mono [THEN order_trans], assumption)
paulson@14268
   586
apply (erule mult_left_mono, assumption)
paulson@14268
   587
done
paulson@14268
   588
paulson@14268
   589
paulson@14268
   590
subsection{*Cancellation Laws for Relationships With a Common Factor*}
paulson@14268
   591
paulson@14268
   592
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
paulson@14268
   593
   also with the relations @{text "\<le>"} and equality.*}
paulson@14268
   594
paulson@14268
   595
lemma mult_less_cancel_right:
paulson@14268
   596
    "(a*c < b*c) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   597
apply (case_tac "c = 0")
paulson@14268
   598
apply (auto simp add: linorder_neq_iff mult_strict_right_mono 
paulson@14268
   599
                      mult_strict_right_mono_neg)
paulson@14268
   600
apply (auto simp add: linorder_not_less 
paulson@14268
   601
                      linorder_not_le [symmetric, of "a*c"]
paulson@14268
   602
                      linorder_not_le [symmetric, of a])
paulson@14268
   603
apply (erule_tac [!] notE)
paulson@14268
   604
apply (auto simp add: order_less_imp_le mult_right_mono 
paulson@14268
   605
                      mult_right_mono_neg)
paulson@14268
   606
done
paulson@14268
   607
paulson@14268
   608
lemma mult_less_cancel_left:
paulson@14268
   609
    "(c*a < c*b) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   610
by (simp add: mult_commute [of c] mult_less_cancel_right)
paulson@14268
   611
paulson@14268
   612
lemma mult_le_cancel_right:
paulson@14268
   613
     "(a*c \<le> b*c) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   614
by (simp add: linorder_not_less [symmetric] mult_less_cancel_right)
paulson@14268
   615
paulson@14268
   616
lemma mult_le_cancel_left:
paulson@14268
   617
     "(c*a \<le> c*b) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   618
by (simp add: mult_commute [of c] mult_le_cancel_right)
paulson@14268
   619
paulson@14268
   620
lemma mult_less_imp_less_left:
paulson@14268
   621
    "[|c*a < c*b; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   622
  by (force elim: order_less_asym simp add: mult_less_cancel_left)
paulson@14268
   623
paulson@14268
   624
lemma mult_less_imp_less_right:
paulson@14268
   625
    "[|a*c < b*c; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   626
  by (force elim: order_less_asym simp add: mult_less_cancel_right)
paulson@14268
   627
paulson@14268
   628
text{*Cancellation of equalities with a common factor*}
paulson@14268
   629
lemma mult_cancel_right [simp]:
paulson@14268
   630
     "(a*c = b*c) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   631
apply (cut_tac linorder_less_linear [of 0 c])
paulson@14268
   632
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono
paulson@14268
   633
             simp add: linorder_neq_iff)
paulson@14268
   634
done
paulson@14268
   635
paulson@14268
   636
text{*These cancellation theorems require an ordering. Versions are proved
paulson@14268
   637
      below that work for fields without an ordering.*}
paulson@14268
   638
lemma mult_cancel_left [simp]:
paulson@14268
   639
     "(c*a = c*b) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   640
by (simp add: mult_commute [of c] mult_cancel_right)
paulson@14268
   641
paulson@14265
   642
paulson@14265
   643
subsection {* Fields *}
paulson@14265
   644
paulson@14288
   645
lemma right_inverse [simp]:
paulson@14288
   646
      assumes not0: "a \<noteq> 0" shows "a * inverse (a::'a::field) = 1"
paulson@14288
   647
proof -
paulson@14288
   648
  have "a * inverse a = inverse a * a" by (simp add: mult_ac)
paulson@14288
   649
  also have "... = 1" using not0 by simp
paulson@14288
   650
  finally show ?thesis .
paulson@14288
   651
qed
paulson@14288
   652
paulson@14288
   653
lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
paulson@14288
   654
proof
paulson@14288
   655
  assume neq: "b \<noteq> 0"
paulson@14288
   656
  {
paulson@14288
   657
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
paulson@14288
   658
    also assume "a / b = 1"
paulson@14288
   659
    finally show "a = b" by simp
paulson@14288
   660
  next
paulson@14288
   661
    assume "a = b"
paulson@14288
   662
    with neq show "a / b = 1" by (simp add: divide_inverse)
paulson@14288
   663
  }
paulson@14288
   664
qed
paulson@14288
   665
paulson@14288
   666
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 ==> inverse (a::'a::field) = 1/a"
paulson@14288
   667
by (simp add: divide_inverse)
paulson@14288
   668
paulson@14288
   669
lemma divide_self [simp]: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
paulson@14288
   670
  by (simp add: divide_inverse)
paulson@14288
   671
paulson@14277
   672
lemma divide_inverse_zero: "a/b = a * inverse(b::'a::{field,division_by_zero})"
paulson@14277
   673
apply (case_tac "b = 0")
paulson@14277
   674
apply (simp_all add: divide_inverse)
paulson@14277
   675
done
paulson@14277
   676
paulson@14277
   677
lemma divide_zero_left [simp]: "0/a = (0::'a::{field,division_by_zero})"
paulson@14277
   678
by (simp add: divide_inverse_zero)
paulson@14277
   679
paulson@14277
   680
lemma inverse_eq_divide: "inverse (a::'a::{field,division_by_zero}) = 1/a"
paulson@14277
   681
by (simp add: divide_inverse_zero)
paulson@14277
   682
paulson@14293
   683
lemma nonzero_add_divide_distrib: "c \<noteq> 0 ==> (a+b)/(c::'a::field) = a/c + b/c"
paulson@14293
   684
by (simp add: divide_inverse left_distrib) 
paulson@14293
   685
paulson@14293
   686
lemma add_divide_distrib: "(a+b)/(c::'a::{field,division_by_zero}) = a/c + b/c"
paulson@14293
   687
apply (case_tac "c=0", simp) 
paulson@14293
   688
apply (simp add: nonzero_add_divide_distrib) 
paulson@14293
   689
done
paulson@14293
   690
paulson@14270
   691
text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
paulson@14270
   692
      of an ordering.*}
paulson@14270
   693
lemma field_mult_eq_0_iff: "(a*b = (0::'a::field)) = (a = 0 | b = 0)"
paulson@14270
   694
  proof cases
paulson@14270
   695
    assume "a=0" thus ?thesis by simp
paulson@14270
   696
  next
paulson@14270
   697
    assume anz [simp]: "a\<noteq>0"
paulson@14270
   698
    thus ?thesis
paulson@14270
   699
    proof auto
paulson@14270
   700
      assume "a * b = 0"
paulson@14270
   701
      hence "inverse a * (a * b) = 0" by simp
paulson@14270
   702
      thus "b = 0"  by (simp (no_asm_use) add: mult_assoc [symmetric])
paulson@14270
   703
    qed
paulson@14270
   704
  qed
paulson@14270
   705
paulson@14268
   706
text{*Cancellation of equalities with a common factor*}
paulson@14268
   707
lemma field_mult_cancel_right_lemma:
paulson@14269
   708
      assumes cnz: "c \<noteq> (0::'a::field)"
paulson@14269
   709
	  and eq:  "a*c = b*c"
paulson@14269
   710
	 shows "a=b"
paulson@14268
   711
  proof -
paulson@14268
   712
  have "(a * c) * inverse c = (b * c) * inverse c"
paulson@14268
   713
    by (simp add: eq)
paulson@14268
   714
  thus "a=b"
paulson@14268
   715
    by (simp add: mult_assoc cnz)
paulson@14268
   716
  qed
paulson@14268
   717
paulson@14268
   718
lemma field_mult_cancel_right:
paulson@14268
   719
     "(a*c = b*c) = (c = (0::'a::field) | a=b)"
paulson@14269
   720
  proof cases
paulson@14268
   721
    assume "c=0" thus ?thesis by simp
paulson@14268
   722
  next
paulson@14268
   723
    assume "c\<noteq>0" 
paulson@14268
   724
    thus ?thesis by (force dest: field_mult_cancel_right_lemma)
paulson@14268
   725
  qed
paulson@14268
   726
paulson@14268
   727
lemma field_mult_cancel_left:
paulson@14268
   728
     "(c*a = c*b) = (c = (0::'a::field) | a=b)"
paulson@14268
   729
  by (simp add: mult_commute [of c] field_mult_cancel_right) 
paulson@14268
   730
paulson@14268
   731
lemma nonzero_imp_inverse_nonzero: "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::field)"
paulson@14268
   732
  proof
paulson@14268
   733
  assume ianz: "inverse a = 0"
paulson@14268
   734
  assume "a \<noteq> 0"
paulson@14268
   735
  hence "1 = a * inverse a" by simp
paulson@14268
   736
  also have "... = 0" by (simp add: ianz)
paulson@14268
   737
  finally have "1 = (0::'a::field)" .
paulson@14268
   738
  thus False by (simp add: eq_commute)
paulson@14268
   739
  qed
paulson@14268
   740
paulson@14277
   741
paulson@14277
   742
subsection{*Basic Properties of @{term inverse}*}
paulson@14277
   743
paulson@14268
   744
lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   745
apply (rule ccontr) 
paulson@14268
   746
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   747
done
paulson@14268
   748
paulson@14268
   749
lemma inverse_nonzero_imp_nonzero:
paulson@14268
   750
   "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   751
apply (rule ccontr) 
paulson@14268
   752
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   753
done
paulson@14268
   754
paulson@14268
   755
lemma inverse_nonzero_iff_nonzero [simp]:
paulson@14268
   756
   "(inverse a = 0) = (a = (0::'a::{field,division_by_zero}))"
paulson@14268
   757
by (force dest: inverse_nonzero_imp_nonzero) 
paulson@14268
   758
paulson@14268
   759
lemma nonzero_inverse_minus_eq:
paulson@14269
   760
      assumes [simp]: "a\<noteq>0"  shows "inverse(-a) = -inverse(a::'a::field)"
paulson@14268
   761
  proof -
paulson@14269
   762
    have "-a * inverse (- a) = -a * - inverse a"
paulson@14268
   763
      by simp
paulson@14268
   764
    thus ?thesis 
paulson@14269
   765
      by (simp only: field_mult_cancel_left, simp)
paulson@14268
   766
  qed
paulson@14268
   767
paulson@14268
   768
lemma inverse_minus_eq [simp]:
paulson@14268
   769
     "inverse(-a) = -inverse(a::'a::{field,division_by_zero})";
paulson@14269
   770
  proof cases
paulson@14268
   771
    assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14268
   772
  next
paulson@14268
   773
    assume "a\<noteq>0" 
paulson@14268
   774
    thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14268
   775
  qed
paulson@14268
   776
paulson@14268
   777
lemma nonzero_inverse_eq_imp_eq:
paulson@14269
   778
      assumes inveq: "inverse a = inverse b"
paulson@14269
   779
	  and anz:  "a \<noteq> 0"
paulson@14269
   780
	  and bnz:  "b \<noteq> 0"
paulson@14269
   781
	 shows "a = (b::'a::field)"
paulson@14268
   782
  proof -
paulson@14268
   783
  have "a * inverse b = a * inverse a"
paulson@14268
   784
    by (simp add: inveq)
paulson@14268
   785
  hence "(a * inverse b) * b = (a * inverse a) * b"
paulson@14268
   786
    by simp
paulson@14268
   787
  thus "a = b"
paulson@14268
   788
    by (simp add: mult_assoc anz bnz)
paulson@14268
   789
  qed
paulson@14268
   790
paulson@14268
   791
lemma inverse_eq_imp_eq:
paulson@14268
   792
     "inverse a = inverse b ==> a = (b::'a::{field,division_by_zero})"
paulson@14268
   793
apply (case_tac "a=0 | b=0") 
paulson@14268
   794
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
   795
              simp add: eq_commute [of "0::'a"])
paulson@14268
   796
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
   797
done
paulson@14268
   798
paulson@14268
   799
lemma inverse_eq_iff_eq [simp]:
paulson@14268
   800
     "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))"
paulson@14268
   801
by (force dest!: inverse_eq_imp_eq) 
paulson@14268
   802
paulson@14270
   803
lemma nonzero_inverse_inverse_eq:
paulson@14270
   804
      assumes [simp]: "a \<noteq> 0"  shows "inverse(inverse (a::'a::field)) = a"
paulson@14270
   805
  proof -
paulson@14270
   806
  have "(inverse (inverse a) * inverse a) * a = a" 
paulson@14270
   807
    by (simp add: nonzero_imp_inverse_nonzero)
paulson@14270
   808
  thus ?thesis
paulson@14270
   809
    by (simp add: mult_assoc)
paulson@14270
   810
  qed
paulson@14270
   811
paulson@14270
   812
lemma inverse_inverse_eq [simp]:
paulson@14270
   813
     "inverse(inverse (a::'a::{field,division_by_zero})) = a"
paulson@14270
   814
  proof cases
paulson@14270
   815
    assume "a=0" thus ?thesis by simp
paulson@14270
   816
  next
paulson@14270
   817
    assume "a\<noteq>0" 
paulson@14270
   818
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
   819
  qed
paulson@14270
   820
paulson@14270
   821
lemma inverse_1 [simp]: "inverse 1 = (1::'a::field)"
paulson@14270
   822
  proof -
paulson@14270
   823
  have "inverse 1 * 1 = (1::'a::field)" 
paulson@14270
   824
    by (rule left_inverse [OF zero_neq_one [symmetric]])
paulson@14270
   825
  thus ?thesis  by simp
paulson@14270
   826
  qed
paulson@14270
   827
paulson@14270
   828
lemma nonzero_inverse_mult_distrib: 
paulson@14270
   829
      assumes anz: "a \<noteq> 0"
paulson@14270
   830
          and bnz: "b \<noteq> 0"
paulson@14270
   831
      shows "inverse(a*b) = inverse(b) * inverse(a::'a::field)"
paulson@14270
   832
  proof -
paulson@14270
   833
  have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
paulson@14270
   834
    by (simp add: field_mult_eq_0_iff anz bnz)
paulson@14270
   835
  hence "inverse(a*b) * a = inverse(b)" 
paulson@14270
   836
    by (simp add: mult_assoc bnz)
paulson@14270
   837
  hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
paulson@14270
   838
    by simp
paulson@14270
   839
  thus ?thesis
paulson@14270
   840
    by (simp add: mult_assoc anz)
paulson@14270
   841
  qed
paulson@14270
   842
paulson@14270
   843
text{*This version builds in division by zero while also re-orienting
paulson@14270
   844
      the right-hand side.*}
paulson@14270
   845
lemma inverse_mult_distrib [simp]:
paulson@14270
   846
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
   847
  proof cases
paulson@14270
   848
    assume "a \<noteq> 0 & b \<noteq> 0" 
paulson@14270
   849
    thus ?thesis  by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
   850
  next
paulson@14270
   851
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
paulson@14270
   852
    thus ?thesis  by force
paulson@14270
   853
  qed
paulson@14270
   854
paulson@14270
   855
text{*There is no slick version using division by zero.*}
paulson@14270
   856
lemma inverse_add:
paulson@14270
   857
     "[|a \<noteq> 0;  b \<noteq> 0|]
paulson@14270
   858
      ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
paulson@14270
   859
apply (simp add: left_distrib mult_assoc)
paulson@14270
   860
apply (simp add: mult_commute [of "inverse a"]) 
paulson@14270
   861
apply (simp add: mult_assoc [symmetric] add_commute)
paulson@14270
   862
done
paulson@14270
   863
paulson@14277
   864
lemma nonzero_mult_divide_cancel_left:
paulson@14277
   865
  assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" 
paulson@14277
   866
    shows "(c*a)/(c*b) = a/(b::'a::field)"
paulson@14277
   867
proof -
paulson@14277
   868
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
paulson@14277
   869
    by (simp add: field_mult_eq_0_iff divide_inverse 
paulson@14277
   870
                  nonzero_inverse_mult_distrib)
paulson@14277
   871
  also have "... =  a * inverse b * (inverse c * c)"
paulson@14277
   872
    by (simp only: mult_ac)
paulson@14277
   873
  also have "... =  a * inverse b"
paulson@14277
   874
    by simp
paulson@14277
   875
    finally show ?thesis 
paulson@14277
   876
    by (simp add: divide_inverse)
paulson@14277
   877
qed
paulson@14277
   878
paulson@14277
   879
lemma mult_divide_cancel_left:
paulson@14277
   880
     "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
paulson@14277
   881
apply (case_tac "b = 0")
paulson@14277
   882
apply (simp_all add: nonzero_mult_divide_cancel_left)
paulson@14277
   883
done
paulson@14277
   884
paulson@14277
   885
(*For ExtractCommonTerm*)
paulson@14277
   886
lemma mult_divide_cancel_eq_if:
paulson@14277
   887
     "(c*a) / (c*b) = 
paulson@14277
   888
      (if c=0 then 0 else a / (b::'a::{field,division_by_zero}))"
paulson@14277
   889
  by (simp add: mult_divide_cancel_left)
paulson@14277
   890
paulson@14284
   891
lemma divide_1 [simp]: "a/1 = (a::'a::field)"
paulson@14284
   892
  by (simp add: divide_inverse [OF not_sym])
paulson@14284
   893
paulson@14288
   894
lemma times_divide_eq_right [simp]:
paulson@14288
   895
     "a * (b/c) = (a*b) / (c::'a::{field,division_by_zero})"
paulson@14288
   896
by (simp add: divide_inverse_zero mult_assoc)
paulson@14288
   897
paulson@14288
   898
lemma times_divide_eq_left [simp]:
paulson@14288
   899
     "(b/c) * a = (b*a) / (c::'a::{field,division_by_zero})"
paulson@14288
   900
by (simp add: divide_inverse_zero mult_ac)
paulson@14288
   901
paulson@14288
   902
lemma divide_divide_eq_right [simp]:
paulson@14288
   903
     "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
paulson@14288
   904
by (simp add: divide_inverse_zero mult_ac)
paulson@14288
   905
paulson@14288
   906
lemma divide_divide_eq_left [simp]:
paulson@14288
   907
     "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
paulson@14288
   908
by (simp add: divide_inverse_zero mult_assoc)
paulson@14288
   909
paulson@14268
   910
paulson@14293
   911
subsection {* Division and Unary Minus *}
paulson@14293
   912
paulson@14293
   913
lemma nonzero_minus_divide_left: "b \<noteq> 0 ==> - (a/b) = (-a) / (b::'a::field)"
paulson@14293
   914
by (simp add: divide_inverse minus_mult_left)
paulson@14293
   915
paulson@14293
   916
lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a/b) = a / -(b::'a::field)"
paulson@14293
   917
by (simp add: divide_inverse nonzero_inverse_minus_eq minus_mult_right)
paulson@14293
   918
paulson@14293
   919
lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a)/(-b) = a / (b::'a::field)"
paulson@14293
   920
by (simp add: divide_inverse nonzero_inverse_minus_eq)
paulson@14293
   921
paulson@14293
   922
lemma minus_divide_left: "- (a/b) = (-a) / (b::'a::{field,division_by_zero})"
paulson@14293
   923
apply (case_tac "b=0", simp) 
paulson@14293
   924
apply (simp add: nonzero_minus_divide_left) 
paulson@14293
   925
done
paulson@14293
   926
paulson@14293
   927
lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
paulson@14293
   928
apply (case_tac "b=0", simp) 
paulson@14293
   929
by (rule nonzero_minus_divide_right) 
paulson@14293
   930
paulson@14293
   931
text{*The effect is to extract signs from divisions*}
paulson@14293
   932
declare minus_divide_left  [symmetric, simp]
paulson@14293
   933
declare minus_divide_right [symmetric, simp]
paulson@14293
   934
paulson@14293
   935
lemma minus_divide_divide [simp]:
paulson@14293
   936
     "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
paulson@14293
   937
apply (case_tac "b=0", simp) 
paulson@14293
   938
apply (simp add: nonzero_minus_divide_divide) 
paulson@14293
   939
done
paulson@14293
   940
paulson@14293
   941
paulson@14268
   942
subsection {* Ordered Fields *}
paulson@14268
   943
paulson@14277
   944
lemma positive_imp_inverse_positive: 
paulson@14269
   945
      assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
paulson@14268
   946
  proof -
paulson@14268
   947
  have "0 < a * inverse a" 
paulson@14268
   948
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
   949
  thus "0 < inverse a" 
paulson@14268
   950
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
paulson@14268
   951
  qed
paulson@14268
   952
paulson@14277
   953
lemma negative_imp_inverse_negative:
paulson@14268
   954
     "a < 0 ==> inverse a < (0::'a::ordered_field)"
paulson@14277
   955
  by (insert positive_imp_inverse_positive [of "-a"], 
paulson@14268
   956
      simp add: nonzero_inverse_minus_eq order_less_imp_not_eq) 
paulson@14268
   957
paulson@14268
   958
lemma inverse_le_imp_le:
paulson@14269
   959
      assumes invle: "inverse a \<le> inverse b"
paulson@14269
   960
	  and apos:  "0 < a"
paulson@14269
   961
	 shows "b \<le> (a::'a::ordered_field)"
paulson@14268
   962
  proof (rule classical)
paulson@14268
   963
  assume "~ b \<le> a"
paulson@14268
   964
  hence "a < b"
paulson@14268
   965
    by (simp add: linorder_not_le)
paulson@14268
   966
  hence bpos: "0 < b"
paulson@14268
   967
    by (blast intro: apos order_less_trans)
paulson@14268
   968
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
   969
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
   970
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
   971
    by (simp add: bpos order_less_imp_le mult_right_mono)
paulson@14268
   972
  thus "b \<le> a"
paulson@14268
   973
    by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
paulson@14268
   974
  qed
paulson@14268
   975
paulson@14277
   976
lemma inverse_positive_imp_positive:
paulson@14277
   977
      assumes inv_gt_0: "0 < inverse a"
paulson@14277
   978
          and [simp]:   "a \<noteq> 0"
paulson@14277
   979
        shows "0 < (a::'a::ordered_field)"
paulson@14277
   980
  proof -
paulson@14277
   981
  have "0 < inverse (inverse a)"
paulson@14277
   982
    by (rule positive_imp_inverse_positive)
paulson@14277
   983
  thus "0 < a"
paulson@14277
   984
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
   985
  qed
paulson@14277
   986
paulson@14277
   987
lemma inverse_positive_iff_positive [simp]:
paulson@14277
   988
      "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
   989
apply (case_tac "a = 0", simp)
paulson@14277
   990
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
   991
done
paulson@14277
   992
paulson@14277
   993
lemma inverse_negative_imp_negative:
paulson@14277
   994
      assumes inv_less_0: "inverse a < 0"
paulson@14277
   995
          and [simp]:   "a \<noteq> 0"
paulson@14277
   996
        shows "a < (0::'a::ordered_field)"
paulson@14277
   997
  proof -
paulson@14277
   998
  have "inverse (inverse a) < 0"
paulson@14277
   999
    by (rule negative_imp_inverse_negative)
paulson@14277
  1000
  thus "a < 0"
paulson@14277
  1001
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
  1002
  qed
paulson@14277
  1003
paulson@14277
  1004
lemma inverse_negative_iff_negative [simp]:
paulson@14277
  1005
      "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1006
apply (case_tac "a = 0", simp)
paulson@14277
  1007
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
  1008
done
paulson@14277
  1009
paulson@14277
  1010
lemma inverse_nonnegative_iff_nonnegative [simp]:
paulson@14277
  1011
      "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1012
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1013
paulson@14277
  1014
lemma inverse_nonpositive_iff_nonpositive [simp]:
paulson@14277
  1015
      "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1016
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1017
paulson@14277
  1018
paulson@14277
  1019
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
  1020
paulson@14268
  1021
lemma less_imp_inverse_less:
paulson@14269
  1022
      assumes less: "a < b"
paulson@14269
  1023
	  and apos:  "0 < a"
paulson@14269
  1024
	shows "inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1025
  proof (rule ccontr)
paulson@14268
  1026
  assume "~ inverse b < inverse a"
paulson@14268
  1027
  hence "inverse a \<le> inverse b"
paulson@14268
  1028
    by (simp add: linorder_not_less)
paulson@14268
  1029
  hence "~ (a < b)"
paulson@14268
  1030
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
paulson@14268
  1031
  thus False
paulson@14268
  1032
    by (rule notE [OF _ less])
paulson@14268
  1033
  qed
paulson@14268
  1034
paulson@14268
  1035
lemma inverse_less_imp_less:
paulson@14268
  1036
   "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1037
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
  1038
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
  1039
done
paulson@14268
  1040
paulson@14268
  1041
text{*Both premises are essential. Consider -1 and 1.*}
paulson@14268
  1042
lemma inverse_less_iff_less [simp]:
paulson@14268
  1043
     "[|0 < a; 0 < b|] 
paulson@14268
  1044
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1045
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
  1046
paulson@14268
  1047
lemma le_imp_inverse_le:
paulson@14268
  1048
   "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1049
  by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
  1050
paulson@14268
  1051
lemma inverse_le_iff_le [simp]:
paulson@14268
  1052
     "[|0 < a; 0 < b|] 
paulson@14268
  1053
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1054
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
  1055
paulson@14268
  1056
paulson@14268
  1057
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
  1058
case is trivial, since inverse preserves signs.*}
paulson@14268
  1059
lemma inverse_le_imp_le_neg:
paulson@14268
  1060
   "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
paulson@14268
  1061
  apply (rule classical) 
paulson@14268
  1062
  apply (subgoal_tac "a < 0") 
paulson@14268
  1063
   prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
paulson@14268
  1064
  apply (insert inverse_le_imp_le [of "-b" "-a"])
paulson@14268
  1065
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1066
  done
paulson@14268
  1067
paulson@14268
  1068
lemma less_imp_inverse_less_neg:
paulson@14268
  1069
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1070
  apply (subgoal_tac "a < 0") 
paulson@14268
  1071
   prefer 2 apply (blast intro: order_less_trans) 
paulson@14268
  1072
  apply (insert less_imp_inverse_less [of "-b" "-a"])
paulson@14268
  1073
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1074
  done
paulson@14268
  1075
paulson@14268
  1076
lemma inverse_less_imp_less_neg:
paulson@14268
  1077
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1078
  apply (rule classical) 
paulson@14268
  1079
  apply (subgoal_tac "a < 0") 
paulson@14268
  1080
   prefer 2
paulson@14268
  1081
   apply (force simp add: linorder_not_less intro: order_le_less_trans) 
paulson@14268
  1082
  apply (insert inverse_less_imp_less [of "-b" "-a"])
paulson@14268
  1083
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1084
  done
paulson@14268
  1085
paulson@14268
  1086
lemma inverse_less_iff_less_neg [simp]:
paulson@14268
  1087
     "[|a < 0; b < 0|] 
paulson@14268
  1088
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1089
  apply (insert inverse_less_iff_less [of "-b" "-a"])
paulson@14268
  1090
  apply (simp del: inverse_less_iff_less 
paulson@14268
  1091
	      add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1092
  done
paulson@14268
  1093
paulson@14268
  1094
lemma le_imp_inverse_le_neg:
paulson@14268
  1095
   "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1096
  by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
  1097
paulson@14268
  1098
lemma inverse_le_iff_le_neg [simp]:
paulson@14268
  1099
     "[|a < 0; b < 0|] 
paulson@14268
  1100
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1101
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
  1102
paulson@14277
  1103
paulson@14277
  1104
subsection{*Division and Signs*}
paulson@14277
  1105
paulson@14277
  1106
lemma zero_less_divide_iff:
paulson@14277
  1107
     "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14277
  1108
by (simp add: divide_inverse_zero zero_less_mult_iff)
paulson@14277
  1109
paulson@14277
  1110
lemma divide_less_0_iff:
paulson@14277
  1111
     "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
paulson@14277
  1112
      (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14277
  1113
by (simp add: divide_inverse_zero mult_less_0_iff)
paulson@14277
  1114
paulson@14277
  1115
lemma zero_le_divide_iff:
paulson@14277
  1116
     "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
paulson@14277
  1117
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14277
  1118
by (simp add: divide_inverse_zero zero_le_mult_iff)
paulson@14277
  1119
paulson@14277
  1120
lemma divide_le_0_iff:
paulson@14288
  1121
     "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) =
paulson@14288
  1122
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14277
  1123
by (simp add: divide_inverse_zero mult_le_0_iff)
paulson@14277
  1124
paulson@14277
  1125
lemma divide_eq_0_iff [simp]:
paulson@14277
  1126
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
paulson@14277
  1127
by (simp add: divide_inverse_zero field_mult_eq_0_iff)
paulson@14277
  1128
paulson@14288
  1129
paulson@14288
  1130
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
  1131
paulson@14288
  1132
lemma pos_le_divide_eq: "0 < (c::'a::ordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
  1133
proof -
paulson@14288
  1134
  assume less: "0<c"
paulson@14288
  1135
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
  1136
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1137
  also have "... = (a*c \<le> b)"
paulson@14288
  1138
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1139
  finally show ?thesis .
paulson@14288
  1140
qed
paulson@14288
  1141
paulson@14288
  1142
paulson@14288
  1143
lemma neg_le_divide_eq: "c < (0::'a::ordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
  1144
proof -
paulson@14288
  1145
  assume less: "c<0"
paulson@14288
  1146
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
  1147
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1148
  also have "... = (b \<le> a*c)"
paulson@14288
  1149
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1150
  finally show ?thesis .
paulson@14288
  1151
qed
paulson@14288
  1152
paulson@14288
  1153
lemma le_divide_eq:
paulson@14288
  1154
  "(a \<le> b/c) = 
paulson@14288
  1155
   (if 0 < c then a*c \<le> b
paulson@14288
  1156
             else if c < 0 then b \<le> a*c
paulson@14288
  1157
             else  a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1158
apply (case_tac "c=0", simp) 
paulson@14288
  1159
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
  1160
done
paulson@14288
  1161
paulson@14288
  1162
lemma pos_divide_le_eq: "0 < (c::'a::ordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
  1163
proof -
paulson@14288
  1164
  assume less: "0<c"
paulson@14288
  1165
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
  1166
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1167
  also have "... = (b \<le> a*c)"
paulson@14288
  1168
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1169
  finally show ?thesis .
paulson@14288
  1170
qed
paulson@14288
  1171
paulson@14288
  1172
lemma neg_divide_le_eq: "c < (0::'a::ordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
  1173
proof -
paulson@14288
  1174
  assume less: "c<0"
paulson@14288
  1175
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
  1176
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1177
  also have "... = (a*c \<le> b)"
paulson@14288
  1178
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1179
  finally show ?thesis .
paulson@14288
  1180
qed
paulson@14288
  1181
paulson@14288
  1182
lemma divide_le_eq:
paulson@14288
  1183
  "(b/c \<le> a) = 
paulson@14288
  1184
   (if 0 < c then b \<le> a*c
paulson@14288
  1185
             else if c < 0 then a*c \<le> b
paulson@14288
  1186
             else 0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1187
apply (case_tac "c=0", simp) 
paulson@14288
  1188
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
  1189
done
paulson@14288
  1190
paulson@14288
  1191
paulson@14288
  1192
lemma pos_less_divide_eq:
paulson@14288
  1193
     "0 < (c::'a::ordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
  1194
proof -
paulson@14288
  1195
  assume less: "0<c"
paulson@14288
  1196
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@14288
  1197
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1198
  also have "... = (a*c < b)"
paulson@14288
  1199
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1200
  finally show ?thesis .
paulson@14288
  1201
qed
paulson@14288
  1202
paulson@14288
  1203
lemma neg_less_divide_eq:
paulson@14288
  1204
 "c < (0::'a::ordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
  1205
proof -
paulson@14288
  1206
  assume less: "c<0"
paulson@14288
  1207
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@14288
  1208
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1209
  also have "... = (b < a*c)"
paulson@14288
  1210
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1211
  finally show ?thesis .
paulson@14288
  1212
qed
paulson@14288
  1213
paulson@14288
  1214
lemma less_divide_eq:
paulson@14288
  1215
  "(a < b/c) = 
paulson@14288
  1216
   (if 0 < c then a*c < b
paulson@14288
  1217
             else if c < 0 then b < a*c
paulson@14288
  1218
             else  a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1219
apply (case_tac "c=0", simp) 
paulson@14288
  1220
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
  1221
done
paulson@14288
  1222
paulson@14288
  1223
lemma pos_divide_less_eq:
paulson@14288
  1224
     "0 < (c::'a::ordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
  1225
proof -
paulson@14288
  1226
  assume less: "0<c"
paulson@14288
  1227
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@14288
  1228
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1229
  also have "... = (b < a*c)"
paulson@14288
  1230
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1231
  finally show ?thesis .
paulson@14288
  1232
qed
paulson@14288
  1233
paulson@14288
  1234
lemma neg_divide_less_eq:
paulson@14288
  1235
 "c < (0::'a::ordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
  1236
proof -
paulson@14288
  1237
  assume less: "c<0"
paulson@14288
  1238
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@14288
  1239
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1240
  also have "... = (a*c < b)"
paulson@14288
  1241
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1242
  finally show ?thesis .
paulson@14288
  1243
qed
paulson@14288
  1244
paulson@14288
  1245
lemma divide_less_eq:
paulson@14288
  1246
  "(b/c < a) = 
paulson@14288
  1247
   (if 0 < c then b < a*c
paulson@14288
  1248
             else if c < 0 then a*c < b
paulson@14288
  1249
             else 0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1250
apply (case_tac "c=0", simp) 
paulson@14288
  1251
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
  1252
done
paulson@14288
  1253
paulson@14288
  1254
lemma nonzero_eq_divide_eq: "c\<noteq>0 ==> ((a::'a::field) = b/c) = (a*c = b)"
paulson@14288
  1255
proof -
paulson@14288
  1256
  assume [simp]: "c\<noteq>0"
paulson@14288
  1257
  have "(a = b/c) = (a*c = (b/c)*c)"
paulson@14288
  1258
    by (simp add: field_mult_cancel_right)
paulson@14288
  1259
  also have "... = (a*c = b)"
paulson@14288
  1260
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1261
  finally show ?thesis .
paulson@14288
  1262
qed
paulson@14288
  1263
paulson@14288
  1264
lemma eq_divide_eq:
paulson@14288
  1265
  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
paulson@14288
  1266
by (simp add: nonzero_eq_divide_eq) 
paulson@14288
  1267
paulson@14288
  1268
lemma nonzero_divide_eq_eq: "c\<noteq>0 ==> (b/c = (a::'a::field)) = (b = a*c)"
paulson@14288
  1269
proof -
paulson@14288
  1270
  assume [simp]: "c\<noteq>0"
paulson@14288
  1271
  have "(b/c = a) = ((b/c)*c = a*c)"
paulson@14288
  1272
    by (simp add: field_mult_cancel_right)
paulson@14288
  1273
  also have "... = (b = a*c)"
paulson@14288
  1274
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1275
  finally show ?thesis .
paulson@14288
  1276
qed
paulson@14288
  1277
paulson@14288
  1278
lemma divide_eq_eq:
paulson@14288
  1279
  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
paulson@14288
  1280
by (force simp add: nonzero_divide_eq_eq) 
paulson@14288
  1281
paulson@14288
  1282
subsection{*Cancellation Laws for Division*}
paulson@14288
  1283
paulson@14288
  1284
lemma divide_cancel_right [simp]:
paulson@14288
  1285
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
paulson@14288
  1286
apply (case_tac "c=0", simp) 
paulson@14288
  1287
apply (simp add: divide_inverse_zero field_mult_cancel_right) 
paulson@14288
  1288
done
paulson@14288
  1289
paulson@14288
  1290
lemma divide_cancel_left [simp]:
paulson@14288
  1291
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
paulson@14288
  1292
apply (case_tac "c=0", simp) 
paulson@14288
  1293
apply (simp add: divide_inverse_zero field_mult_cancel_left) 
paulson@14288
  1294
done
paulson@14288
  1295
paulson@14288
  1296
paulson@14293
  1297
subsection {* Ordering Rules for Division *}
paulson@14293
  1298
paulson@14293
  1299
lemma divide_strict_right_mono:
paulson@14293
  1300
     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1301
by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
paulson@14293
  1302
              positive_imp_inverse_positive) 
paulson@14293
  1303
paulson@14293
  1304
lemma divide_right_mono:
paulson@14293
  1305
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{ordered_field,division_by_zero})"
paulson@14293
  1306
  by (force simp add: divide_strict_right_mono order_le_less) 
paulson@14293
  1307
paulson@14293
  1308
paulson@14293
  1309
text{*The last premise ensures that @{term a} and @{term b} 
paulson@14293
  1310
      have the same sign*}
paulson@14293
  1311
lemma divide_strict_left_mono:
paulson@14293
  1312
       "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
paulson@14293
  1313
by (force simp add: zero_less_mult_iff divide_inverse mult_strict_left_mono 
paulson@14293
  1314
      order_less_imp_not_eq order_less_imp_not_eq2  
paulson@14293
  1315
      less_imp_inverse_less less_imp_inverse_less_neg) 
paulson@14293
  1316
paulson@14293
  1317
lemma divide_left_mono:
paulson@14293
  1318
     "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::ordered_field)"
paulson@14293
  1319
  apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
paulson@14293
  1320
   prefer 2 
paulson@14293
  1321
   apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
paulson@14293
  1322
  apply (case_tac "c=0", simp add: divide_inverse)
paulson@14293
  1323
  apply (force simp add: divide_strict_left_mono order_le_less) 
paulson@14293
  1324
  done
paulson@14293
  1325
paulson@14293
  1326
lemma divide_strict_left_mono_neg:
paulson@14293
  1327
     "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
paulson@14293
  1328
  apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
paulson@14293
  1329
   prefer 2 
paulson@14293
  1330
   apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
paulson@14293
  1331
  apply (drule divide_strict_left_mono [of _ _ "-c"]) 
paulson@14293
  1332
   apply (simp_all add: mult_commute nonzero_minus_divide_left [symmetric]) 
paulson@14293
  1333
  done
paulson@14293
  1334
paulson@14293
  1335
lemma divide_strict_right_mono_neg:
paulson@14293
  1336
     "[|b < a; c < 0|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1337
apply (drule divide_strict_right_mono [of _ _ "-c"], simp) 
paulson@14293
  1338
apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric]) 
paulson@14293
  1339
done
paulson@14293
  1340
paulson@14293
  1341
paulson@14293
  1342
subsection {* Ordered Fields are Dense *}
paulson@14293
  1343
paulson@14293
  1344
lemma zero_less_two: "0 < (1+1::'a::ordered_field)"
paulson@14293
  1345
proof -
paulson@14293
  1346
  have "0 + 0 <  (1+1::'a::ordered_field)"
paulson@14293
  1347
    by (blast intro: zero_less_one add_strict_mono) 
paulson@14293
  1348
  thus ?thesis by simp
paulson@14293
  1349
qed
paulson@14293
  1350
paulson@14293
  1351
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::ordered_field)"
paulson@14293
  1352
by (simp add: zero_less_two pos_less_divide_eq right_distrib) 
paulson@14293
  1353
paulson@14293
  1354
lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::ordered_field) < b"
paulson@14293
  1355
by (simp add: zero_less_two pos_divide_less_eq right_distrib) 
paulson@14293
  1356
paulson@14293
  1357
lemma dense: "a < b ==> \<exists>r::'a::ordered_field. a < r & r < b"
paulson@14293
  1358
by (blast intro!: less_half_sum gt_half_sum)
paulson@14293
  1359
paulson@14293
  1360
paulson@14293
  1361
subsection {* Absolute Value *}
paulson@14293
  1362
paulson@14293
  1363
text{*But is it really better than just rewriting with @{text abs_if}?*}
paulson@14293
  1364
lemma abs_split:
paulson@14293
  1365
     "P(abs(a::'a::ordered_ring)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
paulson@14293
  1366
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
paulson@14293
  1367
paulson@14293
  1368
lemma abs_zero [simp]: "abs 0 = (0::'a::ordered_ring)"
paulson@14293
  1369
by (simp add: abs_if)
paulson@14293
  1370
paulson@14293
  1371
lemma abs_mult: "abs (x * y) = abs x * abs (y::'a::ordered_ring)" 
paulson@14293
  1372
apply (case_tac "x=0 | y=0", force) 
paulson@14293
  1373
apply (auto elim: order_less_asym
paulson@14293
  1374
            simp add: abs_if mult_less_0_iff linorder_neq_iff
paulson@14293
  1375
                  minus_mult_left [symmetric] minus_mult_right [symmetric])  
paulson@14293
  1376
done
paulson@14293
  1377
paulson@14293
  1378
lemma abs_eq_0 [simp]: "(abs x = 0) = (x = (0::'a::ordered_ring))"
paulson@14293
  1379
by (simp add: abs_if)
paulson@14293
  1380
paulson@14293
  1381
lemma zero_less_abs_iff [simp]: "(0 < abs x) = (x ~= (0::'a::ordered_ring))"
paulson@14293
  1382
by (simp add: abs_if linorder_neq_iff)
paulson@14293
  1383
paulson@14293
  1384
paulson@14265
  1385
end