@@ -911,7 +911,7 @@ def fol_fc_ask(KB, alpha):
911
911
ps , q = conjuncts (r .args [0 ]), r .args [1 ]
912
912
raise NotImplementedError
913
913
914
- def standardize_apart (sentence , dic = {} ):
914
+ def standardize_apart (sentence , dic = None ):
915
915
"""Replace all the variables in sentence with new variables.
916
916
>>> e = expr('F(a, b, c) & G(c, A, 23)')
917
917
>>> len(variables(standardize_apart(e)))
@@ -921,6 +921,7 @@ def standardize_apart(sentence, dic={}):
921
921
>>> is_variable(standardize_apart(expr('x')))
922
922
True
923
923
"""
924
+ if dic is None : dic = {}
924
925
if not isinstance (sentence , Expr ):
925
926
return sentence
926
927
elif is_var_symbol (sentence .op ):
@@ -994,8 +995,8 @@ def test_ask(q):
994
995
'(Mother(m, h) & Human(h)) ==> Human(m)'
995
996
])
996
997
)
998
+
997
999
998
-
999
1000
def fol_bc_ask (KB , goals , theta = {}):
1000
1001
"""A simple backward-chaining algorithm for first-order logic. [Fig. 9.6]
1001
1002
KB should be an instance of FolKB, and goals a list of literals.
@@ -1005,7 +1006,7 @@ def fol_bc_ask(KB, goals, theta={}):
1005
1006
>>> test_ask('Human(x)')
1006
1007
['{x: Mac}', '{x: MrsMac}']
1007
1008
>>> test_ask('Hates(x, y)')
1008
- ['{x: Mac, y: Pete}']
1009
+ ['{x: Mac, y: MrsRabbit}', '{x: Mac, y: Pete}']
1009
1010
>>> test_ask('Loves(x, y)')
1010
1011
['{x: MrsMac, y: Mac}', '{x: MrsRabbit, y: Pete}']
1011
1012
>>> test_ask('Rabbit(x)')
@@ -1038,7 +1039,7 @@ def fol_bc_ask(KB, goals, theta={}):
1038
1039
new_goals = goals [1 :]
1039
1040
else :
1040
1041
new_goals = conjuncts (body ) + goals [1 :]
1041
-
1042
+
1042
1043
for ans in fol_bc_ask (KB , new_goals , subst_compose (theta1 , theta )):
1043
1044
yield ans
1044
1045
0 commit comments