Truth Table
A truth table is a two-dimensional array with
columns. The
first
columns correspond to the possible values of
inputs, and the last column to the operation being performed.
The rows list all possible combinations of inputs together with the corresponding
outputs. For example, the following truth table shows the result of the binary AND operator acting on two inputs
and
, each of which
may be true or false.
| F | F | F |
| F | T | F |
| T | F | F |
| T | T | T |
The following Wolfram Language code can be used to generate a truth table for n levels of operator op.
TruthTable[op_, n_] := Module[
{
l = Flatten[Outer[List, Sequence @@
Table[{True, False}, {n}]], n - 1],
a = Array[A, n]
},
DisplayForm[
GridBox[Prepend[Append[#, op @@ #]& /@ l,
Append[a, op @@ a]],
RowLines -> True, ColumnLines -> True]
]
]
truth table



