Package edu.jas.arith
Class ModLong
- java.lang.Object
-
- edu.jas.arith.ModLong
-
- All Implemented Interfaces:
Modular,AbelianGroupElem<ModLong>,Element<ModLong>,GcdRingElem<ModLong>,MonoidElem<ModLong>,RingElem<ModLong>,java.io.Serializable,java.lang.Comparable<ModLong>
public final class ModLong extends java.lang.Object implements GcdRingElem<ModLong>, Modular
ModLong 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 ModLongRingringModLongRing reference.longvalValue part of the element data structure.
-
Constructor Summary
Constructors Constructor Description ModLong(ModLongRing m)The constructor creates a 0 ModLong object from a given ModLongRing.ModLong(ModLongRing m, long a)The constructor creates a ModLong object from a ModLongRing and a long value part.ModLong(ModLongRing m, java.lang.Long a)The constructor creates a ModLong object from a ModLongRing and a Long value part.ModLong(ModLongRing m, java.lang.String s)The constructor creates a ModLong object from a ModLongRing and a String value part.ModLong(ModLongRing m, java.math.BigInteger a)The constructor creates a ModLong object from a ModLongRing and a value part.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ModLongabs()ModLong absolute value.longbitLength()Returns the number of bits in the representation of this ModLong, including a sign bit.intcompareTo(ModLong b)ModLong comparison.ModLongcopy()Clone this.ModLongdivide(ModLong S)ModLong divide.ModLong[]egcd(ModLong S)ModInteger extended greatest common divisor.booleanequals(java.lang.Object b)Comparison with any other object.ModLongRingfactory()Get the corresponding element factory.longgcd(long T, long S)Long greatest common divisor.ModLonggcd(ModLong S)ModInteger greatest common divisor.BigIntegergetInteger()Return a BigInteger from this Element.longgetModul()Get the module part.BigIntegergetSymmetricInteger()Return a symmetric BigInteger from this Element.longgetSymmetricVal()Get the symmetric value part.longgetVal()Get the value part.inthashCode()Hash code for this ModLong.long[]hegcd(long T, long S)Long half extended greatest common divisor.ModLonginverse()ModLong inverse.booleanisONE()Is ModLong number one.booleanisUnit()Is ModLong number a unit.booleanisZERO()Is ModLong number zero.longmodInverse(long T, long m)Long modular inverse.ModLongmultiply(ModLong S)ModLong multiply.ModLongnegate()ModLong negative.ModLongremainder(ModLong S)ModLong remainder.intsignum()ModLong signum.ModLongsubtract(ModLong S)ModLong subtraction.ModLongsum(ModLong S)ModLong 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 ModLongRing ring
ModLongRing reference.
-
val
public final long val
Value part of the element data structure.
-
-
Constructor Detail
-
ModLong
public ModLong(ModLongRing m, java.math.BigInteger a)
The constructor creates a ModLong object from a ModLongRing and a value part.- Parameters:
m- ModLongRing.a- math.BigInteger.
-
ModLong
public ModLong(ModLongRing m, long a)
The constructor creates a ModLong object from a ModLongRing and a long value part.- Parameters:
m- ModLongRing.a- long.
-
ModLong
public ModLong(ModLongRing m, java.lang.Long a)
The constructor creates a ModLong object from a ModLongRing and a Long value part.- Parameters:
m- ModLongRing.a- Long.
-
ModLong
public ModLong(ModLongRing m, java.lang.String s)
The constructor creates a ModLong object from a ModLongRing and a String value part.- Parameters:
m- ModLongRing.s- String.
-
ModLong
public ModLong(ModLongRing m)
The constructor creates a 0 ModLong object from a given ModLongRing.- Parameters:
m- ModLongRing.
-
-
Method Detail
-
getVal
public long getVal()
Get the value part.- Returns:
- val.
-
getModul
public long getModul()
Get the module part.- Returns:
- modul.
-
factory
public ModLongRing factory()
Get the corresponding element factory.- Specified by:
factoryin interfaceElement<ModLong>- Returns:
- factory for this Element.
- See Also:
Element.factory()
-
getSymmetricVal
public long 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 ModLong number zero.- Specified by:
isZEROin interfaceAbelianGroupElem<ModLong>- Returns:
- If this is 0 then true is returned, else false.
- See Also:
AbelianGroupElem.isZERO()
-
isONE
public boolean isONE()
Is ModLong number one.- Specified by:
isONEin interfaceMonoidElem<ModLong>- Returns:
- If this is 1 then true is returned, else false.
- See Also:
MonoidElem.isONE()
-
isUnit
public boolean isUnit()
Is ModLong number a unit.- Specified by:
isUnitin interfaceMonoidElem<ModLong>- 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<ModLong>- 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<ModLong>- 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 ModLong.
-
abs
public ModLong abs()
ModLong absolute value.- Specified by:
absin interfaceAbelianGroupElem<ModLong>- Returns:
- the absolute value of this.
- See Also:
AbelianGroupElem.abs()
-
negate
public ModLong negate()
ModLong negative.- Specified by:
negatein interfaceAbelianGroupElem<ModLong>- Returns:
- -this.
- See Also:
AbelianGroupElem.negate()
-
signum
public int signum()
ModLong signum.- Specified by:
signumin interfaceAbelianGroupElem<ModLong>- Returns:
- signum(this).
- See Also:
AbelianGroupElem.signum()
-
subtract
public ModLong subtract(ModLong S)
ModLong subtraction.- Specified by:
subtractin interfaceAbelianGroupElem<ModLong>- Parameters:
S- ModLong.- Returns:
- this-S.
-
divide
public ModLong divide(ModLong S)
ModLong divide.- Specified by:
dividein interfaceMonoidElem<ModLong>- Parameters:
S- ModLong.- Returns:
- this/S.
-
inverse
public ModLong inverse()
ModLong inverse.- Specified by:
inversein interfaceMonoidElem<ModLong>- Returns:
- S with S=1/this if defined.
- Throws:
NotInvertibleException- if the element is not invertible.- See Also:
MonoidElem.inverse()
-
remainder
public ModLong remainder(ModLong S)
ModLong remainder.- Specified by:
remainderin interfaceMonoidElem<ModLong>- Parameters:
S- ModLong.- Returns:
- remainder(this,S).
-
multiply
public ModLong multiply(ModLong S)
ModLong multiply.- Specified by:
multiplyin interfaceMonoidElem<ModLong>- Parameters:
S- ModLong.- Returns:
- this*S.
-
sum
public ModLong sum(ModLong S)
ModLong summation.- Specified by:
sumin interfaceAbelianGroupElem<ModLong>- Parameters:
S- ModLong.- Returns:
- this+S.
-
gcd
public long gcd(long T, long S)
Long greatest common divisor.- Parameters:
T- long.S- long.- Returns:
- gcd(T,S).
-
hegcd
public long[] hegcd(long T, long S)
Long half extended greatest common divisor.- Parameters:
T- long.S- long.- Returns:
- [ gcd(T,S), a ] with a*T + b*S = gcd(T,S).
-
modInverse
public long modInverse(long T, long m)
Long modular inverse.- Parameters:
T- long.m- long.- Returns:
- a with with a*T = 1 mod m.
-
bitLength
public long bitLength()
Returns the number of bits in the representation of this ModLong, including a sign bit.- Returns:
- number of bits in the representation of this ModLong, including a sign bit.
-
-