build and show a truth table from a boolean expression.
Just a piece of old code I had in my hard drive and I wanted to preserve with some reaconditioning.
truthtable "(((a & b) | (a & c)) ^ d) & b"
Will produce:
a | b | c | d | a & b | a & c | ( a & b ) | ( a & c ) | ( ( a & b ) | ( a & c ) ) ^ d | ( ( ( a & b ) | ( a & c ) ) ^ d ) & b
-----------------------------------------------------------------------------------------------------------------------------
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0
0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0
0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0
0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1
0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0
0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 1
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0
1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0
1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 0
1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 1
1 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 0
1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1
1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0
Adding parameter -f will filter out those rows for which final value is 0
truthtable -f "(((a & b) | (a & c)) ^ d) & b"
Will produce:
a | b | c | d | a & b | a & c | ( a & b ) | ( a & c ) | ( ( a & b ) | ( a & c ) ) ^ d | ( ( ( a & b ) | ( a & c ) ) ^ d ) & b
-----------------------------------------------------------------------------------------------------------------------------
0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1
0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 1
1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 1
1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1
Operators:
- &: and
- |: or
- ^: xor
- ~: not
python3 setup.py install [--prefix=base folder]