Re: Reciprocal Sums

• To: mathgroup at smc.vnet.net
• Subject: [mg32480] Re: Reciprocal Sums
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Wed, 23 Jan 2002 00:59:55 -0500 (EST)
• References: <a2j8u1\$7a6\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Juan,
I guess it depends on how big n might be, whether the following is reliable
or not. It may be possible up to  quite big n to guarantee that we get all
possibilities and possibly some more; and  then use your method on the
possiblities.
Another way: look if the code for Partitions can be modified.

<< "DiscreteMath`Combinatorica`"

n = 40;

p = Partitions[n];

is = Compile[{{x, _Integer, 1}}, Plus @@ (1/x)];

Timing[ans = p[[Flatten[Position[FractionalPart[is /@ p],
x_ /; x < .000001 || x > 0.999999]]]]; ]

{13.35 Second,Null}

Timing[ans2 = Cases[p, x_ /; IntegerQ[Plus @@ (1/x)]]; ]

{47.95 Second,Null}

Check:

ans === ans2

True
--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Juan" <erfa11 at hotmail.com> wrote in message
news:a2j8u1\$7a6\$1 at smc.vnet.net...
> Hello,
> I need your help to resolve this question (I give a example for n=12):
>
> In[1]:= << DiscreteMath`Combinatorica`
>
> In[2]:= n = 12;
>
> In[3]:= p = Partitions[n];
>
>
> Now, I want to get from p thouse partitions which reciprocal sum is a
> integer.
>
> In[4]:= r = Cases[p, x_ /; IntegerQ[Plus @@ (1/x)]]
>
> Out[4]:= {{6, 3, 2, 1}, {4, 4, 2, 1, 1}, {3, 3, 3, 1, 1, 1}, {2, 2, 2, 2,
2,
> 2}, {2, 2,2, 2, 1, 1, 1, 1}, {2, 2, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1,
1,
> 1, 1, 1, 1, 1, 1, 1}}
>
> But, is n is a big number, then you have to wait a big number of seconds
to
> get r.
>
> Any suggestion to do that better-faster?
>
> Best regard
> Juan
>
>
> _________________________________________________________________
> Hable con sus amigos en línea, pruebe MSN Messenger:
http://messenger.msn.es
>
>

```

• Prev by Date: Re: Simplify with assumptions
• Next by Date: Re: Unstable solutions to NonlinearFit
• Previous by thread: Re: Reciprocal Sums
• Next by thread: PDF Format