Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-319

Schur Complement Determinant

Problem

Compute the determinant of the 4x4 block matrix [[A, B], [C, D]] using the Schur complement with A as a 2x2 invertible block:

det = det(A) * det(D - C A^(-1) B)

Return None if det(A) is zero within 1e-12.

Hint

The Schur complement eliminates the top-left block and reduces the 4x4 determinant to a 2x2 one.

Test cases

case 1
in: [[[1,0],[0,1]],[[0,0],[0,0]],[[0,0],[0,0]],[[1,0],[0,1]]]
expected: 1
case 2
in: [[[2,0],[0,2]],[[1,0],[0,1]],[[0,0],[0,0]],[[1,0],[0,1]]]
expected: 4
case 3
in: [[[1,0],[0,1]],[[1,0],[0,0]],[[0,1],[1,0]],[[2,0],[0,2]]]
expected: 4
case 4
in: [[[1,2],[3,4]],[[1,0],[0,1]],[[1,1],[0,1]],[[0,0],[0,0]]]
expected: 1
case 5
in: [[[1,1],[2,2]],[[1,0],[0,1]],[[0,0],[0,0]],[[1,0],[0,1]]]
expected: null
Starter codePython
def schur_complement_determinant(A, B, C, D):
    # Your code here
    pass

5 test cases · run your code against them in the editor