edu.jas.arith
Class BigInteger

java.lang.Object
  extended by edu.jas.arith.BigInteger
All Implemented Interfaces:
AbelianGroupElem<BigInteger>, AbelianGroupFactory<BigInteger>, Element<BigInteger>, ElemFactory<BigInteger>, GcdRingElem<BigInteger>, MonoidElem<BigInteger>, MonoidFactory<BigInteger>, RingElem<BigInteger>, RingFactory<BigInteger>, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<BigInteger>, java.lang.Iterable<BigInteger>

public final class BigInteger
extends java.lang.Object
implements GcdRingElem<BigInteger>, RingFactory<BigInteger>, java.lang.Iterable<BigInteger>

BigInteger class to make java.math.BigInteger available with RingElem interface and with the familiar SAC static method names. Objects of this class are immutable.

Author:
Heinz Kredel
See Also:
BigInteger, Serialized Form

Field Summary
static BigInteger ONE
          The constant 1.
protected  java.math.BigInteger val
          The data structure.
static BigInteger ZERO
          The constant 0.
 
Constructor Summary
BigInteger()
          Constructor for BigInteger without parameters.
BigInteger(java.math.BigInteger a)
          Constructor for BigInteger from math.BigInteger.
BigInteger(long a)
          Constructor for BigInteger from long.
BigInteger(java.lang.String s)
          Constructor for BigInteger from String.
 
Method Summary
 BigInteger abs()
          Absolute value of this.
 java.math.BigInteger characteristic()
          Characteristic of this ring.
 BigInteger clone()
          Clone this.
 int compareTo(BigInteger b)
          Compare to BigInteger b.
 BigInteger copy(BigInteger c)
          Copy BigInteger element c.
 BigInteger divide(BigInteger S)
          BigInteger divide.
 BigInteger[] divideAndRemainder(BigInteger S)
          Deprecated. use quotientRemainder()
 BigInteger[] egcd(BigInteger S)
          BigInteger extended greatest common divisor.
 boolean equals(java.lang.Object b)
          Comparison with any other object.
 BigInteger factory()
          Get the corresponding element factory.
 BigInteger fromInteger(java.math.BigInteger a)
          Get a BigInteger element from a math.BigInteger.
 BigInteger fromInteger(long a)
          Get a BigInteger element from long.
 BigInteger gcd(BigInteger S)
          BigInteger greatest common divisor.
 java.util.List<BigInteger> generators()
          Get a list of the generating elements.
 BigInteger getONE()
          Get the one element.
 java.math.BigInteger getVal()
          Get the value.
 BigInteger getZERO()
          Get the zero element.
 int hashCode()
          Hash code for this BigInteger.
static BigInteger IABS(BigInteger A)
          Absolute value.
static int ICOMP(BigInteger A, BigInteger B)
          Integer comparison.
static BigInteger IDIF(BigInteger A, BigInteger B)
          BigInteger subtract.
static BigInteger IGCD(BigInteger A, BigInteger B)
          BigInteger greatest common divisor.
static BigInteger INEG(BigInteger A)
          Negative value.
 BigInteger inverse()
          Integer inverse.
static BigInteger IPROD(BigInteger A, BigInteger B)
          BigInteger multiply.
static BigInteger IQ(BigInteger A, BigInteger B)
          BigInteger divide.
static BigInteger[] IQR(BigInteger A, BigInteger B)
          Integer quotient and remainder.
static BigInteger IRAND(int NL)
          BigInteger random.
static BigInteger IREM(BigInteger A, BigInteger B)
          BigInteger remainder.
 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.
 boolean isFinite()
          Is this structure finite or infinite.
static int ISIGN(BigInteger A)
          Integer signum.
 boolean isONE()
          Is BigInteger number one.
static BigInteger ISUM(BigInteger A, BigInteger B)
          BigInteger addition.
 boolean isUnit()
          Is BigInteger number unit.
 boolean isZERO()
          Is BigInteger number zero.
 java.util.Iterator<BigInteger> iterator()
          Get a BigInteger iterator.
 long longValue()
          Get the value as long.
 BigInteger multiply(BigInteger S)
          BigInteger multiply.
 BigInteger negate()
          Negate this.
 BigInteger parse(java.io.Reader r)
          BigInteger parse from Reader.
 BigInteger parse(java.lang.String s)
          BigInteger parse from String.
 BigInteger[] quotientRemainder(BigInteger S)
          BigInteger compute quotient and remainder.
 BigInteger random(int n)
          BigInteger random.
 BigInteger random(int n, java.util.Random rnd)
          BigInteger random.
 BigInteger remainder(BigInteger S)
          BigInteger remainder.
 void setAllIterator()
          Set the iteration algorithm to all elements.
 void setNonNegativeIterator()
          Set the iteration algorithm to non-negative elements.
 int signum()
          signum.
 BigInteger subtract(BigInteger S)
          BigInteger subtract.
 BigInteger sum(BigInteger S)
          BigInteger summation.
 java.lang.String toScript()
          Get a scripting compatible string representation.
 java.lang.String toScriptFactory()
          Get a scripting compatible string representation of the factory.
 java.lang.String toString()
          Get the String representation.
static BigInteger valueOf(java.math.BigInteger a)
          Get a BigInteger element from a math.BigInteger.
static BigInteger valueOf(long a)
          Get a BigInteger element from long.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

val

protected final java.math.BigInteger val
The data structure.


ZERO

public static final BigInteger ZERO
The constant 0.


ONE

public static final BigInteger ONE
The constant 1.

Constructor Detail

BigInteger

public BigInteger(java.math.BigInteger a)
Constructor for BigInteger from math.BigInteger.

Parameters:
a - java.math.BigInteger.

BigInteger

public BigInteger(long a)
Constructor for BigInteger from long.

Parameters:
a - long.

BigInteger

public BigInteger(java.lang.String s)
Constructor for BigInteger from String.

Parameters:
s - String.

BigInteger

public BigInteger()
Constructor for BigInteger without parameters.

Method Detail

getVal

public java.math.BigInteger getVal()
Get the value.

Returns:
val java.math.BigInteger.

longValue

public long longValue()
Get the value as long.

Returns:
val as long.

factory

public BigInteger factory()
Get the corresponding element factory.

Specified by:
factory in interface Element<BigInteger>
Returns:
factory for this Element.
See Also:
Element.factory()

generators

public java.util.List<BigInteger> generators()
Get a list of the generating elements.

Specified by:
generators in interface ElemFactory<BigInteger>
Returns:
list of generators for the algebraic structure.
See Also:
ElemFactory.generators()

isFinite

public boolean isFinite()
Is this structure finite or infinite.

Specified by:
isFinite in interface ElemFactory<BigInteger>
Returns:
true if this structure is finite, else false.
See Also:
ElemFactory.isFinite()

clone

public BigInteger clone()
Clone this.

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

copy

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

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

getZERO

public BigInteger getZERO()
Get the zero element.

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

getONE

public BigInteger getONE()
Get the one element.

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

isCommutative

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

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

isAssociative

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

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

isField

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

Specified by:
isField in interface RingFactory<BigInteger>
Returns:
false.

characteristic

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

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

fromInteger

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

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

valueOf

public static BigInteger valueOf(java.math.BigInteger a)
Get a BigInteger element from a math.BigInteger.

Parameters:
a - math.BigInteger.
Returns:
a as BigInteger.

fromInteger

public BigInteger fromInteger(long a)
Get a BigInteger element from long.

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

valueOf

public static BigInteger valueOf(long a)
Get a BigInteger element from long.

Parameters:
a - long.
Returns:
a as BigInteger.

isZERO

public boolean isZERO()
Is BigInteger number zero.

Specified by:
isZERO in interface AbelianGroupElem<BigInteger>
Returns:
If this is 0 then true is returned, else false.
See Also:
AbelianGroupElem.isZERO()

isONE

public boolean isONE()
Is BigInteger number one.

Specified by:
isONE in interface MonoidElem<BigInteger>
Returns:
true if this is 1, else false.
See Also:
MonoidElem.isONE()

isUnit

public boolean isUnit()
Is BigInteger number unit.

Specified by:
isUnit in interface MonoidElem<BigInteger>
Returns:
true if this is a unit, else false.
See Also:
MonoidElem.isUnit()

toString

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

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

toScript

public java.lang.String toScript()
Get a scripting compatible string representation.

Specified by:
toScript in interface Element<BigInteger>
Specified by:
toScript in interface ElemFactory<BigInteger>
Returns:
script compatible representation for this Element.
See Also:
Element.toScript()

toScriptFactory

public java.lang.String toScriptFactory()
Get a scripting compatible string representation of the factory.

Specified by:
toScriptFactory in interface Element<BigInteger>
Returns:
script compatible representation for this ElemFactory.
See Also:
Element.toScriptFactory()

compareTo

public int compareTo(BigInteger b)
Compare to BigInteger b.

Specified by:
compareTo in interface Element<BigInteger>
Specified by:
compareTo in interface java.lang.Comparable<BigInteger>
Parameters:
b - BigInteger.
Returns:
0 if this == b, 1 if this > b, -1 if this < b.

ICOMP

public static int ICOMP(BigInteger A,
                        BigInteger B)
Integer comparison.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
0 if A == B, 1 if A > B, -1 if A < B.

equals

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

Specified by:
equals in interface Element<BigInteger>
Overrides:
equals in class java.lang.Object
Returns:
true if this is equal to b, else false.
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Hash code for this BigInteger.

Specified by:
hashCode in interface Element<BigInteger>
Overrides:
hashCode in class java.lang.Object
Returns:
the hashCode.
See Also:
Object.hashCode()

abs

public BigInteger abs()
Absolute value of this.

Specified by:
abs in interface AbelianGroupElem<BigInteger>
Returns:
|this|.
See Also:
AbelianGroupElem.abs()

IABS

public static BigInteger IABS(BigInteger A)
Absolute value.

Parameters:
A - BigInteger.
Returns:
abs(A).

negate

public BigInteger negate()
Description copied from interface: AbelianGroupElem
Negate this.

Specified by:
negate in interface AbelianGroupElem<BigInteger>
Returns:
- this.

INEG

public static BigInteger INEG(BigInteger A)
Negative value.

Parameters:
A - BigInteger.
Returns:
-A.

signum

public int signum()
signum.

Specified by:
signum in interface AbelianGroupElem<BigInteger>
Returns:
the sign of this.
See Also:
AbelianGroupElem.signum()

ISIGN

public static int ISIGN(BigInteger A)
Integer signum.

Parameters:
A - BigInteger.
Returns:
signum(A).

subtract

public BigInteger subtract(BigInteger S)
BigInteger subtract.

Specified by:
subtract in interface AbelianGroupElem<BigInteger>
Parameters:
S - BigInteger.
Returns:
this-S.

IDIF

public static BigInteger IDIF(BigInteger A,
                              BigInteger B)
BigInteger subtract.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
A-B.

divide

public BigInteger divide(BigInteger S)
BigInteger divide.

Specified by:
divide in interface MonoidElem<BigInteger>
Parameters:
S - BigInteger.
Returns:
this/S.

IQ

public static BigInteger IQ(BigInteger A,
                            BigInteger B)
BigInteger divide.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
A/B.

inverse

public BigInteger inverse()
Integer inverse. R is a non-zero integer. S=1/R if defined else 0.

Specified by:
inverse in interface MonoidElem<BigInteger>
Returns:
x with this * x = 1, if it exists.
See Also:
MonoidElem.inverse()

remainder

public BigInteger remainder(BigInteger S)
BigInteger remainder.

Specified by:
remainder in interface MonoidElem<BigInteger>
Parameters:
S - BigInteger.
Returns:
this - (this/S)*S.

IREM

public static BigInteger IREM(BigInteger A,
                              BigInteger B)
BigInteger remainder.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
A - (A/B)*B.

quotientRemainder

public BigInteger[] quotientRemainder(BigInteger S)
BigInteger compute quotient and remainder. Throws an exception, if S == 0.

Parameters:
S - BigInteger.
Returns:
BigInteger[] { q, r } with this = q S + r and 0 ≤ r < |S|.

divideAndRemainder

@Deprecated
public BigInteger[] divideAndRemainder(BigInteger S)
Deprecated. use quotientRemainder()

BigInteger compute quotient and remainder. Throws an exception, if S == 0.

Parameters:
S - BigInteger.
Returns:
BigInteger[] { q, r } with this = q S + r and 0 ≤ r < |S|.

IQR

public static BigInteger[] IQR(BigInteger A,
                               BigInteger B)
Integer quotient and remainder. A and B are integers, B ne 0. Q is the quotient, integral part of A/B, and R is the remainder A-B*Q. Throws an exception, if B == 0.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
BigInteger[] { q, r } with A = q B + r and 0 ≤ r < |B|

gcd

public BigInteger gcd(BigInteger S)
BigInteger greatest common divisor.

Specified by:
gcd in interface RingElem<BigInteger>
Parameters:
S - BigInteger.
Returns:
gcd(this,S).

egcd

public BigInteger[] egcd(BigInteger S)
BigInteger extended greatest common divisor.

Specified by:
egcd in interface RingElem<BigInteger>
Parameters:
S - BigInteger.
Returns:
[ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).

IGCD

public static BigInteger IGCD(BigInteger A,
                              BigInteger B)
BigInteger greatest common divisor.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
gcd(A,B).

random

public BigInteger random(int n)
BigInteger random.

Specified by:
random in interface ElemFactory<BigInteger>
Parameters:
n - such that 0 ≤ r ≤ (2n-1).
Returns:
r, a random BigInteger.

random

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

Specified by:
random in interface ElemFactory<BigInteger>
Parameters:
n - such that 0 ≤ r ≤ (2n-1).
rnd - is a source for random bits.
Returns:
r, a random BigInteger.

IRAND

public static BigInteger IRAND(int NL)
BigInteger random.

Parameters:
NL - such that 0 ≤ r ≤ (2n-1).
Returns:
r, a random BigInteger.

multiply

public BigInteger multiply(BigInteger S)
BigInteger multiply.

Specified by:
multiply in interface MonoidElem<BigInteger>
Parameters:
S - BigInteger.
Returns:
this*S.

IPROD

public static BigInteger IPROD(BigInteger A,
                               BigInteger B)
BigInteger multiply.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
A*B.

sum

public BigInteger sum(BigInteger S)
BigInteger summation.

Specified by:
sum in interface AbelianGroupElem<BigInteger>
Parameters:
S - BigInteger.
Returns:
this+S.

ISUM

public static BigInteger ISUM(BigInteger A,
                              BigInteger B)
BigInteger addition.

Parameters:
A - BigInteger.
B - BigInteger.
Returns:
A+B.

parse

public BigInteger parse(java.lang.String s)
BigInteger parse from String.

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

parse

public BigInteger parse(java.io.Reader r)
BigInteger parse from Reader.

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

setAllIterator

public void setAllIterator()
Set the iteration algorithm to all elements.


setNonNegativeIterator

public void setNonNegativeIterator()
Set the iteration algorithm to non-negative elements.


iterator

public java.util.Iterator<BigInteger> iterator()
Get a BigInteger iterator.

Specified by:
iterator in interface java.lang.Iterable<BigInteger>
Returns:
a iterator over all integers.