48 axclass division_by_zero \<subseteq> zero, inverse |
48 axclass division_by_zero \<subseteq> zero, inverse |
49 inverse_zero [simp]: "inverse 0 = 0" |
49 inverse_zero [simp]: "inverse 0 = 0" |
50 divide_zero [simp]: "a / 0 = 0" |
50 divide_zero [simp]: "a / 0 = 0" |
51 |
51 |
52 |
52 |
53 subsection {* Derived rules for addition *} |
53 subsection {* Derived Rules for Addition *} |
54 |
54 |
55 lemma right_zero [simp]: "a + 0 = (a::'a::semiring)" |
55 lemma right_zero [simp]: "a + 0 = (a::'a::semiring)" |
56 proof - |
56 proof - |
57 have "a + 0 = 0 + a" by (simp only: add_commute) |
57 have "a + 0 = 0 + a" by (simp only: add_commute) |
58 also have "... = a" by simp |
58 also have "... = a" by simp |
78 finally show "a = b" by simp |
78 finally show "a = b" by simp |
79 next |
79 next |
80 assume "a = b" |
80 assume "a = b" |
81 thus "a - b = 0" by (simp add: diff_minus) |
81 thus "a - b = 0" by (simp add: diff_minus) |
82 qed |
82 qed |
83 |
|
84 lemma diff_self [simp]: "a - (a::'a::ring) = 0" |
|
85 by (simp add: diff_minus) |
|
86 |
83 |
87 lemma add_left_cancel [simp]: |
84 lemma add_left_cancel [simp]: |
88 "(a + b = a + c) = (b = (c::'a::ring))" |
85 "(a + b = a + c) = (b = (c::'a::ring))" |
89 proof |
86 proof |
90 assume eq: "a + b = a + c" |
87 assume eq: "a + b = a + c" |
112 done |
109 done |
113 |
110 |
114 lemma minus_zero [simp]: "- 0 = (0::'a::ring)" |
111 lemma minus_zero [simp]: "- 0 = (0::'a::ring)" |
115 by (simp add: equals_zero_I) |
112 by (simp add: equals_zero_I) |
116 |
113 |
|
114 lemma diff_self [simp]: "a - (a::'a::ring) = 0" |
|
115 by (simp add: diff_minus) |
|
116 |
|
117 lemma diff_0 [simp]: "(0::'a::ring) - a = -a" |
|
118 by (simp add: diff_minus) |
|
119 |
|
120 lemma diff_0_right [simp]: "a - (0::'a::ring) = a" |
|
121 by (simp add: diff_minus) |
|
122 |
117 lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ring))" |
123 lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ring))" |
118 proof |
124 proof |
119 assume "- a = - b" |
125 assume "- a = - b" |
120 hence "- (- a) = - (- b)" |
126 hence "- (- a) = - (- b)" |
121 by simp |
127 by simp |
145 by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute]) |
151 by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute]) |
146 |
152 |
147 theorems mult_ac = mult_assoc mult_commute mult_left_commute |
153 theorems mult_ac = mult_assoc mult_commute mult_left_commute |
148 |
154 |
149 lemma right_inverse [simp]: |
155 lemma right_inverse [simp]: |
150 assumes not0: "a ~= 0" shows "a * inverse (a::'a::field) = 1" |
156 assumes not0: "a \<noteq> 0" shows "a * inverse (a::'a::field) = 1" |
151 proof - |
157 proof - |
152 have "a * inverse a = inverse a * a" by (simp add: mult_ac) |
158 have "a * inverse a = inverse a * a" by (simp add: mult_ac) |
153 also have "... = 1" using not0 by simp |
159 also have "... = 1" using not0 by simp |
154 finally show ?thesis . |
160 finally show ?thesis . |
155 qed |
161 qed |
213 |
219 |
214 lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)" |
220 lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)" |
215 by (simp add: right_distrib diff_minus |
221 by (simp add: right_distrib diff_minus |
216 minus_mult_left [symmetric] minus_mult_right [symmetric]) |
222 minus_mult_left [symmetric] minus_mult_right [symmetric]) |
217 |
223 |
218 |
224 lemma minus_diff_eq [simp]: "- (a - b) = b - (a::'a::ring)" |
219 subsection {* Ordering rules *} |
225 by (simp add: diff_minus add_commute) |
|
226 |
|
227 |
|
228 subsection {* Ordering Rules for Addition *} |
220 |
229 |
221 lemma add_right_mono: "a \<le> (b::'a::ordered_semiring) ==> a + c \<le> b + c" |
230 lemma add_right_mono: "a \<le> (b::'a::ordered_semiring) ==> a + c \<le> b + c" |
222 by (simp add: add_commute [of _ c] add_left_mono) |
231 by (simp add: add_commute [of _ c] add_left_mono) |
223 |
232 |
224 text {* non-strict, in both arguments *} |
233 text {* non-strict, in both arguments *} |
238 text{*Strict monotonicity in both arguments*} |
247 text{*Strict monotonicity in both arguments*} |
239 lemma add_strict_mono: "[|a<b; c<d|] ==> a + c < b + (d::'a::ordered_ring)" |
248 lemma add_strict_mono: "[|a<b; c<d|] ==> a + c < b + (d::'a::ordered_ring)" |
240 apply (erule add_strict_right_mono [THEN order_less_trans]) |
249 apply (erule add_strict_right_mono [THEN order_less_trans]) |
241 apply (erule add_strict_left_mono) |
250 apply (erule add_strict_left_mono) |
242 done |
251 done |
|
252 |
|
253 lemma add_less_imp_less_left: |
|
254 assumes less: "c + a < c + b" shows "a < (b::'a::ordered_ring)" |
|
255 proof - |
|
256 have "-c + (c + a) < -c + (c + b)" |
|
257 by (rule add_strict_left_mono [OF less]) |
|
258 thus "a < b" by (simp add: add_assoc [symmetric]) |
|
259 qed |
|
260 |
|
261 lemma add_less_imp_less_right: |
|
262 "a + c < b + c ==> a < (b::'a::ordered_ring)" |
|
263 apply (rule add_less_imp_less_left [of c]) |
|
264 apply (simp add: add_commute) |
|
265 done |
|
266 |
|
267 lemma add_less_cancel_left [simp]: |
|
268 "(c+a < c+b) = (a < (b::'a::ordered_ring))" |
|
269 by (blast intro: add_less_imp_less_left add_strict_left_mono) |
|
270 |
|
271 lemma add_less_cancel_right [simp]: |
|
272 "(a+c < b+c) = (a < (b::'a::ordered_ring))" |
|
273 by (blast intro: add_less_imp_less_right add_strict_right_mono) |
|
274 |
|
275 lemma add_le_cancel_left [simp]: |
|
276 "(c+a \<le> c+b) = (a \<le> (b::'a::ordered_ring))" |
|
277 by (simp add: linorder_not_less [symmetric]) |
|
278 |
|
279 lemma add_le_cancel_right [simp]: |
|
280 "(a+c \<le> b+c) = (a \<le> (b::'a::ordered_ring))" |
|
281 by (simp add: linorder_not_less [symmetric]) |
|
282 |
|
283 lemma add_le_imp_le_left: |
|
284 "c + a \<le> c + b ==> a \<le> (b::'a::ordered_ring)" |
|
285 by simp |
|
286 |
|
287 lemma add_le_imp_le_right: |
|
288 "a + c \<le> b + c ==> a \<le> (b::'a::ordered_ring)" |
|
289 by simp |
|
290 |
|
291 |
|
292 subsection {* Ordering Rules for Unary Minus *} |
243 |
293 |
244 lemma le_imp_neg_le: |
294 lemma le_imp_neg_le: |
245 assumes "a \<le> (b::'a::ordered_ring)" shows "-b \<le> -a" |
295 assumes "a \<le> (b::'a::ordered_ring)" shows "-b \<le> -a" |
246 proof - |
296 proof - |
247 have "-a+a \<le> -a+b" |
297 have "-a+a \<le> -a+b" |
278 by (subst neg_less_iff_less [symmetric], simp) |
328 by (subst neg_less_iff_less [symmetric], simp) |
279 |
329 |
280 lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::ordered_ring))" |
330 lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::ordered_ring))" |
281 by (subst neg_less_iff_less [symmetric], simp) |
331 by (subst neg_less_iff_less [symmetric], simp) |
282 |
332 |
|
333 |
|
334 subsection{*Subtraction Laws*} |
|
335 |
|
336 lemma add_diff_eq: "a + (b - c) = (a + b) - (c::'a::ring)" |
|
337 by (simp add: diff_minus add_ac) |
|
338 |
|
339 lemma diff_add_eq: "(a - b) + c = (a + c) - (b::'a::ring)" |
|
340 by (simp add: diff_minus add_ac) |
|
341 |
|
342 lemma diff_eq_eq: "(a-b = c) = (a = c + (b::'a::ring))" |
|
343 by (auto simp add: diff_minus add_assoc) |
|
344 |
|
345 lemma eq_diff_eq: "(a = c-b) = (a + (b::'a::ring) = c)" |
|
346 by (auto simp add: diff_minus add_assoc) |
|
347 |
|
348 lemma diff_diff_eq: "(a - b) - c = a - (b + (c::'a::ring))" |
|
349 by (simp add: diff_minus add_ac) |
|
350 |
|
351 lemma diff_diff_eq2: "a - (b - c) = (a + c) - (b::'a::ring)" |
|
352 by (simp add: diff_minus add_ac) |
|
353 |
|
354 text{*Further subtraction laws for ordered rings*} |
|
355 |
|
356 lemma less_eq_diff: "(a < b) = (a - b < (0::'a::ordered_ring))" |
|
357 proof - |
|
358 have "(a < b) = (a + (- b) < b + (-b))" |
|
359 by (simp only: add_less_cancel_right) |
|
360 also have "... = (a - b < 0)" by (simp add: diff_minus) |
|
361 finally show ?thesis . |
|
362 qed |
|
363 |
|
364 lemma diff_less_eq: "(a-b < c) = (a < c + (b::'a::ordered_ring))" |
|
365 apply (subst less_eq_diff) |
|
366 apply (rule less_eq_diff [of _ c, THEN ssubst]) |
|
367 apply (simp add: diff_minus add_ac) |
|
368 done |
|
369 |
|
370 lemma less_diff_eq: "(a < c-b) = (a + (b::'a::ordered_ring) < c)" |
|
371 apply (subst less_eq_diff) |
|
372 apply (rule less_eq_diff [of _ "c-b", THEN ssubst]) |
|
373 apply (simp add: diff_minus add_ac) |
|
374 done |
|
375 |
|
376 lemma diff_le_eq: "(a-b \<le> c) = (a \<le> c + (b::'a::ordered_ring))" |
|
377 by (simp add: linorder_not_less [symmetric] less_diff_eq) |
|
378 |
|
379 lemma le_diff_eq: "(a \<le> c-b) = (a + (b::'a::ordered_ring) \<le> c)" |
|
380 by (simp add: linorder_not_less [symmetric] diff_less_eq) |
|
381 |
|
382 text{*This list of rewrites simplifies (in)equalities by bringing subtractions |
|
383 to the top and then moving negative terms to the other side. |
|
384 Use with @{text add_ac}*} |
|
385 lemmas compare_rls = |
|
386 diff_minus [symmetric] |
|
387 add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2 |
|
388 diff_less_eq less_diff_eq diff_le_eq le_diff_eq |
|
389 diff_eq_eq eq_diff_eq |
|
390 |
|
391 |
|
392 subsection {* Ordering Rules for Multiplication *} |
|
393 |
283 lemma mult_strict_right_mono: |
394 lemma mult_strict_right_mono: |
284 "[|a < b; 0 < c|] ==> a * c < b * (c::'a::ordered_semiring)" |
395 "[|a < b; 0 < c|] ==> a * c < b * (c::'a::ordered_semiring)" |
285 by (simp add: mult_commute [of _ c] mult_strict_left_mono) |
396 by (simp add: mult_commute [of _ c] mult_strict_left_mono) |
286 |
397 |
287 lemma mult_left_mono: |
398 lemma mult_left_mono: |
481 lemma zero_less_abs_iff [simp]: "(0 < abs x) = (x ~= (0::'a::ordered_ring))" |
592 lemma zero_less_abs_iff [simp]: "(0 < abs x) = (x ~= (0::'a::ordered_ring))" |
482 by (simp add: abs_if linorder_neq_iff) |
593 by (simp add: abs_if linorder_neq_iff) |
483 |
594 |
484 |
595 |
485 subsection {* Fields *} |
596 subsection {* Fields *} |
|
597 |
|
598 text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement |
|
599 of an ordering.*} |
|
600 lemma field_mult_eq_0_iff: "(a*b = (0::'a::field)) = (a = 0 | b = 0)" |
|
601 proof cases |
|
602 assume "a=0" thus ?thesis by simp |
|
603 next |
|
604 assume anz [simp]: "a\<noteq>0" |
|
605 thus ?thesis |
|
606 proof auto |
|
607 assume "a * b = 0" |
|
608 hence "inverse a * (a * b) = 0" by simp |
|
609 thus "b = 0" by (simp (no_asm_use) add: mult_assoc [symmetric]) |
|
610 qed |
|
611 qed |
486 |
612 |
487 text{*Cancellation of equalities with a common factor*} |
613 text{*Cancellation of equalities with a common factor*} |
488 lemma field_mult_cancel_right_lemma: |
614 lemma field_mult_cancel_right_lemma: |
489 assumes cnz: "c \<noteq> (0::'a::field)" |
615 assumes cnz: "c \<noteq> (0::'a::field)" |
490 and eq: "a*c = b*c" |
616 and eq: "a*c = b*c" |
575 done |
701 done |
576 |
702 |
577 lemma inverse_eq_iff_eq [simp]: |
703 lemma inverse_eq_iff_eq [simp]: |
578 "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))" |
704 "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))" |
579 by (force dest!: inverse_eq_imp_eq) |
705 by (force dest!: inverse_eq_imp_eq) |
|
706 |
|
707 lemma nonzero_inverse_inverse_eq: |
|
708 assumes [simp]: "a \<noteq> 0" shows "inverse(inverse (a::'a::field)) = a" |
|
709 proof - |
|
710 have "(inverse (inverse a) * inverse a) * a = a" |
|
711 by (simp add: nonzero_imp_inverse_nonzero) |
|
712 thus ?thesis |
|
713 by (simp add: mult_assoc) |
|
714 qed |
|
715 |
|
716 lemma inverse_inverse_eq [simp]: |
|
717 "inverse(inverse (a::'a::{field,division_by_zero})) = a" |
|
718 proof cases |
|
719 assume "a=0" thus ?thesis by simp |
|
720 next |
|
721 assume "a\<noteq>0" |
|
722 thus ?thesis by (simp add: nonzero_inverse_inverse_eq) |
|
723 qed |
|
724 |
|
725 lemma inverse_1 [simp]: "inverse 1 = (1::'a::field)" |
|
726 proof - |
|
727 have "inverse 1 * 1 = (1::'a::field)" |
|
728 by (rule left_inverse [OF zero_neq_one [symmetric]]) |
|
729 thus ?thesis by simp |
|
730 qed |
|
731 |
|
732 lemma nonzero_inverse_mult_distrib: |
|
733 assumes anz: "a \<noteq> 0" |
|
734 and bnz: "b \<noteq> 0" |
|
735 shows "inverse(a*b) = inverse(b) * inverse(a::'a::field)" |
|
736 proof - |
|
737 have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" |
|
738 by (simp add: field_mult_eq_0_iff anz bnz) |
|
739 hence "inverse(a*b) * a = inverse(b)" |
|
740 by (simp add: mult_assoc bnz) |
|
741 hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" |
|
742 by simp |
|
743 thus ?thesis |
|
744 by (simp add: mult_assoc anz) |
|
745 qed |
|
746 |
|
747 text{*This version builds in division by zero while also re-orienting |
|
748 the right-hand side.*} |
|
749 lemma inverse_mult_distrib [simp]: |
|
750 "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})" |
|
751 proof cases |
|
752 assume "a \<noteq> 0 & b \<noteq> 0" |
|
753 thus ?thesis by (simp add: nonzero_inverse_mult_distrib mult_commute) |
|
754 next |
|
755 assume "~ (a \<noteq> 0 & b \<noteq> 0)" |
|
756 thus ?thesis by force |
|
757 qed |
|
758 |
|
759 text{*There is no slick version using division by zero.*} |
|
760 lemma inverse_add: |
|
761 "[|a \<noteq> 0; b \<noteq> 0|] |
|
762 ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)" |
|
763 apply (simp add: left_distrib mult_assoc) |
|
764 apply (simp add: mult_commute [of "inverse a"]) |
|
765 apply (simp add: mult_assoc [symmetric] add_commute) |
|
766 done |
580 |
767 |
581 |
768 |
582 subsection {* Ordered Fields *} |
769 subsection {* Ordered Fields *} |
583 |
770 |
584 lemma inverse_gt_0: |
771 lemma inverse_gt_0: |