#!/usr/bin/env python # coding: utf-8 # > This is one of the 100 recipes of the [IPython Cookbook](http://ipython-books.github.io/), the definitive guide to high-performance scientific computing and data science in Python. # # # 15.6. Finding a Boolean propositional formula from a truth table # In[ ]: from sympy import * init_printing() # Let's define a few variables. # In[ ]: var('x y z') # We can define propositional formulas with symbols and a few operators. # In[ ]: P = x & (y | ~z); P # In[ ]: P.subs({x: True, y: False, z: True}) # Now, we want to find a propositional formula depending on x, y, z, with the following truth table: # In[1]: get_ipython().run_cell_magic('HTML', '', '\n
x | y | z | ?? | \n
---|---|---|---|
T | T | T | * | \n
T | T | F | * | \n
T | F | T | T | \n
T | F | F | T | \n
F | T | T | F | \n
F | T | F | F | \n
F | F | T | F | \n
F | F | F | T | \n