boolgen
is a Python library and command-line tool for generating and
simplifying Boolean expressions from truth tables.
The library implements a version of the Quine-McCluskey method to perform the simplification. I created it to help with designing digital logic circuits from truth tables.
To install boolgen
, use pip:
pip install boolgen
If you download the source, you can run the unit tests.
The boolgen
tool can be used from the command line to process truth tables
stored in files and output simplified Boolean expressions.
boolgen <input_file>
<input_file>
: Path to the input file containing the truth table.
If no filename is provided, then boolgen
will try to read the table from
STDIN
.
Create a file named input.txt
with the following content:
A B C D= E=
0 0 0 0 1
0 0 1 1 0
0 1 0 1 0
1 0 0 1 0
1 1 1 0 1
Truth table columns can be delimited by one or more non-alphanumeric characters.
Input and output variables can be identified with any alphanumeric string (including underscores).
Output variables are identified by a pre- or postfix '='.
If no output variable is explicitly declared, the last column in the table is assumed to be the output.
Truth values can be 0
, 1
, or -
for "don't care".
No error checking is done on these values, so check your work.
boolgen
will output the simplified Boolean expressions for each output variable in the truth table.
D = A | B & ~C
E = ~A & ~B & ~C | A & B & C
In degenerate cases, an output variable might be set to 0
or 1
.
You can also import boolgen
into your own project. See the function
definitions for an idea of how it all works.
Contributions are welcome! Please fork the repository and submit pull requests.
This project is licensed under the MIT License. See LICENSE.md for details.
TBQH I used ChatGPT liberally when creating this module, so if you find your own code in here, please let me know so I can remove it or else attribute you properly.