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

Skip to content

Commit 7dcc214

Browse files
committed
Fixed is_definite_clause().
1 parent 290bd46 commit 7dcc214

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

logic.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,17 @@ def is_definite_clause(s):
333333
True
334334
>>> is_definite_clause(expr('(Farmer(f) & ~Rabbit(r)) ==> Hates(f, r)'))
335335
False
336+
>>> is_definite_clause(expr('(Farmer(f) | Rabbit(r)) ==> Hates(f, r)'))
337+
False
336338
"""
337-
op = s.op
338-
return (is_symbol(op) or
339-
(op == '>>' and every(is_positive, literals(s))))
339+
if is_symbol(s.op): return True
340+
if s.op != '>>': return False
341+
antecedent, consequent = s.args
342+
antecedent = NaryExpr('&', antecedent)
343+
return (is_symbol(consequent.op)
344+
and (is_symbol(antecedent.op)
345+
or (antecedent.op == '&'
346+
and all(is_symbol(arg.op) for arg in antecedent.args))))
340347

341348
## Useful constant Exprs used in examples and code:
342349
TRUE, FALSE, ZERO, ONE, TWO = map(Expr, ['TRUE', 'FALSE', 0, 1, 2])
@@ -996,7 +1003,7 @@ def test_ask(q):
9961003
])
9971004
)
9981005

999-
1006+
10001007
def fol_bc_ask(KB, goals, theta={}):
10011008
"""A simple backward-chaining algorithm for first-order logic. [Fig. 9.6]
10021009
KB should be an instance of FolKB, and goals a list of literals.

0 commit comments

Comments
 (0)