shh.csparse
Class SparseEltZ

Object
  extended bySparseElt
      extended bySparseEltEuc
          extended bySparseEltZ
All Implemented Interfaces:
Comparable
Direct Known Subclasses:
SparseEltZBig, SparseEltZInt

public abstract class SparseEltZ
extends SparseEltEuc
implements Comparable

Elements of a sparse vector over the ring of integers Z, in arbitrary precision. The subclass SparseEltZBig directly uses arbitrary-precision integers (BigIntegers). Other subclasses use primitive types like int, but the code automatically upgrades to more precise types when necessary. The user should never have to know which subclass of SparseEltZ is behind any given instance.

The implementation of Comparable compares by < on the values. Use SparseElt.INDEX_SORTER to compare on the indices.

The methods in this class assume that all their SparseElt arguments are from SparseEltZ. Expect ClassCastExceptions if this rule isn't followed.

Author:
Mark McConnell

Field Summary
static SparseEltZ NEG_ONE
          A constant with value -1 and unspecified index.
static SparseEltZ ONE
          A constant with value 1 and unspecified index.
static SparseEltZ ZERO
          A constant with value 0 and unspecified index.
 
Fields inherited from class SparseElt
INDEX_SORTER
 
Constructor Summary
SparseEltZ()
           
 
Method Summary
abstract  SparseEltZ abs()
          Returns a SparseEltZ whose value is the absolute value of the value of this, and whose index is that of this.
abstract  int compareTo(Object o)
          Compares SparseEltZs by < on the values.
abstract  SparseEltField copyMod(int p, BigInteger pBig)
          Returns this mod p, preserving the index.
abstract  SparseEltZ[] divideAndRemainder(SparseEltZ y)
          Computes this/y and returns a two-element array with values quotient and remainder.
 Comparator getEucNormComparator()
          Returns a Comparator C that compares by Euclidean norm.
 SparseElt getNegOne()
          Returns a SparseElt from the same integral domain as this, with value -1 and unspecified index.
 SparseElt getOne()
          Returns a SparseElt from the same integral domain as this, with value 1 and unspecified index.
abstract  BigInteger getValueAsBigInteger()
          Returns the value as a BigInteger.
abstract  double getValueAsDouble()
          Returns the value as a double.
abstract  int getValueAsInt()
          Coerces the value into an int and returns it.
 SparseElt getZero()
          Returns a SparseElt from the same integral domain as this, with value 0 and unspecified index.
 int hashCode()
          Is consistent with SparseElt.equals(java.lang.Object).
 boolean isEqualValue(SparseElt y)
          Tests whether the values are equal, ignoring the indices.
static SparseEltZ makeInstance(int index, BigInteger value)
          Makes a new instance of SparseEltZ, using the specified arguments.
static SparseEltZ makeInstance(int index, int value)
          Makes a new instance of SparseEltZ, using the specified arguments.
abstract  int signum()
          Returns -1, 0, or 1 as the value is negative, zero, or positive.
 
Methods inherited from class SparseEltEuc
eucNorm, negClosestQuotient
 
Methods inherited from class SparseElt
add, bitLength, copy, divides, equals, getIndex, getPrintValue, isNegOne, isOne, isZero, multiply, multiply, negate, subtract, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final SparseEltZ ZERO
A constant with value 0 and unspecified index. Use this instead of SparseElt.ZERO if you are working over Z.


ONE

public static final SparseEltZ ONE
A constant with value 1 and unspecified index. Use this instead of SparseElt.ONE if you are working over Z.


NEG_ONE

public static final SparseEltZ NEG_ONE
A constant with value -1 and unspecified index. Use this instead of SparseElt.NEG_ONE if you are working over Z.

Constructor Detail

SparseEltZ

public SparseEltZ()
Method Detail

abs

public abstract SparseEltZ abs()
Returns a SparseEltZ whose value is the absolute value of the value of this, and whose index is that of this.


compareTo

public abstract int compareTo(Object o)
Compares SparseEltZs by < on the values. Use SparseElt.INDEX_SORTER to compare on the indices.

Specified by:
compareTo in interface Comparable

copyMod

public abstract SparseEltField copyMod(int p,
                                       BigInteger pBig)
Returns this mod p, preserving the index. Returns null if the value mod p is 0.

Parameters:
p - A prime. The user should check it with SparseEltModp.checkP(int).
pBig - p as a BigInteger.

divideAndRemainder

public abstract SparseEltZ[] divideAndRemainder(SparseEltZ y)
Computes this/y and returns a two-element array with values quotient and remainder. Each index is the index of this.

Throws:
ArithmeticException - If y is zero.

getEucNormComparator

public Comparator getEucNormComparator()
Description copied from class: SparseEltEuc
Returns a Comparator C that compares by Euclidean norm. C.compare(a,b) should give the same results as a.eucNorm().compareTo(b.eucNorm()), where compareTo is the usual <, but C.compare might be more efficient.

Specified by:
getEucNormComparator in class SparseEltEuc

getNegOne

public SparseElt getNegOne()
Description copied from class: SparseElt
Returns a SparseElt from the same integral domain as this, with value -1 and unspecified index.

Specified by:
getNegOne in class SparseElt

getOne

public SparseElt getOne()
Description copied from class: SparseElt
Returns a SparseElt from the same integral domain as this, with value 1 and unspecified index.

Specified by:
getOne in class SparseElt

getValueAsDouble

public abstract double getValueAsDouble()
Returns the value as a double.


getValueAsInt

public abstract int getValueAsInt()
Coerces the value into an int and returns it. In other words, returns the value modulo 232.


getValueAsBigInteger

public abstract BigInteger getValueAsBigInteger()
Returns the value as a BigInteger. In principle, this is the only accurate way to get the value, but it may consume memory unnecessarily if this is not a SparseEltZBig. Compare getValueAsInt().


getZero

public SparseElt getZero()
Description copied from class: SparseElt
Returns a SparseElt from the same integral domain as this, with value 0 and unspecified index.

Specified by:
getZero in class SparseElt

hashCode

public final int hashCode()
Is consistent with SparseElt.equals(java.lang.Object).

Specified by:
hashCode in class SparseElt

isEqualValue

public boolean isEqualValue(SparseElt y)
Description copied from class: SparseElt
Tests whether the values are equal, ignoring the indices.

Specified by:
isEqualValue in class SparseElt

makeInstance

public static SparseEltZ makeInstance(int index,
                                      BigInteger value)
Makes a new instance of SparseEltZ, using the specified arguments. Returns SparseEltZInt instead of SparseEltZBig whenever value is small enough.


makeInstance

public static SparseEltZ makeInstance(int index,
                                      int value)
Makes a new instance of SparseEltZ, using the specified arguments.


signum

public abstract int signum()
Returns -1, 0, or 1 as the value is negative, zero, or positive.