Karim Belabas on Wed, 28 Dec 2022 17:52:45 +0100


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

Re: A022921-code


* Ruud H.G. van Tol [2022-12-28 16:28]:
> 
> [ logint(3^(n+1),2) - logint(3^n,2) |n<-[0..98]]
> 
> is half as fast as
> 
> 
> 
> but IMO looks ugly.
> 
> Is there a both "nice" and fast way to do similar?

Not sure about "nice"; but faster, definitely:

? N = 30000;
? w0 = [logint(3^(n+1),2) - logint(3^n,2) | n<-[0..N]];
time = 767 ms.

? my(n0=logint(3^0,2)); w1 = [-n0 + n0=logint(3^(n+1),2) |n<-[0..N]];
time = 355 ms.

? my(v = [logint(x,2) | x <-powers(3, N+1)]); w = vector(#v-1, i, v[i+1]-v[i]);
time = 20 ms.

? [w == w0, w == w1]
%4 = [1, 1]

Cheers,

    K.B.
--
Karim Belabas  /  U. Bordeaux,  vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/
`