New mpz_lucas... functions

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Thu Jul 14 15:19:24 CEST 2011


Hi,

Il Gio, 14 Luglio 2011 6:00 am, David Cleaver ha scritto:
> int mpz_lucasu(mpz_t rop, int p, int q, int k)
> int mpz_lucasumod(mpz_t rop, int p, int q, int k, mpz_t n)
> int mpz_lucasv(mpz_t rop, int p, int q, int k)
> int mpz_lucasvmod(mpz_t rop, int p, int q, int k, mpz_t n)
>
> With these functions, you can generate several familiar sequences, like:
> U[k](1,-1) : Fibonacci Numbers
> V[k](1,-1) : Lucas Numbers

As you can see from the manual of GMP [
http://gmplib.org/manual/Number-Theoretic-Functions.html#index-Binomial-coefficient-functions-400
] we already have:

void mpz_fib_ui (mpz_t fn, unsigned long int n)
void mpz_fib2_ui (mpz_t fn, mpz_t fnsub1, unsigned long int n)
void mpz_lucnum_ui (mpz_t ln, unsigned long int n)
void mpz_lucnum2_ui (mpz_t ln, mpz_t lnsub1, unsigned long int n)

I mean: the functions that are actually available in the standard GMP
library, and are more similar to the functions you propose, use long int
for the parameters and void for return. You should probably consider it.

> my computer it takes about 0.03 seconds to calculate the 1000000th
> Fibonacci Number.

It would be nice to have a speed comparison with current code for
Fibonacci. We may expect that the code in the library is faster, because
it is not as general as yours, but the difference should not be too large.

> I have a c file already written, but wanted to see if there was interest
> before sending it out.

I'd rather reverse the sequence. I suggest you to publish your code (with
some free licence of your choice), so that anyone can test it. It can be
useful even if it is not integrated in the GMP library yet.

Regards,
Marco

-- 
http://bodrato.it/software/combinatorics.html



More information about the gmp-discuss mailing list