tt - the Boolean expression toolbox

Welcome to the documentation site for tt.


Warning

tt is heavily tested and fully usable, but is still pre-1.0/stable software with no guarantees of avoiding breaking API changes until hitting version 1.0.

tt's PyPI page Linux build on Travis CI Windows build on AppVeyor

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 is tested on CPython 2.7, 3.3, 3.4, 3.5, and 3.6. You can get the latest release from PyPI with:

pip install ttable

Basic Usage

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(from_values='01xx')
>>> t.ordering
['A', 'B']
>>> for inputs, result in t:
...     inputs, result
...
(<BooleanValues [A=0, B=0]>, False)
(<BooleanValues [A=0, B=1]>, True)
(<BooleanValues [A=1, B=0]>, 'x')
(<BooleanValues [A=1, B=1]>, 'x')
>>> t.equivalent_to(b)
True

License

tt uses the MIT License.

Want to learn more?

If you’re just getting started and looking for tutorial-style documentation, head on over to the User Guide. If you would prefer a comprehensive view of the tools tt provided, check out the autogenerated API docs: