Click or drag to resize
gmp_libmpz_lucnum2_ui Method
Sets ln to L[n], and lnsub1 to L[n - 1].

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void mpz_lucnum2_ui(
	mpz_t ln,
	mpz_t lnsub1,
	uint n
)

Parameters

ln
Type: Math.Gmp.Nativempz_t
The L[n] result.
lnsub1
Type: Math.Gmp.Nativempz_t
The L[n - 1] result.
n
Type: SystemUInt32
The operand integer.
Remarks

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.

Examples
// 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);
See Also