# Boolean function from incomplete truth table

BooleanFunction in mathematica can convert an input truth table to a Boolean function. It can do so even if the truth table is incomplete. But the interpretation of truth table obtained from such an incomplete truth table is not clear.

For example, let the incomplete truth table be:

A  B  C
0  0  0
0  1  0
1  0  1


The output Boolean function is C=A in this case.

But if the truth table is

A  B  C
0  0  0
0  1  1
1  0  0


Then the output truth table is C= !A & B, instead of C=B

The code for generating Boolean function from first truth tables is as follows:

BooleanFunction[{{False, False}->False,{False,True}->False,{True,False}->True},{A,B}];


For the second truth table, it is

BooleanFunction[{{False, False}->False,{False,True}->True,{True,False}->False},{A,B}];


Can anyone help in giving consistent explanation for above results? The algorithm used in BooleanFunction is not clear.

• Can you add the working Mathematica code associated with these truth tables and operations? – march Jun 27 '16 at 3:43
• Have edited the question to include the code, thanks. – prabhat Jun 27 '16 at 3:56
• The code is not complete. What are the definitions of arr and inputs? – march Jun 27 '16 at 4:02
• That part is just to read the input text file, specify (A,B) as input and C and output values. – prabhat Jun 27 '16 at 4:10
• Please add all necessary definitions. – Yves Klett Jun 27 '16 at 5:02

Using BooleanMinterms to solve the system:

1st

table1 = {{0, 0} -> 0, {0, 1} -> 0, {1, 0} -> 1};
trueTab1 = Pick[table1, table1[[All, 2]], 1];
boolMin1 = BooleanMinterms[trueTab1[[All, 1]], {a, b}]

(* a && ! b *)


BooleanFunction has a problem here (bug?)

BooleanFunction[table1, {a, b}]
(* a *)


2nd

table2 = {{0, 0} -> 0, {0, 1} -> 1, {1, 0} -> 0};
trueTab2 = Pick[table2, table2[[All, 2]], 1];
boolMin2 = BooleanMinterms[trueTab2[[All, 1]], {a, b}]

(* ! a && b *)


and with BooleanFunction

BooleanFunction[table2, {a, b}]
(* ! a && b *)


table = {{0, 0} -> 0, {0, 1} -> 1, {1, 0} -> 1};
trueTab = Pick[table, table[[All, 2]], 1]
{{0, 1} -> 1, {1, 0} -> 1}

BooleanMinterms[trueTab[[All, 1]], {a, b}]
(a && ! b) || (! a && b)


This code snippet "trueTab" is very helpful if you have 32 bit or more input.

• Thanks a lot for this answer, looks like I would be needing this only. However a question. I checked the term Pick[table2, table2[[All, 2]], 1], and its output is only {{0, 1} -> 1} while it should be the entire table, right? – prabhat Jun 27 '16 at 13:05
• @prabhat No, it's right as it is. See my addendum. – user36273 Jun 27 '16 at 15:25
• Now I understand, the snippet picks up only those rows where the output is 1, and ignores others. Thanks a lot, this is great solution :) – prabhat Jun 28 '16 at 2:21