438 then show "inverse q * q = 1" by (cases q rule: Rat_cases_nonzero) |
438 then show "inverse q * q = 1" by (cases q rule: Rat_cases_nonzero) |
439 (simp_all add: rat_number_expand eq_rat) |
439 (simp_all add: rat_number_expand eq_rat) |
440 next |
440 next |
441 fix q r :: rat |
441 fix q r :: rat |
442 show "q / r = q * inverse r" by (simp add: divide_rat_def) |
442 show "q / r = q * inverse r" by (simp add: divide_rat_def) |
443 qed |
443 qed (simp add: rat_number_expand, simp add: rat_number_collapse) |
444 |
444 |
445 end |
445 end |
446 |
|
447 instance rat :: division_ring_inverse_zero proof |
|
448 qed (simp add: rat_number_expand, simp add: rat_number_collapse) |
|
449 |
446 |
450 |
447 |
451 subsubsection {* Various *} |
448 subsubsection {* Various *} |
452 |
449 |
453 lemma Fract_add_one: "n \<noteq> 0 ==> Fract (m + n) n = Fract m n + 1" |
450 lemma Fract_add_one: "n \<noteq> 0 ==> Fract (m + n) n = Fract m n + 1" |
622 instance by intro_classes |
619 instance by intro_classes |
623 (auto simp add: abs_rat_def sgn_rat_def min_max.sup_inf_distrib1 inf_rat_def sup_rat_def) |
620 (auto simp add: abs_rat_def sgn_rat_def min_max.sup_inf_distrib1 inf_rat_def sup_rat_def) |
624 |
621 |
625 end |
622 end |
626 |
623 |
627 instance rat :: linordered_field |
624 instance rat :: linordered_field_inverse_zero |
628 proof |
625 proof |
629 fix q r s :: rat |
626 fix q r s :: rat |
630 show "q \<le> r ==> s + q \<le> s + r" |
627 show "q \<le> r ==> s + q \<le> s + r" |
631 proof (induct q, induct r, induct s) |
628 proof (induct q, induct r, induct s) |
632 fix a b c d e f :: int |
629 fix a b c d e f :: int |
722 proof - |
719 proof - |
723 have "Fract a b = of_int (a div b) + Fract (a mod b) b" |
720 have "Fract a b = of_int (a div b) + Fract (a mod b) b" |
724 by (cases "b = 0", simp, simp add: of_int_rat) |
721 by (cases "b = 0", simp, simp add: of_int_rat) |
725 moreover have "0 \<le> Fract (a mod b) b \<and> Fract (a mod b) b < 1" |
722 moreover have "0 \<le> Fract (a mod b) b \<and> Fract (a mod b) b < 1" |
726 unfolding Fract_of_int_quotient |
723 unfolding Fract_of_int_quotient |
727 by (rule linorder_cases [of b 0]) |
724 by (rule linorder_cases [of b 0]) (simp add: divide_nonpos_neg, simp, simp add: divide_nonneg_pos) |
728 (simp add: divide_nonpos_neg, simp, simp add: divide_nonneg_pos) |
|
729 ultimately show ?thesis by simp |
725 ultimately show ?thesis by simp |
730 qed |
726 qed |
731 |
727 |
732 instance rat :: archimedean_field |
728 instance rat :: archimedean_field |
733 proof |
729 proof |
816 apply (rule inverse_unique [symmetric]) |
812 apply (rule inverse_unique [symmetric]) |
817 apply (simp add: of_rat_mult [symmetric]) |
813 apply (simp add: of_rat_mult [symmetric]) |
818 done |
814 done |
819 |
815 |
820 lemma of_rat_inverse: |
816 lemma of_rat_inverse: |
821 "(of_rat (inverse a)::'a::{field_char_0,division_ring_inverse_zero}) = |
817 "(of_rat (inverse a)::'a::{field_char_0, field_inverse_zero}) = |
822 inverse (of_rat a)" |
818 inverse (of_rat a)" |
823 by (cases "a = 0", simp_all add: nonzero_of_rat_inverse) |
819 by (cases "a = 0", simp_all add: nonzero_of_rat_inverse) |
824 |
820 |
825 lemma nonzero_of_rat_divide: |
821 lemma nonzero_of_rat_divide: |
826 "b \<noteq> 0 \<Longrightarrow> of_rat (a / b) = of_rat a / of_rat b" |
822 "b \<noteq> 0 \<Longrightarrow> of_rat (a / b) = of_rat a / of_rat b" |
827 by (simp add: divide_inverse of_rat_mult nonzero_of_rat_inverse) |
823 by (simp add: divide_inverse of_rat_mult nonzero_of_rat_inverse) |
828 |
824 |
829 lemma of_rat_divide: |
825 lemma of_rat_divide: |
830 "(of_rat (a / b)::'a::{field_char_0,division_ring_inverse_zero}) |
826 "(of_rat (a / b)::'a::{field_char_0, field_inverse_zero}) |
831 = of_rat a / of_rat b" |
827 = of_rat a / of_rat b" |
832 by (cases "b = 0") (simp_all add: nonzero_of_rat_divide) |
828 by (cases "b = 0") (simp_all add: nonzero_of_rat_divide) |
833 |
829 |
834 lemma of_rat_power: |
830 lemma of_rat_power: |
835 "(of_rat (a ^ n)::'a::field_char_0) = of_rat a ^ n" |
831 "(of_rat (a ^ n)::'a::field_char_0) = of_rat a ^ n" |
966 apply (rule range_eqI) |
962 apply (rule range_eqI) |
967 apply (erule nonzero_of_rat_inverse [symmetric]) |
963 apply (erule nonzero_of_rat_inverse [symmetric]) |
968 done |
964 done |
969 |
965 |
970 lemma Rats_inverse [simp]: |
966 lemma Rats_inverse [simp]: |
971 fixes a :: "'a::{field_char_0,division_ring_inverse_zero}" |
967 fixes a :: "'a::{field_char_0, field_inverse_zero}" |
972 shows "a \<in> Rats \<Longrightarrow> inverse a \<in> Rats" |
968 shows "a \<in> Rats \<Longrightarrow> inverse a \<in> Rats" |
973 apply (auto simp add: Rats_def) |
969 apply (auto simp add: Rats_def) |
974 apply (rule range_eqI) |
970 apply (rule range_eqI) |
975 apply (rule of_rat_inverse [symmetric]) |
971 apply (rule of_rat_inverse [symmetric]) |
976 done |
972 done |
982 apply (rule range_eqI) |
978 apply (rule range_eqI) |
983 apply (erule nonzero_of_rat_divide [symmetric]) |
979 apply (erule nonzero_of_rat_divide [symmetric]) |
984 done |
980 done |
985 |
981 |
986 lemma Rats_divide [simp]: |
982 lemma Rats_divide [simp]: |
987 fixes a b :: "'a::{field_char_0,division_ring_inverse_zero}" |
983 fixes a b :: "'a::{field_char_0, field_inverse_zero}" |
988 shows "\<lbrakk>a \<in> Rats; b \<in> Rats\<rbrakk> \<Longrightarrow> a / b \<in> Rats" |
984 shows "\<lbrakk>a \<in> Rats; b \<in> Rats\<rbrakk> \<Longrightarrow> a / b \<in> Rats" |
989 apply (auto simp add: Rats_def) |
985 apply (auto simp add: Rats_def) |
990 apply (rule range_eqI) |
986 apply (rule range_eqI) |
991 apply (rule of_rat_divide [symmetric]) |
987 apply (rule of_rat_divide [symmetric]) |
992 done |
988 done |