Complex

com.phasmidsoftware.number.algebra.eager.Complex
See theComplex companion object
case class Complex(complex: Complex)(maybeName: Option[String] = ...) extends Solution

This is a wrapper for a Complex number to demonstrate where it should appear in the type hierarchy (it should extend Solution).

Attributes

See also

com.phasmidsoftware.number.core.numerical.Complex

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Solution
trait Eager
trait DyadicOps
trait Approximate
trait Valuable
trait TypeSafe
trait Exactitude
trait Unitary
trait Zeroable
trait Numeric
trait Renderable
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def +(other: Solution): Solution

Adds another Solution instance to the current instance, combining their effects or values based on the implementation of the + operation in the Solution trait.

Adds another Solution instance to the current instance, combining their effects or values based on the implementation of the + operation in the Solution trait.

CONSIDER this should be defined in CanAdd[Solution] rather than Solution. Maybe we could achieve that by defining Can as a subtype of Eager, rather than of Structure.

Value parameters

other

the Solution instance to add to the current instance

Attributes

Returns

a new Solution instance representing the result of the addition

def approximation(force: Boolean): Option[Real]

Attempts to compute an approximate representation of the current value.

Attempts to compute an approximate representation of the current value.

This method provides an optional approximation of the value represented by the implementing class. The approximation may account for uncertainties or computational limitations. By default, this method does not force computation of the approximation unless explicitly requested.

Value parameters

force

a boolean flag indicating whether to force computation of the approximation. If true, the method will attempt to generate an approximation even if such computation is resource-intensive or not strictly necessary.

Attributes

Returns

an Option containing the approximate value as a Real if available, or None if no approximation can be computed.

Method to determine the argument (angle) of this Complex number.

Method to determine the argument (angle) of this Complex number.

Attributes

Returns

a Number (in radians).

def branches: Int

Returns the number of branches in this.

Returns the number of branches in this.

CONSIDER implement this more generally. For the roots of quadratic equations, the number of branches is 2, since there are two possible solutions. But for nth roots, we would need to support more branches.

branches corresponds to the number of possible solutions to some equation.

Attributes

Returns

the number of branches as an integer.

Computes and returns the conjugate of the current Solution instance.

Computes and returns the conjugate of the current Solution instance.

The conjugate represents a value or transformation that is mathematically paired oppositely with the current instance based on the structure and properties of the Solution implementation.

Normally, the branch of the conjugate, added to the current branch should equal branches.

Attributes

Returns

a new Solution instance representing the conjugate of the current instance

def doAdd(other: Complex): Complex

Method to add this Complex to another Complex.

Method to add this Complex to another Complex.

Value parameters

other

the other Complex.

Attributes

Returns

the sum of the Complexes.

def doMultiply(other: Complex): Complex

Method to multiply this Complex by another Complex.

Method to multiply this Complex by another Complex.

Value parameters

other

the other Complex.

Attributes

Returns

the product of the Complexes.

override def eqv(that: Eager): Try[Boolean]

Compares this Eager instance with another Eager instance for equality. This method is unimplemented and currently returns a failure with an AlgebraException.

Compares this Eager instance with another Eager instance for equality. This method is unimplemented and currently returns a failure with an AlgebraException.

Value parameters

that

the Eager instance to compare against

Attributes

Returns

a Try[Boolean] indicating whether the two instances are equal. As the method is unimplemented, it always returns a failure containing an AlgebraException.

Definition Classes
override def fuzzyEqv(confidence: Double)(that: Eager): Try[Boolean]

Performs a fuzzy equality comparison between the current Eager instance and another Eager instance. The comparison is based on a specified tolerance level. This method is unimplemented and currently returns a failure containing an AlgebraException.

Performs a fuzzy equality comparison between the current Eager instance and another Eager instance. The comparison is based on a specified tolerance level. This method is unimplemented and currently returns a failure containing an AlgebraException.

Value parameters

confidence

the tolerance level (as a Double) to be used for the fuzzy equality comparison

that

the Eager instance to compare against this instance

Attributes

Returns

a Try[Boolean] indicating whether the two instances are fuzzy equal. As the method is unimplemented, it always returns a failure containing an AlgebraException.

Definition Classes
def isComplex: Boolean

Attributes

Returns

true.

def isExact: Boolean

Determines whether this Valuable is exact, i.e., has no approximation.

Determines whether this Valuable is exact, i.e., has no approximation.

CONSIDER it may be possible that there are non-approximatable entities that are not exact either.

The method returns true if there is no approximate representation available (i.e., approximation is None), indicating that the entity is exact. Otherwise, it returns false.

Attributes

Returns

a Boolean indicating whether the entity is exact (true) or has an approximation (false).

def isUnity: Boolean

Determines if the current Complex number is both real and of unity magnitude.

Determines if the current Complex number is both real and of unity magnitude.

A Complex number is considered to have unity magnitude if its modulus equals one. Additionally, the number must lie on the real axis to satisfy the condition of being real.

Attributes

Returns

true if the Complex number is real and has unity magnitude, false otherwise.

def isZero: Boolean

Determines if the current number is equal to zero.

Determines if the current number is equal to zero.

Attributes

Returns

true if the number is zero, false otherwise

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.

def maybeFactor(context: Context): Option[Factor]

Optionally retrieves a factor associated with this Valuable if one exists (this is a Scalar).

Optionally retrieves a factor associated with this Valuable if one exists (this is a Scalar).

Factors are components or divisors related to the numerical value represented by this Valuable. If no such factor exists or is applicable, the result will be None.

Attributes

Returns

an Option containing the Factor if available, otherwise None.

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.

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.

Scales the current Complex instance by a given Rational value.

Scales the current Complex instance by a given Rational value.

This method multiplies the internal representation of the Complex number by the specified Rational value, returning a new Solution instance that represents the resulting scaled value.

Value parameters

r

the Rational value by which to scale the Complex number

Attributes

Returns

a Complex instance representing the scaled value

def signum: Int

Determines the sign of the Structure value represented by this instance. Returns an integer indicating whether the value is positive, negative, or zero.

Determines the sign of the Structure value represented by this instance. Returns an integer indicating whether the value is positive, negative, or zero.

Attributes

Returns

1 if the value is positive, -1 if the value is negative, and 0 if the value is zero

def toMonotone: Option[Structure]

If this Solution can be represented as a Structure, return it wrapped in Some, otherwise return None. TODO implement imaginary cases.

If this Solution can be represented as a Structure, return it wrapped in Some, otherwise return None. TODO implement imaginary cases.

Attributes

Returns

an Option[Structure].

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the complex number is imaginary.

Inherited methods

infix def add(y: Eager): Try[Eager]

Adds the current Eager instance to another Eager instance using the DyadicOperator mechanism. The addition operation is implemented by delegating to the addEagers function for specific behavior, ensuring proper handling of various subtypes of Eager.

Adds the current Eager instance to another Eager instance using the DyadicOperator mechanism. The addition operation is implemented by delegating to the addEagers function for specific behavior, ensuring proper handling of various subtypes of Eager.

Value parameters

y

the Eager instance to be added to this Eager instance

Attributes

Returns

a Try[Eager] containing the result of the addition if successful, or a failure if the operation fails

Inherited from:
Eager

Computes an approximate representation of the current value.

Computes an approximate representation of the current value.

This method utilizes the approximation mechanism to derive the most likely value in the form of a Real. Should the approximation fail, an AlgebraException will be raised to indicate the error.

Attributes

Returns

the approximate value as a Real if successful; throws an AlgebraException otherwise.

Inherited from:
Approximate
def approximationComplex(force: Boolean = ...): Option[Eager]

Attempts to compute an approximate complex representation of the current value.

Attempts to compute an approximate complex representation of the current value.

This method provides an optional approximation in the form of an Eager type. By default, it does not perform the computation unless explicitly requested through the force flag. The method may return None if no approximation can be computed or if the operation fails.

Value parameters

force

a boolean flag indicating whether to force computation of the approximation. If true, the method will attempt to perform a complex approximation even if it is resource-intensive or otherwise unwarranted.

Attributes

Returns

an Option containing the approximate value as an Eager if successful, or None if no approximation is available.

Inherited from:
Approximate
def category: String

Returns the category of this value in the Valuable type hierarchy.

Returns the category of this value in the Valuable type hierarchy.

Attributes

Returns

a string indicating the high-level category (e.g., "Expression", "Structure", "Nat", "Complex")

Inherited from:
TypeSafe
def compare(x: Eager, y: Eager): Try[Int]

Compares two instances of Eager and determines their relative ordering. This method is not yet implemented and will raise an com.phasmidsoftware.number.algebra.util.AlgebraException if called.

Compares two instances of Eager and determines their relative ordering. This method is not yet implemented and will raise an com.phasmidsoftware.number.algebra.util.AlgebraException if called.

Value parameters

x

the first Eager instance to compare

y

the second Eager instance to compare

Attributes

Returns

a Try[Int] that contains the comparison result: - 0 if x and y are equal, - a negative result if x is less than y, - and a positive result if x is greater than y. As the method is unimplemented, it will always return a failure with an AlgebraException.

Inherited from:
Eager
def describe: String

Returns a descriptive string combining category and type name. Useful for debugging to understand both the hierarchy level and concrete type.

Returns a descriptive string combining category and type name. Useful for debugging to understand both the hierarchy level and concrete type.

Attributes

Returns

a string in the format "Category.TypeName" (e.g., "Structure.WholeNumber")

Inherited from:
TypeSafe
infix def divide(y: Eager): Try[Eager]

Performs division of the current Eager instance by another Eager instance. This operation is implemented using the DyadicOperator mechanism, delegating the actual division logic to the divideEagers function.

Performs division of the current Eager instance by another Eager instance. This operation is implemented using the DyadicOperator mechanism, delegating the actual division logic to the divideEagers function.

Value parameters

y

the Eager instance to divide the current instance by

Attributes

Returns

a Try[Eager] containing the result of the division if successful, or a failure if the operation cannot be performed

Inherited from:
Eager
def fuzzyCompare(p: Double)(x: Eager, y: Eager): Try[Int]

Performs a fuzzy comparison between two Eager instances. The comparison is based on a specified tolerance and determines their relative ordering. If the comparison cannot be performed, an AlgebraException is returned as a failure.

Performs a fuzzy comparison between two Eager instances. The comparison is based on a specified tolerance and determines their relative ordering. If the comparison cannot be performed, an AlgebraException is returned as a failure.

Value parameters

p

the tolerance (as a Double) to be used for the comparison

x

the first Eager instance to be compared

y

the second Eager instance to be compared

Attributes

Returns

a Try[Int] representing the result of the comparison: - A negative integer if x is less than y - Zero if x is approximately equal to y within the tolerance p - A positive integer if x is greater than y - A Failure(AlgebraException) if the comparison cannot be performed

Inherited from:
Eager
def maybeDouble: Option[Double]

If this Valuable is exact, it returns the exact value as a Double. Otherwise, it returns None. NOTE: do NOT implement this method to return a Double for a fuzzy Real--only for exact numbers.

If this Valuable is exact, it returns the exact value as a Double. Otherwise, it returns None. NOTE: do NOT implement this method to return a Double for a fuzzy Real--only for exact numbers.

Attributes

Returns

Some(x) where x is a Double if this is exact, else None.

Inherited from:
Eager
infix def multiply(y: Eager): Try[Eager]

Multiplies the current Eager instance with another Eager instance. The multiplication operation is carried out using the DyadicOperator mechanism, which delegates to the multiplyEagers function for specific behavior. This ensures proper handling of various subtypes of Eager.

Multiplies the current Eager instance with another Eager instance. The multiplication operation is carried out using the DyadicOperator mechanism, which delegates to the multiplyEagers function for specific behavior. This ensures proper handling of various subtypes of Eager.

Value parameters

y

the Eager instance to multiply with this Eager instance

Attributes

Returns

a Try[Eager] containing the result of the multiplication if successful, or a failure if the operation cannot be performed

Inherited from:
Eager
def product(other: Valuable): Valuable

Obtains the product of this Valuable instance and another Valuable instance. The behavior of the method is determined by whether the instances are of type Lazy or Eager. If the provided instances do not conform to the expected types, an AlgebraException is thrown. CONSIDER supporting sum also.

Obtains the product of this Valuable instance and another Valuable instance. The behavior of the method is determined by whether the instances are of type Lazy or Eager. If the provided instances do not conform to the expected types, an AlgebraException is thrown. CONSIDER supporting sum also.

CONSIDER using lazify

Value parameters

other

the other Valuable instance to compute the product with

Attributes

Returns

a Valuable instance representing the product of this and the other instance

Note

throws AlgebraException if the computation involves unsupported Valuable types

Inherited from:
Valuable
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

Renders and returns a string representation of the object. By default, this is the same as render but it can be overridden in subclasses.

Renders and returns a string representation of the object. By default, this is the same as render but it can be overridden in subclasses.

Attributes

Returns

a string representing the object

Inherited from:
Valuable
infix def subtract(y: Eager): Try[Eager]

Subtracts the given Eager instance y from the current Eager instance. This operation is performed using the DyadicOperator mechanism, which delegates to the subtractEagers function to handle the specific subtraction behavior.

Subtracts the given Eager instance y from the current Eager instance. This operation is performed using the DyadicOperator mechanism, which delegates to the subtractEagers function to handle the specific subtraction behavior.

Value parameters

y

the Eager instance to be subtracted from this Eager instance

Attributes

Returns

a Try[Eager] containing the result of the subtraction if successful, or a failure if the operation fails

Inherited from:
Eager
def typeName: String

Returns a simple string representation of the runtime type. Useful for debugging and logging.

Returns a simple string representation of the runtime type. Useful for debugging and logging.

Attributes

Returns

the simple class name (e.g., "WholeNumber", "RationalNumber")

Inherited from:
TypeSafe

Concrete fields

override val fuzzy: Eager

Attributes

Returns

this Eager.

val maybeName: Option[String]

Retrieves an optional name associated with this instance.

Retrieves an optional name associated with this instance.

Attributes

Returns

an Option[String] containing the name if present, otherwise None

lazy val negate: Solution

Returns the negation of this Complex number.

Returns the negation of this Complex number.

The negation operation inverts both the real and imaginary components of the Complex instance. This is equivalent to rotating the complex number by 180 degrees in the complex plane.

Attributes

Returns

a new Solution representing the negated value of this Complex instance

lazy val normalize: Eager

Normalizes the Complex instance represented by the current object.

Normalizes the Complex instance represented by the current object.

This method computes a normalized form of the underlying complex structure, converting it to either a Complex or Eager representation, depending on the resulting value. If the normalized value is of type numerical.Complex, it is converted into a Complex instance. Otherwise, if the normalized value is a Field, it is wrapped in an Eager instance.

Attributes

Returns

an Eager instance that encapsulates the normalized value, either as a Complex or another Eager representation.

lazy val render: String

Method to render this Valuable for presentation to the user.

Method to render this Valuable for presentation to the user.

Attributes

Returns

a String

Inherited fields

lazy val asMonotone: Structure

Casts this Valuable instance into a Structure type if it already is a Structure. If the instance is not a Structure, an AlgebraException is thrown. CONSIDER returning Option[Structure] instead.

Casts this Valuable instance into a Structure type if it already is a Structure. If the instance is not a Structure, an AlgebraException is thrown. CONSIDER returning Option[Structure] instead.

Attributes

Returns

the current instance as a Structure

Note

Throws com.phasmidsoftware.number.algebra.util.AlgebraException if the instance is not of type Structure

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

Attempts to cast this instance to a Number. If the instance is of type Number, it is wrapped in an Option and returned. Otherwise, returns None.

Attempts to cast this instance to a Number. If the instance is of type Number, it is wrapped in an Option and returned. Otherwise, returns None.

Attributes

Returns

an Option containing the instance as a Number if applicable, or None if not.

Inherited from:
Valuable
lazy val materialize: Eager

Converts the current Lazy instance into an Eager instance by forcing the resolution or evaluation of its underlying value.

Converts the current Lazy instance into an Eager instance by forcing the resolution or evaluation of its underlying value.

The materialize method ensures that the computation of the value represented by this Lazy instance is completed and encapsulated within an appropriate Eager representation. This is particularly useful in scenarios where deferred computation needs to be explicitly resolved prior to further processing.

Attributes

Returns

the materialized Eager instance representing the resolved value

Inherited from:
Eager
lazy val toDouble: Double

Converts the approximate representation of this number into a Double.

Converts the approximate representation of this number into a Double.

This method attempts to approximate the value of this number by invoking the approximation method with force = true. If the approximation exists, it is converted to a Double. If no approximation can be obtained, an AlgebraException is thrown to indicate a logic error.

Attributes

Returns

the approximate value as a Double.

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if no approximation can be obtained.

Inherited from:
Approximate