Maxima interface to Lisp bit-functions
- Subject: Maxima interface to Lisp bit-functions
- From: van Nek
- Date: Fri, 21 Mar 2008 19:35:59 +0100
Some specifications for the proposed bit functions:
Comments welcome.
1. bitwise left shift:
bit_lsh(21,1) => 42
bit_lsh(21,-1) => 10
bit_lsh(x,3) => 2^3*x
bit_lsh(x,-3) => bit_lsh(x,-3)
bit_lsh(x,pos_int) => 2^pos_int*x
bit_lsh(x,n) => bit_lsh(x,n)
bit_lsh(42,pos_int) => 2^pos_int*42
bit_lsh(42,n) => bit_lsh(42,n)
2. bitwise test for bit value 1
bit_onep(8,3) => true
bit_onep(x,3) => bit_onep(x,3)
bit_onep(42,n) => bit_onep(42,n)
3. bitlength
bit_length(8) => 4
bit_length(-8) => 3 (according to Mathematica)
bit_length(-n) => bit_length(n-1) (useful ?)
Meanwhile I couldn't resist to code bit_and, bit_or and bit_xor. I assumed agreement
concerning their specifications. Here is a copy of the rtestbitwise.mac file.
Volker van Nek
bit_and();
-1$
bit_and(42);
42$
bit_and(x);
x$
bit_and(foo(x));
foo(x)$
bit_and(0,x);
0$
bit_and(-1,x);
x$
bit_and(42,63,127);
42$
bit_and(42,z,63,y,127,x);
'bit_and(42,x,y,z)$
bit_and(x,x,x);
x$
bit_and(x,x,x,y);
'bit_and(x,y)$
bit_and(x,-x-1,y);
0$
declare(xx,even);
'done$
bit_and(xx,1);
0$
declare(yy,odd);
'done$
bit_and(yy,1);
1$
bit_or();
0$
bit_or(x);
x$
bit_or(x,x,x);
x$
bit_or(x,x,x,y);
'bit_or(x,y)$
bit_or(0,x,y);
'bit_or(x,y)$
bit_or(-1,x,y);
-1$
bit_or(x,-x-1,y);
-1$
declare(xx,even);
'done$
bit_or(1,xx,y);
'bit_or(xx+1,y)$
bit_or(1,xx,-xx-2);
-1$
declare(yy,odd)$
'done$
bit_or(1,x,yy);
'bit_or(x,yy)$
bit_xor();
0$
bit_xor(7);
7$
bit_xor(x);
x$
bit_xor(x,x);
0$
bit_xor(x,x,x);
x$
bit_xor(5,7,15);
13$
bit_xor(0,x);
x$
bit_xor(-1,x);
-x-1$
bit_xor(5,7,15,x);
'bit_xor(13,x)$
bit_xor(x,-x-1);
-1$
bit_xor(x,-x-1,y,z);
'bit_xor(-y-1,z)$
bit_xor(x+x,-a,-2*x-1,a-1,y,z);
'bit_xor(y,z)$
declare(xx,even);
'done$
bit_xor(1,xx);
xx+1$
declare(yy,odd);
'done$
bit_xor(1,yy,z);
'bit_xor(yy-1,z)$
bit_xor(1,yy,-yy);
-1$