'How can I solve the problem of PLResolution python coding

This is my first writing in here. I have an issue to write a code about PL resolution. I am beginner of python and artificial algorithm so this is really hard to make it.

In stackoverflow, I have been watched that there are so many people who are so smart! I really appreciate you help or advice to solve the problem what I face!

So, here is my problem I want to make 'PL resolution' not using python package('logic.py'). Then, I write code by myself.

def PLR(KB, alpha):
    clauses = KB+[alpha]
    new = set()
    print('clauses:', clauses)
    
    while True:
        n=len(clauses)
        pairs = [(clauses[i], clauses[j]) for i in range(n) for j in range(i + 1, n)]
        print('n & pairs: ', n, pairs)

        for (ci, cj) in pairs:
            resolvents = pl_resolve(ci, cj)
            if False in resolvents: 
                return True
            print('resolvents: ', resolvents)
            new = new.union(resolvents)
            print('new_union: ', new, type(new))
            
            if [new] in clauses: 
                return False
        for c in new:
            print('new_check', new)
            print('c', c)
            if c not in clauses: clauses.append(c)

def pl_resolve(ci, cj):
    clauses = []
    for di in disjuncts(ci):
        for dj in disjuncts(cj):
            print('di and dj are', di, dj)
            if di != dj or dj == di:
                clauses.append(di)
                clauses.append(dj)
                print('resolve', clauses)
            return clauses
    return set(clauses)

def disjuncts(s):
    if isinstance(s, set):
        return list(s)
    else:
        return [s]

## Test of PL resolution
kb = [{'P12', 'B11'}, {'-B11'}]
alpha = {'P12'}
print(PLR(kb, alpha))
>>> True

I have been trying to fix my coding but unfortunately I can not do it.... Please if you can give me advice or solution, I really appreciate your kindness.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source