A Python implementation of the Quine McCluskey algorithm



The QuineMcCluskey Python class minimises boolean functions to a sum of products. This implementation of the Quine McCluskey algorithm has no inherent limits (other than the calculation time) on the size of the inputs.

Also, in the limited tests of the author of this module, this implementation is considerably faster than other public Python implementations for non-trivial inputs.

Another unique feature of this implementation is the possibility to use the XOR and XNOR operators, in addition to the normal AND operator, to minimise the terms. This slows down the algorithm, but in some cases the result can be much more compact than a sum of product.


Use the QuineMcCluskey class like this:

from qm import QuineMcCluskey

qm = QuineMcCluskey()
ones = [0, 2, 3]
dontcares = [4, 5, 6, 7]
print(qm.simplify(ones, dontcares))

This will return the following set:

set(['1--', '-1-', '--0'])

Please note that the least significant bit in the output is in the leftmost position (a position 0 for the string). If the bits are called ABC then the result should be interpreted as:

C or B or (not A)


The latest released version is:

Fork QuineMcCluskey on GitHub.


Version 0.2 03 January 2014

Released v0.2. This version contains a bugfix for the XOR expression simplifier. Read more…

Added Quine McCluskey page 26 November 2012

Added a project page for the Quine McCluskey project. The project is actually actually quite old but the the GitHub project and the Python cheeseshop page were created now. Update: version 0.1 was released On the 9th December 2012. Read more…

To Do

No known bugs or issues.