Simplifying a block matrix with zero-valued blocks?

Viewed 120

In my recent project, I'd like to solve symbolic linear algebra problem. The equation I want to solve is

S^{-1}*S^{-1}.T

where S is a lower triangular matrix

S = [[a,0,0],[b,c,0],[d,e,f]]

I can implement this equation in SymPy and even solve it, but I don't know of a way to tell Sympy that Z is a matrix of zeros (and hence all terms with a Z in it should cancel out). I tried replacing a symbolic Z with a matrix of zeros, but this just naively inserts the matrix of zeros into the equation without cancelling any terms.

Is there a way to define Z=0 and cancel all corresponding terms without inserting any values for A, B, C, D, E, and F?

# Import sympy
import sympy as sym

# Create some symbolic square matrices; 3-by-3 size not strictly necessary
A = sym.MatrixSymbol('A',3,3)
B = sym.MatrixSymbol('B',3,3)
C = sym.MatrixSymbol('C',3,3)
D = sym.MatrixSymbol('D',3,3)
E = sym.MatrixSymbol('E',3,3)
F = sym.MatrixSymbol('F',3,3)

# Create a dummy MatrixSymbol for a block of zeros
Z = sym.MatrixSymbol('Z',3,3)
# Z = sym.zeros(3,3) # Specifying a matrix of zeros does not cancel out

# Create a lower triangular BlockMatrix; the upper right entries are all zero
S   = sym.BlockMatrix([[A,Z,Z],[B,C,Z],[D,E,F]])

# Calculate the inverse of S
Sinv = S.inverse()

# Simplify the dot product between Sinv and Sinv.T
# This does NOT cancel terms with Z
rhs = sym.block_collapse(Sinv*Sinv.transpose())
1 Answers

Best I can come up with:

Through the power of math, if I haven't forgotten everything I learned, then `S^{-1} S^{-T} = (S^T S)^{-1}

Now you can just block-multiply your matrix S symbolically by hand, and then ask sympy to invert that.

EDIT: Actually, why not replace Z with ZeroMatrix(3,3)?

Related