MathGroup Archive 1995

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

Search the Archive

Efficient way of using replacement rules

Suppose I have an expression 

t1 = x[1] x[2] x[3] x[4] x[5]

(or similar).  I want to replace the x's by a long expression of the form

x[i] = <n1 terms> + q <n2 terms> + q^2 <n3 terms>

and then expand, keeping terms of terms up to q^2 but no higher.  If I
do this, the naive way, I would use:

t2 = Normal[Series[t1 /. x[i_] -> <n1 terms> + q <n2 terms> + q^2 <n3 terms>,{q,0,2}]]

But, the replacement part would generate a lot of terms (n1,n2,n3 are
large) presumably making this slow.  Would it be quicker/possible to:

replace x[1] = <n1 terms> + q <n2 terms> + q^2 <n3 terms>
Normal[Series[ ,{q,0,2}]]
replace x[2]  = <n1 terms> + q <n2 terms> + q^2 <n3 terms>
Normal[Series[ ,{q,0,2}]]

i.e. replace one of the x's at a time.

Hope this makes sense!

Stephen Corcoran,		email:	corcoran at (internet)
Dept. of Statistics,			corcoran at (janet)
University of Oxford,
1, South Parks Road		phone:  (0865) 272879
OXFORD, OX1 3TG			fax:	(0865) 272595

  • Prev by Date: quadratic programming
  • Next by Date: contour integral
  • Previous by thread: quadratic programming
  • Next by thread: contour integral