Package edu.jas.arith
Class ModInt
- java.lang.Object
-
- edu.jas.arith.ModInt
-
- All Implemented Interfaces:
Modular,AbelianGroupElem<ModInt>,Element<ModInt>,GcdRingElem<ModInt>,MonoidElem<ModInt>,RingElem<ModInt>,java.io.Serializable,java.lang.Comparable<ModInt>
public final class ModInt extends java.lang.Object implements GcdRingElem<ModInt>, Modular
ModInt class with RingElem interface. Objects of this class are immutable.- Author:
- Heinz Kredel
- See Also:
ModInteger, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description ModIntRingringModIntRing reference.intvalValue part of the element data structure.
-
Constructor Summary
Constructors Constructor Description ModInt(ModIntRing m)The constructor creates a 0 ModInt object from a given ModIntRing.ModInt(ModIntRing m, int a)The constructor creates a ModInt object from a ModIntRing and a int value part.ModInt(ModIntRing m, long a)The constructor creates a ModInt object from a ModIntRing and a long value part.ModInt(ModIntRing m, java.lang.Integer a)The constructor creates a ModInt object from a ModIntRing and a Int value part.ModInt(ModIntRing m, java.lang.Long a)The constructor creates a ModInt object from a ModIntRing and a Long value part.ModInt(ModIntRing m, java.lang.String s)The constructor creates a ModInt object from a ModIntRing and a String value part.ModInt(ModIntRing m, java.math.BigInteger a)The constructor creates a ModInt object from a ModIntRing and a value part.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ModIntabs()ModInt absolute value.intbitLength()Returns the number of bits in the representation of this ModInt, including a sign bit.intcompareTo(ModInt b)ModInt comparison.ModIntcopy()Clone this.ModIntdivide(ModInt S)ModInt divide.ModInt[]egcd(ModInt S)ModInteger extended greatest common divisor.booleanequals(java.lang.Object b)Comparison with any other object.ModIntRingfactory()Get the corresponding element factory.intgcd(int T, int S)Int greatest common divisor.ModIntgcd(ModInt S)ModInteger greatest common divisor.BigIntegergetInteger()Return a BigInteger from this Element.intgetModul()Get the module part.BigIntegergetSymmetricInteger()Return a symmetric BigInteger from this Element.intgetSymmetricVal()Get the symmetric value part.intgetVal()Get the value part.inthashCode()Hash code for this ModInt.int[]hegcd(int T, int S)Int half extended greatest common divisor.ModIntinverse()ModInt inverse.booleanisONE()Is ModInt number one.booleanisUnit()Is ModInt number a unit.booleanisZERO()Is ModInt number zero.intmodInverse(int T, int m)Int modular inverse.ModIntmultiply(ModInt S)ModInt multiply.ModIntnegate()ModInt negative.ModIntremainder(ModInt S)ModInt remainder.intsignum()ModInt signum.ModIntsubtract(ModInt S)ModInt subtraction.ModIntsum(ModInt S)ModInt 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, quotientRemainder, rightDivide, rightRemainder, twosidedDivide, twosidedRemainder
-
-
-
-
Field Detail
-
ring
public final ModIntRing ring
ModIntRing reference.
-
val
public final int val
Value part of the element data structure.
-
-
Constructor Detail
-
ModInt
public ModInt(ModIntRing m, java.math.BigInteger a)
The constructor creates a ModInt object from a ModIntRing and a value part.- Parameters:
m- ModIntRing.a- math.BigInteger.
-
ModInt
public ModInt(ModIntRing m, int a)
The constructor creates a ModInt object from a ModIntRing and a int value part.- Parameters:
m- ModIntRing.a- int.
-
ModInt
public ModInt(ModIntRing m, long a)
The constructor creates a ModInt object from a ModIntRing and a long value part.- Parameters:
m- ModIntRing.a- long.
-
ModInt
public ModInt(ModIntRing m, java.lang.Integer a)
The constructor creates a ModInt object from a ModIntRing and a Int value part.- Parameters:
m- ModIntRing.a- Int.
-
ModInt
public ModInt(ModIntRing m, java.lang.Long a)
The constructor creates a ModInt object from a ModIntRing and a Long value part.- Parameters:
m- ModIntRing.a- long.
-
ModInt
public ModInt(ModIntRing m, java.lang.String s)
The constructor creates a ModInt object from a ModIntRing and a String value part.- Parameters:
m- ModIntRing.s- String.
-
ModInt
public ModInt(ModIntRing m)
The constructor creates a 0 ModInt object from a given ModIntRing.- Parameters:
m- ModIntRing.
-
-
Method Detail
-
getVal
public int getVal()
Get the value part.- Returns:
- val.
-
getModul
public int getModul()
Get the module part.- Returns:
- modul.
-
factory
public ModIntRing factory()
Get the corresponding element factory.- Specified by:
factoryin interfaceElement<ModInt>- Returns:
- factory for this Element.
- See Also:
Element.factory()
-
getSymmetricVal
public int 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.
-
isZERO
public boolean isZERO()
Is ModInt number zero.- Specified by:
isZEROin interfaceAbelianGroupElem<ModInt>- Returns:
- If this is 0 then true is returned, else false.
- See Also:
AbelianGroupElem.isZERO()
-
isONE
public boolean isONE()
Is ModInt number one.- Specified by:
isONEin interfaceMonoidElem<ModInt>- Returns:
- If this is 1 then true is returned, else false.
- See Also:
MonoidElem.isONE()
-
isUnit
public boolean isUnit()
Is ModInt number a unit.- Specified by:
isUnitin interfaceMonoidElem<ModInt>- 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<ModInt>- 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<ModInt>- Returns:
- script compatible representation for this ElemFactory.
- See Also:
Element.toScriptFactory()
-
equals
public boolean equals(java.lang.Object b)
Comparison with any other object.
-
hashCode
public int hashCode()
Hash code for this ModInt.
-
abs
public ModInt abs()
ModInt absolute value.- Specified by:
absin interfaceAbelianGroupElem<ModInt>- Returns:
- the absolute value of this.
- See Also:
AbelianGroupElem.abs()
-
negate
public ModInt negate()
ModInt negative.- Specified by:
negatein interfaceAbelianGroupElem<ModInt>- Returns:
- -this.
- See Also:
AbelianGroupElem.negate()
-
signum
public int signum()
ModInt signum.- Specified by:
signumin interfaceAbelianGroupElem<ModInt>- Returns:
- signum(this).
- See Also:
AbelianGroupElem.signum()
-
subtract
public ModInt subtract(ModInt S)
ModInt subtraction.- Specified by:
subtractin interfaceAbelianGroupElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this-S.
-
divide
public ModInt divide(ModInt S)
ModInt divide.- Specified by:
dividein interfaceMonoidElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this/S.
-
inverse
public ModInt inverse()
ModInt inverse.- Specified by:
inversein interfaceMonoidElem<ModInt>- Returns:
- S with S=1/this if defined.
- Throws:
NotInvertibleException- if the element is not invertible.- See Also:
MonoidElem.inverse()
-
remainder
public ModInt remainder(ModInt S)
ModInt remainder.- Specified by:
remainderin interfaceMonoidElem<ModInt>- Parameters:
S- ModInt.- Returns:
- remainder(this,S).
-
multiply
public ModInt multiply(ModInt S)
ModInt multiply.- Specified by:
multiplyin interfaceMonoidElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this*S.
-
sum
public ModInt sum(ModInt S)
ModInt summation.- Specified by:
sumin interfaceAbelianGroupElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this+S.
-
gcd
public int gcd(int T, int S)
Int greatest common divisor.- Parameters:
T- int.S- int.- Returns:
- gcd(T,S).
-
hegcd
public int[] hegcd(int T, int S)
Int half extended greatest common divisor.- Parameters:
T- int.S- int.- Returns:
- [ gcd(T,S), a ] with a*T + b*S = gcd(T,S).
-
modInverse
public int modInverse(int T, int m)
Int modular inverse.- Parameters:
T- int.m- int.- Returns:
- a with with a*T = 1 mod m.
-
bitLength
public int bitLength()
Returns the number of bits in the representation of this ModInt, including a sign bit.- Returns:
- number of bits in the representation of this ModInt, including a sign bit.
-
-