Boolean algebra simplifier based on n-dimensional k-maps
Define a boolean function ( lambda a, b, c : not (a or (a and b)) and c
, and pass it, along with its arity simplify
function, which will return a string containing the result of the simplification, in disjunctive normal form.
k_user.py
contains two examples: the half and full adder. As a simple usage example, here is the full adder (c
is the input remainder):
arity = 3
out = lambda a, b, c : 1 if (a + b + c == 1) or (a + b + c == 3) else 0
remainder = lambda a, b, c : 1 if a + b + c >= 2 else 0
print("output:")
print(simplify(out, arity))
print("remainder:")
print(simplify(remainder, arity))
The output will be:
output:
(~A)(~B)C + (~A)B(~C) + A(~B)(~C) + ABC
remainder:
AB + AC + BC