shh.csparse
Class SparseEltModp

Object
  extended bySparseElt
      extended bySparseEltEuc
          extended bySparseEltField
              extended bySparseEltModp

public class SparseEltModp
extends SparseEltField

Elements of a sparse vector over the finite field Fp = Z/(p) of p elements.

It is an error if the following don't hold:

Author:
Mark McConnell

Field Summary
protected  int p
           
protected  int val
          The value.
 
Fields inherited from class SparseElt
INDEX_SORTER, NEG_ONE, ONE, ZERO
 
Constructor Summary
SparseEltModp(int index, int val, int p)
          Constructs an element whose value is val mod p.
 
Method Summary
 SparseElt add(SparseElt y)
          Returns a SparseElt whose value is the sum of the values in this and y, and whose index is that of this.
 int bitLength()
          If the value is a BigInteger, returns its BigInteger.bitLength(); if the value is stored in a primitive type, returns the bit length of the type.
static void checkP(int p)
          Utility to check whether p is a positive prime small enough so that (p-1)2 fits in a positive int.
 SparseElt copy(int indexOfCopy)
          Returns a SparseElt with the same value as this, and with index indexOfCopy.
 SparseEltField dividedBy(SparseEltField y)
          Returns this/y.
 boolean divides(SparseElt y)
          Whether the value of this divides the value of y; that is, whether there is an x such that x * this = y.
 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.
 String getPrintValue()
          Returns the value in human-readable form.
 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.
 boolean isNegOne()
          Whether the value is -1.
 boolean isOne()
          Whether the value is one.
 boolean isZero()
          Whether the value is zero.
 SparseElt multiply(int newIndex, SparseElt y)
          Returns a SparseElt with index newIndex and whose value is the product of the values in this and y.
 SparseElt multiply(SparseElt y)
          Returns a SparseElt whose value is the product of the values in this and y, and whose index is that of this.
 SparseElt negate()
          Returns a SparseElt whose value is the negative of the value of this, and whose index is that of this.
 SparseEltEuc negClosestQuotient(SparseEltEuc y)
          Negative of the closest quotient: returns q such that q * y + this is as small as possible for SparseEltField.eucNorm().
 SparseElt subtract(SparseElt y)
          Returns a SparseElt whose value is (value of this) minus (value of y), and whose index is that of this.
 
Methods inherited from class SparseEltField
eucNorm, getEucNormComparator
 
Methods inherited from class SparseElt
equals, getIndex, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

val

protected int val
The value. It is always the least positive residue in its congruence class mod p.


p

protected int p
Constructor Detail

SparseEltModp

public SparseEltModp(int index,
                     int val,
                     int p)
Constructs an element whose value is val mod p.

Method Detail

checkP

public static void checkP(int p)
                   throws RuntimeException
Utility to check whether p is a positive prime small enough so that (p-1)2 fits in a positive int. This means 2 ≤ p ≤ 46337.

Throws:
RuntimeException - If the test fails. The method does nothing if the test succeeds.

add

public SparseElt add(SparseElt y)
Description copied from class: SparseElt
Returns a SparseElt whose value is the sum of the values in this and y, and whose index is that of this.

Specified by:
add in class SparseElt

bitLength

public int bitLength()
Description copied from class: SparseElt
If the value is a BigInteger, returns its BigInteger.bitLength(); if the value is stored in a primitive type, returns the bit length of the type.

Specified by:
bitLength in class SparseElt

copy

public SparseElt copy(int indexOfCopy)
Description copied from class: SparseElt
Returns a SparseElt with the same value as this, and with index indexOfCopy.

Specified by:
copy in class SparseElt

dividedBy

public SparseEltField dividedBy(SparseEltField y)
Description copied from class: SparseEltField
Returns this/y. The index is that of this.

Specified by:
dividedBy in class SparseEltField

divides

public boolean divides(SparseElt y)
Description copied from class: SparseElt
Whether the value of this divides the value of y; that is, whether there is an x such that x * this = y.

Specified by:
divides in class SparseElt

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

getPrintValue

public String getPrintValue()
Description copied from class: SparseElt
Returns the value in human-readable form.

Specified by:
getPrintValue in class SparseElt

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 final boolean isEqualValue(SparseElt y)
Description copied from class: SparseElt
Tests whether the values are equal, ignoring the indices.

Specified by:
isEqualValue in class SparseElt

isNegOne

public boolean isNegOne()
Description copied from class: SparseElt
Whether the value is -1.

Specified by:
isNegOne in class SparseElt

isOne

public boolean isOne()
Description copied from class: SparseElt
Whether the value is one.

Specified by:
isOne in class SparseElt

isZero

public boolean isZero()
Description copied from class: SparseElt
Whether the value is zero.

Specified by:
isZero in class SparseElt

multiply

public SparseElt multiply(SparseElt y)
Description copied from class: SparseElt
Returns a SparseElt whose value is the product of the values in this and y, and whose index is that of this.

Overrides:
multiply in class SparseElt

multiply

public SparseElt multiply(int newIndex,
                          SparseElt y)
Description copied from class: SparseElt
Returns a SparseElt with index newIndex and whose value is the product of the values in this and y.

Specified by:
multiply in class SparseElt

negate

public SparseElt negate()
Description copied from class: SparseElt
Returns a SparseElt whose value is the negative of the value of this, and whose index is that of this.

Specified by:
negate in class SparseElt

negClosestQuotient

public SparseEltEuc negClosestQuotient(SparseEltEuc y)
Description copied from class: SparseEltEuc
Negative of the closest quotient: returns q such that q * y + this is as small as possible for SparseEltEuc.eucNorm(). In other words, returns -this/y rounded off to the nearest element of D. The index is that of this.

Specified by:
negClosestQuotient in class SparseEltEuc

subtract

public SparseElt subtract(SparseElt y)
Description copied from class: SparseElt
Returns a SparseElt whose value is (value of this) minus (value of y), and whose index is that of this.

Specified by:
subtract in class SparseElt