Class Real

java.lang.Object
java.lang.Number
org.episteme.core.mathematics.numbers.real.Real
All Implemented Interfaces:
Serializable, Comparable<Real>, AbelianGroup<Real>, AbelianMonoid<Real>, Group<Real>, Magma<Real>, Monoid<Real>, Field<Real>, FieldElement<Real>, Ring<Real>, RingElement<Real>, Semiring<Real>, Set<Real>
Direct Known Subclasses:
NativeRealBig, RealBig, RealDouble, RealFloat

public abstract class Real extends Number implements Comparable<Real>, Field<Real>, FieldElement<Real>
Abstract base class for real numbers (ℝ).

Real numbers form a Field under addition and multiplication. This class provides a smart factory that chooses the backing implementation

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
    static final Real
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Real
    abs()
     
    abstract Real
    Returns the arccosine of this number.
    abstract Real
    Returns the inverse hyperbolic cosine of this number.
    abstract Real
    add(Real other)
    Returns the sum of this element and another.
    add(Real left, Real right)
    Returns the sum of two elements (additive notation).
    abstract Real
    Returns the arcsine of this number.
    abstract Real
    Returns the inverse hyperbolic sine of this number.
    abstract Real
    Returns the arctangent of this number.
    abstract Real
    Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
    abstract Real
    Returns the inverse hyperbolic tangent of this number.
    abstract BigDecimal
     
    abstract Real
    Returns the cube root of this number.
    abstract Real
    Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
    int
    Returns the characteristic of this field.
    abstract int
    compareTo(Real other)
     
    boolean
    contains(Real element)
    Tests whether this set contains the specified element.
    abstract Real
    cos()
    Returns the cosine of this number (in radians).
    abstract Real
    Returns the hyperbolic cosine of this number.
    Returns a human-readable description of this set.
    abstract Real
    divide(Real other)
    Returns this element divided by another.
    abstract double
     
    static Real
    eE()
    The real number E
    abstract boolean
     
    abstract Real
    exp()
    Returns e raised to this number.
    float
     
    abstract Real
    Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
    Returns the ring structure for real numbers.
    static Real
    π/2 - quarter turn in radians
    abstract int
     
    abstract Real
    Returns sqrt(x^2 + y^2) without intermediate overflow or underflow.
    int
     
    abstract Real
    Returns the multiplicative inverse of this element.
    inverse(Real element)
    Returns the multiplicative inverse of a non-zero element.
    boolean
    Returns true if this set contains no elements.
    boolean
     
    boolean
     
    abstract boolean
     
    boolean
    Fields always have commutative multiplication.
    abstract boolean
     
    boolean
     
    abstract boolean
    Checks if this element is the multiplicative identity (one).
    boolean
     
    abstract boolean
    Checks if this element is the additive identity (zero).
    static Real
    Natural logarithm of 10
    static Real
    Natural logarithm of 2
    abstract Real
    log()
    Returns the natural logarithm of this number.
    abstract Real
    Returns the base-10 logarithm of this number.
    long
     
    max(Real other)
    Returns the maximum of this and another number.
    min(Real other)
    Returns the minimum of this and another number.
    mod(Real other)
    Returns the modulo of this number (always non-negative).
    abstract Real
    multiply(Real other)
    Returns the product of this element and another.
    multiply(Real left, Real right)
    Returns the product of two elements.
    static Real
    The real number NaN
    abstract Real
    Returns the additive inverse of this element.
    negate(Real element)
    Returns the additive inverse (negation) of an element.
    static Real
    Negative infinity
    static Real
    of(double value)
    Creates a real number from a double value.
    static Real
    of(float value)
    Creates a real number from a float value.
    static Real
    of(int value)
    Creates a real number from an int value.
    static Real
    of(long value)
    Creates a real number from a long value.
    static Real
    of(String value)
    Creates a real number from a String representation.
    static Real
    of(BigDecimal value)
    Creates a real number from a BigDecimal value.
    one()
    Returns the multiplicative identity (one element).
    static Real
    The real number 1
    operate(Real left, Real right)
    Performs the binary operation on two elements.
    static Real
    piE()
    The real number PI
    static Real
    Positive infinity
    abstract Real
    pow(double exponent)
    Returns this number raised to a power.
    abstract Real
    pow(int exp)
     
    abstract Real
    pow(Real exp)
     
    remainder(Real other)
    Returns the remainder of this number divided by another.
    static Ring<Real>
     
    abstract Real
    Returns the closest long to the argument, with ties rounding to positive infinity.
    int
    Returns the sign of this number (-1, 0, or 1).
    abstract Real
    sin()
    Returns the sine of this number (in radians).
    abstract Real
    Returns the hyperbolic sine of this number.
    abstract Real
     
    abstract Real
    subtract(Real other)
    Returns the difference of this element and another.
    abstract Real
    tan()
    Returns the tangent of this number (in radians).
    abstract Real
    Returns the hyperbolic tangent of this number.
    Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
    Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
    abstract String
     
    static Real
    The real number 2
    static Real
    2Ï€ - commonly used in angular calculations
    static Real
    valueOf(String value)
     
    Returns the additive identity (zero element).
    static Real
    The real number 0

    Methods inherited from class Number

    byteValue, shortValue

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface AbelianGroup

    isCommutative, subtract

    Methods inherited from interface AbelianMonoid

    identity, isCommutative

    Methods inherited from interface Field

    divide, hasUnity

    Methods inherited from interface Monoid

    isAssociative

    Methods inherited from interface Semiring

    pow
  • Field Details

    • ZERO

      public static final Real ZERO
    • ONE

      public static final Real ONE
    • NaN

      public static final Real NaN
    • PI

      public static final Real PI
    • E

      public static final Real E
    • TWO

      public static final Real TWO
    • TWO_PI

      public static final Real TWO_PI
    • HALF_PI

      public static final Real HALF_PI
    • POSITIVE_INFINITY

      public static final Real POSITIVE_INFINITY
    • NEGATIVE_INFINITY

      public static final Real NEGATIVE_INFINITY
    • LN2

      public static final Real LN2
    • LN10

      public static final Real LN10
  • Constructor Details

    • Real

      protected Real()
  • Method Details

    • zero

      public Real zero()
      Description copied from interface: AbelianMonoid
      Returns the additive identity (zero element).

      Delegates to AbelianMonoid.identity().

      Specified by:
      zero in interface AbelianMonoid<Real>
      Specified by:
      zero in interface RingElement<Real>
      Returns:
      the zero element
    • one

      public Real one()
      Description copied from interface: Semiring
      Returns the multiplicative identity (one element).

      Satisfies: 1 × a = a × 1 = a for all elements a.

      Specified by:
      one in interface RingElement<Real>
      Specified by:
      one in interface Semiring<Real>
      Returns:
      the multiplicative identity
    • zeroE

      public static Real zeroE()
      The real number 0
    • oneE

      public static Real oneE()
      The real number 1
    • nanE

      public static Real nanE()
      The real number NaN
    • piE

      public static Real piE()
      The real number PI
    • eE

      public static Real eE()
      The real number E
    • twoE

      public static Real twoE()
      The real number 2
    • twoPiE

      public static Real twoPiE()
      2Ï€ - commonly used in angular calculations
    • halfPiE

      public static Real halfPiE()
      π/2 - quarter turn in radians
    • positiveInfinityE

      public static Real positiveInfinityE()
      Positive infinity
    • negativeInfinityE

      public static Real negativeInfinityE()
      Negative infinity
    • ln2E

      public static Real ln2E()
      Natural logarithm of 2
    • ln10E

      public static Real ln10E()
      Natural logarithm of 10
    • of

      public static Real of(double value)
      Creates a real number from a double value. Uses current MathContext to decide implementation.
      Parameters:
      value - the value
      Returns:
      the Real instance
    • of

      public static Real of(float value)
      Creates a real number from a float value. Uses current MathContext to decide implementation.
      Parameters:
      value - the value
      Returns:
      the Real instance
    • of

      public static Real of(BigDecimal value)
      Creates a real number from a BigDecimal value.
      Parameters:
      value - the value
      Returns:
      the Real instance
      Throws:
      IllegalArgumentException - if value is null
    • of

      public static Real of(String value)
      Creates a real number from a String representation.
      Parameters:
      value - the string value
      Returns:
      the Real instance
    • valueOf

      public static Real valueOf(String value)
    • of

      public static Real of(int value)
      Creates a real number from an int value.
      Parameters:
      value - the value
      Returns:
      the Real instance
    • of

      public static Real of(long value)
      Creates a real number from a long value.
      Parameters:
      value - the value
      Returns:
      the Real instance
    • add

      public abstract Real add(Real other)
      Description copied from interface: RingElement
      Returns the sum of this element and another.
      Specified by:
      add in interface RingElement<Real>
      Parameters:
      other - the element to add
      Returns:
      this + other
    • subtract

      public abstract Real subtract(Real other)
      Description copied from interface: RingElement
      Returns the difference of this element and another.

      Default implementation: this.add(other.negate())

      Specified by:
      subtract in interface RingElement<Real>
      Parameters:
      other - the element to subtract
      Returns:
      this - other
    • multiply

      public abstract Real multiply(Real other)
      Description copied from interface: RingElement
      Returns the product of this element and another.
      Specified by:
      multiply in interface RingElement<Real>
      Parameters:
      other - the element to multiply
      Returns:
      this * other
    • divide

      public abstract Real divide(Real other)
      Description copied from interface: FieldElement
      Returns this element divided by another.

      Default implementation: this.multiply(other.inverse())

      Specified by:
      divide in interface FieldElement<Real>
      Parameters:
      other - the divisor
      Returns:
      this / other
    • negate

      public abstract Real negate()
      Description copied from interface: RingElement
      Returns the additive inverse of this element.
      Specified by:
      negate in interface RingElement<Real>
      Returns:
      -this
    • abs

      public abstract Real abs()
    • inverse

      public abstract Real inverse()
      Description copied from interface: FieldElement
      Returns the multiplicative inverse of this element.

      For any non-zero element e: e.multiply(e.inverse()) = e.one()

      Specified by:
      inverse in interface FieldElement<Real>
      Returns:
      1/this
    • sqrt

      public abstract Real sqrt()
    • pow

      public abstract Real pow(int exp)
    • pow

      public abstract Real pow(Real exp)
    • isZero

      public abstract boolean isZero()
      Description copied from interface: RingElement
      Checks if this element is the additive identity (zero).
      Specified by:
      isZero in interface RingElement<Real>
      Returns:
      true if this equals zero()
    • isOne

      public abstract boolean isOne()
      Description copied from interface: RingElement
      Checks if this element is the multiplicative identity (one).
      Specified by:
      isOne in interface RingElement<Real>
      Returns:
      true if this equals one()
    • isNaN

      public abstract boolean isNaN()
    • isInfinite

      public abstract boolean isInfinite()
    • isFast

      public boolean isFast()
    • isHighPrecision

      public boolean isHighPrecision()
    • isPositive

      public boolean isPositive()
    • isNegative

      public boolean isNegative()
    • doubleValue

      public abstract double doubleValue()
      Specified by:
      doubleValue in class Number
    • bigDecimalValue

      public abstract BigDecimal bigDecimalValue()
    • equals

      public abstract boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public abstract String toString()
      Overrides:
      toString in class Object
    • compareTo

      public abstract int compareTo(Real other)
      Specified by:
      compareTo in interface Comparable<Real>
    • sign

      public int sign()
      Returns the sign of this number (-1, 0, or 1).
      Returns:
      -1 if negative, 0 if zero, 1 if positive
    • pow

      public abstract Real pow(double exponent)
      Returns this number raised to a power.
      Parameters:
      exponent - the exponent
      Returns:
      this^exponent
    • exp

      public abstract Real exp()
      Returns e raised to this number.
      Returns:
      e^this
    • log

      public abstract Real log()
      Returns the natural logarithm of this number.
      Returns:
      ln(this)
    • log10

      public abstract Real log10()
      Returns the base-10 logarithm of this number.
      Returns:
      log₁₀(this)
    • sin

      public abstract Real sin()
      Returns the sine of this number (in radians).
      Returns:
      sin(this)
    • cos

      public abstract Real cos()
      Returns the cosine of this number (in radians).
      Returns:
      cos(this)
    • tan

      public abstract Real tan()
      Returns the tangent of this number (in radians).
      Returns:
      tan(this)
    • asin

      public abstract Real asin()
      Returns the arcsine of this number.
      Returns:
      arcsin(this) in radians
    • acos

      public abstract Real acos()
      Returns the arccosine of this number.
      Returns:
      arccos(this) in radians
    • atan

      public abstract Real atan()
      Returns the arctangent of this number.
      Returns:
      arctan(this) in radians
    • atan2

      public abstract Real atan2(Real x)
      Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
      Parameters:
      x - the abscissa coordinate
      Returns:
      the theta component of the point (r, theta)
    • sinh

      public abstract Real sinh()
      Returns the hyperbolic sine of this number.
      Returns:
      sinh(this)
    • cosh

      public abstract Real cosh()
      Returns the hyperbolic cosine of this number.
      Returns:
      cosh(this)
    • tanh

      public abstract Real tanh()
      Returns the hyperbolic tangent of this number.
      Returns:
      tanh(this)
    • asinh

      public abstract Real asinh()
      Returns the inverse hyperbolic sine of this number.
      Returns:
      asinh(this)
    • acosh

      public abstract Real acosh()
      Returns the inverse hyperbolic cosine of this number.
      Returns:
      acosh(this)
    • atanh

      public abstract Real atanh()
      Returns the inverse hyperbolic tangent of this number.
      Returns:
      atanh(this)
    • cbrt

      public abstract Real cbrt()
      Returns the cube root of this number.
      Returns:
      cbrt(this)
    • hypot

      public abstract Real hypot(Real y)
      Returns sqrt(x^2 + y^2) without intermediate overflow or underflow.
      Parameters:
      y - the other value
      Returns:
      sqrt(this^2 + y^2)
    • ceil

      public abstract Real ceil()
      Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
      Returns:
      ceil(this)
    • floor

      public abstract Real floor()
      Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
      Returns:
      floor(this)
    • round

      public abstract Real round()
      Returns the closest long to the argument, with ties rounding to positive infinity.
      Returns:
      round(this)
    • toDegrees

      public Real toDegrees()
      Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
      Returns:
      this converted to degrees
    • toRadians

      public Real toRadians()
      Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
      Returns:
      this converted to radians
    • min

      public Real min(Real other)
      Returns the minimum of this and another number.
      Parameters:
      other - the other number
      Returns:
      min(this, other)
    • max

      public Real max(Real other)
      Returns the maximum of this and another number.
      Parameters:
      other - the other number
      Returns:
      max(this, other)
    • remainder

      public Real remainder(Real other)
      Returns the remainder of this number divided by another.
      Parameters:
      other - the divisor
      Returns:
      this % other
    • mod

      public Real mod(Real other)
      Returns the modulo of this number (always non-negative).
      Parameters:
      other - the divisor
      Returns:
      ((this % other) + other) % other
    • floatValue

      public float floatValue()
      Specified by:
      floatValue in class Number
    • intValue

      public int intValue()
      Specified by:
      intValue in class Number
    • longValue

      public long longValue()
      Specified by:
      longValue in class Number
    • characteristic

      public int characteristic()
      Description copied from interface: Field
      Returns the characteristic of this field.

      The characteristic is the smallest positive integer n such that:
      1 + 1 + ... + 1 (n times) = 0
      If no such n exists, the characteristic is 0.

      Examples:

      • char(ℚ) = char(ℝ) = char(â„‚) = 0
      • char(𝔽ₚ) = p (for prime p)

      Specified by:
      characteristic in interface Field<Real>
      Returns:
      the characteristic (0 for infinite fields, p for finite fields)
    • operate

      public Real operate(Real left, Real right)
      Description copied from interface: Magma
      Performs the binary operation on two elements.

      This is the fundamental operation of a magma. The result must be an element of this magma (closure property).

      Properties: None required (not necessarily associative or commutative)

      Specified by:
      operate in interface Magma<Real>
      Parameters:
      left - the first operand
      right - the second operand
      Returns:
      the result of a ∗ b
      See Also:
    • add

      public Real add(Real left, Real right)
      Description copied from interface: AbelianMonoid
      Returns the sum of two elements (additive notation).

      Delegates to Magma.operate(Object, Object).

      Specified by:
      add in interface AbelianMonoid<Real>
      Parameters:
      left - the first addend
      right - the second addend
      Returns:
      a + b
    • multiply

      public Real multiply(Real left, Real right)
      Description copied from interface: Semiring
      Returns the product of two elements.

      Multiplication must be associative and distribute over addition.

      Specified by:
      multiply in interface Semiring<Real>
      Parameters:
      left - the first factor
      right - the second factor
      Returns:
      a × b
    • isMultiplicationCommutative

      public boolean isMultiplicationCommutative()
      Description copied from interface: Field
      Fields always have commutative multiplication.
      Specified by:
      isMultiplicationCommutative in interface Field<Real>
      Specified by:
      isMultiplicationCommutative in interface Semiring<Real>
      Returns:
      always true
    • negate

      public Real negate(Real element)
      Description copied from interface: AbelianGroup
      Returns the additive inverse (negation) of an element.

      Satisfies: a + (-a) = (-a) + a = 0

      Specified by:
      negate in interface AbelianGroup<Real>
      Parameters:
      element - the element to negate
      Returns:
      -element
      See Also:
    • inverse

      public Real inverse(Real element)
      Description copied from interface: Field
      Returns the multiplicative inverse of a non-zero element.

      For element a ≠ 0, returns a⁻¹ such that: a × a⁻¹ = a⁻¹ × a = 1

      Examples:

      • In ℚ: inverse(2/3) = 3/2
      • In ℝ: inverse(5.0) = 0.2
      • In â„‚: inverse(3+4i) = (3-4i)/25

      Specified by:
      inverse in interface Field<Real>
      Specified by:
      inverse in interface Group<Real>
      Parameters:
      element - the element to invert (must be non-zero)
      Returns:
      the multiplicative inverse
      See Also:
    • contains

      public boolean contains(Real element)
      Description copied from interface: Set
      Tests whether this set contains the specified element.

      This is the fundamental operation of a set - membership testing.

      Specified by:
      contains in interface Set<Real>
      Parameters:
      element - the element to test for membership
      Returns:
      true if this set contains the element, false otherwise
      See Also:
    • description

      public String description()
      Description copied from interface: Set
      Returns a human-readable description of this set.

      Examples:

      • "ℝ (Real Numbers)"
      • "ℤ/12ℤ (Integers modulo 12)"
      • "{1, 2, 3, 4, 5}"

      Specified by:
      description in interface Set<Real>
      Returns:
      a description of this set
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Set
      Returns true if this set contains no elements.

      The empty set (∅) is a fundamental concept in set theory. It is the unique set containing no elements.

      Specified by:
      isEmpty in interface Set<Real>
      Returns:
      true if this set is empty
    • ring

      public static Ring<Real> ring()
    • getScalarRing

      public Ring<Real> getScalarRing()
      Returns the ring structure for real numbers.
      Returns:
      this instance (as it implements Field)