[math-fun] "how many newman(step)s does it take
to tack a 1 on the front of a cf?" Apparently, this question is a thought crime. If there are already six 1s on the front, the answer is 128: In[634]:= cfzewm[{1, 1, 1, 1, 1, 1, 69}, 128] Out[634]= {1, 1, 1, 1, 1, 1, 1, 69} Independent of "69": In[635]:= cfzewm[{1, 1, 1, 1, 1, 1, 105}, 128] Out[635]= {1, 1, 1, 1, 1, 1, 1, 105} But for four initial 1s the answer is only 32: In[637]:= cfzewm[{1, 1, 1, 1, 288}, 32] Out[637]= {1, 1, 1, 1, 1, 288} So clearly for five 1s, we need In[636]:= cfzewm[{1, 1, 1, 1, 1, 69}, 28334198897217871282112] Out[636]= {1, 1, 1, 1, 1, 1, 69} Excuse me kids, but WtF?? And it depends (heavily) on the "69": In[638]:= cfzewm[{1, 1, 1, 1, 1, 9}, 24512] Out[638]= {1, 1, 1, 1, 1, 1, 9} This is paradoxical. The four 1s case *is* dependent on the "288". No, not if we make it 69: In[639]:= cfzewm[{1, 1, 1, 1, 69}, 32] Out[639]= {1, 1, 1, 1, 1, 69} But we can make it a noninteger: 139/70 = {1,1,69} In[641]:= cfzewm[{1, 1, 1, 1, 139/70}, 128] Out[641]= {1, 1, 1, 1, 1, 1, 1, 69} which takes 128 because this is equivalent to the six 1s case. Can someone make sense of this? --Bill Here are Neil's magic functions, in case you want to play with this: ([[2;;-1]] instead of //Rest is a sign of the remarkable haste with which he wrote this.) cfzewm[cf_, n_: 1] := ContinuedFraction[ Divide @@ pos2newman[n + newman2pos[FromContinuedFraction[cf]]]] (*Note: n can be negative.*) calkinwilf[num_, denom_] := Block[{lis = {}, n = num, d = denom}, (While[ n > 1 || d > 1, (lis = Prepend[lis, Boole[n > d]]; If[n > d, n -= d, d -= n])]; lis)] wilfcalkin[bitlis_List] := Block[{n = 1, d = 1}, (Do[ If[bitlis[[i]] == 0, d += n, n += d], {i, 1, Length[bitlis]}]; {n,d})] newman2pos[num_, denom_] := FromDigits[Prepend[calkinwilf[num, denom], 1], 2] newman2pos[frac_] := newman2pos[Numerator[frac], Denominator[frac]] pos2newman[pos_] := wilfcalkin[IntegerDigits[pos, 2][[2 ;; -1]]]
participants (2)
-
Bill Gosper -
Marc LeBrun