Skip to main content

Python Electronic Design Automation

Project description

PyEDA is a Python library for electronic design automation.

Read the docs!

https://travis-ci.org/cjdrake/pyeda.png?branch=master

Features

  • Symbolic Boolean algebra with a selection of function representations:

    • Logic expressions

    • Truth tables, with three output states (0, 1, “don’t care”)

    • Reduced, ordered binary decision diagrams (ROBDDs)

  • SAT solvers:

  • Formal equivalence

  • Multi-dimensional bit vectors

  • DIMACS CNF/SAT parsers

  • Logic expression parser

Download

Bleeding edge code:

$ git clone git://github.com/cjdrake/pyeda.git

For release tarballs and zipfiles, visit PyEDA’s page at the Cheese Shop.

Installation

Latest released version using setuptools:

$ easy_install pyeda

Latest release version using pip:

$ pip install pyeda

Installation from the repository:

$ python setup.py install

Logic Expressions

Invoke your favorite Python terminal, and invoke an interactive pyeda session:

>>> from pyeda.inter import *

Create some Boolean expression variables:

>>> a, b, c, d = map(exprvar, "abcd")

Construct Boolean functions using overloaded Python operators: - (NOT), + (OR), * (AND), >> (IMPLIES):

>>> f0 = -a * b + c * -d
>>> f1 = a >> b
>>> f2 = -a * b + a * -b
>>> f3 = -a * -b + a * b
>>> f4 = -a * -b * -c + a * b * c
>>> f5 = a * b + -a * c

Construct Boolean functions using standard function syntax:

>>> f10 = Or(And(Not(a), b), And(c, Not(d)))
>>> f11 = Implies(a, b)
>>> f12 = Xor(a, b)
>>> f13 = Xnor(a, b)
>>> f14 = Equal(a, b, c)
>>> f15 = ITE(a, b, c)

Construct Boolean functions using higher order operators:

>>> f20 = Nor(a, b, c)
>>> f21 = Nand(a, b, c)
>>> f22 = OneHot(a, b, c)
>>> f23 = OneHot0(a, b, c)

Investigate a function’s properties:

>>> f0.support
frozenset([a, b, c, d])
>>> f0.inputs
(a, b, c, d)
>>> f0.top
a
>>> f0.degree
4
>>> f0.cardinality
16
>>> f0.depth
2

Factor complex expressions into only OR/AND and literals:

>>> f11.factor()
a' + b
>>> f12.factor()
a' * b + a * b'
>>> f13.factor()
a' * b' + a * b
>>> f14.factor()
a' * b' * c' + a * b * c
>>> f15.factor()
a * b + a' * c

Restrict a function’s input variables to fixed values, and perform function composition:

>>> f0.restrict({a: 0, c: 1})
b + d'
>>> f0.compose({a: c, b: -d})
c' * d' + c * d'

Test function formal equivalence:

>>> f2.equivalent(f12)
True
>>> f4.equivalent(f14)
True

Investigate Boolean identities:

# Law of double complement
>>> --a
a

# Idempotent laws
>>> a + a
a
>>> a * a
a

# Identity laws
>>> a + 0
a
>>> a * 1
a

# Dominance laws
>>> a + 1
1
>>> a * 0
0

# Commutative laws
>>> (a + b).equivalent(b + a)
True
>>> (a * b).equivalent(b * a)
True

# Associative laws
>>> a + (b + c)
a + b + c
>>> a * (b * c)
a * b * c

# Distributive laws
>>> (a + (b * c)).to_cnf()
(a + b) * (a + c)
>>> (a * (b + c)).to_dnf()
a * b + a * c

# De Morgan's laws
>>> Not(a + b).factor()
a' * b'
>>> Not(a * b).factor()
a' + b'

# Absorption laws
>>> (a + (a * b)).absorb()
a
>>> (a * (a + b)).absorb()
a

Perform Shannon expansions:

>>> a.expand(b)
a * b' + a * b
>>> (a * b).expand([c, d])
a * b * c' * d' + a * b * c' * d + a * b * c * d' + a * b * c * d

Convert a nested expression to disjunctive normal form:

>>> f = a * (b + (c * d))
>>> f.depth
3
>>> g = f.to_dnf()
>>> g
a * b + a * c * d
>>> g.depth
2
>>> f.equivalent(g)
True

Convert between disjunctive and conjunctive normal forms:

>>> f = -a * -b * c + -a * b * -c + a * -b * -c + a * b * c
>>> g = f.to_cnf()
>>> h = g.to_dnf()
>>> g
(a + b + c) * (a + b' + c') * (a' + b + c') * (a' + b' + c)
>>> h
a' * b' * c + a' * b * c' + a * b' * c' + a * b * c

Multi-Dimensional Bit Vectors

Create some four-bit vectors, and use slice operators:

>>> A = bitvec('A', 4)
>>> B = bitvec('B', 4)
>>> A
[A[0], A[1], A[2], A[3]]
>>> A[2:]
[A[2], A[3]]
>>> A[-3:-1]
[A[1], A[2]]

Perform bitwise operations using Python overloaded operators: ~ (NOT), | (OR), & (AND), ^ (XOR):

>>> ~A
[A[0]', A[1]', A[2]', A[3]']
>>> A | B
[A[0] + B[0], A[1] + B[1], A[2] + B[2], A[3] + B[3]]
>>> A & B
[A[0] * B[0], A[1] * B[1], A[2] * B[2], A[3] * B[3]]
>>> A ^ B
[Xor(A[0], B[0]), Xor(A[1], B[1]), Xor(A[2], B[2]), Xor(A[3], B[3])]

Reduce bit vectors using unary OR, AND, XOR:

>>> A.uor()
A[0] + A[1] + A[2] + A[3]
>>> A.uand()
A[0] * A[1] * A[2] * A[3]
>>> A.uxor()
Xor(A[0], A[1], A[2], A[3])

Create and test functions that implement non-trivial logic such as arithmetic:

>>> from pyeda.logic.addition import *
>>> S, C = ripple_carry_add(A, B)
# Note "1110" is LSB first. This says: "7 + 1 = 8".
>>> S.vrestrict({A: "1110", B: "1000"}).to_uint()
8

Other Function Representations

Consult the documentation for information about truth tables, and binary decision diagrams. Each function representation has different trade-offs, so always use the right one for the job.

PicoSAT SAT Solver C Extension

PyEDA includes an extension to the industrial-strength PicoSAT SAT solving engine.

Use the satisfy_one method to finding a single satisfying input point:

>>> f = OneHot(a, b, c)
>>> f.satisfy_one()
{a: 0, b: 0, c: 1}

Use the satisfy_all method to iterate through all satisfying input points:

>>> list(f.satisfy_all())
[{a: 0, b: 0, c: 1}, {a: 0, b: 1, c: 0}, {a: 1, b: 0, c: 0}]

For more interesting examples, see the following documentation chapters:

Execute Unit Test Suite

If you have Nose installed, run the unit test suite with the following command:

$ make test

If you have Coverage installed, generate a coverage report (including HTML) with the following command:

$ make cover

Perform Static Lint Checks

If you have Pylint installed, perform static lint checks with the following command:

$ make lint

Build the Documentation

If you have Sphinx installed, build the HTML documentation with the following command:

$ make html

Python Versions Supported

PyEDA is developed using Python 3.2+. It is NOT compatible with Python 2.7.

Contact the Authors

Project details


Download files

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

Source Distributions

pyeda-0.18.0.zip (150.7 kB view details)

Uploaded Source

pyeda-0.18.0.tar.gz (133.5 kB view details)

Uploaded Source

pyeda-0.18.0.tar.bz2 (114.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyeda-0.18.0.win-amd64-py3.3.exe (327.5 kB view details)

Uploaded Source

pyeda-0.18.0.win-amd64-py3.2.exe (329.5 kB view details)

Uploaded Source

pyeda-0.18.0.win32-py3.3.exe (287.7 kB view details)

Uploaded Source

pyeda-0.18.0.win32-py3.2.exe (292.8 kB view details)

Uploaded Source

File details

Details for the file pyeda-0.18.0.zip.

File metadata

  • Download URL: pyeda-0.18.0.zip
  • Upload date:
  • Size: 150.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyeda-0.18.0.zip
Algorithm Hash digest
SHA256 cd1877d912561386c0a701cc878ceb15e103d120fb0db27a4136016fe44202a9
MD5 791443ebc8f788f70d68ecdb83c02a8e
BLAKE2b-256 b668cb18501cf881787fe952979cde0f584d356caffb8769734704dab3c737f4

See more details on using hashes here.

File details

Details for the file pyeda-0.18.0.tar.gz.

File metadata

  • Download URL: pyeda-0.18.0.tar.gz
  • Upload date:
  • Size: 133.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyeda-0.18.0.tar.gz
Algorithm Hash digest
SHA256 93da895a7de0471523b54f18a2485a4887131e90547a30384e4ec1839b68ab4e
MD5 41dbd621d00883c07915d4173ffed866
BLAKE2b-256 b725d39efde34d7a00ffc6dbfcb8c06ed05eedd01dd1324ae9f29cb177ef0f06

See more details on using hashes here.

File details

Details for the file pyeda-0.18.0.tar.bz2.

File metadata

  • Download URL: pyeda-0.18.0.tar.bz2
  • Upload date:
  • Size: 114.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyeda-0.18.0.tar.bz2
Algorithm Hash digest
SHA256 dddaaa5d2d432831e94ef157c1cb478782c11e01e001e1f95bb5858cb433db37
MD5 217defaf9d470b0ddb530e0868d2e0bb
BLAKE2b-256 d6cb046fe725e8c57fc897bef9dce427401ff567898a97be00ce5048c4ef6163

See more details on using hashes here.

File details

Details for the file pyeda-0.18.0.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for pyeda-0.18.0.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 5b9ca1fe2002b6107521741ac713613717bf7b079e17ec699411dbbc5e42403a
MD5 ef03c04467e34ddb6d6e965abdaefe65
BLAKE2b-256 f450fe771a7e2db8bc2fc08f46a7bcd8b973f058920c361591fb73f2f96c7d37

See more details on using hashes here.

File details

Details for the file pyeda-0.18.0.win-amd64-py3.2.exe.

File metadata

File hashes

Hashes for pyeda-0.18.0.win-amd64-py3.2.exe
Algorithm Hash digest
SHA256 668ba0b650c8d1822d8bf1504852c7cd1f129dd544126196c564470d181c0803
MD5 328848f4575e70fcca2a1e1f033edd9b
BLAKE2b-256 6294abf18ce21deec48d442441a26e136379eee62d07bee3db5dfdf149746359

See more details on using hashes here.

File details

Details for the file pyeda-0.18.0.win32-py3.3.exe.

File metadata

File hashes

Hashes for pyeda-0.18.0.win32-py3.3.exe
Algorithm Hash digest
SHA256 c81847f782c0725eb89e5d893d2e546b467dad7b518e24656952f63b3b32e63c
MD5 256f0290c237cf93a8e250c2fbc15b53
BLAKE2b-256 fef32d0bfc115ad1583535fb9c65d9321f47e89d69df40e5e5c9ecf203373bfb

See more details on using hashes here.

File details

Details for the file pyeda-0.18.0.win32-py3.2.exe.

File metadata

File hashes

Hashes for pyeda-0.18.0.win32-py3.2.exe
Algorithm Hash digest
SHA256 a00cdd091cf06a692310bdbb442cebda8da354e999f81a25b10ac8ca2b240907
MD5 79cff2a9b9be93522a46a3dd5dbd831b
BLAKE2b-256 4ee8fbf8bd342789c8ec31a974310c0961b9ddc7037ea57058ab9c34c18dc812

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page