FYI, here's a complete tree of the arguments of the sigmatest of what's
going on with the number 24
+/divs 24
60
-: 60 - +:24
6
divisors needed:
24-.~divs 24
12 8 6 4 3 2 1
SigmaTest:
6 sigmaTest 12 8 6 4 3 2 1
6 | 6 4 3 2 1
6 -6 | 4 3 2 1 6 | 4 3 2 1
0 | 4 3 2 1
-|- 6-4 | 3 2 1 6 | 3 2 1
2 | 3 2 1 6-3 | 2 1 6 | 2 1
2 | 2 1 3 | 2 1 6-2 | 1 6 | 1
2-2 | 1 2 | 1 3-2 | 1 4 | 1 6-1 | {}
0 | 1 2-1| {} 1 | 1 3 | 1 4-1 | {} -|-
-|- -|- 1-1 | {} 3-1 | {} -|-
-|- -|-
-|- termination
{} empty set
You will notice that on the second line of the tree
6 -6 | 4 3 2 1
already gives a true indication.
I hope the tree will make sense and that it survives the influences of
its journey through cyberspace.
Anyway I have no idea if M. is of any help here.
Hallo Roger Hui, je schreef op 28-01-10 17:54:
> When it's a double recursion you should try using M. .
>
>
>
> ----- Original Message -----
> From: Aai <[email protected]>
> Date: Thursday, January 28, 2010 7:25
> Subject: Re: [Jprogramming] Zumkeller numbers
> To: Programming forum <[email protected]>
>
>
>> Well it would be nice if someone can explain why this is so much
>> slower :-)
>> Is there no short cut by oring recursive calls?
>>
>> ik schreef op 28-01-10 15:59:
>>
>>> sigma(n) is just the sum of the divisors +/divs
>>>
>>> This was my first approach of sigmaTest:
>>>
>>> sigmtest=: 4 : 0
>>> if. 0=x do. 1 return. end.
>>> if. 0=#y do. 0 return. end.
>>> if. x < {.y do. x sigmtest }.y
>>> else. ((x-{.y) sigmtest }.y ) +. x sigmtest }.y end.
>>> )
>>>
>>> This 'exact' translation makes it probably much slower.
>>>
>>>
>>>
>>> Thanks
>>>
>>>
>>>
>>>
>>>
>>> Hallo Raul Miller, je schreef op 28-01-10 15:20:
>>>
>>>
>>>> On Thu, Jan 28, 2010 at 7:11 AM, Aai <[email protected]> wrote:
>>>>
>>>>
>>>>
>>>>> fact 3: The sigma test. n is a Zumkeller number if and only if
>>>>> (sigma(n)-2n)/2 is either zero or is a sum of distinct
>>>>>
>> positive factors
>>
>>>>> of n excluding n itself.
>>>>>
>>>>>
>>>>>
>>>> What definition of sigma are you using here?
>>>>
>>>> I can reverse engineer your code, but that will take a bit
>>>> of time.
>>>>
>>>>
>>>>
>>>>
>>>>> divs=: 13 :'\:~ , > */&>/(^ i.@>:)&.>/__ q: y'
>>>>>
>>>>>
>>>>>
>>>> This can be simplified slightly:
>>>>
>>>> divs=: 13 :'\:~ , */&>/(^ i.@>:)&.>/__ q: y'
>>>>
>>>>
>>>>
>>>>
>>>>> [1] with this kind of code Haskell seems much faster. Excerpt
>>>>>
>>>>> ....
>>>>>
>>>>> sigmaTest 0 _ = True
>>>>> sigmaTest _ [] = False
>>>>> sigmaTest n (f:fs)
>>>>> | f > n = sigmaTest n fs
>>>>> | otherwise = sigmaTest (n-f) fs || sigmaTest n fs
>>>>>
>>>>>
>>>>>
>>>> Here is a literal translation of that into J:
>>>>
>>>> sigmaTest=: 4 :0
>>>> if. 0=x do.1 return.end.
>>>> if. 0=#y do.0 return.end.
>>>> f=.{.y
>>>> fs=.}.y
>>>> if. x<f do. x sigmaTest fs return.end.
>>>> if. (x-f) sigmaTest fs do.1 return.end.
>>>> x sigmaTest fs
>>>> )
>>>>
>>>> With this definition, and
>>>>
>>>> zumkeller =: 3 : 0"0
>>>> s=. +/ fs=. divs y
>>>> if. (2|s) +. s < +: y do. 0 else.
>>>> (s&-&.+:y) sigmaTest fs end.
>>>> )
>>>>
>>>> zumkeller 80010
>>>> 1
>>>>
>>>> FYI,
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>> --
>> Met vriendelijke groet,
>> =@@i
>>
>> -----------------------------------------------------------------
>> -----
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
--
Met vriendelijke groet,
=@@i
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm