[OT] Number theory [Was: A use for integer quotients]

David C. Ullrich ullrich at math.okstate.edu
Mon Jul 30 10:20:01 EDT 2001


On Sun, 29 Jul 2001 22:13:18 -0700, David Eppstein
<eppstein at ics.uci.edu> wrote:

>In article <3b645f76.747435355 at wa.news.verio.net>,
> bokr at accessone.com (Bengt Richter) wrote:
>
>> ISTM that thinking of bit twiddling as operating on integers
>> is not clean conceptually. I.e., I think there is an implicit
>> coercion to a set type for the twiddle operation and then implicitly
>> back to integer again when supposedly twiddling two integers
>> with a binary twiddling operation (same for unary, of course).
>
>Bit-twiddling operations like bitwise xor are generally not nice continuous 
>operations on (binary representations of) real numbers, e.g. because 
>0.11111... and 1.00000... are the same as real numbers but very different 
>as bitstrings.
>
>However, I think bit twiddling is nice and continuous if instead you use 
>2-adic numbers (overcondensed tutorial: 2-adic integers are binary numbers 
>where the bit sequence goes to infinity to the left instead of to the 
>right, e.g. 3 1/4 = .....000011.01 -- just apply usual 2's complement 
>arithmetic to these sequences and everything works).
>
>Of course, this doesn't do much for your attempt to make this thread 
>relevant to Python again...

The discontinuities in bit twiddling are certainly relevant to
programming in general: There's a person elsewhere wondering why
his FFT-based image format is giving bizarre results, and the
answer has a lot to do with the discontinuity of the n-th bit
of x. (He's packing several channels into one number before
doing the FFT - now discontinuities mean that small numeric
errors give huge errors in the decoded channels.)

Of course a Python programmer wouldn't do that...

>David Eppstein       UC Irvine Dept. of Information & Computer Science
>eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/


David C. Ullrich



More information about the Python-list mailing list