Möbius function: Difference between revisions
Content added Content deleted
m (→{{header|J}}: concision) |
m (→{{header|J}}: consistency) |
||
Line 785: | Line 785: | ||
<lang J>mu=: ({{*/1-y>1}} * _1 ^ 2|+/)@q:~&_</lang> |
<lang J>mu=: ({{*/1-y>1}} * _1 ^ 2|+/)@q:~&_</lang> |
||
Explanation: _ q: n gives the list of exponents of prime factors of n. (This is an empty list for 1, is 2 0 2 for the number 100 and is 3 1 1 for the number 120.) |
Explanation: _ q: n gives the list of exponents of prime factors of n. (This is an empty list for the number 1, is 2 0 2 for the number 100 and is 3 1 1 for the number 120.) |
||
In this context +/ is the sum of that list, 2 | +/ is 1 if the sum is odd and 0 if the sum is even. _1^0 is 1 and _1^1 is _1. And, {{*/1-y>1}} returns zero if any exponent is at least 2 in magnitude. |
In this context +/ is the sum of that list, 2 | +/ is 1 if the sum is odd and 0 if the sum is even. _1^0 is 1 and _1^1 is _1. And, {{*/1-y>1}} returns zero if any exponent is at least 2 in magnitude. |