def test_reduce_piecewise_inequalities(): e = abs(x - 5) < 3 ans = And(Lt(2, x), Lt(x, 8)) assert reduce_inequalities(e) == ans assert reduce_inequalities(e, x) == ans assert reduce_inequalities(abs(x - 5)) == Eq(x, 5) assert reduce_inequalities( abs(2*x + 3) >= 8) == Or(And(Le(Rational(5, 2), x), Lt(x, oo)), And(Le(x, -Rational(11, 2)), Lt(-oo, x))) assert reduce_inequalities(abs(x - 4) + abs( 3*x - 5) < 7) == And(Lt(Rational(1, 2), x), Lt(x, 4)) assert reduce_inequalities(abs(x - 4) + abs(3*abs(x) - 5) < 7) == \ Or(And(Integer(-2) < x, x < -1), And(Rational(1, 2) < x, x < 4)) nr = Symbol('nr', extended_real=False) pytest.raises(TypeError, lambda: reduce_inequalities(abs(nr - 5) < 3)) # sympy/sympy#10198 assert reduce_inequalities(-1 + 1/abs(1/x - 1) < 0) == \ Or(And(S.Zero < x, x < S.Half), And(-oo < x, x < S.Zero)) # sympy/sympy#10255 assert reduce_inequalities(Piecewise((1, x < 1), (3, True)) > 1) == \ And(S.One <= x, x < oo) assert reduce_inequalities(Piecewise((x**2, x < 0), (2*x, x >= 0)) < 1) == \ And(-S.One < x, x < S.Half)
def test_deltaproduct_mul_add_x_y_add_y_kd(): assert dp((x + y)*(y + Kd(i, j)), (j, 1, 3)) == ((x + y)*y)**3 + \ (x + y)*((x + y)*y)**2*Kd(i, 1) + \ (x + y)*y*(x + y)**2*y*Kd(i, 2) + \ ((x + y)*y)**2*(x + y)*Kd(i, 3) assert dp((x + y) * (y + Kd(i, j)), (j, 1, 1)) == (x + y) * (y + Kd(i, 1)) assert dp((x + y) * (y + Kd(i, j)), (j, 2, 2)) == (x + y) * (y + Kd(i, 2)) assert dp((x + y) * (y + Kd(i, j)), (j, 3, 3)) == (x + y) * (y + Kd(i, 3)) assert dp((x + y)*(y + Kd(i, j)), (j, 1, k)) == \ ((x + y)*y)**k + Piecewise( (((x + y)*y)**(i - 1)*(x + y)*((x + y)*y)**(k - i), And(Integer(1) <= i, i <= k)), (0, True) ) assert dp((x + y)*(y + Kd(i, j)), (j, k, 3)) == \ ((x + y)*y)**(-k + 4) + Piecewise( (((x + y)*y)**(i - k)*(x + y)*((x + y)*y)**(3 - i), And(k <= i, i <= 3)), (0, True) ) assert dp((x + y)*(y + Kd(i, j)), (j, k, l)) == \ ((x + y)*y)**(-k + l + 1) + Piecewise( (((x + y)*y)**(i - k)*(x + y)*((x + y)*y)**(l - i), And(k <= i, i <= l)), (0, True) )
def test_Sum_doit(): f = Function('f') assert Sum(n * Integral(a**2), (n, 0, 2)).doit() == a**3 assert Sum(n*Integral(a**2), (n, 0, 2)).doit(deep=False) == \ 3*Integral(a**2) assert summation(n * Integral(a**2), (n, 0, 2)) == 3 * Integral(a**2) # test nested sum evaluation s = Sum(Sum(Sum(2, (z, 1, n + 1)), (y, x + 1, n)), (x, 1, n)) assert 0 == (s.doit() - n * (n + 1) * (n - 1)).factor() assert Sum(Sum(KroneckerDelta(m, n), (m, 1, 3)), (n, 1, 3)).doit() == 3 assert Sum(Sum(KroneckerDelta(k, m), (m, 1, 3)), (n, 1, 3)).doit() == \ 3*Piecewise((1, And(Integer(1) <= k, k <= 3)), (0, True)) assert Sum(f(n)*Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, 3)).doit() == \ f(1) + f(2) + f(3) assert Sum(f(n)*Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, oo)).doit() == \ Sum(Piecewise((f(n), And(Le(0, n), n < oo)), (0, True)), (n, 1, oo)) l = Symbol('l', integer=True, positive=True) assert Sum(f(l)*Sum(KroneckerDelta(m, l), (m, 0, oo)), (l, 1, oo)).doit() == \ Sum(f(l), (l, 1, oo)) # issue sympy/sympy#2597 nmax = symbols('N', integer=True, positive=True) pw = Piecewise((1, And(Integer(1) <= n, n <= nmax)), (0, True)) assert Sum(pw, (n, 1, nmax)).doit() == Sum(pw, (n, 1, nmax))
def test_interval_arguments(): assert Interval(0, oo).right_open is false assert Interval(-oo, 0).left_open is false assert Interval(oo, -oo) == S.EmptySet assert isinstance(Interval(1, 1), FiniteSet) e = Sum(x, (x, 1, 3)) assert isinstance(Interval(e, e), FiniteSet) assert Interval(1, 0) == S.EmptySet assert Interval(1, 1).measure == 0 assert Interval(1, 1, False, True) == S.EmptySet assert Interval(1, 1, True, False) == S.EmptySet assert Interval(1, 1, True, True) == S.EmptySet assert isinstance(Interval(0, Symbol('a')), Interval) assert Interval(Symbol('a', extended_real=True, positive=True), 0) == S.EmptySet pytest.raises(ValueError, lambda: Interval(0, I)) pytest.raises(ValueError, lambda: Interval(0, Symbol('z', extended_real=False))) pytest.raises(NotImplementedError, lambda: Interval(0, 1, And(x, y))) pytest.raises(NotImplementedError, lambda: Interval(0, 1, False, And(x, y))) pytest.raises(NotImplementedError, lambda: Interval(0, 1, z, And(x, y)))
def test_domains(): X, Y = Die('x', 6), Die('y', 6) x, y = X.symbol, Y.symbol # Domains d = where(X > Y) assert d.condition == (x > y) d = where(And(X > Y, Y > 3)) assert d.as_boolean() == Or(And(Eq(x, 5), Eq(y, 4)), And(Eq(x, 6), Eq(y, 5)), And(Eq(x, 6), Eq(y, 4))) assert len(d.elements) == 3 assert len(pspace(X + Y).domain.elements) == 36 Z = Die('x', 4) pytest.raises(ValueError, lambda: P(X > Z)) # Two domains with same internal symbol assert pspace(X + Y).domain.set == FiniteSet(1, 2, 3, 4, 5, 6)**2 assert where(X > 3).set == FiniteSet(4, 5, 6) assert X.pspace.domain.dict == FiniteSet( *[Dict({X.symbol: i}) for i in range(1, 7)]) assert where(X > Y).dict == FiniteSet(*[ Dict({ X.symbol: i, Y.symbol: j }) for i in range(1, 7) for j in range(1, 7) if i > j ])
def test_equals(): assert Not(Or(A, B)).equals( And(Not(A), Not(B)) ) is True assert Equivalent(A, B).equals((A >> B) & (B >> A)) is True assert ((A | ~B) & (~A | B)).equals((~A & ~B) | (A & B)) is True assert (A >> B).equals(~A >> ~B) is False assert (A >> (B >> A)).equals(A >> (C >> A)) is False pytest.raises(NotImplementedError, lambda: And(A, A < B).equals(And(A, B > A)))
def test_deltaproduct_mul_add_x_kd_add_y_kd(): assert dp((x + Kd(i, k))*(y + Kd(i, j)), (j, 1, 3)) == \ Kd(i, 1)*(Kd(i, k) + x)*((Kd(i, k) + x)*y)**2 + \ Kd(i, 2)*(Kd(i, k) + x)*y*(Kd(i, k) + x)**2*y + \ Kd(i, 3)*((Kd(i, k) + x)*y)**2*(Kd(i, k) + x) + \ ((Kd(i, k) + x)*y)**3 assert dp((x + Kd(i, k))*(y + Kd(i, j)), (j, 1, 1)) == \ (x + Kd(i, k))*(y + Kd(i, 1)) assert dp((x + Kd(i, k))*(y + Kd(i, j)), (j, 2, 2)) == \ (x + Kd(i, k))*(y + Kd(i, 2)) assert dp((x + Kd(i, k))*(y + Kd(i, j)), (j, 3, 3)) == \ (x + Kd(i, k))*(y + Kd(i, 3)) assert dp((x + Kd(i, k))*(y + Kd(i, j)), (j, 1, k)) == \ ((x + Kd(i, k))*y)**k + Piecewise( (((x + Kd(i, k))*y)**(i - 1)*(x + Kd(i, k)) * ((x + Kd(i, k))*y)**(-i + k), And(Integer(1) <= i, i <= k)), (0, True) ) assert dp((x + Kd(i, k))*(y + Kd(i, j)), (j, k, 3)) == \ ((x + Kd(i, k))*y)**(4 - k) + Piecewise( (((x + Kd(i, k))*y)**(i - k)*(x + Kd(i, k)) * ((x + Kd(i, k))*y)**(-i + 3), And(k <= i, i <= 3)), (0, True) ) assert dp((x + Kd(i, k))*(y + Kd(i, j)), (j, k, l)) == \ ((x + Kd(i, k))*y)**(-k + l + 1) + Piecewise( (((x + Kd(i, k))*y)**(i - k)*(x + Kd(i, k)) * ((x + Kd(i, k))*y)**(-i + l), And(k <= i, i <= l)), (0, True) )
def test_bool_symbol(): assert And(a, True) == a assert And(a, True, True) == a assert And(a, False) is false assert And(a, True, False) is false assert Or(a, True) is true assert Or(a, False) == a
def test_bool_symbol(): """Test that mixing symbols with boolean values works as expected.""" assert And(A, True) == A assert And(A, True, True) == A assert And(A, False) is false assert And(A, True, False) is false assert Or(A, True) is true assert Or(A, False) == A
def test_overloading(): """Test that |, & are overloaded as expected.""" assert A & B == And(A, B) assert A | B == Or(A, B) assert (A & B) | C == Or(And(A, B), C) assert A >> B == Implies(A, B) assert A << B == Implies(B, A) assert ~A == Not(A) assert A ^ B == Xor(A, B)
def test_bool_as_set(): assert And(x <= 2, x >= -2).as_set() == Interval(-2, 2) assert Or(x >= 2, x <= -2).as_set() == (Interval(-oo, -2, True) + Interval(2, oo, False, True)) assert Not(x > 2, evaluate=False).as_set() == Interval(-oo, 2, True) # issue sympy/sympy#10240 assert Not(And(x > 2, x < 3)).as_set() == \ Union(Interval(-oo, 2, True), Interval(3, oo, False, True)) assert true.as_set() == S.UniversalSet assert false.as_set() == EmptySet()
def test_Interval_as_relational(): x = Symbol('x') assert Interval(-1, 2, False, False).as_relational(x) == \ And(Le(-1, x), Le(x, 2)) assert Interval(-1, 2, True, False).as_relational(x) == \ And(Lt(-1, x), Le(x, 2)) assert Interval(-1, 2, False, True).as_relational(x) == \ And(Le(-1, x), Lt(x, 2)) assert Interval(-1, 2, True, True).as_relational(x) == \ And(Lt(-1, x), Lt(x, 2)) assert Interval(-oo, 2, right_open=False).as_relational(x) == And( Le(-oo, x), Le(x, 2)) assert Interval(-oo, 2, right_open=True).as_relational(x) == And( Le(-oo, x), Lt(x, 2)) assert Interval(-2, oo, left_open=False).as_relational(x) == And( Le(-2, x), Le(x, oo)) assert Interval(-2, oo, left_open=True).as_relational(x) == And( Lt(-2, x), Le(x, oo)) assert Interval(-oo, oo).as_relational(x) == And(Le(-oo, x), Le(x, oo)) x = Symbol('x', extended_real=True) y = Symbol('y', extended_real=True) assert Interval(x, y).as_relational(x) == (x <= y) assert Interval(y, x).as_relational(x) == (y <= x)
def test_sympyissue_10925(): try: name = 'test' tmp_file = TmpFileManager.tmp_file f = Piecewise((-1, x < -1), (x, And(-1 <= x, x < 0)), (x**2, And(0 <= x, x < 1)), (x**3, True)) p = plot(f, (x, -3, 3)) p.save(tmp_file('%s_10925' % name)) finally: TmpFileManager.cleanup()
def test_triangular(): a = Symbol('a') b = Symbol('b') c = Symbol('c') X = Triangular('x', a, b, c) assert density(X)(x) == Piecewise( ((2*x - 2*a)/((-a + b)*(-a + c)), And(a <= x, x < c)), (2/(-a + b), Eq(x, c)), ((-2*x + 2*b)/((-a + b)*(b - c)), And(x <= b, c < x)), (0, True))
def test_triangular(): a = Symbol("a") b = Symbol("b") c = Symbol("c") X = Triangular('x', a, b, c) assert density(X)(x) == Piecewise( ((2 * x - 2 * a) / ((-a + b) * (-a + c)), And(a <= x, x < c)), (2 / (-a + b), x == c), ((-2 * x + 2 * b) / ((-a + b) * (b - c)), And(x <= b, c < x)), (0, True))
def test_deltasummation_mul_x_kd(): assert ds(x*Kd(i, j), (j, 1, 3)) == \ Piecewise((x, And(Integer(1) <= i, i <= 3)), (0, True)) assert ds(x * Kd(i, j), (j, 1, 1)) == Piecewise((x, Eq(i, 1)), (0, True)) assert ds(x * Kd(i, j), (j, 2, 2)) == Piecewise((x, Eq(i, 2)), (0, True)) assert ds(x * Kd(i, j), (j, 3, 3)) == Piecewise((x, Eq(i, 3)), (0, True)) assert ds(x*Kd(i, j), (j, 1, k)) == \ Piecewise((x, And(Integer(1) <= i, i <= k)), (0, True)) assert ds(x*Kd(i, j), (j, k, 3)) == \ Piecewise((x, And(k <= i, i <= 3)), (0, True)) assert ds(x*Kd(i, j), (j, k, l)) == \ Piecewise((x, And(k <= i, i <= l)), (0, True))
def test_sympyissue_4527(): k, m = symbols('k m', integer=True) assert integrate(sin(k * x) * sin(m * x), (x, 0, pi)) == Piecewise( (0, And(Eq(k, 0), Eq(m, 0))), (-pi / 2, Eq(k, -m)), (pi / 2, Eq(k, m)), (0, True)) assert integrate(sin(k * x) * sin(m * x), (x, )) == Piecewise( (0, And(Eq(k, 0), Eq(m, 0))), (-x * sin(m * x)**2 / 2 - x * cos(m * x)**2 / 2 + sin(m * x) * cos(m * x) / (2 * m), Eq(k, -m)), (x * sin(m * x)**2 / 2 + x * cos(m * x)**2 / 2 - sin(m * x) * cos(m * x) / (2 * m), Eq(k, m)), (m * sin(k * x) * cos(m * x) / (k**2 - m**2) - k * sin(m * x) * cos(k * x) / (k**2 - m**2), True))
def test_to_cnf(): assert to_cnf(~(B | C)) == And(Not(B), Not(C)) assert to_cnf((A & B) | C) == And(Or(A, C), Or(B, C)) assert to_cnf(A >> B) == (~A) | B assert to_cnf(A >> (B & C)) == (~A | B) & (~A | C) assert to_cnf(A & (B | C) | ~A & (B | C), True) == B | C assert to_cnf(Equivalent(A, B)) == And(Or(A, Not(B)), Or(B, Not(A))) assert to_cnf(Equivalent(A, B & C)) == \ (~A | B) & (~A | C) & (~B | ~C | A) assert to_cnf(Equivalent(A, B | C), True) == \ And(Or(Not(B), A), Or(Not(C), A), Or(B, C, Not(A))) assert to_cnf(~(A | B) | C) == And(Or(Not(A), C), Or(Not(B), C))
def convergence_statement(self): """ Return a condition on z under which the series converges. """ from diofant import And, Or, re, Ne, oo R = self.radius_of_convergence if R == 0: return False if R == oo: return True # The special functions and their approximations, page 44 e = self.eta z = self.argument c1 = And(re(e) < 0, abs(z) <= 1) c2 = And(0 <= re(e), re(e) < 1, abs(z) <= 1, Ne(z, 1)) c3 = And(re(e) >= 1, abs(z) < 1) return Or(c1, c2, c3)
def test_issue_7173(): assert laplace_transform(sinh(a*x)*cosh(a*x), x, s) == \ (a/(s**2 - 4*a**2), 0, And(Or(Abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) < pi/2, Abs(periodic_argument(exp_polar(I*pi)*polar_lift(a), oo)) <= pi/2), Or(Abs(periodic_argument(a, oo)) < pi/2, Abs(periodic_argument(a, oo)) <= pi/2)))
def test_union_contains(): i1 = Interval(0, 1) i2 = Interval(2, 3) i3 = Union(i1, i2) pytest.raises(TypeError, lambda: x in i3) e = i3.contains(x) assert e == Or(And(0 <= x, x <= 1), And(2 <= x, x <= 3)) assert e.subs(x, -0.5) is false assert e.subs(x, 0.5) is true assert e.subs(x, 1.5) is false assert e.subs(x, 2.5) is true assert e.subs(x, 3.5) is false U = Interval(0, 2, True, True) + Interval(10, oo) + FiniteSet(-1, 2, 5, 6) assert all(el not in U for el in [0, 4, -oo]) assert all(el in U for el in [2, 5, 10])
def test_messy(): assert laplace_transform(Si(x), x, s) == ((-atan(s) + pi / 2) / s, 0, True) assert laplace_transform(Shi(x), x, s) == (acoth(s) / s, 1, True) # where should the logs be simplified? assert laplace_transform(Chi(x), x, s) == \ ((log(s**(-2)) - log((s**2 - 1)/s**2))/(2*s), 1, True) # TODO maybe simplify the inequalities? assert laplace_transform(besselj(a, x), x, s)[1:] == \ (0, And(Integer(0) < re(a/2) + Rational(1, 2), Integer(0) < re(a/2) + 1)) # NOTE s < 0 can be done, but argument reduction is not good enough yet assert fourier_transform(besselj(1, x)/x, x, s, noconds=False) == \ (Piecewise((0, 4*abs(pi**2*s**2) > 1), (2*sqrt(-4*pi**2*s**2 + 1), True)), s > 0) # TODO FT(besselj(0,x)) - conditions are messy (but for acceptable reasons) # - folding could be better assert integrate(E1(x)*besselj(0, x), (x, 0, oo), meijerg=True) == \ log(1 + sqrt(2)) assert integrate(E1(x)*besselj(1, x), (x, 0, oo), meijerg=True) == \ log(Rational(1, 2) + sqrt(2)/2) assert integrate(1/x/sqrt(1 - x**2), x, meijerg=True) == \ Piecewise((-acosh(1/x), 1 < abs(x**(-2))), (I*asin(1/x), True))
def test_to_nnf(): assert to_nnf(true) is true assert to_nnf(false) is false assert to_nnf(A) == A assert (~A).to_nnf() == ~A class Boo(BooleanFunction): pass pytest.raises(ValueError, lambda: to_nnf(~Boo(A))) assert to_nnf(A | ~A | B) is true assert to_nnf(A & ~A & B) is false assert to_nnf(A >> B) == ~A | B assert to_nnf(Equivalent(A, B, C)) == (~A | B) & (~B | C) & (~C | A) assert to_nnf(A ^ B ^ C) == \ (A | B | C) & (~A | ~B | C) & (A | ~B | ~C) & (~A | B | ~C) assert to_nnf(ITE(A, B, C)) == (~A | B) & (A | C) assert to_nnf(Not(A | B | C)) == ~A & ~B & ~C assert to_nnf(Not(A & B & C)) == ~A | ~B | ~C assert to_nnf(Not(A >> B)) == A & ~B assert to_nnf(Not(Equivalent(A, B, C))) == And(Or(A, B, C), Or(~A, ~B, ~C)) assert to_nnf(Not(A ^ B ^ C)) == \ (~A | B | C) & (A | ~B | C) & (A | B | ~C) & (~A | ~B | ~C) assert to_nnf(Not(ITE(A, B, C))) == (~A | ~B) & (A | ~C) assert to_nnf((A >> B) ^ (B >> A)) == (A & ~B) | (~A & B) assert to_nnf((A >> B) ^ (B >> A), False) == \ (~A | ~B | A | B) & ((A & ~B) | (~A & B))
def test_deltasummation_mul_x_add_y_kd(): assert ds(x*(y + Kd(i, j)), (j, 1, 3)) == \ Piecewise((3*x*y + x, And(Integer(1) <= i, i <= 3)), (3*x*y, True)) assert ds(x*(y + Kd(i, j)), (j, 1, 1)) == \ Piecewise((x*y + x, Eq(i, 1)), (x*y, True)) assert ds(x*(y + Kd(i, j)), (j, 2, 2)) == \ Piecewise((x*y + x, Eq(i, 2)), (x*y, True)) assert ds(x*(y + Kd(i, j)), (j, 3, 3)) == \ Piecewise((x*y + x, Eq(i, 3)), (x*y, True)) assert ds(x*(y + Kd(i, j)), (j, 1, k)) == \ Piecewise((k*x*y + x, And(Integer(1) <= i, i <= k)), (k*x*y, True)) assert ds(x*(y + Kd(i, j)), (j, k, 3)) == \ Piecewise(((4 - k)*x*y + x, And(k <= i, i <= 3)), ((4 - k)*x*y, True)) assert ds(x * (y + Kd(i, j)), (j, k, l)) == Piecewise( ((l - k + 1) * x * y + x, And(k <= i, i <= l)), ((l - k + 1) * x * y, True))
def test_quadratic_u(): a = Symbol('a', extended_real=True) b = Symbol('b', extended_real=True) X = QuadraticU('x', a, b) assert density(X)(x) == (Piecewise((12*(x - a/2 - b/2)**2/(-a + b)**3, And(x <= b, a <= x)), (0, True))) assert X.pspace.domain.set == Interval(a, b)
def test_quadratic_u(): a = Symbol("a", extended_real=True) b = Symbol("b", extended_real=True) X = QuadraticU("x", a, b) assert density(X)(x) == (Piecewise( (12 * (x - a / 2 - b / 2)**2 / (-a + b)**3, And(x <= b, a <= x)), (0, True)))
def test_raised_cosine(): mu = Symbol('mu', extended_real=True) s = Symbol('s', positive=True) X = RaisedCosine('x', mu, s) assert density(X)(x) == (Piecewise(((cos(pi*(x - mu)/s) + 1)/(2*s), And(x <= mu + s, mu - s <= x)), (0, True))) assert X.pspace.domain.set == Interval(mu - s, mu + s)
def test_sympyissue_8368(): assert integrate(exp(-s*x)*cosh(x), (x, 0, oo)) == \ Piecewise((pi*Piecewise((-s/(pi*(-s**2 + 1)), Abs(s**2) < 1), (1/(pi*s*(1 - 1/s**2)), Abs(s**(-2)) < 1), (meijerg(((Rational(1, 2),), (0, 0)), ((0, Rational(1, 2)), (0,)), polar_lift(s)**2), True)), And(Abs(periodic_argument(polar_lift(s)**2, oo)) < pi, Ne(s**2, 1), cos(Abs(periodic_argument(polar_lift(s)**2, oo))/2)*sqrt(Abs(s**2)) - 1 > 0)), (Integral(exp(-s*x)*cosh(x), (x, 0, oo)), True)) assert integrate(exp(-s*x)*sinh(x), (x, 0, oo)) == \ Piecewise((pi*Piecewise((2/(pi*(2*s**2 - 2)), Abs(s**2) < 1), (-2/(pi*s**2*(-2 + 2/s**2)), Abs(s**(-2)) < 1), (meijerg(((0,), (Rational(-1, 2), Rational(1, 2))), ((0, Rational(1, 2)), (Rational(-1, 2),)), polar_lift(s)**2), True)), And(Abs(periodic_argument(polar_lift(s)**2, oo)) < pi, Ne(s**2, 1), cos(Abs(periodic_argument(polar_lift(s)**2, oo))/2)*sqrt(Abs(s**2)) - 1 > 0)), (Integral(E**(-s*x)*sinh(x), (x, 0, oo)), True))
def test_basic(): assert lambdarepr(x * y) == "x*y" assert lambdarepr(x + y) in ["y + x", "x + y"] assert lambdarepr(x**y) == "x**y" assert lambdarepr(And(x, y)) == "((x) and (y))" assert lambdarepr(Or(x, y)) == "((x) or (y))" assert lambdarepr(Not(x)) == "(not (x))" assert lambdarepr(false) == "False"
def test_satisfiable_non_symbols(): class Zero(Boolean): pass assumptions = Zero(x*y) facts = Implies(Zero(x*y), Zero(x) | Zero(y)) query = ~Zero(x) & ~Zero(y) refutations = [ {Zero(x): True, Zero(x*y): True}, {Zero(y): True, Zero(x*y): True}, {Zero(x): True, Zero(y): True, Zero(x*y): True}, {Zero(x): True, Zero(y): False, Zero(x*y): True}, {Zero(x): False, Zero(y): True, Zero(x*y): True}] assert not satisfiable(And(assumptions, facts, query), algorithm='dpll') assert satisfiable(And(assumptions, facts, ~query), algorithm='dpll') in refutations assert not satisfiable(And(assumptions, facts, query), algorithm='dpll2') assert satisfiable(And(assumptions, facts, ~query), algorithm='dpll2') in refutations