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>,Serializable,Comparable<ModInt>
ModInt class with RingElem interface. Objects of this class are immutable.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ModIntRingModIntRing reference.final intValue part of the element data structure. -
Constructor Summary
ConstructorsConstructorDescriptionModInt(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, Integer 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, String s) The constructor creates a ModInt object from a ModIntRing and a String value part.ModInt(ModIntRing m, BigInteger a) The constructor creates a ModInt object from a ModIntRing and a value part. -
Method Summary
Modifier and TypeMethodDescriptionabs()ModInt absolute value.intReturns the number of bits in the representation of this ModInt, including a sign bit.intModInt comparison.copy()Clone this.ModInt divide.ModInt[]ModInteger extended greatest common divisor.booleanComparison with any other object.factory()Get the corresponding element factory.intgcd(int T, int S) Int greatest common divisor.ModInteger greatest common divisor.Return a BigInteger from this Element.intgetModul()Get the module part.Return a symmetric BigInteger from this Element.intGet 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.inverse()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.ModInt multiply.negate()ModInt negative.ModInt remainder.intsignum()ModInt signum.ModInt subtraction.ModInt summation.toScript()Get a scripting compatible string representation.Get a scripting compatible string representation of the factory.toString()Get the String representation.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.jas.structure.MonoidElem
leftDivide, leftRemainder, power, quotientRemainder, rightDivide, rightRemainder, twosidedDivide, twosidedRemainder
-
Field Details
-
ring
ModIntRing reference. -
val
public final int valValue part of the element data structure.
-
-
Constructor Details
-
ModInt
The constructor creates a ModInt object from a ModIntRing and a value part.- Parameters:
m- ModIntRing.a- math.BigInteger.
-
ModInt
The constructor creates a ModInt object from a ModIntRing and a int value part.- Parameters:
m- ModIntRing.a- int.
-
ModInt
The constructor creates a ModInt object from a ModIntRing and a long value part.- Parameters:
m- ModIntRing.a- long.
-
ModInt
The constructor creates a ModInt object from a ModIntRing and a Int value part.- Parameters:
m- ModIntRing.a- Int.
-
ModInt
The constructor creates a ModInt object from a ModIntRing and a Long value part.- Parameters:
m- ModIntRing.a- long.
-
ModInt
The constructor creates a ModInt object from a ModIntRing and a String value part.- Parameters:
m- ModIntRing.s- String.
-
ModInt
The constructor creates a 0 ModInt object from a given ModIntRing.- Parameters:
m- ModIntRing.
-
-
Method Details
-
getVal
public int getVal()Get the value part.- Returns:
- val.
-
getModul
public int getModul()Get the module part.- Returns:
- modul.
-
factory
Get the corresponding element factory. -
getSymmetricVal
public int getSymmetricVal()Get the symmetric value part.- Returns:
- val with -modul/2 ≤ val < modul/2.
-
getInteger
Return a BigInteger from this Element.- Specified by:
getIntegerin interfaceModular- Returns:
- a BigInteger of this.
-
getSymmetricInteger
Return a symmetric BigInteger from this Element.- Specified by:
getSymmetricIntegerin interfaceModular- Returns:
- a symmetric BigInteger of this.
-
copy
Clone 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:
-
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:
-
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:
-
toString
Get the String representation. -
toScript
Get a scripting compatible string representation. -
toScriptFactory
Get a scripting compatible string representation of the factory.- Specified by:
toScriptFactoryin interfaceElement<ModInt>- Returns:
- script compatible representation for this ElemFactory.
- See Also:
-
compareTo
ModInt comparison. -
equals
Comparison with any other object. -
hashCode
public int hashCode()Hash code for this ModInt. -
abs
ModInt absolute value.- Specified by:
absin interfaceAbelianGroupElem<ModInt>- Returns:
- the absolute value of this.
- See Also:
-
negate
ModInt negative.- Specified by:
negatein interfaceAbelianGroupElem<ModInt>- Returns:
- -this.
- See Also:
-
signum
public int signum()ModInt signum.- Specified by:
signumin interfaceAbelianGroupElem<ModInt>- Returns:
- signum(this).
- See Also:
-
subtract
ModInt subtraction.- Specified by:
subtractin interfaceAbelianGroupElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this-S.
-
divide
ModInt divide.- Specified by:
dividein interfaceMonoidElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this/S.
-
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:
-
remainder
ModInt remainder.- Specified by:
remainderin interfaceMonoidElem<ModInt>- Parameters:
S- ModInt.- Returns:
- remainder(this,S).
-
multiply
ModInt multiply.- Specified by:
multiplyin interfaceMonoidElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this*S.
-
sum
ModInt summation.- Specified by:
sumin interfaceAbelianGroupElem<ModInt>- Parameters:
S- ModInt.- Returns:
- this+S.
-
gcd
ModInteger greatest common divisor. -
egcd
ModInteger extended greatest common divisor. -
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.
-