public class Zn.ZnElement extends java.lang.Object implements RingElement, UniqueByteRepresentable
| Modifier and Type | Field and Description |
|---|---|
protected java.math.BigInteger |
v
The unique integer
v such that 0 <= v < n and v projects
to the represented element in Zn. |
| Modifier | Constructor and Description |
|---|---|
protected |
ZnElement()
Create the zero element.
|
protected |
ZnElement(java.math.BigInteger v)
Construct a new
ZnElement initialized as [v] mod n (must reduce v before calling!). |
| Modifier and Type | Method and Description |
|---|---|
Zn.ZnElement |
add(Element e)
Computes \(\text{this} + e\).
|
ExponentExpr |
add(ExponentExpr e) |
ExponentConstantExpr |
asExponentExpression() |
java.math.BigInteger |
asInteger()
Interprets this element as an integer.
|
protected void |
checkSameModulus(Element e) |
Zn.ZnElement |
div(Element e)
Computes \(\text{this} / e = \text{this} \cdot e^{-1}\).
|
boolean |
divides(RingElement e)
Returns true iff there exists an \(x\) in the ring such that \(\text{this} \cdot x = e\).
|
Zn.ZnElement[] |
divideWithRemainder(RingElement e)
Divides this by e with remainder, returning both quotient and remainder.
|
boolean |
equals(java.lang.Object obj) |
java.math.BigInteger |
getRank()
Implements the euclidean function of a euclidean domain.
|
Representation |
getRepresentation()
The representation of this object.
|
Zn |
getStructure()
Returns the
Structure that this Element belongs to. |
int |
hashCode() |
Zn.ZnElement |
inv()
Computes the multiplicative inverse of this element.
|
ExponentEqualityExpr |
isEqualTo(java.math.BigInteger other)
Returns an expression "this = other mod n".
|
ExponentEqualityExpr |
isEqualTo(ExponentExpr other)
Returns an expression "this = other".
|
ExponentEqualityExpr |
isEqualTo(long other)
Returns an expression "this = other mod n".
|
ExponentEqualityExpr |
isEqualTo(Zn.ZnElement other)
Returns an expression "this = other".
|
Zn.ZnElement |
mul(java.math.BigInteger k)
Computes \(\text{this} \cdot k\) (equivalent to \(\text{this} + \text{this} + \cdots\) k-times).
|
Zn.ZnElement |
mul(Element e)
Computes \(\text{this} \cdot e\).
|
ExponentExpr |
mul(ExponentExpr e) |
Zn.ZnElement |
mul(long k)
Computes \(\text{this} \cdot k\) (equivalent to \(\text{this} + \text{this} + \cdots\) k-times).
|
Zn.ZnElement |
neg()
Computes the additive inverse of this element.
|
Zn.ZnElement |
pow(java.math.BigInteger k)
Calculates \(\text{this}^k\).
|
ExponentExpr |
pow(ExponentExpr e) |
Zn.ZnElement |
pow(long k)
Calculates \(\text{this}^k\).
|
Zn.ZnElement |
square()
Computes \(\text{this}^2\).
|
Zn.ZnElement |
sub(Element e)
Computes \(\text{this} - e\).
|
ExponentExpr |
sub(ExponentExpr e) |
java.lang.String |
toString() |
ByteAccumulator |
updateAccumulator(ByteAccumulator accumulator)
Updates the ByteAccumulator with the unique byte representation of this object.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitisOne, isUnit, isZero, toAdditiveGroupElement, toUnitGroupElementgetUniqueByteRepresentationprotected final java.math.BigInteger v
v such that 0 <= v < n and v projects
to the represented element in Zn.protected ZnElement(java.math.BigInteger v)
ZnElement initialized as [v] mod n (must reduce v before calling!).protected ZnElement()
public Zn getStructure()
ElementStructure that this Element belongs to.getStructure in interface ElementgetStructure in interface RingElementpublic Zn.ZnElement add(Element e)
RingElementadd in interface RingElemente - the addendpublic ExponentExpr add(ExponentExpr e)
public Zn.ZnElement neg()
RingElementneg in interface RingElementpublic Zn.ZnElement sub(Element e)
RingElementsub in interface RingElemente - the subtrahendpublic ExponentExpr sub(ExponentExpr e)
public Zn.ZnElement mul(Element e)
RingElementmul in interface RingElemente - the factorpublic Zn.ZnElement mul(java.math.BigInteger k)
RingElementmul in interface RingElementk - the factorpublic Zn.ZnElement mul(long k)
RingElementmul in interface RingElementk - the factorpublic ExponentExpr mul(ExponentExpr e)
public Zn.ZnElement pow(java.math.BigInteger k)
RingElementNote that \(a^0 = 1\) for any \(a\) in the ring, particularly \(0^0 = 1\).
pow in interface RingElementpublic Zn.ZnElement pow(long k)
RingElementNote that \(a^0 = 1\) for any \(a\) in the ring, particularly \(0^0 = 1\).
pow in interface RingElementpublic ExponentExpr pow(ExponentExpr e)
public Zn.ZnElement inv() throws java.lang.UnsupportedOperationException
RingElementinv in interface RingElementjava.lang.UnsupportedOperationException - if this is not a unitpublic Zn.ZnElement square()
RingElementUseful if the ring allows squaring to be more efficiently implemented than general exponentiation.
square in interface RingElementpublic Zn.ZnElement div(Element e) throws java.lang.IllegalArgumentException
RingElementdiv in interface RingElemente - the divisorjava.lang.IllegalArgumentException - if e is not a unitpublic boolean divides(RingElement e) throws java.lang.UnsupportedOperationException
RingElementdivides in interface RingElementjava.lang.UnsupportedOperationException - if this cannot be decided (efficiently)public Zn.ZnElement[] divideWithRemainder(RingElement e) throws java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException
RingElement
Specifically, returns an array result such that the first entry contains the quotient
and the second entry the remainder.
Furthermore, result[1].getRank() < e.getRank() or result[1] = 0.
This definition implies that the remainder is zero if and only if e divides this element.
divideWithRemainder in interface RingElementjava.lang.UnsupportedOperationException - if the ring is not a euclidean domainjava.lang.IllegalArgumentException - if e is zeropublic java.math.BigInteger getRank()
throws java.lang.UnsupportedOperationException
RingElementThe euclidean function is a function from \(R \setminus \{0\}\) to \(\mathbb{N}_0\) such that
a.getRank() >= 0 for any a in the ring
a.mul(b).getRank() >= a.getRank() for any a, b != 0
divideWithRemainder is less than the divisor's rank
The rank of the zero element is undefined (no guarantee as to what this method returns in that case).
getRank in interface RingElementjava.lang.UnsupportedOperationException - if the ring is not a euclidean domainprotected void checkSameModulus(Element e)
public boolean equals(java.lang.Object obj)
public int hashCode()
public Representation getRepresentation()
RepresentableReprUtilgetRepresentation in interface RepresentableRepresentationpublic java.lang.String toString()
toString in class java.lang.Objectpublic ByteAccumulator updateAccumulator(ByteAccumulator accumulator)
UniqueByteRepresentableThe input to the accumulators update function is an injective (with respect to a given domain) byte encoding of this object.
For many use-cases, the AnnotatedUbrUtil can be used to quickly implement this method.
updateAccumulator in interface UniqueByteRepresentablepublic ExponentConstantExpr asExponentExpression()
public ExponentEqualityExpr isEqualTo(ExponentExpr other)
equals(Object).public ExponentEqualityExpr isEqualTo(Zn.ZnElement other)
equals(Object).public ExponentEqualityExpr isEqualTo(java.math.BigInteger other)
equals(Object).public ExponentEqualityExpr isEqualTo(long other)
equals(Object).public java.math.BigInteger asInteger()
throws java.lang.UnsupportedOperationException
RingElementResult will be between 0 and the ring's characteristic.
Formally, this method shall return the inverse of Ring.getElement(BigInteger), i.e.
x.getStructure().getElement(x.asInteger()).equals(x) (if asInteger() doesn't throw an exception).
asInteger in interface RingElementjava.lang.UnsupportedOperationException - if no such element exists or cannot be efficiently computed