[math-fun] fun function
I was considering a way to represent any real number by a binary fraction in ( -1, +1 ). Here's the function that maps the representation to the number represented. I typed it into Python and tried it out pretty much this way:
def sb( x ): ... if abs(x) >= 1: ... raise ValueError ... elif x < 0: return -sb( -x ) ... elif x == 0: return 0.0 ... else: return 2.0 ** sb( 2.0 * x - 1.0 ) ... sb( 0 ) 0.0 sb( .5 ) 1.0 sb( .75 ) 2.0 sb( 7.0 / 8.0 ) 4.0 sb( 15.0 / 16.0 ) 16.0 sb( 31.0 / 32.0 ) 65536.0 sb( 1.0 / 3.0 ) 0.641185744504986
...wait. Why did that last line return anything at all? Does the function I'm computing have a name? Just looking at the Python procedure, how do you think it computes sb( 1/3 )? (I've never seen an algorithm (if you can even call it that) work like this.) Without going to Google, Plouffe's Inverter or a calculator, what's the significance of 0.641185744504986? You can find it by expanding sb( 1/3 ) three steps. http://www.tiac.net/~sw/2010/03/Superbola --Steve
From: Steve Witham <sw@tiac.net> To: math-fun@mailman.xmission.com Sent: Thu, April 1, 2010 1:03:50 PM Subject: [math-fun] fun function I was considering a way to represent any real number by a binary fraction in ( -1, +1 ). Here's the function that maps the representation to the number represented. I typed it into Python and tried it out pretty much this way:
def sb( x ): ... if abs(x) >= 1: ... raise ValueError ... elif x < 0: return -sb( -x ) ... elif x == 0: return 0.0 ... else: return 2.0 ** sb( 2.0 * x - 1.0 ) ... sb( 0 ) 0.0 sb( .5 ) 1.0 sb( .75 ) 2.0 sb( 7.0 / 8.0 ) 4.0 sb( 15.0 / 16.0 ) 16.0 sb( 31.0 / 32.0 ) 65536.0 sb( 1.0 / 3.0 ) 0.641185744504986
...wait. Why did that last line return anything at all? Does the function I'm computing have a name? Just looking at the Python procedure, how do you think it computes sb( 1/3 )? (I've never seen an algorithm (if you can even call it that) work like this.) Without going to Google, Plouffe's Inverter or a calculator, what's the significance of 0.641185744504986? You can find it by expanding sb( 1/3 ) three steps. http://www.tiac.net/~sw/2010/03/Superbola --Steve _______________________________________________ The function terminates due to the finite precision of floating point. When the recursion finally unwinds, the resulting calculation consists of starting with x = 0, and successively substituting x = 2^(-x) as many times as the bit precision of floating point. Because the slope of 2^(-x) has absolute value less than 1, the sequence converges to the intersection point of y = x and y = 2^(-x). -- Gene
participants (2)
-
Eugene Salamin -
Steve Witham