Lesson 7 of 15

Cosets & Lagrange's Theorem

Cosets & Lagrange's Theorem

Cosets

Let HH be a subgroup of GG. For any element aGa \in G, the left coset of HH with respect to aa is:

aH={ah:hH}aH = \{a * h : h \in H\}

In Zn\mathbb{Z}_n, where the operation is addition: a+H={(a+h)modn:hH}a + H = \{(a + h) \bmod n : h \in H\}.

Example

In Z6\mathbb{Z}_6, let H={0,3}H = \{0, 3\}. The cosets are:

  • 0+H={0,3}0 + H = \{0, 3\}
  • 1+H={1,4}1 + H = \{1, 4\}
  • 2+H={2,5}2 + H = \{2, 5\}

Notice that every element of Z6\mathbb{Z}_6 belongs to exactly one coset, and all cosets have the same size.

Lagrange's Theorem

If HH is a subgroup of a finite group GG, then H|H| divides G|G|. Moreover:

G=H[G:H]|G| = |H| \cdot [G : H]

where [G:H][G : H] is the index of HH in GG (the number of distinct cosets).

Consequences

  • The order of any element divides G|G|
  • A group of prime order pp is cyclic (its only subgroups are {e}\{e\} and GG itself)
  • aG=ea^{|G|} = e for all aGa \in G (gives Fermat's little theorem as a special case)

Your Task

Implement left_cosets(subgroup, n) that returns the list of all distinct left cosets of the given subgroup in Zn\mathbb{Z}_n (each coset as a sorted list), sorted by smallest element. Also implement verify_lagrange(n) that checks Lagrange's theorem for all subgroups of Zn\mathbb{Z}_n.

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