448 |
448 |
449 lemma uint_sint: |
449 lemma uint_sint: |
450 "uint w = bintrunc (len_of TYPE('a)) (sint (w :: 'a :: len word))" |
450 "uint w = bintrunc (len_of TYPE('a)) (sint (w :: 'a :: len word))" |
451 unfolding sint_uint by (auto simp: bintrunc_sbintrunc_le) |
451 unfolding sint_uint by (auto simp: bintrunc_sbintrunc_le) |
452 |
452 |
453 lemma bintr_uint': |
453 lemma bintr_uint: |
454 "n >= size w \<Longrightarrow> bintrunc n (uint w) = uint w" |
454 fixes w :: "'a::len0 word" |
455 apply (unfold word_size) |
455 shows "len_of TYPE('a) \<le> n \<Longrightarrow> bintrunc n (uint w) = uint w" |
456 apply (subst word_ubin.norm_Rep [symmetric]) |
456 apply (subst word_ubin.norm_Rep [symmetric]) |
457 apply (simp only: bintrunc_bintrunc_min word_size) |
457 apply (simp only: bintrunc_bintrunc_min word_size) |
458 apply (simp add: min_max.inf_absorb2) |
458 apply (simp add: min_max.inf_absorb2) |
459 done |
459 done |
460 |
460 |
461 lemma wi_bintr': |
461 lemma wi_bintr: |
462 "wb = word_of_int bin \<Longrightarrow> n >= size wb \<Longrightarrow> |
462 "len_of TYPE('a::len0) \<le> n \<Longrightarrow> |
463 word_of_int (bintrunc n bin) = wb" |
463 word_of_int (bintrunc n w) = (word_of_int w :: 'a word)" |
464 unfolding word_size |
|
465 by (clarsimp simp add: word_ubin.norm_eq_iff [symmetric] min_max.inf_absorb1) |
464 by (clarsimp simp add: word_ubin.norm_eq_iff [symmetric] min_max.inf_absorb1) |
466 |
|
467 lemmas bintr_uint = bintr_uint' [unfolded word_size] |
|
468 lemmas wi_bintr = wi_bintr' [unfolded word_size] |
|
469 |
465 |
470 lemma td_ext_sbin: |
466 lemma td_ext_sbin: |
471 "td_ext (sint :: 'a word => int) word_of_int (sints (len_of TYPE('a::len))) |
467 "td_ext (sint :: 'a word => int) word_of_int (sints (len_of TYPE('a::len))) |
472 (sbintrunc (len_of TYPE('a) - 1))" |
468 (sbintrunc (len_of TYPE('a) - 1))" |
473 apply (unfold td_ext_def' sint_uint) |
469 apply (unfold td_ext_def' sint_uint) |
680 unfolding word_test_bit_def word_size |
676 unfolding word_test_bit_def word_size |
681 by (simp add: nth_bintr [symmetric]) |
677 by (simp add: nth_bintr [symmetric]) |
682 |
678 |
683 lemmas test_bit_bin = test_bit_bin' [unfolded word_size] |
679 lemmas test_bit_bin = test_bit_bin' [unfolded word_size] |
684 |
680 |
685 lemma bin_nth_uint_imp': "bin_nth (uint w) n --> n < size w" |
681 lemma bin_nth_uint_imp: |
686 apply (unfold word_size) |
682 "bin_nth (uint (w::'a::len0 word)) n \<Longrightarrow> n < len_of TYPE('a)" |
687 apply (rule impI) |
|
688 apply (rule nth_bintr [THEN iffD1, THEN conjunct1]) |
683 apply (rule nth_bintr [THEN iffD1, THEN conjunct1]) |
689 apply (subst word_ubin.norm_Rep) |
684 apply (subst word_ubin.norm_Rep) |
690 apply assumption |
685 apply assumption |
691 done |
686 done |
692 |
687 |
693 lemma bin_nth_sint': |
688 lemma bin_nth_sint: |
694 "n >= size w --> bin_nth (sint w) n = bin_nth (sint w) (size w - 1)" |
689 fixes w :: "'a::len word" |
695 apply (rule impI) |
690 shows "len_of TYPE('a) \<le> n \<Longrightarrow> |
|
691 bin_nth (sint w) n = bin_nth (sint w) (len_of TYPE('a) - 1)" |
696 apply (subst word_sbin.norm_Rep [symmetric]) |
692 apply (subst word_sbin.norm_Rep [symmetric]) |
697 apply (simp add : nth_sbintr word_size) |
693 apply (auto simp add: nth_sbintr) |
698 apply auto |
694 done |
699 done |
|
700 |
|
701 lemmas bin_nth_uint_imp = bin_nth_uint_imp' [rule_format, unfolded word_size] |
|
702 lemmas bin_nth_sint = bin_nth_sint' [rule_format, unfolded word_size] |
|
703 |
695 |
704 (* type definitions theorem for in terms of equivalent bool list *) |
696 (* type definitions theorem for in terms of equivalent bool list *) |
705 lemma td_bl: |
697 lemma td_bl: |
706 "type_definition (to_bl :: 'a::len0 word => bool list) |
698 "type_definition (to_bl :: 'a::len0 word => bool list) |
707 of_bl |
699 of_bl |
2895 "(sshiftr1 (number_of w) :: 'a :: len word) = |
2887 "(sshiftr1 (number_of w) :: 'a :: len word) = |
2896 number_of (bin_rest (sbintrunc (len_of TYPE ('a) - 1) w))" |
2888 number_of (bin_rest (sbintrunc (len_of TYPE ('a) - 1) w))" |
2897 unfolding sshiftr1_def word_number_of_def |
2889 unfolding sshiftr1_def word_number_of_def |
2898 by (simp add : word_sbin.eq_norm) |
2890 by (simp add : word_sbin.eq_norm) |
2899 |
2891 |
2900 lemma shiftr_no': |
2892 lemma shiftr_no [simp]: |
2901 "w = number_of bin \<Longrightarrow> |
2893 "(number_of w::'a::len0 word) >> n = word_of_int |
2902 (w::'a::len0 word) >> n = word_of_int ((bin_rest ^^ n) (bintrunc (size w) (number_of bin)))" |
2894 ((bin_rest ^^ n) (bintrunc (len_of TYPE('a)) (number_of w)))" |
2903 apply clarsimp |
|
2904 apply (rule word_eqI) |
2895 apply (rule word_eqI) |
2905 apply (auto simp: nth_shiftr nth_rest_power_bin nth_bintr word_size) |
2896 apply (auto simp: nth_shiftr nth_rest_power_bin nth_bintr word_size) |
2906 done |
2897 done |
2907 |
2898 |
2908 lemma sshiftr_no': |
2899 lemma sshiftr_no [simp]: |
2909 "w = number_of bin \<Longrightarrow> w >>> n = word_of_int ((bin_rest ^^ n) |
2900 "(number_of w::'a::len word) >>> n = word_of_int |
2910 (sbintrunc (size w - 1) (number_of bin)))" |
2901 ((bin_rest ^^ n) (sbintrunc (len_of TYPE('a) - 1) (number_of w)))" |
2911 apply clarsimp |
|
2912 apply (rule word_eqI) |
2902 apply (rule word_eqI) |
2913 apply (auto simp: nth_sshiftr nth_rest_power_bin nth_sbintr word_size) |
2903 apply (auto simp: nth_sshiftr nth_rest_power_bin nth_sbintr word_size) |
2914 apply (subgoal_tac "na + n = len_of TYPE('a) - Suc 0", simp, simp)+ |
2904 apply (subgoal_tac "na + n = len_of TYPE('a) - Suc 0", simp, simp)+ |
2915 done |
2905 done |
2916 |
|
2917 lemmas sshiftr_no [simp] = |
|
2918 sshiftr_no' [where w = "number_of w", OF refl, unfolded word_size] for w |
|
2919 |
|
2920 lemmas shiftr_no [simp] = |
|
2921 shiftr_no' [where w = "number_of w", OF refl, unfolded word_size] for w |
|
2922 |
2906 |
2923 lemma shiftr1_bl_of: |
2907 lemma shiftr1_bl_of: |
2924 "length bl \<le> len_of TYPE('a) \<Longrightarrow> |
2908 "length bl \<le> len_of TYPE('a) \<Longrightarrow> |
2925 shiftr1 (of_bl bl::'a::len0 word) = of_bl (butlast bl)" |
2909 shiftr1 (of_bl bl::'a::len0 word) = of_bl (butlast bl)" |
2926 by (clarsimp simp: shiftr1_def of_bl_def butlast_rest_bl2bin |
2910 by (clarsimp simp: shiftr1_def of_bl_def butlast_rest_bl2bin |