src/HOL/Real/Rational.thy
changeset 23343 6a83ca5fe282
parent 23342 0261d2da0b1c
child 23365 f31794033ae1
equal deleted inserted replaced
23342:0261d2da0b1c 23343:6a83ca5fe282
   506 by (simp add: One_rat_def of_rat_rat)
   506 by (simp add: One_rat_def of_rat_rat)
   507 
   507 
   508 lemma of_rat_add: "of_rat (a + b) = of_rat a + of_rat b"
   508 lemma of_rat_add: "of_rat (a + b) = of_rat a + of_rat b"
   509 by (induct a, induct b, simp add: add_rat of_rat_rat add_frac_eq)
   509 by (induct a, induct b, simp add: add_rat of_rat_rat add_frac_eq)
   510 
   510 
       
   511 lemma of_rat_minus: "of_rat (- a) = - of_rat a"
       
   512 by (induct a, simp add: minus_rat of_rat_rat)
       
   513 
       
   514 lemma of_rat_diff: "of_rat (a - b) = of_rat a - of_rat b"
       
   515 by (simp only: diff_minus of_rat_add of_rat_minus)
       
   516 
   511 lemma of_rat_mult: "of_rat (a * b) = of_rat a * of_rat b"
   517 lemma of_rat_mult: "of_rat (a * b) = of_rat a * of_rat b"
   512 apply (induct a, induct b, simp add: mult_rat of_rat_rat)
   518 apply (induct a, induct b, simp add: mult_rat of_rat_rat)
   513 apply (simp add: divide_inverse nonzero_inverse_mult_distrib mult_ac)
   519 apply (simp add: divide_inverse nonzero_inverse_mult_distrib mult_ac)
   514 done
   520 done
   515 
   521 
   516 lemma nonzero_inverse_divide:
       
   517   fixes a b :: "'a::field"
       
   518   shows "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> inverse (a / b) = b / a"
       
   519 apply (simp add: divide_inverse)
       
   520 apply (simp add: nonzero_inverse_mult_distrib nonzero_imp_inverse_nonzero)
       
   521 apply (simp add: nonzero_inverse_inverse_eq)
       
   522 done
       
   523 
       
   524 lemma nonzero_of_rat_inverse:
   522 lemma nonzero_of_rat_inverse:
   525   "a \<noteq> 0 \<Longrightarrow> of_rat (inverse a) = inverse (of_rat a)"
   523   "a \<noteq> 0 \<Longrightarrow> of_rat (inverse a) = inverse (of_rat a)"
   526 apply (induct a)
   524 apply (rule inverse_unique [symmetric])
   527 apply (simp add: Zero_rat_def inverse_rat eq_rat of_rat_rat)
   525 apply (simp add: of_rat_mult [symmetric])
   528 apply (simp add: nonzero_inverse_divide)
       
   529 done
   526 done
   530 
   527 
   531 lemma of_rat_inverse:
   528 lemma of_rat_inverse:
   532   "(of_rat (inverse a)::'a::{field_char_0,division_by_zero}) =
   529   "(of_rat (inverse a)::'a::{field_char_0,division_by_zero}) =
   533    inverse (of_rat a)"
   530    inverse (of_rat a)"
   540 lemma of_rat_divide:
   537 lemma of_rat_divide:
   541   "(of_rat (a / b)::'a::{field_char_0,division_by_zero})
   538   "(of_rat (a / b)::'a::{field_char_0,division_by_zero})
   542    = of_rat a / of_rat b"
   539    = of_rat a / of_rat b"
   543 by (cases "b = 0", simp_all add: nonzero_of_rat_divide)
   540 by (cases "b = 0", simp_all add: nonzero_of_rat_divide)
   544 
   541 
       
   542 lemma of_rat_power:
       
   543   "(of_rat (a ^ n)::'a::{field_char_0,recpower}) = of_rat a ^ n"
       
   544 by (induct n) (simp_all add: of_rat_mult power_Suc)
       
   545 
       
   546 lemma of_rat_eq_iff [simp]: "(of_rat a = of_rat b) = (a = b)"
       
   547 apply (induct a, induct b)
       
   548 apply (simp add: of_rat_rat eq_rat)
       
   549 apply (simp add: nonzero_divide_eq_eq nonzero_eq_divide_eq)
       
   550 apply (simp only: of_int_mult [symmetric] of_int_eq_iff)
       
   551 done
       
   552 
       
   553 lemmas of_rat_eq_0_iff [simp] = of_rat_eq_iff [of _ 0, simplified]
       
   554 
       
   555 lemma of_rat_eq_id [simp]: "of_rat = (id :: rat \<Rightarrow> rat)"
       
   556 proof
       
   557   fix a
       
   558   show "of_rat a = id a"
       
   559   by (induct a)
       
   560      (simp add: of_rat_rat divide_rat Fract_of_int_eq [symmetric])
       
   561 qed
       
   562 
       
   563 text{*Collapse nested embeddings*}
       
   564 lemma of_rat_of_nat_eq [simp]: "of_rat (of_nat n) = of_nat n"
       
   565 by (induct n) (simp_all add: of_rat_add)
       
   566 
       
   567 lemma of_rat_of_int_eq [simp]: "of_rat (of_int z) = of_int z"
       
   568 by (cases z rule: int_diff_cases', simp add: of_rat_diff)
       
   569 
       
   570 lemma of_rat_number_of_eq [simp]:
       
   571   "of_rat (number_of w) = (number_of w :: 'a::{number_ring,field_char_0})"
       
   572 by (simp add: number_of_eq)
       
   573 
   545 end
   574 end