Efficient way of using replacement rules
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg484] Efficient way of using replacement rules
- From: corcoran at markov.stats.ox.ac.uk (Stephen Corcoran)
- Date: Mon, 20 Feb 1995 18:25:22 +0000
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}]]
....etc
i.e. replace one of the x's at a time.
Hope this makes sense!
--------------------------------------------------------------------------
Stephen Corcoran, email: corcoran at stats.ox.ac.uk (internet)
Dept. of Statistics, corcoran at uk.ac.ox.stats (janet)
University of Oxford,
1, South Parks Road phone: (0865) 272879
OXFORD, OX1 3TG fax: (0865) 272595
--------------------------------------------------------------------------