Regina Calculation Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends
regina::NPerm5 Class Reference

Represents a permutation of {0,1,2,3,4}. More...

#include <maths/nperm5.h>

List of all members.

Public Member Functions

 NPerm5 ()
 Creates the identity permutation.
 NPerm5 (int a, int b)
 Creates the transposition of a and b.
 NPerm5 (int a, int b, int c, int d, int e)
 Creates a permutation mapping (0,1,2,3,4) to (a,b,c,d,e) respectively.
 NPerm5 (int a0, int a1, int b0, int b1, int c0, int c1, int d0, int d1, int e0, int e1)
 Creates a permutation mapping (a0,b0,c0,d0,e0) to (a1,b1,c1,d1,e1) respectively.
 NPerm5 (const NPerm5 &cloneMe)
 Creates a permutation that is a clone of the given permutation.
unsigned getPermCode () const
 Returns the internal code representing this permutation.
void setPermCode (unsigned newCode)
 Sets this permutation to that represented by the given internal code.
NPerm5operator= (const NPerm5 &cloneMe)
 Sets this permutation to be equal to the given permutation.
NPerm5 operator* (const NPerm5 &q) const
 Returns the composition of this permutation with the given permutation.
NPerm5 inverse () const
 Finds the inverse of this permutation.
int sign () const
 Determines the sign of this permutation.
int operator[] (int source) const
 Determines the image of the given integer under this permutation.
int preImageOf (int image) const
 Determines the preimage of the given integer under this permutation.
bool operator== (const NPerm5 &other) const
 Determines if this is equal to the given permutation.
bool operator!= (const NPerm5 &other) const
 Determines if this differs from the given permutation.
int compareWith (const NPerm5 &other) const
 Lexicographically compares the images of (0,1,2,3,4) under this and the given permutation.
bool isIdentity () const
 Determines if this is the identity permutation.
std::string toString () const
 Returns a string representation of this permutation.
std::string trunc2 () const
 Returns a string representation of this permutation with only the images of 0 and 1.
std::string trunc3 () const
 Returns a string representation of this permutation with only the images of 0, 1 and 2.
std::string trunc4 () const
 Returns a string representation of this permutation with only the images of 0, 1, 2 and 3.
int S5Index () const
 Returns the index of this permutation in the NPerm5::S5 array.
int orderedS5Index () const
 Returns the index of this permutation in the NPerm5::orderedS5 array.

Static Public Member Functions

static NPerm5 fromPermCode (unsigned newCode)
 Creates a permutation from the given internal code.
static bool isPermCode (unsigned newCode)
 Determines whether the given integer is a valid internal permutation code.

Static Public Attributes

static const NPerm5 S5 [120]
 Contains all possible permutations of five elements.
static const NPerm5 orderedS5 [120]
 Contains all possible permutations of five elements in lexicographical order.
static const unsigned invS5 [120]
 Contains the inverses of the permutations in the array S5.

Friends

std::ostream & operator<< (std::ostream &out, const NPerm5 &p)
 Writes a string representation of the given permutation to the given output stream.

Detailed Description

Represents a permutation of {0,1,2,3,4}.

Amongst other things, such permutations are used in describing simplex gluings in 4-manifold triangulations. NPerm5 objects are small enough to pass about by value instead of by reference.

Each permutation has an internal code, and this code is sufficient to reconstruct the permutation. Thus the internal code may be a useful means for passing permutation objects to and from the engine.

The internal code is an unsigned integer. The lowest three bits represent the image of 0, the next lowest three bits represent the image of 1 and so on.

Test:
Exhaustively tested in the test suite.

Constructor & Destructor Documentation

regina::NPerm5::NPerm5 ( ) [inline]

Creates the identity permutation.

regina::NPerm5::NPerm5 ( int  a,
int  b 
) [inline]

Creates the transposition of a and b.

Note that a and b need not be distinct.

Precondition:
a and b are in {0,1,2,3,4}.
Parameters:
athe element to switch with b.
bthe element to switch with a.
regina::NPerm5::NPerm5 ( int  a,
int  b,
int  c,
int  d,
int  e 
) [inline]

Creates a permutation mapping (0,1,2,3,4) to (a,b,c,d,e) respectively.

Precondition:
{a,b,c,d,e} = {0,1,2,3,4}.
Parameters:
athe desired image of 0.
bthe desired image of 1.
cthe desired image of 2.
dthe desired image of 3.
ethe desired image of 4.
regina::NPerm5::NPerm5 ( int  a0,
int  a1,
int  b0,
int  b1,
int  c0,
int  c1,
int  d0,
int  d1,
int  e0,
int  e1 
) [inline]

Creates a permutation mapping (a0,b0,c0,d0,e0) to (a1,b1,c1,d1,e1) respectively.

Precondition:
{a0,b0,c0,d0,e0} = {a1,b1,c1,d1,e1} = {0,1,2,3,4}.
Parameters:
a0the desired preimage of a1.
b0the desired preimage of b1.
c0the desired preimage of c1.
d0the desired preimage of d1.
e0the desired preimage of e1.
a1the desired image of a0.
b1the desired image of b0.
c1the desired image of c0.
d1the desired image of d0.
e1the desired image of e0.
regina::NPerm5::NPerm5 ( const NPerm5 cloneMe) [inline]

Creates a permutation that is a clone of the given permutation.

Parameters:
cloneMethe permutation to clone.

Member Function Documentation

int regina::NPerm5::compareWith ( const NPerm5 other) const

Lexicographically compares the images of (0,1,2,3,4) under this and the given permutation.

Parameters:
otherthe permutation with which to compare this.
Returns:
-1 if this permutation produces a smaller image, 0 if the permutations are equal and 1 if this permutation produces a greater image.
NPerm5 regina::NPerm5::fromPermCode ( unsigned  newCode) [inline, static]

Creates a permutation from the given internal code.

Precondition:
the given code is a valid permutation code; see isPermCode() for details.
Parameters:
newCodethe internal code for the new permutation.
Returns:
the permutation reprsented by the given internal code.
unsigned regina::NPerm5::getPermCode ( ) const [inline]

Returns the internal code representing this permutation.

Note that the internal code is sufficient to reproduce the entire permutation.

The code returned will be a valid permutation code as determined by isPermCode().

Returns:
the internal code.
NPerm5 regina::NPerm5::inverse ( ) const [inline]

Finds the inverse of this permutation.

Returns:
the inverse of this permutation.
bool regina::NPerm5::isIdentity ( ) const [inline]

Determines if this is the identity permutation.

This is true if and only if each of 0, 1, 2, 3 and 4 is mapped to itself.

Returns:
true if and only if this is the identity permutation.
static bool regina::NPerm5::isPermCode ( unsigned  newCode) [static]

Determines whether the given integer is a valid internal permutation code.

Valid permutation codes can be passed to setPermCode() or fromPermCode(), and are returned by getPermCode().

Returns:
true if and only if the given code is a valid internal permutation code.
bool regina::NPerm5::operator!= ( const NPerm5 other) const [inline]

Determines if this differs from the given permutation.

This is true if and only if the two permutations have different images for at least one of 0, 1, 2, 3 or 4.

Parameters:
otherthe permutation with which to compare this.
Returns:
true if and only if this and the given permutation differ.
NPerm5 regina::NPerm5::operator* ( const NPerm5 q) const [inline]

Returns the composition of this permutation with the given permutation.

If this permutation is p, the resulting permutation will be p o q, satisfying (p*q)[x] == p[q[x]].

Parameters:
qthe permutation with which to compose this.
Returns:
the composition of both permutations.
NPerm5 & regina::NPerm5::operator= ( const NPerm5 cloneMe) [inline]

Sets this permutation to be equal to the given permutation.

Parameters:
cloneMethe permutation whose value will be assigned to this permutation.
Returns:
a reference to this permutation.
bool regina::NPerm5::operator== ( const NPerm5 other) const [inline]

Determines if this is equal to the given permutation.

This is true if and only if both permutations have the same images for 0, 1, 2, 3 and 4.

Parameters:
otherthe permutation with which to compare this.
Returns:
true if and only if this and the given permutation are equal.
int regina::NPerm5::operator[] ( int  source) const [inline]

Determines the image of the given integer under this permutation.

Parameters:
sourcethe integer whose image we wish to find. This should be between 0 and 4 inclusive.
Returns:
the image of source.

Returns the index of this permutation in the NPerm5::orderedS5 array.

Returns:
the index i for which this permutation is equal to NPerm5::orderedS5[i]. This will be between 0 and 119 inclusive.
Author:
Ryan Budney
int regina::NPerm5::preImageOf ( int  image) const [inline]

Determines the preimage of the given integer under this permutation.

Parameters:
imagethe integer whose preimage we wish to find. This should be between 0 and 4 inclusive.
Returns:
the preimage of image.
int regina::NPerm5::S5Index ( ) const

Returns the index of this permutation in the NPerm5::S5 array.

Returns:
the index i for which this permutation is equal to NPerm5::S5[i]. This will be between 0 and 119 inclusive.
Author:
Ryan Budney
void regina::NPerm5::setPermCode ( unsigned  newCode) [inline]

Sets this permutation to that represented by the given internal code.

Precondition:
the given code is a valid permutation code; see isPermCode() for details.
Parameters:
newCodethe internal code that will determine the new value of this permutation.
int regina::NPerm5::sign ( ) const

Determines the sign of this permutation.

Returns:
1 if this permutation is even, or -1 if this permutation is odd.
std::string regina::NPerm5::toString ( ) const

Returns a string representation of this permutation.

The representation will consist of five adjacent digits representing the images of 0, 1, 2, 3 and 4 respectively. An example of a string representation is 30421.

Returns:
a string representation of this permutation.
std::string regina::NPerm5::trunc2 ( ) const

Returns a string representation of this permutation with only the images of 0 and 1.

The resulting string will therefore have length two.

Returns:
a truncated string representation of this permutation.
std::string regina::NPerm5::trunc3 ( ) const

Returns a string representation of this permutation with only the images of 0, 1 and 2.

The resulting string will therefore have length three.

Returns:
a truncated string representation of this permutation.
std::string regina::NPerm5::trunc4 ( ) const

Returns a string representation of this permutation with only the images of 0, 1, 2 and 3.

The resulting string will therefore have length four.

Returns:
a truncated string representation of this permutation.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const NPerm5 p 
) [friend]

Writes a string representation of the given permutation to the given output stream.

The format will be the same as is used by NPerm5::toString().

Parameters:
outthe output stream to which to write.
pthe permutation to write.
Returns:
a reference to out.

Member Data Documentation

const unsigned regina::NPerm5::invS5[120] [static]

Contains the inverses of the permutations in the array S5.

Specifically, the inverse of permutation S5[i] is the permutation S5[ invS5[i] ].

const NPerm5 regina::NPerm5::orderedS5[120] [static]

Contains all possible permutations of five elements in lexicographical order.

const NPerm5 regina::NPerm5::S5[120] [static]

Contains all possible permutations of five elements.

The permutations with even indices in the array are the even permutations, and those with odd indices in the array are the odd permutations.

Note that the permutations are not necessarily in lexicographical order.


The documentation for this class was generated from the following file:

Copyright © 1999-2011, The Regina development team
This software is released under the GNU General Public License.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).