def substitute_unique(self, n): new_var = Operation.get_new_variable([op for op in self.body if op.type == Operation.VARIABLE]) if self.body[n] == UNIQUE: self.body = self.body[:n] + [EXISTS, self.body[n + 1], AND] + self.body[n + 2:self.start_of_child(n, 3)] + \ [FORALL, new_var, IF] + Formula(self.body[n + 2:self.start_of_child(n, 3)]).substitute( Formula([self.body[n + 1]]), Formula([new_var])).body \ + [EQUALS, new_var, self.body[n + 1]] + self.body[self.start_of_child(n, 3):]
def rename_one_quantor(self): for k in range(len(self.body)): if self.body[k].type == Operation.QUANTOR: for n in range(k + 2, len(self.body)): if self.body[n].type == Operation.QUANTOR and self.body[k + 1] == self.body[n + 1]: new_var = Operation.get_new_variable([op for op in self.body if op.type == Operation.VARIABLE]) s = Formula(self.body[n:self.start_of_child(n, 3)]).substitute(Formula([self.body[n + 1]]), Formula([new_var])) self.body = self.body[:n] + s.body + self.body[self.start_of_child(n, 3):] return True return False