Apparently, _Rational is an illegal Mma compiler type, let alone _Integer|_Rational, but taking the trouble to rewrite it in integers, In[1192]:= Compile[{{N, _Integer}, {D, _Integer}}, Module[{n = N, d = D, k = 0}, While[n > 0, ++k; {n, d} = {2*n*Ceiling[d/n] - n - d, n}]; k], CompilationTarget :> "C"] Out[1192]= CompiledFunction[] In[1194]:= Timing[%1192[355, 113]] Out[1194]= {4.614657, 67107847} Compare with %1134 below. --rwg I was under the delusion of needing {n,d}={n,d}/GCD[n,d] in the loop. This is an error because you can't(?) specify integer divide, and {n,d}=Floor[{n,d}/GCD[n,d]] is exorbitant. Lucky it was a delusion. On Sat, Oct 5, 2013 at 9:43 PM, Bill Gosper <billgosper@gmail.com> wrote:
Is anything known about the growth of this function? In[1130]:= NestWhile[{2*Ceiling[1/#[[1]]] - 1 - 1/#[[1]], #[[2]] + 1} &, {3/8, 0}, #[[1]] != 0 &]
Out[1130]= {0, 20}
In[1131]:= NestWhile[{2*Ceiling[1/#[[1]]] - 1 - 1/#[[1]], #[[2]] + 1} &, {22/7, 0}, #[[1]] != 0 &]
Out[1131]= {0, 519}
In[1132]:= NestWhile[{2*Ceiling[1/#[[1]]] - 1 - 1/#[[1]], #[[2]] + 1} &, {355/113, 0}, #[[1]] != 0 &]
Out[1132]= {0, 67107847}
Checks:
In[1133]:= Timing[ NestWhile[{1/(2*Floor[#[[1]]] + 1 - #[[1]]), #[[2]] + 1} &, {0, 0}, #[[1]] != 22/7 &]]
Out[1133]= {0.005219, {22/7, 519}}
In[1134]:= Timing[ NestWhile[{1/(2*Floor[#[[1]]] + 1 - #[[1]]), #[[2]] + 1} &, {0, 0}, #[[1]] != 355/113 &]]
Out[1134]= {700.483896, {355/113, 67107847}} --rwg
On Sat, Oct 5, 2013 at 6:20 PM, Bill Gosper <billgosper@gmail.com> wrote:
In[1106]:= NestList[2*Ceiling[1/#] - 1 - 1/# &, 3/8, 22]
Out[1106]= {3/8, 7/3, 4/7, 5/4, 1/5, 4, 3/4, 5/3, 2/5, 5/2, 3/5, 4/3, 1/4, 3, 2/3, 3/2, 1/3, 2, 1/2, 1, 0, Indeterminate, Indeterminate}
So 3/8 is the "20th rational".
The 68th iterate on √2: In[1127]:= ContinuedFraction[ Nest[Simplify[2*Ceiling[1/#] - 1 - 1/#] &, Sqrt[2], 68]]
Out[1127]= {1, 1, 1, 1, 1, 1, 1, 1, 1, {2}}
I.e., it tries to disguise √2 as the golden ratio by sticking nine 1s on the front. Many other iterates of this process produce CFs with only 1s and 2s. --rwg