Skip to content

Totient ​

Euler's totient function: the count of integers in 1..n coprime to n.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaEuler's totient functionMathWorldTotientFunctionWikidataQ190026Encyclopedia of MathematicsEuler_functionBritannicatopic/Euler-phi-functionDLMF27.2.E7FungrimTotient✓Fungrim entryOEISA000010Wolfram LanguageEulerPhi!
Totient(n)count of integers in [1,n][1,n] coprime to nn, Euler's φ(n)\varphi(n).
SageMatheuler_phi(n)!SymPytotient(n)Oscareuler_phi(ZZ(n))Juliaeuler_phi(ZZ(n))
Typed signatures
TypePackageApplies
(integer) -> integercompute-enginealways
(number) -> integernumber-theoryreplaces compute-enginealways

Domain: Number theory

Details
  • Also called Euler's phi function; central to RSA key generation and elementary number theory.
  • Multiplicative: φ(mn)=φ(m)φ(n)\varphi(mn)=\varphi(m)\varphi(n) whenever gcd⁡(m,n)=1\gcd(m,n)=1.
  • For n=p1k1⋯pmkmn=p_1^{k_1}\cdots p_m^{k_m}, φ(n)=n∏i(1−1pi)\varphi(n)=n\prod_i\left(1-\frac1{p_i}\right).
  • Divisor sum identity: ∑d∣nφ(d)=n\sum_{d\mid n}\varphi(d)=n.
  • φ(0)=0\varphi(0) = 0, as in Wolfram; a list argument is threaded over element-wise.

Plot

Examples

Basic #
live ↗
InTotient(12)\mathrm{Totient}(12)Out44
live ↗
InTotient(36)\mathrm{Totient}(36)Out1212
live ↗
InTotient(1)\mathrm{Totient}(1)Out11
live ↗
InTotient(10)\mathrm{Totient}(10)Out44
Scope #

φ(0)=0\varphi(0) = 0, as in Wolfram

live ↗
InTotient(0)\mathrm{Totient}(0)Out00

Threads element-wise over a list, as Wolfram's Listable heads do

live ↗
InTotient([2,4,6])\mathrm{Totient}(\bigl\lbrack2, 4, 6\bigr\rbrack)Out[1,2,2]\bigl\lbrack1, 2, 2\bigr\rbrack

Large integers: φ(50!)\varphi(50!)

live ↗
InTotient(50!)\mathrm{Totient}(50!)Out4 218 559 200 885 839 042 679 312 107 816 703 841 788 854 953 574 400 000 000 000 0004\,218\,559\,200\,885\,839\,042\,679\,312\,107\,816\,703\,841\,788\,854\,953\,574\,400\,000\,000\,000\,000

Negative nn: φ(−n)=φ(n)\varphi(-n)=\varphi(n)

live ↗
InTotient(−10)\mathrm{Totient}(-10)Out44
Applications #

RSA key setup: φ(17×23)=16×22=352\varphi(17\times23)=16\times22=352

live ↗
InTotient(391)\mathrm{Totient}(391)Out352352

Euler's theorem: aφ(n)≡1(modn)a^{\varphi(n)}\equiv1\pmod n when gcd⁡(a,n)=1\gcd(a,n)=1. See PowerMod

live ↗
InPowerMod(7,Totient(10),10)\mathrm{PowerMod}(7, \mathrm{Totient}(10), 10)Out11
Properties #

∑d∣nφ(d)=n\sum_{d\mid n}\varphi(d)=n, checked over the divisors of 12

live ↗
InTotient(1)+Totient(2)+Totient(3)+Totient(4)+Totient(6)+Totient(12)\mathrm{Totient}(1)+\mathrm{Totient}(2)+\mathrm{Totient}(3)+\mathrm{Totient}(4)+\mathrm{Totient}(6)+\mathrm{Totient}(12)Out1212

Multiplicative: φ(mn)=φ(m)φ(n)\varphi(mn)=\varphi(m)\varphi(n) when gcd⁡(m,n)=1\gcd(m,n)=1, here for 44 and 33

live ↗
InTotient(12)=Totient(4)Totient(3)\mathrm{Totient}(12)=\mathrm{Totient}(4)\mathrm{Totient}(3)OutTrue\mathrm{True}

φ(p)=p−1\varphi(p)=p-1 for a prime pp

live ↗
InTotient(17)\mathrm{Totient}(17)Out1616

φ(pk)=pk−1(p−1)\varphi(p^k)=p^{k-1}(p-1): 33⋅2=543^3\cdot2=54

live ↗
InTotient(81)\mathrm{Totient}(81)Out5454

φ(100)=100⋅12⋅45\varphi(100)=100\cdot\frac12\cdot\frac45

live ↗
InTotient(100)\mathrm{Totient}(100)Out4040

φ(35)=4⋅6\varphi(35)=4\cdot6 for coprime factors

live ↗
InTotient(35)\mathrm{Totient}(35)Out2424

The Carmichael function always divides Euler's

live ↗
InCarmichaelLambda(8)∣Totient(8)\mathrm{CarmichaelLambda}(8)\mid\mathrm{Totient}(8)OutTrue\mathrm{True}

For odd prime powers the two agree

live ↗
In[Totient(25),CarmichaelLambda(25)]\bigl\lbrack\mathrm{Totient}(25), \mathrm{CarmichaelLambda}(25)\bigr\rbrackOut[20,20]\bigl\lbrack20, 20\bigr\rbrack

Gauss: ∑d∣nφ(d)=n\sum_{d\mid n}\varphi(d)=n

live ↗
InDivisorSum(15,Totient)=15\mathrm{DivisorSum}(15, \mathrm{Totient})=15OutTrue\mathrm{True}

Multiplicative over 1023=3⋅11⋅311023=3\cdot11\cdot31

live ↗
InTotient(1 023)=Totient(3)Totient(11)Totient(31)\mathrm{Totient}(1\,023)=\mathrm{Totient}(3)\mathrm{Totient}(11)\mathrm{Totient}(31)OutTrue\mathrm{True}

Only 11 is coprime to 22

live ↗
InTotient(2)\mathrm{Totient}(2)Out11

Known value · Wolfram MathematicalFunctionData, EulerPhi

A prime pp gives p−1p-1

live ↗
InTotient(3)\mathrm{Totient}(3)Out22

Known value · Wolfram MathematicalFunctionData, EulerPhi

Odd numbers below 4: 11 and 33

live ↗
InTotient(4)\mathrm{Totient}(4)Out22

Known value · Wolfram MathematicalFunctionData, EulerPhi

Prime, so 44

live ↗
InTotient(5)\mathrm{Totient}(5)Out44

Known value · Wolfram MathematicalFunctionData, EulerPhi

Only 11 and 55 are coprime to 66

live ↗
InTotient(6)\mathrm{Totient}(6)Out22

Known value · Wolfram MathematicalFunctionData, EulerPhi

Prime, so 66

live ↗
InTotient(7)\mathrm{Totient}(7)Out66

Known value · Wolfram MathematicalFunctionData, EulerPhi

Half the residues are odd: 2k−12^{k-1} at 2k2^k

live ↗
InTotient(8)\mathrm{Totient}(8)Out44

Known value · Wolfram MathematicalFunctionData, EulerPhi

φ(p2)=p(p−1)=6\varphi(p^2)=p(p-1)=6

live ↗
InTotient(9)\mathrm{Totient}(9)Out66

Known value · Wolfram MathematicalFunctionData, EulerPhi

Prime, so 1010

live ↗
InTotient(11)\mathrm{Totient}(11)Out1010

Known value · Wolfram MathematicalFunctionData, EulerPhi

Prime, so 1212

live ↗
InTotient(13)\mathrm{Totient}(13)Out1212

Known value · Wolfram MathematicalFunctionData, EulerPhi

φ(2)φ(7)=6\varphi(2)\varphi(7)=6

live ↗
InTotient(14)\mathrm{Totient}(14)Out66

Known value · Wolfram MathematicalFunctionData, EulerPhi

φ(3)φ(5)=8\varphi(3)\varphi(5)=8

live ↗
InTotient(15)\mathrm{Totient}(15)Out88

Known value · Wolfram MathematicalFunctionData, EulerPhi

242^4 gives 23=82^3=8

live ↗
InTotient(16)\mathrm{Totient}(16)Out88

Known value · Wolfram MathematicalFunctionData, EulerPhi

live ↗
InAssuming(p∈P∧r∈Z∧r>0,FunctionExpand(Totient(pr)))\mathrm{Assuming}(p∈\mathbb{P}∧r∈ℤ∧r\gt0, \mathrm{FunctionExpand}(\mathrm{Totient}(p^{r})))OutTotient(pr)\mathrm{Totient}(p^{{{r}}})
About
Examples34
Checked againstWolfram Language 33 agree1 differSageMath 30 agree1 differSymPy 29 agree2 errormathlib4 8 agreeOscar 10 agree3 errorJulia 28 agree2 error
CrosswalkWikipediaMathWorldWikidataEncyclopedia of MathematicsBritannicaDLMFFungrimFungrim entry ×16OEISWolfram LanguageSageMathSymPyOscarJulia

Implementation

mappedwolframpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedoscarpackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedmathlib4packages/oracle/src/mappings.ts

See also: MultiplicativeOrder, DivisorSigma