src/HOL/Archimedean_Field.thy
changeset 66515 85c505c98332
parent 66154 bc5e6461f759
child 66793 deabce3ccf1f
equal deleted inserted replaced
66511:9756684f4d74 66515:85c505c98332
   222   assumes floor_correct: "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)"
   222   assumes floor_correct: "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)"
   223 
   223 
   224 lemma floor_unique: "of_int z \<le> x \<Longrightarrow> x < of_int z + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = z"
   224 lemma floor_unique: "of_int z \<le> x \<Longrightarrow> x < of_int z + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = z"
   225   using floor_correct [of x] floor_exists1 [of x] by auto
   225   using floor_correct [of x] floor_exists1 [of x] by auto
   226 
   226 
   227 lemma floor_unique_iff: "\<lfloor>x\<rfloor> = a \<longleftrightarrow> of_int a \<le> x \<and> x < of_int a + 1"
   227 lemma floor_eq_iff: "\<lfloor>x\<rfloor> = a \<longleftrightarrow> of_int a \<le> x \<and> x < of_int a + 1"
   228   for x :: "'a::floor_ceiling"
   228 using floor_correct floor_unique by auto
   229   using floor_correct floor_unique by auto
       
   230 
   229 
   231 lemma of_int_floor_le [simp]: "of_int \<lfloor>x\<rfloor> \<le> x"
   230 lemma of_int_floor_le [simp]: "of_int \<lfloor>x\<rfloor> \<le> x"
   232   using floor_correct ..
   231   using floor_correct ..
   233 
   232 
   234 lemma le_floor_iff: "z \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z \<le> x"
   233 lemma le_floor_iff: "z \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z \<le> x"
   465   by (simp add: le_minus_iff)
   464   by (simp add: le_minus_iff)
   466 
   465 
   467 lemma ceiling_unique: "of_int z - 1 < x \<Longrightarrow> x \<le> of_int z \<Longrightarrow> \<lceil>x\<rceil> = z"
   466 lemma ceiling_unique: "of_int z - 1 < x \<Longrightarrow> x \<le> of_int z \<Longrightarrow> \<lceil>x\<rceil> = z"
   468   unfolding ceiling_def using floor_unique [of "- z" "- x"] by simp
   467   unfolding ceiling_def using floor_unique [of "- z" "- x"] by simp
   469 
   468 
       
   469 lemma ceiling_eq_iff: "\<lceil>x\<rceil> = a \<longleftrightarrow> of_int a - 1 < x \<and> x \<le> of_int a"
       
   470 using ceiling_correct ceiling_unique by auto
       
   471 
   470 lemma le_of_int_ceiling [simp]: "x \<le> of_int \<lceil>x\<rceil>"
   472 lemma le_of_int_ceiling [simp]: "x \<le> of_int \<lceil>x\<rceil>"
   471   using ceiling_correct ..
   473   using ceiling_correct ..
   472 
   474 
   473 lemma ceiling_le_iff: "\<lceil>x\<rceil> \<le> z \<longleftrightarrow> x \<le> of_int z"
   475 lemma ceiling_le_iff: "\<lceil>x\<rceil> \<le> z \<longleftrightarrow> x \<le> of_int z"
   474   unfolding ceiling_def using le_floor_iff [of "- z" "- x"] by auto
   476   unfolding ceiling_def using le_floor_iff [of "- z" "- x"] by auto
   671 proof -
   673 proof -
   672   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>"
   674   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>"
   673     by (metis add.commute floor_unique le_floor_add le_floor_iff of_int_add)
   675     by (metis add.commute floor_unique le_floor_add le_floor_iff of_int_add)
   674   moreover
   676   moreover
   675   have "\<not> x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>) \<Longrightarrow> \<lfloor>x + y\<rfloor> = 1 + (\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>)"
   677   have "\<not> x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>) \<Longrightarrow> \<lfloor>x + y\<rfloor> = 1 + (\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>)"
   676     apply (simp add: floor_unique_iff)
   678     apply (simp add: floor_eq_iff)
   677     apply (auto simp add: algebra_simps)
   679     apply (auto simp add: algebra_simps)
   678     apply linarith
   680     apply linarith
   679     done
   681     done
   680   ultimately show ?thesis by (auto simp add: frac_def algebra_simps)
   682   ultimately show ?thesis by (auto simp add: frac_def algebra_simps)
   681 qed
   683 qed
   725   with A show "\<bar>of_int (round x) - x\<bar> \<le> 1/2"
   727   with A show "\<bar>of_int (round x) - x\<bar> \<le> 1/2"
   726     by linarith
   728     by linarith
   727 qed
   729 qed
   728 
   730 
   729 lemma round_of_int [simp]: "round (of_int n) = n"
   731 lemma round_of_int [simp]: "round (of_int n) = n"
   730   unfolding round_def by (subst floor_unique_iff) force
   732   unfolding round_def by (subst floor_eq_iff) force
   731 
   733 
   732 lemma round_0 [simp]: "round 0 = 0"
   734 lemma round_0 [simp]: "round 0 = 0"
   733   using round_of_int[of 0] by simp
   735   using round_of_int[of 0] by simp
   734 
   736 
   735 lemma round_1 [simp]: "round 1 = 1"
   737 lemma round_1 [simp]: "round 1 = 1"