Regina 7.0 Calculation Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
regina::Perm< 6 > Class Reference

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

#include <maths/spec/perm6.h>

Public Types

using Index = int
 Denotes a native signed integer type large enough to count all permutations on six elements. More...
 
using ImagePack = uint32_t
 Indicates the native unsigned integer type used to store a single image pack. More...
 
using Code1 = ImagePack
 Indicates the native unsigned integer type used to store a first-generation permutation code. More...
 
using Code2 = uint16_t
 Indicates the native unsigned integer type used to store a second-generation permutation code. More...
 
using Code = Code1
 An alias for the first-generation code type Code1. More...
 

Public Member Functions

constexpr Perm ()
 Creates the identity permutation. More...
 
constexpr Perm (int a, int b)
 Creates the transposition of a and b. More...
 
constexpr Perm (int a, int b, int c, int d, int e, int f)
 Creates a permutation mapping (0,1,2,3,4,5) to (a,b,c,d,e,f) respectively. More...
 
constexpr Perm (const std::array< int, 6 > &image)
 Creates a permutation mapping i to image[i] for each i = 0,1,2,3,4,5. More...
 
constexpr Perm (const int *image)
 Deprecated constructor that creates a permutation mapping i to image[i] for each i = 0,1,2,3,4,5. More...
 
constexpr Perm (const int *a, const int *b)
 Deprecated constructor that creates a permutation mapping (a[0], ..., a[5]) to (b[0], ..., b[5]) respectively. More...
 
constexpr Perm (int a0, int a1, int b0, int b1, int c0, int c1, int d0, int d1, int e0, int e1, int f0, int f1)
 Creates a permutation mapping (a0,b0,c0,d0,e0,f0) to (a1,b1,c1,d1,e1,f1) respectively. More...
 
constexpr Perm (const Perm< 6 > &cloneMe)=default
 Creates a permutation that is a clone of the given permutation. More...
 
constexpr Code1 permCode1 () const
 Returns the first-generation code representing this permutation. More...
 
constexpr Code2 permCode2 () const
 Returns the second-generation code representing this permutation. More...
 
constexpr Code1 permCode () const
 Deprecated routine that returns the first-generation code representing this permutation. More...
 
void setPermCode1 (Code1 code)
 Sets this permutation to that represented by the given first-generation permutation code. More...
 
void setPermCode2 (Code2 code)
 Sets this permutation to that represented by the given second-generation permutation code. More...
 
void setPermCode (Code1 code)
 Deprecated routine that sets this permutation to that represented by the given first-generation permutation code. More...
 
constexpr ImagePack imagePack () const
 Returns the image pack that represents this permutation. More...
 
Perm< 6 > & operator= (const Perm< 6 > &cloneMe)=default
 Sets this permutation to be equal to the given permutation. More...
 
constexpr Perm< 6 > operator* (const Perm< 6 > &q) const
 Returns the composition of this permutation with the given permutation. More...
 
Perm< 6 > cachedComp (const Perm< 6 > &q) const
 Returns the composition of this and the given permutation, using fast precomputed lookup tables. More...
 
Perm< 6 > cachedComp (const Perm< 6 > &q, const Perm< 6 > &r) const
 Returns the composition of this and the given two permutations, using fast precomputed lookup tables. More...
 
constexpr Perm< 6 > inverse () const
 Finds the inverse of this permutation. More...
 
constexpr Perm< 6 > pow (long exp) const
 Computes the given power of this permutation. More...
 
Perm< 6 > cachedPow (long exp) const
 Computes the given power of this permutation, using fast precomputed lookup tables. More...
 
constexpr int order () const
 Returns the order of this permutation. More...
 
constexpr Perm< 6 > reverse () const
 Finds the reverse of this permutation. More...
 
constexpr int sign () const
 Determines the sign of this permutation. More...
 
constexpr int operator[] (int source) const
 Determines the image of the given integer under this permutation. More...
 
constexpr int pre (int image) const
 Determines the preimage of the given integer under this permutation. More...
 
constexpr int preImageOf (int image) const
 Deprecated routine that determines the preimage of the given integer under this permutation. More...
 
constexpr bool operator== (const Perm< 6 > &other) const
 Determines if this is equal to the given permutation. More...
 
constexpr bool operator!= (const Perm< 6 > &other) const
 Determines if this differs from the given permutation. More...
 
constexpr int compareWith (const Perm< 6 > &other) const
 Lexicographically compares the images of (0,1,2,3,4,5) under this and the given permutation. More...
 
constexpr bool isIdentity () const
 Determines if this is the identity permutation. More...
 
Perm< 6 > & operator++ ()
 A preincrement operator that changes this to be the next permutation in the array Perm<6>::Sn. More...
 
constexpr Perm< 6 > operator++ (int)
 A postincrement operator that changes this to be the next permutation in the array Perm<6>::Sn. More...
 
constexpr bool operator< (const Perm< 6 > &rhs) const
 Determines if this appears earlier than the given permutation in the array Perm<6>::Sn. More...
 
std::string str () const
 Returns a string representation of this permutation. More...
 
std::string trunc (unsigned len) const
 Returns a prefix of the string representation of this permutation, containing only the images of the first len integers. More...
 
void clear (unsigned from)
 Resets the images of all integers from from onwards to the identity map. More...
 
constexpr Index SnIndex () const
 Returns the index of this permutation in the Perm<6>::Sn array. More...
 
constexpr Index S6Index () const
 Returns the index of this permutation in the Perm<6>::S6 array. More...
 
constexpr Index orderedSnIndex () const
 Returns the lexicographical index of this permutation. More...
 
constexpr Index orderedS6Index () const
 Returns the lexicographical index of this permutation. More...
 
constexpr Index index () const
 Deprecated routine that returns the lexicographical index of this permutation. More...
 
constexpr bool isConjugacyMinimal () const
 Is this permutation minimal in its conjugacy class? More...
 
template<class URBG >
Perm< 6 > rand (URBG &&gen, bool even)
 

Static Public Member Functions

static void precompute ()
 Performs the precomputation necessary for using the optimised cachedComp() and cachedPow() routines. More...
 
static constexpr Perm< 6 > fromPermCode1 (Code1 code)
 Creates a permutation from the given first-generation permutation code. More...
 
static constexpr Perm< 6 > fromPermCode2 (Code2 code)
 Creates a permutation from the given second-generation permutation code. More...
 
static constexpr Perm< 6 > fromPermCode (Code1 code)
 Deprecated routine that creates a permutation from the given first-generation permutation code. More...
 
static constexpr bool isPermCode1 (Code1 code)
 Determines whether the given character is a valid first-generation permutation code. More...
 
static constexpr bool isPermCode2 (Code2 code)
 Determines whether the given character is a valid second-generation permutation code. More...
 
static constexpr bool isPermCode (Code1 code)
 Deprecated routine that determines whether the given character is a valid first-generation permutation code. More...
 
static constexpr Perm fromImagePack (ImagePack pack)
 Creates a permutation from the given image pack. More...
 
static constexpr bool isImagePack (ImagePack pack)
 Determines whether the given argument is the image pack of some 6-element permutation. More...
 
static constexpr Perm rot (int i)
 Returns the ith rotation. More...
 
static Perm rand (bool even=false)
 Returns a random permutation on six elements. More...
 
template<class URBG >
static Perm rand (URBG &&gen, bool even=false)
 Returns a random permutation on six elements, using the given uniform random bit generator. More...
 
static constexpr Perm atIndex (Index i)
 Deprecated routine that returns the ith permutation on six elements, where permutations are numbered lexicographically. More...
 
template<int k>
static constexpr Perm< 6 > extend (Perm< k > p)
 Extends a k-element permutation to a 6-element permutation, where 2 ≤ k < 6. More...
 
template<int k>
static constexpr Perm< 6 > contract (Perm< k > p)
 Restricts a k-element permutation to an 6-element permutation, where k > 6. More...
 

Static Public Attributes

static constexpr PermCodeType codeType = PERM_CODE_INDEX
 Indicates what type of internal permutation code is used by this instance of the Perm class template. More...
 
static constexpr Index nPerms = 720
 The total number of permutations on six elements. More...
 
static constexpr Index nPerms_1 = 120
 The total number of permutations on five elements. More...
 
static constexpr int imageBits = 3
 Indicates the number of bits used in an image pack to store the image of a single integer. More...
 
static constexpr ImagePack imageMask
 A bitmask whose lowest imageBits bits are 1, and whose remaining higher order bits are all 0. More...
 
static constexpr S6Lookup Sn {}
 Gives array-like access to all possible permutations of six elements. More...
 
static constexpr S6Lookup S6 {}
 Gives array-like access to all possible permutations of six elements. More...
 
static constexpr OrderedS6Lookup orderedSn {}
 Gives array-like access to all possible permutations of six elements in lexicographical order. More...
 
static constexpr OrderedS6Lookup orderedS6 {}
 Gives array-like access to all possible permutations of six elements in lexicographical order. More...
 

Protected Member Functions

constexpr Perm (Code2 code)
 Creates a permutation from the given second-generation permutation code. More...
 

Protected Attributes

Code2 code2_
 The internal second-generation permutation code representing this permutation. More...
 

Detailed Description

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

This is a specialisation of the generic Perm template: it is highly optimised, and also offers some additional functionality. Amongst other things, this permutation class is used to specify how simplices of a 5-dimensional triangulation are glued together.

As with all Perm template classes, these objects are small enough to pass by value and swap with std::swap(), with no need for any specialised move operations or swap functions.

Each permutation has an internal code, which is a single native integer that is sufficient to reconstruct the permutation. Thus the internal code may be a useful means for passing permutation objects to and from the engine. For Perm<6>, the internal permutation codes have changed as of Regina 7.0:

It is highly recommended that, if you need to work with permutation codes at all, you use second-generation codes where possible. This is because the first-generation routines incur additional overhead in converting back and forth between the second-generation codes (which are used internally by Perm<6>).

To use this class, simply include the main permutation header maths/perm.h.

Python
Since Python does not support templates, this class is made available under the name Perm6.

Member Typedef Documentation

◆ Code

using regina::Perm< 6 >::Code = Code1

An alias for the first-generation code type Code1.

Instead of Code, you should use either Code1 or Code2 to more clearly express which kind of permutation code you are using.

◆ Code1

using regina::Perm< 6 >::Code1 = ImagePack

Indicates the native unsigned integer type used to store a first-generation permutation code.

◆ Code2

using regina::Perm< 6 >::Code2 = uint16_t

Indicates the native unsigned integer type used to store a second-generation permutation code.

◆ ImagePack

using regina::Perm< 6 >::ImagePack = uint32_t

Indicates the native unsigned integer type used to store a single image pack.

See the class notes for more information on image packs, and how they are used to build the old first-generation permutation codes.

◆ Index

using regina::Perm< 6 >::Index = int

Denotes a native signed integer type large enough to count all permutations on six elements.

In other words, this is a native signed integer type large enough to store (6!).

Constructor & Destructor Documentation

◆ Perm() [1/9]

constexpr regina::Perm< 6 >::Perm ( )
inlineconstexpr

Creates the identity permutation.

◆ Perm() [2/9]

constexpr regina::Perm< 6 >::Perm ( int  a,
int  b 
)
inlineconstexpr

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,5}.
Parameters
athe element to switch with b.
bthe element to switch with a.

◆ Perm() [3/9]

constexpr regina::Perm< 6 >::Perm ( int  a,
int  b,
int  c,
int  d,
int  e,
int  f 
)
inlineconstexpr

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

Precondition
{a,b,c,d,e,f} = {0,1,2,3,4,5}.
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.
fthe desired image of 5.

◆ Perm() [4/9]

constexpr regina::Perm< 6 >::Perm ( const std::array< int, 6 > &  image)
inlineconstexpr

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

Precondition
The elements of image are 0, 1, 2, 3, 4 and 5 in some order.
Parameters
imagethe array of images.

◆ Perm() [5/9]

constexpr regina::Perm< 6 >::Perm ( const int *  image)
inlineconstexpr

Deprecated constructor that creates a permutation mapping i to image[i] for each i = 0,1,2,3,4,5.

Deprecated:
Use the six-integer constructor or the std::array constructor instead.
Precondition
The array image contains six elements, which are 0, 1, 2, 3, 4 and 5 in some order.
Parameters
imagethe array of images.

◆ Perm() [6/9]

constexpr regina::Perm< 6 >::Perm ( const int *  a,
const int *  b 
)
inlineconstexpr

Deprecated constructor that creates a permutation mapping (a[0], ..., a[5]) to (b[0], ..., b[5]) respectively.

Deprecated:
Use the 12-integer constructor or the std::array constructor instead.
Precondition
Both arrays a and b contain six elements, which are 0,...,5 in some order.
Python
Not present; use the single-array constructor instead.
Parameters
athe array of preimages; this must have length 6.
bthe corresponding array of images; this must also have length 6.

◆ Perm() [7/9]

constexpr regina::Perm< 6 >::Perm ( int  a0,
int  a1,
int  b0,
int  b1,
int  c0,
int  c1,
int  d0,
int  d1,
int  e0,
int  e1,
int  f0,
int  f1 
)
inlineconstexpr

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

Precondition
{a0,b0,c0,d0,e0,f0} = {a1,b1,c1,d1,e1,f1} = {0,1,2,3,4,5}.
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.
f0the desired preimage of f1.
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.
f1the desired image of f0.

◆ Perm() [8/9]

constexpr regina::Perm< 6 >::Perm ( const Perm< 6 > &  cloneMe)
constexprdefault

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

Parameters
cloneMethe permutation to clone.

◆ Perm() [9/9]

constexpr regina::Perm< 6 >::Perm ( Code2  code)
inlineconstexprprotected

Creates a permutation from the given second-generation permutation code.

Precondition
the given code is a valid second-generation permutation code; see isPermCode2() for details.
Parameters
codethe second-generation code from which the new permutation will be created.

Member Function Documentation

◆ atIndex()

constexpr Perm< 6 > regina::Perm< 6 >::atIndex ( Index  i)
inlinestaticconstexpr

Deprecated routine that returns the ith permutation on six elements, where permutations are numbered lexicographically.

Deprecated:
Use orderedSn[i] instead.
Parameters
ithe lexicographical index of the permutation; this must be between 0 and 719 inclusive.
Returns
the ith permutation.

◆ cachedComp() [1/2]

Perm< 6 > regina::Perm< 6 >::cachedComp ( const Perm< 6 > &  q) const
inline

Returns the composition of this and the given permutation, using fast precomputed lookup tables.

The advantage of this routine is speed: calling cachedComp() is a single lookup, whereas the * operator requires two lookups and a few steps of mathematical computation.

The disadvantages of this routine are that (1) you must remember to call precompute() in advance, and (2) the resulting lookup table will consume roughly 1MB of memory for the lifetime of your program.

The permutation that is returned is the same as you would obtain by calling (*this) * q.

Precondition
You must have called the routine precompute() at least once in the lifetime of this program before using cachedComp(). Otherwise this routine will almost certainly crash your program.
Parameters
qthe permutation to compose this with.
Returns
the composition of both permutations.

◆ cachedComp() [2/2]

Perm< 6 > regina::Perm< 6 >::cachedComp ( const Perm< 6 > &  q,
const Perm< 6 > &  r 
) const
inline

Returns the composition of this and the given two permutations, using fast precomputed lookup tables.

The advantage of this routine is speed: calling cachedComp() with two arguments requires just two lookups, whereas using the * operator twice would involve four lookups and a handful of steps of mathematical computation.

The disadvantages of this routine are that (1) you must remember to call precompute() in advance, and (2) the resulting lookup table will consume roughly 1MB of memory for the lifetime of your program.

The permutation that is returned is the same as you would obtain by calling (*this) * q * r.

Precondition
You must have called the routine precompute() at least once in the lifetime of this program before using cachedComp(). Otherwise this routine will almost certainly crash your program.
Parameters
qthe first permutation to compose this with.
rthe second permutation to compose this with.
Returns
the composition of both permutations.

◆ cachedPow()

Perm< 6 > regina::Perm< 6 >::cachedPow ( long  exp) const
inline

Computes the given power of this permutation, using fast precomputed lookup tables.

This routine runs in constant time.

The advantage of this routine is speed: calling cachedPow() removes some (but not all) of the mathematical overhead required by pow().

The disadvantages of this routine are that (1) you must remember to call precompute() in advance, and (2) the resulting lookup table will consume roughly 1MB of memory for the lifetime of your program. Note that this is the same lookup table used by cachedComp(), so if you are already using cachedComp() then there is no extra cost for using this routine also.

The permutation that is returned is the same as you would obtain by calling pow(exp).

Precondition
You must have called the routine precompute() at least once in the lifetime of this program before using cachedPow(). Otherwise this routine will almost certainly crash your program.
Parameters
expthe exponent; this may be positive, zero or negative.
Returns
this permutation raised to the power of exp.

◆ clear()

void regina::Perm< 6 >::clear ( unsigned  from)

Resets the images of all integers from from onwards to the identity map.

Specifically, for each i in the range from,...,5, this routine will ensure that image[i] == i. The images of 0,1,...,from-1 will not be altered.

Precondition
The images of from,...,5 are exactly from,...,5, but possibly in a different order.
Parameters
fromthe first integer whose image should be reset. This must be between 0 and 6 inclusive.

◆ compareWith()

constexpr int regina::Perm< 6 >::compareWith ( const Perm< 6 > &  other) const
inlineconstexpr

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

Note that this does not yield the same ordering of permutations as used by the less-than and increment operators. Moreover, compareWith() is slower than the less-than operator to compute.

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.

◆ contract()

template<int k>
static constexpr Perm< 6 > regina::Perm< 6 >::contract ( Perm< k >  p)
staticconstexpr

Restricts a k-element permutation to an 6-element permutation, where k > 6.

The resulting permutation will map 0,...,5 to their respective images under p, and will ignore the "unused" images p[6],...,p[k-1].

Precondition
The given permutation maps 0,...,5 to 0,...,5 in some order.
Template Parameters
kthe number of elements for the input permutation; this must be strictly greater than 6.
Parameters
pa permutation on k elements.
Returns
the same permutation restricted to a permutation on 6 elements.

◆ extend()

template<int k>
static constexpr Perm< 6 > regina::Perm< 6 >::extend ( Perm< k >  p)
staticconstexpr

Extends a k-element permutation to a 6-element permutation, where 2 ≤ k < 6.

The resulting permutation will map 0,...,k-1 to their respective images under p, and will map the "unused" elements k,...,5 to themselves.

Template Parameters
kthe number of elements for the input permutation; this must be 2, 3, 4 or 5.
Parameters
pa permutation on k elements.
Returns
the same permutation expressed as a permutation on six elements.

◆ fromImagePack()

constexpr Perm< 6 > regina::Perm< 6 >::fromImagePack ( ImagePack  pack)
inlinestaticconstexpr

Creates a permutation from the given image pack.

See the class notes for more information on image packs, and how they are used to build the old first-generation permutation codes.

For Perm<6>, this routine is identical to fromPermCode1().

Precondition
The argument pack is a valid image pack; see isImagePack() for details.
Parameters
packan image pack that describes a permutation.
Returns
the permutation represented by the given image pack.

◆ fromPermCode()

constexpr Perm< 6 > regina::Perm< 6 >::fromPermCode ( Code1  code)
inlinestaticconstexpr

Deprecated routine that creates a permutation from the given first-generation permutation code.

Precondition
the given code is a valid first-generation permutation code; see isPermCode1() for details.
Deprecated:
Use fromPermCode1() to reproduce this behaviour. However, unless you need backward compatibility, it is strongly recommended to switch to the much faster second-generation codes instead.
Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine fromPermCode2() for details.
Parameters
codethe first-generation code for the new permutation.
Returns
the permutation represented by the given code.

◆ fromPermCode1()

constexpr Perm< 6 > regina::Perm< 6 >::fromPermCode1 ( Code1  code)
inlinestaticconstexpr

Creates a permutation from the given first-generation permutation code.

Precondition
the given code is a valid first-generation permutation code; see isPermCode1() for details.
Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine fromPermCode2() for details.
Parameters
codethe first-generation code for the new permutation.
Returns
the permutation represented by the given code.

◆ fromPermCode2()

constexpr Perm< 6 > regina::Perm< 6 >::fromPermCode2 ( Code2  code)
inlinestaticconstexpr

Creates a permutation from the given second-generation permutation code.

Second-generation codes are fast to work with, since they are used internally by the Perm<6> class.

Precondition
the given code is a valid second-generation permutation code; see isPermCode2() for details.
Parameters
codethe second-generation code for the new permutation.
Returns
the permutation represented by the given code.

◆ imagePack()

constexpr Perm< 6 >::ImagePack regina::Perm< 6 >::imagePack ( ) const
inlineconstexpr

Returns the image pack that represents this permutation.

See the class notes for more information on image packs, and how they are used to build the old first-generation permutation codes.

For Perm<6>, this routine is identical to permCode1().

Returns
the image pack for this permutation.

◆ index()

constexpr Perm< 6 >::Index regina::Perm< 6 >::index ( ) const
inlineconstexpr

Deprecated routine that returns the lexicographical index of this permutation.

Deprecated:
Use the equivalent routine orderedSnIndex() instead.
Returns
the lexicographical index of this permutation.

◆ inverse()

constexpr Perm< 6 > regina::Perm< 6 >::inverse ( ) const
inlineconstexpr

Finds the inverse of this permutation.

Returns
the inverse of this permutation.

◆ isConjugacyMinimal()

constexpr bool regina::Perm< 6 >::isConjugacyMinimal ( ) const
inlineconstexpr

Is this permutation minimal in its conjugacy class?

Here "minimal" means that, amongst all its conjugates, this permutation has the smallest index in the array Perm<6>::Sn.

See Sn for further information on how permutations are indexed.

This routine is extremely fast for Perm<6>, since it essentially uses a hard-coded lookup table.

Returns
true if and only if this permutation is minimal in its conjugacy class.

◆ isIdentity()

constexpr bool regina::Perm< 6 >::isIdentity ( ) const
inlineconstexpr

Determines if this is the identity permutation.

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

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

◆ isImagePack()

constexpr bool regina::Perm< 6 >::isImagePack ( ImagePack  pack)
inlinestaticconstexpr

Determines whether the given argument is the image pack of some 6-element permutation.

See the class notes for more information on image packs, and how they are used to build the old first-generation permutation codes.

For Perm<6>, this routine is identical to isPermCode1().

Parameters
packthe candidate image pack to test.
Returns
true if and only if pack is a valid image pack.

◆ isPermCode()

constexpr bool regina::Perm< 6 >::isPermCode ( Code1  code)
inlinestaticconstexpr

Deprecated routine that determines whether the given character is a valid first-generation permutation code.

Deprecated:
Use isPermCode1() to reproduce this behaviour. However, unless you need backward compatibility, it is strongly recommended to switch to the much faster second-generation codes instead.
Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine isPermCode2() for details.
Parameters
codethe permutation code to test.
Returns
true if and only if the given code is a valid first-generation permutation code.

◆ isPermCode1()

constexpr bool regina::Perm< 6 >::isPermCode1 ( Code1  code)
inlinestaticconstexpr

Determines whether the given character is a valid first-generation permutation code.

Valid first-generation codes can be passed to setPermCode1() or fromPermCode1(), and are returned by permCode1().

Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine isPermCode2() for details.
Parameters
codethe permutation code to test.
Returns
true if and only if the given code is a valid first-generation permutation code.

◆ isPermCode2()

constexpr bool regina::Perm< 6 >::isPermCode2 ( Code2  code)
inlinestaticconstexpr

Determines whether the given character is a valid second-generation permutation code.

Valid second-generation codes can be passed to setPermCode2() or fromPermCode2(), and are returned by permCode2().

Second-generation codes are fast to work with, since they are used internally by the Perm<6> class.

Parameters
codethe permutation code to test.
Returns
true if and only if the given code is a valid second-generation permutation code.

◆ operator!=()

constexpr bool regina::Perm< 6 >::operator!= ( const Perm< 6 > &  other) const
inlineconstexpr

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, 4 or 5.

Parameters
otherthe permutation with which to compare this.
Returns
true if and only if this and the given permutation differ.

◆ operator*()

constexpr Perm< 6 > regina::Perm< 6 >::operator* ( const Perm< 6 > &  q) const
inlineconstexpr

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]].

For permutations of five and fewer objects, composition is extremely fast because it uses hard-coded lookup tables. However, for Perm<6> these tables would grow too large and so Regina adopts a hybrid approach: it uses "partial tables" which are significantly smaller, combined with a small amount of computation.

If you do need your compositions to be as fast as possible, with no computation required at all, then you can:

  • call precompute() to precompute a full 720-by-720 lookup table in advance (this will consume roughly 1MB of memory); and then
  • call cachedComp() instead of the * operator to compute your compositions.
Parameters
qthe permutation to compose this with.
Returns
the composition of both permutations.

◆ operator++() [1/2]

Perm< 6 > & regina::Perm< 6 >::operator++ ( )
inline

A preincrement operator that changes this to be the next permutation in the array Perm<6>::Sn.

If this is the last such permutation then this will wrap around to become the first permutation in Perm<6>::Sn, which is the identity.

Python
Not present, although the postincrement operator is present in python as the member function inc().
Returns
a reference to this permutation after the increment.

◆ operator++() [2/2]

constexpr Perm< 6 > regina::Perm< 6 >::operator++ ( int  )
inlineconstexpr

A postincrement operator that changes this to be the next permutation in the array Perm<6>::Sn.

If this is the last such permutation then this will wrap around to become the first permutation in Perm<6>::Sn, which is the identity.

Python
This routine is named inc() since python does not support the increment operator.
Returns
a copy of this permutation before the increment took place.

◆ operator<()

constexpr bool regina::Perm< 6 >::operator< ( const Perm< 6 > &  rhs) const
inlineconstexpr

Determines if this appears earlier than the given permutation in the array Perm<6>::Sn.

Note that this is not the same ordering of permutations as the ordering implied by compareWith(). This is, however, consistent with the ordering implied by the ++ operators, and this order is also faster to compute than compareWith().

Parameters
rhsthe permutation to compare this against.
Returns
true if and only if this appears before rhs in Sn.

◆ operator=()

Perm< 6 > & regina::Perm< 6 >::operator= ( const Perm< 6 > &  cloneMe)
default

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.

◆ operator==()

constexpr bool regina::Perm< 6 >::operator== ( const Perm< 6 > &  other) const
inlineconstexpr

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, 4 and 5.

Parameters
otherthe permutation with which to compare this.
Returns
true if and only if this and the given permutation are equal.

◆ operator[]()

constexpr int regina::Perm< 6 >::operator[] ( int  source) const
inlineconstexpr

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 5 inclusive.
Returns
the image of source.

◆ order()

constexpr int regina::Perm< 6 >::order ( ) const
inlineconstexpr

Returns the order of this permutation.

In other words; this routine returns the smallest positive integer k for which the kth power of this permutation is the identity.

Returns
the order of this permutation.

◆ orderedS6Index()

constexpr Perm< 6 >::Index regina::Perm< 6 >::orderedS6Index ( ) const
inlineconstexpr

Returns the lexicographical index of this permutation.

This will be the index of this permutation in the Perm<6>::orderedSn array.

This is a dimension-specific alias for orderedSnIndex(). In general, for every n there will be a member function Perm<n>::orderedSnIndex(); however, these numerical aliases Perm<2>::orderedS2Index(), ..., Perm<6>::orderedS6Index() are only available for small n.

See orderedSn for further information on lexicographical ordering.

Returns
the lexicographical index of this permutation. This will be between 0 and 719 inclusive.

◆ orderedSnIndex()

constexpr Perm< 6 >::Index regina::Perm< 6 >::orderedSnIndex ( ) const
inlineconstexpr

Returns the lexicographical index of this permutation.

This will be the index of this permutation in the Perm<6>::orderedSn array.

See orderedSn for further information on lexicographical ordering.

Returns
the lexicographical index of this permutation. This will be between 0 and 719 inclusive.

◆ permCode()

constexpr Perm< 6 >::Code1 regina::Perm< 6 >::permCode ( ) const
inlineconstexpr

Deprecated routine that returns the first-generation code representing this permutation.

The code returned will be a valid first-generation permutation code as determined by isPermCode1().

Deprecated:
Use permCode1() to reproduce this behaviour. However, unless you need backward compatibility, it is strongly recommended to switch to the much faster second-generation codes instead.
Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine permCode2() for details.
Returns
the first-generation permutation code.

◆ permCode1()

constexpr Perm< 6 >::Code1 regina::Perm< 6 >::permCode1 ( ) const
inlineconstexpr

Returns the first-generation code representing this permutation.

This code is sufficient to reproduce the entire permutation.

The code returned will be a valid first-generation permutation code as determined by isPermCode1().

Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine permCode2() for details.
Returns
the first-generation permutation code.

◆ permCode2()

constexpr Perm< 6 >::Code2 regina::Perm< 6 >::permCode2 ( ) const
inlineconstexpr

Returns the second-generation code representing this permutation.

This code is sufficient to reproduce the entire permutation.

The code returned will be a valid second-generation permutation code as determined by isPermCode2().

Second-generation codes are fast to work with, since they are used internally by the Perm<6> class.

Returns
the second-generation permutation code.

◆ pow()

constexpr Perm< 6 > regina::Perm< 6 >::pow ( long  exp) const
inlineconstexpr

Computes the given power of this permutation.

This routine runs in constant time.

For Perm<6>, this routine makes use of the "partial" product tables, which (as seen with the composition operator) require some small amount of extra computation to use. If you need your powers to be as fast as possible, you can instead:

  • call precompute() to precompute a full 720-by-720 product table in advance (this will consume roughly 1MB of memory); and then
  • call cachedPow() instead of pow() to make full use of this table, which will remove some (but not all) of the mathematical overhead from this routine.
Parameters
expthe exponent; this may be positive, zero or negative.
Returns
this permutation raised to the power of exp.

◆ pre()

constexpr int regina::Perm< 6 >::pre ( int  image) const
inlineconstexpr

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 5 inclusive.
Returns
the preimage of image.

◆ precompute()

static void regina::Perm< 6 >::precompute ( )
static

Performs the precomputation necessary for using the optimised cachedComp() and cachedPow() routines.

This must be called before calling cachedComp() or cachedPow().

This only needs to be done once in the lifetime of the program. If you do try to call precompute() a second time then it will do nothing and return immediately.

This routine is thread-safe.

◆ preImageOf()

constexpr int regina::Perm< 6 >::preImageOf ( int  image) const
inlineconstexpr

Deprecated routine that determines the preimage of the given integer under this permutation.

Deprecated:
This routine has been renamed to pre().
Parameters
imagethe integer whose preimage we wish to find. This should be between 0 and 5 inclusive.
Returns
the preimage of image.

◆ rand() [1/2]

Perm< 6 > regina::Perm< 6 >::rand ( bool  even = false)
inlinestatic

Returns a random permutation on six elements.

All permutations are returned with equal probability.

This routine is thread-safe, and uses RandomEngine for its random number generation.

Warning
This routine is expensive, since it locks and unlocks the mutex protecting Regina's global uniform random bit generator. If you are calling this many times in quick succession, consider creating a single RandomEngine object yourself and then calling rand(randomEngine.engine(), even).
Parameters
evenif true, then the resulting permutation is guaranteed to be even (and again all even permutations are returned with equal probability).
Returns
a random permutation.

◆ rand() [2/2]

template<class URBG >
static Perm regina::Perm< 6 >::rand ( URBG &&  gen,
bool  even = false 
)
static

Returns a random permutation on six elements, using the given uniform random bit generator.

All permutations are returned with equal probability.

The thread safety of this routine is of course dependent on the thread safety of your uniform random bit generator gen.

Template Parameters
URBGA type which, once any references are removed, must adhere to the C++ UniformRandomBitGenerator concept.
Python
Not present, though the non-thread-safe variant without the gen argument is available.
Parameters
genthe source of randomness to use (e.g., one of the many options provided in the C++ standard random header).
evenif true, then the resulting permutation is guaranteed to be even (and again all even permutations are returned with equal probability).
Returns
a random permutation.

◆ reverse()

constexpr Perm< 6 > regina::Perm< 6 >::reverse ( ) const
inlineconstexpr

Finds the reverse of this permutation.

Here reverse means that we reverse the images of 0,...,5. In other words, if permutation q is the reverse of p, then p[i] == q[5 - i] for all i.

◆ rot()

constexpr Perm< 6 > regina::Perm< 6 >::rot ( int  i)
inlinestaticconstexpr

Returns the ith rotation.

This maps k to k + i (mod 6) for all k.

Parameters
ithe image of 0; this must be between 0 and 5 inclusive.
Returns
the ith rotation.

◆ S6Index()

constexpr Perm< 6 >::Index regina::Perm< 6 >::S6Index ( ) const
inlineconstexpr

Returns the index of this permutation in the Perm<6>::S6 array.

This is a dimension-specific alias for SnIndex(). In general, for every n there will be a member function Perm<n>::SnIndex(); however, these numerical aliases Perm<2>::S2Index(), ..., Perm<6>::S6Index() are only available for small n.

See Sn for further information on how these permutations are indexed.

Returns
the index i for which this permutation is equal to Perm<6>::S6[i]. This will be between 0 and 719 inclusive.

◆ setPermCode()

void regina::Perm< 6 >::setPermCode ( Code1  code)
inline

Deprecated routine that sets this permutation to that represented by the given first-generation permutation code.

Deprecated:
Use setPermCode1() to reproduce this behaviour. However, unless you need backward compatibility, it is strongly recommended to switch to the much faster second-generation codes instead.
Precondition
the given code is a valid first-generation permutation code; see isPermCode1() for details.
Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine setPermCode2() for details.
Parameters
codethe first-generation code that will determine the new value of this permutation.

◆ setPermCode1()

void regina::Perm< 6 >::setPermCode1 ( Code1  code)
inline

Sets this permutation to that represented by the given first-generation permutation code.

Precondition
the given code is a valid first-generation permutation code; see isPermCode1() for details.
Warning
This routine will incur additional overhead, since Perm<6> now uses second-generation codes internally. See the class notes and the routine setPermCode2() for details.
Parameters
codethe first-generation code that will determine the new value of this permutation.

◆ setPermCode2()

void regina::Perm< 6 >::setPermCode2 ( Code2  code)
inline

Sets this permutation to that represented by the given second-generation permutation code.

Second-generation codes are fast to work with, since they are used internally by the Perm<6> class.

Precondition
the given code is a valid second-generation permutation code; see isPermCode2() for details.
Parameters
codethe second-generation code that will determine the new value of this permutation.

◆ sign()

constexpr int regina::Perm< 6 >::sign ( ) const
inlineconstexpr

Determines the sign of this permutation.

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

◆ SnIndex()

constexpr Perm< 6 >::Index regina::Perm< 6 >::SnIndex ( ) const
inlineconstexpr

Returns the index of this permutation in the Perm<6>::Sn array.

See Sn for further information on how these permutations are indexed.

Returns
the index i for which this permutation is equal to Perm<6>::Sn[i]. This will be between 0 and 719 inclusive.

◆ str()

std::string regina::Perm< 6 >::str ( ) const

Returns a string representation of this permutation.

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

Returns
a string representation of this permutation.

◆ trunc()

std::string regina::Perm< 6 >::trunc ( unsigned  len) const

Returns a prefix of the string representation of this permutation, containing only the images of the first len integers.

Parameters
lenthe length of the prefix required; this must be between 0 and 6 inclusive.
Returns
the corresponding prefix of the string representation of this permutation.

Member Data Documentation

◆ code2_

Code2 regina::Perm< 6 >::code2_
protected

The internal second-generation permutation code representing this permutation.

◆ codeType

constexpr PermCodeType regina::Perm< 6 >::codeType = PERM_CODE_INDEX
staticconstexpr

Indicates what type of internal permutation code is used by this instance of the Perm class template.

◆ imageBits

constexpr int regina::Perm< 6 >::imageBits = 3
staticconstexpr

Indicates the number of bits used in an image pack to store the image of a single integer.

A full image pack combines 6 such images together, and so uses 6 * imageBits bits in total.

◆ imageMask

constexpr ImagePack regina::Perm< 6 >::imageMask
staticconstexpr
Initial value:
=
(static_cast<ImagePack>(1) << imageBits) - 1
static constexpr int imageBits
Indicates the number of bits used in an image pack to store the image of a single integer.
Definition: perm6.h:170
uint32_t ImagePack
Indicates the native unsigned integer type used to store a single image pack.
Definition: perm6.h:178

A bitmask whose lowest imageBits bits are 1, and whose remaining higher order bits are all 0.

This may be useful when creating or analysing image packs.

◆ nPerms

constexpr Index regina::Perm< 6 >::nPerms = 720
staticconstexpr

The total number of permutations on six elements.

This is the size of the array Sn.

◆ nPerms_1

constexpr Index regina::Perm< 6 >::nPerms_1 = 120
staticconstexpr

The total number of permutations on five elements.

This is the size of the symmetric group S5.

◆ orderedS6

constexpr OrderedS6Lookup regina::Perm< 6 >::orderedS6 {}
staticconstexpr

Gives array-like access to all possible permutations of six elements in lexicographical order.

This is a dimension-specific alias for Perm<6>::orderedSn; see that member for further information. In general, for every n there will be a static member Perm<n>::orderedSn; however, these numerical aliases Perm<2>::orderedS2, ..., Perm<6>::orderedS6 are only available for small n.

◆ orderedSn

constexpr OrderedS6Lookup regina::Perm< 6 >::orderedSn {}
staticconstexpr

Gives array-like access to all possible permutations of six elements in lexicographical order.

To access the permutation at index i, you simply use the square bracket operator: orderedSn[i]. The index i must be between 0 and 719 inclusive.

Lexicographical ordering treats each permutation p as the ordered pair (p[0], ..., p[5]).

Accessing elements through this object is extremely fast. The object that is returned is lightweight and is defined in the headers only; in particular, you cannot make a reference to it (but you can always make a copy).

This is different from Perm<6>::Sn, since this array orderedSn stores permutations in lexicographical order, whereas Sn alternates between even and odd permutations.

◆ S6

constexpr S6Lookup regina::Perm< 6 >::S6 {}
staticconstexpr

Gives array-like access to all possible permutations of six elements.

This is a dimension-specific alias for Perm<6>::Sn; see that member for further information. In general, for every n there will be a static member Perm<n>::Sn; however, these numerical aliases Perm<2>::S2, ..., Perm<6>::S6 are only available for small n.

◆ Sn

constexpr S6Lookup regina::Perm< 6 >::Sn {}
staticconstexpr

Gives array-like access to all possible permutations of six elements.

To access the permutation at index i, you simply use the square bracket operator: Sn[i]. The index i must be between 0 and 719 inclusive.

Accessing elements through this object is extremely fast. The object that is returned is lightweight and is defined in the headers only; in particular, you cannot make a reference to it (but you can always make a copy).

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

This is different from Perm<6>::orderedSn, since this array Sn alternates between even and odd permutations, whereas orderedSn stores permutations in lexicographical order.


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

Copyright © 1999-2021, 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@maths.uq.edu.au).