Ruud H.G. van Tol on Tue, 23 Jan 2024 09:36:36 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: log_int_rat



On 2024-01-23 09:07, Ruud H.G. van Tol wrote:
On 2024-01-22 21:05, Bill Allombert wrote:
On Mon, Jan 22, 2024 at 02:30:13PM +0100, Ruud H.G. van Tol wrote:
safedigits(f)=
{
    my(z=f(),e=exponent(z),k=3,r);
    while(1,
      my(K=10^k,y=round(K*z,&r));
      if (r<0 && (y+1)%K>1, return(y\K));
      k*=2;
      localbitprec(e+4*k);z=f());
}
a(n) = localbitprec(logint(n+2,2)); 1+n+safedigits(()->(n*log(2)/log(3/2)));
To me this is just another example of why to avoid floats and floor() and
such, when the goal is integers.

So I'm back at my original quest. :)
? a054414(n) = 1 + n + floor( n * log(2) / log(3/2) );
Is there a cleaner way, similar to logint, to do that floor-expression?
The table() function (from Bill) made me think that a discrete a(n),
ideally without any slow while-loop, is doable,
so I will keep looking and trying in that direction.
Well, you can take a middle ground: compute an approximation of the result
using floating point and check and ajust it using exact arithmetic.

That had indeed crossed my mind, and is likely the way
that the world needs and is waiting for. ;)

My gut still says that there would be a "cleaner" way, and I am not in a hurry.

Then, implementing the shoot-and-fix trick could well involve "learnings"
that bring the Diophantine method closer!

Thanks, Ruud
(yeah, it's fun)

And apologies for selling Diophantus short here.
https://en.wikipedia.org/wiki/Diophantine_approximation
https://en.wikipedia.org/wiki/Adequality

-- Ruud