Home </br>Permutation Generators </br>Combination Generators </br>Set/Subset Generators </br>Cartesian Product Generators </br>Math Functions </br>Ranking Algorithms </br>Number System Algorithms
JNumberTools provides three number system algorithms related to combinatorics, enabling efficient encoding and decoding of permutations and combinations. These APIs support BigInteger
for large indices, making them suitable for applications in combinatorial generation, ranking, and data compression.
Currently Available Algorithms
The Factorial Number System, also known as Factoradic, represents numbers as sums of factorials, where each digit is constrained by its position. It is used to encode and decode unique permutations efficiently.
// Convert a number to its factoradic representation
BigInteger number = BigInteger.valueOf(859);
int[] factoradic = JNumberTools.numberSystem().factoradic(number);
System.out.println(Arrays.toString(factoradic)); // Output: [7, 1, 2, 0, 1]
// Convert a factoradic representation back to a number
BigInteger result = JNumberTools.numberSystem().fromFactoradic(new int[]{7, 1, 2, 0, 1});
System.out.println(result); // Output: 859
The Permutation Number System, or Permutadic, is a generalization of the factoradic system for k-permutations. It encodes k-permutations using a mixed-radix system, enabling efficient generation of permutations at specific indices.
// Convert a number to its permutadic representation for n=5, k=3
BigInteger number = BigInteger.valueOf(100);
int[] permutadic = JNumberTools.numberSystem().permutadic(5, 3, number);
System.out.println(Arrays.toString(permutadic)); // Output: [4, 2, 0]
// Convert a permutadic representation back to a number
BigInteger result = JNumberTools.numberSystem().fromPermutadic(5, new int[]{4, 2, 0});
System.out.println(result); // Output: 100
The Combinatorial Number System, or Combinadic, encodes combinations by representing their indices as sums of binomial coefficients. It is used to efficiently generate and rank combinations.
// Convert a number to its combinadic representation for n=5, k=3
BigInteger number = BigInteger.valueOf(35);
int[] combinadic = JNumberTools.numberSystem().combinadic(5, 3, number);
System.out.println(Arrays.toString(combinadic)); // Output: [4, 3, 1]
// Convert a combinadic representation back to a number
BigInteger result = JNumberTools.numberSystem().fromCombinadic(new int[]{4, 3, 1});
System.out.println(result); // Output: 35
Home </br>Permutation Generators </br>Combination Generators </br>Set/Subset Generators </br>Cartesian Product Generators </br>Math Functions </br>Ranking Algorithms </br>Number System Algorithms