Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix absorption issue #113

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion boolean/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,12 @@ def absorb(self, args):
i -= 1
continue
else:
args[j] = b
if b in args:
del args[j]
if j < i:
i -= 1
else:
args[j] = b
j += 1
continue

Expand Down
22 changes: 22 additions & 0 deletions boolean/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,28 @@ def test_simplify(self):
)
assert result.pretty() == expected.pretty()

def test_absorption_invariant_to_order(self):
algebra = BooleanAlgebra()

a, b = algebra.symbols(*"ab")
pombredanne marked this conversation as resolved.
Show resolved Hide resolved

e = (~a | ~b) & b & ~a
args = [
~a | ~b,
~a,
b,
]

result_original = e.absorb(args)

args[1], args[2] = args[2], args[1]
pombredanne marked this conversation as resolved.
Show resolved Hide resolved
result_swapped = e.absorb(args)

assert len(result_original) == 2
assert len(result_swapped) == 2
assert result_original[0] == result_swapped[1]
assert result_original[1] == result_swapped[0]

@expectedFailure
def test_parse_complex_expression_should_create_same_expression_as_python(self):
algebra = BooleanAlgebra()
Expand Down