Newsgroups: comp.lang.lisp,comp.lang.scheme,sci.crypt,sci.math.num-analysis,sci.math.symbolic,sci.math,comp.lang.c,comp.lang.c++
Path: cantaloupe.srv.cs.cmu.edu!nntp.club.cc.cmu.edu!miner.usbm.gov!news.er.usgs.gov!stc06.ctd.ornl.gov!cs.utk.edu!gatech!csulb.edu!news.sgi.com!howland.erols.net!ix.netcom.com!hbaker
From: hbaker@netcom.com (Henry Baker)
Subject: Re: Name for fcn to find first low-order '1' bit in integer
Content-Type: text/plain; charset=ISO-8859-1
Message-ID: <hbaker-0302972122000001@10.0.2.1>
Sender: hbaker@netcom8.netcom.com
Content-Transfer-Encoding: 8bit
Organization: nil
X-Newsreader: Yet Another NewsWatcher 2.2.0
References: <hbaker-0302971702490001@10.0.2.1> <5d6291$i2g@tools.bbnplanet.com>
Mime-Version: 1.0
Distribution: inet
Date: Tue, 4 Feb 1997 05:22:00 GMT
Lines: 57
Xref: glinda.oz.cs.cmu.edu comp.lang.lisp:25100 comp.lang.scheme:18407 sci.crypt:61605 sci.math.num-analysis:32921 sci.math.symbolic:25250 sci.math:183664 comp.lang.c:234730 comp.lang.c++:245371

In article <5d6291$i2g@tools.bbnplanet.com>, barmar@tools.bbnplanet.com
(Barry Margolin) wrote:

> In article <hbaker-0302971702490001@10.0.2.1>,
> Henry Baker <hbaker@netcom.com> wrote:
> >A week or so ago, I posted a question about what the name of a function
> >which provided the index to the first low-order 1 bit in an integer. 
Curiously,
> >(since Common Lisp defines nearly every other useful function ;-) even Common
> >Lisp does not have a name for this very useful function.
> 
> Interestingly, I think the PDP-10 has an instruction that computed it (JFFO
> -- Jump if Find First One).  So it's surprising to me that the MacLisp
> developers didn't provide an interface to it; had they done so, it surely
> would have been been inherited by Common Lisp.
> 
> Or does JFFO count from the high order down, i.e. it's the function used to
> compute INTEGER-LENGTH?
> 
> >For the record, here is one not particularly efficient Common Lisp definition
> >for val2(n):
> 
> >(defun val2(n) (1- (integer-length (logand n (- n)))))
> 
> Without a built-in, or some low-level interface to bignums, you're probably
> not going to do much better than this.

Such a low-level interface to bignums is precisely what I had in mind.  Many,
if not most, of such packages already provide such a function for the internal
use of the package itself.  I'm suggesting that this function be made available
for users of the package, as well.

> >I'm not sure what the proper value for val2(0) should be, since infinity
> >is not a usual number available.  val2(0) can't be zero, since that doesn't
> >distinguish from cases like val2(1)=0.
> 
> Since it's treating the integer as a bit sequence, it probably makes sense
> to do what the POSITION function does when it can't find a value in the
> sequence: return NIL.  Alternatively, you could specificy that this makes
> no sense, so it should be undefined (like dividing by 0).
> 
> You're the one who needs the function.  In your application, what would you
> like it to do with 0?

In most of the applications I envision, I won't be calling the function with
an argument of 0.  But perhaps other applications that I can't envision
right now, might have a better idea of what this value should be.

> >Another question arises as to what the value of val2(floating point number)
> >should be.  I'm open to suggestions.
> 
> It should probably be undefined (signal TYPE-ERROR under high safety).
> This function is clearly intended only for integers.

Well, I didn't go into it, but it is my understanding that v_p(n) is defined
also for _rational_ numbers m/n, and if gcd(m,n)=1, then v_p(m/n)=v_p(m).
(I hope I got it right; I haven't worked much with p-adics.)
