Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate a truth table for a Boolean expression
| ResourceFunction["TruthTable"][expr,vars] creates a truth table for the logical expression expr with respect to vars. | 
Produce a truth table for a simple logical expression:
| In[1]:= | ![ResourceFunction["TruthTable"][p && q, {p, q}]](https://www.wolframcloud.com/obj/resourcesystem/images/292/2921b60c-bbfd-437a-94f4-d131eacb5c2a/597a622aa1a8ec75.png) | 
| Out[1]= |  | 
You can also build up larger expressions:
| In[2]:= | ![ResourceFunction[
 "TruthTable"][((p && q) || (r && p)) && (r || q), {p, q, r}]](https://www.wolframcloud.com/obj/resourcesystem/images/292/2921b60c-bbfd-437a-94f4-d131eacb5c2a/42cfba92755ac105.png) | 
| Out[2]= |  | 
TruthTable also accepts raw BooleanFunction inputs and produces an explicit logical expression for the function:
| In[3]:= | ![ResourceFunction["TruthTable"][BooleanFunction[3, 3], "GridForm"]](https://www.wolframcloud.com/obj/resourcesystem/images/292/2921b60c-bbfd-437a-94f4-d131eacb5c2a/30376024f6eab33f.png) | 
| Out[3]= |  | 
Display the same result using the list format:
| In[4]:= | ![ResourceFunction["TruthTable"][BooleanFunction[3, 3], "ListForm"]](https://www.wolframcloud.com/obj/resourcesystem/images/292/2921b60c-bbfd-437a-94f4-d131eacb5c2a/6be4e9ea1620fcd9.png) | 
| Out[4]= |  | 
Show DeMorgan's law by comparing two logical expressions:
| In[5]:= | ![ResourceFunction["TruthTable"][{! (p && q), ! p || ! q}, {p, q}]](https://www.wolframcloud.com/obj/resourcesystem/images/292/2921b60c-bbfd-437a-94f4-d131eacb5c2a/58cdffc2630ace38.png) | 
| Out[5]= |  | 
Show that Implies is not associative by comparing the truth tables of two expressions:
| In[6]:= | ![ResourceFunction[
 "TruthTable"][{(p \[Implies] q) \[Implies] r, p \[Implies] (q \[Implies] r)}, {p, q, r}]](https://www.wolframcloud.com/obj/resourcesystem/images/292/2921b60c-bbfd-437a-94f4-d131eacb5c2a/1cb46ce1079d68fa.png) | 
| Out[6]= |  | 
Use a truth table to easily determine if multiple logical expressions are equivalent:
| In[7]:= | ![ResourceFunction[
 "TruthTable"][{p \[Implies] (q \[Implies] r), ! p || ! q || r, ! (q \[Implies] r) \[Implies] ! p, q && ! r \[Implies] ! p, ! (q && ! r) || ! p}, {p, q, r}]](https://www.wolframcloud.com/obj/resourcesystem/images/292/2921b60c-bbfd-437a-94f4-d131eacb5c2a/2058abc8b4b4f62a.png) | 
| Out[7]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License