Skip to main content

auto generate truth tables

Project description

truths is a simple tool that allows you to quickly generate a truth table from python variable names and phrases

install

pip install truths or git clone and pip install -e to play with the code

use is simple:

start by creating some base variables

import truths
print truths.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 phrases

now 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 python

from truths import Truths
print Truths(['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 pass ints=False:

from truths import Truths
print Truths(['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 works

check 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 are evaluated in the object’s context against each row in that grid of values

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

truths-1.2.tar.gz (7.6 kB view details)

Uploaded Source

File details

Details for the file truths-1.2.tar.gz.

File metadata

  • Download URL: truths-1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for truths-1.2.tar.gz
Algorithm Hash digest
SHA256 99287a3da4f8982b90613f0aafae5fa94fc001560fa881ec3c8ea3963ed8362b
MD5 24d07f68ad2b0718f42529ca596ffd93
BLAKE2b-256 3f5abbdd1bd5caebb13cbbe23a4a4b7458e449235c8e8ea7075a34a48676ace7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page