Weird behaviour of Identity matrix with symbolic type

Hi all,

I’m utilizing SymPy within Julia to perform symbolic calculations, but I’ve noticed that the symbolic identity matrix operation is producing inaccurate outcomes. Can you explain why this is happening?

Please find the details in the attached picture.

image

Odd, I don’t see this:

julia> using SymPy

julia> using LinearAlgebra

julia> B = Sym[1 2; 3 4]
2×2 Matrix{Sym}:
 1  2
 3  4

julia> I - B
2×2 Matrix{Sym}:
  0  -2
 -3  -3

Does it happen with a fresh session?

Yes. I got different output.

julia> using SymPy

julia> using LinearAlgebra

julia> B = Sym[1 2; 3 4]
2×2 Matrix{Sym}:
1 2
3 4

julia> I - B
2×2 Matrix{Sym}:
0 2
3 3

julia>

julia>

and my julia version is

julia> VERSION
v"1.6.5"

I only have 1.6 installed on my machine, but this worked:

  | | |_| | | | (_| |  |  Version 1.6.0 (2021-03-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using SymPy, LinearAlgebra
[ Info: Precompiling SymPy [24249f21-da20-56a4-8eb1-6a02cf4ae2e6]

julia> I - Sym[1 2; 3 4]
2×2 Matrix{Sym}:
  0  -2
 -3  -3

Which version of SymPy do you have?

SymPy v1.0.47

That is a bit old, maybe upgrading will fix this?

Thanks for your suggestion. The problem is fixed after the upgrading.