boolean.py icon indicating copy to clipboard operation
boolean.py copied to clipboard

Not able to simplify some simple expressions (eg. (0)&~((1)|(0)) )

Open gabe-nasc opened this issue 7 years ago • 1 comments

I've ran into a problem while using simplify with a few expressions, even though they are valid and have not apparent reason to cause these errors.

One thing I noticed is that if I remove the 'not' symbol from them, they'll work "correctly"

Cases where "TypeError: '_FALSE' object is not callable" is raised:

(0)&~((1)|(0)) (1)&(~((0)|(1))) (0)&(~((0)|(0)))&(1)

Cases where "TypeError: '_TRUE' object is not callable" is raised:

(~((0)&(0)))&(1)&(0)&(1) (0)|(0)|(~((1)&(0)&(0)&(0)&(0))) (~((1)&(0)&(1)&(1)))|(0)|(~((0)|(0)|(1)))

gabe-nasc avatar Aug 16 '18 19:08 gabe-nasc

I have reproduced this same issue. The minimal expression that causes this issue is 'NOT (FALSE)'. The problem is here. The self.TRUE and self.FALSE instances of DualBase are given instances not classes of _TRUE and _FALSE. I have come up with the following workaround:

algebra = boolean.BooleanAlgebra()
algebra.TRUE.dual = type(algebra.FALSE)
algebra.FALSE.dual = type(algebra.TRUE)

A more permanent solution would be to change the __init__ method of BooleanAlgebra like so:

self.TRUE_class = TRUE_class or _TRUE
self.TRUE = self.TRUE_class()

self.FALSE_class = FALSE_class or _FALSE
self.FALSE = self.FALSE_class()

# they cross-reference each other
self.TRUE.dual = self.FALSE_class
self.FALSE.dual = self.TRUE_class

MarcelRobitaille avatar Mar 30 '19 01:03 MarcelRobitaille