bastikr / boolean.py

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

Absorbtion is not invariant to order of args. #112

Open tomas789 opened 1 year ago

tomas789 commented 1 year ago

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'))]
tomas789 commented 1 year ago

After more investigation it looks like this is the core cause of the previous issue https://github.com/bastikr/boolean.py/issues/111