116 syntax |
118 syntax |
117 of_int :: "int => 'a" |
119 of_int :: "int => 'a" |
118 translations |
120 translations |
119 "case x of CONST of_int y => b" == "CONST word_int_case (%y. b) x" |
121 "case x of CONST of_int y => b" == "CONST word_int_case (%y. b) x" |
120 |
122 |
121 |
123 subsection {* Type-definition locale instantiations *} |
122 subsection "Arithmetic operations" |
|
123 |
|
124 instantiation word :: (len0) "{number, uminus, minus, plus, one, zero, times, Divides.div, ord}" |
|
125 begin |
|
126 |
|
127 definition |
|
128 word_0_wi: "0 = word_of_int 0" |
|
129 |
|
130 definition |
|
131 word_1_wi: "1 = word_of_int 1" |
|
132 |
|
133 definition |
|
134 word_add_def: "a + b = word_of_int (uint a + uint b)" |
|
135 |
|
136 definition |
|
137 word_sub_wi: "a - b = word_of_int (uint a - uint b)" |
|
138 |
|
139 definition |
|
140 word_minus_def: "- a = word_of_int (- uint a)" |
|
141 |
|
142 definition |
|
143 word_mult_def: "a * b = word_of_int (uint a * uint b)" |
|
144 |
|
145 definition |
|
146 word_div_def: "a div b = word_of_int (uint a div uint b)" |
|
147 |
|
148 definition |
|
149 word_mod_def: "a mod b = word_of_int (uint a mod uint b)" |
|
150 |
|
151 definition |
|
152 word_number_of_def: "number_of w = word_of_int w" |
|
153 |
|
154 definition |
|
155 word_le_def: "a \<le> b \<longleftrightarrow> uint a \<le> uint b" |
|
156 |
|
157 definition |
|
158 word_less_def: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> (y \<Colon> 'a word)" |
|
159 |
|
160 instance .. |
|
161 |
|
162 end |
|
163 |
|
164 definition |
|
165 word_succ :: "'a :: len0 word => 'a word" |
|
166 where |
|
167 "word_succ a = word_of_int (Int.succ (uint a))" |
|
168 |
|
169 definition |
|
170 word_pred :: "'a :: len0 word => 'a word" |
|
171 where |
|
172 "word_pred a = word_of_int (Int.pred (uint a))" |
|
173 |
|
174 definition udvd :: "'a::len word => 'a::len word => bool" (infixl "udvd" 50) where |
|
175 "a udvd b = (EX n>=0. uint b = n * uint a)" |
|
176 |
|
177 definition word_sle :: "'a :: len word => 'a word => bool" ("(_/ <=s _)" [50, 51] 50) where |
|
178 "a <=s b = (sint a <= sint b)" |
|
179 |
|
180 definition word_sless :: "'a :: len word => 'a word => bool" ("(_/ <s _)" [50, 51] 50) where |
|
181 "(x <s y) = (x <=s y & x ~= y)" |
|
182 |
|
183 |
|
184 |
|
185 subsection "Bit-wise operations" |
|
186 |
|
187 instantiation word :: (len0) bits |
|
188 begin |
|
189 |
|
190 definition |
|
191 word_and_def: |
|
192 "(a::'a word) AND b = word_of_int (uint a AND uint b)" |
|
193 |
|
194 definition |
|
195 word_or_def: |
|
196 "(a::'a word) OR b = word_of_int (uint a OR uint b)" |
|
197 |
|
198 definition |
|
199 word_xor_def: |
|
200 "(a::'a word) XOR b = word_of_int (uint a XOR uint b)" |
|
201 |
|
202 definition |
|
203 word_not_def: |
|
204 "NOT (a::'a word) = word_of_int (NOT (uint a))" |
|
205 |
|
206 definition |
|
207 word_test_bit_def: "test_bit a = bin_nth (uint a)" |
|
208 |
|
209 definition |
|
210 word_set_bit_def: "set_bit a n x = |
|
211 word_of_int (bin_sc n (If x 1 0) (uint a))" |
|
212 |
|
213 definition |
|
214 word_set_bits_def: "(BITS n. f n) = of_bl (bl_of_nth (len_of TYPE ('a)) f)" |
|
215 |
|
216 definition |
|
217 word_lsb_def: "lsb a \<longleftrightarrow> bin_last (uint a) = 1" |
|
218 |
|
219 definition shiftl1 :: "'a word \<Rightarrow> 'a word" where |
|
220 "shiftl1 w = word_of_int (uint w BIT 0)" |
|
221 |
|
222 definition shiftr1 :: "'a word \<Rightarrow> 'a word" where |
|
223 -- "shift right as unsigned or as signed, ie logical or arithmetic" |
|
224 "shiftr1 w = word_of_int (bin_rest (uint w))" |
|
225 |
|
226 definition |
|
227 shiftl_def: "w << n = (shiftl1 ^^ n) w" |
|
228 |
|
229 definition |
|
230 shiftr_def: "w >> n = (shiftr1 ^^ n) w" |
|
231 |
|
232 instance .. |
|
233 |
|
234 end |
|
235 |
|
236 instantiation word :: (len) bitss |
|
237 begin |
|
238 |
|
239 definition |
|
240 word_msb_def: |
|
241 "msb a \<longleftrightarrow> bin_sign (sint a) = Int.Min" |
|
242 |
|
243 instance .. |
|
244 |
|
245 end |
|
246 |
|
247 lemma [code]: |
|
248 "msb a \<longleftrightarrow> bin_sign (sint a) = (- 1 :: int)" |
|
249 by (simp only: word_msb_def Min_def) |
|
250 |
|
251 definition setBit :: "'a :: len0 word => nat => 'a word" where |
|
252 "setBit w n = set_bit w n True" |
|
253 |
|
254 definition clearBit :: "'a :: len0 word => nat => 'a word" where |
|
255 "clearBit w n = set_bit w n False" |
|
256 |
|
257 |
|
258 subsection "Shift operations" |
|
259 |
|
260 definition sshiftr1 :: "'a :: len word => 'a word" where |
|
261 "sshiftr1 w = word_of_int (bin_rest (sint w))" |
|
262 |
|
263 definition bshiftr1 :: "bool => 'a :: len word => 'a word" where |
|
264 "bshiftr1 b w = of_bl (b # butlast (to_bl w))" |
|
265 |
|
266 definition sshiftr :: "'a :: len word => nat => 'a word" (infixl ">>>" 55) where |
|
267 "w >>> n = (sshiftr1 ^^ n) w" |
|
268 |
|
269 definition mask :: "nat => 'a::len word" where |
|
270 "mask n = (1 << n) - 1" |
|
271 |
|
272 definition revcast :: "'a :: len0 word => 'b :: len0 word" where |
|
273 "revcast w = of_bl (takefill False (len_of TYPE('b)) (to_bl w))" |
|
274 |
|
275 definition slice1 :: "nat => 'a :: len0 word => 'b :: len0 word" where |
|
276 "slice1 n w = of_bl (takefill False n (to_bl w))" |
|
277 |
|
278 definition slice :: "nat => 'a :: len0 word => 'b :: len0 word" where |
|
279 "slice n w = slice1 (size w - n) w" |
|
280 |
|
281 |
|
282 subsection "Rotation" |
|
283 |
|
284 definition rotater1 :: "'a list => 'a list" where |
|
285 "rotater1 ys = |
|
286 (case ys of [] => [] | x # xs => last ys # butlast ys)" |
|
287 |
|
288 definition rotater :: "nat => 'a list => 'a list" where |
|
289 "rotater n = rotater1 ^^ n" |
|
290 |
|
291 definition word_rotr :: "nat => 'a :: len0 word => 'a :: len0 word" where |
|
292 "word_rotr n w = of_bl (rotater n (to_bl w))" |
|
293 |
|
294 definition word_rotl :: "nat => 'a :: len0 word => 'a :: len0 word" where |
|
295 "word_rotl n w = of_bl (rotate n (to_bl w))" |
|
296 |
|
297 definition word_roti :: "int => 'a :: len0 word => 'a :: len0 word" where |
|
298 "word_roti i w = (if i >= 0 then word_rotr (nat i) w |
|
299 else word_rotl (nat (- i)) w)" |
|
300 |
|
301 |
|
302 subsection "Split and cat operations" |
|
303 |
|
304 definition word_cat :: "'a :: len0 word => 'b :: len0 word => 'c :: len0 word" where |
|
305 "word_cat a b = word_of_int (bin_cat (uint a) (len_of TYPE ('b)) (uint b))" |
|
306 |
|
307 definition word_split :: "'a :: len0 word => ('b :: len0 word) * ('c :: len0 word)" where |
|
308 "word_split a = |
|
309 (case bin_split (len_of TYPE ('c)) (uint a) of |
|
310 (u, v) => (word_of_int u, word_of_int v))" |
|
311 |
|
312 definition word_rcat :: "'a :: len0 word list => 'b :: len0 word" where |
|
313 "word_rcat ws = |
|
314 word_of_int (bin_rcat (len_of TYPE ('a)) (map uint ws))" |
|
315 |
|
316 definition word_rsplit :: "'a :: len0 word => 'b :: len word list" where |
|
317 "word_rsplit w = |
|
318 map word_of_int (bin_rsplit (len_of TYPE ('b)) (len_of TYPE ('a), uint w))" |
|
319 |
|
320 definition max_word :: "'a::len word" -- "Largest representable machine integer." where |
|
321 "max_word = word_of_int (2 ^ len_of TYPE('a) - 1)" |
|
322 |
|
323 primrec of_bool :: "bool \<Rightarrow> 'a::len word" where |
|
324 "of_bool False = 0" |
|
325 | "of_bool True = 1" |
|
326 |
|
327 |
|
328 lemmas of_nth_def = word_set_bits_def |
|
329 |
124 |
330 lemmas word_size_gt_0 [iff] = |
125 lemmas word_size_gt_0 [iff] = |
331 xtr1 [OF word_size len_gt_0, standard] |
126 xtr1 [OF word_size len_gt_0, standard] |
332 lemmas lens_gt_0 = word_size_gt_0 len_gt_0 |
127 lemmas lens_gt_0 = word_size_gt_0 len_gt_0 |
333 lemmas lens_not_0 [iff] = lens_gt_0 [THEN gr_implies_not0, standard] |
128 lemmas lens_not_0 [iff] = lens_gt_0 [THEN gr_implies_not0, standard] |
380 td_ext "uint::'a::len0 word \<Rightarrow> int" |
175 td_ext "uint::'a::len0 word \<Rightarrow> int" |
381 word_of_int |
176 word_of_int |
382 "uints (len_of TYPE('a::len0))" |
177 "uints (len_of TYPE('a::len0))" |
383 "bintrunc (len_of TYPE('a::len0))" |
178 "bintrunc (len_of TYPE('a::len0))" |
384 by (rule td_ext_ubin) |
179 by (rule td_ext_ubin) |
|
180 |
|
181 lemma split_word_all: |
|
182 "(\<And>x::'a::len0 word. PROP P x) \<equiv> (\<And>x. PROP P (word_of_int x))" |
|
183 proof |
|
184 fix x :: "'a word" |
|
185 assume "\<And>x. PROP P (word_of_int x)" |
|
186 hence "PROP P (word_of_int (uint x))" . |
|
187 thus "PROP P x" by simp |
|
188 qed |
|
189 |
|
190 subsection "Arithmetic operations" |
|
191 |
|
192 definition |
|
193 word_succ :: "'a :: len0 word => 'a word" |
|
194 where |
|
195 "word_succ a = word_of_int (Int.succ (uint a))" |
|
196 |
|
197 definition |
|
198 word_pred :: "'a :: len0 word => 'a word" |
|
199 where |
|
200 "word_pred a = word_of_int (Int.pred (uint a))" |
|
201 |
|
202 instantiation word :: (len0) "{number, Divides.div, ord, comm_monoid_mult, comm_ring}" |
|
203 begin |
|
204 |
|
205 definition |
|
206 word_0_wi: "0 = word_of_int 0" |
|
207 |
|
208 definition |
|
209 word_1_wi: "1 = word_of_int 1" |
|
210 |
|
211 definition |
|
212 word_add_def: "a + b = word_of_int (uint a + uint b)" |
|
213 |
|
214 definition |
|
215 word_sub_wi: "a - b = word_of_int (uint a - uint b)" |
|
216 |
|
217 definition |
|
218 word_minus_def: "- a = word_of_int (- uint a)" |
|
219 |
|
220 definition |
|
221 word_mult_def: "a * b = word_of_int (uint a * uint b)" |
|
222 |
|
223 definition |
|
224 word_div_def: "a div b = word_of_int (uint a div uint b)" |
|
225 |
|
226 definition |
|
227 word_mod_def: "a mod b = word_of_int (uint a mod uint b)" |
|
228 |
|
229 definition |
|
230 word_number_of_def: "number_of w = word_of_int w" |
|
231 |
|
232 definition |
|
233 word_le_def: "a \<le> b \<longleftrightarrow> uint a \<le> uint b" |
|
234 |
|
235 definition |
|
236 word_less_def: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> (y \<Colon> 'a word)" |
|
237 |
|
238 lemmas word_arith_wis = |
|
239 word_add_def word_mult_def word_minus_def |
|
240 word_succ_def word_pred_def word_0_wi word_1_wi |
|
241 |
|
242 lemmas arths = |
|
243 bintr_ariths [THEN word_ubin.norm_eq_iff [THEN iffD1], |
|
244 folded word_ubin.eq_norm, standard] |
|
245 |
|
246 lemma wi_homs: |
|
247 shows |
|
248 wi_hom_add: "word_of_int a + word_of_int b = word_of_int (a + b)" and |
|
249 wi_hom_mult: "word_of_int a * word_of_int b = word_of_int (a * b)" and |
|
250 wi_hom_neg: "- word_of_int a = word_of_int (- a)" and |
|
251 wi_hom_succ: "word_succ (word_of_int a) = word_of_int (Int.succ a)" and |
|
252 wi_hom_pred: "word_pred (word_of_int a) = word_of_int (Int.pred a)" |
|
253 by (auto simp: word_arith_wis arths) |
|
254 |
|
255 lemmas wi_hom_syms = wi_homs [symmetric] |
|
256 |
|
257 lemma word_sub_def: "a - b = a + - (b :: 'a :: len0 word)" |
|
258 unfolding word_sub_wi diff_minus |
|
259 by (simp only : word_uint.Rep_inverse wi_hom_syms) |
|
260 |
|
261 lemmas word_diff_minus = word_sub_def [standard] |
|
262 |
|
263 lemma word_of_int_sub_hom: |
|
264 "(word_of_int a) - word_of_int b = word_of_int (a - b)" |
|
265 unfolding word_sub_def diff_minus by (simp only : wi_homs) |
|
266 |
|
267 lemmas new_word_of_int_homs = |
|
268 word_of_int_sub_hom wi_homs word_0_wi word_1_wi |
|
269 |
|
270 lemmas new_word_of_int_hom_syms = new_word_of_int_homs [symmetric, standard] |
|
271 |
|
272 lemmas word_of_int_hom_syms = |
|
273 new_word_of_int_hom_syms [unfolded succ_def pred_def] |
|
274 |
|
275 lemmas word_of_int_homs = |
|
276 new_word_of_int_homs [unfolded succ_def pred_def] |
|
277 |
|
278 lemmas word_of_int_add_hom = word_of_int_homs (2) |
|
279 lemmas word_of_int_mult_hom = word_of_int_homs (3) |
|
280 lemmas word_of_int_minus_hom = word_of_int_homs (4) |
|
281 lemmas word_of_int_succ_hom = word_of_int_homs (5) |
|
282 lemmas word_of_int_pred_hom = word_of_int_homs (6) |
|
283 lemmas word_of_int_0_hom = word_of_int_homs (7) |
|
284 lemmas word_of_int_1_hom = word_of_int_homs (8) |
|
285 |
|
286 instance |
|
287 by default (auto simp: split_word_all word_of_int_homs algebra_simps) |
|
288 |
|
289 end |
|
290 |
|
291 lemma word_zero_neq_one: "0 < len_of TYPE ('a :: len0) \<Longrightarrow> (0 :: 'a word) ~= 1" |
|
292 unfolding word_arith_wis |
|
293 by (auto simp add: word_ubin.norm_eq_iff [symmetric] gr0_conv_Suc) |
|
294 |
|
295 lemmas lenw1_zero_neq_one = len_gt_0 [THEN word_zero_neq_one] |
|
296 |
|
297 instance word :: (len) comm_ring_1 |
|
298 by (intro_classes) (simp add: lenw1_zero_neq_one) |
|
299 |
|
300 lemma word_of_nat: "of_nat n = word_of_int (int n)" |
|
301 by (induct n) (auto simp add : word_of_int_hom_syms) |
|
302 |
|
303 lemma word_of_int: "of_int = word_of_int" |
|
304 apply (rule ext) |
|
305 apply (case_tac x rule: int_diff_cases) |
|
306 apply (simp add: word_of_nat word_of_int_sub_hom) |
|
307 done |
|
308 |
|
309 lemma word_number_of_eq: |
|
310 "number_of w = (of_int w :: 'a :: len word)" |
|
311 unfolding word_number_of_def word_of_int by auto |
|
312 |
|
313 instance word :: (len) number_ring |
|
314 by (intro_classes) (simp add : word_number_of_eq) |
|
315 |
|
316 definition udvd :: "'a::len word => 'a::len word => bool" (infixl "udvd" 50) where |
|
317 "a udvd b = (EX n>=0. uint b = n * uint a)" |
|
318 |
|
319 definition word_sle :: "'a :: len word => 'a word => bool" ("(_/ <=s _)" [50, 51] 50) where |
|
320 "a <=s b = (sint a <= sint b)" |
|
321 |
|
322 definition word_sless :: "'a :: len word => 'a word => bool" ("(_/ <s _)" [50, 51] 50) where |
|
323 "(x <s y) = (x <=s y & x ~= y)" |
|
324 |
|
325 |
|
326 subsection "Bit-wise operations" |
|
327 |
|
328 instantiation word :: (len0) bits |
|
329 begin |
|
330 |
|
331 definition |
|
332 word_and_def: |
|
333 "(a::'a word) AND b = word_of_int (uint a AND uint b)" |
|
334 |
|
335 definition |
|
336 word_or_def: |
|
337 "(a::'a word) OR b = word_of_int (uint a OR uint b)" |
|
338 |
|
339 definition |
|
340 word_xor_def: |
|
341 "(a::'a word) XOR b = word_of_int (uint a XOR uint b)" |
|
342 |
|
343 definition |
|
344 word_not_def: |
|
345 "NOT (a::'a word) = word_of_int (NOT (uint a))" |
|
346 |
|
347 definition |
|
348 word_test_bit_def: "test_bit a = bin_nth (uint a)" |
|
349 |
|
350 definition |
|
351 word_set_bit_def: "set_bit a n x = |
|
352 word_of_int (bin_sc n (If x 1 0) (uint a))" |
|
353 |
|
354 definition |
|
355 word_set_bits_def: "(BITS n. f n) = of_bl (bl_of_nth (len_of TYPE ('a)) f)" |
|
356 |
|
357 definition |
|
358 word_lsb_def: "lsb a \<longleftrightarrow> bin_last (uint a) = 1" |
|
359 |
|
360 definition shiftl1 :: "'a word \<Rightarrow> 'a word" where |
|
361 "shiftl1 w = word_of_int (uint w BIT 0)" |
|
362 |
|
363 definition shiftr1 :: "'a word \<Rightarrow> 'a word" where |
|
364 -- "shift right as unsigned or as signed, ie logical or arithmetic" |
|
365 "shiftr1 w = word_of_int (bin_rest (uint w))" |
|
366 |
|
367 definition |
|
368 shiftl_def: "w << n = (shiftl1 ^^ n) w" |
|
369 |
|
370 definition |
|
371 shiftr_def: "w >> n = (shiftr1 ^^ n) w" |
|
372 |
|
373 instance .. |
|
374 |
|
375 end |
|
376 |
|
377 instantiation word :: (len) bitss |
|
378 begin |
|
379 |
|
380 definition |
|
381 word_msb_def: |
|
382 "msb a \<longleftrightarrow> bin_sign (sint a) = Int.Min" |
|
383 |
|
384 instance .. |
|
385 |
|
386 end |
|
387 |
|
388 lemma [code]: |
|
389 "msb a \<longleftrightarrow> bin_sign (sint a) = (- 1 :: int)" |
|
390 by (simp only: word_msb_def Min_def) |
|
391 |
|
392 definition setBit :: "'a :: len0 word => nat => 'a word" where |
|
393 "setBit w n = set_bit w n True" |
|
394 |
|
395 definition clearBit :: "'a :: len0 word => nat => 'a word" where |
|
396 "clearBit w n = set_bit w n False" |
|
397 |
|
398 |
|
399 subsection "Shift operations" |
|
400 |
|
401 definition sshiftr1 :: "'a :: len word => 'a word" where |
|
402 "sshiftr1 w = word_of_int (bin_rest (sint w))" |
|
403 |
|
404 definition bshiftr1 :: "bool => 'a :: len word => 'a word" where |
|
405 "bshiftr1 b w = of_bl (b # butlast (to_bl w))" |
|
406 |
|
407 definition sshiftr :: "'a :: len word => nat => 'a word" (infixl ">>>" 55) where |
|
408 "w >>> n = (sshiftr1 ^^ n) w" |
|
409 |
|
410 definition mask :: "nat => 'a::len word" where |
|
411 "mask n = (1 << n) - 1" |
|
412 |
|
413 definition revcast :: "'a :: len0 word => 'b :: len0 word" where |
|
414 "revcast w = of_bl (takefill False (len_of TYPE('b)) (to_bl w))" |
|
415 |
|
416 definition slice1 :: "nat => 'a :: len0 word => 'b :: len0 word" where |
|
417 "slice1 n w = of_bl (takefill False n (to_bl w))" |
|
418 |
|
419 definition slice :: "nat => 'a :: len0 word => 'b :: len0 word" where |
|
420 "slice n w = slice1 (size w - n) w" |
|
421 |
|
422 |
|
423 subsection "Rotation" |
|
424 |
|
425 definition rotater1 :: "'a list => 'a list" where |
|
426 "rotater1 ys = |
|
427 (case ys of [] => [] | x # xs => last ys # butlast ys)" |
|
428 |
|
429 definition rotater :: "nat => 'a list => 'a list" where |
|
430 "rotater n = rotater1 ^^ n" |
|
431 |
|
432 definition word_rotr :: "nat => 'a :: len0 word => 'a :: len0 word" where |
|
433 "word_rotr n w = of_bl (rotater n (to_bl w))" |
|
434 |
|
435 definition word_rotl :: "nat => 'a :: len0 word => 'a :: len0 word" where |
|
436 "word_rotl n w = of_bl (rotate n (to_bl w))" |
|
437 |
|
438 definition word_roti :: "int => 'a :: len0 word => 'a :: len0 word" where |
|
439 "word_roti i w = (if i >= 0 then word_rotr (nat i) w |
|
440 else word_rotl (nat (- i)) w)" |
|
441 |
|
442 |
|
443 subsection "Split and cat operations" |
|
444 |
|
445 definition word_cat :: "'a :: len0 word => 'b :: len0 word => 'c :: len0 word" where |
|
446 "word_cat a b = word_of_int (bin_cat (uint a) (len_of TYPE ('b)) (uint b))" |
|
447 |
|
448 definition word_split :: "'a :: len0 word => ('b :: len0 word) * ('c :: len0 word)" where |
|
449 "word_split a = |
|
450 (case bin_split (len_of TYPE ('c)) (uint a) of |
|
451 (u, v) => (word_of_int u, word_of_int v))" |
|
452 |
|
453 definition word_rcat :: "'a :: len0 word list => 'b :: len0 word" where |
|
454 "word_rcat ws = |
|
455 word_of_int (bin_rcat (len_of TYPE ('a)) (map uint ws))" |
|
456 |
|
457 definition word_rsplit :: "'a :: len0 word => 'b :: len word list" where |
|
458 "word_rsplit w = |
|
459 map word_of_int (bin_rsplit (len_of TYPE ('b)) (len_of TYPE ('a), uint w))" |
|
460 |
|
461 definition max_word :: "'a::len word" -- "Largest representable machine integer." where |
|
462 "max_word = word_of_int (2 ^ len_of TYPE('a) - 1)" |
|
463 |
|
464 primrec of_bool :: "bool \<Rightarrow> 'a::len word" where |
|
465 "of_bool False = 0" |
|
466 | "of_bool True = 1" |
|
467 |
|
468 |
|
469 lemmas of_nth_def = word_set_bits_def |
385 |
470 |
386 lemma sint_sbintrunc': |
471 lemma sint_sbintrunc': |
387 "sint (word_of_int bin :: 'a word) = |
472 "sint (word_of_int bin :: 'a word) = |
388 (sbintrunc (len_of TYPE ('a :: len) - 1) bin)" |
473 (sbintrunc (len_of TYPE ('a :: len) - 1) bin)" |
389 unfolding sint_uint |
474 unfolding sint_uint |
1114 |
1195 |
1115 lemma ucast_1 [simp] : "ucast (1 :: 'a :: len word) = 1" |
1196 lemma ucast_1 [simp] : "ucast (1 :: 'a :: len word) = 1" |
1116 unfolding ucast_def word_1_wi |
1197 unfolding ucast_def word_1_wi |
1117 by (simp add: word_ubin.eq_norm int_one_bin bintrunc_minus_simps) |
1198 by (simp add: word_ubin.eq_norm int_one_bin bintrunc_minus_simps) |
1118 |
1199 |
1119 (* abstraction preserves the operations |
|
1120 (the definitions tell this for bins in range uint) *) |
|
1121 |
|
1122 lemmas arths = |
|
1123 bintr_ariths [THEN word_ubin.norm_eq_iff [THEN iffD1], |
|
1124 folded word_ubin.eq_norm, standard] |
|
1125 |
|
1126 lemma wi_homs: |
|
1127 shows |
|
1128 wi_hom_add: "word_of_int a + word_of_int b = word_of_int (a + b)" and |
|
1129 wi_hom_mult: "word_of_int a * word_of_int b = word_of_int (a * b)" and |
|
1130 wi_hom_neg: "- word_of_int a = word_of_int (- a)" and |
|
1131 wi_hom_succ: "word_succ (word_of_int a) = word_of_int (Int.succ a)" and |
|
1132 wi_hom_pred: "word_pred (word_of_int a) = word_of_int (Int.pred a)" |
|
1133 by (auto simp: word_arith_wis arths) |
|
1134 |
|
1135 lemmas wi_hom_syms = wi_homs [symmetric] |
|
1136 |
|
1137 lemma word_sub_def: "a - b = a + - (b :: 'a :: len0 word)" |
|
1138 unfolding word_sub_wi diff_minus |
|
1139 by (simp only : word_uint.Rep_inverse wi_hom_syms) |
|
1140 |
|
1141 lemmas word_diff_minus = word_sub_def [standard] |
|
1142 |
|
1143 lemma word_of_int_sub_hom: |
|
1144 "(word_of_int a) - word_of_int b = word_of_int (a - b)" |
|
1145 unfolding word_sub_def diff_minus by (simp only : wi_homs) |
|
1146 |
|
1147 lemmas new_word_of_int_homs = |
|
1148 word_of_int_sub_hom wi_homs word_0_wi word_1_wi |
|
1149 |
|
1150 lemmas new_word_of_int_hom_syms = new_word_of_int_homs [symmetric, standard] |
|
1151 |
|
1152 lemmas word_of_int_hom_syms = |
|
1153 new_word_of_int_hom_syms [unfolded succ_def pred_def] |
|
1154 |
|
1155 lemmas word_of_int_homs = |
|
1156 new_word_of_int_homs [unfolded succ_def pred_def] |
|
1157 |
|
1158 lemmas word_of_int_add_hom = word_of_int_homs (2) |
|
1159 lemmas word_of_int_mult_hom = word_of_int_homs (3) |
|
1160 lemmas word_of_int_minus_hom = word_of_int_homs (4) |
|
1161 lemmas word_of_int_succ_hom = word_of_int_homs (5) |
|
1162 lemmas word_of_int_pred_hom = word_of_int_homs (6) |
|
1163 lemmas word_of_int_0_hom = word_of_int_homs (7) |
|
1164 lemmas word_of_int_1_hom = word_of_int_homs (8) |
|
1165 |
|
1166 (* now, to get the weaker results analogous to word_div/mod_def *) |
1200 (* now, to get the weaker results analogous to word_div/mod_def *) |
1167 |
1201 |
1168 lemmas word_arith_alts = |
1202 lemmas word_arith_alts = |
1169 word_sub_wi [unfolded succ_def pred_def, standard] |
1203 word_sub_wi [unfolded succ_def pred_def, standard] |
1170 word_arith_wis [unfolded succ_def pred_def, standard] |
1204 word_arith_wis [unfolded succ_def pred_def, standard] |
1171 |
1205 |
|
1206 (* FIXME: Lots of duplicate lemmas *) |
1172 lemmas word_sub_alt = word_arith_alts (1) |
1207 lemmas word_sub_alt = word_arith_alts (1) |
1173 lemmas word_add_alt = word_arith_alts (2) |
1208 lemmas word_add_alt = word_arith_alts (2) |
1174 lemmas word_mult_alt = word_arith_alts (3) |
1209 lemmas word_mult_alt = word_arith_alts (3) |
1175 lemmas word_minus_alt = word_arith_alts (4) |
1210 lemmas word_minus_alt = word_arith_alts (4) |
1176 lemmas word_succ_alt = word_arith_alts (5) |
1211 lemmas word_succ_alt = word_arith_alts (5) |