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
exception while simplifying product over matrices #18413
Comments
Looks like a bug in sympy/sympy/concrete/products.py Line 299 in aaf43fc
For your example SymPy can compute it as a power: In [48]: M = Matrix([[a, b], [b, a]])
In [49]: M
Out[49]:
⎡a b⎤
⎢ ⎥
⎣b a⎦
In [50]: M**n
Out[50]:
⎡ n n n n⎤
⎢ (a - b) (a + b) (a - b) (a + b) ⎥
⎢ ──────── + ──────── - ──────── + ────────⎥
⎢ 2 2 2 2 ⎥
⎢ ⎥
⎢ n n n n ⎥
⎢ (a - b) (a + b) (a - b) (a + b) ⎥
⎢- ──────── + ──────── ──────── + ──────── ⎥
⎣ 2 2 2 2 ⎦ A side note here might be that perhaps Product should recognise when a product is just a power. I'm not sure what other matrix cases could be handled in general... (for symbolic limits) |
I anticipate that there are lots of problems regarding sympy functional used with matrix, because |
I'm not sure we need special I can understand introducing In [1]: M = Matrix([[x, y], [y, x]])
In [2]: S = Sum(M, (n, 1, m))
In [3]: S
Out[3]:
m
____
╲
╲
╲ ⎡x y⎤
╱ ⎢ ⎥
╱ ⎣y x⎦
╱
‾‾‾‾
n = 1
In [4]: A = eye(3)
In [5]: A
Out[5]:
⎡1 0 0⎤
⎢ ⎥
⎢0 1 0⎥
⎢ ⎥
⎣0 0 1⎦
In [6]: S*A
Out[6]:
⎡ m ⎤
⎢ ____ ⎥
⎢ ╲ ⎥
⎢ ╲ ⎥
⎢ ╲ ⎡x y⎤ ⎥
⎢ ╱ ⎢ ⎥ 0 0 ⎥
⎢ ╱ ⎣y x⎦ ⎥
⎢ ╱ ⎥
⎢ ‾‾‾‾ ⎥
⎢n = 1 ⎥
⎢ ⎥
⎢ m ⎥
⎢ ____ ⎥
⎢ ╲ ⎥
⎢ ╲ ⎥
⎢ ╲ ⎡x y⎤ ⎥
⎢ 0 ╱ ⎢ ⎥ 0 ⎥
⎢ ╱ ⎣y x⎦ ⎥
⎢ ╱ ⎥
⎢ ‾‾‾‾ ⎥
⎢ n = 1 ⎥
⎢ ⎥
⎢ m ⎥
⎢ ____ ⎥
⎢ ╲ ⎥
⎢ ╲ ⎥
⎢ ╲ ⎡x y⎤⎥
⎢ 0 0 ╱ ⎢ ⎥⎥
⎢ ╱ ⎣y x⎦⎥
⎢ ╱ ⎥
⎢ ‾‾‾‾ ⎥
⎣ n = 1 ⎦ What I think we need is a way to distinguish different classes of object (matrix vs number vs set etc) that is not inherently tied to the the class hierarchy. |
Now
expr.simplify()
results in the exceptionTypeError: cannot add <class 'sympy.matrices.immutable.ImmutableDenseMatrix'> and <class 'int'>
.The text was updated successfully, but these errors were encountered: