655 fixes z :: "'a :: floor_ceiling" |
655 fixes z :: "'a :: floor_ceiling" |
656 shows "abs (z - of_int (round z)) \<le> abs (z - of_int m)" |
656 shows "abs (z - of_int (round z)) \<le> abs (z - of_int m)" |
657 proof (cases "of_int m \<ge> z") |
657 proof (cases "of_int m \<ge> z") |
658 case True |
658 case True |
659 hence "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int (ceiling z) - z\<bar>" |
659 hence "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int (ceiling z) - z\<bar>" |
660 unfolding round_altdef by (simp add: ceiling_altdef frac_def) linarith? |
660 unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith? |
661 also have "of_int \<lceil>z\<rceil> - z \<ge> 0" by linarith |
661 also have "of_int \<lceil>z\<rceil> - z \<ge> 0" by linarith |
662 with True have "\<bar>of_int (ceiling z) - z\<bar> \<le> \<bar>z - of_int m\<bar>" |
662 with True have "\<bar>of_int (ceiling z) - z\<bar> \<le> \<bar>z - of_int m\<bar>" |
663 by (simp add: ceiling_le_iff) |
663 by (simp add: ceiling_le_iff) |
664 finally show ?thesis . |
664 finally show ?thesis . |
665 next |
665 next |
666 case False |
666 case False |
667 hence "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int (floor z) - z\<bar>" |
667 hence "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int (floor z) - z\<bar>" |
668 unfolding round_altdef by (simp add: ceiling_altdef frac_def) linarith? |
668 unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith? |
669 also have "z - of_int \<lfloor>z\<rfloor> \<ge> 0" by linarith |
669 also have "z - of_int \<lfloor>z\<rfloor> \<ge> 0" by linarith |
670 with False have "\<bar>of_int (floor z) - z\<bar> \<le> \<bar>z - of_int m\<bar>" |
670 with False have "\<bar>of_int (floor z) - z\<bar> \<le> \<bar>z - of_int m\<bar>" |
671 by (simp add: le_floor_iff) |
671 by (simp add: le_floor_iff) |
672 finally show ?thesis . |
672 finally show ?thesis . |
673 qed |
673 qed |