When I reviewed the rscale patch I guess I didn't actually test that the code worked with SymEngine (I thought I did but I guess the unit tests I ran did not exercise everything).
matrix / scalar doesn't work. matrix * scalar**-1 works instead (This seems like it ought to be fixed in SymEngine).
-is there a function in sympy and/or symengine that accomplishes that?
Not that I know of, but it should be easy to write a custom function for it.
Btw, do you really need subs using a list? Is it supposed to be unordered? For example, what do you expect (x + 2*y).subs([(x, y), (y, x)]) to give you?
No--it's not totally necessary (though I feel safer if it is). It was more an efficiency concern, where it was clear that if I were to call .subs() multiple times, I would have to pay for multiple traversals of the expression tree.
Is it supposed to be unordered?
Yeah.
For example, what do you expect (x + 2*y).subs([(x, y), (y, x)]) to give you?
(x + 2*y).subs([(x, y), (y, x)]) currently gives you 3*x because there are multiple traversals. In SymPy, .subs(simultaneous=True) would save you multiple traversals and give you y+2*x. Otherwise it'll do multiple tree traversals internally. SymEngine doesn't have that option, but does only one traversal by default.
Also subs is inefficient because it is mathematically aware. (x+y+z).subs(x+y, 1) gives you z+1. xreplace on the other hand is not mathematically aware and relies on the structure. It takes in a dictionary and does the replacements simultaneously.
In [86]: (x + 2*y).subs([(x, y), (y, x)])Out[86]: 3*xIn [87]: (x + 2*y).subs([(x, y), (y, x)], simultaneous=True)Out[87]: 2*x + yIn [89]: (x + 2*y).xreplace({x: y, y: x})Out[89]: 2*x + yIn [90]: (x+y+z).subs({x+y: 1})Out[90]: z + 1In [91]: (x+y+z).xreplace({x+y: 1})Out[91]: x + y + z
EDIT: simultaneous=True also has multiple tree traversals.
I think the goal is to distribute over the "first layer" of multiplication, no matter how deep it may be in the tree, but I am not sure. @inducer, can you give an example of how this is supposed to help the rscale code?