1-- Orders of elements in finite groups: every element of a finite group2-- has finite order, the cyclic subgroup it generates has exactly that3-- many elements, so by Lagrange the order divides the order of the group4-- and the group order annihilates every element5-- Part of Cumulus, the Grace17 mathematics library.6-- Copyright (c) 2026 Grant Passmore.7-- Released under the Apache License 2.0. See LICENSE in the repository root.8-- Authors: Grant Passmore910module Grace.Cumulus.Algebra.Group.ElementOrder11import Cyclic12import Cardinal.Dominance1314section Orders15variable (G : Set)16hypothesis group : Group(G)1718theorem pow_eq_one_of_pow_add_eq (g : G) (m k : Nat)19requires equal : g ^ (m + k) = g ^ m20shows g ^ k = G.one21proof22havesplit : g ^ (m + k) = g ^ m * g ^ k := pow_add with*23have products : g ^ m * g ^ k = g ^ m * G.one24rw [←split, equal, mul_one]25rfl26exact mul_left_cancel at G, g ^ m, g ^ k, G.one with*2728theorem HasFiniteOrder.of_pow_eq (g : G) (m n : Nat)29requires below : m < n30requires equal : g ^ m = g ^ n31shows HasFiniteOrder(G, g)32proof33obtain⟨j, jNat, shape⟩:= below34have form : m + succ(j) = n35rw← shape36exact add.successor_shift at m, j37have shifted : g ^ (m + succ(j)) = g ^ m bycc38have vanishes : g ^ succ(j) = G.one := pow_eq_one_of_pow_add_eq with*39have positive : 0 < succ(j) byarith40exact HasFiniteOrder.of_pow with positive, vanishes4142end Orders4344-- Powers as a function on the naturals.45defgraph powerMap (G g : Set) (n ∈ ℕ) : G.carrier := groupPow(G, g, n)46requires group : Group(G)47requires hg : g ∈ G.carrier48proof49have nNat := nat.omega.backward with member50exact Group.pow_mem with group, hg, nNat5152-- The exponents below the order enumerate the cyclic subgroup.53defgraph orderMap (G g : Set) (n ∈ elementOrder(G, g)) : powers(G, g) := groupPow(G, g, n)54requires group : Group(G)55requires hg : g ∈ G.carrier56requires finite : HasFiniteOrder(G, g)57proof58have natural := elementOrder.natural with finite59have nNat := natural.member at elementOrder(G, g) with n, member60exact powers.pow_mem with group, hg, nNat6162section FiniteOrders63variable (G : Set)64hypothesis group : Group(G)6566theorem powerMap.injective_of_infinite_order (g : G)67requires infinite : ¬HasFiniteOrder(G, g)68shows InjectiveBetween(powerMap(G, g), ℕ, G.carrier)69proof70have function := powerMap.function at G, g with*71constructor72 . exact function73 . intros m hm n hn z hz hmz hnz74have mNat := nat.omega.backward with hm75have nNat := nat.omega.backward with hn76have vm := FunctionBetween.apply_value with function, hm, hmz77have vn := FunctionBetween.apply_value with function, hn, hnz78have valueM := powerMap.value at G, g, m with*79have valueN := powerMap.value at G, g, n with*80have equal : g ^ m = g ^ n bycc81have comparison := Less.trichotomy at m, n with mNat, nNat82rcases comparison with less | same | greater83 . exfalso84have finite := HasFiniteOrder.of_pow_eq at G, g, m, n with*85exact infinite with finite86 . exact same87 . exfalso88have reversed : g ^ n = g ^ m bycc89have finite := HasFiniteOrder.of_pow_eq at G, g, n, m with*90exact infinite with finite9192-- Every element of a finite group has finite order.93theorem Group.finite_order (g : G)94requires finite : Finite(G)95shows HasFiniteOrder(G, g)96proof97by_contra98have injective := powerMap.injective_of_infinite_order with*99have dominated := Dominated.of_injective with injective100have finiteNaturals := Finite.of_dominated with finite, dominated101exact omega.infinite with finiteNaturals102103theorem elementOrder.le_of_pow_eq (g : G) (m n : Nat)104requires finite : HasFiniteOrder(G, g)105requires below : m < n106requires equal : g ^ m = g ^ n107shows elementOrder(G, g) ≤ n108proof109have natural := elementOrder.natural with finite110obtain⟨j, jNat, shape⟩:= below111have form : m + succ(j) = n112rw← shape113exact add.successor_shift at m, j114have shifted : g ^ (m + succ(j)) = g ^ m bycc115have vanishes : g ^ succ(j) = G.one := pow_eq_one_of_pow_add_eq with*116have positive : 0 < succ(j) byarith117have least := elementOrder.least with finite, positive, vanishes118have bound : succ(j) ≤ n119witness m120rw← form121ring122exact LessEqual.transitive with least, bound123124-- Below the order, distinct exponents give distinct powers.125theorem elementOrder.pow_injective_below (g : G) (m n : Nat)126requires finite : HasFiniteOrder(G, g)127requires mBelow : m < elementOrder(G, g)128requires nBelow : n < elementOrder(G, g)129requires equal : g ^ m = g ^ n130shows m = n131proof132have natural := elementOrder.natural with finite133have mNat : Nat(m) bytypecheck134have nNat : Nat(n) bytypecheck135have comparison := Less.trichotomy at m, n with mNat, nNat136rcases comparison with less | same | greater137 . exfalso138have bound := elementOrder.le_of_pow_eq at G, g, m, n with*139have strict := LessEqual.transitive_Less with bound, nBelow140exact Less.irreflexive with strict141 . exact same142 . exfalso143have reversed : g ^ n = g ^ m bycc144have bound := elementOrder.le_of_pow_eq at G, g, n, m with*145have strict := LessEqual.transitive_Less with bound, mBelow146exact Less.irreflexive with strict147148theorem orderMap.injective (g : G)149requires finite : HasFiniteOrder(G, g)150shows InjectiveBetween(orderMap(G, g), elementOrder(G, g), powers(G, g))151proof152have natural := elementOrder.natural with finite153have function := orderMap.function at G, g with*154constructor155 . exact function156 . intros m hm n hn z hz hmz hnz157have mNat := natural.member at elementOrder(G, g) with m, hm158have nNat := natural.member at elementOrder(G, g) with n, hn159have mBelow := Less.of_membership at m, elementOrder(G, g) with hm160have nBelow := Less.of_membership at n, elementOrder(G, g) with hn161have vm := FunctionBetween.apply_value with function, hm, hmz162have vn := FunctionBetween.apply_value with function, hn, hnz163have valueM := orderMap.value at G, g, m with*164have valueN := orderMap.value at G, g, n with*165have equal : g ^ m = g ^ n bycc166exact elementOrder.pow_injective_below with*167168theorem orderMap.surjective (g : G)169requires finite : HasFiniteOrder(G, g)170shows SurjectiveBetween(orderMap(G, g), elementOrder(G, g), powers(G, g))171proof172have natural := elementOrder.natural with finite173have nonzero := elementOrder.nonzero with finite174have function := orderMap.function at G, g with*175constructor176 . exact function177 . intros y hy178obtain⟨yIn, n, nIn, yEq⟩:= powers.membership.forward with hy179have nNat := nat.omega.backward with nIn180have remainderNat : Nat(n % elementOrder(G, g)) bytypecheck181have below := mod.less at n, elementOrder(G, g) with nonzero182have member := membership.of_Less with remainderNat, natural, below183have reduced : g ^ n = g ^ (n % elementOrder(G, g)) := elementOrder.pow_mod with*184have value := orderMap.value at G, g, n % elementOrder(G, g) with*185have edge := FunctionBetween.relates_apply with function, member186refine⟨n % elementOrder(G, g), member, ?_⟩187rw [value, ← reduced] at edge188rw yEq189exact edge190191theorem orderMap.bijective (g : G)192requires finite : HasFiniteOrder(G, g)193shows BijectiveBetween(orderMap(G, g), elementOrder(G, g), powers(G, g))194proof195constructor196 . exact orderMap.injective with*197 . exact orderMap.surjective with*198199theorem powers.has_cardinality (g : G)200requires finite : HasFiniteOrder(G, g)201shows HasCardinality(powers(G, g), elementOrder(G, g))202proof203have natural := elementOrder.natural with finite204have bijective := orderMap.bijective with*205have equipotent : Equipotent(elementOrder(G, g), powers(G, g))206witness orderMap(G, g)207exact bijective208have reversed := Equipotent.symmetric with equipotent209unfold HasCardinality210exact⟨natural, reversed⟩211212theorem powers.cardinality (g : G)213requires finite : HasFiniteOrder(G, g)214shows cardinality(powers(G, g)) = elementOrder(G, g)215proof216have hasCardinality := powers.has_cardinality with*217exact cardinality.eq_of_has with hasCardinality218219theorem powers.finite (g : G)220requires finite : HasFiniteOrder(G, g)221shows Finite(powers(G, g))222proof223have hasCardinality := powers.has_cardinality with*224exact Finite.from_cardinality with hasCardinality225226-- The order of an element divides the order of the group.227theorem elementOrder.dvd_card (g : G)228requires finite : Finite(G)229shows elementOrder(G, g) ∣ cardinality(G)230proof231have finiteOrder := Group.finite_order with*232have subgroup := powers.subgroup with*233have divides := lagrange.theorem with group, subgroup, finite234have same := powers.cardinality with*235rw order.value at divides236 rwa same at divides237238theorem Group.pow_card (g : G)239requires finite : Finite(G)240shows g ^ cardinality(G) = G.one241proof242have finiteOrder := Group.finite_order with*243have cardNat := cardinality.nat with finite244have divides := elementOrder.dvd_card with*245exact elementOrder.pow_eq_one_of_dvd at G, g, cardinality(G) with*246247theorem elementOrder.le_card (g : G)248requires finite : Finite(G)249shows elementOrder(G, g) ≤ cardinality(G)250proof251have finiteOrder := Group.finite_order with*252have natural := elementOrder.natural with finiteOrder253have cardNat := cardinality.nat with finite254have subgroup := powers.subgroup with*255have subset := Subgroup.subset with subgroup256have bound := cardinality.monotone with finite, subset257have same := powers.cardinality with*258 rwa same at bound259260end FiniteOrders261