[Maxima] Maxima interface to Lisp bit-functions
macrakis at alum.mit.edu
Fri Mar 21 14:09:55 CDT 2008
Thanks for this!
On 3/21/08, van Nek <van.nek at arcor.de> wrote:
> bit_lsh(x,pos_int) => 2^pos_int*x (presumably you mean non-neg)
> 2. bitwise test for bit value 1
> bit_onep(8,3) => true
I think I'd prefer to define bit_onep(x,i) so that for integer x it is
the same as bit_and(x,2^i)=1. This gives bit_onep(8,2) => true.
Bit_onep extends naturally to all real numbers: bit_onep(0.5,-1) =>
true; bit_onep(%pi,-1)=>false, etc.
Some more simplifications
bit_onep(oddnum,0) => true; evennum,0 => false
bit_onep(k^n,m) => true if (NOT iff) m=n*log(k)/log(2)
bit_onep(x,n) where 0<=x<2^n => false
> 3. bitlength
> bit_length(8) => 4
OK, == floor(log(x)/log(2)) for x>0, right?
> bit_length(-8) => 3 (according to Mathematica)
I'm not sure this is useful, but I don't object strongly.
bit_length(2^n) => n (n>=0) (also 4^n=>2*n, etc.)
More information about the Maxima