Interface Ring<T extends Ring<T>>
- Type Parameters:
T
- the type of the ring element.
- All Superinterfaces:
Comparable<T>
,Semiring<T>
,Serializable
- All Known Subinterfaces:
Field<T>
- All Known Implementing Classes:
Complex128
,Complex64
,RealFloat32
,RealFloat64
,RealInt16
,RealInt32
A ring is an algebraic structure consisting of a set R equipped with two binary operations:
addition (+) and multiplication (*). Rings generalize fields
by not requiring every non-zero element to have a
multiplicative inverse, and multiplication may not be commutative.
Formal Definition:
For all elements a
, b
, and c
in R, the following properties must hold:
- Addition is associative:
a + (b + c) = (a + b) + c
- Addition is commutative:
a + b = b + a
- Additive identity exists: There exists an element
0
in R such thata + 0 = a
- Existence of additive inverses: For every
a
in R, there exists an element-a
in R such thata + (-a) = 0
- Multiplication is associative:
a * (b * c) = (a * b) * c
- Distributivity of multiplication over addition:
- Left distributivity:
a * (b + c) = (a * b) + (a * c)
- Right distributivity:
(a + b) * c = (a * c) + (b * c)
- Left distributivity:
Implementations:
Implementations of the Ring
interface should ensure that instances are immutable. This means
that all operations should return new instances rather than modifying existing ones. Immutability guarantees
thread safety and consistent behavior across different contexts.
The Semiring.compareTo(Semiring)
method should implement some ordering (total or partial) on the semiring.
Further, implementations should ensure that the equality and hash code methods are consistent with the semiring's equality definition.
Interface Methods:
The Ring
interface specifies the following methods that ring elements must implement:
Semiring.add(Semiring)
: Performs the addition operation, returning a new ring element.Semiring.mult(Semiring)
: Performs the multiplication operation, returning a new ring element.sub(Ring)
: Performs the subtraction operation, defined as addition with the additive inverse.addInv()
: Returns the additive inverse of this element.Semiring.isZero()
: Checks if the element is the additive identity (zero element).Semiring.isOne()
: Checks if the element is the multiplicative identity (one element), if it exists.Semiring.getZero()
: Returns the additive identity element of the ring.Semiring.getOne()
: Returns the multiplicative identity element of the ring, if it exists.
Usage Example:
// Assume T is a concrete implementation of Ring<T>
T a = ...; // Initialize element a
T b = ...; // Initialize element b
T sum = a.add(b); // Perform addition in the ring
T difference = a.sub(b); // Perform subtraction in the ring
T product = a.mult(b); // Perform multiplication in the ring
T negation = a.addInv(); // Get the additive inverse of a
boolean isZero = a.isZero(); // Check if a is the additive identity
boolean isOne = b.isOne(); // Check if b is the multiplicative identity
Examples of Rings:
- Integers (ℤ): The set of integers with usual addition and multiplication forms a ring.
- Polynomials: Polynomials with coefficients in a field form a ring under polynomial addition and multiplication.
- Matrix Rings: Square matrices of a given size over a ring form a ring under matrix addition and multiplication.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault double
abs()
Computes the absolute value of this ring element.addInv()
Computes the additive inverse for an element of this ring.default T
conj()
Computes the conjugation of this ring's element.default double
mag()
Computes the magnitude of this ring element.Computes difference of two elements of this ring.
-
Method Details
-
sub
-
addInv
T addInv()Computes the additive inverse for an element of this ring.
An element -x is an additive inverse for a field element x if -x + x = 0 where 0 is the additive identity.
- Returns:
- The additive inverse for this ring element.
-
abs
default double abs()Computes the absolute value of this ring element.
- Returns:
- The absolute value of this ring element.
-
mag
default double mag()Computes the magnitude of this ring element.- Returns:
- The magnitude of this ring element.
-
conj
Computes the conjugation of this ring's element.- Returns:
- The conjugation of this ring's element.
-