Lesson 4 of 15

Cyclic Groups

Cyclic Groups

A group GG is cyclic if there exists an element gGg \in G such that every element of GG can be written as a power of gg:

G=g={g0,g1,g2,}G = \langle g \rangle = \{g^0, g^1, g^2, \ldots\}

The element gg is called a generator of GG.

Order of an Element

The order of an element aa in a group GG, written ord(a)\text{ord}(a), is the smallest positive integer kk such that ak=ea^k = e (identity).

In Zn\mathbb{Z}_n under addition, the order of aa is:

ord(a)=ngcd(a,n)\text{ord}(a) = \frac{n}{\gcd(a, n)}

Generators of Zn\mathbb{Z}_n

An element aa is a generator of Zn\mathbb{Z}_n if and only if gcd(a,n)=1\gcd(a, n) = 1. The number of generators equals φ(n)\varphi(n) (Euler's totient function).

from math import gcd

def order_in_Zn(a, n):
    return n // gcd(a, n)

def generators_of_Zn(n):
    return [a for a in range(n) if gcd(a, n) == 1]

Fundamental Theorem of Cyclic Groups

Every subgroup of a cyclic group is cyclic. Furthermore, for each divisor dd of nn, there is exactly one subgroup of Zn\mathbb{Z}_n of order dd.

Example: Z8\mathbb{Z}_8

  • Generators: {1,3,5,7}\{1, 3, 5, 7\} (elements coprime to 8)
  • Orders: ord(1)=8\text{ord}(1) = 8, ord(2)=4\text{ord}(2) = 4, ord(4)=2\text{ord}(4) = 2, ord(0)=1\text{ord}(0) = 1

Your Task

Implement element_order(a, n) for the order of aa in Zn\mathbb{Z}_n, is_cyclic_generator(a, n) to check if aa generates Zn\mathbb{Z}_n, and all_generators(n) returning the sorted list of all generators.

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