gmp_libmpz_lucnum2_ui Method |
Namespace: Math.Gmp.Native
Assembly: Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)

public static void mpz_lucnum2_ui( mpz_t ln, mpz_t lnsub1, uint n )
Public Shared Sub mpz_lucnum2_ui ( ln As mpz_t, lnsub1 As mpz_t, n As UInteger )
public: static void mpz_lucnum2_ui( mpz_t^ ln, mpz_t^ lnsub1, unsigned int n )
static member mpz_lucnum2_ui : ln : mpz_t * lnsub1 : mpz_t * n : uint32 -> unit
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.

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);
' Create, initialize, and set the values of lnsub1 and ln to 0. Dim ln As New mpz_t() Dim lnsub1 As New mpz_t() gmp_lib.mpz_inits(ln, lnsub1, Nothing) ' Set lnsub1 and ln to the 8'th and 9'th Lucas nunbers respectively. gmp_lib.mpz_lucnum2_ui(ln, lnsub1, 9UI) ' 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, Nothing)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
