Beispiel #1
0
    def visit(self, operator):
        if operator.negate:
            return And(self.visit(~operator.operand1),
                       self.visit(~operator.operand2), not operator.negate)

        return Or(self.visit(operator.operand1), self.visit(operator.operand2),
                  operator.negate)
Beispiel #2
0
    def visit(self, operator):
        op1 = operator.operand1
        op2 = operator.operand2

        if self.body == op1:
            op1 = self.subst
        if self.body == op2:
            op2 = self.subst
        if self.body in op1:
            op1 = self.visit(op1)
        if self.body in op2:
            op2 = self.visit(op2)
        return Or(op1, op2, operator.negate)
Beispiel #3
0
    def visit(self, operator: Operator):
        new_op = operator
        if And in [type(new_op.operand1), type(new_op.operand2)]:
            if type(new_op.operand1) is And:
                new_op = And(
                    Or(self.visit(new_op.operand2),
                       self.visit(new_op.operand1.operand1)),
                    Or(self.visit(new_op.operand2),
                       self.visit(new_op.operand1.operand2)))

            if type(new_op.operand2) is And:
                new_op = And(
                    Or(self.visit(new_op.operand1),
                       self.visit(new_op.operand2.operand1)),
                    Or(self.visit(new_op.operand1),
                       self.visit(new_op.operand2.operand2)))

            op1 = self.visit(new_op.operand1)
            op2 = self.visit(new_op.operand2)

            return And(op1, op2, new_op.negate)

        return new_op
Beispiel #4
0
def prettify(clause: HornClause):
    new_body = HornClause._make_or(clause.body)
    free_clause = FreeClause([Or(clause.head, ~new_body)])

    new_terms = []
    canonicalize = CanonicalizeVisitor()
    for term in free_clause.terms:
        if type(term
                ) is Or:  # from Horn's, must be one positive and one negative
            if term.operand1.negate:
                new_terms += Implies(canonicalize.visit(term.operand1),
                                     term.operand2)
            else:
                new_terms += [
                    Implies(canonicalize.visit(term.operand2), term.operand1)
                ]
        else:
            new_terms += [term]

    return FreeClause(new_terms)
Beispiel #5
0
    def visit(self, operator):
        vars = self.var_visitor.visit(
            operator.operand1) + self.var_visitor.visit(operator.operand2)
        counter = Counter(vars)
        dups = [var for var in vars if counter[var] > 1]

        op1 = operator.operand1
        op2 = operator.operand2

        for var in set(dups):
            new_var = Var(f"x{self.i}")
            subst_visitor = SubstVisitor(var, new_var)
            op1 = subst_visitor.visit(op1)
            self.i += 1

            new_var = Var(f"x{self.i}")
            subst_visitor = SubstVisitor(var, new_var)
            op2 = subst_visitor.visit(op2)
            self.i += 1

        op1 = self.visit(op1)
        op2 = self.visit(op2)

        return Or(op1, op2, operator.negate)
Beispiel #6
0
    def visit(self, operator):
        op1 = self.visit(operator.operand1)
        op2 = self.visit(operator.operand2)

        return Or(op1, op2, operator.negate)
Beispiel #7
0
    def visit(self, implication: Implies):
        op1 = self.visit(implication.operand1)
        op2 = self.visit(implication.operand2)

        return Or(~op1, op2)