src/HOL/Rat.thy
changeset 61942 f02b26f7d39d
parent 61799 4cf66f21b764
child 61944 5d06ecfdb472
equal deleted inserted replaced
61941:31f2105521ee 61942:f02b26f7d39d
   597 
   597 
   598 instantiation rat :: floor_ceiling
   598 instantiation rat :: floor_ceiling
   599 begin
   599 begin
   600 
   600 
   601 definition [code del]:
   601 definition [code del]:
   602   "floor (x::rat) = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))"
   602   "\<lfloor>x::rat\<rfloor> = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))"
   603 
   603 
   604 instance proof
   604 instance
       
   605 proof
   605   fix x :: rat
   606   fix x :: rat
   606   show "of_int (floor x) \<le> x \<and> x < of_int (floor x + 1)"
   607   show "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)"
   607     unfolding floor_rat_def using floor_exists1 by (rule theI')
   608     unfolding floor_rat_def using floor_exists1 by (rule theI')
   608 qed
   609 qed
   609 
   610 
   610 end
   611 end
   611 
   612 
   612 lemma floor_Fract: "floor (Fract a b) = a div b"
   613 lemma floor_Fract: "\<lfloor>Fract a b\<rfloor> = a div b"
   613   by (simp add: Fract_of_int_quotient floor_divide_of_int_eq)
   614   by (simp add: Fract_of_int_quotient floor_divide_of_int_eq)
   614 
   615 
   615 
   616 
   616 subsection \<open>Linear arithmetic setup\<close>
   617 subsection \<open>Linear arithmetic setup\<close>
   617 
   618 
  1015   case (Fract a b) then show ?thesis
  1016   case (Fract a b) then show ?thesis
  1016   by (cases "0::int" a rule: linorder_cases) (simp_all add: quotient_of_Fract)
  1017   by (cases "0::int" a rule: linorder_cases) (simp_all add: quotient_of_Fract)
  1017 qed
  1018 qed
  1018 
  1019 
  1019 lemma rat_floor_code [code]:
  1020 lemma rat_floor_code [code]:
  1020   "floor p = (let (a, b) = quotient_of p in a div b)"
  1021   "\<lfloor>p\<rfloor> = (let (a, b) = quotient_of p in a div b)"
  1021 by (cases p) (simp add: quotient_of_Fract floor_Fract)
  1022   by (cases p) (simp add: quotient_of_Fract floor_Fract)
  1022 
  1023 
  1023 instantiation rat :: equal
  1024 instantiation rat :: equal
  1024 begin
  1025 begin
  1025 
  1026 
  1026 definition [code]:
  1027 definition [code]: