bastikr / boolean.py

Implements boolean algebra in one module.
BSD 2-Clause "Simplified" License
76 stars 34 forks source link

simplify doesn't work on formulas with only 0 or 1s #98

Open suguman opened 3 years ago

suguman commented 3 years ago

I am attempting to determine whether a formula evaluates to True/False given an assignment to all symbols. For this I am substituting symbols with 0 or 1 depending on the truth assignment one by one. At the end, I obtain a formula consisting of 0 and 1s only. For example, I could get a formula like " ((~(0))&(0))&((0)|(0)) " after assigning the truth assignment.

The code is throwing an error when I attempt to simplify() the above formula (in 0s and 1s only). I believe the reason is that simplify() does not implement simplifications on 0 and 1.

pombredanne commented 3 years ago

@suguman re:

I believe the reason is that simplify() does not implement simplifications on 0 and 1.

I get this: what does not work there?

>>> import boolean
>>> A = boolean.BooleanAlgebra()
>>> bar=A.parse(" ((~(0))&(0))&((0)|(0)) " )
>>> bar
AND(AND(NOT(FALSE), FALSE), OR(FALSE, FALSE))
>>> bar.simplify()
FALSE

Note that 0 and 1 are interpreted as the TRUE and FALSE built-in symbols respectively