back to list

Ministry of Funny Kludges

🔗Gene Ward Smith <genewardsmith@coolgoose.com>

6/3/2006 2:45:12 PM

Conway rediscovered the Minkowski ?(x) function, and in typical Conway
style he went Minkowski one better by denoting the inverse function by
drawing a box around the x. I'm just calling it box(x), and I call the
? function quest(x) because Maple won't let me call it ?(x). I give
routines below for quest and box, and if all is well then these should
be inverses, with x = quest(box(x)) = box(quest(x)). However, testing
my box routine out I found an anomaly, where box(n+1/8) returned (for
any integer n) n+1/16, whereas it was supposed to give n+1/4. I can't
find any other anomalous values! This seems a little strange, but
below I just patch the one anomaly I did find. If anyone can another
anomaly, I'd be interested, because I've never seen anything quite
like this one--why 1/8??

Here's the Maple code:

invcon := proc(l)
# inverse continued fraction
local d, i, h, k;
h[-2] := 0;
h[-1] := 1;
k[-2] := 1;
k[-1] := 0;
for i from 0 to nops(l)-1 do
h[i] := l[i+1]*h[i-1] + h[i-2];
k[i] := l[i+1]*k[i-1] + k[i-2];
d[i+1] := h[i]/k[i] od;
convert(convert(d, array), list) end:

quest := proc(x)
# Minkowski ? function
local i, j, d, l, s, t;
l := convert(x, confrac);
d := nops(l);
s := l[1];
for i from 2 to d do
t := 1;
for j from 2 to i do
t := t - l[j] od;
s := s + (-1)^i * 2^t od;
if type(x, float) then s := evalf(s) fi;
s end:

box := proc(x)
# inverse ? function
local d, e, i, n, w, y;
if type(x, integer) then RETURN(x) fi;
y := x-floor(x);
if y = 1/8 then RETURN(floor(x)+1/4) fi;
w := round(l2(10)*Digits)-5;
n := round(2^w * y);
i :=0;
while n>0 do
i := i+1;
if modp(n,2)=0 then
d[i] := ordp(n, 2);
n := n/2^d[i];
else
d[i] := ordp(n+1, 2);
n := (n-2^d[i]+1)/2^d[i] fi od;
e := convert(convert(d, array), list);
e := subsop(1=NULL,e);
w := ceil(-l2(y));
e := [op(e), w];
e := [op(e), floor(x)];
e := rev(e);
n := invcon(e);
w := n[nops(n)];
if type(x, rational) and modp(denom(x), 2)=0 then RETURN(w) fi;
evalf(w) end: