       Re: Timing

• To: mathgroup at smc.vnet.net
• Subject: [mg88072] Re: Timing
• From: dh <dh at metrohm.ch>
• Date: Wed, 23 Apr 2008 04:10:56 -0400 (EDT)
• References: <480A0EE6.3090109@csl.pl> <fuhqsk\$rdv\$1@smc.vnet.net>

```
Hi Artur,

most time is spent in calculating ((3 + 2 Sqrt)^(2^(n - 1) - 1) and

(3 -  2 Sqrt)^(2^(n - 1) - 1). We may speed this up by calculating it

recursively and using functions that remember their values. You may even

precalculating p1 and p2 by p1[nmax]; and p2[nmax];. Do not make nmax

too big,the numbers increase astronomically, otherwise your memory will

overflow. The subsequent calculations are then very fast. Here is an

example:

p1[n_]:=p1[n]=p1[n-1]^(2)(3+2Sqrt)//Expand;

p1=1;

p2[n_]:=p2[n]=p2[n-1]^(2)(3-2Sqrt)//Expand;

p2=1;

p1[27; p2;

Timing[Do[If[IntegerQ[t= (p1[n]-p2[n])/(4 Sqrt

(-1+2^n))//Expand],Print[{n}]],{n,1,27,2}]]

hope this helps, Daniel

Artur wrote:

> Who know how change bellow procedure to received reasonable timing?

>

> Part:

> Expand[((3 + 2 Sqrt)^(2^(n - 1) - 1) - (3 - 2 Sqrt)^(2^(n - 1) -

> 1))/(4 Sqrt)]/(2^n - 1)

> is every time integer

>> Timing[Do[ If[IntegerQ[Expand[((3 + 2 Sqrt)^(2^(n - 1) - 1) - (3 -

>> 2 Sqrt)^(2^(n - 1) - 1))/(4 Sqrt)]/(2^n - 1)],

>>   Print[n]], {n, 1, 17}]]

>>

> I will be greatfull for any help! (Mayby some N[] or Floor[N[]]  or

> Int[N[]] will be quickest

>

> Best wishes

> Artur

>

```

• Prev by Date: Re: Dynamic: feature?
• Next by Date: Probably memory problem
• Previous by thread: Re: Re: Timing