Re: fibint(n), fibbinary(n)

"Ruud H.G. van Tol" <[email protected]> Sun, 11 Jan 2026 23:15:46 +0100
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
On 2026-01-11 18:18, Bill Allombert wrote:
 > On Sun, Jan 11, 2026 at 05:45:42PM +0100, Ruud H.G. van Tol wrote:

 >> I'm looking for an effective (discrete, loop-less) way to derive the 
n-th
 >> fibbinary number (Zeckendorf representation).
 >> For definitions, see https://oeis.org/A003714.
 >>
 >> [ n | n<-[0..100], !bitand(n,n>>1) ]
 >> [0,
 >> 1,
 >> 2,
 >> 4, 5,
 >> 8, 9, 10,
 >> 16, 17, 18, 20, 21,
 >> 32, 33, 34, 36, 37, 40, 41, 42,
 >> 64, 65, 66, 68, 69, 72, 73, 74, 80, 81, 82, 84, 85
 >> ]
 >>
 >> - - - - - -
 >>
 >> While on that path, I'm currently also looking for a discrete 
implementation
 >> of "fibint", and rather without loop.
 >> I think that fibint(n) should return the index of the fibonacci 
number <= n.
 >
 > fibintexa(n)=round(log(sqrt(5)*n)/log((1+sqrt(5))/2))
 > fibint(n)=my(m=fibintexa(n),f=fibonacci(m));if(f>n,f-1,f);

Thanks Bill. You obviously meant

fibint(n)= my(m=fibintexa(n)); if(fibonacci(m)>n,m-1,m);

which indeed performs good.


I then also made that:
fibintexa1(n)= my(sqrt_5=2*quadgen(5)-1); 
round(log(sqrt_5*n)/log((1+sqrt_5)/2));
fibint1(n)= my(m=fibintexa1(n)); if(fibonacci(m)>n,m-1,m);

but my goal is to avoid floating point usage, so I'm still walking. :)

-- Ruud