({{, (RefLink[BooleanTable, paclet:ref/BooleanTable])[bf]
gives a list of truth values for all possible combinations of variable values supplied to the Boolean function bf.}, {, (RefLink[BooleanTable, paclet:ref/BooleanTable])[expr,{(Subscript[a, 1]),(Subscript[a, 2]),…}] 
gives a list of the truth values of the Boolean expression expr for all possible combinations of values of the (Subscript[a, i]).}, {, (RefLink[BooleanTable, paclet:ref/BooleanTable])[expr,{(Subscript[a, 1]),(Subscript[a, 2]),…},{(Subscript[b, 1]),…},…]
gives a nested table of truth values of expr with the outermost level giving possible combinations of the (Subscript[a, i]).}})

OpenersNotesSection(Spacer1)Details

The possible combinations of variable values are given in the order (RefLink[Tuples, paclet:ref/Tuples])[{(RefLink[True, paclet:ref/True]),(RefLink[False, paclet:ref/False])},n].

(RefLink[BooleanTable, paclet:ref/BooleanTable]) gives a list or array of (RefLink[True, paclet:ref/True]), (RefLink[False, paclet:ref/False]) values.

(RefLink[Boole, paclet:ref/Boole])[BooleanTable[…]] gives 1, 0 values.

In (RefLink[BooleanTable, paclet:ref/BooleanTable])[expr,{(Subscript[a, 1]),(Subscript[a, 2]),…}] etc. any of the variables in expr that are not explicitly among the (Subscript[a, i]) etc. are left in symbolic form.

(RefLink[BooleanTable, paclet:ref/BooleanTable])[expr,(Subscript[vars, 1]),…,(Subscript[vars, s])] is equivalent to (RefLink[Fold, paclet:ref/Fold])[BooleanTable,expr,{(Subscript[vars, s]),…,(Subscript[vars, 1])}].

(RefLink[BooleanTable, paclet:ref/BooleanTable])[bf,{(Subscript[r, 1]),(Subscript[r, 2]),…}] gives a list of truth values corresponding to possible values of the (Subscript[r, 1])(^th), (Subscript[r, 2])(^th), … variables for the Boolean function bf.

(RefLink[BooleanTable, paclet:ref/BooleanTable])[bf,{(Subscript[r, 1]),…},{(Subscript[s, 1]),…},…] gives a nested table of truth values with the outermost level giving combinations of the (Subscript[r, i])(^th) variables.

OpenersPrimaryExamplesSection(Spacer1)Examples  (19)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

The vector of truth values for (RefLink[Or, paclet:ref/Or]):

BooleanTable[p||q,{p,q}]

Convert to 1, 0 form:

Boole[BooleanTable[p||q,{p,q}]]

2D truth table for (RefLink[Or, paclet:ref/Or]):

BooleanTable[p||q,{p},{q}]//TableForm

OpenersExampleSection1(Spacer1)Scope  (6)

Generate a truth table for a Boolean expression:

BooleanTable[And[a,b],{a,b}]

BooleanTable[And[a,b,c],{a,b,c}]

A truth table with arguments and values:

BooleanTable[{a,b,And[a,b]},{a,b}]//TableForm

Vector-valued Boolean expression:

BooleanTable[{And[a,b],Or[a,b],Xor[a,b],Xnor[a,b]},{a,b}]//TableForm

A 2D truth table:

BooleanTable[And[a,b],{a},{b}]

A 3D truth table:

BooleanTable[And[a,b,c],{a},{b},{c}]

Generate a truth table for a pure Boolean function:

BooleanTable[BooleanFunction[30,3]]

BooleanTable[BooleanCountingFunction[2,3]]

BooleanTable[And[#1,#2,#3]&]

Specify the position of arguments to use:

BooleanTable[BooleanFunction[30,3],{3,1,2}]

BooleanTable[BooleanFunction[30,3][a,b,c],{c,a,b}]

Position and grouping of arguments to use:

BooleanTable[BooleanFunction[30,3],{1,2},{3}]

Expressions do not need to produce Boolean values:

BooleanTable[f[a,b],{a,b}]

BooleanTable[{a,b}->And[a,b],{a,b}]

BooleanTable[Xor[a,b,c],{a,b}]

BooleanTable[Graphics[{If[a,Red,Green],If[b,EdgeForm[Yellow],EdgeForm[Blue]],If[c,Disk[],Rectangle[]]},ImageSize->30],{a,b,c}]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

Generate a truth table without explicitly giving a variable list:

t1=BooleanTable[And[c,Or[a,b]]]

The variables and ordering used are given by (RefLink[BooleanVariables, paclet:ref/BooleanVariables]):

v=BooleanVariables[And[c,Or[a,b]]]

t2=BooleanTable[And[c,Or[a,b]],v]

t1===t2

OpenersExampleSection4(Spacer1)Applications  (3)

OpenersExampleSubsection0(Spacer1)Probability  (2)

Compute the probability for an event as the ratio of true cases to total cases:

BooleanProbability[e_,v_]:=Count[BooleanTable[e,v],True]/2^Length[v]

The probabilities for some events:

BooleanProbability[x∧y,{x,y}]

BooleanProbability[Xor[x,y,z,w],{x,y,z,w}]

The probability that exactly three variables are true:

BooleanProbability[BooleanCountingFunction[{3},{x,y,z,u,v}],{x,y,z,u,v}]

Show that Prob(X⋃Y)==Prob(X)+Prob(Y)-Prob(X⋂Y):

BooleanProbability[x∨y,{x,y}]

BooleanProbability[x,{x,y}]+BooleanProbability[y,{x,y}]-BooleanProbability[x∧y,{x,y}]

Assume that you pay 2 units when x∧y and that you earn 1 unit when x⊻y⊻z:

BooleanTable[-2 Boole[x∧y]+Boole[Xor[x,y,z]],{x,y,z}]

The expected earning when it is equally probable that x,y,z are true or false:

Mean[%]

The risk or variance is:

Variance[%%]

OpenersExampleSubsection1(Spacer1)Cellular Automata  (1)

Generate the truth rules for a Boolean expression:

BooleanTable[{a,b,c}->BooleanFunction[30,{a,b,c}],{a,b,c}]

Use the rules to evolve a cellular automaton:

CellularAutomaton[%,{{True},False},2]

CellularAutomaton[30,{{1},0},2]

Boole[%%]

OpenersExampleSection5(Spacer1)Properties & Relations  (6)

A (RefLink[BooleanTable, paclet:ref/BooleanTable]) with n variables has (2^n) elements:

X[n_]:=Array[x,n]

Table[Length@BooleanTable[Xor@@X[n],X[n]],{n,10}]

With n and m variables the resulting matrix has (2^(m+n)) values:

Y[n_]:=Array[y,n]

Table[Dimensions@BooleanTable[Xor@@Join[X[n],Y[m]],X[n],Y[m]],{n,5},{m,5}];

Apply[Times,%,{2}]//MatrixForm

(RefLink[BooleanTable, paclet:ref/BooleanTable]) with several variable iterators evaluates the outermost iterator first: »

f=BooleanFunction[12345,5][a,b,c,d,e]

t1=BooleanTable[f,{a,b},{c,d,e}]

An equivalent form:

t2=Fold[BooleanTable,f,{{c,d,e},{a,b}}]

t1===t2

(RefLink[BooleanTable, paclet:ref/BooleanTable]) enumerates values in the same order as (RefLink[Tuples, paclet:ref/Tuples])[{(RefLink[True, paclet:ref/True]),(RefLink[False, paclet:ref/False])},n]:

BooleanTable[Xor[a,b],{a,b}]

Xor@@@Tuples[{True,False},2]

Three variables:

BooleanTable[Xnor[a,b,c],{a,b,c}]

Xnor@@@Tuples[{True,False},3]

(RefLink[SatisfiabilityCount, paclet:ref/SatisfiabilityCount]) efficiently counts the number of (RefLink[True, paclet:ref/True]) elements in (RefLink[BooleanTable, paclet:ref/BooleanTable]):

Count[BooleanTable[BooleanFunction[200!,10]],True]

SatisfiabilityCount[BooleanFunction[200!,10]]

In this case the (RefLink[BooleanTable, paclet:ref/BooleanTable]) would have (2^1000) elements:

SatisfiabilityCount[BooleanCountingFunction[500,1000]]

Give an enumerated (RefLink[BooleanFunction, paclet:ref/BooleanFunction]):

BooleanFunction[30,3]

Compute its truth table:

Boole[BooleanTable[%]]

The order of enumeration is consistent with (RefLink[FromDigits, paclet:ref/FromDigits]):

FromDigits[%,2]

Use (RefLink[BooleanFunction, paclet:ref/BooleanFunction]) to convert a truth table to a function or expression:

t=BooleanTable[Implies[a,b],{a,b}]

Convert to a Boolean function:

f=BooleanFunction[t]

Use it as any other function:

BooleanTable[f[a,b],{a,b}]

Convert to a disjunctive normal form:

BooleanFunction[t,{a,b}]

Convert to a "NAND" form:

BooleanFunction[t,{a,b},"NAND"]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

The truth table for (RefLink[BooleanCountingFunction, paclet:ref/BooleanCountingFunction]):

f=BooleanCountingFunction[8,16]@@Array[x,16];

ArrayPlot[Boole@BooleanTable[f,Array[x,8],Array[x,8,9]]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Boole, paclet:ref/Boole])  ▪  (RefLink[BooleanFunction, paclet:ref/BooleanFunction])  ▪  (RefLink[SatisfiabilityInstances, paclet:ref/SatisfiabilityInstances])  ▪  (RefLink[Array, paclet:ref/Array])  ▪  (RefLink[CellularAutomaton, paclet:ref/CellularAutomaton])  ▪  (RefLink[RulePlot, paclet:ref/RulePlot])}, {Related Formats:  (StringTypeLink[Table, paclet:ref/format/Table])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Boolean Computation, paclet:guide/BooleanComputation])}, {▪(RefLinkPlain[Computational Systems, paclet:guide/ComputationalSystemsAndDiscovery])}})}})