Real

com.phasmidsoftware.number.algebra.eager.Real
See theReal companion object
case class Real(value: Double, fuzz: Option[Fuzziness[Double]])(maybeName: Option[String] = ...) extends Number, R, CanAddAndSubtract[Real], Scalable[Real], CanMultiplyAndDivide[Real], CanPower[Number], MaybeFuzzy

Represents a (usually) fuzzy real number, which combines a numerical value with an associated fuzziness attribute. A fuzzy number expresses imprecision or uncertainty around a central numeric value, enabling computations that consider tolerances or relative inaccuracies in mathematical operations.

This class extends additive and multiplicative algebraic structures (Additive and Multiplicative traits) while implementing Number as a base trait to encapsulate numeric-like behavior.

NOTE that a Real with empty fuzz is considered to be exact.

Value parameters

fuzz

the optional fuzziness associated with the numeric value

value

the central numeric value of the fuzzy number

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait MaybeFuzzy
trait CanPower[Number]
trait Scalable[Real]
trait CanNegate[Real]
trait CanAdd[Real, Real]
trait Can[Real]
trait R
trait Number
trait Ordered[Scalar]
trait Comparable[Scalar]
trait Scalar
trait Structure
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 *(t: Real): Real

Multiplies the specified T by this T instance.

Multiplies the specified T by this T instance.

Value parameters

t

an instance of T to be multiplied by this T

Attributes

Returns

a new Multiplicative[T] representing the product of this T and the given T

def *(factor: Rational): Real

Scales the instance of type T by the given rational multiplier.

Scales the instance of type T by the given rational multiplier.

This method performs a multiplication operation between the current instance and the specified rational, returning an optional result. The result is defined if the scaling operation is valid for the specific implementation.

Value parameters

factor

the rational multiplier used to scale the instance

Attributes

Returns

an Option containing the scaled result of type T, or None if the operation is invalid

def +(t: Real): Real

Adds the specified Real to this Real instance.

Adds the specified Real to this Real instance.

Value parameters

t

an instance of Real to be added to this Real

Attributes

Returns

a new Real representing the sum of this Real and the given Real

def -(that: Real)(using AdditiveCommutativeGroup[Real]): Real

Subtracts the specified Real value from this Real value.

Subtracts the specified Real value from this Real value.

Value parameters

that

the Real value to subtract from this Real value

using

evidence parameter providing an AdditiveCommutativeGroup instance for Real

Attributes

Returns

the result of subtracting that from this Real value

def /(t: Real): Real

Divides this T instance by the specified T.

Divides this T instance by the specified T.

Value parameters

t

an instance of T to be the divisor

Attributes

Returns

a new Multiplicative[T] representing the quotient of this T and t

def add(other: Real): Try[Real]

Adds the current Real instance to the specified other Real instance and returns the result. The addition process is wrapped in a Try to safely handle potential failures.

Adds the current Real instance to the specified other Real instance and returns the result. The addition process is wrapped in a Try to safely handle potential failures.

Value parameters

other

the Real instance to be added to the current instance

Attributes

Returns

a Try[Real] containing the result of the addition, or a failure in case of an error

def asDouble: Double

Converts the current instance to a Double representation. CONSIDER changing to maybeDouble returning Option[Double].

Converts the current instance to a Double representation. CONSIDER changing to maybeDouble returning Option[Double].

Attributes

Returns

the Double value corresponding to the current instance

override def compare(that: Number): Int

Compares the current Number instance with another Number instance.

Compares the current Number instance with another Number instance.

This method performs a comparison of two Number instances. If both numbers are exact, it uses exact comparison. If one or both numbers are not exact, it attempts to approximate and compare. Note that in some cases, this method may throw an exception if an invalid approximation logic is encountered.

Value parameters

that

the Number instance to compare the current instance against

Attributes

Returns

an integer value: - a negative value if this Number is less than that - zero if this Number is equal to that - a positive value if this Number is greater than that

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the comparison logic is invalid.

Definition Classes
def compareExact(that: Scalar): Option[Int]

Compares the current Number instance with another Number instance exactly.

Compares the current Number instance with another Number instance exactly.

This method should only be used when both Number instances are exact. An exact comparison ensures a precise evaluation without considering any approximations or fuzziness. If either Number is not exact, this method is expected to throw an exception, as the operation is undefined for non-exact numbers.

Value parameters

that

the Number to compare against

Attributes

Returns

an integer value: - negative if the current Number is lower than that - zero if the current Number is equal to that - positive if the current Number is greater than that

def convert[T <: Structure : ClassTag](t: T): Option[T]

Converts the given numeric value to an optional representation.

Converts the given numeric value to an optional representation.

This method accepts a number of type T, where T is a subtype of Number, and returns an Option containing the input number if certain conditions (not detailed in this method's implementation) are met, otherwise None.

Value parameters

t

a prototype of the required output.

Attributes

Returns

an Option wrapping the input number if the conversion is successful, otherwise None

def divide(other: Real): Try[Real]

Divides the current Real value by another Real value.

Divides the current Real value by another Real value.

Value parameters

other

the Real value to divide the current value by

Attributes

Returns

a Try containing the result of the division as a Real, or a failure if the division is invalid (e.g., division by zero)

infix def doPlus(that: Scalar): Option[Scalar]

Performs an addition operation between the current scalar and another scalar.

Performs an addition operation between the current scalar and another scalar.

This method attempts to add the given Scalar to the current one. If the provided scalar is a Real instance, it directly computes the sum using the realIsRing.plus method. For other scalar types, it attempts to convert them to a compatible type with this scalar and computes the result if the conversion is successful.

CONSIDER eliminating this method.

Value parameters

that

the Scalar to be added to the current scalar

Attributes

Returns

an Option[Scalar] containing the result of the addition, or None if the operation cannot be performed

def doScaleDouble(that: Double): Option[Structure]

Scales the current instance of type T by the specified Double value.

Scales the current instance of type T by the specified Double value.

This method applies a scaling factor to the instance, returning an Option that contains the scaled instance if the operation is valid. If the scaling operation is not valid or feasible, None is returned.

Value parameters

that

the Double value to scale the instance by

Attributes

Returns

an Option containing the scaled instance of type T, or None if scaling is not possible

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

Determines whether this instance is equivalent to another instance of type Eager. NOTE: no normalization is performed or required.

Determines whether this instance is equivalent to another instance of type Eager. NOTE: no normalization is performed or required.

Value parameters

that

The instance of Eager to compare with this instance.

Attributes

Returns

A Try[Boolean] indicating success with true if the instances are equivalent, success with false if they are not, or a failure in case of an error.

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

Determines if the given that object is approximately equal to this object within a specified precision p.

Determines if the given that object is approximately equal to this object within a specified precision p.

This method performs fuzzy equivalence checks between two objects, incorporating uncertainty when the objects have associated fuzziness. The comparison logic adjusts based on whether both, one, or neither of the objects are fuzzy. For two fuzzy objects, their combined uncertainty is considered. For one fuzzy and one exact object, a more lenient comparison is applied. For two exact objects, strict equality is used.

Value parameters

confidence

A precision threshold used for fuzzy comparison. Represents the allowable margin of error within which the two objects are considered equivalent.

that

The object with which equivalence is being checked.

Attributes

Returns

A Try[Boolean] indicating whether this object and the given object are approximately equal within the specified precision threshold.

Definition Classes
def multiply(other: Real): Try[Real]

Multiplies this Real number with another Real number and returns the result wrapped in a Try.

Multiplies this Real number with another Real number and returns the result wrapped in a Try.

Value parameters

other

the Real number to be multiplied with this Real number

Attributes

Returns

a Try containing the result of the multiplication, or a failure if an error occurs

infix def pow(that: ExactNumber): Option[Number]

Computes the result of raising an instance of type T to the power specified by the given ExactNumber.

Computes the result of raising an instance of type T to the power specified by the given ExactNumber.

This method performs the power operation and returns the result wrapped in an Option[T]. If the operation is invalid or cannot be performed, None is returned.

Value parameters

that

the ExactNumber exponent to which the instance is raised

Attributes

Returns

an Option[T] containing the result of the power operation if valid, or None if the operation could not be performed

infix def power(r: Rational): Option[Real]

Computes the power of the current value raised to the provided Rational exponent.

Computes the power of the current value raised to the provided Rational exponent.

Value parameters

r

the Rational exponent to which the value is raised

Attributes

Returns

an Option[Real] containing the result of the power operation, if the computation is successful

def scale(r: Rational): Scalar

Scales the current scalar instance by the specified rational factor. NOTE no normalization is performed or required.

Scales the current scalar instance by the specified rational factor. NOTE no normalization is performed or required.

Value parameters

r

the Rational factor by which to scale the scalar

Attributes

Returns

a new Scalar instance representing the scaled value

def subtract(other: Real): Try[Real]

Subtracts the specified other value from the current value.

Subtracts the specified other value from the current value.

Value parameters

other

the value to be subtracted from the current instance

Attributes

Returns

a Try containing the result of the subtraction if successful, or a failure if an error occurs during the operation

Converts the current value into a FuzzyNumber instance.

Converts the current value into a FuzzyNumber instance.

This lazy value constructs a FuzzyNumber using the given value, with Value.fromDouble to handle conversion, and applies a level of fuzziness determined by fuzz. It sets the type of the number to PureNumber.

Attributes

Returns

A FuzzyNumber representation of the current value.

Inherited methods

def *(that: Real)(using MultiplicativeMonoid[Real]): Real

Multiplies the current instance of type T with another instance of type T, using the provided MultiplicativeMonoid context.

Multiplies the current instance of type T with another instance of type T, using the provided MultiplicativeMonoid context.

Value parameters

that

the instance of type T to be multiplied with the current instance.

Attributes

Returns

the result of multiplying the current instance by the given instance of type T.

Inherited from:
CanMultiply
infix def *(factor: Int): Real

Multiplies the current instance by the specified integer factor.

Multiplies the current instance by the specified integer factor.

Value parameters

factor

the integer value to multiply with the current instance

Attributes

Returns

a new instance of type T representing the result of the multiplication

Inherited from:
Scalable
def *(other: Number): Number

Multiplies the current number with another number using the defined multiplicative group.

Multiplies the current number with another number using the defined multiplicative group.

Value parameters

other

The number to be multiplied with the current number.

Attributes

Returns

The result of the multiplication as a number.

Inherited from:
Number
def +(that: Real)(using AdditiveCommutativeMonoid[Real], Convertible[Real, Real]): Real

Adds the given instance of the same type to this instance, leveraging the properties of an AdditiveCommutativeMonoid to ensure associativity, commutativity, and identity. CONSIDER keeping percentage if both are percentages. CONSIDER rewriting this in such a way that no exception will ever be thrown (use compiler to check, not runtime).

Adds the given instance of the same type to this instance, leveraging the properties of an AdditiveCommutativeMonoid to ensure associativity, commutativity, and identity. CONSIDER keeping percentage if both are percentages. CONSIDER rewriting this in such a way that no exception will ever be thrown (use compiler to check, not runtime).

Value parameters

that

The instance of the same type to be added to this instance.

Attributes

Returns

The result of adding this instance and the provided instance.

Inherited from:
CanAdd
def +(other: Number): Number

Adds this Number instance to another Number instance and returns the result.

Adds this Number instance to another Number instance and returns the result.

CONSIDER: there is an alternative way of adding Numbers and that is to summon an commutative addend. Which should we be using? This method allows for appropriate conversions whereas the other method does not.

The addition is performed based on the types of the two Number instances:

  • If both are WholeNumber, their values are added directly.
  • If one is a RationalNumber and the other is an ExactNumber, the ExactNumber is converted to match the type of the RationalNumber before addition.
  • If one is a Real, an attempt is made to convert the other number to match the type of the Real before addition.
  • For unsupported or invalid type combinations, an AlgebraException is thrown.

Value parameters

other

the Number instance to add to this instance

Attributes

Returns

a Number instance representing the sum of this instance and the provided other instance

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the addition cannot be performed due to unsupported or invalid type combinations

Inherited from:
Number
def -(other: Number): Number

Subtracts another Number from this Number instance and returns the result.

Subtracts another Number from this Number instance and returns the result.

The subtraction is performed based on the types of the two Number instances:

  • If both are WholeNumber, their values are subtracted directly.
  • If one is a RationalNumber and the other is an ExactNumber, the ExactNumber is converted to match the type of the RationalNumber before subtraction.
  • If one is a Real, an attempt is made to convert the other number to match the type of the Real before subtraction.
  • For unsupported or invalid type combinations, an AlgebraException is thrown.

Value parameters

other

the Number instance to subtract from this instance

Attributes

Returns

a Number instance representing the difference of this instance and the provided other instance

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the subtraction cannot be performed due to unsupported or invalid type combinations

Inherited from:
Number
def /(that: Real)(using MultiplicativeGroup[Real]): Real

Divides the current instance by the given value that within the context of a MultiplicativeGroup[T].

Divides the current instance by the given value that within the context of a MultiplicativeGroup[T].

Value parameters

that

the value by which the current instance is to be divided, belonging to type T

Attributes

Returns

the result of the division, computed as per the rules defined by the MultiplicativeGroup[T]

Inherited from:
CanMultiplyAndDivide
def /(other: Number): Number

Divides this Number by another Number.

Divides this Number by another Number.

The division is performed based on the type of the input Number:

  • If the input is an ExactNumber, it computes the reciprocal of the input, converts it to a RationalNumber, multiplies it with this Number, and normalizes the result.
  • For unsupported types, an AlgebraException is thrown.

Value parameters

other

the Number by which this Number is to be divided

Attributes

Returns

the result of division as a Number

Throws
com.phasmidsoftware.number.algebra.util.AlgebraException

if the division is unsupported for the provided other type

Inherited from:
Number
def <(that: Scalar): 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: Scalar): 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: Scalar): 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: Scalar): 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(other: Number): Try[Number]

Adds the given number to the current instance and returns the result.

Adds the given number to the current instance and returns the result.

Value parameters

other

the number to be added to the current instance

Attributes

Returns

a Try containing the result of the addition if successful, or a failure if an exception occurs

Inherited from:
Number
infix def add[B <: Scalar](y: B): Try[Scalar]

Adds the specified Scalar instance to this Scalar and returns the result. The addition operation is performed for compatible scalar types. If the types are incompatible or the operation fails, a Failure is returned.

Adds the specified Scalar instance to this Scalar and returns the result. The addition operation is performed for compatible scalar types. If the types are incompatible or the operation fails, a Failure is returned.

Value parameters

y

the Scalar instance to add to this instance

Attributes

Returns

a Try[Scalar] containing the resulting Scalar if the addition is successful, or a Failure if the operation cannot be performed

Inherited from:
Scalar
def add(y: Structure): Try[Structure]

Adds the specified Structure instance to the current instance, producing a new Structure.

Adds the specified Structure instance to the current instance, producing a new Structure.

Value parameters

y

The Structure instance to be added.

Attributes

Returns

A Try wrapping the resulting Structure instance, or a failure if the operation cannot be completed.

Inherited from:
Structure
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 approximation(force: Boolean = ...): Option[Real]

Attempts to approximate the current instance to a Real value. If the instance is already of type Real, it is simply returned, wrapped inside Some. Otherwise, depending on the value of force, it either attempts a conversion to a default Real (if force is true), or returns None.

Attempts to approximate the current instance to a Real value. If the instance is already of type Real, it is simply returned, wrapped inside Some. Otherwise, depending on the value of force, it either attempts a conversion to a default Real (if force is true), or returns None.

NOTE that this method tries to keep exact quantities exact.

Value parameters

force

a boolean flag indicating whether to force the conversion to a default Real value when the current instance is not of type Real

Attributes

Returns

an Option[Real] containing the approximated value if successful, or None if approximation fails

Inherited from:
Structure
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 asJavaNumber: Option[Number]

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

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

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

  • If the Structure object is an ExactNumber and its factor is PureNumber, the result is converted using Value.asJavaNumber.
  • If the Structure object is a Real 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:
Structure
def asT: Real

Casts the current instance to the type parameter T of the enclosing Can trait.

Casts the current instance to the type parameter T of the enclosing Can trait.

This method performs a type-safe cast using the ClassTag to verify at runtime that the cast is valid. If the current instance cannot be cast to type T, an AlgebraException is thrown.

Attributes

Returns

the current instance as an instance of type T

Throws
AlgebraException

if the cast is invalid

Inherited from:
Can
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(that: Scalar): Int

Compares this Number instance with a Scalar instance.

Compares this Number instance with a Scalar instance.

This method matches the type of the input Scalar and performs a comparison based on its type. If the input is a Number, it delegates to the compare(Number) method. If the input is a Radians, it first attempts to convert the Radians into a comparable value and then performs the comparison.

Value parameters

that

the Scalar instance to compare the current instance against.

Attributes

Returns

an integer value: - a negative value if the current instance is less than that. - zero if the current instance is equal to that. - a positive value if the current instance is greater than that.

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the conversion to a comparable value is not possible

Inherited from:
Number
override 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.

Definition Classes
Inherited from:
Scalar
def compareTo(that: Scalar): 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 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
def divide(other: Number): Try[Number]

Divides the current number by the given number.

Divides the current number by the given number.

Value parameters

other

The number to divide the current number by.

Attributes

Returns

A Try[Number] containing the result of the division if successful, or a failure if an exception occurs (e.g., division by zero).

Inherited from:
Number
def divide[B <: Scalar](y: B): Try[Scalar]

Divides this Scalar instance by another Scalar instance of type B. The result of the division is wrapped in a Try to safely handle potential failures.

Divides this Scalar instance by another Scalar instance of type B. The result of the division is wrapped in a Try to safely handle potential failures.

Value parameters

y

The Scalar instance to divide by. Must be a subtype of Scalar.

Attributes

Returns

A Try containing the result of the division as a Scalar, or a failure if the division cannot be performed.

Inherited from:
Scalar
def divide(y: Structure): Try[Structure]

Divides the current Structure instance by another Structure instance. The operation is performed using the DyadicOperator defined for Structure. The result is wrapped in a Try to handle potential failures during the operation.

Divides the current Structure instance by another Structure instance. The operation is performed using the DyadicOperator defined for Structure. The result is wrapped in a Try to handle potential failures during the operation.

Value parameters

y

the Structure instance to divide the current instance by

Attributes

Returns

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

Inherited from:
Structure
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 fuzzy: Eager

Attempts to convert the current object to an instance of Eager using an approximation method. If the conversion fails, it recovers by throwing an AlgebraException with a descriptive error message.

Attempts to convert the current object to an instance of Eager using an approximation method. If the conversion fails, it recovers by throwing an AlgebraException with a descriptive error message.

Attributes

Returns

An instance of Eager if the approximation is successful.

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 maybeFactor(context: Context): Option[Factor]

Attempts to obtain a Factor representation in a specific Context.

Attempts to obtain a Factor representation in a specific Context.

A Factor could represent entities like PureNumber, Radian, etc., that provide numerical or dimensional meaning to a value. This method evaluates the current instance within the given Context to determine if a valid factor can be generated.

Value parameters

context

the evaluation context in which to determine the factor. The Context specifies the criteria under which the factorization is valid.

Attributes

Returns

an Option[Factor] containing the factor if it can be determined, or None if no suitable factor exists within the provided Context.

Inherited from:
Number
def multiply(other: Number): Try[Number]

Multiplies this number by the given number and returns the result wrapped in a Try.

Multiplies this number by the given number and returns the result wrapped in a Try.

Value parameters

other

the number to multiply with this number

Attributes

Returns

a Try containing the product of this number and the given number, or a Failure if an error occurs during multiplication

Inherited from:
Number
def multiply[B <: Scalar](y: B): Try[Scalar]

Multiplies this Scalar instance by another Scalar of type B. The operation uses a dyadic operator to compute the product of the two scalars. The result is wrapped in a Try to handle any potential failures during the operation.

Multiplies this Scalar instance by another Scalar of type B. The operation uses a dyadic operator to compute the product of the two scalars. The result is wrapped in a Try to handle any potential failures during the operation.

Value parameters

y

the Scalar instance to multiply with this instance. Must be a subtype of Scalar.

Attributes

Returns

a Try[Scalar] representing the product of the multiplication, or a failure if the operation is not possible.

Inherited from:
Scalar
def multiply(y: Structure): Try[Structure]

Multiplies the current Structure instance by the specified Structure operand. The result of the operation is wrapped in a Try, allowing for safe handling of failures.

Multiplies the current Structure instance by the specified Structure operand. The result of the operation is wrapped in a Try, allowing for safe handling of failures.

Value parameters

y

the Structure operand with which the current instance is multiplied

Attributes

Returns

a Try[Structure] containing the result of the multiplication if successful, or a failure if the operation is not valid or cannot be performed

Inherited from:
Structure
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 negate(using AdditiveCommutativeGroup[Real]): Real

Computes the additive inverse (negation) of an instance of type T.

Computes the additive inverse (negation) of an instance of type T.

Value parameters

AdditiveCommutativeGroup[T]

an implicit instance of AdditiveCommutativeGroup for the type T, providing the necessary additive group operations.

Attributes

Returns

the negated value of the current instance as an instance of type T.

Inherited from:
CanNegate
infix def plus(that: Structure)(using AdditiveCommutativeMonoid[Real]): Option[Real]

Computes the addition of this object and the given Structure object using the additive properties of an AdditiveCommutativeMonoid. The operation returns an optional result where the addition succeeds if a valid transformation and combination can be performed.

Computes the addition of this object and the given Structure object using the additive properties of an AdditiveCommutativeMonoid. The operation returns an optional result where the addition succeeds if a valid transformation and combination can be performed.

CONSIDER eliminate this method and use with + instead.

Value parameters

that

the Structure object to be added to this object.

Attributes

Returns

an Option containing the result of the addition if successful, or None if the operation cannot be completed.

Inherited from:
CanAdd
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 reciprocal(using MultiplicativeGroup[Real]): Real

Calculates the reciprocal of the given value t within the context of a multiplicative group.

Calculates the reciprocal of the given value t within the context of a multiplicative group.

Value parameters

using

the value of MultiplicativeGroup

Attributes

Returns

the reciprocal of the given value t, computed within the rules of the provided MultiplicativeGroup[T]

Inherited from:
CanMultiplyAndDivide
def scale(x: Int): Scalar

Scales the current scalar instance by a factor derived from the specified integer.

Scales the current scalar instance by a factor derived from the specified integer.

Value parameters

x

the integer factor by which to scale the scalar

Attributes

Returns

a new Scalar instance representing the scaled value

Inherited from:
Scalar
def subtract(other: Number): Try[Number]

Subtracts the given number from the current number and returns the result.

Subtracts the given number from the current number and returns the result.

Value parameters

other

the number to be subtracted from the current number

Attributes

Returns

a Try containing the result of the subtraction as a Number, or a failure if an error occurs

Inherited from:
Number
def subtract[B <: Scalar](y: B): Try[Scalar]

Subtracts the given scalar from this scalar and returns the result wrapped in a Try. The operation is performed using the dyadic operator logic powered by DyadicOperator, with the subtraction behavior provided by subtractScalars.

Subtracts the given scalar from this scalar and returns the result wrapped in a Try. The operation is performed using the dyadic operator logic powered by DyadicOperator, with the subtraction behavior provided by subtractScalars.

Value parameters

y

The scalar value to subtract, which must be a subtype of Scalar.

Attributes

Returns

A Try[Scalar] containing the result of the subtraction if successful, or a failure if the operation cannot be completed (e.g., type mismatch or invalid operation).

Inherited from:
Scalar
def subtract(y: Structure): Try[Structure]

Subtracts the given Structure instance (y) from the current instance. The operation is performed using a dyadic operator that ensures type safety and handles any failures during the subtraction via a Try.

Subtracts the given Structure instance (y) from the current instance. The operation is performed using a dyadic operator that ensures type safety and handles any failures during the subtraction via a Try.

Value parameters

y

the Structure instance to be subtracted from the current instance

Attributes

Returns

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

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

lazy val isExact: Boolean

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

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

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).

lazy val isUnity: Boolean

Determines whether this object represents unity.

Determines whether this object represents unity.

Attributes

Returns

true if the object represents unity, false otherwise

lazy val 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

lazy override val 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 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 Real--only for exact numbers.

Attributes

Returns

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

lazy val maybeFuzz: Option[Fuzziness[Double]]

Represents an optional fuzziness value associated with the implementing entity.

Represents an optional fuzziness value associated with the implementing entity.

This method provides a way to retrieve the fuzziness information if it exists. The fuzziness is represented as an Option[Fuzziness[Double]]:

  • Some(Fuzziness[Double]): Indicates the presence of fuzziness.
  • None: Indicates the absence of fuzziness.

Attributes

Returns

An Option containing a Fuzziness[Double] if fuzziness is present, or None if it is not.

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 maybeQ: Option[Q]

Converts the specified value into an exact rational representation if possible, and wraps it in an Option. If the conversion fails, it returns None.

Converts the specified value into an exact rational representation if possible, and wraps it in an Option. If the conversion fails, it returns None.

Attributes

Returns

Some instance of Q if the conversion is successful, or None if it fails.

lazy override val negate: Real

Computes the negation of this Real instance.

Computes the negation of this Real instance.

Attributes

Returns

A new Real instance representing the negated value of this instance.

lazy val nominalValue: Double

Retrieves the nominal (non-fuzzy) value associated with the entity.

Retrieves the nominal (non-fuzzy) value associated with the entity.

This value represents the precise or primary measurement or parameter of the entity, without considering any associated fuzziness or uncertainty.

Attributes

Returns

The nominal value as a Double.

Returns the normalized representation of the current object. CONSIDER if we have an exact Real, and a value that corresponds precisely to an Int, maybe we should return a WholeNumber instead. XXX would use d == d.floor XXX let's not try it for rationals as well!

Returns the normalized representation of the current object. CONSIDER if we have an exact Real, and a value that corresponds precisely to an Int, maybe we should return a WholeNumber instead. XXX would use d == d.floor XXX let's not try it for rationals as well!

Attributes

Returns

the normalized form of this object as a Valuable instance

lazy val one: Real

Represents the multiplicative identity element of the structure.

Represents the multiplicative identity element of the structure.

The one value serves as the neutral element for the multiplication operation, meaning that for any instance t of type T, the equation one * t = t * one = t holds true.

Attributes

lazy val render: String

Renders this Real for presentation.

Renders this Real for presentation.

This method converts the current Real instance into its string representation, including its value and fuzziness as defined by the internal rendering logic.

Attributes

Returns

a string representation of the Real

lazy val scaleByPi: Real

Scales the current Real instance by the mathematical constant π (pi). CONSIDER make this package private again

Scales the current Real instance by the mathematical constant π (pi). CONSIDER make this package private again

This method creates a new Real by multiplying the internal value of the current instance with the constant π. The fuzziness remains unaffected in the resulting instance.

Attributes

Returns

a new Real instance with its value scaled by π

lazy override val 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

lazy val signum: Int

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

Determines the sign of the scalar 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

lazy override 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, a AlgebraException is thrown to indicate a logic error.

Attributes

Returns

the approximate value as a Double.

Attempts to convert the current value to an exact rational number, if applicable.

Attempts to convert the current value to an exact rational number, if applicable.

Attributes

Returns

An Option containing a RationalNumber instance if the conversion is successful, or None if the value cannot be exactly represented as a rational number.

Converts the current Real instance into an instance of FuzzyNumber.

Converts the current Real instance into an instance of FuzzyNumber.

This method creates a FuzzyNumber using the value of the current Real, its numeric type as PureNumber, and its associated fuzziness.

Attributes

Returns

a FuzzyNumber representation of this Real instance

lazy val toRational: Option[Rational]

Converts this Number into its corresponding Rational representation, if possible.

Converts this Number into its corresponding Rational representation, if possible.

Attributes

Returns

an Option[Rational] containing the Rational representation of this Number if it can be converted, or None if the conversion is not possible.

lazy override val toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

lazy val unary_-: Real

Computes the additive inverse of this instance.

Computes the additive inverse of this instance.

This method returns a new instance representing the negation of this value, as defined in the additive structure of the type T.

Attributes

Returns

a new instance of type T that is the additive inverse of this instance

lazy val zero: Real

Represents the additive identity element for the type T.

Represents the additive identity element for the type T.

The additive identity, commonly referred to as "zero," is the element in an additive algebraic structure that, when added to any element of the structure, results in the same element. For any element x, x + zero and zero + x should equal x.

Attributes

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 scaleFactor: Double

A scale factor applied to this Number.

A scale factor applied to this Number.

The scaleFactor represents a multiplier that influences computations or adjustments involving this number. It is commonly used to scaleFactor or manipulate the magnitude of the number in various arithmetic or operational contexts.

Attributes

Inherited from:
Number