Given R=Z/mZ, construct the unit group of R as an abelian group. This returns an (additive) abelian group A of order φ(m), together with a map from A to R.
Returns true if the element n∈Z/mZ is primitive, that is, if it generates the multiplicative group of Z/mZ, false otherwise.
Given R = Z/mZ, this function returns a generator for the group of units of R if this group is cyclic, and returns 0 otherwise. Thus a valid generator is only returned if m = 2, 4, pt or 2pt, with p an odd prime and t≥1.
Given an element a belonging to Z/mZ, return the multiplicative order k ≥1 of a if a is in the unit group (Z/mZ)^*, and zero if a is not a unit.
Given an element x∈R = Z/mZ, this function returns the unique canonical associate y∈R of x and a unit u∈R such that u.x = y. The canonical associate of x is the GCD of x and m, considered as natural integers (unless x is 0, in which case it is 0).
> m := 735; > R := ResidueClassRing(m); Residue class ring of integers modulo 735 > U, psi := UnitGroup(R); > U; Abelian Group isomorphic to Z/2 + Z/2 + Z/84 Defined on 3 generators Relations: 2*U.1 = 0 4*U.2 = 0 42*U.3 = 0 > #U; 336 > EulerPhi(735); 336
So the order of U is equal to φ(m) as it should be. Finally, we look for three elements of R that generate the unit group.
> gens := [ psi(U.i) : i in [1..3] ]; gens; > [ Order(x) : x in gens ]; [ 2, 4, 42 ]
> R := IntegerRing(50); > U, psi := UnitGroup(R); Abelian Group isomorphic to Z/20 Defined on 1 generator Relations: 20*U.1 = 0 > w := PrimitiveElement(R); > w; 3 > Order(w); 20
We verify that the powers of w are precisely the elements of the unit group U.
> powers := { w^i : i in [0..19] }; > powers; { 29, 1, 31, 3, 33, 7, 37, 9, 39, 11, 41, 13, 43, 17, 47, 19, 49, 21, 23, 27 } > powers eq { psi(u) : u in U }; true