Lesson 13 of 15
Fields
Fields
A field is a commutative ring with unity where every nonzero element has a multiplicative inverse. Equivalently:
- is an abelian group with identity
- is an abelian group with identity
- Multiplication distributes over addition
is a Field
When is prime, is a field. Every nonzero element has a multiplicative inverse, computable by:
This follows from Fermat's little theorem: .
def mod_inverse(a, p):
# Using Fermat's little theorem
return pow(a, p - 2, p)
Why Composites Don't Work
is not a field because — zero divisors exist. An element has a multiplicative inverse if and only if it is coprime to .
Field Multiplication Table
For :
| 1 | 2 | 3 | 4 | |
|---|---|---|---|---|
| 1 | 1 | 2 | 3 | 4 |
| 2 | 2 | 4 | 1 | 3 |
| 3 | 3 | 1 | 4 | 2 |
| 4 | 4 | 3 | 2 | 1 |
Every row is a permutation of — this is a hallmark of a field.
Your Task
Implement is_field(n) that checks if is a field, mod_inverse(a, p) computing in , and mul_table(p) returning the multiplication table for the nonzero elements of .
Pyodide loading...
Loading...
Click "Run" to execute your code.