Skip to content

MultiplicativeOrder ​

The smallest positive k such that a^k ≡ 1 (mod n).

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaMultiplicative orderMathWorldMultiplicativeOrderWikidataQ282723Wolfram LanguageMultiplicativeOrder!
MultiplicativeOrder(a, n)smallest positive kk with ak≡1(modn)a^k\equiv1\pmod n.
SageMathMod(a, n).multiplicative_order()SymPyn_order(a, n)
MultiplicativeOrder(a, n, {r1, r2, …})smallest positive kk with ak≡ri(modn)a^k \equiv r_i \pmod n for some ii — a discrete logarithm
MultiplicativeOrder(ResidueClass(a, n))the order of a unit of Z/n\mathbb{Z}/n
SageMathMod(a, n).multiplicative_order()SymPyn_order(a, n)
Typed signatures
TypePackageApplies
(integer, integer, list<integer>?) -> integercompute-enginealways
(value, integer?, list<integer>?) -> integerresiduesreplaces compute-enginealways

Domain: Modular arithmetic

Details
  • Also called the modulo order; defined only when gcd⁡(a,n)=1\gcd(a,n)=1, since otherwise no power of aa can reach 1 mod nn.
  • Always divides φ(n)\varphi(n), by Lagrange's theorem applied to the group of units mod nn. See Totient.
  • Unevaluated when no order exists.
  • Computed from Carmichael's λ(n)\lambda(n) by stripping primes off it, so nn and each p−1p - 1 must be factored.
  • The three-argument form is a discrete logarithm, by Pohlig–Hellman over the order of aa and baby-step giant-step within each prime: the cost is q\sqrt q for the largest prime qq dividing that order — instant for a smooth order, hopeless for a safe prime.

Plot

argument a of type value has no control

Examples

3 more kept as data, checked against the oracles
Basic #
live ↗
InMultiplicativeOrder(5,8)\mathrm{MultiplicativeOrder}(5, 8)Out22
live ↗
InMultiplicativeOrder(3,7)\mathrm{MultiplicativeOrder}(3, 7)Out66
live ↗
InMultiplicativeOrder(5,7)\mathrm{MultiplicativeOrder}(5, 7)Out66

23=8≡1(mod7)2^3=8\equiv1\pmod7, and no smaller power works

live ↗
InMultiplicativeOrder(2,7)\mathrm{MultiplicativeOrder}(2, 7)Out33
Scope #

a negative base: −5≡2(mod7)-5 \equiv 2 \pmod 7

live ↗
InMultiplicativeOrder(−5,7)\mathrm{MultiplicativeOrder}(-5, 7)Out33

the first power of 5 to reach 3 or 11≡411 \equiv 4: 52=25≡45^2 = 25 \equiv 4

live ↗
InMultiplicativeOrder(5,7,[3,11])\mathrm{MultiplicativeOrder}(5, 7, \bigl\lbrack3, 11\bigr\rbrack)Out22

a 10 001-digit base modulo the prime 7919

live ↗
InMultiplicativeOrder(1010 000,7 919)\mathrm{MultiplicativeOrder}(10^{10\,000}, 7\,919)Out3 9593\,959

the first power of 3 to reach ±1\pm 1: 33=27≡−13^3 = 27 \equiv -1

live ↗
InMultiplicativeOrder(3,7,[−1,1])\mathrm{MultiplicativeOrder}(3, 7, \bigl\lbrack-1, 1\bigr\rbrack)Out33

52=25≡45^2 = 25 \equiv 4

live ↗
InMultiplicativeOrder(5,7,[2,3,4])\mathrm{MultiplicativeOrder}(5, 7, \bigl\lbrack2, 3, 4\bigr\rbrack)Out22

a discrete log mod the Mersenne prime 261−12^{61} - 1, whose p−1p - 1 is smooth

live ↗
InMultiplicativeOrder(3,261−1,[2])\mathrm{MultiplicativeOrder}(3, 2^{61}-1, \bigl\lbrack2\bigr\rbrack)Out159 602 976 958 324 900159\,602\,976\,958\,324\,900

3 has order (p−1)/3(p-1)/3 modulo 2127−12^{127} - 1

live ↗
InMultiplicativeOrder(3,2127−1)\mathrm{MultiplicativeOrder}(3, 2^{127}-1)Out56 713 727 820 156 410 577 229 101 238 628 035 24256\,713\,727\,820\,156\,410\,577\,229\,101\,238\,628\,035\,242
Properties #

1 is the only element of order 1

live ↗
InMultiplicativeOrder(1,7)\mathrm{MultiplicativeOrder}(1, 7)Out11

The multiplicative order always divides φ(n)\varphi(n). See Totient

live ↗
InTotient(7) mod MultiplicativeOrder(3,7)=0\mathrm{Totient}(7)\bmod\mathrm{MultiplicativeOrder}(3, 7)=0OutTrue\mathrm{True}

the discrete log inverts PowerMod

live ↗
InPowerMod(3,MultiplicativeOrder(3,261−1,[2]),261−1)\mathrm{PowerMod}(3, \mathrm{MultiplicativeOrder}(3, 2^{61}-1, \bigl\lbrack2\bigr\rbrack), 2^{61}-1)Out22

The order always divides φ(n)\varphi(n)

live ↗
InMultiplicativeOrder(5,12)∣Totient(12)\mathrm{MultiplicativeOrder}(5, 12)\mid\mathrm{Totient}(12)OutTrue\mathrm{True}

5≡25\equiv2 and 22≡1(mod3)2^2\equiv1 \pmod3

live ↗
InMultiplicativeOrder(5,3)\mathrm{MultiplicativeOrder}(5, 3)Out22

−5≡1(mod3)-5\equiv1 \pmod3 has order 11

live ↗
InMultiplicativeOrder(−5,3)\mathrm{MultiplicativeOrder}(-5, 3)Out11

With target residue 44: least kk with 5k≡4(mod7)5^k\equiv4 \pmod 7

live ↗
InMultiplicativeOrder(5,7,[4])\mathrm{MultiplicativeOrder}(5, 7, \bigl\lbrack4\bigr\rbrack)Out22
live ↗
InMultiplicativeOrder(PrimitiveRoot(109),109)=Totient(109)\mathrm{MultiplicativeOrder}(\mathrm{PrimitiveRoot}(109), 109)=\mathrm{Totient}(109)OutTrue\mathrm{True}
Possible issues #

No order exists when gcd⁡(a,n)≠1\gcd(a,n)\neq1; here gcd⁡(10,22)=2\gcd(10,22)=2, so compute-engine leaves it unevaluated

live ↗
InMultiplicativeOrder(10,22)\mathrm{MultiplicativeOrder}(10, 22)OutMultiplicativeOrder(10,22)\mathrm{MultiplicativeOrder}(10, 22)

3 is not a power of 2 mod 7 — the powers are {1,2,4}\{1, 2, 4\}

live ↗
InMultiplicativeOrder(2,7,[3])\mathrm{MultiplicativeOrder}(2, 7, \bigl\lbrack3\bigr\rbrack)OutMultiplicativeOrder(2,7,[3])\mathrm{MultiplicativeOrder}(2, 7, \bigl\lbrack3\bigr\rbrack)

106≡1(mod21)10^6\equiv1 \pmod{21}

live ↗
InMultiplicativeOrder(10,21)\mathrm{MultiplicativeOrder}(10, 21)Out66

21≡1(mod10)21\equiv1 \pmod{10}, so order 11; argument order matters

live ↗
InMultiplicativeOrder(21,10)\mathrm{MultiplicativeOrder}(21, 10)Out11
About
Examples26
Checked againstWolfram Language 22 agree2 differ2 errorSageMath 16 agree1 errorSymPy 13 agree4 error
CrosswalkWikipediaMathWorldWikidataWolfram LanguageSageMathSymPy

Implementation

mappedsagepackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts

n_order raises where gcd(a, n) is not 1, as ours stays unevaluated. The three-argument discrete logarithm over a list of targets has no one-call SymPy form (discrete_log takes one target).

See also: PowerMod