Package edu.jas.arith
Class ModInteger
- java.lang.Object
-
- edu.jas.arith.ModInteger
-
- All Implemented Interfaces:
Modular,AbelianGroupElem<ModInteger>,Element<ModInteger>,GcdRingElem<ModInteger>,MonoidElem<ModInteger>,RingElem<ModInteger>,java.io.Serializable,java.lang.Comparable<ModInteger>
public final class ModInteger extends java.lang.Object implements GcdRingElem<ModInteger>, Modular
ModInteger class with GcdRingElem interface. Objects of this class are immutable. The SAC2 static methods are also provided.- Author:
- Heinz Kredel
- See Also:
BigInteger, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description ModIntegerRingringModIntegerRing reference.java.math.BigIntegervalValue part of the element data structure.
-
Constructor Summary
Constructors Constructor Description ModInteger(ModIntegerRing m)The constructor creates a 0 ModInteger object from a given ModIntegerRing.ModInteger(ModIntegerRing m, long a)The constructor creates a ModInteger object from a ModIntegerRing and a long value part.ModInteger(ModIntegerRing m, java.lang.String s)The constructor creates a ModInteger object from a ModIntegerRing and a String value part.ModInteger(ModIntegerRing m, java.math.BigInteger a)The constructor creates a ModInteger object from a ModIntegerRing and a value part.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ModIntegerabs()ModInteger absolute value.longbitLength()Returns the number of bits in the representation of this ModInteger, including a sign bit.intcompareTo(ModInteger b)ModInteger comparison.ModIntegercopy()Clone this.ModIntegerdivide(ModInteger S)ModInteger divide.ModInteger[]egcd(ModInteger S)ModInteger extended greatest common divisor.booleanequals(java.lang.Object b)Comparison with any other object.ModIntegerRingfactory()Get the corresponding element factory.ModIntegergcd(ModInteger S)ModInteger greatest common divisor.BigIntegergetInteger()Return a BigInteger from this Element.java.math.BigIntegergetModul()Get the module part.BigIntegergetSymmetricInteger()Return a symmetric BigInteger from this Element.java.math.BigIntegergetSymmetricVal()Get the symmetric value part.java.math.BigIntegergetVal()Get the value part.inthashCode()Hash code for this ModInteger.ModInteger[]hegcd(ModInteger S)ModInteger half extended greatest common divisor.ModIntegerinverse()ModInteger inverse.booleanisONE()Is ModInteger number one.booleanisUnit()Is ModInteger number a unit.booleanisZERO()Is ModInteger number zero.static ModIntegerMIABS(ModInteger A)ModInteger absolute value.static intMICOMP(ModInteger A, ModInteger B)ModInteger comparison.static ModIntegerMIDIF(ModInteger A, ModInteger B)ModInteger subtraction.static ModIntegerMIINV(ModInteger A)ModInteger inverse.static ModIntegerMINEG(ModInteger A)ModInteger negative.static ModIntegerMIPROD(ModInteger A, ModInteger B)ModInteger product.static ModIntegerMIQ(ModInteger A, ModInteger B)ModInteger quotient.static ModIntegerMIREM(ModInteger A, ModInteger B)ModInteger remainder.static intMISIGN(ModInteger A)ModInteger signum.static ModIntegerMISUM(ModInteger A, ModInteger B)ModInteger summation.ModIntegermultiply(ModInteger S)ModInteger multiply.ModIntegernegate()ModInteger negative.ModInteger[]quotientRemainder(ModInteger S)Quotient and remainder by division of this by S.ModIntegerremainder(ModInteger S)ModInteger remainder.intsignum()ModInteger signum.ModIntegersubtract(ModInteger S)ModInteger subtraction.ModIntegersum(ModInteger S)ModInteger summation.java.lang.StringtoScript()Get a scripting compatible string representation.java.lang.StringtoScriptFactory()Get a scripting compatible string representation of the factory.java.lang.StringtoString()Get the String representation.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface edu.jas.structure.MonoidElem
leftDivide, leftRemainder, power, rightDivide, rightRemainder, twosidedDivide, twosidedRemainder
-
-
-
-
Field Detail
-
ring
public final ModIntegerRing ring
ModIntegerRing reference.
-
val
public final java.math.BigInteger val
Value part of the element data structure.
-
-
Constructor Detail
-
ModInteger
public ModInteger(ModIntegerRing m, java.math.BigInteger a)
The constructor creates a ModInteger object from a ModIntegerRing and a value part.- Parameters:
m- ModIntegerRing.a- math.BigInteger.
-
ModInteger
public ModInteger(ModIntegerRing m, long a)
The constructor creates a ModInteger object from a ModIntegerRing and a long value part.- Parameters:
m- ModIntegerRing.a- long.
-
ModInteger
public ModInteger(ModIntegerRing m, java.lang.String s)
The constructor creates a ModInteger object from a ModIntegerRing and a String value part.- Parameters:
m- ModIntegerRing.s- String.
-
ModInteger
public ModInteger(ModIntegerRing m)
The constructor creates a 0 ModInteger object from a given ModIntegerRing.- Parameters:
m- ModIntegerRing.
-
-
Method Detail
-
getVal
public java.math.BigInteger getVal()
Get the value part.- Returns:
- val.
-
getModul
public java.math.BigInteger getModul()
Get the module part.- Returns:
- modul.
-
factory
public ModIntegerRing factory()
Get the corresponding element factory.- Specified by:
factoryin interfaceElement<ModInteger>- Returns:
- factory for this Element.
- See Also:
Element.factory()
-
getSymmetricVal
public java.math.BigInteger getSymmetricVal()
Get the symmetric value part.- Returns:
- val with -modul/2 ≤ val < modul/2.
-
getInteger
public BigInteger getInteger()
Return a BigInteger from this Element.- Specified by:
getIntegerin interfaceModular- Returns:
- a BigInteger of this.
-
getSymmetricInteger
public BigInteger getSymmetricInteger()
Return a symmetric BigInteger from this Element.- Specified by:
getSymmetricIntegerin interfaceModular- Returns:
- a symmetric BigInteger of this.
-
copy
public ModInteger copy()
Clone this.- Specified by:
copyin interfaceElement<ModInteger>- Returns:
- Creates and returns a copy of this Element.
- See Also:
Object.clone()
-
isZERO
public boolean isZERO()
Is ModInteger number zero.- Specified by:
isZEROin interfaceAbelianGroupElem<ModInteger>- Returns:
- If this is 0 then true is returned, else false.
- See Also:
AbelianGroupElem.isZERO()
-
isONE
public boolean isONE()
Is ModInteger number one.- Specified by:
isONEin interfaceMonoidElem<ModInteger>- Returns:
- If this is 1 then true is returned, else false.
- See Also:
MonoidElem.isONE()
-
isUnit
public boolean isUnit()
Is ModInteger number a unit.- Specified by:
isUnitin interfaceMonoidElem<ModInteger>- Returns:
- If this is a unit then true is returned, else false.
- See Also:
MonoidElem.isUnit()
-
toString
public java.lang.String toString()
Get the String representation.- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
toScript
public java.lang.String toScript()
Get a scripting compatible string representation.- Specified by:
toScriptin interfaceElement<ModInteger>- 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:
toScriptFactoryin interfaceElement<ModInteger>- Returns:
- script compatible representation for this ElemFactory.
- See Also:
Element.toScriptFactory()
-
compareTo
public int compareTo(ModInteger b)
ModInteger comparison.- Specified by:
compareToin interfacejava.lang.Comparable<ModInteger>- Specified by:
compareToin interfaceElement<ModInteger>- Parameters:
b- ModInteger.- Returns:
- sign(this-b).
-
MICOMP
public static int MICOMP(ModInteger A, ModInteger B)
ModInteger comparison.- Parameters:
A- ModInteger.B- ModInteger.- Returns:
- sign(this-b).
-
equals
public boolean equals(java.lang.Object b)
Comparison with any other object.- Specified by:
equalsin interfaceElement<ModInteger>- Overrides:
equalsin classjava.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 ModInteger.- Specified by:
hashCodein interfaceElement<ModInteger>- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashCode.
- See Also:
Object.hashCode()
-
abs
public ModInteger abs()
ModInteger absolute value.- Specified by:
absin interfaceAbelianGroupElem<ModInteger>- Returns:
- the absolute value of this.
- See Also:
AbelianGroupElem.abs()
-
MIABS
public static ModInteger MIABS(ModInteger A)
ModInteger absolute value.- Parameters:
A- ModInteger.- Returns:
- the absolute value of A.
-
negate
public ModInteger negate()
ModInteger negative.- Specified by:
negatein interfaceAbelianGroupElem<ModInteger>- Returns:
- -this.
- See Also:
AbelianGroupElem.negate()
-
MINEG
public static ModInteger MINEG(ModInteger A)
ModInteger negative.- Parameters:
A- ModInteger.- Returns:
- -A.
-
signum
public int signum()
ModInteger signum.- Specified by:
signumin interfaceAbelianGroupElem<ModInteger>- Returns:
- signum(this).
- See Also:
AbelianGroupElem.signum()
-
MISIGN
public static int MISIGN(ModInteger A)
ModInteger signum.- Parameters:
A- ModInteger- Returns:
- signum(A).
-
subtract
public ModInteger subtract(ModInteger S)
ModInteger subtraction.- Specified by:
subtractin interfaceAbelianGroupElem<ModInteger>- Parameters:
S- ModInteger.- Returns:
- this-S.
-
MIDIF
public static ModInteger MIDIF(ModInteger A, ModInteger B)
ModInteger subtraction.- Parameters:
A- ModInteger.B- ModInteger.- Returns:
- A-B.
-
divide
public ModInteger divide(ModInteger S)
ModInteger divide.- Specified by:
dividein interfaceMonoidElem<ModInteger>- Parameters:
S- ModInteger.- Returns:
- this/S.
-
MIQ
public static ModInteger MIQ(ModInteger A, ModInteger B)
ModInteger quotient.- Parameters:
A- ModInteger.B- ModInteger.- Returns:
- A/B.
-
inverse
public ModInteger inverse()
ModInteger inverse.- Specified by:
inversein interfaceMonoidElem<ModInteger>- Returns:
- S with S=1/this if defined.
- Throws:
NotInvertibleException- if the element is not invertible.- See Also:
MonoidElem.inverse()
-
MIINV
public static ModInteger MIINV(ModInteger A)
ModInteger inverse.- Parameters:
A- is a non-zero integer.- Returns:
- S with S=1/A if defined.
- See Also:
MonoidElem.inverse()
-
remainder
public ModInteger remainder(ModInteger S)
ModInteger remainder.- Specified by:
remainderin interfaceMonoidElem<ModInteger>- Parameters:
S- ModInteger.- Returns:
- remainder(this,S).
-
MIREM
public static ModInteger MIREM(ModInteger A, ModInteger B)
ModInteger remainder.- Parameters:
A- ModInteger.B- ModInteger.- Returns:
- A - (A/B)*B.
-
quotientRemainder
public ModInteger[] quotientRemainder(ModInteger S)
Quotient and remainder by division of this by S.- Specified by:
quotientRemainderin interfaceMonoidElem<ModInteger>- Parameters:
S- a modular integer- Returns:
- [this/S, this - (this/S)*S].
-
multiply
public ModInteger multiply(ModInteger S)
ModInteger multiply.- Specified by:
multiplyin interfaceMonoidElem<ModInteger>- Parameters:
S- ModInteger.- Returns:
- this*S.
-
MIPROD
public static ModInteger MIPROD(ModInteger A, ModInteger B)
ModInteger product.- Parameters:
A- ModInteger.B- ModInteger.- Returns:
- A*B.
-
sum
public ModInteger sum(ModInteger S)
ModInteger summation.- Specified by:
sumin interfaceAbelianGroupElem<ModInteger>- Parameters:
S- ModInteger.- Returns:
- this+S.
-
MISUM
public static ModInteger MISUM(ModInteger A, ModInteger B)
ModInteger summation.- Parameters:
A- ModInteger.B- ModInteger.- Returns:
- A+B.
-
gcd
public ModInteger gcd(ModInteger S)
ModInteger greatest common divisor.- Specified by:
gcdin interfaceRingElem<ModInteger>- Parameters:
S- ModInteger.- Returns:
- gcd(this,S).
-
hegcd
public ModInteger[] hegcd(ModInteger S)
ModInteger half extended greatest common divisor.- Parameters:
S- ModInteger.- Returns:
- [ gcd(this,S), a ] with a*this + b*S = gcd(this,S) for some b.
-
egcd
public ModInteger[] egcd(ModInteger S)
ModInteger extended greatest common divisor.- Specified by:
egcdin interfaceRingElem<ModInteger>- Parameters:
S- ModInteger.- Returns:
- [ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).
-
bitLength
public long bitLength()
Returns the number of bits in the representation of this ModInteger, including a sign bit. For positive ModIntegers, this is equivalent toval.bitLength().)- Returns:
- number of bits in the representation of this ModInteger, including a sign bit.
-
-