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 ModIntRing
ring
ModIntRing reference.int
val
Value 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 ModInt
abs()
ModInt absolute value.int
bitLength()
Returns the number of bits in the representation of this ModInt, including a sign bit.int
compareTo(ModInt b)
ModInt comparison.ModInt
copy()
Clone this.ModInt
divide(ModInt S)
ModInt divide.ModInt[]
egcd(ModInt S)
ModInteger extended greatest common divisor.boolean
equals(java.lang.Object b)
Comparison with any other object.ModIntRing
factory()
Get the corresponding element factory.int
gcd(int T, int S)
Int greatest common divisor.ModInt
gcd(ModInt S)
ModInteger greatest common divisor.BigInteger
getInteger()
Return a BigInteger from this Element.int
getModul()
Get the module part.BigInteger
getSymmetricInteger()
Return a symmetric BigInteger from this Element.int
getSymmetricVal()
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.ModInt
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(ModInt S)
ModInt multiply.ModInt
negate()
ModInt negative.ModInt
remainder(ModInt S)
ModInt remainder.int
signum()
ModInt signum.ModInt
subtract(ModInt S)
ModInt subtraction.ModInt
sum(ModInt S)
ModInt summation.java.lang.String
toScript()
Get a scripting compatible string representation.java.lang.String
toScriptFactory()
Get a scripting compatible string representation of the factory.java.lang.String
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 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:
factory
in 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:
getInteger
in interfaceModular
- Returns:
- a BigInteger of this.
-
getSymmetricInteger
public BigInteger getSymmetricInteger()
Return a symmetric BigInteger from this Element.- Specified by:
getSymmetricInteger
in interfaceModular
- Returns:
- a symmetric BigInteger of 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:
AbelianGroupElem.isZERO()
-
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:
MonoidElem.isONE()
-
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:
MonoidElem.isUnit()
-
toString
public java.lang.String toString()
Get the String representation.- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
toScript
public java.lang.String toScript()
Get a scripting compatible string representation.- Specified by:
toScript
in 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:
toScriptFactory
in 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:
abs
in interfaceAbelianGroupElem<ModInt>
- Returns:
- the absolute value of this.
- See Also:
AbelianGroupElem.abs()
-
negate
public ModInt negate()
ModInt negative.- Specified by:
negate
in interfaceAbelianGroupElem<ModInt>
- Returns:
- -this.
- See Also:
AbelianGroupElem.negate()
-
signum
public int signum()
ModInt signum.- Specified by:
signum
in interfaceAbelianGroupElem<ModInt>
- Returns:
- signum(this).
- See Also:
AbelianGroupElem.signum()
-
subtract
public ModInt subtract(ModInt S)
ModInt subtraction.- Specified by:
subtract
in interfaceAbelianGroupElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- this-S.
-
divide
public ModInt divide(ModInt S)
ModInt divide.- Specified by:
divide
in interfaceMonoidElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- this/S.
-
inverse
public ModInt 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:
MonoidElem.inverse()
-
remainder
public ModInt remainder(ModInt S)
ModInt remainder.- Specified by:
remainder
in interfaceMonoidElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- remainder(this,S).
-
multiply
public ModInt multiply(ModInt S)
ModInt multiply.- Specified by:
multiply
in interfaceMonoidElem<ModInt>
- Parameters:
S
- ModInt.- Returns:
- this*S.
-
sum
public ModInt sum(ModInt S)
ModInt summation.- Specified by:
sum
in 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.
-
-