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 ModIntRing
ModIntRing reference.final int
Value 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.int
Returns the number of bits in the representation of this ModInt, including a sign bit.int
ModInt comparison.copy()
Clone this.ModInt divide.ModInt[]
ModInteger extended greatest common divisor.boolean
Comparison with any other object.factory()
Get the corresponding element factory.int
gcd
(int T, int S) Int greatest common divisor.ModInteger greatest common divisor.Return a BigInteger from this Element.int
getModul()
Get the module part.Return a symmetric BigInteger from this Element.int
Get the symmetric value part.int
getVal()
Get the value part.int
hashCode()
Hash code for this ModInt.int[]
hegcd
(int T, int S) Int half extended greatest common divisor.inverse()
ModInt inverse.boolean
isONE()
Is ModInt number one.boolean
isUnit()
Is ModInt number a unit.boolean
isZERO()
Is ModInt number zero.int
modInverse
(int T, int m) Int modular inverse.ModInt multiply.negate()
ModInt negative.ModInt remainder.int
signum()
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, wait
Methods 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:
getInteger
in interfaceModular
- Returns:
- a BigInteger of this.
-
getSymmetricInteger
Return a symmetric BigInteger from this Element.- Specified by:
getSymmetricInteger
in interfaceModular
- Returns:
- a symmetric BigInteger of this.
-
copy
Clone this. -
isZERO
public boolean isZERO()Is ModInt number zero.- Specified by:
isZERO
in 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:
isONE
in 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:
isUnit
in 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:
toScriptFactory
in 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:
abs
in interfaceAbelianGroupElem<ModInt>
- Returns:
- the absolute value of this.
- See Also:
-
negate
ModInt negative.- Specified by:
negate
in interfaceAbelianGroupElem<ModInt>
- Returns:
- -this.
- See Also:
-
signum
public int signum()ModInt signum.- Specified by:
signum
in interfaceAbelianGroupElem<ModInt>
- Returns:
- signum(this).
- See Also:
-
subtract
ModInt subtraction.- Specified by:
subtract
in interfaceAbelianGroupElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- this-S.
-
divide
ModInt divide.- Specified by:
divide
in interfaceMonoidElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- this/S.
-
inverse
ModInt inverse.- Specified by:
inverse
in 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:
remainder
in interfaceMonoidElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- remainder(this,S).
-
multiply
ModInt multiply.- Specified by:
multiply
in interfaceMonoidElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- this*S.
-
sum
ModInt summation.- Specified by:
sum
in 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.
-