Efficiency question
- To: mathgroup at smc.vnet.net
- Subject: [mg34680] Efficiency question
- From: ryan.shannon at bemail.org (Ryan Shannon)
- Date: Fri, 31 May 2002 04:29:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I'm trying to write a function that computes cyclotomic polynomials
faster that Mathematica's built in function, and the best I get is slower than
it by a factor of three. Can anybody point out any improvements?
*****************************************************************************
In[4]:=
\!\(f[n_] :=
Module[{list, a = z - 1}, \[IndentingNewLine]list =
Map[First,
FactorInteger[
n]]; \[IndentingNewLine]q := \((a =
PolynomialQuotient[a /. z \[Rule] z\^#, a,
z])\) &; \[IndentingNewLine]Map[q,
list]; \[IndentingNewLine]a /.
z \[Rule] z\^\(n/Apply[Times, list]\)]\)
In[5]:=
Timing[Table[f[n],{n,2,2000}];]
Out[5]=
{40.999 Second,Null}
In[6]:=
Timing[Table[Cyclotomic[n,z],{n,2,2000}];]
Out[6]=
{7.141 Second,Null}
**********************************************************************
That function reads like this...
f[n_]:=Module[{list,a=z-1},
list=Map[First,FactorInteger[n]];
q:=(a=PolynomialQuotient[a/.z->z^#,a,z])&;
Map[q,list];
a/.z->z^(n/Apply[Times,list])]
On the same note, what are some good resources for learning to program
Mathematica as efficiently as possible (books, websites...)?
Thanks!
Ryan Shannon