src/HOL/Archimedean_Field.thy
changeset 68721 53ad5c01be3f
parent 68499 d4312962161a
child 70365 4df0628e8545
equal deleted inserted replaced
68720:1e1818612124 68721:53ad5c01be3f
   705   by (metis frac_eq_0_iff frac_ge_0 le_less less_irrefl)
   705   by (metis frac_eq_0_iff frac_ge_0 le_less less_irrefl)
   706 
   706 
   707 lemma frac_of_int [simp]: "frac (of_int z) = 0"
   707 lemma frac_of_int [simp]: "frac (of_int z) = 0"
   708   by (simp add: frac_def)
   708   by (simp add: frac_def)
   709 
   709 
       
   710 lemma frac_frac [simp]: "frac (frac x) = frac x"
       
   711   by (simp add: frac_def)
       
   712 
   710 lemma floor_add: "\<lfloor>x + y\<rfloor> = (if frac x + frac y < 1 then \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor> else (\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>) + 1)"
   713 lemma floor_add: "\<lfloor>x + y\<rfloor> = (if frac x + frac y < 1 then \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor> else (\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>) + 1)"
   711 proof -
   714 proof -
   712   have "x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>) \<Longrightarrow> \<lfloor>x + y\<rfloor> = \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>"
   715   have "x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>) \<Longrightarrow> \<lfloor>x + y\<rfloor> = \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>"
   713     by (metis add.commute floor_unique le_floor_add le_floor_iff of_int_add)
   716     by (metis add.commute floor_unique le_floor_add le_floor_iff of_int_add)
   714   moreover
   717   moreover
   740   for x :: "'a::floor_ceiling"
   743   for x :: "'a::floor_ceiling"
   741   apply (auto simp add: frac_unique_iff)
   744   apply (auto simp add: frac_unique_iff)
   742    apply (simp add: frac_def)
   745    apply (simp add: frac_def)
   743   apply (meson frac_lt_1 less_iff_diff_less_0 not_le not_less_iff_gr_or_eq)
   746   apply (meson frac_lt_1 less_iff_diff_less_0 not_le not_less_iff_gr_or_eq)
   744   done
   747   done
       
   748 
       
   749 lemma frac_in_Ints_iff [simp]: "frac x \<in> \<int> \<longleftrightarrow> x \<in> \<int>"
       
   750 proof safe
       
   751   assume "frac x \<in> \<int>"
       
   752   hence "of_int \<lfloor>x\<rfloor> + frac x \<in> \<int>" by auto
       
   753   also have "of_int \<lfloor>x\<rfloor> + frac x = x" by (simp add: frac_def)
       
   754   finally show "x \<in> \<int>" .
       
   755 qed (auto simp: frac_def)
   745 
   756 
   746 
   757 
   747 subsection \<open>Rounding to the nearest integer\<close>
   758 subsection \<open>Rounding to the nearest integer\<close>
   748 
   759 
   749 definition round :: "'a::floor_ceiling \<Rightarrow> int"
   760 definition round :: "'a::floor_ceiling \<Rightarrow> int"