Click or drag to resize
Accord.NET (logo)

CombinatoricsTruthTable Method (Int32)

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

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

Parameters

symbols
Type: SystemInt32
The number of symbols for each variable.

Return Value

Type: Int32

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples

Suppose we would like to generate a truth table (i.e. all possible combinations of a set of discrete symbols) for variables that contain different numbers symbols. Let's say, for example, that the first variable may contain symbols 0 and 1, the second could contain either 0, 1, or 2, and the last one again could contain only 0 and 1. Thus we can generate the truth table in the following way:

// Number of symbols for each variable
int[] symbols = { 2, 3, 2 };

// Generate the truth table for the given symbols
int[][] table = Combinatorics.TruthTable(symbols);

// 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[] { 0, 2, 0 },
    new int[] { 0, 2, 1 },
    new int[] { 1, 0, 0 },
    new int[] { 1, 0, 1 },
    new int[] { 1, 1, 0 },
    new int[] { 1, 1, 1 },
    new int[] { 1, 2, 0 },
    new int[] { 1, 2, 1 },
};
See Also