Skip to content

Latest commit

 

History

History
56 lines (50 loc) · 3.47 KB

README.md

File metadata and controls

56 lines (50 loc) · 3.47 KB

truthtable

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.

Example:

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

Setup

python3 setup.py install [--prefix=base folder]