src/HOL/Ring_and_Field.thy
author paulson
Fri Nov 21 11:15:40 2003 +0100 (2003-11-21)
changeset 14265 95b42e69436c
child 14266 08b34c902618
permissions -rw-r--r--
HOL: installation of Ring_and_Field as the basis for Naturals and Reals
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@14265
     4
    License: GPL (GNU GENERAL PUBLIC LICENSE)
paulson@14265
     5
*)
paulson@14265
     6
paulson@14265
     7
header {*
paulson@14265
     8
  \title{Ring and field structures}
paulson@14265
     9
  \author{Gertrud Bauer and Markus Wenzel}
paulson@14265
    10
*}
paulson@14265
    11
paulson@14265
    12
theory Ring_and_Field = Inductive:
paulson@14265
    13
paulson@14265
    14
text{*Lemmas and extension to semirings by L. C. Paulson*}
paulson@14265
    15
paulson@14265
    16
subsection {* Abstract algebraic structures *}
paulson@14265
    17
paulson@14265
    18
axclass semiring \<subseteq> zero, one, plus, times
paulson@14265
    19
  add_assoc: "(a + b) + c = a + (b + c)"
paulson@14265
    20
  add_commute: "a + b = b + a"
paulson@14265
    21
  left_zero [simp]: "0 + a = a"
paulson@14265
    22
paulson@14265
    23
  mult_assoc: "(a * b) * c = a * (b * c)"
paulson@14265
    24
  mult_commute: "a * b = b * a"
paulson@14265
    25
  left_one [simp]: "1 * a = a"
paulson@14265
    26
paulson@14265
    27
  left_distrib: "(a + b) * c = a * c + b * c"
paulson@14265
    28
  zero_neq_one [simp]: "0 \<noteq> 1"
paulson@14265
    29
paulson@14265
    30
axclass ring \<subseteq> semiring, minus
paulson@14265
    31
  left_minus [simp]: "- a + a = 0"
paulson@14265
    32
  diff_minus: "a - b = a + (-b)"
paulson@14265
    33
paulson@14265
    34
axclass ordered_semiring \<subseteq> semiring, linorder
paulson@14265
    35
  add_left_mono: "a \<le> b ==> c + a \<le> c + b"
paulson@14265
    36
  mult_strict_left_mono: "a < b ==> 0 < c ==> c * a < c * b"
paulson@14265
    37
paulson@14265
    38
axclass ordered_ring \<subseteq> ordered_semiring, ring
paulson@14265
    39
  abs_if: "\<bar>a\<bar> = (if a < 0 then -a else a)"
paulson@14265
    40
paulson@14265
    41
axclass field \<subseteq> ring, inverse
paulson@14265
    42
  left_inverse [simp]: "a \<noteq> 0 ==> inverse a * a = 1"
paulson@14265
    43
  divide_inverse:      "b \<noteq> 0 ==> a / b = a * inverse b"
paulson@14265
    44
paulson@14265
    45
axclass ordered_field \<subseteq> ordered_ring, field
paulson@14265
    46
paulson@14265
    47
axclass division_by_zero \<subseteq> zero, inverse
paulson@14265
    48
  inverse_zero: "inverse 0 = 0"
paulson@14265
    49
  divide_zero: "a / 0 = 0"
paulson@14265
    50
paulson@14265
    51
paulson@14265
    52
subsection {* Derived rules for addition *}
paulson@14265
    53
paulson@14265
    54
lemma right_zero [simp]: "a + 0 = (a::'a::semiring)"
paulson@14265
    55
proof -
paulson@14265
    56
  have "a + 0 = 0 + a" by (simp only: add_commute)
paulson@14265
    57
  also have "... = a" by simp
paulson@14265
    58
  finally show ?thesis .
paulson@14265
    59
qed
paulson@14265
    60
paulson@14265
    61
lemma add_left_commute: "a + (b + c) = b + (a + (c::'a::semiring))"
paulson@14265
    62
  by (rule mk_left_commute [of "op +", OF add_assoc add_commute])
paulson@14265
    63
paulson@14265
    64
theorems add_ac = add_assoc add_commute add_left_commute
paulson@14265
    65
paulson@14265
    66
lemma right_minus [simp]: "a + -(a::'a::ring) = 0"
paulson@14265
    67
proof -
paulson@14265
    68
  have "a + -a = -a + a" by (simp add: add_ac)
paulson@14265
    69
  also have "... = 0" by simp
paulson@14265
    70
  finally show ?thesis .
paulson@14265
    71
qed
paulson@14265
    72
paulson@14265
    73
lemma right_minus_eq: "(a - b = 0) = (a = (b::'a::ring))"
paulson@14265
    74
proof
paulson@14265
    75
  have "a = a - b + b" by (simp add: diff_minus add_ac)
paulson@14265
    76
  also assume "a - b = 0"
paulson@14265
    77
  finally show "a = b" by simp
paulson@14265
    78
next
paulson@14265
    79
  assume "a = b"
paulson@14265
    80
  thus "a - b = 0" by (simp add: diff_minus)
paulson@14265
    81
qed
paulson@14265
    82
paulson@14265
    83
lemma diff_self [simp]: "a - (a::'a::ring) = 0"
paulson@14265
    84
  by (simp add: diff_minus)
paulson@14265
    85
paulson@14265
    86
lemma add_left_cancel [simp]:
paulson@14265
    87
     "(a + b = a + c) = (b = (c::'a::ring))"
paulson@14265
    88
proof
paulson@14265
    89
  assume eq: "a + b = a + c"
paulson@14265
    90
  then have "(-a + a) + b = (-a + a) + c"
paulson@14265
    91
    by (simp only: eq add_assoc)
paulson@14265
    92
  then show "b = c" by simp
paulson@14265
    93
next
paulson@14265
    94
  assume eq: "b = c"
paulson@14265
    95
  then show "a + b = a + c" by simp
paulson@14265
    96
qed
paulson@14265
    97
paulson@14265
    98
lemma add_right_cancel [simp]:
paulson@14265
    99
     "(b + a = c + a) = (b = (c::'a::ring))"
paulson@14265
   100
  by (simp add: add_commute)
paulson@14265
   101
paulson@14265
   102
lemma minus_minus [simp]: "- (- (a::'a::ring)) = a"
paulson@14265
   103
  proof (rule add_left_cancel [of "-a", THEN iffD1])
paulson@14265
   104
    show "(-a + -(-a) = -a + a)"
paulson@14265
   105
    by simp
paulson@14265
   106
  qed
paulson@14265
   107
paulson@14265
   108
lemma equals_zero_I: "a+b = 0 ==> -a = (b::'a::ring)"
paulson@14265
   109
apply (rule right_minus_eq [THEN iffD1, symmetric])
paulson@14265
   110
apply (simp add: diff_minus add_commute) 
paulson@14265
   111
done
paulson@14265
   112
paulson@14265
   113
lemma minus_zero [simp]: "- 0 = (0::'a::ring)"
paulson@14265
   114
by (simp add: equals_zero_I)
paulson@14265
   115
paulson@14265
   116
lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ring))" 
paulson@14265
   117
  proof 
paulson@14265
   118
    assume "- a = - b"
paulson@14265
   119
    then have "- (- a) = - (- b)"
paulson@14265
   120
      by simp
paulson@14265
   121
    then show "a=b"
paulson@14265
   122
      by simp
paulson@14265
   123
  next
paulson@14265
   124
    assume "a=b"
paulson@14265
   125
    then show "-a = -b"
paulson@14265
   126
      by simp
paulson@14265
   127
  qed
paulson@14265
   128
paulson@14265
   129
lemma neg_equal_0_iff_equal [simp]: "(-a = 0) = (a = (0::'a::ring))"
paulson@14265
   130
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   131
paulson@14265
   132
lemma neg_0_equal_iff_equal [simp]: "(0 = -a) = (0 = (a::'a::ring))"
paulson@14265
   133
by (subst neg_equal_iff_equal [symmetric], simp)
paulson@14265
   134
paulson@14265
   135
paulson@14265
   136
subsection {* Derived rules for multiplication *}
paulson@14265
   137
paulson@14265
   138
lemma right_one [simp]: "a = a * (1::'a::semiring)"
paulson@14265
   139
proof -
paulson@14265
   140
  have "a = 1 * a" by simp
paulson@14265
   141
  also have "... = a * 1" by (simp add: mult_commute)
paulson@14265
   142
  finally show ?thesis .
paulson@14265
   143
qed
paulson@14265
   144
paulson@14265
   145
lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::semiring))"
paulson@14265
   146
  by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute])
paulson@14265
   147
paulson@14265
   148
theorems mult_ac = mult_assoc mult_commute mult_left_commute
paulson@14265
   149
paulson@14265
   150
lemma right_inverse [simp]: "a \<noteq> 0 ==>  a * inverse (a::'a::field) = 1"
paulson@14265
   151
proof -
paulson@14265
   152
  have "a * inverse a = inverse a * a" by (simp add: mult_ac)
paulson@14265
   153
  also assume "a \<noteq> 0"
paulson@14265
   154
  hence "inverse a * a = 1" by simp
paulson@14265
   155
  finally show ?thesis .
paulson@14265
   156
qed
paulson@14265
   157
paulson@14265
   158
lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
paulson@14265
   159
proof
paulson@14265
   160
  assume neq: "b \<noteq> 0"
paulson@14265
   161
  {
paulson@14265
   162
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
paulson@14265
   163
    also assume "a / b = 1"
paulson@14265
   164
    finally show "a = b" by simp
paulson@14265
   165
  next
paulson@14265
   166
    assume "a = b"
paulson@14265
   167
    with neq show "a / b = 1" by (simp add: divide_inverse)
paulson@14265
   168
  }
paulson@14265
   169
qed
paulson@14265
   170
paulson@14265
   171
lemma divide_self [simp]: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
paulson@14265
   172
  by (simp add: divide_inverse)
paulson@14265
   173
paulson@14265
   174
lemma mult_left_zero [simp]: "0 * a = (0::'a::ring)"
paulson@14265
   175
proof -
paulson@14265
   176
  have "0*a + 0*a = 0*a + 0"
paulson@14265
   177
    by (simp add: left_distrib [symmetric])
paulson@14265
   178
  then show ?thesis by (simp only: add_left_cancel)
paulson@14265
   179
qed
paulson@14265
   180
paulson@14265
   181
lemma mult_right_zero [simp]: "a * 0 = (0::'a::ring)"
paulson@14265
   182
  by (simp add: mult_commute)
paulson@14265
   183
paulson@14265
   184
paulson@14265
   185
subsection {* Distribution rules *}
paulson@14265
   186
paulson@14265
   187
lemma right_distrib: "a * (b + c) = a * b + a * (c::'a::semiring)"
paulson@14265
   188
proof -
paulson@14265
   189
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
paulson@14265
   190
  also have "... = b * a + c * a" by (simp only: left_distrib)
paulson@14265
   191
  also have "... = a * b + a * c" by (simp add: mult_ac)
paulson@14265
   192
  finally show ?thesis .
paulson@14265
   193
qed
paulson@14265
   194
paulson@14265
   195
theorems ring_distrib = right_distrib left_distrib
paulson@14265
   196
paulson@14265
   197
lemma minus_add_distrib [simp]: "- (a + b) = -a + -(b::'a::ring)"
paulson@14265
   198
apply (rule equals_zero_I)
paulson@14265
   199
apply (simp add: add_ac) 
paulson@14265
   200
done
paulson@14265
   201
paulson@14265
   202
lemma minus_mult_left: "- (a * b) = (-a) * (b::'a::ring)"
paulson@14265
   203
apply (rule equals_zero_I)
paulson@14265
   204
apply (simp add: left_distrib [symmetric]) 
paulson@14265
   205
done
paulson@14265
   206
paulson@14265
   207
lemma minus_mult_right: "- (a * b) = a * -(b::'a::ring)"
paulson@14265
   208
apply (rule equals_zero_I)
paulson@14265
   209
apply (simp add: right_distrib [symmetric]) 
paulson@14265
   210
done
paulson@14265
   211
paulson@14265
   212
lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)"
paulson@14265
   213
by (simp add: right_distrib diff_minus 
paulson@14265
   214
              minus_mult_left [symmetric] minus_mult_right [symmetric]) 
paulson@14265
   215
paulson@14265
   216
paulson@14265
   217
subsection {* Ordering rules *}
paulson@14265
   218
paulson@14265
   219
lemma add_right_mono: "a \<le> (b::'a::ordered_semiring) ==> a + c \<le> b + c"
paulson@14265
   220
by (simp add: add_commute [of _ c] add_left_mono)
paulson@14265
   221
paulson@14265
   222
lemma le_imp_neg_le:
paulson@14265
   223
   assumes "a \<le> (b::'a::ordered_ring)" shows "-b \<le> -a"
paulson@14265
   224
  proof -
paulson@14265
   225
  have "-a+a \<le> -a+b"
paulson@14265
   226
    by (rule add_left_mono) 
paulson@14265
   227
  then have "0 \<le> -a+b"
paulson@14265
   228
    by simp
paulson@14265
   229
  then have "0 + (-b) \<le> (-a + b) + (-b)"
paulson@14265
   230
    by (rule add_right_mono) 
paulson@14265
   231
  then show ?thesis
paulson@14265
   232
    by (simp add: add_assoc)
paulson@14265
   233
  qed
paulson@14265
   234
paulson@14265
   235
lemma neg_le_iff_le [simp]: "(-b \<le> -a) = (a \<le> (b::'a::ordered_ring))"
paulson@14265
   236
  proof 
paulson@14265
   237
    assume "- b \<le> - a"
paulson@14265
   238
    then have "- (- a) \<le> - (- b)"
paulson@14265
   239
      by (rule le_imp_neg_le)
paulson@14265
   240
    then show "a\<le>b"
paulson@14265
   241
      by simp
paulson@14265
   242
  next
paulson@14265
   243
    assume "a\<le>b"
paulson@14265
   244
    then show "-b \<le> -a"
paulson@14265
   245
      by (rule le_imp_neg_le)
paulson@14265
   246
  qed
paulson@14265
   247
paulson@14265
   248
lemma neg_le_0_iff_le [simp]: "(-a \<le> 0) = (0 \<le> (a::'a::ordered_ring))"
paulson@14265
   249
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   250
paulson@14265
   251
lemma neg_0_le_iff_le [simp]: "(0 \<le> -a) = (a \<le> (0::'a::ordered_ring))"
paulson@14265
   252
by (subst neg_le_iff_le [symmetric], simp)
paulson@14265
   253
paulson@14265
   254
lemma neg_less_iff_less [simp]: "(-b < -a) = (a < (b::'a::ordered_ring))"
paulson@14265
   255
by (force simp add: order_less_le) 
paulson@14265
   256
paulson@14265
   257
lemma neg_less_0_iff_less [simp]: "(-a < 0) = (0 < (a::'a::ordered_ring))"
paulson@14265
   258
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   259
paulson@14265
   260
lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::ordered_ring))"
paulson@14265
   261
by (subst neg_less_iff_less [symmetric], simp)
paulson@14265
   262
paulson@14265
   263
lemma mult_strict_right_mono:
paulson@14265
   264
     "[|a < b; 0 < c|] ==> a * c < b * (c::'a::ordered_semiring)"
paulson@14265
   265
by (simp add: mult_commute [of _ c] mult_strict_left_mono)
paulson@14265
   266
paulson@14265
   267
lemma mult_left_mono:
paulson@14265
   268
     "[|a \<le> b; 0 < c|] ==> c * a \<le> c * (b::'a::ordered_semiring)"
paulson@14265
   269
by (force simp add: mult_strict_left_mono order_le_less) 
paulson@14265
   270
paulson@14265
   271
lemma mult_right_mono:
paulson@14265
   272
     "[|a \<le> b; 0 < c|] ==> a*c \<le> b * (c::'a::ordered_semiring)"
paulson@14265
   273
by (force simp add: mult_strict_right_mono order_le_less) 
paulson@14265
   274
paulson@14265
   275
lemma mult_strict_left_mono_neg:
paulson@14265
   276
     "[|b < a; c < 0|] ==> c * a < c * (b::'a::ordered_ring)"
paulson@14265
   277
apply (drule mult_strict_left_mono [of _ _ "-c"])
paulson@14265
   278
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14265
   279
done
paulson@14265
   280
paulson@14265
   281
lemma mult_strict_right_mono_neg:
paulson@14265
   282
     "[|b < a; c < 0|] ==> a * c < b * (c::'a::ordered_ring)"
paulson@14265
   283
apply (drule mult_strict_right_mono [of _ _ "-c"])
paulson@14265
   284
apply (simp_all add: minus_mult_right [symmetric]) 
paulson@14265
   285
done
paulson@14265
   286
paulson@14265
   287
lemma mult_left_mono_neg:
paulson@14265
   288
     "[|b \<le> a; c < 0|] ==> c * a \<le> c * (b::'a::ordered_ring)"
paulson@14265
   289
by (force simp add: mult_strict_left_mono_neg order_le_less) 
paulson@14265
   290
paulson@14265
   291
lemma mult_right_mono_neg:
paulson@14265
   292
     "[|b \<le> a; c < 0|] ==> a * c \<le> b * (c::'a::ordered_ring)"
paulson@14265
   293
by (force simp add: mult_strict_right_mono_neg order_le_less) 
paulson@14265
   294
paulson@14265
   295
paulson@14265
   296
subsection{* Products of Signs *}
paulson@14265
   297
paulson@14265
   298
lemma mult_pos: "[| (0::'a::ordered_ring) < a; 0 < b |] ==> 0 < a*b"
paulson@14265
   299
by (drule mult_strict_left_mono [of 0 b], auto)
paulson@14265
   300
paulson@14265
   301
lemma mult_pos_neg: "[| (0::'a::ordered_ring) < a; b < 0 |] ==> a*b < 0"
paulson@14265
   302
by (drule mult_strict_left_mono [of b 0], auto)
paulson@14265
   303
paulson@14265
   304
lemma mult_neg: "[| a < (0::'a::ordered_ring); b < 0 |] ==> 0 < a*b"
paulson@14265
   305
by (drule mult_strict_right_mono_neg, auto)
paulson@14265
   306
paulson@14265
   307
lemma zero_less_mult_pos: "[| 0 < a*b; 0 < a|] ==> 0 < (b::'a::ordered_ring)"
paulson@14265
   308
apply (case_tac "b\<le>0") 
paulson@14265
   309
 apply (auto simp add: order_le_less linorder_not_less)
paulson@14265
   310
apply (drule_tac mult_pos_neg [of a b]) 
paulson@14265
   311
 apply (auto dest: order_less_not_sym)
paulson@14265
   312
done
paulson@14265
   313
paulson@14265
   314
lemma zero_less_mult_iff:
paulson@14265
   315
     "((0::'a::ordered_ring) < a*b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14265
   316
apply (auto simp add: order_le_less linorder_not_less mult_pos mult_neg)
paulson@14265
   317
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   318
apply (simp add: mult_commute [of a b]) 
paulson@14265
   319
apply (blast dest: zero_less_mult_pos) 
paulson@14265
   320
done
paulson@14265
   321
paulson@14265
   322
paulson@14265
   323
lemma mult_eq_0_iff [iff]: "(a*b = (0::'a::ordered_ring)) = (a = 0 | b = 0)"
paulson@14265
   324
apply (case_tac "a < 0")
paulson@14265
   325
apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff)
paulson@14265
   326
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+
paulson@14265
   327
done
paulson@14265
   328
paulson@14265
   329
lemma zero_le_mult_iff:
paulson@14265
   330
     "((0::'a::ordered_ring) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14265
   331
by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less
paulson@14265
   332
                   zero_less_mult_iff)
paulson@14265
   333
paulson@14265
   334
lemma mult_less_0_iff:
paulson@14265
   335
     "(a*b < (0::'a::ordered_ring)) = (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14265
   336
apply (insert zero_less_mult_iff [of "-a" b]) 
paulson@14265
   337
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   338
done
paulson@14265
   339
paulson@14265
   340
lemma mult_le_0_iff:
paulson@14265
   341
     "(a*b \<le> (0::'a::ordered_ring)) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14265
   342
apply (insert zero_le_mult_iff [of "-a" b]) 
paulson@14265
   343
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   344
done
paulson@14265
   345
paulson@14265
   346
lemma zero_le_square: "(0::'a::ordered_ring) \<le> a*a"
paulson@14265
   347
by (simp add: zero_le_mult_iff linorder_linear) 
paulson@14265
   348
paulson@14265
   349
lemma zero_less_one: "(0::'a::ordered_ring) < 1"
paulson@14265
   350
apply (insert zero_le_square [of 1]) 
paulson@14265
   351
apply (simp add: order_less_le) 
paulson@14265
   352
done
paulson@14265
   353
paulson@14265
   354
paulson@14265
   355
subsection {* Absolute Value *}
paulson@14265
   356
paulson@14265
   357
text{*But is it really better than just rewriting with @{text abs_if}?*}
paulson@14265
   358
lemma abs_split:
paulson@14265
   359
     "P(abs(a::'a::ordered_ring)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
paulson@14265
   360
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
paulson@14265
   361
paulson@14265
   362
lemma abs_zero [simp]: "abs 0 = (0::'a::ordered_ring)"
paulson@14265
   363
by (simp add: abs_if)
paulson@14265
   364
paulson@14265
   365
lemma abs_mult: "abs (x * y) = abs x * abs (y::'a::ordered_ring)" 
paulson@14265
   366
apply (case_tac "x=0 | y=0", force) 
paulson@14265
   367
apply (auto elim: order_less_asym
paulson@14265
   368
            simp add: abs_if mult_less_0_iff linorder_neq_iff
paulson@14265
   369
                  minus_mult_left [symmetric] minus_mult_right [symmetric])  
paulson@14265
   370
done
paulson@14265
   371
paulson@14265
   372
lemma abs_eq_0 [iff]: "(abs x = 0) = (x = (0::'a::ordered_ring))"
paulson@14265
   373
by (simp add: abs_if)
paulson@14265
   374
paulson@14265
   375
lemma zero_less_abs_iff [iff]: "(0 < abs x) = (x ~= (0::'a::ordered_ring))"
paulson@14265
   376
by (simp add: abs_if linorder_neq_iff)
paulson@14265
   377
paulson@14265
   378
paulson@14265
   379
subsection {* Fields *}
paulson@14265
   380
paulson@14265
   381
paulson@14265
   382
end