Skip to main content

Data set of optimal circuits for Boolean functions that have low arity.

Project description

Data set of optimal circuits for Boolean functions that have low arity.

PyPI version and link. Read the Docs documentation status. GitHub Actions status. Coveralls test coverage summary.

Package Installation and Usage

The package is available on PyPI:

python -m pip install circuitdb

The library can be imported in the usual ways:

import circuitdb
from circuitdb import circuitdb

Examples

This library provides a database that contains an (arbitrary but fixed) example of the smallest possible logical circuit (in terms of the number of unary and/or binary gates) for each possible logical function (from a finite set of functions). Logical functions are represented using tuples, as in the logical library. In the example below, a circuit is retrieved for the function f (x, y, z) = x and y and z corresponding to the truth table (0, 0, 0, 0, 0, 0, 0, 1):

>>> from circuitdb import circuitdb
>>> circuitdb((0, 0, 0, 0, 0, 0, 0, 1))
[((0, 1),), ((0, 1),), ((0, 1),), ((0, 0, 0, 1), 0, 1), ((0, 0, 0, 1), 2, 3), ((0, 1), 4)]

The representation of the circuit above consists of a list of unary and binary gates. Each gate is represented as a tuple. The first entry in each gate tuple is the logical function corresponding to that gate (represented using the logical library). The remaining entries in the gate tuple are the indices of the input gates to that gate. For example, the entry ((0, 0, 0, 1), 2, 3) represents a gate that is a conjunction of the gates at positions 2 and 3 in the overall list.

For any given logical function, it is possible to construct a corresponding circuit using a variety of gate sets. For each function, the database contains an example of a smallest circuit for each of a small collection of sets of unary and binary gates. In the remaining examples below, circuits for the function (0, 0, 1, 0, 0, 0, 0, 1) are retrieved. All gates in the circuit below are found in the set {logical.id_, logical.not_, logical.and_, logical.or_}:

>>> from logical import logical
>>> circuitdb((0, 0, 1, 0, 0, 0, 0, 1), frozenset([logical.id_, logical.not_, logical.and_, logical.or_]))
[((0, 1),), ((0, 1),), ((0, 1),), ((0, 0, 0, 1), 0, 2), ((0, 1, 1, 1), 0, 2), ((1, 0), 4), ((0, 1, 1, 1), 3, 5), ((0, 0, 0, 1), 1, 6), ((0, 1), 7)]

All gates in the circuit below are found in the set {logical.id_, logical.not_, logical.and_, logical.xor_}:

>>> circuitdb((0, 0, 1, 0, 0, 0, 0, 1), frozenset([logical.id_, logical.not_, logical.and_, logical.xor_]))
[((0, 1),), ((0, 1),), ((0, 1),), ((1, 0), 0), ((0, 1, 1, 0), 2, 3), ((0, 0, 0, 1), 1, 4), ((0, 1), 5)]

By default (or if the set of all gates logical.every is specified), a smallest circuit that can be built using any combination of unary or binary gates is returned:

>>> circuitdb((0, 0, 1, 0, 0, 0, 0, 1))
[((0, 1),), ((0, 1),), ((0, 1),), ((0, 1, 1, 0), 0, 2), ((0, 0, 1, 0), 1, 3), ((0, 1), 4)]

Documentation

The documentation can be generated automatically from the source files using Sphinx:

cd docs
python -m pip install -r requirements.txt
sphinx-apidoc -f -E --templatedir=_templates -o _source .. ../setup.py && make html

Testing and Conventions

All unit tests are executed and their coverage is measured when using pytest (see setup.cfg for configuration details):

python -m pip install pytest pytest-cov
python -m pytest

Alternatively, all unit tests are included in the module itself and can be executed using doctest:

python circuitdb/circuitdb.py -v

Style conventions are enforced using Pylint:

python -m pip install pylint
python -m pylint circuitdb

Contributions

In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.

Versioning

The version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.

Publishing

This library can be published as a package on PyPI by a package maintainer. Install the wheel package, remove any old build/distribution files, and package the source into a distribution archive:

python -m pip install wheel
rm -rf dist *.egg-info
python setup.py sdist bdist_wheel

Next, install the twine package and upload the package distribution archive to PyPI:

python -m pip install twine
python -m twine upload dist/*

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

circuitdb-1.2.0.tar.gz (23.4 kB view hashes)

Uploaded Source

Built Distribution

circuitdb-1.2.0-py3-none-any.whl (22.6 kB view hashes)

Uploaded 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