Class Complex

java.lang.Object
org.episteme.core.mathematics.numbers.complex.Complex
All Implemented Interfaces:
AbelianGroup<Complex>, AbelianMonoid<Complex>, Group<Complex>, Magma<Complex>, Monoid<Complex>, Field<Complex>, FieldElement<Complex>, Ring<Complex>, RingElement<Complex>, Semiring<Complex>, Set<Complex>

public final class Complex extends Object implements Field<Complex>, FieldElement<Complex>
Represents a complex number (â„‚), defined as a + bi where a, b are Real numbers.

Complex numbers form a Field under addition and multiplication.

* @author Silvere Martin-Michiellot
Since:
1.0
Author:
Gemini AI (Google DeepMind)
  • Field Details

    • ZERO

      public static final Complex ZERO
    • ONE

      public static final Complex ONE
    • I

      public static final Complex I
  • Method Details

    • of

      public static Complex of(Real real, Real imaginary)
    • of

      public static Complex of(Real real)
    • of

      public static Complex of(double real, double imaginary)
    • of

      public static Complex of(float real, float imaginary)
    • of

      public static Complex of(double real)
    • of

      public static Complex of(float real)
    • ofPolar

      public static Complex ofPolar(double magnitude, double phase)
    • valueOf

      public static Complex valueOf(String realStr, String imagStr)
    • valueOf

      public static Complex valueOf(String s)
    • getReal

      public Real getReal()
    • getImaginary

      public Real getImaginary()
    • isNaN

      public boolean isNaN()
    • real

      public double real()
      Returns the real part as a double.
      Returns:
      the real part
    • imaginary

      public double imaginary()
      Returns the imaginary part as a double.
      Returns:
      the imaginary part
    • operate

      public Complex operate(Complex a, Complex b)
      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<Complex>
      Parameters:
      a - the first operand
      b - the second operand
      Returns:
      the result of a ∗ b
      See Also:
    • add

      public Complex add(Complex a, Complex b)
      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<Complex>
      Parameters:
      a - the first addend
      b - the second addend
      Returns:
      a + b
    • add

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

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

      Delegates to AbelianMonoid.identity().

      Specified by:
      zero in interface AbelianMonoid<Complex>
      Specified by:
      zero in interface RingElement<Complex>
      Returns:
      the zero element
    • negate

      public Complex negate(Complex a)
      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<Complex>
      Parameters:
      a - the element to negate
      Returns:
      -element
      See Also:
    • negate

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

      public Complex subtract(Complex a, Complex b)
      Description copied from interface: AbelianGroup
      Returns the difference of two elements.

      Defined as: a - b = a + (-b)

      Specified by:
      subtract in interface AbelianGroup<Complex>
      Parameters:
      a - the minuend
      b - the subtrahend
      Returns:
      a - b
      See Also:
    • subtract

      public Complex subtract(Complex 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<Complex>
      Parameters:
      other - the element to subtract
      Returns:
      this - other
    • multiply

      public Complex multiply(Complex a, Complex b)
      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<Complex>
      Parameters:
      a - the first factor
      b - the second factor
      Returns:
      a × b
    • multiply

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

      public Complex 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<Complex>
      Specified by:
      one in interface Semiring<Complex>
      Returns:
      the multiplicative identity
    • isMultiplicationCommutative

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

      public Complex inverse(Complex a)
      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<Complex>
      Specified by:
      inverse in interface Group<Complex>
      Parameters:
      a - the element to invert (must be non-zero)
      Returns:
      the multiplicative inverse
      See Also:
    • inverse

      public Complex 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<Complex>
      Returns:
      1/this
    • reciprocal

      public Complex reciprocal()
      Alias for inverse() to satisfy certain matrix operation requirements.
      Returns:
      1/this
    • divide

      public Complex divide(Complex a, Complex b)
      Description copied from interface: Field
      Returns the quotient of two elements (division).

      Defined as: a ÷ b = a × b⁻¹

      Specified by:
      divide in interface Field<Complex>
      Parameters:
      a - the dividend (numerator)
      b - the divisor (denominator, must be non-zero)
      Returns:
      dividend ÷ divisor
      See Also:
    • divide

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

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

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

      public Complex conjugate()
    • abs

      public Real abs()
    • sqrt

      public Complex sqrt()
    • arg

      public Real arg()
    • exp

      public Complex exp()
      Returns e raised to this complex number. exp(a + bi) = e^a * (cos(b) + i*sin(b))
      Returns:
      e^this
    • log

      public Complex log()
      Returns the natural logarithm of this complex number. log(z) = ln(|z|) + i*arg(z)
      Returns:
      ln(this)
    • pow

      public Complex pow(Complex exponent)
      Returns this complex number raised to a complex power. z^w = exp(w * log(z))
      Parameters:
      exponent - the exponent
      Returns:
      this^exponent
    • pow

      public Complex pow(double exponent)
      Returns this complex number raised to a double power.
      Parameters:
      exponent - the exponent
      Returns:
      this^exponent
    • sin

      public Complex sin()
      Returns the sine of this complex number. sin(a + bi) = sin(a)cosh(b) + i*cos(a)sinh(b)
      Returns:
      sin(this)
    • cos

      public Complex cos()
      Returns the cosine of this complex number. cos(a + bi) = cos(a)cosh(b) - i*sin(a)sinh(b)
      Returns:
      cos(this)
    • tan

      public Complex tan()
      Returns the tangent of this complex number. tan(z) = sin(z) / cos(z)
      Returns:
      tan(this)
    • asin

      public Complex asin()
      Returns the arcsine of this complex number. asin(z) = -i * log(iz + sqrt(1 - z^2))
      Returns:
      asin(this)
    • acos

      public Complex acos()
      Returns the arccosine of this complex number. acos(z) = -i * log(z + i*sqrt(1 - z^2))
      Returns:
      acos(this)
    • atan

      public Complex atan()
      Returns the arctangent of this complex number. atan(z) = (i/2) * log((1-iz)/(1+iz))
      Returns:
      atan(this)
    • sinh

      public Complex sinh()
      Returns the hyperbolic sine of this complex number. sinh(z) = (exp(z) - exp(-z)) / 2
      Returns:
      sinh(this)
    • cosh

      public Complex cosh()
      Returns the hyperbolic cosine of this complex number. cosh(z) = (exp(z) + exp(-z)) / 2
      Returns:
      cosh(this)
    • tanh

      public Complex tanh()
      Returns the hyperbolic tangent of this complex number. tanh(z) = sinh(z) / cosh(z)
      Returns:
      tanh(this)
    • asinh

      public Complex asinh()
      Returns the inverse hyperbolic sine of this complex number. asinh(z) = log(z + sqrt(z^2 + 1))
      Returns:
      asinh(this)
    • acosh

      public Complex acosh()
      Returns the inverse hyperbolic cosine of this complex number. acosh(z) = log(z + sqrt(z^2 - 1))
      Returns:
      acosh(this)
    • atanh

      public Complex atanh()
      Returns the inverse hyperbolic tangent of this complex number. atanh(z) = 0.5 * log((1 + z) / (1 - z))
      Returns:
      atanh(this)
    • log10

      public Complex log10()
      Returns the base-10 logarithm of this complex number. log10(z) = log(z) / log(10)
      Returns:
      log10(this)
    • cbrt

      public Complex cbrt()
      Returns the cube root of this complex number. cbrt(z) = z^(1/3)
      Returns:
      cube root of this
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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<Complex>
      Returns:
      the characteristic (0 for infinite fields, p for finite fields)
    • contains

      public boolean contains(Complex 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<Complex>
      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<Complex>
      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<Complex>
      Returns:
      true if this set is empty
    • ring

      public static Ring<Complex> ring()
      Returns the ring structure for complex numbers.
      Returns:
      the singleton/context-aware field instance
    • getScalarRing

      public Ring<Complex> getScalarRing()