Example #1
0
 def test_apply_should_succeed_if_new_clauses_are_correct(self):
     rewrite_rules3 = paracontrol.createRewriteRule(self.c6)
     to = ['add', 'B', 'A']
     frm = ['add', 'A', 'B']
     expectedLiteral = literals.Literal([
         '=', ['subtract', ['add', 'B', 'A'], 'C'],
         ['add', ['subtract', 'A', 'C'], 'B']
     ])
     expectedClause = clauses.Clause([expectedLiteral])
     rewrite_rule = rewriterule.rewriteRule(frm, to, [], self.c1)
     res = rewrite_rule.apply(self.c3)
     self.assertTrue(expectedClause.compare(res[0]))
     res2 = rewrite_rules3[1].apply(self.c7)
     print(res2)
Example #2
0
 def test_replaceSubstitute_should_succeed_if_new_clause_is_correct(self):
     subst = substitutions.Substitution()
     pos = position.Position(subst, [
         0,
         1,
         1,
     ])
     clause = self.c3.replaceSubstitute(pos, ['add', 'B', 'A'])
     expectedLiteral = literals.Literal([
         '=', ['subtract', ['add', 'B', 'A'], 'C'],
         ['add', ['subtract', 'A', 'C'], 'B']
     ])
     expectedClause = clauses.Clause([expectedLiteral])
     self.assertEqual(expectedClause.compare(clause), True)
Example #3
0
def factor(clause, lit1, lit2):
    """
    Check if it is possible to form a factor between lit1 and lit2. If
    yes, return it, otherwise return None.
    """
    l1 = clause.getLiteral(lit1)
    l2 = clause.getLiteral(lit2)
    if l1.isNegative() != l2.isNegative():
        return None
    sigma = mgu(l1.atom, l2.atom)
    if sigma == None:
        return None
    lits = [l.instantiate(sigma) for l in clause.literals if l != l2]
    res = clauses.Clause(lits)
    res.removeDupLits()
    res.setDerivation(flatDerivation("factor", [clause]))
    return res
Example #4
0
def resolution(clause1, lit1, clause2, lit2):
    """
    Implementation of the Resolution rule. lit1 and lit2 are indices
    of literals in clause1 and clause2, respectively, so clause1|lit1
    and clause2|lit2 are literals.

    Try to resolve clause1|lit1 against clause2|lit2. If this is
    possible, return the resolvent. Otherwise, return None.
    """
    l1 = clause1.getLiteral(lit1)
    l2 = clause2.getLiteral(lit2)
    if l1.isNegative() == l2.isNegative():
        return None
    sigma = mgu(l1.atom, l2.atom)
    if sigma is None:
        return None
    lits1 = [l.instantiate(sigma) for l in clause1.literals if l!=l1]
    lits2 = [l.instantiate(sigma) for l in clause2.literals if l!=l2]
    lits1.extend(lits2)
    res = clauses.Clause(lits1)
    res.removeDupLits()
    res.setDerivation(flatDerivation("resolution", [clause1, clause2]))
    return res