Exemplo n.º 1
0
    def _resolve(self):
        """

        :return:
        """
        start_time = time.time()
        i = 0
        checked = list()
        while i < len(self._cnf_list):
            if (time.time() - start_time) > self.proof_timeout:
                raise exceptions.TimeoutException('Proof timeout reached')
            j = i + 1
            while j < len(self._cnf_list):
                if [i, j] in checked:
                    j += 1
                    continue
                checked.append([i, j])
                have_resolve = False
                for k in range(len(self._cnf_list[i])):
                    atomic = self._cnf_list[i][k]
                    negation = util.negate_formula(atomic)
                    try:
                        resolve = Prover._get_index(self._cnf_list[j],
                                                    negation)
                        cnf_list1 = deepcopy(self._cnf_list[i])
                        cnf_list2 = deepcopy(self._cnf_list[j])
                        if resolve[1] >= 1:
                            Prover._remove_herbrand(resolve, cnf_list1,
                                                    cnf_list2, k)
                        ind = resolve[0]
                        new_cnf = cnf_list1[:k]
                        new_cnf += cnf_list1[(k + 1):]
                        for cnf in cnf_list2[:ind]:
                            if cnf not in new_cnf:
                                new_cnf.append(cnf)
                        for cnf in cnf_list2[(ind + 1):]:
                            if cnf not in new_cnf:
                                new_cnf.append(cnf)
                        new_cnf.sort()
                        if len(new_cnf) == 0:
                            self._cnf_list.append([])
                            self.parents.append([i, j])
                            return True, time.time() - start_time
                        if not util.is_tautology(new_cnf) and \
                           new_cnf not in self._cnf_list:
                            have_resolve = True
                            self._cnf_list.append(new_cnf)
                            self.parents.append([i, j])
                            checked.append([i, len(self._cnf_list) - 1])
                            checked.append([j, len(self._cnf_list) - 1])
                    except ValueError:
                        pass
                if have_resolve is True:
                    i = -1
                    break
                j += 1
            i += 1
        return False, time.time() - start_time
Exemplo n.º 2
0
    def _tautology_elimination(self):
        """
        Remove any CNF tautologies

        :return:
        """
        i = 0
        while i < len(self._cnf_list):
            cnf = self._cnf_list[i]
            if util.is_tautology(cnf):
                self._cnf_list.pop(i)
                i -= 1
            i += 1
Exemplo n.º 3
0
 def test_is_tautology_negative(self):
     cnf = list()
     cnf.append(Symbol("a"))
     cnf.append(Symbol("b"))
     is_taut = util.is_tautology(cnf)
     self.assertFalse(is_taut)
Exemplo n.º 4
0
 def test_is_tautology_bad_input(self):
     self.assertFalse(util.is_tautology("a"))
     self.assertFalse(util.is_tautology([Symbol("a")]))
Exemplo n.º 5
0
 def test_is_tautology(self):
     cnf = list()
     cnf.append(Symbol("a"))
     cnf.append(Not(Symbol("a")))
     is_taut = util.is_tautology(cnf)
     self.assertTrue(is_taut)