src/HOL/Rational.thy
changeset 30273 ecd6f0ca62ea
parent 30242 aea5d7fa7ef5
child 30649 57753e0ec1d4
equal deleted inserted replaced
30268:5af6ed62385b 30273:ecd6f0ca62ea
   156   then show ?thesis by (simp add: mult_rat [symmetric])
   156   then show ?thesis by (simp add: mult_rat [symmetric])
   157 qed
   157 qed
   158 
   158 
   159 primrec power_rat
   159 primrec power_rat
   160 where
   160 where
   161   rat_power_0:     "q ^ 0 = (1\<Colon>rat)"
   161   "q ^ 0 = (1\<Colon>rat)"
   162   | rat_power_Suc: "q ^ Suc n = (q\<Colon>rat) * (q ^ n)"
   162 | "q ^ Suc n = (q\<Colon>rat) * (q ^ n)"
   163 
   163 
   164 instance proof
   164 instance proof
   165   fix q r s :: rat show "(q * r) * s = q * (r * s)" 
   165   fix q r s :: rat show "(q * r) * s = q * (r * s)" 
   166     by (cases q, cases r, cases s) (simp add: eq_rat)
   166     by (cases q, cases r, cases s) (simp add: eq_rat)
   167 next
   167 next
   197   fix q :: rat
   197   fix q :: rat
   198   fix n :: nat
   198   fix n :: nat
   199   show "q ^ 0 = 1" by simp
   199   show "q ^ 0 = 1" by simp
   200   show "q ^ (Suc n) = q * (q ^ n)" by simp
   200   show "q ^ (Suc n) = q * (q ^ n)" by simp
   201 qed
   201 qed
       
   202 
       
   203 declare power_rat.simps [simp del]
   202 
   204 
   203 end
   205 end
   204 
   206 
   205 lemma of_nat_rat: "of_nat k = Fract (of_nat k) 1"
   207 lemma of_nat_rat: "of_nat k = Fract (of_nat k) 1"
   206   by (induct k) (simp_all add: Zero_rat_def One_rat_def)
   208   by (induct k) (simp_all add: Zero_rat_def One_rat_def)
   664    = of_rat a / of_rat b"
   666    = of_rat a / of_rat b"
   665 by (cases "b = 0") (simp_all add: nonzero_of_rat_divide)
   667 by (cases "b = 0") (simp_all add: nonzero_of_rat_divide)
   666 
   668 
   667 lemma of_rat_power:
   669 lemma of_rat_power:
   668   "(of_rat (a ^ n)::'a::{field_char_0,recpower}) = of_rat a ^ n"
   670   "(of_rat (a ^ n)::'a::{field_char_0,recpower}) = of_rat a ^ n"
   669 by (induct n) (simp_all add: of_rat_mult power_Suc)
   671 by (induct n) (simp_all add: of_rat_mult)
   670 
   672 
   671 lemma of_rat_eq_iff [simp]: "(of_rat a = of_rat b) = (a = b)"
   673 lemma of_rat_eq_iff [simp]: "(of_rat a = of_rat b) = (a = b)"
   672 apply (induct a, induct b)
   674 apply (induct a, induct b)
   673 apply (simp add: of_rat_rat eq_rat)
   675 apply (simp add: of_rat_rat eq_rat)
   674 apply (simp add: nonzero_divide_eq_eq nonzero_eq_divide_eq)
   676 apply (simp add: nonzero_divide_eq_eq nonzero_eq_divide_eq)