Ruud H.G. van Tol on Mon, 22 Jan 2024 04:26:56 +0100


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

Re: log_int_rat



On 2023-11-29 22:15, Ruud H.G. van Tol wrote:
On 2023-11-29 21:17, Bill Allombert wrote:
On Wed, Nov 29, 2023 at 07:44:11PM +0100, Ruud H.G. van Tol wrote:
? a054414(n) = 1 + n + floor( n * log(2) / log(3/2) );

? [ a054414(n) |n<-[0..20]]
% [1, 3, 6, 9, 11, 14, 17, 19, 22, 25, 28, 30, 33, 36, 38, 41, 44, 47, 49,
52, 55]

Is there a cleaner way, similar to logint, to do that floor-expression?
[...]
If being slow is not an issue, I suppose you can do:
  a054414(n)=my(a=2^n,b=1);while(a>=b,a*=2;b*=3;n++);n
and
table(n)=my(a=1/2,b=1);vector(n+1,i,a*=2;while(a>=b,a*=2;b*=3);valuation(a,2));

? table(20)
%12 = [1,3,6,9,11,14,17,19,22,25,28,30,33,36,38,41,44,47,49,52,55]

[...]
The https://oeis.org/A054414 page doesn't have a PARI-prog yet, so I will at least propose alist(n=60) = my(a=1/2, b=1); vector(n+1, i, a*=2; while(a>=b,a*=2;b*=3); valuation(a, 2));
[...]

Now proposed it as:

alist(N=61) = {
  my(a=1/2, b=1, r=-1);
  vector(N, i, a*=4; b*=3; r+=2; if(a>b, a*=2; b*=3; r++); r);
}

-- Ruud