AssocOp (from which Mul and Add derive) and QExpr both have
_new_rawargs methods.

This method is for very quickly rebuilding an expression from the args
given. No checking of any kind is done. It's ideally suited for the
situation where you remove a single argument from an Add, for example,
and want to rebuild the Add without that term:

    h[4] >>> a = Add(3,x,y);args=a.args;args
    (3, y, x)
    h[4] >>> a._new_rawargs(*(args[:1]+args[2:])) # skipping arg 1
    3 + x
    h[4] >>>

The problem I see with the method is that it's hard to use in anything
but this rebuild case. A handy place to use this is in a method of
simplification (like factor) where you want to keep the coefficient
from becoming distributed into an Add as is normally done by Mul:

    >>> 2*(1+x)
    2 + 2*x

So I want to multiply 2 and 1+x but not do the distribution. Although
one can use Mul(2, 1+x, evaluate=False), this is slower than the
_new_rawargs method (by about a factor of 3). But in order to use the
_new_rawargs you already have to have a Mul in hand. You can't do

    Mul._new_rawargs(Mul, S(2), 1+x)

so that defeats the speed of the method. Does anyone see a better way
to be doing this?

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to