# [Maxima] Maxima interface to Lisp bit-functions

Richard Fateman fateman at cs.berkeley.edu
Fri Mar 21 16:04:51 CDT 2008

```I haven't chimed in here, but I suspect that the subject is not right.

If you are defining new functions that operate on Maxima data like %pi and
x, then you are not interfacing to lisp functions.  You are defining analogs
to lisp functions that can be used in Maxima, suitably extended for the
cases that lisp would give errors on.

I don't really have a problem with that latter task, just the subject line
:)
rjf

_____

From: maxima-bounces at math.utexas.edu [mailto:maxima-bounces at math.utexas.edu]
On Behalf Of van Nek
Sent: Friday, March 21, 2008 1:59 PM
To: Stavros Macrakis
Cc: Maxima at math.utexas.edu
Subject: Re: [Maxima] Maxima interface to Lisp bit-functions

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

Mmmh? 8=2^3. I can't follow here.

> Bit_onep extends naturally to all real numbers: bit_onep(0.5,-1)
> =>
> true; bit_onep(%pi,-1)=>false, etc.

I know you are in favour of extending these functions. But today I regard
these extensions as future plans.

> 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

Thank you for this. I will try to code it.

> > 3. bitlength
> > bit_length(8) => 4
>           OK, == floor(log(x)/log(2)) for x>0, right?

No, 8=1000
and floor(log(8)/log(2)) = 3

I think
bit_length(x)== floor(log(x)/log(2))  + 1 for x>0

By the way, there is a floor bug:
(%i1) floor(log(8)/log(2));
(%o1)                                  2
(%i2) float(log(8)/log(2));
(%o2)                                 3.0

> bit_length(2^n) => n (n>=0)  (also 4^n=>2*n, etc.)

Thank you for this. I will try to code it.
But again, I think it's
bit_length(2^n) => n +1  (n>=0)  (also 4^n=>2*n+1, etc.)

Volker

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.math.utexas.edu/pipermail/maxima/attachments/20080321/627ab9c6/attachment-0001.htm
```