A Boolean function of n variables has 2 ^ n possible inputs. They can be listed by printing a binary representation of values ββin the range 0 <= x < 2^n .
For each of these possible inputs, a logic function can output 0 or 1. Enumerate all the possibilities (i.e., all possible truth tables). List binary values ββin the range 0 <= x < 2^(2^n) .
Here's the algorithm in Python:
from __future__ import print_function from itertools import product
The result is as follows:
All possible truth tables for n = 3 Truth table ----------- (0, 0, 0) --> 0 (0, 0, 1) --> 0 (0, 1, 0) --> 0 (0, 1, 1) --> 0 (1, 0, 0) --> 0 (1, 0, 1) --> 0 (1, 1, 0) --> 0 (1, 1, 1) --> 0 Truth table ----------- (0, 0, 0) --> 0 (0, 0, 1) --> 0 (0, 1, 0) --> 0 (0, 1, 1) --> 0 (1, 0, 0) --> 0 (1, 0, 1) --> 0 (1, 1, 0) --> 0 (1, 1, 1) --> 1 Truth table ----------- (0, 0, 0) --> 0 (0, 0, 1) --> 0 (0, 1, 0) --> 0 (0, 1, 1) --> 0 (1, 0, 0) --> 0 (1, 0, 1) --> 0 (1, 1, 0) --> 1 (1, 1, 1) --> 0 Truth table ----------- (0, 0, 0) --> 0 (0, 0, 1) --> 0 (0, 1, 0) --> 0 (0, 1, 1) --> 0 (1, 0, 0) --> 0 (1, 0, 1) --> 0 (1, 1, 0) --> 1 (1, 1, 1) --> 1 ... and so on
If you want to get the result in algebraic form, not a truth table, then the algorithm will be the same:
from __future__ import print_function from itertools import product
The result is as follows:
All possible algebraic expressions for n = 3 Function 0: False Function 1: abc Function 2: ab~c Function 3: ab~c or abc Function 4: a~bc Function 5: a~bc or abc Function 6: a~bc or ab~c Function 7: a~bc or ab~c or abc Function 8: a~b~c Function 9: a~b~c or abc Function 10: a~b~c or ab~c Function 11: a~b~c or ab~c or abc Function 12: a~b~c or a~bc Function 13: a~b~c or a~bc or abc Function 14: a~b~c or a~bc or ab~c Function 15: a~b~c or a~bc or ab~c or abc Function 16: ~abc Function 17: ~abc or abc Function 18: ~abc or ab~c Function 19: ~abc or ab~c or abc Function 20: ~abc or a~bc Function 21: ~abc or a~bc or abc Function 22: ~abc or a~bc or ab~c Function 23: ~abc or a~bc or ab~c or abc Function 24: ~abc or a~b~c Function 25: ~abc or a~b~c or abc Function 26: ~abc or a~b~c or ab~c Function 27: ~abc or a~b~c or ab~c or abc Function 28: ~abc or a~b~c or a~bc Function 29: ~abc or a~b~c or a~bc or abc Function 30: ~abc or a~b~c or a~bc or ab~c Function 31: ~abc or a~b~c or a~bc or ab~c or abc Function 32: ~ab~c Function 33: ~ab~c or abc ... and so on