Implements boolean algebra in one module.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
boolean Improve error checking when parsing Aug 6, 2018
docs
.gitignore
.travis.yml
CHANGELOG.rst Bump version Feb 9, 2017
LICENSE.txt
MANIFEST.in
README.md
setup.cfg
setup.py
test-requirements.txt Fix `tox=2.7.0` -> `tox==2.7.0` in test-requirements.txt Jun 6, 2017
tox.ini

README.md

boolean.py

"boolean.py" is a small library implementing a boolean algebra. It defines two base elements, TRUE and FALSE, and a Symbol class that can take on one of these two values. Calculations are done in terms of AND, OR and NOT - other compositions like XOR and NAND are not implemented but can be emulated with AND or and NOT. Expressions are constructed from parsed strings or in Python.

It runs on Python 2.7 and Python 3.

https://github.com/bastikr/boolean.py

Build status: Build Status

Example

    >>> import boolean
    >>> algebra = boolean.BooleanAlgebra()
    >>> expression1 = algebra.parse(u'apple and (oranges or banana) and not banana', simplify=False)
    >>> expression1
    AND(Symbol('apple'), OR(Symbol('oranges'), Symbol('banana')), NOT(Symbol('banana')))

    >>> expression2 = algebra.parse(u'(oranges | banana) and not banana & apple', simplify=True)
    >>> expression2
    AND(Symbol('apple'), NOT(Symbol('banana')), Symbol('oranges'))

    >>> expression1 == expression2
    False
    >>> expression1.simplify() == expression2
    True    

Documentation

http://readthedocs.org/docs/booleanpy/en/latest/

Installation

pip install boolean.py

Testing

Test boolean.py with your current Python environment:

python setup.py test

Test with all of the supported Python environments using tox:

pip install -r test-requirements.txt
tox

If tox throws InterpreterNotFound, limit it to python interpreters that are actually installed on your machine:

tox -e py27,py36

License

Simplified BSD License