equal
deleted
inserted
replaced
88 shows "\<And>a b c d. b \<noteq> 0 \<Longrightarrow> d \<noteq> 0 \<Longrightarrow> Fract a b = Fract c d \<longleftrightarrow> a * d = c * b" |
88 shows "\<And>a b c d. b \<noteq> 0 \<Longrightarrow> d \<noteq> 0 \<Longrightarrow> Fract a b = Fract c d \<longleftrightarrow> a * d = c * b" |
89 and "\<And>a. Fract a 0 = Fract 0 1" |
89 and "\<And>a. Fract a 0 = Fract 0 1" |
90 and "\<And>a c. Fract 0 a = Fract 0 c" |
90 and "\<And>a c. Fract 0 a = Fract 0 c" |
91 by (simp_all add: Fract_def) |
91 by (simp_all add: Fract_def) |
92 |
92 |
93 instantiation rat :: "{comm_ring_1, recpower}" |
93 instantiation rat :: comm_ring_1 |
94 begin |
94 begin |
95 |
95 |
96 definition |
96 definition |
97 Zero_rat_def [code, code unfold]: "0 = Fract 0 1" |
97 Zero_rat_def [code, code unfold]: "0 = Fract 0 1" |
98 |
98 |
183 next |
183 next |
184 fix q r s :: rat show "(q + r) * s = q * s + r * s" |
184 fix q r s :: rat show "(q + r) * s = q * s + r * s" |
185 by (cases q, cases r, cases s) (simp add: eq_rat algebra_simps) |
185 by (cases q, cases r, cases s) (simp add: eq_rat algebra_simps) |
186 next |
186 next |
187 show "(0::rat) \<noteq> 1" by (simp add: Zero_rat_def One_rat_def eq_rat) |
187 show "(0::rat) \<noteq> 1" by (simp add: Zero_rat_def One_rat_def eq_rat) |
188 next |
|
189 fix q :: rat show "q * 1 = q" |
|
190 by (cases q) (simp add: One_rat_def eq_rat) |
|
191 qed |
188 qed |
192 |
189 |
193 end |
190 end |
194 |
191 |
195 lemma of_nat_rat: "of_nat k = Fract (of_nat k) 1" |
192 lemma of_nat_rat: "of_nat k = Fract (of_nat k) 1" |
654 "(of_rat (a / b)::'a::{field_char_0,division_by_zero}) |
651 "(of_rat (a / b)::'a::{field_char_0,division_by_zero}) |
655 = of_rat a / of_rat b" |
652 = of_rat a / of_rat b" |
656 by (cases "b = 0") (simp_all add: nonzero_of_rat_divide) |
653 by (cases "b = 0") (simp_all add: nonzero_of_rat_divide) |
657 |
654 |
658 lemma of_rat_power: |
655 lemma of_rat_power: |
659 "(of_rat (a ^ n)::'a::{field_char_0,recpower}) = of_rat a ^ n" |
656 "(of_rat (a ^ n)::'a::field_char_0) = of_rat a ^ n" |
660 by (induct n) (simp_all add: of_rat_mult) |
657 by (induct n) (simp_all add: of_rat_mult) |
661 |
658 |
662 lemma of_rat_eq_iff [simp]: "(of_rat a = of_rat b) = (a = b)" |
659 lemma of_rat_eq_iff [simp]: "(of_rat a = of_rat b) = (a = b)" |
663 apply (induct a, induct b) |
660 apply (induct a, induct b) |
664 apply (simp add: of_rat_rat eq_rat) |
661 apply (simp add: of_rat_rat eq_rat) |
814 apply (rule range_eqI) |
811 apply (rule range_eqI) |
815 apply (rule of_rat_divide [symmetric]) |
812 apply (rule of_rat_divide [symmetric]) |
816 done |
813 done |
817 |
814 |
818 lemma Rats_power [simp]: |
815 lemma Rats_power [simp]: |
819 fixes a :: "'a::{field_char_0,recpower}" |
816 fixes a :: "'a::field_char_0" |
820 shows "a \<in> Rats \<Longrightarrow> a ^ n \<in> Rats" |
817 shows "a \<in> Rats \<Longrightarrow> a ^ n \<in> Rats" |
821 apply (auto simp add: Rats_def) |
818 apply (auto simp add: Rats_def) |
822 apply (rule range_eqI) |
819 apply (rule range_eqI) |
823 apply (rule of_rat_power [symmetric]) |
820 apply (rule of_rat_power [symmetric]) |
824 done |
821 done |
834 qed |
831 qed |
835 |
832 |
836 lemma Rats_induct [case_names of_rat, induct set: Rats]: |
833 lemma Rats_induct [case_names of_rat, induct set: Rats]: |
837 "q \<in> \<rat> \<Longrightarrow> (\<And>r. P (of_rat r)) \<Longrightarrow> P q" |
834 "q \<in> \<rat> \<Longrightarrow> (\<And>r. P (of_rat r)) \<Longrightarrow> P q" |
838 by (rule Rats_cases) auto |
835 by (rule Rats_cases) auto |
|
836 |
|
837 instance rat :: recpower .. |
839 |
838 |
840 |
839 |
841 subsection {* Implementation of rational numbers as pairs of integers *} |
840 subsection {* Implementation of rational numbers as pairs of integers *} |
842 |
841 |
843 lemma Fract_norm: "Fract (a div zgcd a b) (b div zgcd a b) = Fract a b" |
842 lemma Fract_norm: "Fract (a div zgcd a b) (b div zgcd a b) = Fract a b" |