-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross product of vectors gives zero erroneously with expand()
, but correct results without
#23749
Comments
This is the test I ran:
On sympy 1.7.1, it gives this:
But on 1.8 and newer, it shows
|
With |
Ok, I got a bit further. It seems the root cause might be that |
Ok, so these are my thoughts now: Since the breaking commit above, That would probably be fine, if Finally, The linked PR adds another special case to |
The basic problem is really just this: In [7]: from sympy.vector import CoordSys3D
In [8]: r = CoordSys3D('r')
In [9]: type(Mul(2, r.i))
Out[9]: sympy.core.mul.Mul
In [10]: type(2*r.i)
Out[10]: sympy.vector.vector.VectorMul It isn't enough in SymPy to override The Matrix types have a way of making this work: In [13]: M = MatrixSymbol('M', 2, 2)
In [14]: type(Mul(2, M))
Out[14]: sympy.matrices.expressions.matmul.MatMul
In [15]: type(2 * M)
Out[15]: sympy.matrices.expressions.matmul.MatMul I think this is handled here: sympy/sympy/core/operations.py Line 101 in 64e187e
Which leads through to here: sympy/sympy/matrices/expressions/matexpr.py Lines 474 to 516 in 64e187e
I'm not a fan of that mechanism but BasisDependent should probably use the same mechanism as MatrixExpr for this.
|
Given that
r
is asympy.vector.CoordSys3D
instance, expandingr.i+r.i
gives aMul
instance in sympy >= 1.8, but aVectorMul
in earlier versions. This leads to very surprising behavior, such as this:Sympy 1.7.1 and earlier give the same result for both the original expression and the expanded expression, but later versions (including current git) give the above.
The text was updated successfully, but these errors were encountered: