Example #1
0
def test_invertible_BlockMatrix():
    assert ask(Q.invertible(BlockMatrix([Identity(3)]))) == True
    assert ask(Q.invertible(BlockMatrix([ZeroMatrix(3, 3)]))) == False

    X = Matrix([[1, 2, 3], [3, 5, 4]])
    Y = Matrix([[4, 2, 7], [2, 3, 5]])
    # non-invertible A block
    assert ask(
        Q.invertible(
            BlockMatrix([
                [Matrix.ones(3, 3), Y.T],
                [X, Matrix.eye(2)],
            ]))) == True
    # non-invertible B block
    assert ask(
        Q.invertible(
            BlockMatrix([
                [Y.T, Matrix.ones(3, 3)],
                [Matrix.eye(2), X],
            ]))) == True
    # non-invertible C block
    assert ask(
        Q.invertible(
            BlockMatrix([
                [X, Matrix.eye(2)],
                [Matrix.ones(3, 3), Y.T],
            ]))) == True
    # non-invertible D block
    assert ask(
        Q.invertible(
            BlockMatrix([
                [Matrix.eye(2), X],
                [Y.T, Matrix.ones(3, 3)],
            ]))) == True
Example #2
0
def test_TensorProduct_construction():
    assert TensorProduct(3, 4) == 12
    assert isinstance(TensorProduct(A, A), TensorProduct)

    expr = TensorProduct(TensorProduct(x, y), z)
    assert expr == x * y * z

    expr = TensorProduct(TensorProduct(A, B), C)
    assert expr == TensorProduct(A, B, C)

    expr = TensorProduct(Matrix.eye(2), [[0, -1], [1, 0]])
    assert expr == Array([[[[0, -1], [1, 0]], [[0, 0], [0, 0]]],
                          [[[0, 0], [0, 0]], [[0, -1], [1, 0]]]])
Example #3
0
def test_TensorProduct_shape():

    expr = TensorProduct(3, 4, evaluate=False)
    assert expr.shape == ()
    assert expr.rank() == 0

    expr = TensorProduct(Array([1, 2]), Array([x, y]), evaluate=False)
    assert expr.shape == (2, 2)
    assert expr.rank() == 2
    expr = TensorProduct(expr, expr, evaluate=False)
    assert expr.shape == (2, 2, 2, 2)
    assert expr.rank() == 4

    expr = TensorProduct(Matrix.eye(2), Array([[0, -1], [1, 0]]), evaluate=False)
    assert expr.shape == (2, 2, 2, 2)
    assert expr.rank() == 4
Example #4
0
def test_issue_2827_trigsimp_methods():
    measure1 = lambda expr: len(str(expr))
    measure2 = lambda expr: -count_ops(expr)
    # Return the most complicated result
    expr = (x + 1) / (x + sin(x)**2 + cos(x)**2)
    ans = Matrix([1])
    M = Matrix([expr])
    assert trigsimp(M, method='fu', measure=measure1) == ans
    assert trigsimp(M, method='fu', measure=measure2) != ans
    # all methods should work with Basic expressions even if they
    # aren't Expr
    M = Matrix.eye(1)
    assert all(
        trigsimp(M, method=m) == M for m in 'fu matching groebner old'.split())
    # watch for E in exptrigsimp, not only exp()
    eq = 1 / sqrt(E) + E
    assert exptrigsimp(eq) == eq