src/HOL/Ring_and_Field.thy
author paulson
Wed Dec 10 15:59:34 2003 +0100 (2003-12-10)
changeset 14288 d149e3cbdb39
parent 14284 f1abe67c448a
child 14293 22542982bffd
permissions -rw-r--r--
Moving some theorems from Real/RealArith0.ML
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 {* Absolute Value *}
paulson@14265
   644
paulson@14265
   645
text{*But is it really better than just rewriting with @{text abs_if}?*}
paulson@14265
   646
lemma abs_split:
paulson@14265
   647
     "P(abs(a::'a::ordered_ring)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
paulson@14265
   648
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
paulson@14265
   649
paulson@14265
   650
lemma abs_zero [simp]: "abs 0 = (0::'a::ordered_ring)"
paulson@14265
   651
by (simp add: abs_if)
paulson@14265
   652
paulson@14265
   653
lemma abs_mult: "abs (x * y) = abs x * abs (y::'a::ordered_ring)" 
paulson@14265
   654
apply (case_tac "x=0 | y=0", force) 
paulson@14265
   655
apply (auto elim: order_less_asym
paulson@14265
   656
            simp add: abs_if mult_less_0_iff linorder_neq_iff
paulson@14265
   657
                  minus_mult_left [symmetric] minus_mult_right [symmetric])  
paulson@14265
   658
done
paulson@14265
   659
paulson@14266
   660
lemma abs_eq_0 [simp]: "(abs x = 0) = (x = (0::'a::ordered_ring))"
paulson@14265
   661
by (simp add: abs_if)
paulson@14265
   662
paulson@14266
   663
lemma zero_less_abs_iff [simp]: "(0 < abs x) = (x ~= (0::'a::ordered_ring))"
paulson@14265
   664
by (simp add: abs_if linorder_neq_iff)
paulson@14265
   665
paulson@14265
   666
paulson@14265
   667
subsection {* Fields *}
paulson@14265
   668
paulson@14288
   669
lemma right_inverse [simp]:
paulson@14288
   670
      assumes not0: "a \<noteq> 0" shows "a * inverse (a::'a::field) = 1"
paulson@14288
   671
proof -
paulson@14288
   672
  have "a * inverse a = inverse a * a" by (simp add: mult_ac)
paulson@14288
   673
  also have "... = 1" using not0 by simp
paulson@14288
   674
  finally show ?thesis .
paulson@14288
   675
qed
paulson@14288
   676
paulson@14288
   677
lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
paulson@14288
   678
proof
paulson@14288
   679
  assume neq: "b \<noteq> 0"
paulson@14288
   680
  {
paulson@14288
   681
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
paulson@14288
   682
    also assume "a / b = 1"
paulson@14288
   683
    finally show "a = b" by simp
paulson@14288
   684
  next
paulson@14288
   685
    assume "a = b"
paulson@14288
   686
    with neq show "a / b = 1" by (simp add: divide_inverse)
paulson@14288
   687
  }
paulson@14288
   688
qed
paulson@14288
   689
paulson@14288
   690
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 ==> inverse (a::'a::field) = 1/a"
paulson@14288
   691
by (simp add: divide_inverse)
paulson@14288
   692
paulson@14288
   693
lemma divide_self [simp]: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
paulson@14288
   694
  by (simp add: divide_inverse)
paulson@14288
   695
paulson@14277
   696
lemma divide_inverse_zero: "a/b = a * inverse(b::'a::{field,division_by_zero})"
paulson@14277
   697
apply (case_tac "b = 0")
paulson@14277
   698
apply (simp_all add: divide_inverse)
paulson@14277
   699
done
paulson@14277
   700
paulson@14277
   701
lemma divide_zero_left [simp]: "0/a = (0::'a::{field,division_by_zero})"
paulson@14277
   702
by (simp add: divide_inverse_zero)
paulson@14277
   703
paulson@14277
   704
lemma inverse_eq_divide: "inverse (a::'a::{field,division_by_zero}) = 1/a"
paulson@14277
   705
by (simp add: divide_inverse_zero)
paulson@14277
   706
paulson@14270
   707
text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
paulson@14270
   708
      of an ordering.*}
paulson@14270
   709
lemma field_mult_eq_0_iff: "(a*b = (0::'a::field)) = (a = 0 | b = 0)"
paulson@14270
   710
  proof cases
paulson@14270
   711
    assume "a=0" thus ?thesis by simp
paulson@14270
   712
  next
paulson@14270
   713
    assume anz [simp]: "a\<noteq>0"
paulson@14270
   714
    thus ?thesis
paulson@14270
   715
    proof auto
paulson@14270
   716
      assume "a * b = 0"
paulson@14270
   717
      hence "inverse a * (a * b) = 0" by simp
paulson@14270
   718
      thus "b = 0"  by (simp (no_asm_use) add: mult_assoc [symmetric])
paulson@14270
   719
    qed
paulson@14270
   720
  qed
paulson@14270
   721
paulson@14268
   722
text{*Cancellation of equalities with a common factor*}
paulson@14268
   723
lemma field_mult_cancel_right_lemma:
paulson@14269
   724
      assumes cnz: "c \<noteq> (0::'a::field)"
paulson@14269
   725
	  and eq:  "a*c = b*c"
paulson@14269
   726
	 shows "a=b"
paulson@14268
   727
  proof -
paulson@14268
   728
  have "(a * c) * inverse c = (b * c) * inverse c"
paulson@14268
   729
    by (simp add: eq)
paulson@14268
   730
  thus "a=b"
paulson@14268
   731
    by (simp add: mult_assoc cnz)
paulson@14268
   732
  qed
paulson@14268
   733
paulson@14268
   734
lemma field_mult_cancel_right:
paulson@14268
   735
     "(a*c = b*c) = (c = (0::'a::field) | a=b)"
paulson@14269
   736
  proof cases
paulson@14268
   737
    assume "c=0" thus ?thesis by simp
paulson@14268
   738
  next
paulson@14268
   739
    assume "c\<noteq>0" 
paulson@14268
   740
    thus ?thesis by (force dest: field_mult_cancel_right_lemma)
paulson@14268
   741
  qed
paulson@14268
   742
paulson@14268
   743
lemma field_mult_cancel_left:
paulson@14268
   744
     "(c*a = c*b) = (c = (0::'a::field) | a=b)"
paulson@14268
   745
  by (simp add: mult_commute [of c] field_mult_cancel_right) 
paulson@14268
   746
paulson@14268
   747
lemma nonzero_imp_inverse_nonzero: "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::field)"
paulson@14268
   748
  proof
paulson@14268
   749
  assume ianz: "inverse a = 0"
paulson@14268
   750
  assume "a \<noteq> 0"
paulson@14268
   751
  hence "1 = a * inverse a" by simp
paulson@14268
   752
  also have "... = 0" by (simp add: ianz)
paulson@14268
   753
  finally have "1 = (0::'a::field)" .
paulson@14268
   754
  thus False by (simp add: eq_commute)
paulson@14268
   755
  qed
paulson@14268
   756
paulson@14277
   757
paulson@14277
   758
subsection{*Basic Properties of @{term inverse}*}
paulson@14277
   759
paulson@14268
   760
lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   761
apply (rule ccontr) 
paulson@14268
   762
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   763
done
paulson@14268
   764
paulson@14268
   765
lemma inverse_nonzero_imp_nonzero:
paulson@14268
   766
   "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   767
apply (rule ccontr) 
paulson@14268
   768
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   769
done
paulson@14268
   770
paulson@14268
   771
lemma inverse_nonzero_iff_nonzero [simp]:
paulson@14268
   772
   "(inverse a = 0) = (a = (0::'a::{field,division_by_zero}))"
paulson@14268
   773
by (force dest: inverse_nonzero_imp_nonzero) 
paulson@14268
   774
paulson@14268
   775
lemma nonzero_inverse_minus_eq:
paulson@14269
   776
      assumes [simp]: "a\<noteq>0"  shows "inverse(-a) = -inverse(a::'a::field)"
paulson@14268
   777
  proof -
paulson@14269
   778
    have "-a * inverse (- a) = -a * - inverse a"
paulson@14268
   779
      by simp
paulson@14268
   780
    thus ?thesis 
paulson@14269
   781
      by (simp only: field_mult_cancel_left, simp)
paulson@14268
   782
  qed
paulson@14268
   783
paulson@14268
   784
lemma inverse_minus_eq [simp]:
paulson@14268
   785
     "inverse(-a) = -inverse(a::'a::{field,division_by_zero})";
paulson@14269
   786
  proof cases
paulson@14268
   787
    assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14268
   788
  next
paulson@14268
   789
    assume "a\<noteq>0" 
paulson@14268
   790
    thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14268
   791
  qed
paulson@14268
   792
paulson@14268
   793
lemma nonzero_inverse_eq_imp_eq:
paulson@14269
   794
      assumes inveq: "inverse a = inverse b"
paulson@14269
   795
	  and anz:  "a \<noteq> 0"
paulson@14269
   796
	  and bnz:  "b \<noteq> 0"
paulson@14269
   797
	 shows "a = (b::'a::field)"
paulson@14268
   798
  proof -
paulson@14268
   799
  have "a * inverse b = a * inverse a"
paulson@14268
   800
    by (simp add: inveq)
paulson@14268
   801
  hence "(a * inverse b) * b = (a * inverse a) * b"
paulson@14268
   802
    by simp
paulson@14268
   803
  thus "a = b"
paulson@14268
   804
    by (simp add: mult_assoc anz bnz)
paulson@14268
   805
  qed
paulson@14268
   806
paulson@14268
   807
lemma inverse_eq_imp_eq:
paulson@14268
   808
     "inverse a = inverse b ==> a = (b::'a::{field,division_by_zero})"
paulson@14268
   809
apply (case_tac "a=0 | b=0") 
paulson@14268
   810
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
   811
              simp add: eq_commute [of "0::'a"])
paulson@14268
   812
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
   813
done
paulson@14268
   814
paulson@14268
   815
lemma inverse_eq_iff_eq [simp]:
paulson@14268
   816
     "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))"
paulson@14268
   817
by (force dest!: inverse_eq_imp_eq) 
paulson@14268
   818
paulson@14270
   819
lemma nonzero_inverse_inverse_eq:
paulson@14270
   820
      assumes [simp]: "a \<noteq> 0"  shows "inverse(inverse (a::'a::field)) = a"
paulson@14270
   821
  proof -
paulson@14270
   822
  have "(inverse (inverse a) * inverse a) * a = a" 
paulson@14270
   823
    by (simp add: nonzero_imp_inverse_nonzero)
paulson@14270
   824
  thus ?thesis
paulson@14270
   825
    by (simp add: mult_assoc)
paulson@14270
   826
  qed
paulson@14270
   827
paulson@14270
   828
lemma inverse_inverse_eq [simp]:
paulson@14270
   829
     "inverse(inverse (a::'a::{field,division_by_zero})) = a"
paulson@14270
   830
  proof cases
paulson@14270
   831
    assume "a=0" thus ?thesis by simp
paulson@14270
   832
  next
paulson@14270
   833
    assume "a\<noteq>0" 
paulson@14270
   834
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
   835
  qed
paulson@14270
   836
paulson@14270
   837
lemma inverse_1 [simp]: "inverse 1 = (1::'a::field)"
paulson@14270
   838
  proof -
paulson@14270
   839
  have "inverse 1 * 1 = (1::'a::field)" 
paulson@14270
   840
    by (rule left_inverse [OF zero_neq_one [symmetric]])
paulson@14270
   841
  thus ?thesis  by simp
paulson@14270
   842
  qed
paulson@14270
   843
paulson@14270
   844
lemma nonzero_inverse_mult_distrib: 
paulson@14270
   845
      assumes anz: "a \<noteq> 0"
paulson@14270
   846
          and bnz: "b \<noteq> 0"
paulson@14270
   847
      shows "inverse(a*b) = inverse(b) * inverse(a::'a::field)"
paulson@14270
   848
  proof -
paulson@14270
   849
  have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
paulson@14270
   850
    by (simp add: field_mult_eq_0_iff anz bnz)
paulson@14270
   851
  hence "inverse(a*b) * a = inverse(b)" 
paulson@14270
   852
    by (simp add: mult_assoc bnz)
paulson@14270
   853
  hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
paulson@14270
   854
    by simp
paulson@14270
   855
  thus ?thesis
paulson@14270
   856
    by (simp add: mult_assoc anz)
paulson@14270
   857
  qed
paulson@14270
   858
paulson@14270
   859
text{*This version builds in division by zero while also re-orienting
paulson@14270
   860
      the right-hand side.*}
paulson@14270
   861
lemma inverse_mult_distrib [simp]:
paulson@14270
   862
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
   863
  proof cases
paulson@14270
   864
    assume "a \<noteq> 0 & b \<noteq> 0" 
paulson@14270
   865
    thus ?thesis  by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
   866
  next
paulson@14270
   867
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
paulson@14270
   868
    thus ?thesis  by force
paulson@14270
   869
  qed
paulson@14270
   870
paulson@14270
   871
text{*There is no slick version using division by zero.*}
paulson@14270
   872
lemma inverse_add:
paulson@14270
   873
     "[|a \<noteq> 0;  b \<noteq> 0|]
paulson@14270
   874
      ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
paulson@14270
   875
apply (simp add: left_distrib mult_assoc)
paulson@14270
   876
apply (simp add: mult_commute [of "inverse a"]) 
paulson@14270
   877
apply (simp add: mult_assoc [symmetric] add_commute)
paulson@14270
   878
done
paulson@14270
   879
paulson@14277
   880
lemma nonzero_mult_divide_cancel_left:
paulson@14277
   881
  assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" 
paulson@14277
   882
    shows "(c*a)/(c*b) = a/(b::'a::field)"
paulson@14277
   883
proof -
paulson@14277
   884
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
paulson@14277
   885
    by (simp add: field_mult_eq_0_iff divide_inverse 
paulson@14277
   886
                  nonzero_inverse_mult_distrib)
paulson@14277
   887
  also have "... =  a * inverse b * (inverse c * c)"
paulson@14277
   888
    by (simp only: mult_ac)
paulson@14277
   889
  also have "... =  a * inverse b"
paulson@14277
   890
    by simp
paulson@14277
   891
    finally show ?thesis 
paulson@14277
   892
    by (simp add: divide_inverse)
paulson@14277
   893
qed
paulson@14277
   894
paulson@14277
   895
lemma mult_divide_cancel_left:
paulson@14277
   896
     "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
paulson@14277
   897
apply (case_tac "b = 0")
paulson@14277
   898
apply (simp_all add: nonzero_mult_divide_cancel_left)
paulson@14277
   899
done
paulson@14277
   900
paulson@14277
   901
(*For ExtractCommonTerm*)
paulson@14277
   902
lemma mult_divide_cancel_eq_if:
paulson@14277
   903
     "(c*a) / (c*b) = 
paulson@14277
   904
      (if c=0 then 0 else a / (b::'a::{field,division_by_zero}))"
paulson@14277
   905
  by (simp add: mult_divide_cancel_left)
paulson@14277
   906
paulson@14284
   907
lemma divide_1 [simp]: "a/1 = (a::'a::field)"
paulson@14284
   908
  by (simp add: divide_inverse [OF not_sym])
paulson@14284
   909
paulson@14288
   910
lemma times_divide_eq_right [simp]:
paulson@14288
   911
     "a * (b/c) = (a*b) / (c::'a::{field,division_by_zero})"
paulson@14288
   912
by (simp add: divide_inverse_zero mult_assoc)
paulson@14288
   913
paulson@14288
   914
lemma times_divide_eq_left [simp]:
paulson@14288
   915
     "(b/c) * a = (b*a) / (c::'a::{field,division_by_zero})"
paulson@14288
   916
by (simp add: divide_inverse_zero mult_ac)
paulson@14288
   917
paulson@14288
   918
lemma divide_divide_eq_right [simp]:
paulson@14288
   919
     "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
paulson@14288
   920
by (simp add: divide_inverse_zero mult_ac)
paulson@14288
   921
paulson@14288
   922
lemma divide_divide_eq_left [simp]:
paulson@14288
   923
     "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
paulson@14288
   924
by (simp add: divide_inverse_zero mult_assoc)
paulson@14288
   925
paulson@14268
   926
paulson@14268
   927
subsection {* Ordered Fields *}
paulson@14268
   928
paulson@14277
   929
lemma positive_imp_inverse_positive: 
paulson@14269
   930
      assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
paulson@14268
   931
  proof -
paulson@14268
   932
  have "0 < a * inverse a" 
paulson@14268
   933
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
   934
  thus "0 < inverse a" 
paulson@14268
   935
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
paulson@14268
   936
  qed
paulson@14268
   937
paulson@14277
   938
lemma negative_imp_inverse_negative:
paulson@14268
   939
     "a < 0 ==> inverse a < (0::'a::ordered_field)"
paulson@14277
   940
  by (insert positive_imp_inverse_positive [of "-a"], 
paulson@14268
   941
      simp add: nonzero_inverse_minus_eq order_less_imp_not_eq) 
paulson@14268
   942
paulson@14268
   943
lemma inverse_le_imp_le:
paulson@14269
   944
      assumes invle: "inverse a \<le> inverse b"
paulson@14269
   945
	  and apos:  "0 < a"
paulson@14269
   946
	 shows "b \<le> (a::'a::ordered_field)"
paulson@14268
   947
  proof (rule classical)
paulson@14268
   948
  assume "~ b \<le> a"
paulson@14268
   949
  hence "a < b"
paulson@14268
   950
    by (simp add: linorder_not_le)
paulson@14268
   951
  hence bpos: "0 < b"
paulson@14268
   952
    by (blast intro: apos order_less_trans)
paulson@14268
   953
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
   954
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
   955
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
   956
    by (simp add: bpos order_less_imp_le mult_right_mono)
paulson@14268
   957
  thus "b \<le> a"
paulson@14268
   958
    by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
paulson@14268
   959
  qed
paulson@14268
   960
paulson@14277
   961
lemma inverse_positive_imp_positive:
paulson@14277
   962
      assumes inv_gt_0: "0 < inverse a"
paulson@14277
   963
          and [simp]:   "a \<noteq> 0"
paulson@14277
   964
        shows "0 < (a::'a::ordered_field)"
paulson@14277
   965
  proof -
paulson@14277
   966
  have "0 < inverse (inverse a)"
paulson@14277
   967
    by (rule positive_imp_inverse_positive)
paulson@14277
   968
  thus "0 < a"
paulson@14277
   969
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
   970
  qed
paulson@14277
   971
paulson@14277
   972
lemma inverse_positive_iff_positive [simp]:
paulson@14277
   973
      "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
   974
apply (case_tac "a = 0", simp)
paulson@14277
   975
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
   976
done
paulson@14277
   977
paulson@14277
   978
lemma inverse_negative_imp_negative:
paulson@14277
   979
      assumes inv_less_0: "inverse a < 0"
paulson@14277
   980
          and [simp]:   "a \<noteq> 0"
paulson@14277
   981
        shows "a < (0::'a::ordered_field)"
paulson@14277
   982
  proof -
paulson@14277
   983
  have "inverse (inverse a) < 0"
paulson@14277
   984
    by (rule negative_imp_inverse_negative)
paulson@14277
   985
  thus "a < 0"
paulson@14277
   986
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
   987
  qed
paulson@14277
   988
paulson@14277
   989
lemma inverse_negative_iff_negative [simp]:
paulson@14277
   990
      "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
   991
apply (case_tac "a = 0", simp)
paulson@14277
   992
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
   993
done
paulson@14277
   994
paulson@14277
   995
lemma inverse_nonnegative_iff_nonnegative [simp]:
paulson@14277
   996
      "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
   997
by (simp add: linorder_not_less [symmetric])
paulson@14277
   998
paulson@14277
   999
lemma inverse_nonpositive_iff_nonpositive [simp]:
paulson@14277
  1000
      "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1001
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1002
paulson@14277
  1003
paulson@14277
  1004
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
  1005
paulson@14268
  1006
lemma less_imp_inverse_less:
paulson@14269
  1007
      assumes less: "a < b"
paulson@14269
  1008
	  and apos:  "0 < a"
paulson@14269
  1009
	shows "inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1010
  proof (rule ccontr)
paulson@14268
  1011
  assume "~ inverse b < inverse a"
paulson@14268
  1012
  hence "inverse a \<le> inverse b"
paulson@14268
  1013
    by (simp add: linorder_not_less)
paulson@14268
  1014
  hence "~ (a < b)"
paulson@14268
  1015
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
paulson@14268
  1016
  thus False
paulson@14268
  1017
    by (rule notE [OF _ less])
paulson@14268
  1018
  qed
paulson@14268
  1019
paulson@14268
  1020
lemma inverse_less_imp_less:
paulson@14268
  1021
   "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1022
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
  1023
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
  1024
done
paulson@14268
  1025
paulson@14268
  1026
text{*Both premises are essential. Consider -1 and 1.*}
paulson@14268
  1027
lemma inverse_less_iff_less [simp]:
paulson@14268
  1028
     "[|0 < a; 0 < b|] 
paulson@14268
  1029
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1030
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
  1031
paulson@14268
  1032
lemma le_imp_inverse_le:
paulson@14268
  1033
   "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1034
  by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
  1035
paulson@14268
  1036
lemma inverse_le_iff_le [simp]:
paulson@14268
  1037
     "[|0 < a; 0 < b|] 
paulson@14268
  1038
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1039
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
  1040
paulson@14268
  1041
paulson@14268
  1042
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
  1043
case is trivial, since inverse preserves signs.*}
paulson@14268
  1044
lemma inverse_le_imp_le_neg:
paulson@14268
  1045
   "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
paulson@14268
  1046
  apply (rule classical) 
paulson@14268
  1047
  apply (subgoal_tac "a < 0") 
paulson@14268
  1048
   prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
paulson@14268
  1049
  apply (insert inverse_le_imp_le [of "-b" "-a"])
paulson@14268
  1050
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1051
  done
paulson@14268
  1052
paulson@14268
  1053
lemma less_imp_inverse_less_neg:
paulson@14268
  1054
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1055
  apply (subgoal_tac "a < 0") 
paulson@14268
  1056
   prefer 2 apply (blast intro: order_less_trans) 
paulson@14268
  1057
  apply (insert less_imp_inverse_less [of "-b" "-a"])
paulson@14268
  1058
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1059
  done
paulson@14268
  1060
paulson@14268
  1061
lemma inverse_less_imp_less_neg:
paulson@14268
  1062
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1063
  apply (rule classical) 
paulson@14268
  1064
  apply (subgoal_tac "a < 0") 
paulson@14268
  1065
   prefer 2
paulson@14268
  1066
   apply (force simp add: linorder_not_less intro: order_le_less_trans) 
paulson@14268
  1067
  apply (insert inverse_less_imp_less [of "-b" "-a"])
paulson@14268
  1068
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1069
  done
paulson@14268
  1070
paulson@14268
  1071
lemma inverse_less_iff_less_neg [simp]:
paulson@14268
  1072
     "[|a < 0; b < 0|] 
paulson@14268
  1073
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1074
  apply (insert inverse_less_iff_less [of "-b" "-a"])
paulson@14268
  1075
  apply (simp del: inverse_less_iff_less 
paulson@14268
  1076
	      add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1077
  done
paulson@14268
  1078
paulson@14268
  1079
lemma le_imp_inverse_le_neg:
paulson@14268
  1080
   "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1081
  by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
  1082
paulson@14268
  1083
lemma inverse_le_iff_le_neg [simp]:
paulson@14268
  1084
     "[|a < 0; b < 0|] 
paulson@14268
  1085
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1086
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
  1087
paulson@14277
  1088
paulson@14277
  1089
subsection{*Division and Signs*}
paulson@14277
  1090
paulson@14277
  1091
lemma zero_less_divide_iff:
paulson@14277
  1092
     "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14277
  1093
by (simp add: divide_inverse_zero zero_less_mult_iff)
paulson@14277
  1094
paulson@14277
  1095
lemma divide_less_0_iff:
paulson@14277
  1096
     "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
paulson@14277
  1097
      (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14277
  1098
by (simp add: divide_inverse_zero mult_less_0_iff)
paulson@14277
  1099
paulson@14277
  1100
lemma zero_le_divide_iff:
paulson@14277
  1101
     "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
paulson@14277
  1102
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14277
  1103
by (simp add: divide_inverse_zero zero_le_mult_iff)
paulson@14277
  1104
paulson@14277
  1105
lemma divide_le_0_iff:
paulson@14288
  1106
     "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) =
paulson@14288
  1107
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14277
  1108
by (simp add: divide_inverse_zero mult_le_0_iff)
paulson@14277
  1109
paulson@14277
  1110
lemma divide_eq_0_iff [simp]:
paulson@14277
  1111
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
paulson@14277
  1112
by (simp add: divide_inverse_zero field_mult_eq_0_iff)
paulson@14277
  1113
paulson@14288
  1114
paulson@14288
  1115
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
  1116
paulson@14288
  1117
lemma pos_le_divide_eq: "0 < (c::'a::ordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
  1118
proof -
paulson@14288
  1119
  assume less: "0<c"
paulson@14288
  1120
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
  1121
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1122
  also have "... = (a*c \<le> b)"
paulson@14288
  1123
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1124
  finally show ?thesis .
paulson@14288
  1125
qed
paulson@14288
  1126
paulson@14288
  1127
paulson@14288
  1128
lemma neg_le_divide_eq: "c < (0::'a::ordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
  1129
proof -
paulson@14288
  1130
  assume less: "c<0"
paulson@14288
  1131
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
  1132
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1133
  also have "... = (b \<le> a*c)"
paulson@14288
  1134
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1135
  finally show ?thesis .
paulson@14288
  1136
qed
paulson@14288
  1137
paulson@14288
  1138
lemma le_divide_eq:
paulson@14288
  1139
  "(a \<le> b/c) = 
paulson@14288
  1140
   (if 0 < c then a*c \<le> b
paulson@14288
  1141
             else if c < 0 then b \<le> a*c
paulson@14288
  1142
             else  a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1143
apply (case_tac "c=0", simp) 
paulson@14288
  1144
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
  1145
done
paulson@14288
  1146
paulson@14288
  1147
lemma pos_divide_le_eq: "0 < (c::'a::ordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
  1148
proof -
paulson@14288
  1149
  assume less: "0<c"
paulson@14288
  1150
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
  1151
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1152
  also have "... = (b \<le> a*c)"
paulson@14288
  1153
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1154
  finally show ?thesis .
paulson@14288
  1155
qed
paulson@14288
  1156
paulson@14288
  1157
lemma neg_divide_le_eq: "c < (0::'a::ordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
  1158
proof -
paulson@14288
  1159
  assume less: "c<0"
paulson@14288
  1160
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
  1161
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1162
  also have "... = (a*c \<le> b)"
paulson@14288
  1163
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1164
  finally show ?thesis .
paulson@14288
  1165
qed
paulson@14288
  1166
paulson@14288
  1167
lemma divide_le_eq:
paulson@14288
  1168
  "(b/c \<le> a) = 
paulson@14288
  1169
   (if 0 < c then b \<le> a*c
paulson@14288
  1170
             else if c < 0 then a*c \<le> b
paulson@14288
  1171
             else 0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1172
apply (case_tac "c=0", simp) 
paulson@14288
  1173
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
  1174
done
paulson@14288
  1175
paulson@14288
  1176
paulson@14288
  1177
lemma pos_less_divide_eq:
paulson@14288
  1178
     "0 < (c::'a::ordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
  1179
proof -
paulson@14288
  1180
  assume less: "0<c"
paulson@14288
  1181
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@14288
  1182
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1183
  also have "... = (a*c < b)"
paulson@14288
  1184
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1185
  finally show ?thesis .
paulson@14288
  1186
qed
paulson@14288
  1187
paulson@14288
  1188
lemma neg_less_divide_eq:
paulson@14288
  1189
 "c < (0::'a::ordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
  1190
proof -
paulson@14288
  1191
  assume less: "c<0"
paulson@14288
  1192
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@14288
  1193
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1194
  also have "... = (b < a*c)"
paulson@14288
  1195
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1196
  finally show ?thesis .
paulson@14288
  1197
qed
paulson@14288
  1198
paulson@14288
  1199
lemma less_divide_eq:
paulson@14288
  1200
  "(a < b/c) = 
paulson@14288
  1201
   (if 0 < c then a*c < b
paulson@14288
  1202
             else if c < 0 then b < a*c
paulson@14288
  1203
             else  a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1204
apply (case_tac "c=0", simp) 
paulson@14288
  1205
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
  1206
done
paulson@14288
  1207
paulson@14288
  1208
lemma pos_divide_less_eq:
paulson@14288
  1209
     "0 < (c::'a::ordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
  1210
proof -
paulson@14288
  1211
  assume less: "0<c"
paulson@14288
  1212
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@14288
  1213
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1214
  also have "... = (b < a*c)"
paulson@14288
  1215
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1216
  finally show ?thesis .
paulson@14288
  1217
qed
paulson@14288
  1218
paulson@14288
  1219
lemma neg_divide_less_eq:
paulson@14288
  1220
 "c < (0::'a::ordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
  1221
proof -
paulson@14288
  1222
  assume less: "c<0"
paulson@14288
  1223
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@14288
  1224
    by (simp add: mult_less_cancel_right order_less_not_sym [OF less])
paulson@14288
  1225
  also have "... = (a*c < b)"
paulson@14288
  1226
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1227
  finally show ?thesis .
paulson@14288
  1228
qed
paulson@14288
  1229
paulson@14288
  1230
lemma divide_less_eq:
paulson@14288
  1231
  "(b/c < a) = 
paulson@14288
  1232
   (if 0 < c then b < a*c
paulson@14288
  1233
             else if c < 0 then a*c < b
paulson@14288
  1234
             else 0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1235
apply (case_tac "c=0", simp) 
paulson@14288
  1236
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
  1237
done
paulson@14288
  1238
paulson@14288
  1239
lemma nonzero_eq_divide_eq: "c\<noteq>0 ==> ((a::'a::field) = b/c) = (a*c = b)"
paulson@14288
  1240
proof -
paulson@14288
  1241
  assume [simp]: "c\<noteq>0"
paulson@14288
  1242
  have "(a = b/c) = (a*c = (b/c)*c)"
paulson@14288
  1243
    by (simp add: field_mult_cancel_right)
paulson@14288
  1244
  also have "... = (a*c = b)"
paulson@14288
  1245
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1246
  finally show ?thesis .
paulson@14288
  1247
qed
paulson@14288
  1248
paulson@14288
  1249
lemma eq_divide_eq:
paulson@14288
  1250
  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
paulson@14288
  1251
by (simp add: nonzero_eq_divide_eq) 
paulson@14288
  1252
paulson@14288
  1253
lemma nonzero_divide_eq_eq: "c\<noteq>0 ==> (b/c = (a::'a::field)) = (b = a*c)"
paulson@14288
  1254
proof -
paulson@14288
  1255
  assume [simp]: "c\<noteq>0"
paulson@14288
  1256
  have "(b/c = a) = ((b/c)*c = a*c)"
paulson@14288
  1257
    by (simp add: field_mult_cancel_right)
paulson@14288
  1258
  also have "... = (b = a*c)"
paulson@14288
  1259
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1260
  finally show ?thesis .
paulson@14288
  1261
qed
paulson@14288
  1262
paulson@14288
  1263
lemma divide_eq_eq:
paulson@14288
  1264
  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
paulson@14288
  1265
by (force simp add: nonzero_divide_eq_eq) 
paulson@14288
  1266
paulson@14288
  1267
subsection{*Cancellation Laws for Division*}
paulson@14288
  1268
paulson@14288
  1269
lemma divide_cancel_right [simp]:
paulson@14288
  1270
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
paulson@14288
  1271
apply (case_tac "c=0", simp) 
paulson@14288
  1272
apply (simp add: divide_inverse_zero field_mult_cancel_right) 
paulson@14288
  1273
done
paulson@14288
  1274
paulson@14288
  1275
lemma divide_cancel_left [simp]:
paulson@14288
  1276
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
paulson@14288
  1277
apply (case_tac "c=0", simp) 
paulson@14288
  1278
apply (simp add: divide_inverse_zero field_mult_cancel_left) 
paulson@14288
  1279
done
paulson@14288
  1280
paulson@14288
  1281
paulson@14265
  1282
end