Re: Efficiency question

*To*: mathgroup at smc.vnet.net*Subject*: [mg34714] Re: Efficiency question*From*: ryan.shannon at bemail.org (Ryan Shannon)*Date*: Sun, 2 Jun 2002 01:14:51 -0400 (EDT)*References*: <ada1u7$kds$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Thank you. I stumbled upon Fold the same day I posted that question. That's a great function! Interestingly, Mathematica doesn't take advantage of the gains to be had if n is prime. f[n_]:=If[PrimeQ[n], Sum[z^(k-1),{k,n}], Cyclotomic[n,z]] This is quite a bit faster ******************************************************************** In[22]:= \!\(f[n_] := If[PrimeQ[n], Sum[z\^\(k - 1\), {k, n}], Cyclotomic[n, z]]\) In[23]:= Table[f[n]-Cyclotomic[n,z],{n,2,20}] Out[23]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} In[24]:= Timing[Table[Cyclotomic[n,z],{n,2,2000}];] Out[24]= {8.242 Second,Null} In[25]:= Timing[Table[f[n],{n,2,2000}];] Out[25]= {6.099 Second,Null} *********************************************************************