JuliaPy / SymPy.jl

Julia interface to SymPy via PyCall
http://juliapy.github.io/SymPy.jl/
MIT License
266 stars 61 forks source link

Matrix multiplication with transpose #512

Closed mzaffalon closed 1 year ago

mzaffalon commented 1 year ago

In both examples below, I expect the matrix [p₁]:

using SymPy

julia> @syms p₁ p₂; B = [1; 0]; P = [p₁ 0; 0 p₂]; transpose(B)*P*B
p₁

julia> B'*P*B
transpose(p₁) # B'*(P*B) -> p₁

with SymPy v1.1.9 and Julia v1.9.1.

jverzani commented 1 year ago

I just checked and this appears to be inherited from how base Julia handles this product.

mzaffalon commented 1 year ago

Thank you. B should be a matrix for it to work as I expect (and for consistency). The following works:

using SymPy

julia> @syms p₁ p₂; B = [1; 0;;]; P = [p₁ 0; 0 p₂]; transpose(B)*P*B
1×1 Matrix{Sym}:
 p₁

julia> B'*P*B
1×1 Matrix{Sym}:
 p₁

Ref: https://discourse.julialang.org/t/1x1-matrix-automatically-converted-to-number/101106