Maxima interface to Lisp bit-functions



On Mon, Mar 17, 2008 at 1:18 PM, van Nek <van.nek at arcor.de> wrote:
>  lsh(int, count): left shift
>  lsh(int):  count=1 by default
>  rsh(int, count): right shift
>  rsh(int):  count=1 by default

I would recommend that you choose either lsh or rsh as fundamental,
and simplify the other one to it, e.g. rsh(x,2) == lsh(x,-2).

>  integer_length(int):  length of the bit representation

I assume you treat negative numbers as their two-complement bitstring,
e.g. logior(-1,x)=>-1.

What is integer_length(-1)?  Is it the same as integer_length(-2^100)?

>  All function behave as follows:
>
>  if all args are integers => evaluation

I think you mean that they simplify to integers.

>  if at least one arg is a string, a Maxima list or constant but not an integer => merror

Why not extend to non-integers?  logior(1/2,1/3) => 5/6;
logand(1/3,2/3) => 0;  logand(1/3,1/9) => 5/63; logand(1.0/3,1.0/9) =>
0.079365079365079. This is *not* the logand of the floating-point
representation, but of the binary fraction it represents.

Then again, there is a problem here... how do you represent the
difference between 1.00000000... and 0.11111111... taken as
bitstrings?

Gets harder for irrationals, of course.... logior(1/2,sqrt(2)) =>
sqrt(2)+1/2, but logior(1/3,sqrt(2)) let alone logand(%e,%pi) is not
at all obvious.

>  all other cases => unevaluated expression

I think you mean un<<simplified>> expression.

>  in addition: logbitp errors, if index is negativ

Why not false for integers?

There are many other useful simplifications, e.g. logand(x,x) => x,
logand(evenpobj,1) => 0, logior(x-1,-x) => -1, etc.

            -s