Interface Field<T extends Field<T>>

Type Parameters:
T - the type of the field element, which should extend Field<T> to ensure type consistency.
All Superinterfaces:
Comparable<T>, Ring<T>, Semiring<T>, Serializable
All Known Implementing Classes:
Complex128, Complex64, RealFloat32, RealFloat64

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

A field is an algebraic structure consisting of a set F equipped with two binary operations: addition (+) and multiplication (*). Fields generalize the familiar arithmetic of rational numbers, real numbers, and complex numbers. In a field, both addition and multiplication are commutative, and every non-zero element has a multiplicative inverse, allowing for division operations.

Formal Definition:

For all elements , b, and c in F, 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 F such that a + 0 = a
  • Existence of additive inverses: For every a in F, there exists an element -a in F such that a + (-a) = 0
  • Multiplication is associative: a * (b * c) = (a * b) * c
  • Multiplication is commutative: a * b = b * a
  • Multiplicative identity exists: There exists an element 1 ≠ 0 in F such that a * 1 = a
  • Existence of multiplicative inverses: For every a ≠ 0 in F, there exists an element a-1 in F such that a * a-1 = 1
  • Distributivity of multiplication over addition:
    • Left distributivity: a * (b + c) = (a * b) + (a * c)
    • Right distributivity: (a + b) * c = (a * c) + (b * c)
Extended Operations:

Implementations:

Implementations of the Field 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.

While the interface defines the core operations of a mathematical field, it also specifies additional methods that are common and useful in numerical computations, such as arithmetic with real numbers (double values), and the computation of square roots. These methods are included to facilitate working with numerical fields like the real numbers or complex numbers. There implementation is optional and default methods are provided which throw a UnsupportedOperationException.

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 Field interface extends the Ring interface and specifies additional methods that field elements must implement:

  • Semiring.add(Semiring): Performs the addition operation, returning a new field element.
  • Ring.sub(Ring): Performs the subtraction operation, defined as addition with the additive inverse.
  • Semiring.mult(Semiring): Performs the multiplication operation, returning a new field element.
  • div(Field): Performs the division operation, defined using the multiplicative inverse.
  • Ring.addInv(): Returns the additive inverse of this element.
  • multInv(): Returns the multiplicative 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).
  • Semiring.getZero(): Returns the additive identity element of the field.
  • Semiring.getOne(): Returns the multiplicative identity element of the field.

Usage Example:


 // Assume T is a concrete implementation of Field<T>
 T a = ...; // Initialize element a
 T b = ...; // Initialize element b

 T sum = a.add(b);         // Perform addition in the field
 T difference = a.sub(b);  // Perform subtraction in the field
 T product = a.mult(b);    // Perform multiplication in the field
 T quotient = a.div(b);    // Perform division in the field
 T negation = a.addInv();  // Get the additive inverse of a
 T reciprocal = a.multInv(); // Get the multiplicative 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 Fields:

  • Rational Numbers (ℚ): Fractions of integers where addition, subtraction, multiplication, and division are defined.
  • Real Numbers (ℝ): All continuous numbers along the number line, including irrational numbers.
  • Complex Numbers (ℂ): Numbers of the form a + bi, where i is the imaginary unit.
  • Finite Fields (𝔽p): Fields with a finite number of elements, such as integers modulo a prime number p.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    add(double b)
    Sums an element of this field with a real number (associative and commutative).
    default T
    div(double b)
    Computes the quotient of an element of this field and a real number.
    div(T b)
    Computes the quotient of two elements of this field.
    boolean
    Checks if this field element is finite in magnitude.
    boolean
    Checks if this field element is infinite in magnitude.
    boolean
    Checks if this field element is NaN in magnitude.
    default T
    mult(double b)
    Multiplies an element of this field with a real number (associative and commutative).
    Computes the multiplicative inverse for an element of this field.
    default T
    Computes the square root of this field element.
    default T
    sub(double b)
    Computes difference of an element of this field and a real number.

    Methods inherited from interface org.flag4j.algebraic_structures.Ring

    abs, addInv, conj, mag, sub

    Methods inherited from interface org.flag4j.algebraic_structures.Semiring

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

    • div

      T div(T b)
      Computes the quotient of two elements of this field.
      Parameters:
      b - Second field element in quotient.
      Returns:
      The quotient of this field element and b.
    • add

      default T add(double b)
      Sums an element of this field with a real number (associative and commutative).
      Parameters:
      b - Real element in sum.
      Returns:
      The sum of this element and b.
    • sub

      default T sub(double b)
      Computes difference of an element of this field and a real number.
      Parameters:
      b - Real value in difference.
      Returns:
      The difference of this ring element and b.
    • mult

      default T mult(double b)
      Multiplies an element of this field with a real number (associative and commutative).
      Parameters:
      b - Real number in product.
      Returns:
      The product of this field element and b.
    • div

      default T div(double b)
      Computes the quotient of an element of this field and a real number.
      Parameters:
      b - Real number in quotient.
      Returns:
      The quotient of this field element and b.
    • multInv

      T multInv()

      Computes the multiplicative inverse for an element of this field.

      An element x-1 is a multiplicative inverse for a filed element x if x-1*x = 1 where 1 is the multiplicative identity.

      Returns:
      The multiplicative inverse for this field element.
    • sqrt

      default T sqrt()
      Computes the square root of this field element.
      Returns:
      The square root of this field element.
    • isFinite

      boolean isFinite()
      Checks if this field element is finite in magnitude.
      Returns:
      True if this field element is finite in magnitude. False otherwise (i.e. infinite, NaN etc.).
    • isInfinite

      boolean isInfinite()
      Checks if this field element is infinite in magnitude.
      Returns:
      True if this field element is infinite in magnitude. False otherwise (i.e. finite, NaN, etc.).
    • isNaN

      boolean isNaN()
      Checks if this field element is NaN in magnitude.
      Returns:
      True if this field element is NaN in magnitude. False otherwise (i.e. finite, NaN, etc.).