Date: Mon, 23 Apr 2007 23:50:04 +0100 (BST)
   From: Ben Harris <[EMAIL PROTECTED]>
   Cc: [EMAIL PROTECTED]

   Ah, yes, I think I got carried away with the cuteness of the idea and 
   didn't bother to check it was actually true.

And it is a cute idea.  My hat's off to you for having the original
inspiration!

   > If bitwise-bit-count was defined as:
   > 
   >   (define (bitwise-bit-count n)
   >     (if (negative? n)
   >    (- (+ 1 (bitwise-bit-count (bitwise-not n))))
   >    <whatever>))
   > 
   > Then you could count the bits set in an N-bit word by taking
   > the bitwise-bit-count mod N+1.  This would also make the
   > claim in the subject actually true.

   Indeed, and it wouldn't break the other nice property I'd produced.  It
   loses a little symmetry, in that (- (bitwise-bit-count x)) is no longer
   equal to (bitwise-bit-count (bitwise-not x)), but two's-complement
   arithmetic is inherently asymmetric like this, so I'm not sure that's a
   bad thing.

You want symmetry?  I'll give you symmetry...  Under the revised definition
(bitwise-not (bitwise-bit-count x)) is equal to
(bitwise-bit-count (bitwise-not x))!

In fact I could have written the definition this way:

   (define (bitwise-bit-count n)
     (if (negative? n)
         (bitwise-not (bitwise-bit-count (bitwise-not n)))
         <whatever>))

- Alan

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to