September 2014
Intermediate to advanced
512 pages
12h 39m
English
The logic module in SymPy lets us manipulate complex Boolean expressions, also known as propositional formulas.
This recipe will show an example where this module can be useful. Let's suppose that, in a program, we need to write a complex if statement depending on three Boolean variables. We can think about each of the eight possible cases (true, true and false, and so on) and evaluate what the outcome should be. SymPy offers a function to generate a compact logic expression that satisfies our truth table.
In [1]: from sympy import *
init_printing()In [2]: var('x y z')Read now
Unlock full access