edu.jas.arith
Class ModIntegerRing

java.lang.Object
  extended by edu.jas.arith.ModIntegerRing
All Implemented Interfaces:
AbelianGroupFactory<ModInteger>, ElemFactory<ModInteger>, MonoidFactory<ModInteger>, RingFactory<ModInteger>, java.io.Serializable

public final class ModIntegerRing
extends java.lang.Object
implements RingFactory<ModInteger>

ModIntegerRing factory with RingFactory interface. Effectively immutable.

Author:
Heinz Kredel
See Also:
Serialized Form

Field Summary
protected  int certainty
          Certainty if module is probable prime.
protected  int isField
          Indicator if this ring is a field.
 java.math.BigInteger modul
          Module part of the factory data structure.
 
Constructor Summary
ModIntegerRing(java.math.BigInteger m)
          The constructor creates a ModIntegerRing object from a BigInteger object as module part.
ModIntegerRing(java.math.BigInteger m, boolean isField)
          The constructor creates a ModIntegerRing object from a BigInteger object as module part.
ModIntegerRing(long m)
          The constructor creates a ModIntegerRing object from a long as module part.
ModIntegerRing(long m, boolean isField)
          The constructor creates a ModIntegerRing object from a long as module part.
ModIntegerRing(java.lang.String m)
          The constructor creates a ModIntegerRing object from a String object as module part.
ModIntegerRing(java.lang.String m, boolean isField)
          The constructor creates a ModIntegerRing object from a String object as module part.
 
Method Summary
 java.math.BigInteger characteristic()
          Characteristic of this ring.
 ModInteger chineseRemainder(ModInteger c, ModInteger ci, ModInteger a)
          ModInteger chinese remainder algorithm.
 ModInteger copy(ModInteger c)
          Copy ModInteger element c.
 boolean equals(java.lang.Object b)
          Comparison with any other object.
 ModInteger fromInteger(java.math.BigInteger a)
          Get a ModInteger element from a BigInteger value.
 ModInteger fromInteger(long a)
          Get a ModInteger element from a long value.
 java.math.BigInteger getModul()
          Get the module part.
 ModInteger getONE()
          Get the one element.
 ModInteger getZERO()
          Get the zero element.
 int hashCode()
          Hash code for this ModIntegerRing.
 boolean isAssociative()
          Query if this ring is associative.
 boolean isCommutative()
          Query if this ring is commutative.
 boolean isField()
          Query if this ring is a field.
 ModInteger parse(java.io.Reader r)
          Parse ModInteger from Reader.
 ModInteger parse(java.lang.String s)
          Parse ModInteger from String.
 ModInteger random(int n)
          ModInteger random.
 ModInteger random(int n, java.util.Random rnd)
          ModInteger random.
 java.lang.String toString()
          Get the String representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

modul

public final java.math.BigInteger modul
Module part of the factory data structure.


isField

protected int isField
Indicator if this ring is a field.


certainty

protected int certainty
Certainty if module is probable prime.

Constructor Detail

ModIntegerRing

public ModIntegerRing(java.math.BigInteger m)
The constructor creates a ModIntegerRing object from a BigInteger object as module part.

Parameters:
m - math.BigInteger.

ModIntegerRing

public ModIntegerRing(java.math.BigInteger m,
                      boolean isField)
The constructor creates a ModIntegerRing object from a BigInteger object as module part.

Parameters:
m - math.BigInteger.
isField - indicator if m is prime.

ModIntegerRing

public ModIntegerRing(long m)
The constructor creates a ModIntegerRing object from a long as module part.

Parameters:
m - long.

ModIntegerRing

public ModIntegerRing(long m,
                      boolean isField)
The constructor creates a ModIntegerRing object from a long as module part.

Parameters:
m - long.
isField - indicator if m is prime.

ModIntegerRing

public ModIntegerRing(java.lang.String m)
The constructor creates a ModIntegerRing object from a String object as module part.

Parameters:
m - String.

ModIntegerRing

public ModIntegerRing(java.lang.String m,
                      boolean isField)
The constructor creates a ModIntegerRing object from a String object as module part.

Parameters:
m - String.
isField - indicator if m is prime.
Method Detail

getModul

public java.math.BigInteger getModul()
Get the module part.

Returns:
modul.

copy

public ModInteger copy(ModInteger c)
Copy ModInteger element c.

Specified by:
copy in interface ElemFactory<ModInteger>
Parameters:
c -
Returns:
a copy of c.

getZERO

public ModInteger getZERO()
Get the zero element.

Specified by:
getZERO in interface AbelianGroupFactory<ModInteger>
Returns:
0 as ModInteger.

getONE

public ModInteger getONE()
Get the one element.

Specified by:
getONE in interface MonoidFactory<ModInteger>
Returns:
1 as ModInteger.

isCommutative

public boolean isCommutative()
Query if this ring is commutative.

Specified by:
isCommutative in interface MonoidFactory<ModInteger>
Returns:
true.

isAssociative

public boolean isAssociative()
Query if this ring is associative.

Specified by:
isAssociative in interface MonoidFactory<ModInteger>
Returns:
true.

isField

public boolean isField()
Query if this ring is a field.

Specified by:
isField in interface RingFactory<ModInteger>
Returns:
true if module is prime, else false.

characteristic

public java.math.BigInteger characteristic()
Characteristic of this ring.

Specified by:
characteristic in interface RingFactory<ModInteger>
Returns:
characteristic of this ring.

fromInteger

public ModInteger fromInteger(java.math.BigInteger a)
Get a ModInteger element from a BigInteger value.

Specified by:
fromInteger in interface ElemFactory<ModInteger>
Parameters:
a - BigInteger.
Returns:
a ModInteger.

fromInteger

public ModInteger fromInteger(long a)
Get a ModInteger element from a long value.

Specified by:
fromInteger in interface ElemFactory<ModInteger>
Parameters:
a - long.
Returns:
a ModInteger.

toString

public java.lang.String toString()
Get the String representation.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

equals

public boolean equals(java.lang.Object b)
Comparison with any other object.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Hash code for this ModIntegerRing.

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

random

public ModInteger random(int n)
ModInteger random.

Specified by:
random in interface ElemFactory<ModInteger>
Parameters:
n - such that 0 ≤ v ≤ (2n-1).
Returns:
a random integer mod modul.

random

public ModInteger random(int n,
                         java.util.Random rnd)
ModInteger random.

Specified by:
random in interface ElemFactory<ModInteger>
Parameters:
n - such that 0 ≤ v ≤ (2n-1).
rnd - is a source for random bits.
Returns:
a random integer mod modul.

parse

public ModInteger parse(java.lang.String s)
Parse ModInteger from String.

Specified by:
parse in interface ElemFactory<ModInteger>
Parameters:
s - String.
Returns:
ModInteger from s.

parse

public ModInteger parse(java.io.Reader r)
Parse ModInteger from Reader.

Specified by:
parse in interface ElemFactory<ModInteger>
Parameters:
r - Reader.
Returns:
next ModInteger from r.

chineseRemainder

public ModInteger chineseRemainder(ModInteger c,
                                   ModInteger ci,
                                   ModInteger a)
ModInteger chinese remainder algorithm. This is a factory method. Assert c.modul >= a.modul and c.modul * a.modul = this.modul.

Parameters:
c - ModInteger.
ci - inverse of c.modul in ring of a.
a - other ModInteger.
Returns:
S, with S mod c.modul == c and S mod a.modul == a.