Synopsis
tt is a Python library and command-line tool for working with Boolean expressions. Please check out the project site for more information.
Installation
tt has been tested with Python 2.7, 3.3, 3.4, and 3.5 and is written in pure Python with no dependencies, so it only requires a compatible Python installation to run. You can get the latest release from PyPI with:
pip install ttable
Basic Usage
Below are a couple of examples to show you the kind of things tt can do. For more examples and further documentation, take a look at the project site.
As a Library
tt aims to provide a Pythonic interface for working with Boolean expressions. Here are some simple examples from the REPL:
>>> from tt import BooleanExpression, TruthTable
>>> b = BooleanExpression('A xor (B and 1)')
>>> b.tokens
['A', 'xor', '(', 'B', 'and', '1', ')']
>>> b.symbols
['A', 'B']
>>> print(b.tree)
xor
`----A
`----and
`----B
`----1
>>> b.evaluate(A=True, B=False)
True
>>> t = TruthTable(b)
>>> print(t)
+---+---+---+
| A | B | |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
| 1 | 0 | 1 |
+---+---+---+
| 1 | 1 | 0 |
+---+---+---+
>>> t = TruthTable('A or B', fill_all=False)
>>> print(t)
Empty!
>>> t.fill(A=0)
>>> print(t)
+---+---+---+
| A | B | |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
>>> t.fill(A=1)
>>> print(t)
+---+---+---+
| A | B | |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
| 1 | 0 | 1 |
+---+---+---+
| 1 | 1 | 1 |
+---+---+---+
From the Command Line
tt also provides a command-line interface for working with expressions. Here are a couple of examples:
$ tt tokens "(op1 nand op2) xnor op3"
(
op1
nand
op2
)
xnor
op3
$ tt table A or B
+---+---+---+
| A | B | |
+---+---+---+
| 0 | 0 | 0 |
+---+---+---+
| 0 | 1 | 1 |
+---+---+---+
| 1 | 0 | 1 |
+---+---+---+
| 1 | 1 | 1 |
+---+---+---+
$ tt tree A or or B
Error! Unexpected binary operator "or":
A or or B
^
License
tt uses the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ttable-0.4.1-py2.py3-none-any.whl.
File metadata
- Download URL: ttable-0.4.1-py2.py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4cb19e6059cbea5495170c70f54bd15d10da48389f5460117def4a02e95765e
|
|
| MD5 |
3f3b6119cabe958875f01d41033af603
|
|
| BLAKE2b-256 |
13cc29ae3f0705b2e276341b29875eaadf6eec9e8470680c16babd922f0c1d3f
|