(50g) Möbius function (MOB) - Joe Horn - 03-16-2018 09:34 AM
The Möbius function, used in number theory, usually written as μ(n) but called MOB(n) here, is defined thus:
- MOB(n) = 0 if n has a squared prime factor.
- MOB(n) = 1 if n is a square-free positive integer with an even number of prime factors.
- MOB(n) = −1 if n is a square-free positive integer with an odd number of prime factors.
Examples:
- MOB(32) = 0 because it has a squared prime factor (it can be divided by 2^2).
- MOB(33) = 1 because it is square-free and has an even number of prime factors (3 and 11).
- MOB(30) = -1 because it is square-free and has an odd number of prime factors (2, 3, and 5).
Here is an HP 50g program that returns MOB(n) for any positive integer n.
Code:
\<<
IF DUP 1 -
THEN FACTORS AXL DUP SIZE 2. / 2. + RDM TRAN AXL EVAL 1. +
IF \PILIST 1. SAME
THEN SIZE 2. MOD -2. * 1. + R\->I
ELSE DROP 0
END
END
\>>
BYTES: 132.5 #2EE7h
RE: (50g) Möbius function (MOB) - Gerald H - 03-17-2018 12:58 AM
Here a Sys version of the important function:
Size: 102.
CkSum: # 22A4h
Code:
::
CK1&Dispatch
# FF
::
{
ROTDROPSWAP
%1
EQUALcase
FPTR2 ^RNEGext
FPTR2 ^DROPZ0
}
1LAMBIND
::
FPTR2 ^ZAbs
FPTR2 ^DupQIsZero?
caseSIZEERR
FPTR2 ^DupZIsOne?
?SEMI
FPTR2 ^MZSQFF
#2/
ZINT 1
SWAP
ZERO_DO
1GETLAM
COMPEVAL
LOOP
;
ABND
;
;
|