Maxima interface to Lisp bit-functions



On 3/21/08, van Nek <van.nek at arcor.de> wrote:

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

Hi Volker, thanks for working on this topic. The names bit_foo
are OK by me. It appears that right-shift has gone away.
I recommend that we bring it back, with just one rule which
simplifies bit_rsh(a, b) => bit_lsh(a, - b).

I think I see which rule each example above is supposed to represent,
but I'm pretty sure the specification for bitwise functions ought to be
phrased in general terms, e.g. bit_lsh(x, y) => 2^y*x where y is a
literal integer, y > 0, and x is any expression. Maxima lacks such
specifications for most built-in operators, so the usual way to
determine which identities are implemented by simplification
functions is to read the code. I think that is a major defect, and now
that we are inventing some new operators, we should try to avoid it.

About bit_lsh(x,-3) => bit_lsh(x,-3), I would expect from bit_lsh(x, 3)
 => 2^3*x that bit_lsh(x, - 3) => x/2^(- 3). It appears that left-shift
operations are simplfiied but not right-shift; I don't see why.

>  Meanwhile I couldn't resist to code bit_and, bit_or and bit_xor.
> I assumed agreement concerning their specifications.

Already I'm not sure what we did or did not agree on. When the
time comes to write the code, we'll want to paste the
specification (if we have one) into the comments, so we
may as well write it out now.

I'm probably making too much noise about the process of
developing these bitwise operators, since historically speaking
the vast majority of the Maxima code has been written without
any definite specification. But it would certainly strengthen the
bitwise stuff to write out and record a specification, and, perhaps,
help us get in the habit of it for other projects.

Thanks again & all the best.

Robert Dodier