Ruud H.G. van Tol on Wed, 28 Dec 2022 19:54:56 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: A022921-code |
On 2022-12-28 17:51, Karim Belabas wrote:
* 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 my(n0=logint(3^0,2)); [ -n0 + n0=logint(3^(n+1),2) |n<-[0..98]] 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]
Pretty "nice" to me.I'm testing on an M1-Max, and could *not* run your fastest alternative under 120ms.
But then I slightly changed it to my(v = [logint(x,2) | x <-powers(3, N+1, 1)]); w = vector(#v-1, i, v[i+1]-v[i]) (so added the explicit '1' with powers) and then it would run at least twice as fast, and would (sometimes) finish in 29ms. How weird is that? (No need to answer!) $ gp --version 2>&1 |sed 's/^ *//' GP/PARI CALCULATOR Version 2.15.1 (released) arm64 running darwin (aarch64/GMP-6.2.1 kernel) 64-bit version compiled: Nov 5 2022, Apple clang version 14.0.0 (clang-1400.0.29.202) threading engine: pthread (readline v8.2 disabled, extended help enabled) -- Ruud