Mul.flatten -- optimize for all-objects-are-commutative case
commitb91318ef9b159c2728b97d9a9d7ca01abb40431f
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Sun, 10 Aug 2008 18:52:47 +0000 (10 22:52 +0400)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Sun, 10 Aug 2008 18:52:47 +0000 (10 22:52 +0400)
treeab37f83baac24cd258a3b33523ae1301712adbfd
parent94918f59b7d2c9df67567d2183f5b338e0159b7a
Mul.flatten -- optimize for all-objects-are-commutative case

Previously we used to pass all objects through non-commutative flow path, and
only then they were returned back to commutative code-path.

Of course this was adding some overhead, and this patch reorganizes PART-1 of
Mul.flatten to handle commutative objects more effectively.

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

    d = [x,y,z]
    q = [x,y,z,x**2,y**2,z**2]

        Mul(*d)     Mul(*q)     fem_test.py

old:    253 µs      599 µs      4.99 s
new:    208 µs      501 µs      4.67 s

speddup: 21.6%      19.5%       6.8%

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