def test_assuming_nested(): assert not ask(Q.integer(x)) assert not ask(Q.integer(y)) with assuming(Q.integer(x)): assert ask(Q.integer(x)) assert not ask(Q.integer(y)) with assuming(Q.integer(y)): assert ask(Q.integer(x)) assert ask(Q.integer(y)) assert ask(Q.integer(x)) assert not ask(Q.integer(y)) assert not ask(Q.integer(x)) assert not ask(Q.integer(y))
def test_assuming_nested(): assert not ask(Q.integer(x)) assert not ask(Q.integer(y)) with assuming(Q.integer(x)): assert ask(Q.integer(x)) assert not ask(Q.integer(y)) with assuming(Q.integer(y)): assert ask(Q.integer(x)) assert ask(Q.integer(y)) assert ask(Q.integer(x)) assert not ask(Q.integer(y)) assert not ask(Q.integer(x)) assert not ask(Q.integer(y))
def test_finally(): try: with assuming(Q.integer(x)): 1 / 0 except ZeroDivisionError: pass assert not ask(Q.integer(x))
def test_finally(): try: with assuming(Q.integer(x)): 1/0 except ZeroDivisionError: pass assert not ask(Q.integer(x))
def test_remove_safe(): global_assumptions.add(Q.integer(x)) with assuming(): assert ask(Q.integer(x)) global_assumptions.remove(Q.integer(x)) assert not ask(Q.integer(x)) assert ask(Q.integer(x)) global_assumptions.clear() # for the benefit of other tests
def test_remove_safe(): global_assumptions.add(Q.integer(x)) with assuming(): assert ask(Q.integer(x)) global_assumptions.remove(Q.integer(x)) assert not ask(Q.integer(x)) assert ask(Q.integer(x)) global_assumptions.clear() # for the benefit of other tests
def test_BlockMatrix_Determinant(): A, B, C, D = [MatrixSymbol(s, 3, 3) for s in 'ABCD'] X = BlockMatrix([[A, B], [C, D]]) from sympy.assumptions.ask import Q from sympy.assumptions.assume import assuming with assuming(Q.invertible(A)): assert det(X) == det(A) * det(X.schur('A')) assert isinstance(det(X), Expr) assert det(BlockMatrix([A])) == det(A) assert det(BlockMatrix([ZeroMatrix(n, n)])) == 0
def test_satask(): # No relevant facts assert satask(Q.real(x), Q.real(x)) is True assert satask(Q.real(x), ~Q.real(x)) is False assert satask(Q.real(x)) is None assert satask(Q.real(x), Q.positive(x)) is True assert satask(Q.positive(x), Q.real(x)) is None assert satask(Q.real(x), ~Q.positive(x)) is None assert satask(Q.positive(x), ~Q.real(x)) is False raises(ValueError, lambda: satask(Q.real(x), Q.real(x) & ~Q.real(x))) with assuming(Q.positive(x)): assert satask(Q.real(x)) is True assert satask(~Q.positive(x)) is False raises(ValueError, lambda: satask(Q.real(x), ~Q.positive(x))) assert satask(Q.zero(x), Q.nonzero(x)) is False assert satask(Q.positive(x), Q.zero(x)) is False assert satask(Q.real(x), Q.zero(x)) is True assert satask(Q.zero(x), Q.zero(x*y)) is None assert satask(Q.zero(x*y), Q.zero(x))
def test_assuming(): with assuming(Q.integer(x)): assert ask(Q.integer(x)) assert not ask(Q.integer(x))
def test_assuming(): with assuming(Q.integer(x)): assert ask(Q.integer(x)) assert not ask(Q.integer(x))