Package: truths
truths is a simple tool that allows you to quickly generate a truth
table from python variable names and phrasesinstallpip install truthsorgit cloneandpip install-eto play
with the codeuse is simple:start by creating some base variablesimporttruthsprinttruths.Truths(['a','b','x'])+---+---+---+
| a | b | x |
+---+---+---+
| 0 | 0 | 0 |
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| 1 | 1 | 1 |
+---+---+---+add some phrasesnow let’s use those base variables and pass in some phrases! your base
variables can be anything you want but must be valid python variable
names. the phrases also have to be valid pythonfromtruthsimportTruthsprintTruths(['a','b','cat','has_address'],['(a and b)','a and b or cat','a and (b or cat) or has_address'])+---+---+-----+-------------+-----------+----------------+---------------------------------+
| a | b | cat | has_address | (a and b) | a and b or cat | a and (b or cat) or has_address |
+---+---+-----+-------------+-----------+----------------+---------------------------------+
| 0 | 0 |  0  |      0      |     0     |       0        |                0                |
| 0 | 0 |  0  |      1      |     0     |       0        |                1                |
| 0 | 0 |  1  |      0      |     0     |       1        |                0                |
| 0 | 0 |  1  |      1      |     0     |       1        |                1                |
| 0 | 1 |  0  |      0      |     0     |       0        |                0                |
| 0 | 1 |  0  |      1      |     0     |       0        |                1                |
| 0 | 1 |  1  |      0      |     0     |       1        |                0                |
| 0 | 1 |  1  |      1      |     0     |       1        |                1                |
| 1 | 0 |  0  |      0      |     0     |       0        |                0                |
| 1 | 0 |  0  |      1      |     0     |       0        |                1                |
| 1 | 0 |  1  |      0      |     0     |       1        |                1                |
| 1 | 0 |  1  |      1      |     0     |       1        |                1                |
| 1 | 1 |  0  |      0      |     1     |       1        |                1                |
| 1 | 1 |  0  |      1      |     1     |       1        |                1                |
| 1 | 1 |  1  |      0      |     1     |       1        |                1                |
| 1 | 1 |  1  |      1      |     1     |       1        |                1                |
+---+---+-----+-------------+-----------+----------------+---------------------------------+prefer boolean words?neat eh? if you prefer True/False over the numbers passints=False:fromtruthsimportTruthsprintTruths(['a','b','x','d'],['(a and b)','a and b or x','a and (b or x) or d'],ints=False)+-------+-------+-------+-------+-----------+--------------+---------------------+
|   a   |   b   |   x   |   d   | (a and b) | a and b or x | a and (b or x) or d |
+-------+-------+-------+-------+-----------+--------------+---------------------+
| False | False | False | False |   False   |    False     |        False        |
| False | False | False |  True |   False   |    False     |         True        |
| False | False |  True | False |   False   |     True     |        False        |
| False | False |  True |  True |   False   |     True     |         True        |
| False |  True | False | False |   False   |    False     |        False        |
| False |  True | False |  True |   False   |    False     |         True        |
| False |  True |  True | False |   False   |     True     |        False        |
| False |  True |  True |  True |   False   |     True     |         True        |
|  True | False | False | False |   False   |    False     |        False        |
|  True | False | False |  True |   False   |    False     |         True        |
|  True | False |  True | False |   False   |     True     |         True        |
|  True | False |  True |  True |   False   |     True     |         True        |
|  True |  True | False | False |    True   |     True     |         True        |
|  True |  True | False |  True |    True   |     True     |         True        |
|  True |  True |  True | False |    True   |     True     |         True        |
|  True |  True |  True |  True |    True   |     True     |         True        |
+-------+-------+-------+-------+-----------+--------------+---------------------+how it workscheck out the code! behind the scenes it’s putting the bases in an
object context and generating a grid of values for them. then, the
phrases areevaluated in the object’s context against each row in
that grid of values