equal
deleted
inserted
replaced
8 imports Misc_Numeric |
8 imports Misc_Numeric |
9 begin |
9 begin |
10 |
10 |
11 subsection {* Constructors and destructors for binary integers *} |
11 subsection {* Constructors and destructors for binary integers *} |
12 |
12 |
13 definition Bit :: "int \<Rightarrow> bool \<Rightarrow> int" (infixl "BIT" 90) where |
13 definition Bit :: "int \<Rightarrow> bool \<Rightarrow> int" (infixl "BIT" 90) |
|
14 where |
14 "k BIT b = (if b then 1 else 0) + k + k" |
15 "k BIT b = (if b then 1 else 0) + k + k" |
15 |
16 |
16 lemma Bit_B0: |
17 lemma Bit_B0: |
17 "k BIT False = k + k" |
18 "k BIT False = k + k" |
18 by (unfold Bit_def) simp |
19 by (unfold Bit_def) simp |
25 by (rule trans, rule Bit_B0) simp |
26 by (rule trans, rule Bit_B0) simp |
26 |
27 |
27 lemma Bit_B1_2t: "k BIT True = 2 * k + 1" |
28 lemma Bit_B1_2t: "k BIT True = 2 * k + 1" |
28 by (rule trans, rule Bit_B1) simp |
29 by (rule trans, rule Bit_B1) simp |
29 |
30 |
30 definition bin_last :: "int \<Rightarrow> bool" where |
31 definition bin_last :: "int \<Rightarrow> bool" |
|
32 where |
31 "bin_last w \<longleftrightarrow> w mod 2 = 1" |
33 "bin_last w \<longleftrightarrow> w mod 2 = 1" |
32 |
34 |
33 lemma bin_last_odd: |
35 lemma bin_last_odd: |
34 "bin_last = odd" |
36 "bin_last = odd" |
35 by (rule ext) (simp add: bin_last_def even_def) |
37 by (rule ext) (simp add: bin_last_def even_def) |
36 |
38 |
37 definition bin_rest :: "int \<Rightarrow> int" where |
39 definition bin_rest :: "int \<Rightarrow> int" |
|
40 where |
38 "bin_rest w = w div 2" |
41 "bin_rest w = w div 2" |
39 |
42 |
40 lemma bin_rl_simp [simp]: |
43 lemma bin_rl_simp [simp]: |
41 "bin_rest w BIT bin_last w = w" |
44 "bin_rest w BIT bin_last w = w" |
42 unfolding bin_rest_def bin_last_def Bit_def |
45 unfolding bin_rest_def bin_last_def Bit_def |
269 bin_nth_numeral_simps |
272 bin_nth_numeral_simps |
270 |
273 |
271 |
274 |
272 subsection {* Truncating binary integers *} |
275 subsection {* Truncating binary integers *} |
273 |
276 |
274 definition bin_sign :: "int \<Rightarrow> int" where |
277 definition bin_sign :: "int \<Rightarrow> int" |
|
278 where |
275 bin_sign_def: "bin_sign k = (if k \<ge> 0 then 0 else - 1)" |
279 bin_sign_def: "bin_sign k = (if k \<ge> 0 then 0 else - 1)" |
276 |
280 |
277 lemma bin_sign_simps [simp]: |
281 lemma bin_sign_simps [simp]: |
278 "bin_sign 0 = 0" |
282 "bin_sign 0 = 0" |
279 "bin_sign 1 = 0" |
283 "bin_sign 1 = 0" |