Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fbaeab

Browse files
committed
Fixed side-effect bug in DPLL; more cleanup.
1 parent 9232957 commit 0fbaeab

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

logic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, sentence=None):
4747
abstract
4848

4949
def tell(self, sentence):
50-
"Add the sentence to the KB"
50+
"Add the sentence to the KB."
5151
abstract
5252

5353
def ask(self, query):
@@ -671,19 +671,19 @@ def dpll(clauses, symbols, model):
671671
P, value = find_unit_clause(clauses, model)
672672
if P:
673673
return dpll(clauses, removeall(P, symbols), extend(model, P, value))
674-
P = symbols.pop() # XXX is this side-effect more global than desired?
674+
P, symbols = symbols[0], symbols[1:]
675675
return (dpll(clauses, symbols, extend(model, P, True)) or
676676
dpll(clauses, symbols, extend(model, P, False)))
677677

678-
def find_pure_symbol(symbols, unknown_clauses):
678+
def find_pure_symbol(symbols, clauses):
679679
"""Find a symbol and its value if it appears only as a positive literal
680680
(or only as a negative) in clauses.
681681
>>> find_pure_symbol([A, B, C], [A|~B,~B|~C,C|A])
682682
(A, True)
683683
"""
684684
for s in symbols:
685685
found_pos, found_neg = False, False
686-
for c in unknown_clauses:
686+
for c in clauses:
687687
if not found_pos and s in disjuncts(c): found_pos = True
688688
if not found_neg and ~s in disjuncts(c): found_neg = True
689689
if found_pos != found_neg: return s, found_pos

0 commit comments

Comments
 (0)