Calculates the inverse of the given permutation.

You're viewing an older version of this page (#5339). View the current version.

View versions (2)

Interface

#include <codecogs/maths/combinatorics/permutations/inverse_large.h>

using namespace Maths::Combinatorics::Permutations;

The inverse of a permutation

$$\sigma = \left( \begin{array}{cccc} 1 & 2 & \ldots & n \cr \sigma(1) & \sigma(2) & \ldots & \sigma(n) \end{array} \right)$$
(1)

is a permutation $\tau$ such that

$$\sigma \circ \tau = \tau \circ \sigma = \left( \begin{array}{cccc} 1 & 2 & \ldots & n \cr 1 & 2 & \ldots & n \end{array} \right)$$
(2)

where $\sigma \circ \tau$ represents multiplication. This function is similar to the inverse component, with the benefit that it is more suited for permutations of larger size.

Example:

#include <codecogs/maths/combinatorics/permutations/inverse_large.h>
#include <iostream>
int main()
{
  int sigma[5] = {3, 1, 2, 5, 4};
  std::vector<int> result = Maths::Combinatorics::Permutations::inverse_large(5, sigma);
  std::cout << "The inverse of the Sigma permutation is: ";
  std::cout << std::endl;
  for (int i = 0; i < 5; i++)
    std::cout << result[i] << " ";
  std::cout << std::endl;
  return 0;
}

Output:

The inverse of the Sigma permutation is:
2 3 1 5 4

References

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Parameters

n
the size of the permutation
p
the actual permutation given as an array

Returns

the inverse of the given permutation p
GPL Licence — free for non commercial use. See Licence details.