Skip to main content
Logo image

Discrete Math with SageMath: Learn math with open-source software

Section 4.2 Truth Tables

The truthtable() function generates the truth table for a given logical expression.
Alternatively, for improved separation and visual clarity, generate truth tables using SymbolicLogic(), statement(), truthtable() and the print_table().
We can also analyze logical expressions involving three variables.
Note that if the list of variables becomes longer (e.g., extending beyond the width of a LaTeX page), the truth table’s columns may run off the screen. Additionally, the function’s performance may degrade as the expression becomes more complex, potentially increasing the computation time.