CombinatoricsTruthTable Method (Int32, Int32) |
Namespace: Accord.Math
Suppose we would like to generate a truth table for a binary problem. In this case, we are only interested in two symbols: 0 and 1. Let's then generate the table for three binary values
int symbols = 2; // Binary variables: either 0 or 1 int length = 3; // The number of variables; or number // of columns in the generated table. // Generate the table using Combinatorics.TruthTable(2,3) int[][] table = Combinatorics.TruthTable(symbols, length); // The generated table will be: { new int[] { 0, 0, 0 }, new int[] { 0, 0, 1 }, new int[] { 0, 1, 0 }, new int[] { 0, 1, 1 }, new int[] { 1, 0, 0 }, new int[] { 1, 0, 1 }, new int[] { 1, 1, 0 }, new int[] { 1, 1, 1 }, };