MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Working with factors of triangular numbers.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78777] Re: Working with factors of triangular numbers.
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Mon, 9 Jul 2007 01:38:55 -0400 (EDT)

On 7/8/07 at 6:14 AM, akoz at mimuw.edu.pl (Andrzej Kozlowski) wrote:

>In fact, one more remark (its hard to stop adding these remarks!).
>Clearly if you are computing the values of T[n] for several
>different n, this is an inefficient way to proceed, because you if
>we know that t1 is the smallest triagular number that can be
>factored as a product of n factors than we know also that no
>triangular number smaller than t1 can be factored as a product of
>(n+1) factors. It is then better to proceed like this.

>t[a_] := k /. ToRules[Reduce[k (k + 1)/2 == a && k > 0, k]]

>T[n_, m_:1] :=
>Block[{k = t[m], $Messages}, While[k++; FF[k*((k + 1)/2) - 1] <
>n,  Null];
>k*((k + 1)/2)]

>T can now be usd to search starting with the last found triangular
>number. Thus:

>i = 1; NestList[T[++i, #] &, 3, 6] {3, 15, 55, 253, 1081, 13861,
>115921}

=46WIW, it appears you can get a small improvement in speed by
substituting Binomial[k+1,2] for k(k+1)/2. On my PowerBook, I get:

In[26]:= Timing[tt = Table[n (n + 1)/2, {n, 100000}];]

Out[26]= {0.600173,Null}

In[27]:= Timing[bb = Table[Binomial[n + 1, 2], {n, 100000}];]

Out[27]= {0.442553,Null}

In[28]:= tt == bb

Out[28]= True

In[29]:= $Version

Out[29]= 6.0 for Mac OS X PowerPC (32-bit) (April 20, 2007)

Apparently, the built in function Binomial has an optimization
which possibly avoids a divide operation.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Bug in packages with RegularExpression[]
  • Next by Date: Re: Loop, deleting intermediary results, lists
  • Previous by thread: Re: Working with factors of triangular numbers.
  • Next by thread: replacing expressions