def testAuto(self): test_data = [ # No conditions ("sqrt 2 >= 1"), ("~((1::real) = 2)"), ("(4::nat) > 2"), # Interval condition ("x Mem real_closed_interval 0 1 --> 1 - x ^ (2::nat) >= 0"), ("x Mem real_open_interval 0 1 --> 1 - x ^ (2::nat) > 0"), ("x Mem real_closed_interval 0 (sqrt 2) --> 2 - x ^ (2::nat) >= 0" ), ("x Mem real_closed_interval 0 (pi / 2) --> sqrt 2 * cos x >= 0"), ("x Mem real_closed_interval 0 (2 ^ (1 / 2)) --> 2 - x ^ (2::nat) >= 0" ), ] vars = {'x': 'real'} for expr in test_data: test_macro(self, 'interval_arith', 'auto', vars=vars, args=expr, res=expr)
def testRealContinuousOn(self): test_data = [ "real_continuous_on (%x. x) (real_closed_interval 0 1)", "real_continuous_on (%x. x * x) (real_closed_interval 0 1)", "real_continuous_on (%x. -x) (real_closed_interval 0 1)", "real_continuous_on (%x. x ^ (2::nat)) (real_closed_interval 0 1)", "real_continuous_on (%x. x ^ (3::nat)) (real_closed_interval 0 1)", "real_continuous_on (%x. (x + 1) ^ (3::nat)) (real_closed_interval 0 1)", "real_continuous_on (%x. exp x) (real_closed_interval 0 1)", "real_continuous_on (%x. exp (x ^ (2::nat))) (real_closed_interval 0 1)", "real_continuous_on (%x. exp (exp x)) (real_closed_interval 0 1)", "real_continuous_on (%x. sin x) (real_closed_interval 0 1)", "real_continuous_on (%x. cos x) (real_closed_interval 0 1)", "real_continuous_on (%x. sin x * cos x) (real_closed_interval 0 1)", "real_continuous_on (%x. sin (cos x)) (real_closed_interval 0 1)", "real_continuous_on (%x. 1 / x) (real_closed_interval 1 2)", "real_continuous_on (%x. 1 / (x ^ (2::nat))) (real_closed_interval 1 2)", "real_continuous_on (%x. 1 / (x ^ (2::nat))) (real_closed_interval (-2) (-1))", "real_continuous_on (%x. 1 / (x ^ (2::nat) + 1)) (real_closed_interval (-1) 1)", "real_continuous_on (%x. abs x) (real_closed_interval (-1) 1)", "real_continuous_on (%x. log x) (real_closed_interval (exp (-1)) (exp 1))", "real_continuous_on (%x. log (x ^ (2::nat) + 1)) (real_closed_interval (-1) 1)", "real_continuous_on (%x. sqrt x) (real_closed_interval 0 1)", "real_continuous_on (%x. sqrt (1 - x ^ (2::nat))) (real_closed_interval 0 1)", "real_continuous_on (%x. sqrt (2 - x ^ (2::nat))) (real_closed_interval 0 (sqrt 2))", "real_continuous_on (%x. x ^ (-(2::real))) (real_closed_interval 1 2)", "real_continuous_on (%x. (3 * x + 1) ^ (-(2::real))) (real_closed_interval 0 1)", "real_continuous_on (%x. x ^ (1 / 2)) (real_closed_interval 0 1)", "real_continuous_on (%x::real. 2 ^ x) (real_closed_interval 0 1)", "real_continuous_on (%x. (1 + -(x ^ (2::nat))) ^ -(1 / 2)) (real_open_interval (1 / 2 * 2 ^ (1 / 2)) 1)", ] for expr in test_data: test_macro(self, 'interval_arith', 'auto', args=expr, res=expr)
def testRealIntegrableOn(self): test_data = [ "real_integrable_on (%x. x) (real_closed_interval 0 1)", "real_integrable_on (%x. sqrt x) (real_closed_interval 0 1)", ] for expr in test_data: test_macro(self, 'interval_arith', 'auto', args=expr, res=expr)
def testNatLessMacro(self): test_data = [ (0, 1), (3, 5), ] for m, n in test_data: goal = "(%d::nat) < %d" % (m, n) test_macro(self, 'nat', 'nat_const_less', args=goal, res=goal)
def testNatLessEqMacro(self): test_data = [ (3, 5), (4, 4), ] for m, n in test_data: goal = "(%d::nat) <= %d" % (m, n) test_macro(self, 'nat', 'nat_const_less_eq', args=goal, res=goal)
def testRealNormMacroFailed(self): test_data = [ ("x * y * z = x * y + z"), ("1 + x + y = x + y + 2"), ] vars = {'x': 'real', 'y': 'real', 'z': 'real'} for expr in test_data: test_macro(self, 'real', 'real_norm', vars=vars, args=expr, failed=AssertionError, eval_only=True)
def testNatNormMacro(self): test_data = [ ("x * (y * z) = y * (z * x)"), ("Suc (Suc (Suc x)) + y = x + Suc (Suc (Suc y))"), ("x + y + (y + z) = y * 2 + (x + z)"), ] vars = {"x": 'nat', "y": 'nat', "z": 'nat'} for expr in test_data: test_macro(self, 'nat', 'nat_norm', vars=vars, args=expr, res=expr)
def testRealNormMacro(self): test_data = [ ("x * (y * z) = y * (z * x)"), ("-x = -1 * x"), ("x - y = x + -1 * y"), ] vars = {'x': 'real', 'y': 'real', 'z': 'real'} for expr in test_data: test_macro(self, 'real', 'real_norm', vars=vars, args=expr, res=expr, eval_only=True)
def testSolve(self): test_data = [("A --> B --> A & B"), ("A & B --> B & A"), ("A | B --> B | A"), ("A & B & C --> (A & B) & C"), ("A | B | C --> (A | B) | C")] vars = {'A': 'bool', 'B': 'bool'} for expr in test_data: test_macro(self, 'logic_base', 'auto', vars=vars, args=expr, res=expr)
def testRealIncreasing(self): test_data = [ "real_derivative (%x. x) x >= 0", "real_derivative (%x. 3 * x + 1) x >= 0", ] for expr in test_data: test_macro(self, 'interval_arith', 'auto', vars={'x': 'real'}, args=expr, res=expr)
def testIneq(self): test_data = [ ("x Mem real_open_interval 0 (pi / 2) --> sin x > 0"), ("x Mem real_open_interval 0 (pi / 2) --> exp(-x) + sin x > 0"), ("x Mem real_open_interval 0 (pi / 2) --> ~(exp(-x) + sin x = 0)"), ] for expr in test_data: test_macro(self, 'interval_arith', 'auto', vars={'x': 'real'}, args=expr, res=expr)
def testZ3MacroFail(self): if not z3wrapper.z3_loaded: return test_macro(self, 'logic_base', 'z3', vars={ 'P': 'bool', 'Q': 'bool' }, args='P --> Q', eval_only=True, failed=AssertionError)
def testRealContinuousOnFail(self): test_data = [ "real_continuous_on (%x. 1 / x) (real_closed_interval (-1) 1)", "real_continuous_on (%x. 1 / x) (real_closed_interval 0 1)", "real_continuous_on (%x. log x) (real_closed_interval 0 1)", "real_continuous_on (%x. sqrt x) (real_closed_interval (-1) 1)", "real_continuous_on (%x. sqrt (1 - x ^ (2::nat))) (real_closed_interval 0 (sqrt 2))", "real_continuous_on (%x. sqrt (2 - x ^ (2::nat))) (real_closed_interval 0 2)", ] for expr in test_data: test_macro(self, 'interval_arith', 'auto', args=expr, failed=TacticException)
def testZ3Macro(self): if not z3wrapper.z3_loaded: return test_macro( self, 'real', 'z3', vars={ 'S': 'real set', 'T': 'real set', 'x': 'real' }, assms=['S Int T = empty_set'], args= '(if x Mem S then (1::real) else 0) + (if x Mem T then 1 else 0) = (if x Mem (S Un T) then 1 else 0)', res= '(if x Mem S then (1::real) else 0) + (if x Mem T then 1 else 0) = (if x Mem (S Un T) then 1 else 0)', eval_only=True)
def testNatIneqMacro(self): test_data = [ (0, 1), (1, 0), (0, 2), (2, 0), (1, 2), (2, 1), (1, 3), (3, 1), (2, 3), (3, 2), (10, 13), (17, 19), (22, 24), ] for m, n in test_data: goal = "~(%d::nat) = %d" % (m, n) test_macro(self, 'nat', 'nat_const_ineq', args=goal, res=goal)
def testRealDifferentiable(self): test_data = [ "real_differentiable (%x. x) (atreal x)", "real_differentiable (%x. x * x) (atreal x)", "real_differentiable (%x. -x) (atreal x)", "real_differentiable (%x. x ^ (2::nat)) (atreal x)", "real_differentiable (%x. x ^ (3::nat)) (atreal x)", "real_differentiable (%x. (x + 1) ^ (3::nat)) (atreal x)", "real_differentiable (%x. exp x) (atreal x)", "real_differentiable (%x. exp (x ^ (2::nat))) (atreal x)", "real_differentiable (%x. exp (exp x)) (atreal x)", "real_differentiable (%x. sin x) (atreal x)", "real_differentiable (%x. cos x) (atreal x)", "real_differentiable (%x. sin x * cos x) (atreal x)", "real_differentiable (%x. sin (cos x)) (atreal x)", "x Mem real_open_interval 0 1 --> real_differentiable (%x. 1 / x) (atreal x)", "x Mem real_open_interval 0 1 --> real_differentiable (%x. 1 / (x ^ (2::nat))) (atreal x)", "x Mem real_open_interval (-1) 0 --> real_differentiable (%x. 1 / (x ^ (2::nat))) (atreal x)", "x Mem real_open_interval (-1) 1 --> real_differentiable (%x. 1 / (x ^ (2::nat) + 1)) (atreal x)", "x Mem real_open_interval 0 (exp 1) --> real_differentiable (%x. log x) (atreal x)", "x Mem real_open_interval (-1) 1 --> real_differentiable (%x. log (x ^ (2::nat) + 1)) (atreal x)", "x Mem real_open_interval 0 1 --> real_differentiable (%x. sqrt x) (atreal x)", "x Mem real_open_interval 0 1 --> real_differentiable (%x. sqrt (1 - x ^ (2::nat))) (atreal x)", "x Mem real_open_interval 0 (sqrt 2) --> real_differentiable (%x. sqrt (2 - x ^ (2::nat))) (atreal x)", "x Mem real_open_interval 0 1 --> real_differentiable (%x. x ^ (-(2::real))) (atreal x)", "x Mem real_open_interval 0 1 --> real_differentiable (%x. (3 * x + 1) ^ (-(2::real))) (atreal x)", "x Mem real_open_interval 0 1 --> real_differentiable (%x. x ^ (1 / 2)) (atreal x)", "x Mem real_open_interval (-1) 1 --> real_differentiable (%x::real. 2 ^ x) (atreal x)", ] for expr in test_data: test_macro(self, 'interval_arith', 'auto', vars={'x': 'real'}, args=expr, res=expr)