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

public interface Ring<T extends Ring<T>> extends Semiring<T>
Defines a mathematical ring structure and specifies the operations that ring elements must support.

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 that a + 0 = a
  • Existence of additive inverses: For every a in R, there exists an element -a in R such that a + (-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)

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 Type
    Method
    Description
    default double
    abs()
    Computes the absolute value of this ring element.
    Computes the additive inverse for an element of this ring.
    default T
    Computes the conjugation of this ring's element.
    default double
    mag()
    Computes the magnitude of this ring element.
    sub(T b)
    Computes difference of two elements of this ring.

    Methods inherited from interface org.flag4j.algebraic_structures.Semiring

    add, compareTo, doubleValue, getOne, getZero, isOne, isZero, mult
  • Method Details

    • sub

      T sub(T b)
      Computes difference of two elements of this ring.
      Parameters:
      b - Second ring element in difference.
      Returns:
      The difference of this ring element and b.
    • 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

      default T conj()
      Computes the conjugation of this ring's element.
      Returns:
      The conjugation of this ring's element.