Blocks mare marked with thick black rectangles. Complementary blocks are connected by red lines.
The equations on the left describe the change that turns the last object into the next one.
The thick dotted lines correspond to that equation.
The thin dotted lines are implied by the change (because the complement of a complement must be equal).
Such an object can be used to save equality and complement relationships between variables in Boolean algebra.
The image illustrates the following test of such an object in Python.
spc = SetPartComp([[3, 4], [5, 6, 7], [8, 9], [20, 30]], {(1, 2), (3, 8), (10, 11)})
spc.set_equal(2, 4)
assert spc == SetPartComp([[1, 8, 9], [2, 3, 4], [5, 6, 7], [20, 30]], {(1, 2), (10, 11)})
spc.set_comp(11, 20)
assert spc == SetPartComp([[1, 8, 9], [2, 3, 4], [5, 6, 7], [10, 20, 30]], {(1, 2), (10, 11)})
spc.set_comp(12, 30)
assert spc == SetPartComp([[1, 8, 9], [2, 3, 4], [5, 6, 7], [10, 20, 30], [11, 12]], {(1, 2), (10, 11)})
spc.set_equal(6, 13)
assert spc == SetPartComp([[1, 8, 9], [2, 3, 4], [5, 6, 7, 13], [10, 20, 30], [11, 12]], {(1, 2), (10, 11)})
spc.set_comp(3, 30)
assert spc == SetPartComp([[1, 8, 9, 10, 20, 30], [2, 3, 4, 11, 12], [5, 6, 7, 13]], {(1, 2)})
spc.set_comp(40, 50)
assert spc == SetPartComp([[1, 8, 9, 10, 20, 30], [2, 3, 4, 11, 12], [5, 6, 7, 13]], {(1, 2), (40, 50)})
spc.set_equal(60, 70)
assert spc == SetPartComp([[1, 8, 9, 10, 20, 30], [2, 3, 4, 11, 12], [5, 6, 7, 13], [60, 70]], {(1, 2), (40, 50)})
spc.set_comp(0, 70)
assert spc == SetPartComp([[1, 8, 9, 10, 20, 30], [2, 3, 4, 11, 12], [5, 6, 7, 13], [60, 70]], {(1, 2), (40, 50), (0, 60)})
spc.set_comp(0, 40)
assert spc == SetPartComp([[0, 50], [1, 8, 9, 10, 20, 30], [2, 3, 4, 11, 12], [5, 6, 7, 13], [40, 60, 70]], {(1, 2), (0, 40)})
spc.set_equal(0, 1)
assert spc == SetPartComp([[0, 1, 8, 9, 10, 20, 30, 50], [2, 3, 4, 11, 12, 40, 60, 70], [5, 6, 7, 13]], {(0, 2)})
spc.set_equal(2, 5)
assert spc == SetPartComp([[0, 1, 8, 9, 10, 20, 30, 50], [2, 3, 4, 5, 6, 7, 11, 12, 13, 40, 60, 70]], {(0, 2)})