# How do we find the limit of my code?

Suppose we have the following:

t[z_, eps_] := Module[{r, x, y}, r = Rationalize[N[z], eps];
x = Numerator[r];
y = Denominator[r];
N[Log[1/y, Abs[z - x/y]]]];


I want to find the limit of t[z_,eps_] for any z as eps approaches zero.

I tried the following:

T[z_] := T[z] =
Limit[t[z, eps], eps -> 0, Analytic -> True, Direction -> 1]


Edit: I can't use NLimit since my version of Mathematica doesn't recognize it as a code.

When I entered a value for z such as the N[2^(1/3)], I get:

ComplexInfinity


The reason a limit may exist is when I computed z=N[2^(1/3)] and eps=N[10^(-s)] in t[z,epsilon] and get:

Table[t[N[2^(1/3)], N[10^(-s)]], {s, 1, 20}]


I notice the values get smaller and smaller:

{2.37724, 3.32765, 2.21994, 2.41479, 2.13848, 2.36157, 2.02019, \
2.32556, 1.90144, 2.21558, 1.92533, 2.07795, 2.10586, 2.0106, \
2.14276, Indeterminate, Indeterminate, Indeterminate, Indeterminate, \
Indeterminate}


However for extremely small values of eps, t[N[2^(1/3)],eps] is indeterminate, for example for eps=N[10^(-20)] I get:

t[N[2^(1/3)], N[10^(-20)]]
Indeterminate


How do we get a value for extremely small eps such that t[z,eps] eventually converges to a value?

Moreover, how do we approximate T[z] without NLimit?

• Could you add some details? Mathematically, do you know that the limit exists and is different from infinity? What value do you expect? Commented Feb 15, 2022 at 14:52
• At least, t[z_, eps_] := Module[{r, x, y}, r = Rationalize[N[z], eps]; x = Numerator[r]; y = Denominator[r]; N[Log[1/y, Abs[z - x/y]], 100]];t[N[2^(1/3), 100], N[10^(-20), 100]] results in 1.98713460803261520065585604185295512950000090120989878650984094255364\ 13164696205073693. Commented Feb 15, 2022 at 14:56
• Consider Rationalize[N[2^(2/3)], eps] and then Denominator@Rationalize[N[2^(2/3)], eps] which means you're taking the limit of Log[1,...], which is infinity. If there's no closed-form formula for t[], I think you will have to find the limit numerically. Commented Feb 15, 2022 at 15:14
• @MichaelE2 How do we find the limit numerically using NLimit? Commented Feb 15, 2022 at 15:44
• @MichaelE2 I’m not able to compute the limit using NLimit? Commented Feb 15, 2022 at 15:51

I think the lim sup for z = 2^(2/3) is 2 and the lim inf is 1. For Liouville's number $$\lambda=\sum 10^{-n!}$$, I expect the lim sup is infinity. I haven't pursued a proof, and at least in some cases, I expect the proof is probably easy. To compute the limit as a discrete limit, we have to pick a sequence. The limit of the convergents of the continued fraction of 2^(2/3) seems to be 2. Another sequence is to round to the nearest multiple of b^-n for n = 1, 2, 3,.... The limit of these sequences for b = 2, 3, 4,... appears to be 1.

tt // ClearAll;
tt // Options = {WorkingPrecision -> 32,
"MaxExtraPrecision" -> 100000};
itt // ClearAll; (* internal common method *)
mem : itt[z_, n_, 1, p_, maxep_] := mem =
Block[{$$MaxExtraPrecision = maxep}, Module[{r, x, y}, r = FromContinuedFraction@ContinuedFraction[z, n]; x = Numerator[r]; y = Denominator[r]; If[y == 1, 1, N[Log[1/y, Abs[z - x/y]], p] ] ]]; mem : itt[z_, n_, b_, p_, maxep_] := mem = Block[{$$MaxExtraPrecision = maxep},
Module[{r, x, y},
r = Round[z, b^-n];
x = Numerator[r]; y = Denominator[r];
If[y == 1,
0, (* won't affect limit, unless it occurs infinitely often *)
N[Log[1/y, Abs[z - x/y]], p]
]
]];
tt[z_?NumericQ, n_Integer?Positive, OptionsPattern[]] :=
itt[z, n, 1, OptionValue@WorkingPrecision,
OptionValue@"MaxExtraPrecision"];
tt[z_?NumericQ, n_Integer?Positive, b_Integer?Positive,
OptionsPattern[]] :=
itt[z, n, b, OptionValue@WorkingPrecision,
OptionValue@"MaxExtraPrecision"];
an // ClearAll;
an[z_?NumericQ, 1, Optional[b_Integer?Positive, 1]] := tt[z, 1, b];
an[z_?NumericQ, n_Integer?Positive, Optional[b_Integer?Positive, 1]] :=
tt[z, n, b] - tt[z, n - 1, b];


The sum of an gives tt:

Sum[an[2^(2/3), n], {n, 5}]
tt[2^(2/3), 5]
(*
2.215243365028606850170915328762
2.2152433650286068501709153287624
*)


Summing an to get the limit of tt might have issues:

(* rounding to powers of 2 *)
NSum[Sum[an[2^(2/3), 4 (n - 1) + k, 2], {k, 4}], {n, Infinity},
NSumTerms -> 100, WorkingPrecision -> 32]
(*
NumericalMathNSequenceLimit::seqlim: The general form of the sequence could not be determined, and the result may be incorrect.

1.0040403804688150370981112890421
*)

(* continued fraction method *)
NSum[Sum[an[2^(2/3), 4 (n - 1) + k], {k, 4}], {n, Infinity},
NSumTerms -> 100, WorkingPrecision -> 32]
(*
NumericalMathNSequenceLimit::seqlim: The general form of the sequence could not be determined, and the result may be incorrect.

2.0067
*)


Seems easier just to compute a large value of n:

tt[2^(2/3), 10000, 1] (* C.F. --> 2 *)
tt[2^(2/3), 10000, 2] (* Round to b^-n --> 1 *)
tt[2^(2/3), 10000, 3]
tt[2^(2/3), 10000, 5]
tt[2^(2/3), 10000, 6]
(*
2.0001483539767939039872676736424
1.0002967802615836143572950681512
1.0003022219505058138381970338731
1.0003118354013750624713960106114
1.0001494855062849417882032219670
*)


You can use DiscretePlot on tt or an to see that the sequences are not well behaved and converge very slowly. There may be tricks for accelerating convergence of these sequences, but I do not have the time to pursue them at this point.

• Out of curiosity, what would we get if z was a rational? Commented Feb 15, 2022 at 17:37
• @Arbuja Eventually you take the log of zero in the continued fraction sequence and in any sequence that ultimately equals z. In the case where the denominator is not a power of the base b, my guess is that the limit is still 1. Commented Feb 15, 2022 at 17:50