I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 2.81
sub units 0.19
+
0

Sign

Calculates the sign of the given permutation.
Controller: CodeCogs

get GPL add to cart

Dependents

Info

Interface

C++
HTML

Sign

 
intsignintn
int*p )
A permutation can always be replaced by a sequence of pairwise transpositions. A given permutation can be represented by many different such transposition sequences, but the number of such transpositions will always be odd or always be even. If the number of transpositions is even or odd, the permutation is said to be even or odd. This function returns a corresponding value of 1 if the permutation is odd, and a value of -1 if it is even.

Example:

#include <codecogs/maths/combinatorics/permutations/sign.h>
#include <iostream>
int main()
{
  int alpha[5] = {4, 3, 5, 1, 2};
  std::cout << "The sign of the Alpha permutation is: ";
  std::cout << Maths::Combinatorics::Permutations::sign(5, alpha) << std::endl;
  return 0;
}

Output:

The sign of the Alpha permutation is: -1

References:

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

Parameters

nthe size of the permutation
pthe actual permutation stored as an array

Returns

the sign of the given permutation

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.