text‹
Normalise word numerals, including negative ones apart from @{term "-1"}, to the
interval ‹[0..2^len_of 'a)›. Only for concrete word lengths. ›
lemma neg_numeral_eq: ‹- numeral n = (word_of_int (take_bit LENGTH('a) (- numeral n)) :: 'a::len word)› by transfer simp
ML ‹
fun signed_dest_wordT 🍋‹word 🍋‹signed T›› = Word_Lib.dest_binT T
| signed_dest_wordT T = Word_Lib.dest_wordT T;
fun typ_size_of t = signed_dest_wordT (type_of (Thm.term_of t));
fun num_len 🍋‹Num.Bit0 for n› = num_len n + 1
| num_len 🍋‹Num.Bit1 for n› = num_len n + 1
| num_len 🍋‹Num.One› = 1
| num_len 🍋‹numeral _ for t› = num_len t
| num_len 🍋‹uminus _ for t› = num_len t
| num_len t = raise TERM ("num_len", [t]);
val expand_pos = mk_eq @{thm num_abs_bintr};
val expand_neg = mk_eq @{thm neg_numeral_eq};
fun expand is_neg ct =
[Thm.reflexive ct, if is_neg then expand_neg else expand_pos] MRS transitive_thm;
fun norm ctxt = Simplifier.rewrite (put_simpset ss ctxt);
(* will work in context of theory Word as well *) fun unsigned_norm is_neg _ ctxt ct =
(if num_len (Thm.term_of ct) > typ_size_of ct orelse is_neg then
SOME ((expand is_neg then_conv norm ctxt) ct)
else NONE)
handle TERM ("num_len", _) => NONE
| TYPE ("dest_binT", _, _) => NONE end ›
simproc_setup
unsigned_norm (‹numeral n :: 'a::len word›) = ‹unsigned_norm false›
context notes[[simprocadd:unsigned_normunsigned_norm_neg0unsigned_norm_neg1]] begin
privatelemma"-2=(13+1::'a::lenword)" usingnumeral_plus_one[simp]
apply simp (* does not touch generic word length *) oops
privatelemma"7 = (3 :: 2 word)" by simp
privatelemma"- 2 = (22 :: 3 word)" by simp
privatelemma"- 2 = (0xFFFFFFFE :: 32 word)" by simp
privatelemma"- 2 = (0xFFFFFFFE :: 32 signed word)" by simp
end
end
text‹
We leave @{term "-1"} untouched by default, because it is often useful
and its normal form can be large.
To include it in the normalisation, add @{thm [source] minus_one_norm_num}.
The additional normalisation is restricted to concrete numeral word lengths,
like the rest. ›
context notes minus_one_norm_num [simp] begin
privatelemma"f (- 1) = f (15 :: 4 word)" by simp
privatelemma"f (- 1) = f (7 :: 3 word)" by simp
privatelemma"f (- 1) = f (0xFFFF :: 16 word)" by simp
privatelemma"f (- 1) = f (0xFFFF + 1 :: 'a::len word)" apply simp (* does not touch generic -1 *) oops
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.