Differences between revisions 6 and 7
 ⇤ ← Revision 6 as of 2007-09-27 02:10:36 → Size: 1551 Editor: RogerHui Comment: word fiddling ← Revision 7 as of 2008-12-08 10:45:40 → ⇥ Size: 1475 Editor: anonymous Comment: converted to 1.6 markup Deletions are marked like this. Additions are marked like this. Line 34: Line 34: [[BR]] <
> Line 37: Line 37: * [http://mathworld.wolfram.com/MoebiusFunction.html MathWorld] * [http://www.research.att.com/projects/OEIS?Anum=A008683 On-line Encyclopedia of Integer Sequences A008683] * [http://en.wikipedia.org/wiki/M%C3%B6bius_function Wikipedia] * [:../Mertens Function:Mertens Function] * [[MathWorld:MoebiusFunction|MathWorld]] * [[OEIS:A008683|On-line Encyclopedia of Integer Sequences A008683]] * [[WikiPedia:M%C3%B6bius_function|Wikipedia]] * [[../Mertens Function|Mertens Function]] Line 42: Line 42: [[BR]] <
> Line 45: Line 45: [http://www.jsoftware.com/pipermail/programming/2007-September/008124.html J Programming Forum] [[http://www.jsoftware.com/pipermail/programming/2007-September/008124.html|J Programming Forum]]

The Möbius function on positive integer n is defined as follows:

•  1 if n has an even number of distinct prime factors

• _1 if n has an odd number of distinct prime factors

•  0 if n is not square-free

The Möbius function can be computed as follows:

```mobius0=: (*./@(1&=) * _1 ^ #) @ {: @ (__&q:)
mobius1=: (-@(*./)@(1&=) ^ #) @ {: @ (__&q:)
mobius2=: (*./@~: * _1 ^ #)@q:
mobius =: */ @: - @: ~: @: q:```

The Möbius function is non-zero only if the prime exponents are all 1s, 1 if there is an even number of them and _1 if odd (mobius0 and mobius1). The Möbius function is non-zero only if n has distinct prime factors, 1 if there is an even number of them and _1 if odd (mobius2 and mobius).

For example:

```   mobius"0 >:i.5 10
1 _1 _1 0 _1 1 _1 0  0  1
_1  0 _1 1  1 0 _1 0 _1  0
1  1 _1 0  0 1  0 0 _1 _1
_1  0  1 1  1 0 _1 1  1  0
_1 _1 _1 0  0 1 _1 0  0  0```