Lesson 9 of 15

Rings

Rings

A ring (R,+,)(R, +, \cdot) is a set RR with two binary operations satisfying:

  1. (R,+)(R, +) is an abelian group
  2. Multiplication is associative: (ab)c=a(bc)(a \cdot b) \cdot c = a \cdot (b \cdot c)
  3. Distributive laws hold:
    • a(b+c)=ab+aca \cdot (b + c) = a \cdot b + a \cdot c
    • (a+b)c=ac+bc(a + b) \cdot c = a \cdot c + b \cdot c

If multiplication is commutative, we call it a commutative ring. If there is a multiplicative identity 11, we call it a ring with unity.

Example: Zn\mathbb{Z}_n

The integers modulo nn form a commutative ring with unity under addition and multiplication mod nn.

def Zn_add(a, b, n):
    return (a + b) % n

def Zn_mul(a, b, n):
    return (a * b) % n

Zero Divisors

An element a0a \neq 0 is a zero divisor if there exists b0b \neq 0 such that ab=0a \cdot b = 0.

In Z6\mathbb{Z}_6: 23=02 \cdot 3 = 0, so both 2 and 3 are zero divisors.

In Z5\mathbb{Z}_5 (prime modulus): there are no zero divisors — this makes it an integral domain.

Units

An element aa is a unit (invertible) if there exists bb such that ab=1(modn)a \cdot b = 1 \pmod{n}. The units form a group under multiplication, denoted Zn\mathbb{Z}_n^*.

Your Task

Implement zero_divisors(n) returning the sorted list of zero divisors in Zn\mathbb{Z}_n, and units(n) returning the sorted list of units (multiplicatively invertible elements).

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