Regina 7.3 Calculation Engine
Public Member Functions | Friends | List of all members
regina::Matrix2 Class Reference

Represents a 2-by-2 integer matrix. More...

#include <maths/matrix2.h>

Public Member Functions

 Matrix2 ()
 Initialises to the zero matrix. More...
 
 Matrix2 (const Matrix2 &)=default
 Initialises to a copy of the given matrix. More...
 
 Matrix2 (long val00, long val01, long val10, long val11)
 Initialises to the given integer values. More...
 
Matrix2operator= (const Matrix2 &)=default
 Sets this matrix to be a copy of the given matrix. More...
 
void swap (Matrix2 &other) noexcept
 Swaps the contents of this and the given matrix. More...
 
const std::array< long, 2 > & operator[] (unsigned row) const
 Returns a single row of this matrix. More...
 
std::array< long, 2 > & operator[] (unsigned row)
 Returns a single row of this matrix. More...
 
Matrix2 operator* (const Matrix2 &other) const
 Calculates the matrix product of this and the given matrix. More...
 
Matrix2 operator* (long scalar) const
 Calculates the scalar product of this matrix and the given integer. More...
 
Matrix2 operator+ (const Matrix2 &other) const
 Calculates the sum of two matrices. More...
 
Matrix2 operator- (const Matrix2 &other) const
 Calculates the difference of two matrices. More...
 
Matrix2 operator- () const
 Determines the negative of this matrix. More...
 
Matrix2 transpose () const
 Returns the transpose of this matrix. More...
 
Matrix2 inverse () const
 Calculates the inverse of this matrix. More...
 
Matrix2operator+= (const Matrix2 &other)
 Adds the given matrix to this. More...
 
Matrix2operator-= (const Matrix2 &other)
 Subtracts the given matrix from this. More...
 
Matrix2operator*= (const Matrix2 &other)
 Multiplies this by the given matrix. More...
 
Matrix2operator*= (long scalar)
 Multiplies this by the given scalar. More...
 
void negate ()
 Negates this matrix. More...
 
bool invert ()
 Inverts this matrix. More...
 
bool operator== (const Matrix2 &compare) const
 Determines if this is equal to the given matrix. More...
 
bool operator!= (const Matrix2 &compare) const
 Determines if this is not equal to the given matrix. More...
 
long determinant () const
 Returns the determinant of this matrix. More...
 
bool isIdentity () const
 Determines if this is the 2-by-2 identity matrix. More...
 
bool isZero () const
 Determines if this is the 2-by-2 zero matrix. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const Matrix2 &mat)
 Writes the given matrix to the given output stream. More...
 

Detailed Description

Represents a 2-by-2 integer matrix.

The advantage of using this class over the larger Matrix class template (e.g., MatrixInt) is that this class has less overhead.

This class only contains four long integers, and so it may be considered small enough to pass about by value.

This class supports copying but does not implement separate move operations, since its internal data is so small that copying is just as efficient. It implements the C++ Swappable requirement via its own member and global swap() functions, for consistency with the Matrix classes.

Constructor & Destructor Documentation

◆ Matrix2() [1/3]

regina::Matrix2::Matrix2 ( )
inline

Initialises to the zero matrix.

◆ Matrix2() [2/3]

regina::Matrix2::Matrix2 ( const Matrix2 )
default

Initialises to a copy of the given matrix.

◆ Matrix2() [3/3]

regina::Matrix2::Matrix2 ( long  val00,
long  val01,
long  val10,
long  val11 
)
inline

Initialises to the given integer values.

Parameters
val00the value to place in row 0, column 0.
val01the value to place in row 0, column 1.
val10the value to place in row 1, column 0.
val11the value to place in row 1, column 1.

Member Function Documentation

◆ determinant()

long regina::Matrix2::determinant ( ) const
inline

Returns the determinant of this matrix.

Returns
the determinant of this matrix.

◆ inverse()

Matrix2 regina::Matrix2::inverse ( ) const

Calculates the inverse of this matrix.

This matrix is not changed.

This routine only works for integer matrices whose determinant is either +1 or -1.

Returns
the inverse of this matrix. If this matrix does not have determinant +1 or -1, the zero matrix will be returned instead.

◆ invert()

bool regina::Matrix2::invert ( )

Inverts this matrix.

This routine only works for integer matrices whose determinant is either +1 or -1. Otherwise this matrix is left unchanged.

Returns
true if this matrix was successfully inverted (i.e., its determinant was +1 or -1), or false otherwise.

◆ isIdentity()

bool regina::Matrix2::isIdentity ( ) const
inline

Determines if this is the 2-by-2 identity matrix.

Returns
true if this is the identity matrix, or false otherwise.

◆ isZero()

bool regina::Matrix2::isZero ( ) const
inline

Determines if this is the 2-by-2 zero matrix.

Returns
true if this is the zero matrix, or false otherwise.

◆ negate()

void regina::Matrix2::negate ( )
inline

Negates this matrix.

This matrix is changed to reflect the result.

◆ operator!=()

bool regina::Matrix2::operator!= ( const Matrix2 compare) const
inline

Determines if this is not equal to the given matrix.

Parameters
comparethe matrix with which this will be compared.
Returns
true if and only if this matrix is not equal to compare.

◆ operator*() [1/2]

Matrix2 regina::Matrix2::operator* ( const Matrix2 other) const
inline

Calculates the matrix product of this and the given matrix.

Neither this nor the given matrix is changed.

Parameters
otherthe matrix that this should be multiplied by.
Returns
the product this * other.

◆ operator*() [2/2]

Matrix2 regina::Matrix2::operator* ( long  scalar) const
inline

Calculates the scalar product of this matrix and the given integer.

This matrix is not changed.

Parameters
scalarthe integer that this matrix should be multiplied by.
Returns
the product this * scalar.

◆ operator*=() [1/2]

Matrix2 & regina::Matrix2::operator*= ( const Matrix2 other)

Multiplies this by the given matrix.

This matrix is changed to reflect the result.

Parameters
otherthe matrix by which this should be multiplied.
Returns
a reference to this matrix with its new value.

◆ operator*=() [2/2]

Matrix2 & regina::Matrix2::operator*= ( long  scalar)
inline

Multiplies this by the given scalar.

This matrix is changed to reflect the result.

Parameters
scalarthe scalar by which this should be multiplied.
Returns
a reference to this matrix with its new value.

◆ operator+()

Matrix2 regina::Matrix2::operator+ ( const Matrix2 other) const
inline

Calculates the sum of two matrices.

Neither this nor the given matrix is changed.

Parameters
otherthe matrix to add to this.
Returns
the sum this + other.

◆ operator+=()

Matrix2 & regina::Matrix2::operator+= ( const Matrix2 other)
inline

Adds the given matrix to this.

This matrix is changed to reflect the result.

Parameters
otherthe matrix to add to this.
Returns
a reference to this matrix with its new value.

◆ operator-() [1/2]

Matrix2 regina::Matrix2::operator- ( ) const
inline

Determines the negative of this matrix.

This matrix is not changed.

Returns
the negative of this matrix.

◆ operator-() [2/2]

Matrix2 regina::Matrix2::operator- ( const Matrix2 other) const
inline

Calculates the difference of two matrices.

Neither this nor the given matrix is changed.

Parameters
otherthe matrix to subtract from this.
Returns
the difference this - other.

◆ operator-=()

Matrix2 & regina::Matrix2::operator-= ( const Matrix2 other)
inline

Subtracts the given matrix from this.

This matrix is changed to reflect the result.

Parameters
otherthe matrix to subtract from this.
Returns
a reference to this matrix with its new value.

◆ operator=()

Matrix2 & regina::Matrix2::operator= ( const Matrix2 )
default

Sets this matrix to be a copy of the given matrix.

Returns
a reference to this matrix.

◆ operator==()

bool regina::Matrix2::operator== ( const Matrix2 compare) const
inline

Determines if this is equal to the given matrix.

Parameters
comparethe matrix with which this will be compared.
Returns
true if and only if this matrix is equal to compare.

◆ operator[]() [1/2]

std::array< long, 2 > & regina::Matrix2::operator[] ( unsigned  row)
inline

Returns a single row of this matrix.

This means that the integer in row r, column c can be accessed as myMatrix[r][c] (where r and c are each 0 or 1). Each such element may be modified directly.

Parameters
rowthe index of the requested row; this must be 0 or 1.
Returns
a two-integer array containing the elements of the requested row.

◆ operator[]() [2/2]

const std::array< long, 2 > & regina::Matrix2::operator[] ( unsigned  row) const
inline

Returns a single row of this matrix.

This means that the integer in row r, column c can be accessed as myMatrix[r][c] (where r and c are each 0 or 1).

Parameters
rowthe index of the requested row; this must be 0 or 1.
Returns
a two-integer array containing the elements of the requested row.

◆ swap()

void regina::Matrix2::swap ( Matrix2 other)
inlinenoexcept

Swaps the contents of this and the given matrix.

Parameters
otherthe matrix whose contents should be swapped with this.

◆ transpose()

Matrix2 regina::Matrix2::transpose ( ) const
inline

Returns the transpose of this matrix.

This matrix is not changed.

Returns
the transpose of this matrix.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const Matrix2 mat 
)
friend

Writes the given matrix to the given output stream.

The matrix will be written entirely on a single line, with the first row followed by the second row.

Parameters
outthe output stream to which to write.
matthe matrix to write.
Returns
a reference to out.

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

Copyright © 1999-2023, 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).