Recover Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttp://yahoo.com/
get GPL
COST (GBP)
this unit 0.50
sub units 0.19
add licence
0

inverse

Calculates the inverse of the given permutation.
Controller: CodeCogs

buy now get GPL add to cart

Dependents

Info

Interface

C++

Inverse

 
std::vector<int>inverseintn
int*p )
The inverse of a permutation is a permutation \tau such that where \sigma \circ \tau represents multiplication. This function searches for the permutation \tau with the property stated above and returns it as a C++ vector object.

References:

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

Example 1

#include <codecogs/maths/combinatorics/permutations/inverse.h>
#include <iostream>
int main()
{
  int sigma[5] = {5, 2, 1, 4, 3};
  std::vector<int> result = Maths::Combinatorics::Permutations::inverse(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:
3 2 5 4 1

Returns

the inverse of the given permutation p

Authors

Lucian Bentea (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


 

Page Comments

cppljevans\′s Photo
26 Dec 11, 3:21PM
(1 reply)
why wouldn't this simpler code work?
The attached code, based on the description:

There is also an inverse permutation P-1 for which P-1 P = P P-1 = I. It can be found by taking the functional inverse, or by reversing each ordered pair in the definition of a function as a set of ordered pairs (and then sorting the ordered pairs by their new first elements).

For example, the inverse of {2,3,1} is the inverse of {(1,2), (2,3), (3,1)}, which is {(2,1), (3,2), (1,3)}, or {(1,3), (2,1), (3,2)}, or {3,1,2}.

from:

http://www.efgh.com/math/algebra/permutations.htm

is much simpler (only 1 loop instead of 4 loops). Why not use this much simpler code?
CodeCogs\′s Photo
31 Dec 11, 10:50PM
I've looked into this page and a variety of sources on this and I have to admit I'm inclined to agreed with you. I think Lucian has made this harder that is actually needed to be.

Where your function would differ over the existing one is when \sigma does not contain a perfect sequence of integers. i.e. {4,1,2,7,3}. However, I can't see when it would be logical to do this.

I'll await feedback from Lucian, but upload you code as a draft for now.
cppljevans\′s Photo
26 Dec 11, 2:27AM
(1 reply)
How does code work?
I've looked briefly at code and have no clue how it works. How can I be assured the code is correct?

TIA.

-Larry
cppljevans\′s Photo
26 Dec 11, 4:19AM
The attached test driver shows the code works for all permutations of 1..5.
 
 Format Excel Equations

  You must login to leave a messge