# Converting truth tables to boolean expressions

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?

• 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? Apr 10, 2014 at 21:30

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 *)

• 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. Apr 11, 2014 at 2:50