5
$\begingroup$

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.

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

1 Answer 1

3
$\begingroup$

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

addendum

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.

$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$
    – prabhat
    Jun 27, 2016 at 13:05
  • $\begingroup$ @prabhat No, it's right as it is. See my addendum. $\endgroup$
    – user36273
    Jun 27, 2016 at 15:25
  • $\begingroup$ 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 :) $\endgroup$
    – prabhat
    Jun 28, 2016 at 2:21

Your Answer

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

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