Simplify a Boolean Algebra expression with don't cares
An arbitrary function with "don't cares" can be defined using either BooleanFunction
or BooleanConvert
, but in those cases, Mathematica makes no effort to find the minimal representation of such a function.
Instead, use BooleanMinimize
with the optional third argument: an assumed condition on the variables. In your case, you can specify that your "don't cares" are 0-9 by making the condition be A ∧ (B ∨ C)
.
Then the calculation
BooleanMinimize[
(A ∧ ¬ B ∧ C ∧ ¬ D) ∨ (A ∧ B ∧ ¬ C ∧ ¬ D) ∨ (A ∧ B ∧ C ∧ ¬ D),
"DNF",
A ∧ (B ∨ C)]
will produce the desired output of !D
.
Thank's to @Misha Lavrov (a great thanks !), here is how you can solve the problem :
BooleanMinimize[
BooleanFunction[{
{1,0,1,0}-> 1,
{1,0,1,1}-> 0,
{1,1,0,0}-> 1,
{1,1,0,1}-> 0,
{1,1,1,0}-> 1,
{1,1,1,1}-> 0
},{a,b,c,d}],
"SOP" (* = "DNF" *),
BooleanFunction[{
{1,1,_,_}-> 1, (* all cases above ... *)
{1,_,1,_}-> 1, (* ... are "do care" *)
{_,_,_,_}-> 0 (* other cases are "don't care" *)
},{a,b,c,d}]]
! d
Note :
@Misha Lavrov's comment (just below) was written before I added the third argument to BooleanMinimize
. At this time there were some "don't care" states in the first BooleanFunction[...]