Ruud H.G. van Tol on Wed, 01 Mar 2023 10:59:46 +0100


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

Re: [seqfan] An unexpected formula related to the Hamming weight of integers



On 2023-02-28 19:54, Thomas Baruchel wrote:
Pari/GP [...] floor(log(n+1)/log(4)+1);

Consider using logint() for such cases:

-- -- -- -- -- -- --
? ??logint

logint(x,b,{&z}) [...]
Return the largest integer e so that b^e <= x
[...] replace floor( log(x) / log(b) )
which may not give the correct answer
since PARI does not guarantee exact rounding.
-- -- -- -- -- -- --


  floor( log(n+1) / log(4) + 1 )
->
  floor( log(n+1) / log(4) ) + 1
->
  logint( n+1, 4 ) + 1

-- Ruud