Regina Calculation Engine
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
regina::NMatrixInt Class Reference

Represents a matrix of arbitrary precision integers. More...

#include <maths/nmatrixint.h>

Inheritance diagram for regina::NMatrixInt:
regina::NMatrixRing< NLargeInteger > regina::ShareableObject regina::NMatrix< NLargeInteger > regina::boost::noncopyable

Public Member Functions

 NMatrixInt (unsigned long rows, unsigned long cols)
 Creates a new matrix of the given size. More...
 
 NMatrixInt (const NMatrixInt &cloneMe)
 Creates a new matrix that is a clone of the given matrix. More...
 
void divRowExact (unsigned long row, const NLargeInteger &divBy)
 Divides all elements of the given row by the given integer. More...
 
void divColExact (unsigned long col, const NLargeInteger &divBy)
 Divides all elements of the given column by the given integer. More...
 
NLargeInteger gcdRow (unsigned long row)
 Computes the greatest common divisor of all elements of the given row. More...
 
NLargeInteger gcdCol (unsigned long col)
 Computes the greatest common divisor of all elements of the given column. More...
 
void reduceRow (unsigned long row)
 Reduces the given row by dividing all its elements by their greatest common divisor. More...
 
void reduceCol (unsigned long col)
 Reduces the given column by dividing all its elements by their greatest common divisor. More...
 
virtual void writeTextShort (std::ostream &out) const
 Writes this object in short text format to the given output stream. More...
 
virtual void writeTextLong (std::ostream &out) const
 Writes this object in long text format to the given output stream. More...
 
void makeIdentity ()
 Turns this matrix into an identity matrix. More...
 
bool isIdentity () const
 Determines whether this matrix is a square identity matrix. More...
 
bool isZero () const
 Determines whether this is the zero matrix. More...
 
void addRow (unsigned long source, unsigned long dest)
 Adds the given source row to the given destination row. More...
 
void addRow (unsigned long source, unsigned long dest, NLargeIntegercopies)
 Adds the given number of copies of the given source row to the given destination row. More...
 
void addCol (unsigned long source, unsigned long dest)
 Adds the given source column to the given destination column. More...
 
void addCol (unsigned long source, unsigned long dest, NLargeIntegercopies)
 Adds the given number of copies of the given source column to the given destination column. More...
 
void multRow (unsigned long row, NLargeIntegerfactor)
 Multiplies the given row by the given factor. More...
 
void multCol (unsigned long column, NLargeIntegerfactor)
 Multiplies the given column by the given factor. More...
 
std::auto_ptr< NMatrixRing
< NLargeInteger > > 
operator* (const NMatrixRing< NLargeInteger > &other) const
 Multiplies this by the given matrix, and returns the result. More...
 
std::auto_ptr< MatrixClass > multiplyAs (const NMatrixRing< NLargeInteger > &other) const
 Multiplies this by the given matrix, and returns a new matrix of subclass MatrixClass. More...
 
NLargeInteger det () const
 Evaluates the determinant of the matrix. More...
 
void initialise (const NLargeInteger &value)
 Sets every entry in the matrix to the given value. More...
 
void initialise (List allValues)
 A Python-only routine that fills the matrix with the given set of elements. More...
 
unsigned long rows () const
 Returns the number of rows in this matrix. More...
 
unsigned long columns () const
 Returns the number of columns in this matrix. More...
 
NLargeIntegerentry (unsigned long row, unsigned long column)
 Returns the entry at the given row and column. More...
 
const NLargeIntegerentry (unsigned long row, unsigned long column) const
 Returns the entry at the given row and column. More...
 
bool operator== (const NMatrix< NLargeInteger > &other) const
 Determines whether this and the given matrix are identical. More...
 
bool operator!= (const NMatrix< NLargeInteger > &other) const
 Determines whether this and the given matrix are different. More...
 
virtual void writeMatrix (std::ostream &out) const
 Writes a complete representation of the matrix to the given output stream. More...
 
void swapRows (unsigned long first, unsigned long second)
 Swaps the elements of the two given rows in the matrix. More...
 
void swapColumns (unsigned long first, unsigned long second)
 Swaps the elements of the two given columns in the matrix. More...
 
Input and Output
std::string str () const
 Returns the output from writeTextShort() as a string. More...
 
std::string toString () const
 A deprecated alias for str(), which returns the output from writeTextShort() as a string. More...
 
std::string detail () const
 Returns the output from writeTextLong() as a string. More...
 
std::string toStringLong () const
 A deprecated alias for detail(), which returns the output from writeTextLong() as a string. More...
 

Static Public Attributes

static NLargeInteger zero
 Zero in the underlying ring. More...
 
static NLargeInteger one
 One (the multiplicative identity) in the underlying ring. More...
 

Protected Attributes

unsigned long nRows
 The number of rows in the matrix. More...
 
unsigned long nCols
 The number of columns in the matrix. More...
 
NLargeInteger ** data
 The actual entries in the matrix. More...
 

Detailed Description

Represents a matrix of arbitrary precision integers.

Calculations will be exact no matter how large the integers become.

Note that many important functions (such as entry()) are inherited from the superclasses NMatrix and NMatrixRing, and are not documented again here. Many other algorithms that work on the NMatrixInt class are available in the maths/matrixops.h file.

Python:
Most inherited member functions are implemented. Exceptions are noted in the documentation for each individual member function.

Member Function Documentation

void regina::NMatrixRing< NLargeInteger >::addCol ( unsigned long  source,
unsigned long  dest 
)
inlineinherited

Adds the given source column to the given destination column.

Precondition
The two given columns are distinct and between 0 and columns()-1 inclusive.
Parameters
sourcethe columns to add.
destthe column that will be added to.
void regina::NMatrixRing< NLargeInteger >::addCol ( unsigned long  source,
unsigned long  dest,
NLargeInteger  copies 
)
inlineinherited

Adds the given number of copies of the given source column to the given destination column.

Note that copies is passed by value in case it is an element of the row to be changed.

Precondition
The two given columns are distinct and between 0 and columns()-1 inclusive.
Parameters
sourcethe columns to add.
destthe column that will be added to.
copiesthe number of copies of source to add to dest.
void regina::NMatrixRing< NLargeInteger >::addRow ( unsigned long  source,
unsigned long  dest 
)
inlineinherited

Adds the given source row to the given destination row.

Precondition
The two given rows are distinct and between 0 and rows()-1 inclusive.
Parameters
sourcethe row to add.
destthe row that will be added to.
void regina::NMatrixRing< NLargeInteger >::addRow ( unsigned long  source,
unsigned long  dest,
NLargeInteger  copies 
)
inlineinherited

Adds the given number of copies of the given source row to the given destination row.

Note that copies is passed by value in case it is an element of the row to be changed.

Precondition
The two given rows are distinct and between 0 and rows()-1 inclusive.
Parameters
sourcethe row to add.
destthe row that will be added to.
copiesthe number of copies of source to add to dest.
unsigned long regina::NMatrix< NLargeInteger >::columns ( ) const
inlineinherited

Returns the number of columns in this matrix.

Returns
the number of columns.
NLargeInteger regina::NMatrixRing< NLargeInteger >::det ( ) const
inlineinherited

Evaluates the determinant of the matrix.

This algorithm has quartic complexity, and uses the dynamic programming approach of Mahajan and Vinay. For further details, see Meena Mahajan and V. Vinay, "Determinant: Combinatorics, algorithms, and complexity", Chicago J. Theor. Comput. Sci., Vol. 1997, Article 5.

Precondition
This is a square matrix.
Returns
the determinant of this matrix.
std::string regina::ShareableObject::detail ( ) const
inherited

Returns the output from writeTextLong() as a string.

Returns
a long text representation of this object.
void regina::NMatrixInt::divColExact ( unsigned long  col,
const NLargeInteger divBy 
)
inline

Divides all elements of the given column by the given integer.

This can only be used when the given integer divides into all column elements exactly (with no remainder), and is much faster than ordinary division.

Precondition
The argument divBy is neither zero nor infinity, and none of the elements of the given column are infinity.
The argument divBy divides exactly into every element of the given column (i.e., it leaves no remainder).
The given column number is between 0 and columns()-1 inclusive.
Parameters
colthe index of the column whose elements should be divided by divBy.
divBythe integer to divide each column element by.
void regina::NMatrixInt::divRowExact ( unsigned long  row,
const NLargeInteger divBy 
)
inline

Divides all elements of the given row by the given integer.

This can only be used when the given integer divides into all row elements exactly (with no remainder), and is much faster than ordinary division.

Precondition
The argument divBy is neither zero nor infinity, and none of the elements of the given row are infinity.
The argument divBy divides exactly into every element of the given row (i.e., it leaves no remainder).
The given row number is between 0 and rows()-1 inclusive.
Parameters
rowthe index of the row whose elements should be divided by divBy.
divBythe integer to divide each row element by.
NLargeInteger & regina::NMatrix< NLargeInteger >::entry ( unsigned long  row,
unsigned long  column 
)
inlineinherited

Returns the entry at the given row and column.

Rows and columns are numbered beginning at zero.

Precondition
row is between 0 and rows()-1 inclusive.
column is between 0 and columns()-1 inclusive.
Python:
Although the entry() routine gives direct read-write access to matrix elements, the syntax matrix.entry(row, column) = value still cannot be used in python to set a matrix element directly. For this, you can use the syntax matrix.set(row, column, value). This set() routine returns nothing, and is provided for python only (i.e., it is not part of the C++ calculation engine).
Parameters
rowthe row of the desired entry.
columnthe column of the desired entry.
Returns
a reference to the entry in the given row and column.
const NLargeInteger & regina::NMatrix< NLargeInteger >::entry ( unsigned long  row,
unsigned long  column 
) const
inlineinherited

Returns the entry at the given row and column.

Rows and columns are numbered beginning at zero.

Precondition
row is between 0 and rows()-1 inclusive.
column is between 0 and columns()-1 inclusive.
Python:
Not present, although the non-const form of this routine is.
Parameters
rowthe row of the desired entry.
columnthe column of the desired entry.
Returns
a reference to the entry in the given row and column.
NLargeInteger regina::NMatrixInt::gcdCol ( unsigned long  col)
inline

Computes the greatest common divisor of all elements of the given column.

The value returned is guaranteed to be non-negative.

Precondition
The given column number is between 0 and columns()-1 inclusive.
Parameters
colthe index of the column whose gcd should be computed.
Returns
the greatest common divisor of all elements of this column.
NLargeInteger regina::NMatrixInt::gcdRow ( unsigned long  row)
inline

Computes the greatest common divisor of all elements of the given row.

The value returned is guaranteed to be non-negative.

Precondition
The given row number is between 0 and rows()-1 inclusive.
Parameters
rowthe index of the row whose gcd should be computed.
Returns
the greatest common divisor of all elements of this row.
void regina::NMatrix< NLargeInteger >::initialise ( const NLargeInteger value)
inlineinherited

Sets every entry in the matrix to the given value.

Parameters
valuethe value to assign to each entry.
void regina::NMatrix< NLargeInteger >::initialise ( List  allValues)
inherited

A Python-only routine that fills the matrix with the given set of elements.

The argument allValues must be a Python list of length rows() * columns(). Its values will be inserted into the matrix row by row (i.e., the first row will be filled, then the second row, and so on).

C++:
Not available; this routine is for Python only.
Parameters
allValuesthe individual elements to place into the matrix.
bool regina::NMatrixRing< NLargeInteger >::isIdentity ( ) const
inlineinherited

Determines whether this matrix is a square identity matrix.

If this matrix is square, isIdentity() will return true if and only if the matrix has ones in the main diagonal and zeroes everywhere else.

If this matrix is not square, isIdentity() will always return false (even if makeIdentity() was called earlier).

Returns
true if and only if this is a square identity matrix.
bool regina::NMatrixRing< NLargeInteger >::isZero ( ) const
inlineinherited

Determines whether this is the zero matrix.

Returns
true if and only if all entries in the matrix are zero.
void regina::NMatrixRing< NLargeInteger >::makeIdentity ( )
inlineinherited

Turns this matrix into an identity matrix.

This matrix need not be square; after this routine it will have entry(r,c) equal to one if r == c and zero otherwise.

void regina::NMatrixRing< NLargeInteger >::multCol ( unsigned long  column,
NLargeInteger  factor 
)
inlineinherited

Multiplies the given column by the given factor.

Note that factor is passed by value in case it is an element of the row to be changed.

Precondition
The given column is between 0 and columns()-1 inclusive.
Parameters
columnthe column to work with.
factorthe factor by which to multiply the given column.
std::auto_ptr<MatrixClass> regina::NMatrixRing< NLargeInteger >::multiplyAs ( const NMatrixRing< NLargeInteger > &  other) const
inlineinherited

Multiplies this by the given matrix, and returns a new matrix of subclass MatrixClass.

This matrix is not changed.

Precondition
The number of columns in this matrix equals the number of rows in the given matrix.
The class MatrixClass is a subclass of NMatrixRing<T>, and can be fully initialised by calling the two-argument constructor (passing the row and column counts) and then settng individual elements via data[r][c]. In particular, there should not be any new data members that need explicit initialisation.
Python:
Not present, but the python multiplication operator performs the same task (see the python notes for operator *).
Parameters
otherthe matrix by which to multiply this matrix.
Returns
a newly allocated matrix representing this * other.
void regina::NMatrixRing< NLargeInteger >::multRow ( unsigned long  row,
NLargeInteger  factor 
)
inlineinherited

Multiplies the given row by the given factor.

Note that factor is passed by value in case it is an element of the row to be changed.

Precondition
The given row is between 0 and rows()-1 inclusive.
Parameters
rowthe row to work with.
factorthe factor by which to multiply the given row.
bool regina::NMatrix< NLargeInteger >::operator!= ( const NMatrix< NLargeInteger > &  other) const
inlineinherited

Determines whether this and the given matrix are different.

Two matrices are different if either (i) their dimensions differ, or (ii) the corresponding elements of each matrix differ in at least one location.

Note that this routine can happily deal with two matrices of different dimensions (in which case it will always return true).

This routine returns true if and only if the equality operator (==) returns false.

Precondition
The type T provides an equality operator (==).
Parameters
otherthe matrix to compare with this.
Returns
true if the matrices are different as described above, or false otherwise.
std::auto_ptr<NMatrixRing<NLargeInteger > > regina::NMatrixRing< NLargeInteger >::operator* ( const NMatrixRing< NLargeInteger > &  other) const
inlineinherited

Multiplies this by the given matrix, and returns the result.

This matrix is not changed.

Precondition
The number of columns in this matrix equals the number of rows in the given matrix.
Warning
The returned matrix will be of the exact class NMatrixRing<T>, even if both this and other are of some common subclass of NMatrixRing<T>. If you need a subclass to be returned, consider calling multiplyAs() instead.
Python:
The multiplication operator for a subclass (such as NMatrixInt) will return a new matrix of that same subclass. That is, the python multiplication operator really calls multiplyAs(), not this routine.
Parameters
otherthe matrix by which to multiply this matrix.
Returns
a newly allocated matrix representing this * other.
bool regina::NMatrix< NLargeInteger >::operator== ( const NMatrix< NLargeInteger > &  other) const
inlineinherited

Determines whether this and the given matrix are identical.

Two matrices are identical if and only if (i) their dimensions are the same, and (ii) the corresponding elements of each matrix are equal.

Note that this routine can happily deal with two matrices of different dimensions (in which case it will always return false).

This routine returns true if and only if the inequality operator (!=) returns false.

Precondition
The type T provides an equality operator (==).
Parameters
otherthe matrix to compare with this.
Returns
true if the matrices are equal as described above, or false otherwise.
void regina::NMatrixInt::reduceCol ( unsigned long  col)
inline

Reduces the given column by dividing all its elements by their greatest common divisor.

It is guaranteed that, if the column is changed at all, it will be divided by a positive integer.

Precondition
The given column number is between 0 and columns()-1 inclusive.
Parameters
colthe index of the column to reduce.
void regina::NMatrixInt::reduceRow ( unsigned long  row)
inline

Reduces the given row by dividing all its elements by their greatest common divisor.

It is guaranteed that, if the row is changed at all, it will be divided by a positive integer.

Precondition
The given row number is between 0 and rows()-1 inclusive.
Parameters
rowthe index of the row to reduce.
unsigned long regina::NMatrix< NLargeInteger >::rows ( ) const
inlineinherited

Returns the number of rows in this matrix.

Returns
the number of rows.
std::string regina::ShareableObject::str ( ) const
inherited

Returns the output from writeTextShort() as a string.

Python:
This implements the __str__() function.
Returns
a short text representation of this object.
void regina::NMatrix< NLargeInteger >::swapColumns ( unsigned long  first,
unsigned long  second 
)
inlineinherited

Swaps the elements of the two given columns in the matrix.

Precondition
The two given columns are between 0 and columns()-1 inclusive.
Parameters
firstthe first column to swap.
secondthe second column to swap.
void regina::NMatrix< NLargeInteger >::swapRows ( unsigned long  first,
unsigned long  second 
)
inlineinherited

Swaps the elements of the two given rows in the matrix.

Precondition
The two given rows are between 0 and rows()-1 inclusive.
Parameters
firstthe first row to swap.
secondthe second row to swap.
std::string regina::ShareableObject::toString ( ) const
inlineinherited

A deprecated alias for str(), which returns the output from writeTextShort() as a string.

Deprecated:
This routine has (at long last) been deprecated; use the simpler-to-type str() instead.
Returns
a short text representation of this object.
std::string regina::ShareableObject::toStringLong ( ) const
inlineinherited

A deprecated alias for detail(), which returns the output from writeTextLong() as a string.

Deprecated:
This routine has (at long last) been deprecated; use the simpler-to-type detail() instead.
Returns
a long text representation of this object.
virtual void regina::NMatrix< NLargeInteger >::writeMatrix ( std::ostream &  out) const
inlinevirtualinherited

Writes a complete representation of the matrix to the given output stream.

Each row will be written on a separate line with elements in each row separated by single spaces.

Python:
Not present, even if a subclass of NMatrix is mirrored and its inherited routines are mirrored also.
Parameters
outthe output stream to which to write.

Member Data Documentation

NLargeInteger ** regina::NMatrix< NLargeInteger >::data
protectedinherited

The actual entries in the matrix.

data[r][c] is the element in row r, column c.

unsigned long regina::NMatrix< NLargeInteger >::nCols
protectedinherited

The number of columns in the matrix.

unsigned long regina::NMatrix< NLargeInteger >::nRows
protectedinherited

The number of rows in the matrix.

One (the multiplicative identity) in the underlying ring.

This would be const if it weren't for the fact that some compilers don't like this. It should never be modified!

Zero in the underlying ring.

This would be const if it weren't for the fact that some compilers don't like this. It should never be modified!


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

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