Click or drag to resize
Accord.NET (logo)

CombinatoricsTruthTable Method (Int32, Int32)

Generates all possible ordered permutations with repetitions allowed (a truth table).

Namespace:  Accord.Math
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.7.0
Syntax
public static int[][] TruthTable(
	int symbols,
	int length
)
Request Example View Source

Parameters

symbols
Type: SystemInt32
The number of symbols.
length
Type: SystemInt32
The length of the sequence to generate.

Return Value

Type: Int32
Examples

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 },
};
See Also