Add/Mul -- introduce ._new_rawargs()
commitfd09ab843cde789d295b9b001a27a3a4cbffc576
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Sun, 10 Aug 2008 07:50:38 +0000 (10 11:50 +0400)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Sun, 10 Aug 2008 07:50:38 +0000 (10 11:50 +0400)
treedd52b5a176a45010cb833e681d6e864573a2cbf9
parent27e3746a101b08890de3e12d8c5227942c4d3803
Add/Mul -- introduce ._new_rawargs()

To create new instance of own class with args exactly as provided by caller

This is handy when we want to optimize things, e.g.

    >>> from sympy import Mul, symbols
    >>> x,y = symbols('xy')
    >>> e = Mul(3,x,y)
    >>> e.args
    (3, x, y)
    >>> Mul(*e.args[1:])
    x*y
    >>> e._new_rawargs(*e.args[1:])  # the same as above, but faster
    x*y

Timings (cache: off)
--------------------

    %timeit             %timeit
    Mul(*e.args[1:])    e._new_rawargs(*e.args[1:])

    204 µs              25.7 µs

We'll use this nice new function to optimize Add(*looong_seq) in the next patch.

Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Ondrej Certik <ondrej@certik.cz>
sympy/core/operations.py