806 subsection \<open>The Set of Rational Numbers\<close> |
806 subsection \<open>The Set of Rational Numbers\<close> |
807 |
807 |
808 context field_char_0 |
808 context field_char_0 |
809 begin |
809 begin |
810 |
810 |
811 definition |
811 definition Rats :: "'a set" ("\<rat>") |
812 Rats :: "'a set" where |
812 where "\<rat> = range of_rat" |
813 "Rats = range of_rat" |
813 |
814 |
814 end |
815 notation (xsymbols) |
815 |
816 Rats ("\<rat>") |
816 lemma Rats_of_rat [simp]: "of_rat r \<in> \<rat>" |
817 |
|
818 end |
|
819 |
|
820 lemma Rats_of_rat [simp]: "of_rat r \<in> Rats" |
|
821 by (simp add: Rats_def) |
817 by (simp add: Rats_def) |
822 |
818 |
823 lemma Rats_of_int [simp]: "of_int z \<in> Rats" |
819 lemma Rats_of_int [simp]: "of_int z \<in> \<rat>" |
824 by (subst of_rat_of_int_eq [symmetric], rule Rats_of_rat) |
820 by (subst of_rat_of_int_eq [symmetric], rule Rats_of_rat) |
825 |
821 |
826 lemma Rats_of_nat [simp]: "of_nat n \<in> Rats" |
822 lemma Rats_of_nat [simp]: "of_nat n \<in> \<rat>" |
827 by (subst of_rat_of_nat_eq [symmetric], rule Rats_of_rat) |
823 by (subst of_rat_of_nat_eq [symmetric], rule Rats_of_rat) |
828 |
824 |
829 lemma Rats_number_of [simp]: "numeral w \<in> Rats" |
825 lemma Rats_number_of [simp]: "numeral w \<in> \<rat>" |
830 by (subst of_rat_numeral_eq [symmetric], rule Rats_of_rat) |
826 by (subst of_rat_numeral_eq [symmetric], rule Rats_of_rat) |
831 |
827 |
832 lemma Rats_0 [simp]: "0 \<in> Rats" |
828 lemma Rats_0 [simp]: "0 \<in> \<rat>" |
833 apply (unfold Rats_def) |
829 apply (unfold Rats_def) |
834 apply (rule range_eqI) |
830 apply (rule range_eqI) |
835 apply (rule of_rat_0 [symmetric]) |
831 apply (rule of_rat_0 [symmetric]) |
836 done |
832 done |
837 |
833 |
838 lemma Rats_1 [simp]: "1 \<in> Rats" |
834 lemma Rats_1 [simp]: "1 \<in> \<rat>" |
839 apply (unfold Rats_def) |
835 apply (unfold Rats_def) |
840 apply (rule range_eqI) |
836 apply (rule range_eqI) |
841 apply (rule of_rat_1 [symmetric]) |
837 apply (rule of_rat_1 [symmetric]) |
842 done |
838 done |
843 |
839 |
844 lemma Rats_add [simp]: "\<lbrakk>a \<in> Rats; b \<in> Rats\<rbrakk> \<Longrightarrow> a + b \<in> Rats" |
840 lemma Rats_add [simp]: "\<lbrakk>a \<in> \<rat>; b \<in> \<rat>\<rbrakk> \<Longrightarrow> a + b \<in> \<rat>" |
845 apply (auto simp add: Rats_def) |
841 apply (auto simp add: Rats_def) |
846 apply (rule range_eqI) |
842 apply (rule range_eqI) |
847 apply (rule of_rat_add [symmetric]) |
843 apply (rule of_rat_add [symmetric]) |
848 done |
844 done |
849 |
845 |
850 lemma Rats_minus [simp]: "a \<in> Rats \<Longrightarrow> - a \<in> Rats" |
846 lemma Rats_minus [simp]: "a \<in> \<rat> \<Longrightarrow> - a \<in> \<rat>" |
851 apply (auto simp add: Rats_def) |
847 apply (auto simp add: Rats_def) |
852 apply (rule range_eqI) |
848 apply (rule range_eqI) |
853 apply (rule of_rat_minus [symmetric]) |
849 apply (rule of_rat_minus [symmetric]) |
854 done |
850 done |
855 |
851 |
856 lemma Rats_diff [simp]: "\<lbrakk>a \<in> Rats; b \<in> Rats\<rbrakk> \<Longrightarrow> a - b \<in> Rats" |
852 lemma Rats_diff [simp]: "\<lbrakk>a \<in> \<rat>; b \<in> \<rat>\<rbrakk> \<Longrightarrow> a - b \<in> \<rat>" |
857 apply (auto simp add: Rats_def) |
853 apply (auto simp add: Rats_def) |
858 apply (rule range_eqI) |
854 apply (rule range_eqI) |
859 apply (rule of_rat_diff [symmetric]) |
855 apply (rule of_rat_diff [symmetric]) |
860 done |
856 done |
861 |
857 |
862 lemma Rats_mult [simp]: "\<lbrakk>a \<in> Rats; b \<in> Rats\<rbrakk> \<Longrightarrow> a * b \<in> Rats" |
858 lemma Rats_mult [simp]: "\<lbrakk>a \<in> \<rat>; b \<in> \<rat>\<rbrakk> \<Longrightarrow> a * b \<in> \<rat>" |
863 apply (auto simp add: Rats_def) |
859 apply (auto simp add: Rats_def) |
864 apply (rule range_eqI) |
860 apply (rule range_eqI) |
865 apply (rule of_rat_mult [symmetric]) |
861 apply (rule of_rat_mult [symmetric]) |
866 done |
862 done |
867 |
863 |
868 lemma nonzero_Rats_inverse: |
864 lemma nonzero_Rats_inverse: |
869 fixes a :: "'a::field_char_0" |
865 fixes a :: "'a::field_char_0" |
870 shows "\<lbrakk>a \<in> Rats; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> Rats" |
866 shows "\<lbrakk>a \<in> \<rat>; a \<noteq> 0\<rbrakk> \<Longrightarrow> inverse a \<in> \<rat>" |
871 apply (auto simp add: Rats_def) |
867 apply (auto simp add: Rats_def) |
872 apply (rule range_eqI) |
868 apply (rule range_eqI) |
873 apply (erule nonzero_of_rat_inverse [symmetric]) |
869 apply (erule nonzero_of_rat_inverse [symmetric]) |
874 done |
870 done |
875 |
871 |
876 lemma Rats_inverse [simp]: |
872 lemma Rats_inverse [simp]: |
877 fixes a :: "'a::{field_char_0, field}" |
873 fixes a :: "'a::{field_char_0, field}" |
878 shows "a \<in> Rats \<Longrightarrow> inverse a \<in> Rats" |
874 shows "a \<in> \<rat> \<Longrightarrow> inverse a \<in> \<rat>" |
879 apply (auto simp add: Rats_def) |
875 apply (auto simp add: Rats_def) |
880 apply (rule range_eqI) |
876 apply (rule range_eqI) |
881 apply (rule of_rat_inverse [symmetric]) |
877 apply (rule of_rat_inverse [symmetric]) |
882 done |
878 done |
883 |
879 |
884 lemma nonzero_Rats_divide: |
880 lemma nonzero_Rats_divide: |
885 fixes a b :: "'a::field_char_0" |
881 fixes a b :: "'a::field_char_0" |
886 shows "\<lbrakk>a \<in> Rats; b \<in> Rats; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> Rats" |
882 shows "\<lbrakk>a \<in> \<rat>; b \<in> \<rat>; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / b \<in> \<rat>" |
887 apply (auto simp add: Rats_def) |
883 apply (auto simp add: Rats_def) |
888 apply (rule range_eqI) |
884 apply (rule range_eqI) |
889 apply (erule nonzero_of_rat_divide [symmetric]) |
885 apply (erule nonzero_of_rat_divide [symmetric]) |
890 done |
886 done |
891 |
887 |
892 lemma Rats_divide [simp]: |
888 lemma Rats_divide [simp]: |
893 fixes a b :: "'a::{field_char_0, field}" |
889 fixes a b :: "'a::{field_char_0, field}" |
894 shows "\<lbrakk>a \<in> Rats; b \<in> Rats\<rbrakk> \<Longrightarrow> a / b \<in> Rats" |
890 shows "\<lbrakk>a \<in> \<rat>; b \<in> \<rat>\<rbrakk> \<Longrightarrow> a / b \<in> \<rat>" |
895 apply (auto simp add: Rats_def) |
891 apply (auto simp add: Rats_def) |
896 apply (rule range_eqI) |
892 apply (rule range_eqI) |
897 apply (rule of_rat_divide [symmetric]) |
893 apply (rule of_rat_divide [symmetric]) |
898 done |
894 done |
899 |
895 |
900 lemma Rats_power [simp]: |
896 lemma Rats_power [simp]: |
901 fixes a :: "'a::field_char_0" |
897 fixes a :: "'a::field_char_0" |
902 shows "a \<in> Rats \<Longrightarrow> a ^ n \<in> Rats" |
898 shows "a \<in> \<rat> \<Longrightarrow> a ^ n \<in> \<rat>" |
903 apply (auto simp add: Rats_def) |
899 apply (auto simp add: Rats_def) |
904 apply (rule range_eqI) |
900 apply (rule range_eqI) |
905 apply (rule of_rat_power [symmetric]) |
901 apply (rule of_rat_power [symmetric]) |
906 done |
902 done |
907 |
903 |