Skip to content

Commit

Permalink
inferences raises an error on Number input
Browse files Browse the repository at this point in the history
    Some atoms should raise an error (like Numbers) and others
    (like Symbols) should not. A commented-out test was uncommented.
  • Loading branch information
smichr committed Mar 21, 2012
1 parent 423293f commit b9bb75c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions sympy/logic/inference.py
Expand Up @@ -72,34 +72,37 @@ def pl_true(expr, model={}):
return expr

expr = sympify(expr)
if expr.is_Atom:

if expr.is_Symbol:
return model.get(expr)

args = expr.args
if expr.func is Not:
func = expr.func

if func is Not:
p = pl_true(args[0], model)
if p is None: return None
else: return not p
elif expr.func is Or:
elif func is Or:
result = False
for arg in args:
p = pl_true(arg, model)
if p == True: return True
if p == None: result = None
return result
elif expr.func is And:
elif func is And:
result = True
for arg in args:
p = pl_true(arg, model)
if p == False: return False
if p == None: result = None
return result

elif expr.func is Implies:
elif func is Implies:
p, q = args
return pl_true(Or(Not(p), q), model)

elif expr.func is Equivalent:
elif func is Equivalent:
p, q = args
pt = pl_true(p, model)
if pt == None:
Expand Down
2 changes: 1 addition & 1 deletion sympy/logic/tests/test_inference.py
Expand Up @@ -115,7 +115,7 @@ def test_pl_true_wrong_input():
from sympy import pi
raises(ValueError, "pl_true('John Cleese')")
raises(ValueError, "pl_true(42+pi+pi**2)")
#raises(ValueError, "pl_true(42)") #returns None, but should it?
raises(ValueError, "pl_true(42)")

def test_PropKB():
A, B, C = symbols('A,B,C')
Expand Down

0 comments on commit b9bb75c

Please sign in to comment.