In 1985 I animated an infinte zoom on a continuous function satisfying: f([0,1]) -> [0,1], f(0) = 0, f(1) = 1, f'(x) < 0 almost everywhere. In fact, f' went arbitrarily negative. A simpler case, with f' = -1 A.E., is 2 d(x) - x, where d is the devil's staircase. Two (slightly nonstandard?) recipes for d(x): inf ==== n \ floor(2 x) 1. Invert g(x) = 2 > ----------- . / n + 1 ==== 3 n = 1 2. Write x in base 3, change all 2s to 1s, stop after the first 1 (if ever), interpret in base 2. A Macsyma function, exact on rationals: dvl(x):=if x=0 then 0 else if integerp(denom(x)/3) then dvl(3*x)/2 else block([p:period(denom(x),3),l:floor(logb(3,x)),a:0], x:x/3^l, for j:0 thru max(l,0)+p do (a:2*a, if x>1 then (a:a+1,if x>2 then x:x-2 else return(j)),x:3*x), if %%=done then (divide(a,2^p)*2^min(0,l),%%[1]+%%[2]/(2^p-1)) else a*2^(l-%%)); period(modulus,b):=(modulus/b, if integerp(%%) then period(%%,b) else for d in divisors(totient(modulus)) do if nummod(?cbexpt(b,d)-1,modulus)=0 then return(d)); (c198) map(dvl,[0,1/4,3/13,1]) 1 2 (d198) [0, -, -, 1] 3 7 g preserves rationality and irrationality, is increasing, and is continuous except at dyadic rationals. d is continuous and preserves rationality but not irrationality. d^-1 is defined except at dyadic rationals. A Fourier series which repeats the staircase with period 1: 1/2-sum((1-(-1)^k*prod(1-2*sin(((%pi*k)/(3^n)))^2,n,1,inf))*sin(2*%pi*k*t)/k,k,1,inf) inf /===\ k | | 2 %pi k inf (1 - (- 1) | | (1 - 2 sin (-----))) sin(2 %pi k t) ==== | | n \ n = 1 3 > ----------------------------------------------------- / k ==== 1 k = 1 - - -----------------------------------------------------------. 2 %pi (from my paper in the McCarthy Festschrift). Like a school bell, it only rings between periods (empirically confirming the continuity of the staircase.) Unlike the ruler function, g is "semicontinuous", i.e., has no isolated values. A semicontinuous version of the ruler function might be h(x):= sum(floor(n*x)/n^2,n,1,inf), whose inverse is a devil's staircase with steps at every rational. That this inverse has a finite domain (i.e., h has a finite range) proves that the rationals have measure 0. Two other semicontinuous functions with jumps at the dyadic rationals are Gray-to-binary and its inverse, when extended to reals simply by breezing past the binary point. Since this doesn't preserve integerhood, they aren't strictly extensions. Exact-on-rationals: g2b(x):=if x=0 then 0 else if evenp(denom(x)) then g2b(2*x)/2 else block([p:2*period(denom(x),2),a:0,b:0,c,l:bitsin(x)],c:2^(l-1), thru p+1+l:max(l,0) do a:2*a+if x<c then (x:2*x,b) else (x:2*(x-c),b:c-b), divide(a/c,2^p)*c/2^l,%%[1]+%%[2]/(2^p-1)); b2g(n):=if evenp(denom(n)) then b2g(2*n)/2 else block([p:period(denom(n),2)],floor(n*2^(1+p)), divide(logxor(%%,?ash(%%,-1)),2^p),(%%[1]+%%[2]/(2^p-1))/2); bitsin(x):=1+floor(logb(2,x)); And because they are 1:1 on (right-infinite) bit strings, they are *not* 1:1 on reals, due to the ambiguity of dyadic rationals: (c208) map(g2b,[0,1/5,1/4,1/3,1/2,2/3,3/4,4/5,1]) 2 1 2 4 1 8 (d208) [0, --, -, -, 1, -, -, --, 2] 15 2 5 5 2 15 (c209) map(b2g,%) 1 3 1 3 2 3 4 (d209) [0, -, -, -, -, -, -, -, 3] 5 4 3 2 3 4 5 Denominators can jump exponentially: (c211) g2b(1/19) 9914 (d211) ------ 262145 (c212) b2g(%) 1 (d212) -- 19 (c213) b2g(%) 47 (d213) ---- 1022 (c214) g2b(%) 1 (d214) -- 19 --rwg