Skip to content

build and show a truth table from a boolean expression

Notifications You must be signed in to change notification settings

Carlos-Descalzi/truthtable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]

About

build and show a truth table from a boolean expression

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published