gmp_libmpz_lucnum2_ui Method |
Namespace: Math.Gmp.Native
This function is designed for calculating isolated Lucas numbers. When a sequence of values is wanted it’s best to start with mpz_lucnum2_ui and iterate the defining L[n + 1] = L[n] + L[n - 1] or similar.
The Fibonacci numbers and Lucas numbers are related sequences, so it’s never necessary to call both mpz_fib2_ui and mpz_lucnum2_ui. The formulas for going from Fibonacci to Lucas can be found in GNU MP - Lucas Numbers Algorithm, the reverse is straightforward too.
// Create, initialize, and set the values of lnsub1 and ln to 0. mpz_t ln = new mpz_t(); mpz_t lnsub1 = new mpz_t(); gmp_lib.mpz_inits(ln, lnsub1, null); // Set lnsub1 and ln to the 8'th and 9'th Lucas nunbers respectively. gmp_lib.mpz_lucnum2_ui(ln, lnsub1, 9U); // Assert that lnsub1 and ln are respectively 47 and 76. Assert.IsTrue(gmp_lib.mpz_get_si(lnsub1) == 47); Assert.IsTrue(gmp_lib.mpz_get_si(ln) == 76); // Release unmanaged memory allocated for ln and lnsub1. gmp_lib.mpz_clears(ln, lnsub1, null);