def test_cnf_conversion_complex(): lang, x, y = create_small_world_elements(2) s1 = exists(y, land(lang.Dodec(y), lang.BackOf(x, y))) s2 = land(lang.Cube(x), exists(y, land(lang.Tet(y), lang.LeftOf(x, y)))) phi = forall(x, implies(s2, s1)) result = remove_quantifiers(lang, phi, QuantifierEliminationMode.All) assert len(to_conjunctive_normal_form_clauses(lang, result)) == 30 # Now remove the quantifiers after tranforming to PNNF result = remove_quantifiers(lang, to_prenex_negation_normal_form(lang, phi), QuantifierEliminationMode.All) assert len(to_conjunctive_normal_form_clauses(lang, result)) == 126
def test_existential_elimination2(): lang, x, y = create_small_world_elements(2) s1 = exists(y, land(lang.Dodec(y), lang.BackOf(x, y))) s2 = land(lang.Cube(x), exists(y, land(lang.Tet(y), lang.LeftOf(x, y)))) phi = forall(x, implies(s2, s1)) result = remove_quantifiers(lang, phi, QuantifierEliminationMode.All) assert is_quantifier_free(result)
def test_universal_elimination_works(): tw = tarskiworld.create_small_world() x = tw.variable('x', tw.Object) y = tw.variable('y', tw.Object) _ = tw.constant('obj1', tw.Object) _ = tw.constant('obj2', tw.Object) _ = tw.constant('obj3', tw.Object) s1 = exists(y, land(tw.Dodec(y), tw.BackOf(x, y))) s2 = land(tw.Cube(x), exists(y, land(tw.Tet(y), tw.LeftOf(x, y)))) phi = forall(x, implies(s2, s1)) # print(str(phi)) result = remove_quantifiers(tw, phi, QuantifierEliminationMode.Forall) result2 = remove_quantifiers(tw, result, QuantifierEliminationMode.Forall) assert str(result) == str(result2)
def fully_ground(smtlang, f, horizon): phi = remove_quantifiers(smtlang, f, QuantifierEliminationMode.All) phi = Simplify().simplify_expression(phi) if phi is False: raise RuntimeError( f'Formula {phi} simplified to False, hence the theory is not satisfiable' ) return phi
def test_cnf_conversion_complex(): lang, x, y = create_small_world_elements(2) s1 = exists(y, land(lang.Dodec(y), lang.BackOf(x, y))) s2 = land(lang.Cube(x), exists(y, land(lang.Tet(y), lang.LeftOf(x, y)))) phi = forall(x, implies(s2, s1)) result = remove_quantifiers(lang, phi, QuantifierEliminationMode.All) transf = CNFTransformation.rewrite(lang, result) # print(transf.cnf) # print('\n'.join([','.join([str(l) for l in c]) for c in transf.clauses])) assert len(transf.clauses) == 30 # Now remove the quantifiers after tranforming to PNNF result = remove_quantifiers(lang, to_prenex_negation_normal_form(lang, phi), QuantifierEliminationMode.All) transf = CNFTransformation.rewrite(lang, result) assert len(transf.clauses) == 126
def test_existential_elimination1(): lang, x, y = create_small_world_elements(2) obj1, obj2 = lang.get("obj1"), lang.get("obj2") phi = exists(y, land(lang.Dodec(y), lang.BackOf(x, y))) result = remove_quantifiers(lang, phi, QuantifierEliminationMode.Exists) # We cannot guarantee in which order the expansion of the exists will be done, so we check for both possibilities: assert result == (lang.Dodec(obj1) & lang.BackOf(x, obj1)) | (lang.Dodec(obj2) & lang.BackOf(x, obj2)) or \ result == (lang.Dodec(obj2) & lang.BackOf(x, obj2)) | (lang.Dodec(obj1) & lang.BackOf(x, obj1))