ComplexPolar

com.phasmidsoftware.number.core.numerical.ComplexPolar
See theComplexPolar companion object
case class ComplexPolar(r: Number, theta: Number, n: Int = ...) extends BaseComplex

Class to represent a family of Complex numbers in polar form. An instance of this class actually represents n different complex numbers.

Value parameters

n

the number of "branches" in this set of complex numbers.

r

the real part (the magnitude) of the number(s).

theta

the imaginary part (the angle) of the 0th branch of the number.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class BaseComplex
trait Complex
trait Multivariate
trait Field
trait Ordered[Field]
trait Comparable[Field]
trait Numerical
trait NumberLike
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def abs: Numerical

Computes the absolute value (magnitude) of this ComplexPolar instance. The calculation is performed using the Cartesian representation of the complex number. NOTE very arbitrary.

Computes the absolute value (magnitude) of this ComplexPolar instance. The calculation is performed using the Cartesian representation of the complex number. NOTE very arbitrary.

Attributes

Returns

the absolute value as a Numerical.

def asReal: Option[Real]

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Attributes

Returns

an Option[Real].

def doAdd(complex: Complex): Complex

Adds this ComplexPolar instance to another Complex. The operation is performed by converting this ComplexPolar instance to its Cartesian representation and then delegating to the doAdd method of the Cartesian representation.

Adds this ComplexPolar instance to another Complex. The operation is performed by converting this ComplexPolar instance to its Cartesian representation and then delegating to the doAdd method of the Cartesian representation.

Value parameters

complex

the other Complex to be added.

Attributes

Returns

the result of adding this ComplexPolar to the given Complex.

def doMultiply(complex: Complex): Complex

Multiplies this ComplexPolar instance with another Complex. If the input is of type ComplexPolar, the multiplication is performed in polar form using the magnitude and phase (angle).

Multiplies this ComplexPolar instance with another Complex. If the input is of type ComplexPolar, the multiplication is performed in polar form using the magnitude and phase (angle).

Value parameters

complex

the other Complex to multiply with.

Attributes

Returns

the product as a Complex.

Note

Throws ComplexException if the given Complex is not a ComplexPolar instance.

def isProbablyZero(confidence: Double): Boolean

Determines if this ComplexPolar instance is equivalent to zero with at least the given level of confidence.

Determines if this ComplexPolar instance is equivalent to zero with at least the given level of confidence.

Value parameters

confidence

the confidence level desired, typically between 0 and 1. Ignored if the instance is already considered zero.

Attributes

Returns

true if the instance is equivalent to zero with at least the specified confidence level; false otherwise.

def isReal: Boolean

Method to determine if this Complex is real-valued (i.e. the point lies on the real axis). TODO fix this properly. We can only really answer this question knowing with branch we're talking about.

Method to determine if this Complex is real-valued (i.e. the point lies on the real axis). TODO fix this properly. We can only really answer this question knowing with branch we're talking about.

Attributes

Returns

true if the angle theta is a multiple of pi.

def make(a: Number, b: Number): BaseComplex

Constructs a new ComplexPolar instance using the given parameters.

Constructs a new ComplexPolar instance using the given parameters.

Value parameters

a

the first parameter, generally representing the modulus (magnitude) of the complex number

b

the second parameter, generally representing the argument (angle) of the complex number in radians

Attributes

Returns

a BaseComplex instance, represented as a ComplexPolar

Multiplies this ComplexPolar instance with a given Number and returns the result as a Complex. If the given Number is imaginary, the operation involves converting this ComplexPolar to its Cartesian form and applying a rotation. Otherwise, the product is computed in polar form using the magnitude and angle.

Multiplies this ComplexPolar instance with a given Number and returns the result as a Complex. If the given Number is imaginary, the operation involves converting this ComplexPolar to its Cartesian form and applying a rotation. Otherwise, the product is computed in polar form using the magnitude and angle.

Value parameters

n

the Number to multiply with. This can be a real or imaginary number.

Attributes

Returns

the product as a Complex.

Rotate this Complex number by phi counter-clockwise.

Rotate this Complex number by phi counter-clockwise.

Attributes

Returns

the value of this, rotated by phi.

def signum: Int

Determine the "sign" of this field. For a real-valued quantity (Real or Number), we try to determine if it is to the right, left or at the origin. For a complex number, we get the signum of the real part.

Determine the "sign" of this field. For a real-valued quantity (Real or Number), we try to determine if it is to the right, left or at the origin. For a complex number, we get the signum of the real part.

Attributes

Returns

+1 if to the right of the origin, -1 if to the left, 0 if at the origin.

def unary_-: Field

Change the sign of this Number.

Change the sign of this Number.

Attributes

Inherited methods

infix def *(x: Field): Field

Multiply this Field by the given Field and return the result.

Multiply this Field by the given Field and return the result.

Value parameters

x

the multiplicand, an instance of Field.

Attributes

Returns

the product of this Field and the given Field.

Inherited from:
Field
infix def +(x: Field): Field

Synonym for add.

Synonym for add.

Value parameters

x

the addend.

Attributes

Returns

the result.

Inherited from:
Field
infix def -(x: Field): Field

Synonym for subtract.

Synonym for subtract.

Value parameters

x

the subtrahend.

Attributes

Returns

this - x.

Inherited from:
Field
def <(that: Field): Boolean

Returns true if this is less than that

Returns true if this is less than that

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def <=(that: Field): Boolean

Returns true if this is less than or equal to that.

Returns true if this is less than or equal to that.

Attributes

Inherited from:
Ordered
def >(that: Field): Boolean

Returns true if this is greater than that.

Returns true if this is greater than that.

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def >=(that: Field): Boolean

Returns true if this is greater than or equal to that.

Returns true if this is greater than or equal to that.

Attributes

Inherited from:
Ordered
def add(x: Field): Field

Add x to this Complex and return the result.

Add x to this Complex and return the result.

Value parameters

x

the addend.

Attributes

Returns

the sum.

Inherited from:
BaseComplex
def approximation: Option[Real]

Computes an approximation of the field as a real number, if possible. This method attempts to map the underlying numerical representation to a real value.

Computes an approximation of the field as a real number, if possible. This method attempts to map the underlying numerical representation to a real value.

Attributes

Returns

an Option containing the Real representation of this field if it can be approximated, or None if the approximation is not possible.

Inherited from:
Field
def asJavaNumber: Option[Number]

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

The method determines whether the current NumberLike object can be represented as a java.lang.Number by leveraging the asNumber method and further evaluating certain conditions:

  • If the NumberLike object is an ExactNumber and its factor is PureNumber, the result is converted using Value.asJavaNumber.
  • If the NumberLike object is a FuzzyNumber with a wiggle value below a specified tolerance, the result is also converted using Value.asJavaNumber.
  • In all other cases, None is returned.

Attributes

Returns

an optional java.lang.Number representation of this object. The result is Some(java.lang.Number) if the conversion is successful under the stated conditions; otherwise, None.

Inherited from:
NumberLike
def atan(y: Real): Field

Computes the arc tangent of the given real number y in the context of this Field. This implements atan2(y, x) where this represents the x coordinate.

Computes the arc tangent of the given real number y in the context of this Field. This implements atan2(y, x) where this represents the x coordinate.

Value parameters

y

the real number representing the y coordinate.

Attributes

Returns

a Field representing the arc tangent atan2(y, x).

Inherited from:
BaseComplex
def compare(that: Field): Int

Method to compare this BaseComplex with that Field. Required by implementing Ordered[Field]. NOTE if the difference is a Complex number, we try to do fuzzy comparison (with confidence of 0.5).

Method to compare this BaseComplex with that Field. Required by implementing Ordered[Field]. NOTE if the difference is a Complex number, we try to do fuzzy comparison (with confidence of 0.5).

TODO Complex should not implement compare (that's to say Field should not extend Ordering).

Value parameters

that

(a Field).

Attributes

Returns

the comparison.

Inherited from:
BaseComplex
def compareTo(that: Field): Int

Result of comparing this with operand that.

Result of comparing this with operand that.

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def divide(x: Field): Field

Divide this Complex by x and return the result. See * and invert for more detail.

Divide this Complex by x and return the result. See * and invert for more detail.

Value parameters

x

the divisor.

Attributes

Returns

the quotient.

Inherited from:
BaseComplex
def isSame(x: Numerical, confidence: Double = ...): Boolean

Method to determine if this Field is equivalent to another Field (x).

Method to determine if this Field is equivalent to another Field (x).

Value parameters

x

the other field.

Attributes

Returns

true if they are the same, otherwise false.

Inherited from:
BaseComplex
def maybeFactor: Option[Factor]

Method to determine what Factor, if there is such, this NumberLike object is based on.

Method to determine what Factor, if there is such, this NumberLike object is based on.

TODO it's more complicated than this! CONSIDER having a Complex sub-type of Factor.

Attributes

Returns

an optional Factor.

Inherited from:
Complex
def memberOf(set: NumberSet): Boolean

Method to determine if this NumberLike object is a member of the given set.

Method to determine if this NumberLike object is a member of the given set.

Value parameters

set

the candidate NumberSet.

Attributes

Returns

true if this is exact and belongs to set.

Inherited from:
NumberLike
def memberOf: Option[NumberSet]

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Attributes

Returns

Some(numberSet) or None if it doesn't belong to any (for example, it is fuzzy).

Inherited from:
NumberLike
def multiply(x: Field): Field

Multiply this Complex by x and return the result.

Multiply this Complex by x and return the result.

  • @param x the multiplicand.
  • @return the product.

Attributes

Inherited from:
BaseComplex
def power(p: Field): Field

Raise this Complex to the power p.

Raise this Complex to the power p.

Value parameters

p

a Number.

Attributes

Returns

this Number raised to power p.

Inherited from:
BaseComplex
def power(n: Number): Complex

Computes the result of raising this number (field element) to the given power n.

Computes the result of raising this number (field element) to the given power n.

Value parameters

n

The exponent as a Number to which this field element will be raised. Can represent integer, rational, or other numerical values.

Attributes

Returns

A new Field instance that is the result of performing the power operation.

Inherited from:
BaseComplex
infix def power(p: Int): Field

Raise this Field to the power p.

Raise this Field to the power p.

Value parameters

p

an Int.

Attributes

Returns

this Field raised to power p.

Inherited from:
Field
def product(multiplicand: Complex): Complex

Method to multiply this by the given parameter (a Polar).

Method to multiply this by the given parameter (a Polar).

Value parameters

multiplicand

the complex multiplicand.

Attributes

Returns

the product of this and multiplicand.

Inherited from:
BaseComplex
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
def show: String

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Attributes

Returns

a String

Inherited from:
NumberLike
infix def subtract(x: Field): Field

Subtract x from this Field and return the result.

Subtract x from this Field and return the result.

Value parameters

x

the subtrahend.

Attributes

Returns

the difference of this - x.

Inherited from:
Field
def sum(addend: Complex): Complex

Method to add this to the given parameter (a Cartesian).

Method to add this to the given parameter (a Cartesian).

Value parameters

addend

the complex addend.

Attributes

Returns

the sum of this and addend.

Inherited from:
BaseComplex
def toRational: Option[Rational]

Converts this Field instance to its equivalent rational representation if it is real-valued.

Converts this Field instance to its equivalent rational representation if it is real-valued.

Attributes

Returns

an Option containing the rational representation of this Field if it is real-valued; otherwise, None.

Inherited from:
Field

Concrete fields

lazy val argument: Number

Attributes

Returns

a Number (in radians).

lazy val invert: Field

Yields the inverse of this Complex.

Yields the inverse of this Complex.

Attributes

Returns

the result of invoking power(-1).

lazy val isExact: Boolean

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Attributes

Returns

true if this NumberLike object is exact in a factor-less context, else false.

lazy val isImaginary: Boolean

Method to determine if this Complex is imaginary-valued (i.e., the point lies on the imaginary axis).

Method to determine if this Complex is imaginary-valued (i.e., the point lies on the imaginary axis).

Attributes

Returns

true if the real part is zero (argument is a multiple of pi/2).

val isInfinite: Boolean

Determines if the magnitude of this Complex field is infinite.

Determines if the magnitude of this Complex field is infinite.

Attributes

Returns

true if the magnitude of this Complex field is infinite, otherwise false.

val isZero: Boolean

Method to determine if this ComplexPolar is zero.

Method to determine if this ComplexPolar is zero.

Attributes

Returns

true if the magnitude of this Field is zero.

lazy val ln: Field

Computes the natural logarithm of this Field. For a real number x, this is equivalent to the logarithm base e: ln(x). For a complex number, this computes the multivalued complex logarithm.

Computes the natural logarithm of this Field. For a real number x, this is equivalent to the logarithm base e: ln(x). For a complex number, this computes the multivalued complex logarithm.

Attributes

Returns

the natural logarithm of this Field as a Field.

lazy val modulus: Number

Method to determine the modulus of this Complex number.

Method to determine the modulus of this Complex number.

Attributes

Returns

the modulus of this Complex.

Computes the square of the modulus (magnitude) of this ComplexPolar instance.

Computes the square of the modulus (magnitude) of this ComplexPolar instance.

Attributes

Returns

the squared modulus as a Number.

lazy val normalize: Field

Normalize a ComplexField based on specific rules of theta modulation and context.

Normalize a ComplexField based on specific rules of theta modulation and context.

  • If theta is 0 and n is 1, return the real part of r.
  • If theta is 1 (normalized as Radian) and n is 1, return the negation of the real part of r.
  • Otherwise, return a ComplexPolar representation of the field.

Attributes

Returns

a Field that represents the normalized form of the Instance.

lazy val render: String

Action to simplifyAndEvaluate this ComplexPolar and render it as a String, that is to say we eagerly evaluate this ComplexPolar as a String.

Action to simplifyAndEvaluate this ComplexPolar and render it as a String, that is to say we eagerly evaluate this ComplexPolar as a String.

NOTE that some of these special cases that are handled here should be eliminated by a prior call to normalize.

Attributes

Returns

a String representing the value of this object.

lazy val rotate: ComplexPolar

Rotate this Complex number by pi/2 counter-clockwise (i.e., multiply by i).

Rotate this Complex number by pi/2 counter-clockwise (i.e., multiply by i).

Attributes

Returns

the value of this * i.

lazy val square: Field

Computes the square of this ComplexPolar instance by doubling its argument (angle). The operation preserves the modulus while doubling the angle in polar representation.

Computes the square of this ComplexPolar instance by doubling its argument (angle). The operation preserves the modulus while doubling the angle in polar representation.

Attributes

Returns

a new Field representing the squared value of the ComplexPolar instance.

Inherited fields

Attributes

Inherited from:
Complex
lazy val asComplex: Complex

Method to return this Field as a Complex. If this is a Real number x, return ComplexPolar(x) otherwise, return this.

Method to return this Field as a Complex. If this is a Real number x, return ComplexPolar(x) otherwise, return this.

Attributes

Returns

a Complex.

Inherited from:
BaseComplex
lazy val asNumber: Option[Number]

Method to determine if this Field is actually a real (or imaginary) Number (i.e. not complex). NOTE: to force this as a Number, use convertToNumber in the companion Object.

Method to determine if this Field is actually a real (or imaginary) Number (i.e. not complex). NOTE: to force this as a Number, use convertToNumber in the companion Object.

Attributes

Returns

a Some(x) if this is a Number; otherwise return None.

Inherited from:
BaseComplex
lazy val conjugate: Complex

Method to determine the conjugate of this Complex number.

Method to determine the conjugate of this Complex number.

Attributes

Returns

the conjugate of this Complex.

Inherited from:
BaseComplex
lazy val cos: Field

Computes the cosine of this field element, interpreted in the context of a complex number. The cosine operation is defined mathematically and extended to work with complex values, leveraging the properties of exponential functions in the complex plane.

Computes the cosine of this field element, interpreted in the context of a complex number. The cosine operation is defined mathematically and extended to work with complex values, leveraging the properties of exponential functions in the complex plane.

Attributes

Returns

a Field representing the cosine of this field element.

Inherited from:
BaseComplex
lazy val cosh: Field

Computes the hyperbolic cosine (cosh) of this complex number.

Computes the hyperbolic cosine (cosh) of this complex number.

For a complex number expressed in Cartesian form (x + iy), the result is calculated using the formula: cosh(x + iy) = cosh(x)cos(y) + i·sinh(x)sin(y).

If the complex number is represented in polar form, it gets converted to Cartesian form, and the cosh is computed on the Cartesian representation.

Attributes

Returns

The hyperbolic cosine of this complex number as a Field.

Inherited from:
BaseComplex
lazy val exp: Field

Computes the exponential of this complex number.

Computes the exponential of this complex number.

Attributes

Returns

the exponential of this Field as a new Field instance.

Inherited from:
BaseComplex
val imag: Number

Attributes

Inherited from:
BaseComplex
lazy val isAlgebraic: Boolean

Attributes

Returns

true.

Inherited from:
Multivariate
lazy val isComplex: Boolean

Attributes

Returns

true.

Inherited from:
Complex
lazy val isUnity: Boolean

Determines if this complex number has a modulus of unity (magnitude of one). This is true if the modulus of the complex number, when subtracted by one, equals zero.

Determines if this complex number has a modulus of unity (magnitude of one). This is true if the modulus of the complex number, when subtracted by one, equals zero.

Attributes

Returns

true if the modulus of this complex number is unity (1), otherwise false.

Inherited from:
BaseComplex
val real: Number

Attributes

Inherited from:
BaseComplex
lazy val sin: Field

Computes the sine of this complex number. The result is calculated in the context of complex numbers, applying the necessary formulas for the sine function on complex inputs.

Computes the sine of this complex number. The result is calculated in the context of complex numbers, applying the necessary formulas for the sine function on complex inputs.

Attributes

Returns

the sine of this complex number as an instance of Field.

Inherited from:
BaseComplex
lazy val sinh: Field

Computes the hyperbolic sine (sinh) of this Complex number.

Computes the hyperbolic sine (sinh) of this Complex number.

This method is defined for both Cartesian and Polar representations of complex numbers:

  • For a complex number in Cartesian form (x + i·y), the formula used is: sinh(x + i·y) = sinh(x)·cos(y) + i·cosh(x)·sin(y)

  • For a complex number in Polar form, it is first converted to Cartesian form and the computation is then performed using the Cartesian formula.

Attributes

Returns

A new ComplexCartesian instance representing the hyperbolic sine of this Complex number.

Inherited from:
BaseComplex
lazy val tan: Field

Computes the tangent of this complex number.

Computes the tangent of this complex number.

Attributes

Returns

The tangent of this complex number as a Field.

Inherited from:
BaseComplex
lazy val tanh: Field

Represents the hyperbolic tangent (tanh) function as a field element.

Represents the hyperbolic tangent (tanh) function as a field element.

Computed as the division of the hyperbolic sine (sinh) and the hyperbolic cosine (cosh).

This lazy value ensures the computation is deferred until the tanh field is accessed, improving efficiency in cases where it is not immediately required.

Attributes

Inherited from:
BaseComplex