Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  halirutan Apr 10 at 21:30

1 Answer 1

up vote 8 down vote accepted
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 *)
share|improve this answer
    
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. –  Techrocket9 Apr 11 at 2:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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