Skip to content

PrimitiveRootList ​

Every primitive root of nn — every generator of (Z/n)×(\mathbb{Z}/n)^\times — ascending.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguagePrimitiveRootList!
PrimitiveRootList(n)the generators of the unit group mod nn, or {}\{\} when it is not cyclic
SageMathenumeratio_primitive_root_list(n)
Typed signatures
TypePackageApplies
(integer) -> list<integer>compute-enginealways
(integer) -> list<integer>residuesreplaces compute-enginealways

Domain: Modular arithmetic

Details
  • (Z/n)×(\mathbb{Z}/n)^\times is cyclic exactly for n=1,2,4,pk,2pkn = 1, 2, 4, p^k, 2p^k with pp an odd prime; otherwise there are no primitive roots and the list is empty.
  • When there is one generator gg there are φ(φ(n))\varphi(\varphi(n)): the powers gkg^k with gcd⁡(k,φ(n))=1\gcd(k, \varphi(n)) = 1.
  • A candidate gg is a generator iff gφ(n)/q≢1g^{\varphi(n)/q} \not\equiv 1 for every prime q∣φ(n)q \mid \varphi(n), so φ(n)\varphi(n) has to be factored.
  • At most 100 000 roots are listed; past that the call stays unevaluated. PrimitiveRoot gives the least one at any size.

Examples

2 more kept as data, checked against the oracles
Basic #
live ↗
InPrimitiveRootList(7)\mathrm{PrimitiveRootList}(7)Out[3,5]\bigl\lbrack3, 5\bigr\rbrack

All generators of (Z/9)×(\mathbb Z/9)^\times, which is cyclic of order 6

live ↗
InPrimitiveRootList(9)\mathrm{PrimitiveRootList}(9)Out[2,5]\bigl\lbrack2, 5\bigr\rbrack
Scope #

10=2⋅510 = 2 \cdot 5 is of the form 2p2p

live ↗
InPrimitiveRootList(10)\mathrm{PrimitiveRootList}(10)Out[3,7]\bigl\lbrack3, 7\bigr\rbrack

an odd prime power: φ(φ(25))=8\varphi(\varphi(25)) = 8 generators

live ↗
InPrimitiveRootList(25)\mathrm{PrimitiveRootList}(25)Out[2,3,8,12,13,17,22,23]\bigl\lbrack2, 3, 8, 12, 13, 17, 22, 23\bigr\rbrack

n=4n = 4 is one of the small cyclic cases

live ↗
InPrimitiveRootList(4)\mathrm{PrimitiveRootList}(4)Out[3]\bigl\lbrack3\bigr\rbrack

threads over a list

live ↗
InPrimitiveRootList([9,11])\mathrm{PrimitiveRootList}(\bigl\lbrack9, 11\bigr\rbrack)Out[[2,5],[2,6,7,8]]\bigl\lbrack\bigl\lbrack2, 5\bigr\rbrack, \bigl\lbrack2, 6, 7, 8\bigr\rbrack\bigr\rbrack

18=2⋅3218 = 2 \cdot 3^2 is of the form 2pk2p^k

live ↗
InPrimitiveRootList(18)\mathrm{PrimitiveRootList}(18)Out[5,11]\bigl\lbrack5, 11\bigr\rbrack
live ↗
InLength(PrimitiveRootList(1 009))\mathrm{Length}(\mathrm{PrimitiveRootList}(1\,009))Out288288
Properties #

there are φ(φ(n))\varphi(\varphi(n)) of them

live ↗
InLength(PrimitiveRootList(1 009))=Totient(Totient(1 009))\mathrm{Length}(\mathrm{PrimitiveRootList}(1\,009))=\mathrm{Totient}(\mathrm{Totient}(1\,009))OutTrue\mathrm{True}

the first is PrimitiveRoot

live ↗
InFirst(PrimitiveRootList(1 009))=PrimitiveRoot(1 009)\mathrm{First}(\mathrm{PrimitiveRootList}(1\,009))=\mathrm{PrimitiveRoot}(1\,009)OutTrue\mathrm{True}
Possible issues #

(Z/12)×≅C2×C2(\mathbb{Z}/12)^\times \cong C_2 \times C_2 is not cyclic either

live ↗
InPrimitiveRootList(12)\mathrm{PrimitiveRootList}(12)Out[]\bigl\lbrack\bigr\rbrack

(Z/8)×≅C2×C2(\mathbb{Z}/8)^\times \cong C_2 \times C_2 is not cyclic

live ↗
InPrimitiveRootList(8)\mathrm{PrimitiveRootList}(8)Out[]\bigl\lbrack\bigr\rbrack

past 100 000 roots the list is not built, but its length is still φ(φ(n))\varphi(\varphi(n))

live ↗
InLength(PrimitiveRootList(1 000 003))\mathrm{Length}(\mathrm{PrimitiveRootList}(1\,000\,003))Out333 332333\,332

The unit group of Z/1\mathbb Z/1 is trivial, generated by 00 (≡1\equiv 1)

live ↗
InPrimitiveRootList(1)\mathrm{PrimitiveRootList}(1)Out[0]\bigl\lbrack0\bigr\rbrack

The smallest modulus with a nonzero root: (Z/2)×={1}(\mathbb Z/2)^\times = \{1\}

live ↗
InPrimitiveRootList(2)\mathrm{PrimitiveRootList}(2)Out[1]\bigl\lbrack1\bigr\rbrack
About
Examples17
Checked againstWolfram Language 14 agree2 differSageMath 12 agree1 differ1 error
CrosswalkWolfram LanguageSageMath

Implementation

mappedwolframpackages/oracle/src/mappings.ts

Sage's primitive_root gives one root only; run.ts's SAGE_PREAMBLE walks the powers coprime to phi(n).

mappedsagepackages/oracle/src/mappings.ts

Sage's primitive_root gives one root only; run.ts's SAGE_PREAMBLE walks the powers coprime to phi(n).

See also: PrimitiveRoot, MultiplicativeOrder, PowerModList