equal
deleted
inserted
replaced
198 definition bitlen :: "int \<Rightarrow> int" where "bitlen a = floorlog 2 (nat a)" |
198 definition bitlen :: "int \<Rightarrow> int" where "bitlen a = floorlog 2 (nat a)" |
199 |
199 |
200 lemma bitlen_alt_def: "bitlen a = (if a > 0 then \<lfloor>log 2 a\<rfloor> + 1 else 0)" |
200 lemma bitlen_alt_def: "bitlen a = (if a > 0 then \<lfloor>log 2 a\<rfloor> + 1 else 0)" |
201 by (simp add: bitlen_def floorlog_def) |
201 by (simp add: bitlen_def floorlog_def) |
202 |
202 |
|
203 lemma bitlen_zero[simp]: "bitlen 0 = 0" |
|
204 by (auto simp: bitlen_def floorlog_def) |
|
205 |
203 lemma bitlen_nonneg: "0 \<le> bitlen x" |
206 lemma bitlen_nonneg: "0 \<le> bitlen x" |
204 by (simp add: bitlen_def) |
207 by (simp add: bitlen_def) |
205 |
208 |
206 lemma bitlen_bounds: |
209 lemma bitlen_bounds: |
207 assumes "x > 0" |
210 assumes "x > 0" |
208 shows "2 ^ nat (bitlen x - 1) \<le> x \<and> x < 2 ^ nat (bitlen x)" |
211 shows "2 ^ nat (bitlen x - 1) \<le> x \<and> x < 2 ^ nat (bitlen x)" |
209 proof - |
212 proof - |