repthy
Class MatrixModp

Object
  extended byMatrixModp
All Implemented Interfaces:
Comparable, GroupElt
Direct Known Subclasses:
PMatrixModp

public class MatrixModp
extends Object
implements GroupElt, Comparable

Square matrices with byte entries modulo a rational prime p. All operations returning mod p values (entries of the matrix, entries of the inverse matrix, etc.) will return least positive residues. The constructors convert all matrix entries to their least positive residues. If p is negative, it's silently made positive.

It follows that this implementation requires 2 ≤ p ≤ 127. For example, if you try to set p to 131, it will be wrapped to -125, which will be rejected because its absolute value is not prime.

Operations on two MatrixModps will throw IllegalArgumentException if the degrees or the primes don't match.

Author:
Mark McConnell

Constructor Summary
MatrixModp(byte[][] x, byte p)
          Builds a matrix with entries taken from the square array x mod p.
MatrixModp(int n, byte[] x, byte p)
          Inspired by APL's ravel function ρ (rho), this constructor returns the n by n matrix whose entries, in row major order, come from x.
 
Method Summary
 boolean commutesWith(GroupElt y)
          Whether this and y commute.
 int compareTo(Object o)
          Compares matrices lexicographically, taking the entries as least positive residues mod p in row-major order; however, a matrix in Jordan canonical form always comes before one that's not.
 GroupElt conjugate(GroupElt y)
          Returns y * this * y^(-1).
 GroupElt conjugateYinvXY(GroupElt y)
          Returns y^(-1) * this * y.
 byte det()
          Returns the determinant.
static byte det(byte[][] a, byte p)
          Returns the determinant of a mod p.
 boolean equals(Object o)
          Tests for equality in the mathematical sense, not by ==.
 byte getEntry(int i, int j)
          Returns the (i,j)-th entry.
 GroupElt getIdentity()
          Returns the identity element of the same class as this.
 int getOrder(Group G)
          Returns the order of this element.
 byte getP()
          Returns the prime p.
 int getSize()
          If this matrix is n-by-n, returns n.
 int hashCode()
          Must be consistent with equals(java.lang.Object).
 GroupElt inverse()
          Returns the inverse element for this.
 boolean isDiagonal()
           
 boolean isIdentity()
          Tests whether this is the identity element among GroupElts of its class.
 boolean isJordanCanonical()
          Whether this is in Jordan canonical form.
 boolean isPermShaped()
          Whether the matrix has exactly one non-zero entry in each row and in each column.
 boolean isSignedPerm()
          Whether the matrix has exactly one non-zero entry in each row and in each column, and each non-zero entry is either 1 or -1.
 boolean isUnipotentUpperTriangular()
          Whether the matrix is upper-triangular with 1's on the diagonal.
 boolean isUpperTriangular()
           
static void main(String[] args)
          For testing.
 GroupElt mult(GroupElt y)
          Returns the product this * y.
 GroupElt power(int i)
          Returns the i-th power of this element.
 String toString()
          For example, prints a 2 by 2 matrix as [a b; c d].
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MatrixModp

public MatrixModp(byte[][] x,
                  byte p)
Builds a matrix with entries taken from the square array x mod p. The array structure is cloned, so changes to x later won't affect what's here. Entries are converted to their least positive residues mod p. As the comment on the class explains, we're effectively requiring 2 ≤ p ≤ 127.

Throws:
IllegalArgumentException - If x is not square or p is not prime.

MatrixModp

public MatrixModp(int n,
                  byte[] x,
                  byte p)
Inspired by APL's ravel function ρ (rho), this constructor returns the n by n matrix whose entries, in row major order, come from x. If x is too short, we cycle through it from the beginning as often as necessary. x must have length at least 1. Entries are converted to their least positive residues mod p.

Method Detail

det

public byte det()
Returns the determinant.


det

public static byte det(byte[][] a,
                       byte p)
Returns the determinant of a mod p. Doesn't change a.


mult

public GroupElt mult(GroupElt y)
Description copied from interface: GroupElt
Returns the product this * y. The operation must be associative.

Specified by:
mult in interface GroupElt

inverse

public GroupElt inverse()
Description copied from interface: GroupElt
Returns the inverse element for this.

Specified by:
inverse in interface GroupElt

equals

public boolean equals(Object o)
Description copied from interface: GroupElt
Tests for equality in the mathematical sense, not by ==.

Specified by:
equals in interface GroupElt

hashCode

public final int hashCode()
Description copied from interface: GroupElt
Must be consistent with GroupElt.equals(java.lang.Object).

Specified by:
hashCode in interface GroupElt

isIdentity

public boolean isIdentity()
Description copied from interface: GroupElt
Tests whether this is the identity element among GroupElts of its class.

Specified by:
isIdentity in interface GroupElt

getIdentity

public GroupElt getIdentity()
Description copied from interface: GroupElt
Returns the identity element of the same class as this.

Specified by:
getIdentity in interface GroupElt

conjugate

public GroupElt conjugate(GroupElt y)
Description copied from interface: GroupElt
Returns y * this * y^(-1). Compare GroupElt.conjugateYinvXY(repthy.GroupElt).

Specified by:
conjugate in interface GroupElt

conjugateYinvXY

public GroupElt conjugateYinvXY(GroupElt y)
Description copied from interface: GroupElt
Returns y^(-1) * this * y. Compare GroupElt.conjugate(repthy.GroupElt).

Specified by:
conjugateYinvXY in interface GroupElt

commutesWith

public boolean commutesWith(GroupElt y)
Description copied from interface: GroupElt
Whether this and y commute.

Specified by:
commutesWith in interface GroupElt

getOrder

public int getOrder(Group G)
Description copied from interface: GroupElt
Returns the order of this element. Implementations may be based on Group.getEltOrder(GroupElt, Group). However, if code needs to compute the order for many elements of a fixed group, Group.getEltOrder(GroupElt, int, int[][]) may be more efficient.

Specified by:
getOrder in interface GroupElt
Parameters:
G - A group containing this element. It can be null, but if it's not, we can use a more efficient algorithm.

power

public GroupElt power(int i)
Description copied from interface: GroupElt
Returns the i-th power of this element. Implementations may be based on Group.power(repthy.GroupElt, int), which uses an efficient squaring algorithm.

Specified by:
power in interface GroupElt

getSize

public final int getSize()
If this matrix is n-by-n, returns n.


getP

public final byte getP()
Returns the prime p.


getEntry

public final byte getEntry(int i,
                           int j)
Returns the (i,j)-th entry. It's an error unless 0 ≤ i, j < n.


toString

public String toString()
For example, prints a 2 by 2 matrix as

[a b; c d].


compareTo

public int compareTo(Object o)
Compares matrices lexicographically, taking the entries as least positive residues mod p in row-major order; however, a matrix in Jordan canonical form always comes before one that's not.

Specified by:
compareTo in interface Comparable

isJordanCanonical

public boolean isJordanCanonical()
Whether this is in Jordan canonical form.


isDiagonal

public boolean isDiagonal()

isSignedPerm

public boolean isSignedPerm()
Whether the matrix has exactly one non-zero entry in each row and in each column, and each non-zero entry is either 1 or -1.


isPermShaped

public boolean isPermShaped()
Whether the matrix has exactly one non-zero entry in each row and in each column.


isUpperTriangular

public boolean isUpperTriangular()

isUnipotentUpperTriangular

public boolean isUnipotentUpperTriangular()
Whether the matrix is upper-triangular with 1's on the diagonal.


main

public static void main(String[] args)
For testing.