# ttable 0.6.2

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

## 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
```

tt uses the MIT License.

File Type Py Version Uploaded on Size
Python Wheel cp27 2017-06-09 70KB
Python Wheel cp27 2017-06-09 76KB
Python Wheel cp33 2017-06-09 71KB
Python Wheel cp33 2017-06-09 78KB
Python Wheel cp34 2017-06-09 71KB
Python Wheel cp34 2017-06-09 78KB
Python Wheel cp35 2017-06-09 67KB
Python Wheel cp35 2017-06-09 73KB
Python Wheel cp36 2017-06-09 67KB
Python Wheel cp36 2017-06-09 73KB
Source 2017-06-09 683KB