mf=: (*./@(1&=) * _1 ^ #) @ {: @ (__&q:)
(mf -: mobiusT)"0 >: i.16
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
----- Original Message -----
From: Arie Groeneveld <[EMAIL PROTECTED]>
Date: Monday, September 17, 2007 9:58
Subject: [Jprogramming] Mobius function
To: Programming forum <[email protected]>
>
> Exercising on tacit verbs I succeed to define
> the Mobius function.
>
>
> Explicit version:
>
> mobiusX=: 3 : 0
> ms=.{:__ q: y
> if. 0=+/1<ms do. _1^+/ms else. 0 end.
> )
>
> mobiusX"0 [1+i.16
> 1 _1 _1 0 _1 1 _1 0 0 1 _1 0 _1 1 1 0
>
>
> Tacit version
>
>
> mobiusT=: [: 0: ` (_1^#) @. (0= [:+/1<]) [: {: __ q: ]
>
> For the value of mobius N = (-1)^r in case N is the product
> of r different primes, one may use (_1^#) or (_1^+/) because
> in this case they are equivalent:
> - determining the length of the list of exponents
> - summing the one's of the exponents.
> It's also very convenient that they both handle the special
> case for mobius 1 = 1.
> In case mobius N is not square free the result has to be 0,
> so I have to use the constant function 0:.
>
>
> mobiusT"0 [1+i.16
> 1 _1 _1 0 _1 1 _1 0 0 1 _1 0 _1 1 1 0
>
>
>
>
>
> a.{~q:9991
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm