def test_not_equal(self): expr = ForAll(x, NotEqual(x, x + 1)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE) expr = ForAll(x, NotEqual(x, 2 * x)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, FALSE)
def test_equal(self): expr = Exists(x, qepcad.Equal(x, x + 1)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, FALSE) expr = Exists(x, qepcad.Equal(x, 2 * x)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE)
def test_implies(self): expr = ForAll(x, sp.Implies(x > 0, x >= 0)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE) expr = ForAll(x, sp.Implies(x > 0, x < 0)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, FALSE)
def test_less(self): expr = Exists(x, StrictLessThan(x + 1, x)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, FALSE) # Sympy simplifies simple expressions. Make it a bit # more complicated to test "<" expr = Exists(x, Exists(y, sp.And(x + 1 < y, sp.Eq(x, y)))) out = run_qepcad(expr, [], [x, y]) self.assertEqual(out, FALSE)
def test_for_all_but_finitely_many(self): expr = ForAllButFinitelyMany(x, ForAll(y, Exists(z, sp.Eq(y, z * x)))) out = run_qepcad(expr, [], [x, y, z]) self.assertEqual(out, TRUE) expr = ForAll(x, ForAll(y, Exists(z, sp.Eq(y, z * x)))) out = run_qepcad(expr, [], [x, y, z]) self.assertEqual(out, FALSE)
def test_for_infinitely_many(self): expr = ForInfinitelyMany(x, x >= 22) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE) expr = ForInfinitelyMany(x, sp.Eq(x, 22)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, FALSE) expr = Exists(x, sp.Eq(x, 22)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE)
def test_a_b_c(self): expr = Exists(x, sp.Eq(a * x**2 + b*x + c, 0)) out = run_qepcad(expr, [a, b, c], [x]) # We expect And(4*a*c - b**2 <= 0, Or(4*a*c - b**2 < 0, a != 0, c == 0)) self.assertTrue(out.subs(c, 0).subs(b, 1)) self.assertFalse(out.subs(b, 0).subs(a, 0).subs(c, 1))
def test_a_b(self): expr = Exists(x, sp.Eq(x**2 + a*x + b, 0)) out = run_qepcad(expr, [a, b], [x]) # We expect 4b - a^2 <= 0 self.assertFalse(out.subs(b,1).subs(a,1)) self.assertTrue(out.subs(b,1).subs(a,100)) self.assertTrue(out.subs(b,100).subs(a,100)) self.assertFalse(out.subs(b,100).subs(a,1))
def test_forall_does_not_exist(self): expr = ForAll(x, Exists(y, sp.Eq(x, y**2))) out = run_qepcad(expr, [], [x, y]) self.assertEqual(out, FALSE)
def test_forall_exists(self): expr = ForAll(x, Exists(y, sp.Eq(x, 2 * y))) out = run_qepcad(expr, [], [x, y]) self.assertEqual(out, TRUE)
def test_multiple_exists(self): expr = Exists(x, Exists(y, x >= 22)) out = run_qepcad(expr, [], [x, y]) self.assertEqual(out, TRUE)
def test_exists(self): expr = Exists(x, x >= 22) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE)
def test_forall(self): expr = ForAll(x, x >= 22) out = run_qepcad(expr, [], [x]) self.assertEqual(out, FALSE)
def test_equivalent(self): expr = ForAll(x, sp.Equivalent(x >= 0, x**3 >= 0)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE)
def test_and(self): expr = ForAll(x, sp.And(x >= 5, x < 1)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, FALSE)
def test_or(self): expr = ForAll(x, sp.Or(x >= 22, x < 22)) out = run_qepcad(expr, [], [x]) self.assertEqual(out, TRUE)