Help to build a function to approximate a expression when X >> Y
Subject: Help to build a function to approximate a expression when X >> Y
From: Javier Sanchez
Date: Wed, 03 Oct 2007 15:37:57 +0200
Hi,
this is a more real example.
(gm*Re+gm*Rb)*CF*CL*RF*RL*S^3+
(((((gm*Re+1)*wt*CF+gm)*CL+gm*CF)*RF+(gm*Re+gm*Rb)*CL)*RL+(gm*Re+gm*Rb)*CF*RF)*S^2
+((gm*wt*CF*RF+(gm*Re+1)*wt*CL+gm)*R+((gm*Re+1)*wt*CF+gm)*RF+gm*Re+gm*Rb)*S+
gm*wt*RL+(gm*Re+1)*wt
Answering your questions,
the ci's are expressions independent of the vi's. They are products of
other variables after expanssion.
In general I can not assume the ci's are positive.
This is a function that seems to be working (but that can be optimized
and generalized). The approximation
assumes x >> y.
approx1(exp,x,y):=block([expanded,f,cp,xterm,xcomp,yterm],
/*Expand to get a sum of terms*/
expanded:expand(exp),
/*Find the terms independent of x and y */
f:apply("+",first(partition(first(partition(args(expanded),x)),y))),
/*Find the terms depending on x and y (in my case x*y) */
cp:apply("+",last(partition(last(partition(args(expanded),x)),y))),
/*Subtract these terms from the expanded expression to
avoid approximating several times the same terms later on*/
expanded:expanded-cp,
/*Build the list of terms that depend on x. Note that because we
made expanded-cp now we do not have the terms that depend on both
variables at the same time. This means that we get the terms that
only depend on x*/
xterm:args(coeff(expanded,x,1)),
/*Build a new list including also the opposite sign terms so that
the approximation works even when the signs in the common factors
are not the same*/
xcomp:join(xterm,(-1)*xterm),
/*Build the list of terms that depend only on y*/
yterm:args(coeff(expanded,y,1)),
/*Modify this y-only dependent list by dropping the terms in common
with the x-only dependent list*/
yterm:listify(setdifference(setify(yterm),setify(xcomp))),
/*Rebuild the expression*/
expanded:x*apply("+",xterm)+y*apply("+",yterm)+f+cp,
expanded:format(expanded,%p(S),%f),
expanded
)$
Thanks for your help and interest.
Stavros Macrakis wrote:
> OK, I'm still not sure I understand all your assumptions here.
>
> Are these expressions exactly of the form
>
> (c0 + c3 + ...) * v0 + (c1 + c3 + ...) * v1 + ...
>
> where all the ci's and vi's are literal variables? Or are the ci's
> arbitrary expressions (presumably independent of the vi's)?
>
> Are we assuming that the ci's are all positive?
>
> Perhaps it would be clearer if you would give us a *specific* real
> example of your expression rather than say it is "of the form"....
>
> -s
>
>