I have a truth table for a Boolean expression represented like this
table={{0, 0, 0, 0} -> 0, {0, 0, 0, 1} -> 0, {0, 0, 1, 0} ->
0, {0, 0, 1, 1} -> 0, {0, 1, 0, 0} -> 0, {0, 1, 0, 1} ->
0, {0, 1, 1, 0} -> 0, {0, 1, 1, 1} -> 1, {1, 0, 0, 0} ->
1, {1, 0, 0, 1} -> 1, {1, 0, 1, 0} -> 1, {1, 0, 1, 1} ->
1, {1, 1, 0, 0} -> 1, {1, 1, 0, 1} -> 1, {1, 1, 1, 0} ->
1, {1, 1, 1, 1} -> 0}
(all on one line)
The table contains the values I want at the output given y4,y3,y2,y1 at the input, i.e.
{y4,y3,y2,y1} -> desiredOutput
What is the best way to transform this data into a form that can be then processed in terms of y with functions such as BooleanMinimize?
Answer
BooleanMinimize[BooleanFunction[table]]
(* (#1 && ! #2) || (#1 && ! #3) || (#1 && ! #4) || (! #1 && #2 && #3 && #4) & *)
Note in the documentation how 1/0 vs True/False are treated here, massage as needed.
Quick verification:
bf = BooleanFunction[table];
Rule @@@ Transpose[{table[[All, 1]],
bf[Sequence @@ #] & /@ table[[All, 1]] // Boole}];
% == table
(* True *)
Comments
Post a Comment