This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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

Project Description

Synopsis

tt is a library aiming to provide a Pythonic toolkit 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

Features

tt lets you do a few things with your prized Boolean expressions. Let’s start by parsing one:

>>> from tt import BooleanExpression
>>> b = BooleanExpression('A impl not (B nand C)')
>>> b.tokens
['A', 'impl', 'not', '(', 'B', 'nand', 'C', ')']
>>> b.symbols
['A', 'B', 'C']
>>> print(b.tree)
impl
`----A
`----not
     `----nand
          `----B
          `----C

Then transform it a couple of times:

>>> from tt import apply_de_morgans, to_cnf, to_primitives
>>> b = to_primitives(b)
>>> b
<BooleanExpression "not A or not (not B or not C)">
>>> b = apply_de_morgans(b)
>>> b
<BooleanExpression "not A or (not not B and not not C)">
>>> b = to_cnf(b)
>>> b
<BooleanExpression "(not A or B) and (not A or C)">

Poke around its structure:

>>> b.is_cnf
True
>>> b.is_dnf
False
>>> for clause in b.iter_clauses():
...     print(clause)
...
not A or B
not A or C

Find all of its SAT solutions:

>>> for sat_solution in b.sat_all():
...     print(sat_solution)
...
A=0, B=1, C=1
A=0, B=1, C=0
A=0, B=0, C=1
A=0, B=0, C=0
A=1, B=1, C=1

Or just find one:

>>> with b.constrain(A=1):
...     b.sat_one()
...
<BooleanValues [A=1, B=1, C=1]>

Turn it into a truth table:

>>> from tt import TruthTable
>>> t = TruthTable(b)
>>> print(t)
+---+---+---+---+
| A | B | C |   |
+---+---+---+---+
| 0 | 0 | 0 | 1 |
+---+---+---+---+
| 0 | 0 | 1 | 1 |
+---+---+---+---+
| 0 | 1 | 0 | 1 |
+---+---+---+---+
| 0 | 1 | 1 | 1 |
+---+---+---+---+
| 1 | 0 | 0 | 0 |
+---+---+---+---+
| 1 | 0 | 1 | 0 |
+---+---+---+---+
| 1 | 1 | 0 | 0 |
+---+---+---+---+
| 1 | 1 | 1 | 1 |
+---+---+---+---+

And compare it to another truth table:

>>> other_table = TruthTable(from_values='111x00x1')
>>> other_table.ordering
['A', 'B', 'C']
>>> for inputs, result in other_table:
...     print(inputs, '=>', result)
...
A=0, B=0, C=0 => True
A=0, B=0, C=1 => True
A=0, B=1, C=0 => True
A=0, B=1, C=1 => x
A=1, B=0, C=0 => False
A=1, B=0, C=1 => False
A=1, B=1, C=0 => x
A=1, B=1, C=1 => True
>>> other_table.equivalent_to(t)
True

License

tt uses the MIT License.

Release History

Release History

This version
History Node

0.6.2

History Node

0.6.1

History Node

0.6.0

History Node

0.5.1

History Node

0.5.0

History Node

0.4.1

History Node

0.3

History Node

0.2

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ttable-0.6.2-cp27-cp27m-win32.whl (71.9 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Jun 9, 2017
ttable-0.6.2-cp27-cp27m-win_amd64.whl (78.5 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Jun 9, 2017
ttable-0.6.2-cp33-cp33m-win32.whl (73.4 kB) Copy SHA256 Checksum SHA256 cp33 Wheel Jun 9, 2017
ttable-0.6.2-cp33-cp33m-win_amd64.whl (79.9 kB) Copy SHA256 Checksum SHA256 cp33 Wheel Jun 9, 2017
ttable-0.6.2-cp34-cp34m-win32.whl (73.4 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Jun 9, 2017
ttable-0.6.2-cp34-cp34m-win_amd64.whl (79.9 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Jun 9, 2017
ttable-0.6.2-cp35-cp35m-win32.whl (69.2 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Jun 9, 2017
ttable-0.6.2-cp35-cp35m-win_amd64.whl (75.1 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Jun 9, 2017
ttable-0.6.2-cp36-cp36m-win32.whl (69.2 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Jun 9, 2017
ttable-0.6.2-cp36-cp36m-win_amd64.whl (75.1 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Jun 9, 2017
ttable-0.6.2.tar.gz (699.7 kB) Copy SHA256 Checksum SHA256 Source Jun 9, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting