Fermat primality test

From Number
Revision as of 23:23, 4 January 2012 by Vipul (talk | contribs) (Created page with "{{primality test}} ==Definition== The '''Fermat primality test''' is a quick and often inconclusive primality test. In the version below, we consider only <math>n > 2 </...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Primality test

Definition

The Fermat primality test is a quick and often inconclusive primality test. In the version below, we consider only n>2.

Given a natural number n>2, the test works as follows:

  1. Pick a random element a from the congruence classes of integers mod n (exclude the congruence classes of 0 and 1). Explicitly, pick a as an integer among 2,3,,n1.
  2. Check whether an11(modn). To compute the power use repeated squaring. If the condition does not hold, then n is composite. If the condition does hold, then n may be prime or composite.

The above is a single iteration of the test. Multiple iterations of the test may be carried out with multiple random elements. If at any stage the condition an11(modn) is violated, we can conclude that the number is composite. If, however, the condition holds every time, the situation is inconclusive and n may be prime or composite.

Theory

Why it works

The primality test above is correct because of Fermat's little theorem, which says that for a prime p and a relatively prime to p, we have:

ap11(modp)

Behavior on composite numbers

For any composite number n, we use the following terms:

Nonzero numbers that have a common factor with n always serve as Fermat witnesses. There are nφ(n)1 of these where φ is the Euler totient function. For n composite, this number is at least equal to n1, the worst case arising when n is a square of a prime. In general, if n has a small number of large prime factors, there are very few such numbers and a uniform random choice is highly unlikely to hit them.

For the numbers that are relatively prime to n, we have the formula for probability of relatively prime integer being a Fermat liar. If the probability is 1, then n is a Carmichael number. If the probability is less than 1, then it is at most 1/2, which means that the Fermat primality test can find a witness with arbitrarily high probability of success in a finite number of trials.


Related tests