Lesson 13 of 15

Fields

Fields

A field (F,+,)(F, +, \cdot) is a commutative ring with unity where every nonzero element has a multiplicative inverse. Equivalently:

  1. (F,+)(F, +) is an abelian group with identity 00
  2. (F{0},)(F \setminus \{0\}, \cdot) is an abelian group with identity 11
  3. Multiplication distributes over addition

Zp\mathbb{Z}_p is a Field

When pp is prime, Zp\mathbb{Z}_p is a field. Every nonzero element aa has a multiplicative inverse, computable by:

a1ap2(modp)a^{-1} \equiv a^{p-2} \pmod{p}

This follows from Fermat's little theorem: ap11(modp)a^{p-1} \equiv 1 \pmod{p}.

def mod_inverse(a, p):
    # Using Fermat's little theorem
    return pow(a, p - 2, p)

Why Composites Don't Work

Z6\mathbb{Z}_6 is not a field because 23=02 \cdot 3 = 0 — zero divisors exist. An element has a multiplicative inverse if and only if it is coprime to nn.

Field Multiplication Table

For Z5\mathbb{Z}_5:

\cdot1234
11234
22413
33142
44321

Every row is a permutation of {1,2,3,4}\{1,2,3,4\} — this is a hallmark of a field.

Your Task

Implement is_field(n) that checks if Zn\mathbb{Z}_n is a field, mod_inverse(a, p) computing a1a^{-1} in Zp\mathbb{Z}_p, and mul_table(p) returning the multiplication table for the nonzero elements of Zp\mathbb{Z}_p.

Pyodide loading...
Loading...
Click "Run" to execute your code.