Truth Table

A truth table is a two-dimensional array with n+1 columns. The first n columns correspond to the possible values of n 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 A and B, each of which may be true or false.

ABA ^ B
FFF
FTF
TFF
TTT

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]
    ]
  ]

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.