3
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ It is not completely clear what your result should be. When you want to make a function out of your table, you could do it as follows: (func[#1] = #2) & @@@ table; and then you can easily call func[{1, 0, 1, 0}]. Does that help? $\endgroup$
    – halirutan
    Apr 10, 2014 at 21:30

1 Answer 1

10
$\begingroup$
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 *)
$\endgroup$
1
  • $\begingroup$ BooleanFunction is exactly what I was looking for. After reading the documentation I see that BooleanFunction[table, {y4, y3, y2, y1}] will name the variables as desired. $\endgroup$ Apr 11, 2014 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.