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

Skip to content

Commit 290bd46

Browse files
committed
Fixed standardize_apart to start afresh on top-level calls.
1 parent eedec13 commit 290bd46

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

logic.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ def fol_fc_ask(KB, alpha):
911911
ps, q = conjuncts(r.args[0]), r.args[1]
912912
raise NotImplementedError
913913

914-
def standardize_apart(sentence, dic={}):
914+
def standardize_apart(sentence, dic=None):
915915
"""Replace all the variables in sentence with new variables.
916916
>>> e = expr('F(a, b, c) & G(c, A, 23)')
917917
>>> len(variables(standardize_apart(e)))
@@ -921,6 +921,7 @@ def standardize_apart(sentence, dic={}):
921921
>>> is_variable(standardize_apart(expr('x')))
922922
True
923923
"""
924+
if dic is None: dic = {}
924925
if not isinstance(sentence, Expr):
925926
return sentence
926927
elif is_var_symbol(sentence.op):
@@ -994,8 +995,8 @@ def test_ask(q):
994995
'(Mother(m, h) & Human(h)) ==> Human(m)'
995996
])
996997
)
998+
997999

998-
9991000
def fol_bc_ask(KB, goals, theta={}):
10001001
"""A simple backward-chaining algorithm for first-order logic. [Fig. 9.6]
10011002
KB should be an instance of FolKB, and goals a list of literals.
@@ -1005,7 +1006,7 @@ def fol_bc_ask(KB, goals, theta={}):
10051006
>>> test_ask('Human(x)')
10061007
['{x: Mac}', '{x: MrsMac}']
10071008
>>> test_ask('Hates(x, y)')
1008-
['{x: Mac, y: Pete}']
1009+
['{x: Mac, y: MrsRabbit}', '{x: Mac, y: Pete}']
10091010
>>> test_ask('Loves(x, y)')
10101011
['{x: MrsMac, y: Mac}', '{x: MrsRabbit, y: Pete}']
10111012
>>> test_ask('Rabbit(x)')
@@ -1038,7 +1039,7 @@ def fol_bc_ask(KB, goals, theta={}):
10381039
new_goals = goals[1:]
10391040
else:
10401041
new_goals = conjuncts(body) + goals[1:]
1041-
1042+
10421043
for ans in fol_bc_ask(KB, new_goals, subst_compose(theta1, theta)):
10431044
yield ans
10441045

0 commit comments

Comments
 (0)