def test_doit_with_MatrixBase(): X = ImmutableMatrix([[1, 2], [3, 4]]) assert MatPow(X, 0).doit() == ImmutableMatrix(Identity(2)) assert MatPow(X, 1).doit() == X assert MatPow(X, 2).doit() == X**2 assert MatPow(X, -1).doit() == X.inv() assert MatPow(X, -2).doit() == (X.inv())**2 # less expensive than testing on a 2x2 assert MatPow(ImmutableMatrix([4]), Rational(1, 2)).doit() == ImmutableMatrix([2])
def test_as_explicit(): A = ImmutableMatrix([[1, 2], [3, 4]]) assert MatPow(A, 0).as_explicit() == ImmutableMatrix(Identity(2)) assert MatPow(A, 1).as_explicit() == A assert MatPow(A, 2).as_explicit() == A**2 assert MatPow(A, -1).as_explicit() == A.inv() assert MatPow(A, -2).as_explicit() == (A.inv())**2 # less expensive than testing on a 2x2 A = ImmutableMatrix([4]) assert MatPow(A, Rational(1, 2)).as_explicit() == A**Rational(1, 2)