Relational: return BooleanAtoms instead of bools. #2844

Merged
merged 1 commit into from Feb 1, 2014

2 participants

@randyheydon

Also fixed tests in several locations to check for the new results, and corrected several areas where Python bools were expected; these areas should now handle Python bools and SymPy BooleanAtoms equally.

I realize this may be a contentious change, as True and S.true each have their place; see this comment block in sympy.logic.boolalg for reference. I feel that, since Relationals are "arbitrary symbolic Boolean[s]", it's more appropriate to have them simplify to SymPy objects instead of native Python bools. As an example, I have a current application where I substitute a series of symbols in an Equality; currently, I have to check whether it's reduced to True or False before substituting. My code would be simpler if I could just call the subs method on S.true and not worry about how it simplifies until the end. But I am open to arguments to leave the current behaviour too.

Note that, when using inequality operators, Python bools are still returned in some cases, since they do not always pass off to the Relational subclasses. For example, (x < 2).subs(x, 1) will return S.true, because it starts out as a StrictLessThan object, but S.One < 2 will return True because that logic is all within the Number class. Presumably consistency would be good here; I can try to change the behaviour of the second case if it's deemed worthwhile.

@randyheydon randyheydon Relational: return BooleanAtoms instead of bools.
Fixed tests in several locations to check for the new results.  Corrected
several areas where Python bools were expected; these areas should now handle
Python bools and SymPy BooleanAtoms equally.
f5e0a15
@asmeurer
SymPy member

I think this change is OK. Your argument seems valid, and your use-case seems motivating.

Probably you should change the number class ones too.

@asmeurer
SymPy member

This passes tests, though, and I don't think we need to block on the S.One < 2, so I am going to merge it.

@asmeurer asmeurer merged commit 4c29e99 into sympy:master Feb 1, 2014

1 check failed

Details default The Travis CI build could not complete due to an error
@randyheydon randyheydon deleted the randyheydon:relational_STrue branch Feb 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment