regina::NPerm3 Class Reference
Mathematical Support

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

`#include <maths/nperm3.h>`

## Public Types

enum | { nPerms = 6, nPerms_1 = 2 }
enum | { code012 = 0, code021 = 1, code120 = 2, code102 = 3, code201 = 4, code210 = 5 }

## Public Member Functions

| NPerm3 ()
| Creates the identity permutation. More...
| NPerm3 (int a, int b)
| Creates the transposition of a and b. More...
| NPerm3 (int a, int b, int c)
| Creates a permutation mapping (0,1,2) to (a,b,c) respectively. More...
| NPerm3 (const int *image)
| Creates a permutation mapping i to image[i] for each i = 0,1,2. More...
| NPerm3 (const NPerm3 &cloneMe)
| Creates a permutation that is a clone of the given permutation. More...
unsigned char | getPermCode () const
| Returns the internal code representing this permutation. More...
void | setPermCode (unsigned char code)
| Sets this permutation to that represented by the given internal code. More...
NPerm3 & | operator= (const NPerm3 &cloneMe)
| Sets this permutation to be equal to the given permutation. More...
NPerm3 | operator* (const NPerm3 &q) const
| Returns the composition of this permutation with the given permutation. More...
NPerm3 | inverse () const
| Finds the inverse of this permutation. More...
int | sign () const
| Determines the sign of this permutation. More...
int | operator[] (int source) const
| Determines the image of the given integer under this permutation. More...
int | preImageOf (int image) const
| Determines the preimage of the given integer under this permutation. More...
bool | operator== (const NPerm3 &other) const
| Determines if this is equal to the given permutation. More...
bool | operator!= (const NPerm3 &other) const
| Determines if this differs from the given permutation. More...
int | compareWith (const NPerm3 &other) const
| Lexicographically compares the images of (0,1,2) under this and the given permutation. More...
bool | isIdentity () const
| Determines if this is the identity permutation. More...
std::string | toString () const
| A deprecated alias for str(), which returns a string representation of this permutation. More...
std::string | str () const
| Returns a string representation of this permutation. More...
std::string | trunc2 () const
| Returns a string representation of this permutation with only the images of 0 and 1. More...
int | S3Index () const
| Returns the index of this permutation in the NPerm3::S3 array. More...
int | SnIndex () const
| Returns the index of this permutation in the NPerm3::S3 array. More...
int | orderedS3Index () const
| Returns the index of this permutation in the NPerm3::orderedS3 array. More...
int | orderedSnIndex () const
| Returns the index of this permutation in the NPerm3::orderedS3 array. More...

## Static Public Member Functions

static NPerm3 | fromPermCode (unsigned char code)
| Creates a permutation from the given internal code. More...
static bool | isPermCode (unsigned char code)
| Determines whether the given integer is a valid internal permutation code. More...

## Static Public Attributes

static const NPerm3 | S3 [6]
| Contains all possible permutations of three elements. More...
static const NPerm3 * | Sn
| A dimension-agnostic alias for NPerm3::S3. More...
static const int | invS3 [6]
| Contains the inverses of the permutations in the array S3. More...
static const NPerm3 | orderedS3 [6]
| Contains all possible permutations of three elements in lexicographical order. More...
static const NPerm3 * | orderedSn
| A dimension-agnostic alias for NPerm3::orderedS3. More...
static const NPerm3 | S2 [2]
| Contains all possible permutations of two elements. More...
static const NPerm3 * | Sn_1
| A dimension-agnostic alias for NPerm3::S2. More...

## Friends

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

## Detailed Description

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

These objects are small enough to pass about by value instead of by reference. Moreover, they are extremely fast to work with.

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 integer between 0 and 5 inclusive, representing the index of the permutation in the array NPerm3::S3.

This class is faster and sleeker than related classes such as NPerm4 and NPerm5. On the other hand, this class does not offer quite as rich an interface as the others.

Test:
  Exhaustively tested in the test suite.

## Member Enumeration Documentation

anonymous enum

Enumerator

nPerms

The total number of permutations on three elements.

This is the size of the array Sn.

Python:
  Not present.

nPerms_1

The total number of permutations on two elements.

This is the size of the array Sn_1.

Python:
  Not present.

anonymous enum

Enumerator

code012

The internal code for the permutation (0,1,2).

Python:
  Not present.

code021

The internal code for the permutation (0,2,1).

Python:
  Not present.

code120

The internal code for the permutation (1,2,0).

Python:
  Not present.

code102

The internal code for the permutation (1,0,2).

Python:
  Not present.

code201

The internal code for the permutation (2,0,1).

Python:
  Not present.

code210

The internal code for the permutation (2,1,0).

Python:
  Not present.

## Constructor & Destructor Documentation

regina::NPerm3::NPerm3 | ( |  | ) |

inline

Creates the identity permutation.

regina::NPerm3::NPerm3 | ( | 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}.

Parameters

  a | the element to switch with b.
  b | the element to switch with a.

regina::NPerm3::NPerm3 | ( | int | a,
|  | int | b,
|  | int | c
| ) |  |

inline

Creates a permutation mapping (0,1,2) to (a,b,c) respectively.

Precondition
  {a,b,c} = {0,1,2}.

Parameters

  a | the desired image of 0.
  b | the desired image of 1.
  c | the desired image of 2.

regina::NPerm3::NPerm3 | ( | const int * | image | ) |

inline

Creates a permutation mapping i to image[i] for each i = 0,1,2.

Precondition
  The array image contains three elements, which are 0, 1 and 2 in some order.

Python:
  Not present.

Parameters

  image | the array of images.

regina::NPerm3::NPerm3 | ( | const NPerm3 & | cloneMe | ) |

inline

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

Parameters

  cloneMe | the permutation to clone.

## Member Function Documentation

int regina::NPerm3::compareWith | ( | const NPerm3 & | other | ) | const

inline

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

Parameters

  other | the 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.

NPerm3 regina::NPerm3::fromPermCode | ( | unsigned char | code | ) |

inline static

Creates a permutation from the given internal code.

Precondition
  the given code is a valid permutation code; see isPermCode() for details.

Parameters

  code | the internal code for the new permutation.

Returns
  the permutation represented by the given internal code.

unsigned char regina::NPerm3::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.

NPerm3 regina::NPerm3::inverse | ( |  | ) | const

inline

Finds the inverse of this permutation.

Returns
  the inverse of this permutation.

bool regina::NPerm3::isIdentity | ( |  | ) | const

inline

Determines if this is the identity permutation.

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

Returns
  `true` if and only if this is the identity permutation.

bool regina::NPerm3::isPermCode | ( | unsigned char | code | ) |

inline 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::NPerm3::operator!= | ( | const NPerm3 & | 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 or 2.

Parameters

  other | the permutation with which to compare this.

Returns
  `true` if and only if this and the given permutation differ.

NPerm3 regina::NPerm3::operator* | ( | const NPerm3 & | 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

  q | the permutation with which to compose this.

Returns
  the composition of both permutations.

NPerm3 & regina::NPerm3::operator= | ( | const NPerm3 & | cloneMe | ) |

inline

Sets this permutation to be equal to the given permutation.

Parameters

  cloneMe | the permutation whose value will be assigned to this permutation.

Returns
  a reference to this permutation.

bool regina::NPerm3::operator== | ( | const NPerm3 & | 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 and 2.

Parameters

  other | the permutation with which to compare this.

Returns
  `true` if and only if this and the given permutation are equal.

int regina::NPerm3::operator[] | ( | int | source | ) | const

inline

Determines the image of the given integer under this permutation.

Parameters

  source | the integer whose image we wish to find. This should be between 0 and 2 inclusive.

Returns
  the image of source.

int regina::NPerm3::orderedS3Index | ( |  | ) | const

inline

Returns the index of this permutation in the NPerm3::orderedS3 array.

Returns
  the index i for which this permutation is equal to NPerm3::orderedS3[i]. This will be between 0 and 5 inclusive.

int regina::NPerm3::orderedSnIndex | ( |  | ) | const

inline

Returns the index of this permutation in the NPerm3::orderedS3 array.

This is a dimension-agnostic alias for orderedS3Index().

Returns
  the index i for which this permutation is equal to NPerm3::orderedS3[i]. This will be between 0 and 5 inclusive.

int regina::NPerm3::preImageOf | ( | int | image | ) | const

inline

Determines the preimage of the given integer under this permutation.

Parameters

  image | the integer whose preimage we wish to find. This should be between 0 and 2 inclusive.

Returns
  the preimage of image.

int regina::NPerm3::S3Index | ( |  | ) | const

inline

Returns the index of this permutation in the NPerm3::S3 array.

Returns
  the index i for which this permutation is equal to NPerm3::S3[i]. This will be between 0 and 5 inclusive.

void regina::NPerm3::setPermCode | ( | unsigned char | code | ) |

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

  code | the internal code that will determine the new value of this permutation.

int regina::NPerm3::sign | ( |  | ) | const

inline

Determines the sign of this permutation.

Returns
  1 if this permutation is even, or -1 if this permutation is odd.

int regina::NPerm3::SnIndex | ( |  | ) | const

inline

Returns the index of this permutation in the NPerm3::S3 array.

This is a dimension-agnostic alias for S3Index().

Returns
  the index i for which this permutation is equal to NPerm3::S3[i]. This will be between 0 and 5 inclusive.

std::string regina::NPerm3::str | ( |  | ) | const

Returns a string representation of this permutation.

The representation will consist of three adjacent digits representing the images of 0, 1 and 2 respectively. An example of a string representation is `120`.

Returns
  a string representation of this permutation.

std::string regina::NPerm3::toString | ( |  | ) | const

inline

A deprecated alias for str(), which returns a string representation of this permutation.

Deprecated:
  This routine has (at long last) been deprecated; use the simpler-to-type str() instead.

Returns
  a string representation of this permutation.

std::string regina::NPerm3::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.

## Friends And Related Function Documentation

std::ostream& operator<< | ( | std::ostream & | out,
|  | const NPerm3 & | 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 NPerm3::str().

Parameters

  out | the output stream to which to write.
  p | the permutation to write.

Returns
  a reference to out.

## Member Data Documentation

const int regina::NPerm3::invS3[6]

static

Contains the inverses of the permutations in the array S3.

Specifically, the inverse of permutation `S3[i]` is the permutation `S3[ invS3[i] ]`.

const NPerm3 regina::NPerm3::orderedS3[6]

static

Contains all possible permutations of three elements in lexicographical order.

const NPerm3* regina::NPerm3::orderedSn

static

A dimension-agnostic alias for NPerm3::orderedS3.

In general, for each K the class NPermK will define an alias orderedSn that references the list of all permutations NPermK::orderedSK.

const NPerm3 regina::NPerm3::S2[2]

static

Contains all possible permutations of two elements.

In each permutation, 2 maps to 2 and 3 maps to 3.

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

For all permutation classes (NPerm3, NPerm4 and so on), the S2 array stores the same permutations in the same order (but of course using different data types).

Note that these permutations are already in lexicographical order.

const NPerm3 regina::NPerm3::S3[6]

static

Contains all possible permutations of three 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.

For all permutation classes (NPerm3, NPerm4 and so on), the S3 array stores the same permutations in the same order (but of course using different data types).

Note that these permutations are not necessarily in lexicographical order.

const NPerm3* regina::NPerm3::Sn

static

A dimension-agnostic alias for NPerm3::S3.

In general, for each K the class NPermK will define an alias Sn that references the list of all permutations NPermK::SK.

const NPerm3* regina::NPerm3::Sn_1

static

A dimension-agnostic alias for NPerm3::S2.

In general, for each K the class NPermK will define an alias Sn_1 that references the list of all permutations NPermK::S(K-1).

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

- maths/nperm3.h

Copyright © 1999-2013, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).