boolean.py
boolean.py copied to clipboard
Absorbtion is not invariant to order of args.
The function absorb should produce the same results no matter the order of the args
passed to it.
There is a counter-example where this property does not hold.
import boolean
algebra = boolean.BooleanAlgebra()
TRUE, FALSE, NOT, AND, OR, symbol = algebra.definition()
e = AND(OR(NOT(symbol("x1")), NOT(symbol("x2"))), TRUE, symbol("x2"), NOT(symbol("x1")))
args = [
OR(NOT(symbol("x1")), NOT(symbol("x2"))),
NOT(symbol("x1")),
symbol("x2"),
]
print("ORIGINAL ORDER")
print(e.absorb(args))
args[1], args[2] = args[2], args[1]
print("SWAPPED")
print(e.absorb(args))
Which produces following output
ORIGINAL ORDER
[NOT(Symbol('x1')), Symbol('x2')]
SWAPPED
[NOT(Symbol('x1')), Symbol('x2'), NOT(Symbol('x1'))]