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!jobone!newsxfer3.itd.umich.edu!su-news-hub1.bbnplanet.com!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!howland.erols.net!ix.netcom.com!hbaker
From: hbaker@netcom.com (Henry Baker)
Subject: Name for fcn to find first low-order '1' bit in integer
Content-Type: text/plain; charset=ISO-8859-1
Message-ID: <hbaker-0302971702490001@10.0.2.1>
Sender: hbaker@netcom2.netcom.com
Content-Transfer-Encoding: 8bit
Organization: nil
X-Newsreader: Yet Another NewsWatcher 2.2.0
Mime-Version: 1.0
Date: Tue, 4 Feb 1997 01:02:49 GMT
Lines: 50
Xref: glinda.oz.cs.cmu.edu comp.lang.lisp:25086 comp.lang.scheme:18397 sci.crypt:61589 sci.math.num-analysis:32912 sci.math.symbolic:25243 sci.math:183632 comp.lang.c:234622 comp.lang.c++:245250

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.

A finally found a positive reference for the use of the notation v_p(n)
for this function when p=2 -- i.e., v_2(n).  This is the so-called p-adic
'valuation' function, which for p=2 is the function I was looking for.

Gouvea, F.Q.  p-adic Numbers.  Springer, NY 1993.

also

Calderbank, A.R., et al.  "A 2-Adic Approach to the Analysis of Cyclic Codes".
Found on a netlib site on the web.

Therefore, I would propose that programming languages now standardize on
such a function and such a name, so that we don't have 10,000 different
names for the same function.

In particular, the name (in the binary case) could be one of:

val2(n)
val_2(n)
valu2(n)
valu_2(n)
valuation2(n)
valuation_2(n)

depending upon whether you belong to the 'long name' (Ada, Lisp, etc.)
school, or the 'short name' (C, etc.) school of function names.

(the "_" here means the ascii "_" character, and not TeX subscript).

Since binary notation is so ubiquitous, I would _not_ suggest generalizing
this function to val(n,2), since val(n,p) for p/=2 is considerably more
expensive to compute, and considerably less common, since val2(n) is useful
for lots of things having nothing to do with p-adic arithmetic.

For the record, here is one not particularly efficient Common Lisp definition
for val2(n):

(defun val2(n) (1- (integer-length (logand n (- n)))))

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.

Another question arises as to what the value of val2(floating point number)
should be.  I'm open to suggestions.
