Teoría de NúmerosFermat, Euler and Wilson

Wilson's Theorem

An integer p > 1 is prime exactly when (p − 1)! ≡ −1 (mod p): the factors from 2 to p − 2 pair up with their inverses, leaving 1 · (p − 1) ≡ −1.

Sin empezar Ir a la práctica

Esta lección aún no está traducida. Por ahora se muestra en inglés; la versión en español está en camino.

Multiply all the nonzero residues mod a prime. Mod 5: $1 \cdot 2 \cdot 3 \cdot 4 = 24 \equiv -1$. Mod 7: $6! = 720 \equiv -1$. It is always $-1$, and the reason is a pretty pairing argument with modular inverses.

Wilson's theorem. An integer $p > 1$ is prime exactly when $$(p - 1)! \equiv -1 \pmod{p}.$$

Por qué funciona

Primes. Mod a prime $p$, every $x$ from $1$ to $p - 1$ has an inverse. Which are their own inverses? $x^{2} \equiv 1$ means $p \mid (x - 1)(x + 1)$, so by Euclid's lemma $x \equiv 1$ or $x \equiv -1$. Every other number from $2$ to $p - 2$ pairs off with a different partner, and each pair multiplies to $1$. So $(p - 1)! \equiv 1 \cdot (p - 1) \equiv -1$.
Composites. If $n = ab$ with $1 < a < b < n$, both $a$ and $b$ appear in $(n - 1)!$, so $n \mid (n - 1)!$. If $n = a^{2}$ with $a > 2$, then $a$ and $2a$ both appear, so again $n \mid (n - 1)!$. Either way $(n - 1)! \equiv 0$, not $-1$. The lone exception $n = 4$ gives $3! = 6 \equiv 2$, still not $-1$.
Mod 13, each chord joins a residue to its inverse: 2 and 7, 3 and 9, 4 and 10, 5 and 8, 6 and 11. Only 1 and 12 are left alone, so $12! \equiv 1 \cdot 12 \equiv -1$. Try $n = 12$: most points have no partner at all.

Ejemplo resuelto: Checking the theorem

Find $12! \bmod 13$ without computing $12!$.
  1. Pair each number with its inverse mod 13: $2 \cdot 7 = 14$, $3 \cdot 9 = 27$, $4 \cdot 10 = 40$, $5 \cdot 8 = 40$, $6 \cdot 11 = 66$ are all $\equiv 1$.
  2. $12! \equiv 1 \cdot 12 \cdot 1^{5} = 12 \equiv -1 \pmod{13}$.

Respuesta: $12$, that is, $-1$.

Ejemplo resuelto: One factor short

Find $15! \bmod 17$.
  1. Wilson: $16! \equiv -1 \pmod{17}$. And $16! = 15! \cdot 16$ with $16 \equiv -1$.
  2. So $15! \cdot (-1) \equiv -1$, which gives $15! \equiv 1 \pmod{17}$.

Respuesta: $1$.

Ejemplo resuelto: Two factors short

Find $20! \bmod 23$.
  1. $22! = 20! \cdot 21 \cdot 22 \equiv 20! \cdot (-2)(-1) = 2 \cdot 20! \pmod{23}$, and $22! \equiv -1$.
  2. So $2 \cdot 20! \equiv -1$. The inverse of 2 mod 23 is 12, so $20! \equiv -12 \equiv 11 \pmod{23}$.

Respuesta: $11$.

For primes the value is $n - 1 \equiv -1$; for composites it is $0$, except $2$ at $n = 4$.
$n$234567891011
$(n-1)! \bmod n$12240600010

Error común

Expecting $(n - 1)! \equiv -1 \pmod{n}$ for every $n$. For $n = 6$: $5! = 120 = 6 \cdot 20 \equiv 0$. The theorem is about primes, and for composites the value is $0$ (or $2$ when $n = 4$). That difference is exactly why Wilson's theorem characterizes primes.
As a primality test Wilson's theorem is perfect and useless: it never errs, but computing $(n - 1)! \bmod n$ takes about $n$ multiplications, far slower than trial division. Its value is the pairing idea, which comes back in quadratic residues.

Idea clave

$p$ is prime exactly when $(p - 1)! \equiv -1 \pmod{p}$: the residues $2, \dots, p - 2$ pair up with their inverses, leaving $1 \cdot (p - 1)$.

Práctica

Apruebas con 3 respuestas correctas, las 2 últimas seguidas. Cada respuesta correcta da 2 XP.

Cargando la práctica…

Se apoya en

Lleva a

Este es uno de los peldaños más altos de Teoría de Números.

Fuentes y lecturas

  • William Stein, Elementary Number Theory: Primes, Congruences, and Secrets (Springer, 2009; free online edition), chapter 2, The Ring of Integers Modulo n (Wilson's theorem)
  • MIT OpenCourseWare 18.781 Theory of Numbers (Spring 2012), lecture notes on Wilson's theorem