Package edu.jas.arith
Class BigInteger
java.lang.Object
edu.jas.arith.BigInteger
- All Implemented Interfaces:
Rational
,AbelianGroupElem<BigInteger>
,AbelianGroupFactory<BigInteger>
,Element<BigInteger>
,ElemFactory<BigInteger>
,GcdRingElem<BigInteger>
,MonoidElem<BigInteger>
,MonoidFactory<BigInteger>
,RingElem<BigInteger>
,RingFactory<BigInteger>
,Serializable
,Comparable<BigInteger>
,Iterable<BigInteger>
public final class BigInteger
extends Object
implements GcdRingElem<BigInteger>, RingFactory<BigInteger>, Iterable<BigInteger>, Rational
BigInteger class to make java.math.BigInteger available with RingElem
respectively the GcdRingElem interface. Objects of this class are immutable.
The SAC2 static methods are also provided.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
static final BigInteger
The constant 1.private static final Random
static final BigInteger
The constant 2.final BigInteger
The data structure.static final BigInteger
The constant 0. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for BigInteger without parameters.BigInteger
(long a) Constructor for BigInteger from long.BigInteger
(String s) Constructor for BigInteger from String.Constructor for BigInteger from math.BigInteger. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Absolute value of this.long
Returns the number of bits in the representation of this BigInteger, including a sign bit.static long
bitLength
(long v) Returns the number of bits in the representation of a Long, including a sign bit.Characteristic of this ring.int
Compare to BigInteger b.copy()
Clone this.copy
(BigInteger c) Copy BigInteger element c.divide
(BigInteger S) BigInteger divide.egcd
(BigInteger S) BigInteger extended greatest common divisor.boolean
Comparison with any other object.factory()
Get the corresponding element factory.fromInteger
(long a) Get a BigInteger element from long.Get a BigInteger element from a math.BigInteger.gcd
(BigInteger S) BigInteger greatest common divisor.Get a list of the generating elements.Get the decimal representation.getONE()
Get the one element.Return a BigRational approximation of this Element.getVal()
Get the value.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.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
Query if this ring is associative.boolean
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.iterator()
Get a BigInteger iterator.long
Get the value as long.long
Get the value as long.BigInteger multiply.negate()
Negate this.BigInteger parse from Reader.BigInteger parse from String.BigInteger compute quotient and remainder.random
(int n) BigInteger random.BigInteger random.BigInteger remainder.void
Set the iteration algorithm to all elements.void
Set the iteration algorithm to non-negative elements.shiftLeft
(int n) BigInteger shift left.int
signum()
signum.BigInteger subtract.sum
(BigInteger S) BigInteger summation.toScript()
Get a scripting compatible string representation.Get a scripting compatible string representation of the factory.toString()
Get the String representation.static BigInteger
valueOf
(long a) Get a BigInteger element from long.static BigInteger
Get a BigInteger element from a math.BigInteger.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface edu.jas.structure.ElemFactory
valueOf
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface edu.jas.structure.MonoidElem
leftDivide, leftRemainder, power, rightDivide, rightRemainder, twosidedDivide, twosidedRemainder
-
Field Details
-
val
The data structure. -
random
-
ZERO
The constant 0. -
ONE
The constant 1. -
TWO
The constant 2. -
nonNegative
private boolean nonNegative
-
-
Constructor Details
-
BigInteger
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
Constructor for BigInteger from String.- Parameters:
s
- String.
-
BigInteger
public BigInteger()Constructor for BigInteger without parameters.
-
-
Method Details
-
getVal
Get the value.- Returns:
- val java.math.BigInteger.
-
longValue
public long longValue()Get the value as long.- Returns:
- val as long.
-
longValueExact
public long longValueExact()Get the value as long.- Returns:
- val as long if val fits in long.
-
factory
Get the corresponding element factory.- Specified by:
factory
in interfaceElement<BigInteger>
- Returns:
- factory for this Element.
- See Also:
-
generators
Get a list of the generating elements.- Specified by:
generators
in interfaceElemFactory<BigInteger>
- Returns:
- list of generators for the algebraic structure.
- See Also:
-
isFinite
public boolean isFinite()Is this structure finite or infinite.- Specified by:
isFinite
in interfaceElemFactory<BigInteger>
- Returns:
- true if this structure is finite, else false.
- See Also:
-
copy
Clone this.- Specified by:
copy
in interfaceElement<BigInteger>
- Returns:
- Creates and returns a copy of this Element.
- See Also:
-
copy
Copy BigInteger element c.- Specified by:
copy
in interfaceElemFactory<BigInteger>
- Parameters:
c
- BigInteger.- Returns:
- a copy of c.
-
getZERO
Get the zero element.- Specified by:
getZERO
in interfaceAbelianGroupFactory<BigInteger>
- Returns:
- 0.
-
getONE
Get the one element.- Specified by:
getONE
in interfaceMonoidFactory<BigInteger>
- Returns:
- 1.
-
isCommutative
public boolean isCommutative()Query if this ring is commutative.- Specified by:
isCommutative
in interfaceMonoidFactory<BigInteger>
- Returns:
- true.
-
isAssociative
public boolean isAssociative()Query if this ring is associative.- Specified by:
isAssociative
in interfaceMonoidFactory<BigInteger>
- Returns:
- true.
-
isField
public boolean isField()Query if this ring is a field.- Specified by:
isField
in interfaceRingFactory<BigInteger>
- Returns:
- false.
-
characteristic
Characteristic of this ring.- Specified by:
characteristic
in interfaceRingFactory<BigInteger>
- Returns:
- characteristic of this ring.
-
fromInteger
Get a BigInteger element from a math.BigInteger.- Specified by:
fromInteger
in interfaceElemFactory<BigInteger>
- Parameters:
a
- math.BigInteger.- Returns:
- a as BigInteger.
-
valueOf
Get a BigInteger element from a math.BigInteger.- Parameters:
a
- math.BigInteger.- Returns:
- a as BigInteger.
-
fromInteger
Get a BigInteger element from long.- Specified by:
fromInteger
in interfaceElemFactory<BigInteger>
- Parameters:
a
- long.- Returns:
- a as BigInteger.
-
valueOf
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 interfaceAbelianGroupElem<BigInteger>
- Returns:
- If this is 0 then true is returned, else false.
- See Also:
-
isONE
public boolean isONE()Is BigInteger number one.- Specified by:
isONE
in interfaceMonoidElem<BigInteger>
- Returns:
- true if this is 1, else false.
- See Also:
-
isUnit
public boolean isUnit()Is BigInteger number unit.- Specified by:
isUnit
in interfaceMonoidElem<BigInteger>
- Returns:
- true if this is a unit, else false.
- See Also:
-
toString
Get the String representation. -
toScript
Get a scripting compatible string representation.- Specified by:
toScript
in interfaceElement<BigInteger>
- Specified by:
toScript
in interfaceElemFactory<BigInteger>
- Returns:
- script compatible representation for this Element.
- See Also:
-
toScriptFactory
Get a scripting compatible string representation of the factory.- Specified by:
toScriptFactory
in interfaceElement<BigInteger>
- Returns:
- script compatible representation for this ElemFactory.
- See Also:
-
compareTo
Compare to BigInteger b.- Specified by:
compareTo
in interfaceComparable<BigInteger>
- Specified by:
compareTo
in interfaceElement<BigInteger>
- Parameters:
b
- BigInteger.- Returns:
- 0 if this == b, 1 if this > b, -1 if this < b.
-
ICOMP
Integer comparison.- Parameters:
A
- BigInteger.B
- BigInteger.- Returns:
- 0 if A == B, 1 if A > B, -1 if A < B.
-
equals
Comparison with any other object.- Specified by:
equals
in interfaceElement<BigInteger>
- Overrides:
equals
in classObject
- Parameters:
b
-- Returns:
- true if this is equal to b, else false.
- See Also:
-
hashCode
public int hashCode()Hash code for this BigInteger.- Specified by:
hashCode
in interfaceElement<BigInteger>
- Overrides:
hashCode
in classObject
- Returns:
- the hashCode.
- See Also:
-
abs
Absolute value of this.- Specified by:
abs
in interfaceAbelianGroupElem<BigInteger>
- Returns:
- |this|.
- See Also:
-
IABS
Absolute value.- Parameters:
A
- BigInteger.- Returns:
- abs(A).
-
negate
Description copied from interface:AbelianGroupElem
Negate this.- Specified by:
negate
in interfaceAbelianGroupElem<BigInteger>
- Returns:
- - this.
-
INEG
Negative value.- Parameters:
A
- BigInteger.- Returns:
- -A.
-
signum
public int signum()signum.- Specified by:
signum
in interfaceAbelianGroupElem<BigInteger>
- Returns:
- the sign of this.
- See Also:
-
ISIGN
Integer signum.- Parameters:
A
- BigInteger.- Returns:
- signum(A).
-
subtract
BigInteger subtract.- Specified by:
subtract
in interfaceAbelianGroupElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- this-S.
-
IDIF
BigInteger subtract.- Parameters:
A
- BigInteger.B
- BigInteger.- Returns:
- A-B.
-
divide
BigInteger divide.- Specified by:
divide
in interfaceMonoidElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- this/S.
-
IQ
BigInteger divide.- Parameters:
A
- BigInteger.B
- BigInteger.- Returns:
- A/B.
-
inverse
Integer inverse. R is a non-zero integer. S=1/R if defined else throws not invertible exception.- Specified by:
inverse
in interfaceMonoidElem<BigInteger>
- Returns:
- x with this * x = 1, if it exists.
- See Also:
-
remainder
BigInteger remainder.- Specified by:
remainder
in interfaceMonoidElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- this - (this/S)*S.
-
IREM
BigInteger remainder.- Parameters:
A
- BigInteger.B
- BigInteger.- Returns:
- A - (A/B)*B.
-
quotientRemainder
BigInteger compute quotient and remainder. Throws an exception, if S == 0.- Specified by:
quotientRemainder
in interfaceMonoidElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- BigInteger[] { q, r } with this = q S + r and 0 ≤ r < |S|.
-
IQR
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
BigInteger greatest common divisor.- Specified by:
gcd
in interfaceRingElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- gcd(this,S).
-
egcd
BigInteger extended greatest common divisor.- Specified by:
egcd
in interfaceRingElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- [ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).
-
IGCD
BigInteger greatest common divisor.- Parameters:
A
- BigInteger.B
- BigInteger.- Returns:
- gcd(A,B).
-
random
BigInteger random.- Specified by:
random
in interfaceElemFactory<BigInteger>
- Parameters:
n
- such that 0 ≤ r ≤ (2n-1).- Returns:
- r, a random BigInteger.
-
random
BigInteger random.- Specified by:
random
in interfaceElemFactory<BigInteger>
- Parameters:
n
- such that 0 ≤ r ≤ (2n-1).rnd
- is a source for random bits.- Returns:
- r, a random BigInteger.
-
IRAND
BigInteger random.- Parameters:
NL
- such that 0 ≤ r ≤ (2n-1).- Returns:
- r, a random BigInteger.
-
multiply
BigInteger multiply.- Specified by:
multiply
in interfaceMonoidElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- this*S.
-
shiftLeft
BigInteger shift left.- Parameters:
n
- bits to shift.- Returns:
- this << n.
-
IPROD
BigInteger multiply.- Parameters:
A
- BigInteger.B
- BigInteger.- Returns:
- A*B.
-
sum
BigInteger summation.- Specified by:
sum
in interfaceAbelianGroupElem<BigInteger>
- Parameters:
S
- BigInteger.- Returns:
- this+S.
-
ISUM
BigInteger addition.- Parameters:
A
- BigInteger.B
- BigInteger.- Returns:
- A+B.
-
parse
BigInteger parse from String.- Specified by:
parse
in interfaceElemFactory<BigInteger>
- Parameters:
s
- String.- Returns:
- Biginteger from s.
-
parse
BigInteger parse from Reader.- Specified by:
parse
in interfaceElemFactory<BigInteger>
- Parameters:
r
- Reader.- Returns:
- next Biginteger from r.
-
getDecimal
Get the decimal representation.- Returns:
- decimal.
-
getRational
Return a BigRational approximation of this Element.- Specified by:
getRational
in interfaceRational
- Returns:
- a BigRational approximation of this.
-
bitLength
public long bitLength()Returns the number of bits in the representation of this BigInteger, including a sign bit. For positive BigIntegers, this is equivalent to(ceil(log2(this+1))+1)
.)- Returns:
- number of bits in the representation of this BigInteger, including a sign bit.
-
bitLength
public static long bitLength(long v) Returns the number of bits in the representation of a Long, including a sign bit.- Parameters:
v
- value.- Returns:
- number of bits in the representation of a Long, including a sign bit.
-
setAllIterator
public void setAllIterator()Set the iteration algorithm to all elements. -
setNonNegativeIterator
public void setNonNegativeIterator()Set the iteration algorithm to non-negative elements. -
iterator
Get a BigInteger iterator.- Specified by:
iterator
in interfaceIterable<BigInteger>
- Returns:
- a iterator over all integers.
-