# Finite fields #

This file contains basic results about finite fields. Throughout most of this file, K denotes a finite field and q is notation for the cardinality of K.

See RingTheory.IntegralDomain for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (Fintype.fieldOfDomain).

## Main results #

1. Fintype.card_units: The unit group of a finite field has cardinality q - 1.
2. sum_pow_units: The sum of x^i, where x ranges over the units of K, is
• q-1 if q-1 ∣ i
• 0 otherwise
3. FiniteField.card: The cardinality q is a power of the characteristic of K. See FiniteField.card' for a variant.

## Notation #

Throughout most of this file, K denotes a finite field and q is notation for the cardinality of K.

## Implementation notes #

While Fintype Kˣ can be inferred from Fintype K in the presence of DecidableEq K, in this file we take the Fintype Kˣ argument directly to reduce the chance of typeclass diamonds, as Fintype carries data.

theorem FiniteField.card_image_polynomial_eval {R : Type u_2} [] [] [] [] {p : } (hp : 0 < p.degree) :
p.natDegree * (Finset.image (fun (x : R) => ) Finset.univ).card

The cardinality of a field is at most n times the cardinality of the image of a degree n polynomial

theorem FiniteField.exists_root_sum_quadratic {R : Type u_2} [] [] [] {f : } {g : } (hf2 : f.degree = 2) (hg2 : g.degree = 2) (hR : = 1) :
∃ (a : R) (b : R), + = 0

If f and g are quadratic polynomials, then the f.eval a + g.eval b = 0 has a solution.

theorem FiniteField.prod_univ_units_id_eq_neg_one {K : Type u_1} [] [] [] :
x : Kˣ, x = -1
theorem FiniteField.card_cast_subgroup_card_ne_zero {K : Type u_1} [Ring K] [] [] (G : ) [Fintype G] :
() 0
theorem FiniteField.sum_subgroup_units_eq_zero {K : Type u_1} [Ring K] [] {G : } [Fintype G] (hg : G ) :
x : G, x = 0

The sum of a nontrivial subgroup of the units of a field is zero.

@[simp]
theorem FiniteField.sum_subgroup_units {K : Type u_1} [Ring K] [] {G : } [Fintype G] [Decidable (G = )] :
x : G, x = if G = then 1 else 0

The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise

@[simp]
theorem FiniteField.sum_subgroup_pow_eq_zero {K : Type u_1} [] [] {G : } [Fintype G] {k : } (k_pos : k 0) (k_lt_card_G : k < ) :
x : G, x ^ k = 0
theorem FiniteField.pow_card_sub_one_eq_one {K : Type u_1} [] [] (a : K) (ha : a 0) :
a ^ () = 1
theorem FiniteField.pow_card {K : Type u_1} [] [] (a : K) :
= a
theorem FiniteField.pow_card_pow {K : Type u_1} [] [] (n : ) (a : K) :
a ^ = a
theorem FiniteField.card (K : Type u_1) [] [] (p : ) [CharP K p] :
∃ (n : ℕ+), = p ^ n
theorem FiniteField.card' (K : Type u_1) [] [] :
∃ (p : ) (n : ℕ+), = p ^ n
theorem FiniteField.cast_card_eq_zero (K : Type u_1) [] [] :
() = 0
theorem FiniteField.forall_pow_eq_one_iff (K : Type u_1) [] [] (i : ) :
(∀ (x : Kˣ), x ^ i = 1) i
theorem FiniteField.sum_pow_units (K : Type u_1) [] [] [] (i : ) :
x : Kˣ, x ^ i = if i then -1 else 0

The sum of x ^ i as x ranges over the units of a finite field of cardinality q is equal to 0 unless (q - 1) ∣ i, in which case the sum is q - 1.

theorem FiniteField.sum_pow_lt_card_sub_one (K : Type u_1) [] [] (i : ) (h : i < ) :
x : K, x ^ i = 0

The sum of x ^ i as x ranges over a finite field of cardinality q is equal to 0 if i < q - 1.

theorem FiniteField.X_pow_card_sub_X_natDegree_eq (K' : Type u_3) [Field K'] {p : } (hp : 1 < p) :
(Polynomial.X ^ p - Polynomial.X).natDegree = p
theorem FiniteField.X_pow_card_pow_sub_X_natDegree_eq (K' : Type u_3) [Field K'] {p : } {n : } (hn : n 0) (hp : 1 < p) :
(Polynomial.X ^ p ^ n - Polynomial.X).natDegree = p ^ n
theorem FiniteField.X_pow_card_sub_X_ne_zero (K' : Type u_3) [Field K'] {p : } (hp : 1 < p) :
Polynomial.X ^ p - Polynomial.X 0
theorem FiniteField.X_pow_card_pow_sub_X_ne_zero (K' : Type u_3) [Field K'] {p : } {n : } (hn : n 0) (hp : 1 < p) :
Polynomial.X ^ p ^ n - Polynomial.X 0
theorem FiniteField.roots_X_pow_card_sub_X (K : Type u_1) [] [] :
(Polynomial.X ^ - Polynomial.X).roots = Finset.univ.val
theorem FiniteField.frobenius_pow {K : Type u_1} [] [] {p : } [Fact ()] [CharP K p] {n : } (hcard : = p ^ n) :
^ n = 1
theorem FiniteField.expand_card {K : Type u_1} [] [] (f : ) :
() f =
theorem ZMod.sq_add_sq (p : ) [hp : Fact ()] (x : ZMod p) :
∃ (a : ZMod p) (b : ZMod p), a ^ 2 + b ^ 2 = x
theorem Nat.sq_add_sq_zmodEq (p : ) [Fact ()] (x : ) :
∃ (a : ) (b : ), a p / 2 b p / 2 a ^ 2 + b ^ 2 x [ZMOD p]

If p is a prime natural number and x is an integer number, then there exist natural numbers a ≤ p / 2 and b ≤ p / 2 such that a ^ 2 + b ^ 2 ≡ x [ZMOD p]. This is a version of ZMod.sq_add_sq with estimates on a and b.

theorem Nat.sq_add_sq_modEq (p : ) [Fact ()] (x : ) :
∃ (a : ) (b : ), a p / 2 b p / 2 a ^ 2 + b ^ 2 x [MOD p]

If p is a prime natural number and x is a natural number, then there exist natural numbers a ≤ p / 2 and b ≤ p / 2 such that a ^ 2 + b ^ 2 ≡ x [MOD p]. This is a version of ZMod.sq_add_sq with estimates on a and b.

theorem CharP.sq_add_sq (R : Type u_3) [] [] (p : ) [] [CharP R p] (x : ) :
∃ (a : ) (b : ), a ^ 2 + b ^ 2 = x
@[simp]
theorem ZMod.pow_totient {n : } (x : (ZMod n)ˣ) :
x ^ n.totient = 1

The Fermat-Euler totient theorem. Nat.ModEq.pow_totient is an alternative statement of the same theorem.

theorem Nat.ModEq.pow_totient {x : } {n : } (h : x.Coprime n) :
x ^ n.totient 1 [MOD n]

The Fermat-Euler totient theorem. ZMod.pow_totient is an alternative statement of the same theorem.

instance instFiniteZModUnits (n : ) :

For each n ≥ 0, the unit group of ZMod n is finite.

Equations
• =
theorem card_eq_pow_finrank {K : Type u_1} {V : Type u_3} [] [] [] [Module K V] [] :
@[simp]
theorem ZMod.pow_card {p : } [Fact ()] (x : ZMod p) :
x ^ p = x

A variation on Fermat's little theorem. See ZMod.pow_card_sub_one_eq_one

@[simp]
theorem ZMod.pow_card_pow {n : } {p : } [Fact ()] (x : ZMod p) :
x ^ p ^ n = x
@[simp]
theorem ZMod.frobenius_zmod (p : ) [Fact ()] :
theorem ZMod.card_units (p : ) [Fact ()] :
= p - 1
theorem ZMod.units_pow_card_sub_one_eq_one (p : ) [Fact ()] (a : (ZMod p)ˣ) :
a ^ (p - 1) = 1

Fermat's Little Theorem: for every unit a of ZMod p, we have a ^ (p - 1) = 1.

theorem ZMod.pow_card_sub_one_eq_one {p : } [Fact ()] {a : ZMod p} (ha : a 0) :
a ^ (p - 1) = 1

Fermat's Little Theorem: for all nonzero a : ZMod p, we have a ^ (p - 1) = 1.

theorem ZMod.pow_card_sub_one {p : } [Fact ()] (a : ZMod p) :
a ^ (p - 1) = if a 0 then 1 else 0
theorem ZMod.orderOf_units_dvd_card_sub_one {p : } [Fact ()] (u : (ZMod p)ˣ) :
p - 1
theorem ZMod.orderOf_dvd_card_sub_one {p : } [Fact ()] {a : ZMod p} (ha : a 0) :
p - 1
theorem ZMod.expand_card {p : } [Fact ()] (f : Polynomial (ZMod p)) :
() f = f ^ p
theorem Int.ModEq.pow_card_sub_one_eq_one {p : } (hp : ) {n : } (hpn : IsCoprime n p) :
n ^ (p - 1) 1 [ZMOD p]

Fermat's Little Theorem: for all a : ℤ coprime to p, we have a ^ (p - 1) ≡ 1 [ZMOD p].

theorem FiniteField.isSquare_of_char_two {F : Type u_3} [] [] (hF : = 2) (a : F) :

In a finite field of characteristic 2, all elements are squares.

theorem FiniteField.exists_nonsquare {F : Type u_3} [] [] (hF : 2) :
∃ (a : F),

In a finite field of odd characteristic, not every element is a square.

theorem FiniteField.even_card_iff_char_two {F : Type u_3} [] [] :
= 2 = 0

The finite field F has even cardinality iff it has characteristic 2.

theorem FiniteField.even_card_of_char_two {F : Type u_3} [] [] (hF : = 2) :
= 0
theorem FiniteField.odd_card_of_char_ne_two {F : Type u_3} [] [] (hF : 2) :
= 1
theorem FiniteField.pow_dichotomy {F : Type u_3} [] [] (hF : 2) {a : F} (ha : a 0) :
a ^ () = 1 a ^ () = -1

If F has odd characteristic, then for nonzero a : F, we have that a ^ (#F / 2) = ±1.

theorem FiniteField.unit_isSquare_iff {F : Type u_3} [] [] (hF : 2) (a : Fˣ) :
a ^ () = 1

A unit a of a finite field F of odd characteristic is a square if and only if a ^ (#F / 2) = 1.

theorem FiniteField.isSquare_iff {F : Type u_3} [] [] (hF : 2) {a : F} (ha : a 0) :
a ^ () = 1

A non-zero a : F is a square if and only if a ^ (#F / 2) = 1.