src/HOL/Ring_and_Field.thy
author paulson
Tue Dec 02 11:48:15 2003 +0100 (2003-12-02)
changeset 14270 342451d763f9
parent 14269 502a7c95de73
child 14272 5efbb548107d
permissions -rw-r--r--
More re-organising of numerical theorems
paulson@14265
     1
(*  Title:   HOL/Ring_and_Field.thy
paulson@14265
     2
    ID:      $Id$
paulson@14265
     3
    Author:  Gertrud Bauer and Markus Wenzel, TU Muenchen
paulson@14269
     4
             Lawrence C Paulson, University of Cambridge
paulson@14265
     5
    License: GPL (GNU GENERAL PUBLIC LICENSE)
paulson@14265
     6
*)
paulson@14265
     7
paulson@14265
     8
header {*
paulson@14265
     9
  \title{Ring and field structures}
paulson@14265
    10
  \author{Gertrud Bauer and Markus Wenzel}
paulson@14265
    11
*}
paulson@14265
    12
paulson@14265
    13
theory Ring_and_Field = Inductive:
paulson@14265
    14
paulson@14265
    15
text{*Lemmas and extension to semirings by L. C. Paulson*}
paulson@14265
    16
paulson@14265
    17
subsection {* Abstract algebraic structures *}
paulson@14265
    18
paulson@14265
    19
axclass semiring \<subseteq> zero, one, plus, times
paulson@14265
    20
  add_assoc: "(a + b) + c = a + (b + c)"
paulson@14265
    21
  add_commute: "a + b = b + a"
paulson@14265
    22
  left_zero [simp]: "0 + a = a"
paulson@14265
    23
paulson@14265
    24
  mult_assoc: "(a * b) * c = a * (b * c)"
paulson@14265
    25
  mult_commute: "a * b = b * a"
paulson@14267
    26
  mult_1 [simp]: "1 * a = a"
paulson@14265
    27
paulson@14265
    28
  left_distrib: "(a + b) * c = a * c + b * c"
paulson@14265
    29
  zero_neq_one [simp]: "0 \<noteq> 1"
paulson@14265
    30
paulson@14265
    31
axclass ring \<subseteq> semiring, minus
paulson@14265
    32
  left_minus [simp]: "- a + a = 0"
paulson@14265
    33
  diff_minus: "a - b = a + (-b)"
paulson@14265
    34
paulson@14265
    35
axclass ordered_semiring \<subseteq> semiring, linorder
paulson@14265
    36
  add_left_mono: "a \<le> b ==> c + a \<le> c + b"
paulson@14265
    37
  mult_strict_left_mono: "a < b ==> 0 < c ==> c * a < c * b"
paulson@14265
    38
paulson@14265
    39
axclass ordered_ring \<subseteq> ordered_semiring, ring
paulson@14265
    40
  abs_if: "\<bar>a\<bar> = (if a < 0 then -a else a)"
paulson@14265
    41
paulson@14265
    42
axclass field \<subseteq> ring, inverse
paulson@14265
    43
  left_inverse [simp]: "a \<noteq> 0 ==> inverse a * a = 1"
paulson@14265
    44
  divide_inverse:      "b \<noteq> 0 ==> a / b = a * inverse b"
paulson@14265
    45
paulson@14265
    46
axclass ordered_field \<subseteq> ordered_ring, field
paulson@14265
    47
paulson@14265
    48
axclass division_by_zero \<subseteq> zero, inverse
paulson@14268
    49
  inverse_zero [simp]: "inverse 0 = 0"
paulson@14268
    50
  divide_zero [simp]: "a / 0 = 0"
paulson@14265
    51
paulson@14265
    52
paulson@14270
    53
subsection {* Derived Rules for Addition *}
paulson@14265
    54
paulson@14265
    55
lemma right_zero [simp]: "a + 0 = (a::'a::semiring)"
paulson@14265
    56
proof -
paulson@14265
    57
  have "a + 0 = 0 + a" by (simp only: add_commute)
paulson@14265
    58
  also have "... = a" by simp
paulson@14265
    59
  finally show ?thesis .
paulson@14265
    60
qed
paulson@14265
    61
paulson@14265
    62
lemma add_left_commute: "a + (b + c) = b + (a + (c::'a::semiring))"
paulson@14265
    63
  by (rule mk_left_commute [of "op +", OF add_assoc add_commute])
paulson@14265
    64
paulson@14265
    65
theorems add_ac = add_assoc add_commute add_left_commute
paulson@14265
    66
paulson@14265
    67
lemma right_minus [simp]: "a + -(a::'a::ring) = 0"
paulson@14265
    68
proof -
paulson@14265
    69
  have "a + -a = -a + a" by (simp add: add_ac)
paulson@14265
    70
  also have "... = 0" by simp
paulson@14265
    71
  finally show ?thesis .
paulson@14265
    72
qed
paulson@14265
    73
paulson@14265
    74
lemma right_minus_eq: "(a - b = 0) = (a = (b::'a::ring))"
paulson@14265
    75
proof
paulson@14265
    76
  have "a = a - b + b" by (simp add: diff_minus add_ac)
paulson@14265
    77
  also assume "a - b = 0"
paulson@14265
    78
  finally show "a = b" by simp
paulson@14265
    79
next
paulson@14265
    80
  assume "a = b"
paulson@14265
    81
  thus "a - b = 0" by (simp add: diff_minus)
paulson@14265
    82
qed
paulson@14265
    83
paulson@14265
    84
lemma add_left_cancel [simp]:
paulson@14265
    85
     "(a + b = a + c) = (b = (c::'a::ring))"
paulson@14265
    86
proof
paulson@14265
    87
  assume eq: "a + b = a + c"
paulson@14268
    88
  hence "(-a + a) + b = (-a + a) + c"
paulson@14265
    89
    by (simp only: eq add_assoc)
paulson@14266
    90
  thus "b = c" by simp
paulson@14265
    91
next
paulson@14265
    92
  assume eq: "b = c"
paulson@14266
    93
  thus "a + b = a + c" by simp
paulson@14265
    94
qed
paulson@14265
    95
paulson@14265
    96
lemma add_right_cancel [simp]:
paulson@14265
    97
     "(b + a = c + a) = (b = (c::'a::ring))"
paulson@14265
    98
  by (simp add: add_commute)
paulson@14265
    99
paulson@14265
   100
lemma minus_minus [simp]: "- (- (a::'a::ring)) = a"
paulson@14265
   101
  proof (rule add_left_cancel [of "-a", THEN iffD1])
paulson@14265
   102
    show "(-a + -(-a) = -a + a)"
paulson@14265
   103
    by simp
paulson@14265
   104
  qed
paulson@14265
   105
paulson@14265
   106
lemma equals_zero_I: "a+b = 0 ==> -a = (b::'a::ring)"
paulson@14265
   107
apply (rule right_minus_eq [THEN iffD1, symmetric])
paulson@14265
   108
apply (simp add: diff_minus add_commute) 
paulson@14265
   109
done
paulson@14265
   110
paulson@14265
   111
lemma minus_zero [simp]: "- 0 = (0::'a::ring)"
paulson@14265
   112
by (simp add: equals_zero_I)
paulson@14265
   113
paulson@14270
   114
lemma diff_self [simp]: "a - (a::'a::ring) = 0"
paulson@14270
   115
  by (simp add: diff_minus)
paulson@14270
   116
paulson@14270
   117
lemma diff_0 [simp]: "(0::'a::ring) - a = -a"
paulson@14270
   118
by (simp add: diff_minus)
paulson@14270
   119
paulson@14270
   120
lemma diff_0_right [simp]: "a - (0::'a::ring) = a" 
paulson@14270
   121
by (simp add: diff_minus)
paulson@14270
   122
paulson@14265
   123
lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ring))" 
paulson@14265
   124
  proof 
paulson@14265
   125
    assume "- a = - b"
paulson@14268
   126
    hence "- (- a) = - (- b)"
paulson@14265
   127
      by simp
paulson@14266
   128
    thus "a=b" by simp
paulson@14265
   129
  next
paulson@14265
   130
    assume "a=b"
paulson@14266
   131
    thus "-a = -b" by simp
paulson@14265
   132
  qed
paulson@14265
   133
paulson@14265
   134
lemma neg_equal_0_iff_equal [simp]: "(-a = 0) = (a = (0::'a::ring))"
paulson@14265
   135
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   136
paulson@14265
   137
lemma neg_0_equal_iff_equal [simp]: "(0 = -a) = (0 = (a::'a::ring))"
paulson@14265
   138
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   139
paulson@14265
   140
paulson@14265
   141
subsection {* Derived rules for multiplication *}
paulson@14265
   142
paulson@14267
   143
lemma mult_1_right [simp]: "a * (1::'a::semiring) = a"
paulson@14265
   144
proof -
paulson@14267
   145
  have "a * 1 = 1 * a" by (simp add: mult_commute)
paulson@14267
   146
  also have "... = a" by simp
paulson@14265
   147
  finally show ?thesis .
paulson@14265
   148
qed
paulson@14265
   149
paulson@14265
   150
lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::semiring))"
paulson@14265
   151
  by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute])
paulson@14265
   152
paulson@14265
   153
theorems mult_ac = mult_assoc mult_commute mult_left_commute
paulson@14265
   154
paulson@14269
   155
lemma right_inverse [simp]:
paulson@14270
   156
      assumes not0: "a \<noteq> 0" shows "a * inverse (a::'a::field) = 1"
paulson@14265
   157
proof -
paulson@14265
   158
  have "a * inverse a = inverse a * a" by (simp add: mult_ac)
paulson@14269
   159
  also have "... = 1" using not0 by simp
paulson@14265
   160
  finally show ?thesis .
paulson@14265
   161
qed
paulson@14265
   162
paulson@14265
   163
lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
paulson@14265
   164
proof
paulson@14265
   165
  assume neq: "b \<noteq> 0"
paulson@14265
   166
  {
paulson@14265
   167
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
paulson@14265
   168
    also assume "a / b = 1"
paulson@14265
   169
    finally show "a = b" by simp
paulson@14265
   170
  next
paulson@14265
   171
    assume "a = b"
paulson@14265
   172
    with neq show "a / b = 1" by (simp add: divide_inverse)
paulson@14265
   173
  }
paulson@14265
   174
qed
paulson@14265
   175
paulson@14265
   176
lemma divide_self [simp]: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
paulson@14265
   177
  by (simp add: divide_inverse)
paulson@14265
   178
paulson@14265
   179
lemma mult_left_zero [simp]: "0 * a = (0::'a::ring)"
paulson@14265
   180
proof -
paulson@14265
   181
  have "0*a + 0*a = 0*a + 0"
paulson@14265
   182
    by (simp add: left_distrib [symmetric])
paulson@14266
   183
  thus ?thesis by (simp only: add_left_cancel)
paulson@14265
   184
qed
paulson@14265
   185
paulson@14265
   186
lemma mult_right_zero [simp]: "a * 0 = (0::'a::ring)"
paulson@14265
   187
  by (simp add: mult_commute)
paulson@14265
   188
paulson@14265
   189
paulson@14265
   190
subsection {* Distribution rules *}
paulson@14265
   191
paulson@14265
   192
lemma right_distrib: "a * (b + c) = a * b + a * (c::'a::semiring)"
paulson@14265
   193
proof -
paulson@14265
   194
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
paulson@14265
   195
  also have "... = b * a + c * a" by (simp only: left_distrib)
paulson@14265
   196
  also have "... = a * b + a * c" by (simp add: mult_ac)
paulson@14265
   197
  finally show ?thesis .
paulson@14265
   198
qed
paulson@14265
   199
paulson@14265
   200
theorems ring_distrib = right_distrib left_distrib
paulson@14265
   201
paulson@14265
   202
lemma minus_add_distrib [simp]: "- (a + b) = -a + -(b::'a::ring)"
paulson@14265
   203
apply (rule equals_zero_I)
paulson@14265
   204
apply (simp add: add_ac) 
paulson@14265
   205
done
paulson@14265
   206
paulson@14265
   207
lemma minus_mult_left: "- (a * b) = (-a) * (b::'a::ring)"
paulson@14265
   208
apply (rule equals_zero_I)
paulson@14265
   209
apply (simp add: left_distrib [symmetric]) 
paulson@14265
   210
done
paulson@14265
   211
paulson@14265
   212
lemma minus_mult_right: "- (a * b) = a * -(b::'a::ring)"
paulson@14265
   213
apply (rule equals_zero_I)
paulson@14265
   214
apply (simp add: right_distrib [symmetric]) 
paulson@14265
   215
done
paulson@14265
   216
paulson@14268
   217
lemma minus_mult_minus [simp]: "(- a) * (- b) = a * (b::'a::ring)"
paulson@14268
   218
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
paulson@14268
   219
paulson@14265
   220
lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)"
paulson@14265
   221
by (simp add: right_distrib diff_minus 
paulson@14265
   222
              minus_mult_left [symmetric] minus_mult_right [symmetric]) 
paulson@14265
   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@14270
   333
paulson@14270
   334
subsection{*Subtraction Laws*}
paulson@14270
   335
paulson@14270
   336
lemma add_diff_eq: "a + (b - c) = (a + b) - (c::'a::ring)"
paulson@14270
   337
by (simp add: diff_minus add_ac)
paulson@14270
   338
paulson@14270
   339
lemma diff_add_eq: "(a - b) + c = (a + c) - (b::'a::ring)"
paulson@14270
   340
by (simp add: diff_minus add_ac)
paulson@14270
   341
paulson@14270
   342
lemma diff_eq_eq: "(a-b = c) = (a = c + (b::'a::ring))"
paulson@14270
   343
by (auto simp add: diff_minus add_assoc)
paulson@14270
   344
paulson@14270
   345
lemma eq_diff_eq: "(a = c-b) = (a + (b::'a::ring) = c)"
paulson@14270
   346
by (auto simp add: diff_minus add_assoc)
paulson@14270
   347
paulson@14270
   348
lemma diff_diff_eq: "(a - b) - c = a - (b + (c::'a::ring))"
paulson@14270
   349
by (simp add: diff_minus add_ac)
paulson@14270
   350
paulson@14270
   351
lemma diff_diff_eq2: "a - (b - c) = (a + c) - (b::'a::ring)"
paulson@14270
   352
by (simp add: diff_minus add_ac)
paulson@14270
   353
paulson@14270
   354
text{*Further subtraction laws for ordered rings*}
paulson@14270
   355
paulson@14270
   356
lemma less_eq_diff: "(a < b) = (a - b < (0::'a::ordered_ring))"
paulson@14270
   357
proof -
paulson@14270
   358
  have  "(a < b) = (a + (- b) < b + (-b))"  
paulson@14270
   359
    by (simp only: add_less_cancel_right)
paulson@14270
   360
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
paulson@14270
   361
  finally show ?thesis .
paulson@14270
   362
qed
paulson@14270
   363
paulson@14270
   364
lemma diff_less_eq: "(a-b < c) = (a < c + (b::'a::ordered_ring))"
paulson@14270
   365
apply (subst less_eq_diff)
paulson@14270
   366
apply (rule less_eq_diff [of _ c, THEN ssubst])
paulson@14270
   367
apply (simp add: diff_minus add_ac)
paulson@14270
   368
done
paulson@14270
   369
paulson@14270
   370
lemma less_diff_eq: "(a < c-b) = (a + (b::'a::ordered_ring) < c)"
paulson@14270
   371
apply (subst less_eq_diff)
paulson@14270
   372
apply (rule less_eq_diff [of _ "c-b", THEN ssubst])
paulson@14270
   373
apply (simp add: diff_minus add_ac)
paulson@14270
   374
done
paulson@14270
   375
paulson@14270
   376
lemma diff_le_eq: "(a-b \<le> c) = (a \<le> c + (b::'a::ordered_ring))"
paulson@14270
   377
by (simp add: linorder_not_less [symmetric] less_diff_eq)
paulson@14270
   378
paulson@14270
   379
lemma le_diff_eq: "(a \<le> c-b) = (a + (b::'a::ordered_ring) \<le> c)"
paulson@14270
   380
by (simp add: linorder_not_less [symmetric] diff_less_eq)
paulson@14270
   381
paulson@14270
   382
text{*This list of rewrites simplifies (in)equalities by bringing subtractions
paulson@14270
   383
  to the top and then moving negative terms to the other side.
paulson@14270
   384
  Use with @{text add_ac}*}
paulson@14270
   385
lemmas compare_rls =
paulson@14270
   386
       diff_minus [symmetric]
paulson@14270
   387
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
paulson@14270
   388
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
paulson@14270
   389
       diff_eq_eq eq_diff_eq
paulson@14270
   390
paulson@14270
   391
paulson@14270
   392
subsection {* Ordering Rules for Multiplication *}
paulson@14270
   393
paulson@14265
   394
lemma mult_strict_right_mono:
paulson@14265
   395
     "[|a < b; 0 < c|] ==> a * c < b * (c::'a::ordered_semiring)"
paulson@14265
   396
by (simp add: mult_commute [of _ c] mult_strict_left_mono)
paulson@14265
   397
paulson@14265
   398
lemma mult_left_mono:
paulson@14267
   399
     "[|a \<le> b; 0 \<le> c|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14267
   400
  apply (case_tac "c=0", simp)
paulson@14267
   401
  apply (force simp add: mult_strict_left_mono order_le_less) 
paulson@14267
   402
  done
paulson@14265
   403
paulson@14265
   404
lemma mult_right_mono:
paulson@14267
   405
     "[|a \<le> b; 0 \<le> c|] ==> a*c \<le> b * (c::'a::ordered_ring)"
paulson@14267
   406
  by (simp add: mult_left_mono mult_commute [of _ c]) 
paulson@14265
   407
paulson@14265
   408
lemma mult_strict_left_mono_neg:
paulson@14265
   409
     "[|b < a; c < 0|] ==> c * a < c * (b::'a::ordered_ring)"
paulson@14265
   410
apply (drule mult_strict_left_mono [of _ _ "-c"])
paulson@14265
   411
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14265
   412
done
paulson@14265
   413
paulson@14265
   414
lemma mult_strict_right_mono_neg:
paulson@14265
   415
     "[|b < a; c < 0|] ==> a * c < b * (c::'a::ordered_ring)"
paulson@14265
   416
apply (drule mult_strict_right_mono [of _ _ "-c"])
paulson@14265
   417
apply (simp_all add: minus_mult_right [symmetric]) 
paulson@14265
   418
done
paulson@14265
   419
paulson@14265
   420
paulson@14265
   421
subsection{* Products of Signs *}
paulson@14265
   422
paulson@14265
   423
lemma mult_pos: "[| (0::'a::ordered_ring) < a; 0 < b |] ==> 0 < a*b"
paulson@14265
   424
by (drule mult_strict_left_mono [of 0 b], auto)
paulson@14265
   425
paulson@14265
   426
lemma mult_pos_neg: "[| (0::'a::ordered_ring) < a; b < 0 |] ==> a*b < 0"
paulson@14265
   427
by (drule mult_strict_left_mono [of b 0], auto)
paulson@14265
   428
paulson@14265
   429
lemma mult_neg: "[| a < (0::'a::ordered_ring); b < 0 |] ==> 0 < a*b"
paulson@14265
   430
by (drule mult_strict_right_mono_neg, auto)
paulson@14265
   431
paulson@14265
   432
lemma zero_less_mult_pos: "[| 0 < a*b; 0 < a|] ==> 0 < (b::'a::ordered_ring)"
paulson@14265
   433
apply (case_tac "b\<le>0") 
paulson@14265
   434
 apply (auto simp add: order_le_less linorder_not_less)
paulson@14265
   435
apply (drule_tac mult_pos_neg [of a b]) 
paulson@14265
   436
 apply (auto dest: order_less_not_sym)
paulson@14265
   437
done
paulson@14265
   438
paulson@14265
   439
lemma zero_less_mult_iff:
paulson@14265
   440
     "((0::'a::ordered_ring) < a*b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14265
   441
apply (auto simp add: order_le_less linorder_not_less mult_pos mult_neg)
paulson@14265
   442
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   443
apply (simp add: mult_commute [of a b]) 
paulson@14265
   444
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   445
done
paulson@14265
   446
paulson@14266
   447
lemma mult_eq_0_iff [simp]: "(a*b = (0::'a::ordered_ring)) = (a = 0 | b = 0)"
paulson@14265
   448
apply (case_tac "a < 0")
paulson@14265
   449
apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff)
paulson@14265
   450
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+
paulson@14265
   451
done
paulson@14265
   452
paulson@14265
   453
lemma zero_le_mult_iff:
paulson@14265
   454
     "((0::'a::ordered_ring) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14265
   455
by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less
paulson@14265
   456
                   zero_less_mult_iff)
paulson@14265
   457
paulson@14265
   458
lemma mult_less_0_iff:
paulson@14265
   459
     "(a*b < (0::'a::ordered_ring)) = (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14265
   460
apply (insert zero_less_mult_iff [of "-a" b]) 
paulson@14265
   461
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   462
done
paulson@14265
   463
paulson@14265
   464
lemma mult_le_0_iff:
paulson@14265
   465
     "(a*b \<le> (0::'a::ordered_ring)) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14265
   466
apply (insert zero_le_mult_iff [of "-a" b]) 
paulson@14265
   467
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   468
done
paulson@14265
   469
paulson@14265
   470
lemma zero_le_square: "(0::'a::ordered_ring) \<le> a*a"
paulson@14265
   471
by (simp add: zero_le_mult_iff linorder_linear) 
paulson@14265
   472
paulson@14265
   473
lemma zero_less_one: "(0::'a::ordered_ring) < 1"
paulson@14265
   474
apply (insert zero_le_square [of 1]) 
paulson@14265
   475
apply (simp add: order_less_le) 
paulson@14265
   476
done
paulson@14265
   477
paulson@14268
   478
lemma zero_le_one: "(0::'a::ordered_ring) \<le> 1"
paulson@14268
   479
  by (rule zero_less_one [THEN order_less_imp_le]) 
paulson@14268
   480
paulson@14268
   481
paulson@14268
   482
subsection{*More Monotonicity*}
paulson@14268
   483
paulson@14268
   484
lemma mult_left_mono_neg:
paulson@14268
   485
     "[|b \<le> a; c \<le> 0|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14268
   486
apply (drule mult_left_mono [of _ _ "-c"]) 
paulson@14268
   487
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14268
   488
done
paulson@14268
   489
paulson@14268
   490
lemma mult_right_mono_neg:
paulson@14268
   491
     "[|b \<le> a; c \<le> 0|] ==> a * c \<le> b * (c::'a::ordered_ring)"
paulson@14268
   492
  by (simp add: mult_left_mono_neg mult_commute [of _ c]) 
paulson@14268
   493
paulson@14268
   494
text{*Strict monotonicity in both arguments*}
paulson@14268
   495
lemma mult_strict_mono:
paulson@14268
   496
     "[|a<b; c<d; 0<b; 0\<le>c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   497
apply (case_tac "c=0")
paulson@14268
   498
 apply (simp add: mult_pos) 
paulson@14268
   499
apply (erule mult_strict_right_mono [THEN order_less_trans])
paulson@14268
   500
 apply (force simp add: order_le_less) 
paulson@14268
   501
apply (erule mult_strict_left_mono, assumption)
paulson@14268
   502
done
paulson@14268
   503
paulson@14268
   504
text{*This weaker variant has more natural premises*}
paulson@14268
   505
lemma mult_strict_mono':
paulson@14268
   506
     "[| a<b; c<d; 0 \<le> a; 0 \<le> c|] ==> a * c < b * (d::'a::ordered_ring)"
paulson@14268
   507
apply (rule mult_strict_mono)
paulson@14268
   508
apply (blast intro: order_le_less_trans)+
paulson@14268
   509
done
paulson@14268
   510
paulson@14268
   511
lemma mult_mono:
paulson@14268
   512
     "[|a \<le> b; c \<le> d; 0 \<le> b; 0 \<le> c|] 
paulson@14268
   513
      ==> a * c  \<le>  b * (d::'a::ordered_ring)"
paulson@14268
   514
apply (erule mult_right_mono [THEN order_trans], assumption)
paulson@14268
   515
apply (erule mult_left_mono, assumption)
paulson@14268
   516
done
paulson@14268
   517
paulson@14268
   518
paulson@14268
   519
subsection{*Cancellation Laws for Relationships With a Common Factor*}
paulson@14268
   520
paulson@14268
   521
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
paulson@14268
   522
   also with the relations @{text "\<le>"} and equality.*}
paulson@14268
   523
paulson@14268
   524
lemma mult_less_cancel_right:
paulson@14268
   525
    "(a*c < b*c) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   526
apply (case_tac "c = 0")
paulson@14268
   527
apply (auto simp add: linorder_neq_iff mult_strict_right_mono 
paulson@14268
   528
                      mult_strict_right_mono_neg)
paulson@14268
   529
apply (auto simp add: linorder_not_less 
paulson@14268
   530
                      linorder_not_le [symmetric, of "a*c"]
paulson@14268
   531
                      linorder_not_le [symmetric, of a])
paulson@14268
   532
apply (erule_tac [!] notE)
paulson@14268
   533
apply (auto simp add: order_less_imp_le mult_right_mono 
paulson@14268
   534
                      mult_right_mono_neg)
paulson@14268
   535
done
paulson@14268
   536
paulson@14268
   537
lemma mult_less_cancel_left:
paulson@14268
   538
    "(c*a < c*b) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring)))"
paulson@14268
   539
by (simp add: mult_commute [of c] mult_less_cancel_right)
paulson@14268
   540
paulson@14268
   541
lemma mult_le_cancel_right:
paulson@14268
   542
     "(a*c \<le> b*c) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   543
by (simp add: linorder_not_less [symmetric] mult_less_cancel_right)
paulson@14268
   544
paulson@14268
   545
lemma mult_le_cancel_left:
paulson@14268
   546
     "(c*a \<le> c*b) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring)))"
paulson@14268
   547
by (simp add: mult_commute [of c] mult_le_cancel_right)
paulson@14268
   548
paulson@14268
   549
lemma mult_less_imp_less_left:
paulson@14268
   550
    "[|c*a < c*b; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   551
  by (force elim: order_less_asym simp add: mult_less_cancel_left)
paulson@14268
   552
paulson@14268
   553
lemma mult_less_imp_less_right:
paulson@14268
   554
    "[|a*c < b*c; 0 < c|] ==> a < (b::'a::ordered_ring)"
paulson@14268
   555
  by (force elim: order_less_asym simp add: mult_less_cancel_right)
paulson@14268
   556
paulson@14268
   557
text{*Cancellation of equalities with a common factor*}
paulson@14268
   558
lemma mult_cancel_right [simp]:
paulson@14268
   559
     "(a*c = b*c) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   560
apply (cut_tac linorder_less_linear [of 0 c])
paulson@14268
   561
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono
paulson@14268
   562
             simp add: linorder_neq_iff)
paulson@14268
   563
done
paulson@14268
   564
paulson@14268
   565
text{*These cancellation theorems require an ordering. Versions are proved
paulson@14268
   566
      below that work for fields without an ordering.*}
paulson@14268
   567
lemma mult_cancel_left [simp]:
paulson@14268
   568
     "(c*a = c*b) = (c = (0::'a::ordered_ring) | a=b)"
paulson@14268
   569
by (simp add: mult_commute [of c] mult_cancel_right)
paulson@14268
   570
paulson@14265
   571
paulson@14265
   572
subsection {* Absolute Value *}
paulson@14265
   573
paulson@14265
   574
text{*But is it really better than just rewriting with @{text abs_if}?*}
paulson@14265
   575
lemma abs_split:
paulson@14265
   576
     "P(abs(a::'a::ordered_ring)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
paulson@14265
   577
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
paulson@14265
   578
paulson@14265
   579
lemma abs_zero [simp]: "abs 0 = (0::'a::ordered_ring)"
paulson@14265
   580
by (simp add: abs_if)
paulson@14265
   581
paulson@14265
   582
lemma abs_mult: "abs (x * y) = abs x * abs (y::'a::ordered_ring)" 
paulson@14265
   583
apply (case_tac "x=0 | y=0", force) 
paulson@14265
   584
apply (auto elim: order_less_asym
paulson@14265
   585
            simp add: abs_if mult_less_0_iff linorder_neq_iff
paulson@14265
   586
                  minus_mult_left [symmetric] minus_mult_right [symmetric])  
paulson@14265
   587
done
paulson@14265
   588
paulson@14266
   589
lemma abs_eq_0 [simp]: "(abs x = 0) = (x = (0::'a::ordered_ring))"
paulson@14265
   590
by (simp add: abs_if)
paulson@14265
   591
paulson@14266
   592
lemma zero_less_abs_iff [simp]: "(0 < abs x) = (x ~= (0::'a::ordered_ring))"
paulson@14265
   593
by (simp add: abs_if linorder_neq_iff)
paulson@14265
   594
paulson@14265
   595
paulson@14265
   596
subsection {* Fields *}
paulson@14265
   597
paulson@14270
   598
text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
paulson@14270
   599
      of an ordering.*}
paulson@14270
   600
lemma field_mult_eq_0_iff: "(a*b = (0::'a::field)) = (a = 0 | b = 0)"
paulson@14270
   601
  proof cases
paulson@14270
   602
    assume "a=0" thus ?thesis by simp
paulson@14270
   603
  next
paulson@14270
   604
    assume anz [simp]: "a\<noteq>0"
paulson@14270
   605
    thus ?thesis
paulson@14270
   606
    proof auto
paulson@14270
   607
      assume "a * b = 0"
paulson@14270
   608
      hence "inverse a * (a * b) = 0" by simp
paulson@14270
   609
      thus "b = 0"  by (simp (no_asm_use) add: mult_assoc [symmetric])
paulson@14270
   610
    qed
paulson@14270
   611
  qed
paulson@14270
   612
paulson@14268
   613
text{*Cancellation of equalities with a common factor*}
paulson@14268
   614
lemma field_mult_cancel_right_lemma:
paulson@14269
   615
      assumes cnz: "c \<noteq> (0::'a::field)"
paulson@14269
   616
	  and eq:  "a*c = b*c"
paulson@14269
   617
	 shows "a=b"
paulson@14268
   618
  proof -
paulson@14268
   619
  have "(a * c) * inverse c = (b * c) * inverse c"
paulson@14268
   620
    by (simp add: eq)
paulson@14268
   621
  thus "a=b"
paulson@14268
   622
    by (simp add: mult_assoc cnz)
paulson@14268
   623
  qed
paulson@14268
   624
paulson@14268
   625
lemma field_mult_cancel_right:
paulson@14268
   626
     "(a*c = b*c) = (c = (0::'a::field) | a=b)"
paulson@14269
   627
  proof cases
paulson@14268
   628
    assume "c=0" thus ?thesis by simp
paulson@14268
   629
  next
paulson@14268
   630
    assume "c\<noteq>0" 
paulson@14268
   631
    thus ?thesis by (force dest: field_mult_cancel_right_lemma)
paulson@14268
   632
  qed
paulson@14268
   633
paulson@14268
   634
lemma field_mult_cancel_left:
paulson@14268
   635
     "(c*a = c*b) = (c = (0::'a::field) | a=b)"
paulson@14268
   636
  by (simp add: mult_commute [of c] field_mult_cancel_right) 
paulson@14268
   637
paulson@14268
   638
lemma nonzero_imp_inverse_nonzero: "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::field)"
paulson@14268
   639
  proof
paulson@14268
   640
  assume ianz: "inverse a = 0"
paulson@14268
   641
  assume "a \<noteq> 0"
paulson@14268
   642
  hence "1 = a * inverse a" by simp
paulson@14268
   643
  also have "... = 0" by (simp add: ianz)
paulson@14268
   644
  finally have "1 = (0::'a::field)" .
paulson@14268
   645
  thus False by (simp add: eq_commute)
paulson@14268
   646
  qed
paulson@14268
   647
paulson@14268
   648
lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   649
apply (rule ccontr) 
paulson@14268
   650
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   651
done
paulson@14268
   652
paulson@14268
   653
lemma inverse_nonzero_imp_nonzero:
paulson@14268
   654
   "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   655
apply (rule ccontr) 
paulson@14268
   656
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   657
done
paulson@14268
   658
paulson@14268
   659
lemma inverse_nonzero_iff_nonzero [simp]:
paulson@14268
   660
   "(inverse a = 0) = (a = (0::'a::{field,division_by_zero}))"
paulson@14268
   661
by (force dest: inverse_nonzero_imp_nonzero) 
paulson@14268
   662
paulson@14268
   663
lemma nonzero_inverse_minus_eq:
paulson@14269
   664
      assumes [simp]: "a\<noteq>0"  shows "inverse(-a) = -inverse(a::'a::field)"
paulson@14268
   665
  proof -
paulson@14269
   666
    have "-a * inverse (- a) = -a * - inverse a"
paulson@14268
   667
      by simp
paulson@14268
   668
    thus ?thesis 
paulson@14269
   669
      by (simp only: field_mult_cancel_left, simp)
paulson@14268
   670
  qed
paulson@14268
   671
paulson@14268
   672
lemma inverse_minus_eq [simp]:
paulson@14268
   673
     "inverse(-a) = -inverse(a::'a::{field,division_by_zero})";
paulson@14269
   674
  proof cases
paulson@14268
   675
    assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14268
   676
  next
paulson@14268
   677
    assume "a\<noteq>0" 
paulson@14268
   678
    thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14268
   679
  qed
paulson@14268
   680
paulson@14268
   681
lemma nonzero_inverse_eq_imp_eq:
paulson@14269
   682
      assumes inveq: "inverse a = inverse b"
paulson@14269
   683
	  and anz:  "a \<noteq> 0"
paulson@14269
   684
	  and bnz:  "b \<noteq> 0"
paulson@14269
   685
	 shows "a = (b::'a::field)"
paulson@14268
   686
  proof -
paulson@14268
   687
  have "a * inverse b = a * inverse a"
paulson@14268
   688
    by (simp add: inveq)
paulson@14268
   689
  hence "(a * inverse b) * b = (a * inverse a) * b"
paulson@14268
   690
    by simp
paulson@14268
   691
  thus "a = b"
paulson@14268
   692
    by (simp add: mult_assoc anz bnz)
paulson@14268
   693
  qed
paulson@14268
   694
paulson@14268
   695
lemma inverse_eq_imp_eq:
paulson@14268
   696
     "inverse a = inverse b ==> a = (b::'a::{field,division_by_zero})"
paulson@14268
   697
apply (case_tac "a=0 | b=0") 
paulson@14268
   698
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
   699
              simp add: eq_commute [of "0::'a"])
paulson@14268
   700
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
   701
done
paulson@14268
   702
paulson@14268
   703
lemma inverse_eq_iff_eq [simp]:
paulson@14268
   704
     "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))"
paulson@14268
   705
by (force dest!: inverse_eq_imp_eq) 
paulson@14268
   706
paulson@14270
   707
lemma nonzero_inverse_inverse_eq:
paulson@14270
   708
      assumes [simp]: "a \<noteq> 0"  shows "inverse(inverse (a::'a::field)) = a"
paulson@14270
   709
  proof -
paulson@14270
   710
  have "(inverse (inverse a) * inverse a) * a = a" 
paulson@14270
   711
    by (simp add: nonzero_imp_inverse_nonzero)
paulson@14270
   712
  thus ?thesis
paulson@14270
   713
    by (simp add: mult_assoc)
paulson@14270
   714
  qed
paulson@14270
   715
paulson@14270
   716
lemma inverse_inverse_eq [simp]:
paulson@14270
   717
     "inverse(inverse (a::'a::{field,division_by_zero})) = a"
paulson@14270
   718
  proof cases
paulson@14270
   719
    assume "a=0" thus ?thesis by simp
paulson@14270
   720
  next
paulson@14270
   721
    assume "a\<noteq>0" 
paulson@14270
   722
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
   723
  qed
paulson@14270
   724
paulson@14270
   725
lemma inverse_1 [simp]: "inverse 1 = (1::'a::field)"
paulson@14270
   726
  proof -
paulson@14270
   727
  have "inverse 1 * 1 = (1::'a::field)" 
paulson@14270
   728
    by (rule left_inverse [OF zero_neq_one [symmetric]])
paulson@14270
   729
  thus ?thesis  by simp
paulson@14270
   730
  qed
paulson@14270
   731
paulson@14270
   732
lemma nonzero_inverse_mult_distrib: 
paulson@14270
   733
      assumes anz: "a \<noteq> 0"
paulson@14270
   734
          and bnz: "b \<noteq> 0"
paulson@14270
   735
      shows "inverse(a*b) = inverse(b) * inverse(a::'a::field)"
paulson@14270
   736
  proof -
paulson@14270
   737
  have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
paulson@14270
   738
    by (simp add: field_mult_eq_0_iff anz bnz)
paulson@14270
   739
  hence "inverse(a*b) * a = inverse(b)" 
paulson@14270
   740
    by (simp add: mult_assoc bnz)
paulson@14270
   741
  hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
paulson@14270
   742
    by simp
paulson@14270
   743
  thus ?thesis
paulson@14270
   744
    by (simp add: mult_assoc anz)
paulson@14270
   745
  qed
paulson@14270
   746
paulson@14270
   747
text{*This version builds in division by zero while also re-orienting
paulson@14270
   748
      the right-hand side.*}
paulson@14270
   749
lemma inverse_mult_distrib [simp]:
paulson@14270
   750
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
   751
  proof cases
paulson@14270
   752
    assume "a \<noteq> 0 & b \<noteq> 0" 
paulson@14270
   753
    thus ?thesis  by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
   754
  next
paulson@14270
   755
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
paulson@14270
   756
    thus ?thesis  by force
paulson@14270
   757
  qed
paulson@14270
   758
paulson@14270
   759
text{*There is no slick version using division by zero.*}
paulson@14270
   760
lemma inverse_add:
paulson@14270
   761
     "[|a \<noteq> 0;  b \<noteq> 0|]
paulson@14270
   762
      ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
paulson@14270
   763
apply (simp add: left_distrib mult_assoc)
paulson@14270
   764
apply (simp add: mult_commute [of "inverse a"]) 
paulson@14270
   765
apply (simp add: mult_assoc [symmetric] add_commute)
paulson@14270
   766
done
paulson@14270
   767
paulson@14268
   768
paulson@14268
   769
subsection {* Ordered Fields *}
paulson@14268
   770
paulson@14268
   771
lemma inverse_gt_0: 
paulson@14269
   772
      assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
paulson@14268
   773
  proof -
paulson@14268
   774
  have "0 < a * inverse a" 
paulson@14268
   775
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
   776
  thus "0 < inverse a" 
paulson@14268
   777
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
paulson@14268
   778
  qed
paulson@14268
   779
paulson@14268
   780
lemma inverse_less_0:
paulson@14268
   781
     "a < 0 ==> inverse a < (0::'a::ordered_field)"
paulson@14268
   782
  by (insert inverse_gt_0 [of "-a"], 
paulson@14268
   783
      simp add: nonzero_inverse_minus_eq order_less_imp_not_eq) 
paulson@14268
   784
paulson@14268
   785
lemma inverse_le_imp_le:
paulson@14269
   786
      assumes invle: "inverse a \<le> inverse b"
paulson@14269
   787
	  and apos:  "0 < a"
paulson@14269
   788
	 shows "b \<le> (a::'a::ordered_field)"
paulson@14268
   789
  proof (rule classical)
paulson@14268
   790
  assume "~ b \<le> a"
paulson@14268
   791
  hence "a < b"
paulson@14268
   792
    by (simp add: linorder_not_le)
paulson@14268
   793
  hence bpos: "0 < b"
paulson@14268
   794
    by (blast intro: apos order_less_trans)
paulson@14268
   795
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
   796
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
   797
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
   798
    by (simp add: bpos order_less_imp_le mult_right_mono)
paulson@14268
   799
  thus "b \<le> a"
paulson@14268
   800
    by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
paulson@14268
   801
  qed
paulson@14268
   802
paulson@14268
   803
lemma less_imp_inverse_less:
paulson@14269
   804
      assumes less: "a < b"
paulson@14269
   805
	  and apos:  "0 < a"
paulson@14269
   806
	shows "inverse b < inverse (a::'a::ordered_field)"
paulson@14268
   807
  proof (rule ccontr)
paulson@14268
   808
  assume "~ inverse b < inverse a"
paulson@14268
   809
  hence "inverse a \<le> inverse b"
paulson@14268
   810
    by (simp add: linorder_not_less)
paulson@14268
   811
  hence "~ (a < b)"
paulson@14268
   812
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
paulson@14268
   813
  thus False
paulson@14268
   814
    by (rule notE [OF _ less])
paulson@14268
   815
  qed
paulson@14268
   816
paulson@14268
   817
lemma inverse_less_imp_less:
paulson@14268
   818
   "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
   819
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
   820
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
   821
done
paulson@14268
   822
paulson@14268
   823
text{*Both premises are essential. Consider -1 and 1.*}
paulson@14268
   824
lemma inverse_less_iff_less [simp]:
paulson@14268
   825
     "[|0 < a; 0 < b|] 
paulson@14268
   826
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
   827
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
   828
paulson@14268
   829
lemma le_imp_inverse_le:
paulson@14268
   830
   "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
   831
  by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
   832
paulson@14268
   833
lemma inverse_le_iff_le [simp]:
paulson@14268
   834
     "[|0 < a; 0 < b|] 
paulson@14268
   835
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
   836
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
   837
paulson@14268
   838
paulson@14268
   839
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
   840
case is trivial, since inverse preserves signs.*}
paulson@14268
   841
lemma inverse_le_imp_le_neg:
paulson@14268
   842
   "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
paulson@14268
   843
  apply (rule classical) 
paulson@14268
   844
  apply (subgoal_tac "a < 0") 
paulson@14268
   845
   prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
paulson@14268
   846
  apply (insert inverse_le_imp_le [of "-b" "-a"])
paulson@14268
   847
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
   848
  done
paulson@14268
   849
paulson@14268
   850
lemma less_imp_inverse_less_neg:
paulson@14268
   851
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
paulson@14268
   852
  apply (subgoal_tac "a < 0") 
paulson@14268
   853
   prefer 2 apply (blast intro: order_less_trans) 
paulson@14268
   854
  apply (insert less_imp_inverse_less [of "-b" "-a"])
paulson@14268
   855
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
   856
  done
paulson@14268
   857
paulson@14268
   858
lemma inverse_less_imp_less_neg:
paulson@14268
   859
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
paulson@14268
   860
  apply (rule classical) 
paulson@14268
   861
  apply (subgoal_tac "a < 0") 
paulson@14268
   862
   prefer 2
paulson@14268
   863
   apply (force simp add: linorder_not_less intro: order_le_less_trans) 
paulson@14268
   864
  apply (insert inverse_less_imp_less [of "-b" "-a"])
paulson@14268
   865
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
   866
  done
paulson@14268
   867
paulson@14268
   868
lemma inverse_less_iff_less_neg [simp]:
paulson@14268
   869
     "[|a < 0; b < 0|] 
paulson@14268
   870
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
   871
  apply (insert inverse_less_iff_less [of "-b" "-a"])
paulson@14268
   872
  apply (simp del: inverse_less_iff_less 
paulson@14268
   873
	      add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
   874
  done
paulson@14268
   875
paulson@14268
   876
lemma le_imp_inverse_le_neg:
paulson@14268
   877
   "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
   878
  by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
   879
paulson@14268
   880
lemma inverse_le_iff_le_neg [simp]:
paulson@14268
   881
     "[|a < 0; b < 0|] 
paulson@14268
   882
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
   883
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
   884
paulson@14265
   885
end