Regina 7.0 Calculation Engine
|
Represents a permutation of {0,1,2}. More...
#include <maths/spec/perm3.h>
Public Types | |
using | Index = int |
Denotes a native signed integer type large enough to count all permutations on three elements. More... | |
using | Code = uint8_t |
Indicates the native unsigned integer type used to store the internal permutation code. 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) |
Creates a permutation mapping (0,1,2) to (a,b,c) respectively. More... | |
constexpr | Perm (const std::array< int, 3 > &image) |
Creates a permutation mapping i to image[i] for each i = 0,1,2. More... | |
constexpr | Perm (const int *image) |
Deprecated constructor that creates a permutation mapping i to image[i] for each i = 0,1,2. More... | |
constexpr | Perm (const int *a, const int *b) |
Deprecated constructor that creates a permutation mapping (a[0], ..., a[2]) to (b[0], ..., b[2]) respectively. More... | |
constexpr | Perm (int a0, int a1, int b0, int b1, int c0, int c1) |
Creates a permutation mapping (a0,b0,c0) to (a1,b1,c1) respectively. More... | |
constexpr | Perm (const Perm< 3 > &cloneMe)=default |
Creates a permutation that is a clone of the given permutation. More... | |
constexpr Code | permCode () const |
Returns the internal code representing this permutation. More... | |
void | setPermCode (Code code) |
Sets this permutation to that represented by the given internal code. More... | |
Perm< 3 > & | operator= (const Perm< 3 > &cloneMe)=default |
Sets this permutation to be equal to the given permutation. More... | |
constexpr Perm< 3 > | operator* (const Perm< 3 > &q) const |
Returns the composition of this permutation with the given permutation. More... | |
constexpr Perm< 3 > | inverse () const |
Finds the inverse of this permutation. More... | |
constexpr Perm< 3 > | pow (long exp) const |
Computes the given power of this permutation. More... | |
constexpr int | order () const |
Returns the order of this permutation. More... | |
constexpr Perm< 3 > | 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< 3 > &other) const |
Determines if this is equal to the given permutation. More... | |
constexpr bool | operator!= (const Perm< 3 > &other) const |
Determines if this differs from the given permutation. More... | |
constexpr int | compareWith (const Perm< 3 > &other) const |
Lexicographically compares the images of (0,1,2) under this and the given permutation. More... | |
constexpr bool | isIdentity () const |
Determines if this is the identity permutation. More... | |
Perm< 3 > & | operator++ () |
A preincrement operator that changes this to be the next permutation in the array Perm<3>::Sn. More... | |
constexpr Perm< 3 > | operator++ (int) |
A postincrement operator that changes this to be the next permutation in the array Perm<3>::Sn. More... | |
constexpr bool | operator< (const Perm< 3 > &rhs) const |
Determines if this appears earlier than the given permutation in the array Perm<3>::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... | |
std::string | trunc2 () const |
Returns a string representation of this permutation with only the images of 0 and 1. 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<3>::Sn array. More... | |
constexpr Index | S3Index () const |
Returns the index of this permutation in the Perm<3>::S3 array. More... | |
constexpr Index | orderedSnIndex () const |
Returns the lexicographical index of this permutation. More... | |
constexpr Index | orderedS3Index () 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< 3 > | rand (URBG &&gen, bool even) |
Static Public Member Functions | |
static constexpr Perm< 3 > | fromPermCode (Code code) |
Creates a permutation from the given internal code. More... | |
static constexpr bool | isPermCode (Code code) |
Determines whether the given integer is a valid internal permutation code. More... | |
static constexpr Perm | rot (int i) |
Returns the ith rotation. More... | |
static Perm | rand (bool even=false) |
Returns a random permutation on three elements. More... | |
template<class URBG > | |
static Perm | rand (URBG &&gen, bool even=false) |
Returns a random permutation on three elements, using the given uniform random bit generator. More... | |
static constexpr Perm | atIndex (Index i) |
Deprecated routine that returns the ith permutation on three elements, where permutations are numbered lexicographically. More... | |
template<int k> | |
static constexpr Perm< 3 > | extend (Perm< k > p) |
Extends a k-element permutation to an 3-element permutation. More... | |
template<int k> | |
static constexpr Perm< 3 > | contract (Perm< k > p) |
Restricts a k-element permutation to an 3-element permutation, where k > 3. 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 = 6 |
The total number of permutations on three elements. More... | |
static constexpr Index | nPerms_1 = 2 |
The total number of permutations on two elements. More... | |
static constexpr S3Lookup | Sn {} |
Gives array-like access to all possible permutations of three elements. More... | |
static constexpr S3Lookup | S3 {} |
Gives array-like access to all possible permutations of three elements. More... | |
static constexpr OrderedS3Lookup | orderedSn {} |
Gives array-like access to all possible permutations of three elements in lexicographical order. More... | |
static constexpr OrderedS3Lookup | orderedS3 {} |
Gives array-like access to all possible permutations of three elements in lexicographical order. More... | |
static constexpr S2Lookup | Sn_1 {} |
Gives array-like access to all possible permutations of two elements. More... | |
static constexpr S2Lookup | S2 {} |
Gives array-like access to all possible permutations of two elements. More... | |
static constexpr Code | code012 = 0 |
The internal code for the permutation (0,1,2). More... | |
static constexpr Code | code021 = 1 |
The internal code for the permutation (0,2,1). More... | |
static constexpr Code | code120 = 2 |
The internal code for the permutation (1,2,0). More... | |
static constexpr Code | code102 = 3 |
The internal code for the permutation (1,0,2). More... | |
static constexpr Code | code201 = 4 |
The internal code for the permutation (2,0,1). More... | |
static constexpr Code | code210 = 5 |
The internal code for the permutation (2,1,0). More... | |
Protected Member Functions | |
constexpr | Perm (Code code) |
Creates a permutation from the given internal code. More... | |
Protected Attributes | |
Code | code_ |
The internal code representing this permutation. More... | |
Represents a permutation of {0,1,2}.
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 2-manifold 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. Moreover, Perm<3> in particular is extremely fast to work with.
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<3>, the internal code is an integer between 0 and 5 inclusive that gives the index of the permutation in the array Perm<3>::S3. This is consistent with the second-generation codes used in classes Perm<4>,...,Perm<7>.
To use this class, simply include the main permutation header maths/perm.h.
using regina::Perm< 3 >::Code = uint8_t |
Indicates the native unsigned integer type used to store the internal permutation code.
using regina::Perm< 3 >::Index = int |
Denotes a native signed integer type large enough to count all permutations on three elements.
In other words, this is a native signed integer type large enough to store (3!).
|
inlineconstexpr |
Creates the identity permutation.
|
inlineconstexpr |
Creates the transposition of a and b.
Note that a and b need not be distinct.
a | the element to switch with b. |
b | the element to switch with a. |
|
inlineconstexpr |
Creates a permutation mapping (0,1,2) to (a,b,c) respectively.
a | the desired image of 0. |
b | the desired image of 1. |
c | the desired image of 2. |
|
inlineconstexpr |
Creates a permutation mapping i to image[i] for each i = 0,1,2.
image | the array of images. |
|
inlineconstexpr |
Deprecated constructor that creates a permutation mapping i to image[i] for each i = 0,1,2.
image | the array of images. |
|
inlineconstexpr |
Deprecated constructor that creates a permutation mapping (a[0], ..., a[2]) to (b[0], ..., b[2]) respectively.
a | the array of preimages; this must have length 3. |
b | the corresponding array of images; this must also have length 3. |
|
inlineconstexpr |
Creates a permutation mapping (a0,b0,c0) to (a1,b1,c1) respectively.
a0 | the desired preimage of a1. |
b0 | the desired preimage of b1. |
c0 | the desired preimage of c1. |
a1 | the desired image of a0. |
b1 | the desired image of b0. |
c1 | the desired image of c0. |
|
constexprdefault |
Creates a permutation that is a clone of the given permutation.
cloneMe | the permutation to clone. |
|
inlineconstexprprotected |
Creates a permutation from the given internal code.
code | the internal code from which the new permutation will be created. |
|
inlinestaticconstexpr |
Deprecated routine that returns the ith permutation on three elements, where permutations are numbered lexicographically.
i | the lexicographical index of the permutation; this must be between 0 and 5 inclusive. |
void regina::Perm< 3 >::clear | ( | unsigned | from | ) |
Resets the images of all integers from from onwards to the identity map.
Specifically, for each i in the range from,...,2, this routine will ensure that image[i] == i
. The images of 0,1,...,from-1 will not be altered.
from | the first integer whose image should be reset. This must be between 0 and 3 inclusive. |
|
inlineconstexpr |
Lexicographically compares the images of (0,1,2) 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.
other | the permutation with which to compare this. |
|
staticconstexpr |
Restricts a k-element permutation to an 3-element permutation, where k > 3.
The resulting permutation will map 0,1,2 to their respective images under p, and will ignore the "unused" images p[3],...,p[k-1].
k | the number of elements for the input permutation; this must be strictly greater than 3. |
p | a permutation on k elements. |
|
staticconstexpr |
Extends a k-element permutation to an 3-element permutation.
where 2 ≤ k < 3. The only possible value of k is 2, but this routine is kept as a template function for consistency with the other classes' Perm<n>::extend() routines.
The resulting permutation will map 0,1 to their respective images under p, and will map the "unused" element 3 to itself.
k | the number of elements for the input permutation; this must be exactly 2. |
p | a permutation on two elements. |
|
inlinestaticconstexpr |
Creates a permutation from the given internal code.
code | the internal code for the new permutation. |
|
inlineconstexpr |
Deprecated routine that returns the lexicographical index of this permutation.
|
inlineconstexpr |
Finds the inverse of this permutation.
|
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<3>::Sn.
See Sn for further information on how permutations are indexed.
This routine is extremely fast for Perm<3>, since it essentially uses a hard-coded lookup table.
true
if and only if this permutation is minimal in its conjugacy class.
|
inlineconstexpr |
Determines if this is the identity permutation.
This is true if and only if each of 0, 1 and 2 is mapped to itself.
true
if and only if this is the identity permutation.
|
inlinestaticconstexpr |
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 permCode().
true
if and only if the given code is a valid internal permutation code.
|
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 or 2.
other | the permutation with which to compare this. |
true
if and only if this and the given permutation differ.
|
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]]
.
q | the permutation with which to compose this. |
|
inline |
A preincrement operator that changes this to be the next permutation in the array Perm<3>::Sn.
If this is the last such permutation then this will wrap around to become the first permutation in Perm<3>::Sn, which is the identity.
|
inlineconstexpr |
A postincrement operator that changes this to be the next permutation in the array Perm<3>::Sn.
If this is the last such permutation then this will wrap around to become the first permutation in Perm<3>::Sn, which is the identity.
|
inlineconstexpr |
Determines if this appears earlier than the given permutation in the array Perm<3>::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().
rhs | the permutation to compare this against. |
true
if and only if this appears before rhs in Sn.
|
default |
Sets this permutation to be equal to the given permutation.
cloneMe | the permutation whose value will be assigned to this permutation. |
|
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 and 2.
other | the permutation with which to compare this. |
true
if and only if this and the given permutation are equal.
|
inlineconstexpr |
Determines the image of the given integer under this permutation.
source | the integer whose image we wish to find. This should be between 0 and 2 inclusive. |
|
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.
|
inlineconstexpr |
Returns the lexicographical index of this permutation.
This will be the index of this permutation in the Perm<3>::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<5>::orderedS5Index() are only available for small n.
See orderedSn for further information on lexicographical ordering.
|
inlineconstexpr |
Returns the lexicographical index of this permutation.
This will be the index of this permutation in the Perm<3>::orderedSn array.
See orderedSn for further information on lexicographical ordering.
|
inlineconstexpr |
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().
|
inlineconstexpr |
Computes the given power of this permutation.
This routine runs in constant time.
exp | the exponent; this may be positive, zero or negative. |
|
inlineconstexpr |
Determines the preimage of the given integer under this permutation.
image | the integer whose preimage we wish to find. This should be between 0 and 2 inclusive. |
|
inlineconstexpr |
Deprecated routine that determines the preimage of the given integer under this permutation.
image | the integer whose preimage we wish to find. This should be between 0 and 2 inclusive. |
|
inlinestatic |
Returns a random permutation on three elements.
All permutations are returned with equal probability.
This routine is thread-safe, and uses RandomEngine for its random number generation.
rand(randomEngine.engine(), even)
.even | if true , then the resulting permutation is guaranteed to be even (and again all even permutations are returned with equal probability). |
|
static |
Returns a random permutation on three 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.
URBG | A type which, once any references are removed, must adhere to the C++ UniformRandomBitGenerator concept. |
gen | the source of randomness to use (e.g., one of the many options provided in the C++ standard random header). |
even | if true , then the resulting permutation is guaranteed to be even (and again all even permutations are returned with equal probability). |
|
inlineconstexpr |
Finds the reverse of this permutation.
Here reverse means that we reverse the images of 0,1,2. In other words, if permutation q is the reverse of p, then p[i] == q[2 - i]
for all i.
|
inlinestaticconstexpr |
Returns the ith rotation.
This maps k to k + i (mod 3) for all k.
i | the image of 0; this must be between 0 and 2 inclusive. |
|
inlineconstexpr |
Returns the index of this permutation in the Perm<3>::S3 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<5>::S5Index() are only available for small n.
See Sn for further information on how these permutations are indexed.
|
inline |
Sets this permutation to that represented by the given internal code.
code | the internal code that will determine the new value of this permutation. |
|
inlineconstexpr |
Determines the sign of this permutation.
|
inlineconstexpr |
Returns the index of this permutation in the Perm<3>::Sn array.
See Sn for further information on how these permutations are indexed.
std::string regina::Perm< 3 >::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
.
std::string regina::Perm< 3 >::trunc | ( | unsigned | len | ) | const |
Returns a prefix of the string representation of this permutation, containing only the images of the first len integers.
len | the length of the prefix required; this must be between 0 and 3 inclusive. |
std::string regina::Perm< 3 >::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.
|
staticconstexpr |
The internal code for the permutation (0,1,2).
|
staticconstexpr |
The internal code for the permutation (0,2,1).
|
staticconstexpr |
The internal code for the permutation (1,0,2).
|
staticconstexpr |
The internal code for the permutation (1,2,0).
|
staticconstexpr |
The internal code for the permutation (2,0,1).
|
staticconstexpr |
The internal code for the permutation (2,1,0).
|
protected |
The internal code representing this permutation.
|
staticconstexpr |
Indicates what type of internal permutation code is used by this instance of the Perm class template.
|
staticconstexpr |
The total number of permutations on three elements.
This is the size of the array Sn.
|
staticconstexpr |
The total number of permutations on two elements.
This is the size of the array Sn_1.
|
staticconstexpr |
Gives array-like access to all possible permutations of three elements in lexicographical order.
This is a dimension-specific alias for Perm<3>::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<5>::orderedS5 are only available for small n.
|
staticconstexpr |
Gives array-like access to all possible permutations of three 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 5 inclusive.
Lexicographical ordering treats each permutation p as the ordered pair (p[0], p[1], p[2]).
In Regina 6.0.1 and earlier, this was a hard-coded C-style array; since Regina 7.0 it has changed type, but accessing elements as described above remains 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<3>::Sn, since this array orderedSn stores permutations in lexicographical order, whereas Sn alternates between even and odd permutations.
|
staticconstexpr |
Gives array-like access to all possible permutations of two elements.
This is a dimension-specific alias for Perm<3>::Sn_1; see that member for further information.
Note that all small permutation classes (Perm<2>, ..., Perm<5>) have an S2 array: these all store the same two permutations in the same order (but of course using different data types).
There is no corresponding orderedS2 array, since the (trivial) arrays S2 and orderedS2 are identical.
|
staticconstexpr |
Gives array-like access to all possible permutations of three elements.
This is a dimension-specific alias for Perm<3>::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<5>::S5 are only available for small n.
Note that small permutation classes (Perm<3>, Perm<4>, Perm<5>) have an S3 array: these all store the same six permutations in the same order (but of course using different data types).
|
staticconstexpr |
Gives array-like access to all possible permutations of three 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 5 inclusive.
In Regina 6.0.1 and earlier, this was a hard-coded C-style array; since Regina 7.0 it has changed type, but accessing elements as described above remains 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<3>::orderedSn, since this array Sn alternates between even and odd permutations, whereas orderedSn stores permutations in lexicographical order.
|
staticconstexpr |
Gives array-like access to all possible permutations of two elements.
In each permutation, 2 maps to 2.
To access the permutation at index i, you simply use the square bracket operator: Sn_1[i]
. The index i must be between 0 and 1 inclusive.
In Regina 6.0.1 and earlier, this was a hard-coded C-style array; since Regina 7.0 it has changed type, but accessing elements as described above remains 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.