Skip to main content

A library and command-line tool for working with Boolean expressions

Project description

tt's PyPI page Mac/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 as well as PyPy. tt 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

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')
>>> for inputs, result in t:
...     inputs, result
...
((False, False), False)
((False, True), True)
((True, False), 'x')
((True, True), 'x')
>>> t.equivalent_to(b)
True

License

tt uses the MIT License.

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

ttable-0.5.1.tar.gz (586.7 kB view hashes)

Uploaded Source

Built Distribution

ttable-0.5.1-py2.py3-none-any.whl (25.5 kB view hashes)

Uploaded Python 2 Python 3

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