Esempio n. 1
0
    def test_problems_1(self):
        inp = """fof(a1, axiom, p(a) => q(a)).
fof(a2, axiom, q(a) => $false).
fof(a3, axiom, $true => p(a)).
fof(c, conjecture, $false)."""
        result = [
            problem.Problem(
                premises=[
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a1",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("a")]),
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.PredicateExpression(
                                predicate="q",
                                arguments=[logic.Constant("a")]),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a2",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.PredicateExpression(
                                predicate="q",
                                arguments=[logic.Constant("a")]),
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.DefinedConstant.FALSUM,
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a3",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("a")]),
                        ),
                    ),
                ],
                conjecture=problem.AnnotatedFormula(
                    logic="fof",
                    name="c",
                    role=problem.FormulaRole.CONJECTURE,
                    formula=logic.DefinedConstant.FALSUM,
                ),
            )
        ]

        self.check_parser(inp, result)
Esempio n. 2
0
 def test_connective(self):
     for input_conn, expected_conn in [
         (logic.BinaryConnective.CONJUNCTION, "&"),
         (logic.BinaryConnective.DISJUNCTION, "|"),
     ]:
         with self.subTest(input_conn=input_conn, expected_conn=expected_conn):
             self.assert_compiler(
                 logic.BinaryFormula(
                     logic.Variable("X"), input_conn, logic.Variable("Y")
                 ),
                 "X%sY" % expected_conn,
             )
Esempio n. 3
0
 def test_functor(self):
     inp = """cnf(and_definition1,axiom,( and(X,n0) = n0 ))."""
     result = problem.AnnotatedFormula(
         logic="cnf",
         name="and_definition1",
         role=problem.FormulaRole.AXIOM,
         formula=logic.BinaryFormula(
             left=logic.FunctorExpression(
                 functor="and",
                 arguments=[logic.Variable("X"),
                            logic.Constant("n0")]),
             operator=logic.BinaryConnective.EQ,
             right=logic.Constant("n0"),
         ),
     )
     self.check_parser(inp, result)
Esempio n. 4
0
 def parseJavaToPython(node):
     if node.getVisitName() == "quantifier":
         return logic.Quantifier(node.getId())
     elif node.getVisitName() == "binary_connective":
         return logic.BinaryConnective(node.getId())
     elif node.getVisitName() == "defined_predicate":
         return logic.DefinedPredicate(node.getId())
     elif node.getVisitName() == "unary_connective":
         return logic.UnaryConnective(node.getId())
     elif node.getVisitName() == "unary_formula":
         return logic.UnaryFormula(
             OWLParser.parseJavaToPython(node.getConnective()),
             OWLParser.parseJavaToPython(node.getFormula()))
     elif node.getVisitName() == "quantified_formula":
         variables = []
         for var in node.getVariables():
             variables.append(OWLParser.parseJavaToPython(var))
         return logic.QuantifiedFormula(
             OWLParser.parseJavaToPython(node.getQuantifier()), variables,
             OWLParser.parseJavaToPython(node.getFormula()))
     elif node.getVisitName() == "binary_formula":
         return logic.BinaryFormula(
             OWLParser.parseJavaToPython(node.getLeft()),
             OWLParser.parseJavaToPython(node.getOp()),
             OWLParser.parseJavaToPython(node.getRight()))
     elif node.getVisitName() == "predicate_expression":
         # TODO: find out how to handle lists like arguments
         arguments = []
         for arg in node.getArguments():
             arguments.append(OWLParser.parseJavaToPython(arg))
         return logic.PredicateExpression(node.getPredicate(), arguments)
     elif node.getVisitName() == "typed_variable":
         return logic.TypedVariable(
             node.getName(), OWLParser.parseJavaToPython(node.getVType()))
     elif node.getVisitName() == "variable":
         return logic.Variable(node.getSymbol())
     elif node.getVisitName() == "constant":
         return logic.Constant(node.getSymbol())
     elif node.getVisitName() == "defined_constant":
         return logic.DefinedConstant(node.getId())
     elif node.getVisitName() == "subtype":
         return logic.Subtype(OWLParser.parseJavaToPython(node.getLeft),
                              OWLParser.parseJavaToPython(node.getRight))
     elif node.getVisitName() == "type":
         return logic.Type(node.getName())
Esempio n. 5
0
 def test_verum(self):
     inp = """fof(mElmSort,axiom,(
 ! [W0] :
   ( aElement0(W0)
  => $true ) ))."""
     result = problem.AnnotatedFormula(
         logic="fof",
         name="mElmSort",
         role=problem.FormulaRole.AXIOM,
         formula=logic.QuantifiedFormula(
             quantifier=logic.Quantifier.UNIVERSAL,
             variables=[logic.Variable("W0")],
             formula=logic.BinaryFormula(
                 left=logic.PredicateExpression(
                     predicate="aElement0",
                     arguments=[logic.Variable("W0")]),
                 operator=logic.BinaryConnective.IMPLICATION,
                 right=logic.DefinedConstant.VERUM,
             ),
         ),
     )
     self.check_parser(inp, result)
Esempio n. 6
0
 def parse_binary_formula(self, formula: dict):
     return logic.BinaryFormula(
         left=self._parse_rec(formula["left"]),
         right=self._parse_rec(formula["right"]),
         operator=self._parse_rec(formula["connective"]),
     )
Esempio n. 7
0
 def visit_binary_formula(self, obj, **kwargs):
     return logic.BinaryFormula(
         left=self.visit(obj.children[0], **kwargs),
         operator=self.visit_binary_operator(obj.children[1], **kwargs),
         right=self.visit(obj.children[2], **kwargs),
     )
Esempio n. 8
0
 def visit_disjunction(self, obj, **kwargs):
     return logic.BinaryFormula(
         left=self.visit(obj.children[0], **kwargs),
         operator=logic.BinaryConnective.DISJUNCTION,
         right=self.visit(obj.children[1], **kwargs),
     )
Esempio n. 9
0
    def test_problems_2_2(self):
        inp = """fof(a1, axiom, $true => a=d).
fof(a2, axiom, $true => p(g(f(a),b))).
fof(a3, axiom, $true => f(d)=b).
fof(a4, axiom, $true => g(b,b)=c).
fof(a5, axiom, p(c) => $false).
fof(c, conjecture, $false)."""
        result = [
            problem.Problem(
                premises=[
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a1",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.BinaryFormula(
                                left=logic.Constant("a"),
                                operator=logic.BinaryConnective.EQ,
                                right=logic.Constant("d")),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a2",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.PredicateExpression(
                                predicate="p",
                                arguments=[
                                    logic.FunctorExpression(
                                        functor="g",
                                        arguments=[
                                            logic.FunctorExpression(
                                                functor="f",
                                                arguments=[
                                                    logic.Constant("a")
                                                ]),
                                            logic.Constant("b")
                                        ]),
                                ]),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a3",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.BinaryFormula(
                                left=logic.FunctorExpression(
                                    functor="f",
                                    arguments=[logic.Constant("d")]),
                                operator=logic.BinaryConnective.EQ,
                                right=logic.Constant("b")),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a4",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.BinaryFormula(
                                left=logic.FunctorExpression(
                                    functor="g",
                                    arguments=[
                                        logic.Constant("b"),
                                        logic.Constant("b")
                                    ]),
                                operator=logic.BinaryConnective.EQ,
                                right=logic.Constant("c")),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a5",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("c")]),
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.DefinedConstant.FALSUM,
                        ),
                    ),
                ],
                conjecture=problem.AnnotatedFormula(
                    logic="fof",
                    name="c",
                    role=problem.FormulaRole.CONJECTURE,
                    formula=logic.DefinedConstant.FALSUM,
                ),
            )
        ]
        self.check_parser(inp, result)
Esempio n. 10
0
    def test_problems_2_1(self):
        inp = """fof(a1, axiom, (p(e) & p(b) & p(d)) => $false).
fof(a2, axiom, p(e) => p(d)).
fof(a3, axiom, $true => p(f)).
fof(a4, axiom, p(a) => $false).
fof(a5, axiom, p(c) => p(e)).
fof(a6, axiom, $true => p(c)).
fof(a7, axiom, $true => (f=b)).
fof(c, conjecture, $false)."""
        result = [
            problem.Problem(
                premises=[
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a1",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.BinaryFormula(
                                left=logic.PredicateExpression(
                                    predicate="p",
                                    arguments=[logic.Constant("e")]),
                                operator=logic.BinaryConnective.CONJUNCTION,
                                right=logic.BinaryFormula(
                                    left=logic.PredicateExpression(
                                        predicate="p",
                                        arguments=[logic.Constant("b")]),
                                    operator=logic.BinaryConnective.
                                    CONJUNCTION,
                                    right=logic.PredicateExpression(
                                        predicate="p",
                                        arguments=[logic.Constant("d")]),
                                ),
                            ),
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.DefinedConstant.FALSUM,
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a2",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("e")]),
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("d")]),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a3",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("f")]),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a4",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("a")]),
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.DefinedConstant.FALSUM,
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a5",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("c")]),
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("e")]),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a6",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.PredicateExpression(
                                predicate="p",
                                arguments=[logic.Constant("c")]),
                        ),
                    ),
                    problem.AnnotatedFormula(
                        logic="fof",
                        name="a7",
                        role=problem.FormulaRole.AXIOM,
                        formula=logic.BinaryFormula(
                            left=logic.DefinedConstant.VERUM,
                            operator=logic.BinaryConnective.IMPLICATION,
                            right=logic.BinaryFormula(
                                left=logic.Constant("f"),
                                operator=logic.BinaryConnective.EQ,
                                right=logic.Constant("b")),
                        ),
                    ),
                ],
                conjecture=problem.AnnotatedFormula(
                    logic="fof",
                    name="c",
                    role=problem.FormulaRole.CONJECTURE,
                    formula=logic.DefinedConstant.FALSUM,
                ),
            )
        ]
        self.check_parser(inp, result)