MoebiusMu[n]
gives the Möbius function
.
MoebiusMu
MoebiusMu[n]
gives the Möbius function
.
Details
- MoebiusMu is also known as Möbius function.
- Integer mathematical function, suitable for both symbolic and numerical manipulation.
- MoebiusMu[n] gives the sum of the primitive
roots of unity. - For a number n=u p1k1⋯ pmkm with u a unit and pi primes, MoebiusMu[n]returns 0 unless all ki are equal to 1, in which case it gives (-1)m.
- MoebiusMu[m+In] automatically works over Gaussian integers.
Examples
open all close allBasic Examples (2)
Compute the Möbius function at 11:
MoebiusMu[11]Plot the MoebiusMu sequence for the first 20 numbers:
DiscretePlot[MoebiusMu[k], {k, 20}, AxesOrigin -> {0, 0}]Scope (10)
Numerical Evaluation (4)
Symbolic Manipulation (6)
TraditionalForm formatting:
MoebiusMu[n]//TraditionalFormReduce[MoebiusMu[a] == (-1) ^ a && 0 < a < 10, a, Integers]Solve[MoebiusMu[a + b] == 1 && 5 < a < b < 10, {a, b}, Integers]Use MoebiusMu in a sum:
Sum[MoebiusMu[n] / n ^ 2, {n, 1, ∞}]Product[k ^ (-MoebiusMu[k] / k), {k, 1, ∞}]Identify the MoebiusMu sequence:
MoebiusMu[Range[20]]FindSequenceFunction[%, n]DirichletTransform of MoebiusMu:
DirichletTransform[MoebiusMu[n], n, s]Sum[MoebiusMu[n] / n ^ s, {n, ∞}]Applications (11)
Basic Applications (2)
Highlight numbers n for which
in blue, numbers n for which
in red and numbers n for which
in black:
Multicolumn[If[MoebiusMu[#] == -1, Style[#, Blue, Bold], If[MoebiusMu[#] == 1, Style[#, Red, Bold], Style[#, Bold]]]& /@ Range[100], 10, ...]Histogram of the cumulative values of MoebiusMu:
M[n_] := Total[MoebiusMu[Range[n]]];Histogram[Table[M[n], {n, 10 ^ 3}]]The underlying distribution from the data:
FindDistribution[Table[M[n], {n, 10 ^ 3}]]Number Theory (9)
Use MoebiusMu to test for a square-free number:
MoebiusMu[15] ≠ 0SquareFreeQ[15]Use MoebiusMu to compute the number of terms in the Farey sequence:
n = 15;
1 / 2(3 + Sum[MoebiusMu[d]Floor[n / d] ^ 2, {d, n}])Length[FareySequence[n]]Use MoebiusMu to compute MangoldtLambda:
DivisorSum[n, MoebiusMu[n / #]Log[#]&]DivisorSum[n, MoebiusMu[n / # ^ 2]&, Divisible[n, # ^ 2]&]DivisorSum[n, MoebiusMu[#]n / #&]DivisorSum[n + 1, MoebiusMu[#]&]DivisorSum[1, MoebiusMu[#]&]AllTrue[Table[DivisorSum[n, MoebiusMu[#]&], {n, 2, 100}], # == 0&]MoebiusMu is related to DivisorSigma through the Möbius inversion formulas:
Table[n == Sum[MoebiusMu[d]DivisorSigma[1, n / d], {d, Divisors[n]}], {n, 10}]MoebiusMu is related to PrimeNu through the following formula:
With[{n = 30}, DivisorSum[n, Abs[MoebiusMu[#]]&] == 2 ^ PrimeNu[n]]MoebiusMu satisfies the following identities:
n = 27;DivisorSum[n, MoebiusMu[n / #]Log[#]&] == MangoldtLambda[n]DivisorSum[n, MoebiusMu[#]Log[#]&] == -MangoldtLambda[n]DivisorSum[n, MoebiusMu[n / #]MangoldtLambda[#]&] == -MoebiusMu[n]Log[n]Compute the number of polynomials over
that are irreducible of degree n:
polynomialCount[p_, n_] := DivisorSum[n, MoebiusMu[n / #]p ^ #&] / n;Irreducible polynomials modulo 5:
Table[polynomialCount[5, n], {n, 1, 20}]Distribution of irreducible polynomials modulo 5:
DiscretePlot[polynomialCount[5, n] / 5 ^ n, {n, 20}, PlotRange -> All]Logarithmic plot of the count for
:
DiscretePlot[{polynomialCount[2, n], polynomialCount[3, n], polynomialCount[5, n]}, {n, 20}, ScalingFunctions -> "Log", PlotLegends -> {"p=2", "p=3", "p=5"}]Plot the Mertens function
[more info]:
M[n_] := Total[MoebiusMu[Range[n]]];DiscretePlot[M[n], {n, 1, 1000}]ListLinePlot[Table[Sqrt[n] - Abs[M[n]], {n, 1000}]]Properties & Relations (7)
MoebiusMu is a multiplicative function:
MoebiusMu[11 23] == MoebiusMu[11]MoebiusMu[23]
is 1 if n is a product of an even number of distinct primes:
FactorInteger[5187]MoebiusMu[5187]
is
if it is a product of an odd number of primes:
FactorInteger[32538]MoebiusMu[32538]
is 0 if it has a multiple prime factor:
FactorInteger[1440]MoebiusMu[1440]MoebiusMu is 0 for composite prime powers and
for primes:
{PrimePowerQ[121] && CompositeQ[121], MoebiusMu[121]}{PrimeQ[11], MoebiusMu[11]}MoebiusMu is 0 for non-square-free integers:
SquareFreeQ[12]MoebiusMu[12]Use PrimeNu to compute MoebiusMu for square-free numbers:
With[{n = 42}, MoebiusMu[42] == (-1) ^ PrimeNu[42]]MoebiusMu is equal to the sum of the primitive
roots of unity:
n = 5;x /. Solve[Cyclotomic[n, x] == 0]FullSimplify[Total[%]]MoebiusMu[n]MoebiusMu can be expressed in terms of LiouvilleLambda and KroneckerDelta:
μ[n_] := KroneckerDelta[PrimeNu[n], PrimeOmega[n]]LiouvilleLambda[n];Table[μ[n], {n, 1, 10}]Table[MoebiusMu[n], {n, 1, 10}]Neat Examples (4)
Plot MoebiusMu for the sum of two squares:
ArrayPlot[Table[MoebiusMu[a ^ 2 + b ^ 2], {a, 50}, {b, 50}], ColorFunction -> "Rainbow"]Plot the arguments of the Fourier transform of MoebiusMu:
ArrayPlot[Arg[Fourier[Table[MoebiusMu[m + n], {m, 200}, {n, 200}]]], ColorFunction -> Hue]Plot the Ulam spiral of MoebiusMu:
ulam[n_] := Partition[Permute[Range[n ^ 2], Accumulate[Take[Flatten[{{n ^ 2 + 1} / 2, Table
[(-1) ^ j i, {j, n}, {i, {-1, n}}, {j}]}], n ^ 2]]], n];ArrayPlot[MoebiusMu[ulam[51]], ColorFunction -> "BlueGreenYellow"]Plot the values of
that have
:
ArrayMesh[Abs[Table[MoebiusMu[a ^ 2 + b ^ 2 + c ^ 2], {a, 10}, {b, 10}, {c, 10}]] /. {1 -> 0, 0 -> 1}]See Also
Divisors SquareFreeQ FactorInteger DivisorSigma JacobiSymbol DivisorSum DirichletConvolve KroneckerDelta LiouvilleLambda PrimeOmega PrimeNu
Function Repository: RamanujanC
Tech Notes
Related Links
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), MoebiusMu, Wolfram Language function, https://reference.wolfram.com/language/ref/MoebiusMu.html.
CMS
Wolfram Language. 1988. "MoebiusMu." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/MoebiusMu.html.
APA
Wolfram Language. (1988). MoebiusMu. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MoebiusMu.html
BibTeX
@misc{reference.wolfram_2026_moebiusmu, author="Wolfram Research", title="{MoebiusMu}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/MoebiusMu.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_moebiusmu, organization={Wolfram Research}, title={MoebiusMu}, year={1988}, url={https://reference.wolfram.com/language/ref/MoebiusMu.html}, note=[Accessed: 12-June-2026]}