def resolution(self, predicates, target): '''从已知谓词关系公式证明给定谓词公式 如果能够证明给定谓词公式,返回真,否则返回假 :param predicates: 已知谓词公式 :type predicates: list of string :param target: 待证明谓词公式 :type target: string ''' # 将所有谓词关系公式转换成内部表现形式 conditions = [expr(i) for i in predicates] target = expr(target) # 使用反演法,将待证明结论取反 negated_target = target.negate() # 构造条件谓词集合 predicates = conditions + [negated_target] # 将谓词集合进行 skolem 标准化,转换为子句集 clauses_set = [skolemize(i) for i in predicates] # 进行归结 solver = ResolutionProverCommand(None, clauses_set) # 检查迭代后的子句集是否为空 result = solver.prove() # 生成证明过程 self._proof = solver.proof() return result
def clausify(expression): """ Skolemize, clausify, and standardize the variables apart. """ clause_list = [] for clause in _clausify(skolemize(expression)): for free in clause.free(): if is_indvar(free.name): newvar = VariableExpression(unique_variable()) clause = clause.replace(free, newvar) clause_list.append(clause) return clause_list