| www.delorie.com/gnu/docs/gmp/gmp_36.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function does some trial divisions, then some Miller-Rabin probabilistic primality tests. reps controls how many such tests are done, 5 to 10 is a reasonable number, more will reduce the chances of a composite being returned as "probably prime".
Miller-Rabin and similar tests can be more properly called compositeness tests. Numbers which fail are known to be composite but those which pass might be prime or might be composite. Only a few composites pass, hence those which pass are considered probably prime.
This function uses a probabilistic algorithm to identify primes. For practical purposes it's adequate, the chance of a composite passing will be extremely small.
NULL, store the result there.
If the result is small enough to fit in an unsigned long int, it is
returned. If the result does not fit, 0 is returned, and the result is equal
to the argument op1. Note that the result will always fit if op2
is non-zero.
If t is NULL then that value is not computed.
When b is odd the Jacobi symbol and Kronecker symbol are
identical, so mpz_kronecker_ui etc can be used for mixed
precision Jacobi symbols too.
For more information see Henri Cohen section 1.4.2 (see section B. References),
or any number theory textbook. See also the example program
`demos/qcn.c' which uses mpz_kronecker_ui.
mpz_bin_ui, using the identity
\N\\atop{k}\right) = (-1)^k \left({n+k-1}\atop{k}\right),
bin(-n,k) = (-1)^k * bin(n+k-1,k)}, see Knuth volume 1 section 1.2.6
part G.
mpz_fib_ui sets fn to to F[n], the n'th Fibonacci
number. mpz_fib2_ui sets fn to F[n], and fnsub1 to
\N\,F[n-1]}.
These functions are designed for calculating isolated Fibonacci numbers. When
a sequence of values is wanted it's best to start with mpz_fib2_ui and
iterate the defining \N\ = F_n + F_{n-1}, F[n+1]=F[n]+F[n-1]} or
similar.
mpz_lucnum_ui sets ln to to L[n], the n'th Lucas
number. mpz_lucnum2_ui sets ln to L[n], and lnsub1
to \N\,L[n-1]}.
These functions are 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 \N\ = L_n + L_{n-1}, 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 16.7.4 Lucas Numbers, the reverse is straightforward too.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |