# [Maxima] Maxima interface to Lisp bit-functions

van Nek van.nek at arcor.de
Mon Mar 17 14:20:14 CDT 2008

```Am 17 Mar 2008 um 13:55 hat Stavros Macrakis geschrieben:

> 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).

Stavros, my intention is the here, to make clear the shift direction just by the functions
name. The original Lisp function ash (artihmetric shift) doesn't do so. But you are right,
lsh(x,-1) is understandable as a shift to the right.

> >  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)?

integer_length(-1) returns 0, because for negative integers it returns the position of the
leftmost zero (the leftmost 1 in case of positive ints).
So integer_length(-2^100) returns 100.

> >  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;

It was not my intention to handle these numbers. I just looked into the Mathematica doc and
they also only care about integers.

Stavros, do you see an interesting application of such to rationals extended bitwise
operations ?

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

Right, these are useful simplifications. Can you give me any hint, how to manage them.