Represents a rational number based on the Rational type, providing various mathematical operations and utilities applicable to rational numbers.
This class extends several traits to enable arithmetic operations such as addition, subtraction, multiplication, and division. It also supports comparisons, conversions, scaling, and power operations.
The class is designed to work seamlessly with precise and exact number representations, ensuring that operations maintain a high level of numeric fidelity.
CONSIDER adding a percentage flag to Real. CONSIDER merging the Rational class into this class (there's no compelling reason to have two separate classes).
Value parameters
- percentage
-
whether this is a percentage value or not. Similarly to the
degreesattribute ofAngle, this is a flag that is primarily cosmetic. - r
-
The
Rationalvalue represented by thisRationalNumber.
Attributes
- Constructor
-
Creates a
RationalNumberwith the givenRationalvalue. - Companion
- object
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait CanAddAndSubtract[RationalNumber]trait CanNegate[RationalNumber]trait Can[RationalNumber]trait ExactNumbertrait Scalable[ExactNumber]trait Qtrait Rtrait Exacttrait Numbertrait Ordered[Scalar]trait Comparable[Scalar]trait Scalartrait Structuretrait WithFuzzinesstrait Eagertrait DyadicOpstrait Approximatetrait Valuabletrait TypeSafetrait Normalizable[Valuable]trait Exactitudetrait Unitarytrait Zeroabletrait Numerictrait Renderableclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Scales the current instance of RationalNumber by the given Int value.
Scales the current instance of RationalNumber by the given Int value.
Value parameters
- factor
-
the integer value to scale the
RationalNumberinstance by
Attributes
- Returns
-
an
Option[RationalNumber]representing the scaled result; returnsNoneif the operation cannot be performed
Subtracts the given rational number from this one. NOTE that this result is not normalized.
Subtracts the given rational number from this one. NOTE that this result is not normalized.
Value parameters
- that
-
the rational number to subtract
Attributes
- Returns
-
the result of the subtraction
Compares this RationalNumber instance with another Scalar instance for exact equivalence. The comparison is performed by checking the type of the given Scalar and attempting an exact comparison if applicable. The result is encapsulated in an Option[Int].
Compares this RationalNumber instance with another Scalar instance for exact equivalence. The comparison is performed by checking the type of the given Scalar and attempting an exact comparison if applicable. The result is encapsulated in an Option[Int].
Value parameters
- that
-
the
Scalarinstance to compare against
Attributes
- Returns
-
an
Option[Int]: -Some(-1)if thisRationalNumberis less thanthat-Some(0)if thisRationalNumberis equal tothat-Some(1)if thisRationalNumberis greater thanthat-Noneif the exact comparison is not possible
Converts the given instance of type T (a subtype of Structure) into an optional transformed instance of the same type.
Converts the given instance of type T (a subtype of Structure) into an optional transformed instance of the same type.
The method attempts to match the input object t to specific subtypes (Real, WholeNumber) and performs a corresponding transformation if possible. If the input t does not match any recognized subtype, the result is None.
Type parameters
- T
-
the type of the input object, which must be a subtype of
Structureand must have an availableClassTag.
Value parameters
- t
-
the input object of type
T, whereTis a subtype ofStructure.
Attributes
- Returns
-
an
Optioncontaining the transformed instance of typeTif the conversion is successful, orNoneif it is not.
Compares two instances of Eager for equality.
Compares two instances of Eager for equality.
This method is intended to check if the provided instances, x and y, are equivalent. Currently, this functionality is not implemented and will return a failure with an appropriate exception message.
Value parameters
- that
-
the first
Eagerinstance to compare
Attributes
- Returns
-
a
Try[Boolean]where: -Success(true)indicates the objects are equivalent -Success(false)indicates the objects are not equivalent -Failureindicates this functionality is not implemented - Definition Classes
Computes the sign of the current RationalNumber. It evaluates to:
Computes the sign of the current RationalNumber. It evaluates to:
- 0 if the value is zero.
- 1 if the value is positive.
- -1 if the value is negative.
Attributes
- Returns
-
an integer representing the sign of the number: 0 for zero, 1 for positive, and -1 for negative.
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.
- Definition Classes
-
Any
Computes the negation of this RationalNumber.
Computes the negation of this RationalNumber.
This method returns a new RationalNumber instance that represents the negation of the current value.
Attributes
- Returns
-
a new
RationalNumberwhich is the additive inverse of thisRationalNumber
Inherited methods
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
Trepresenting the result of the multiplication - Inherited from:
- Scalable
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
Tto 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
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
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
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
RationalNumberand the other is anExactNumber, theExactNumberis converted to match the type of theRationalNumberbefore addition. - If one is a
Real, an attempt is made to convert the other number to match the type of theRealbefore addition. - For unsupported or invalid type combinations, an
AlgebraExceptionis thrown.
Value parameters
- other
-
the
Numberinstance to add to this instance
Attributes
- Returns
-
a
Numberinstance representing the sum of this instance and the providedotherinstance - 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
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
RationalNumberand the other is anExactNumber, theExactNumberis converted to match the type of theRationalNumberbefore subtraction. - If one is a
Real, an attempt is made to convert the other number to match the type of theRealbefore subtraction. - For unsupported or invalid type combinations, an
AlgebraExceptionis thrown.
Value parameters
- other
-
the
Numberinstance to subtract from this instance
Attributes
- Returns
-
a
Numberinstance representing the difference of this instance and the providedotherinstance - 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
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
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 aRationalNumber, multiplies it withthisNumber, and normalizes the result. - For unsupported types, an
AlgebraExceptionis thrown.
Value parameters
- other
-
the
Numberby which thisNumberis 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
othertype - Inherited from:
- Number
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
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
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
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
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
Trycontaining the result of the addition if successful, or a failure if an exception occurs - Inherited from:
- Number
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
Scalarinstance to add to this instance
Attributes
- Returns
-
a
Try[Scalar]containing the resultingScalarif the addition is successful, or aFailureif the operation cannot be performed - Inherited from:
- Scalar
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
Structureinstance to be added.
Attributes
- Returns
-
A
Trywrapping the resultingStructureinstance, or a failure if the operation cannot be completed. - Inherited from:
- Structure
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
Eagerinstance to be added to thisEagerinstance
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
Realif successful; throws anAlgebraExceptionotherwise. - Inherited from:
- Approximate
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
Realvalue when the current instance is not of typeReal
Attributes
- Returns
-
an
Option[Real]containing the approximated value if successful, orNoneif approximation fails - Inherited from:
- Structure
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
Optioncontaining the approximate value as anEagerif successful, orNoneif no approximation is available. - Inherited from:
- Approximate
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
Structureobject is anExactNumberand its factor isPureNumber, the result is converted usingValue.asJavaNumber. - If the
Structureobject is aRealwith awigglevalue below a specified tolerance, the result is also converted usingValue.asJavaNumber. - In all other cases,
Noneis returned.
Attributes
- Returns
-
an optional
java.lang.Numberrepresentation of this object. The result isSome(java.lang.Number)if the conversion is successful under the stated conditions; otherwise,None. - Inherited from:
- Structure
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
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
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
Numberinstance to compare the current instance against
Attributes
- Returns
-
an integer value: - a negative value if this
Numberis lower thanthat- zero if thisNumberis equal tothat- a positive value if thisNumberis greater thanthat - Note
-
Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the comparison cannot be performed due to invalid approximation logic
- Inherited from:
- Number
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
Scalarinstance 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 tothat. - a positive value if the current instance is greater thanthat. - Note
-
Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the conversion to a comparable value is not possible
- Inherited from:
- Number
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
Eagerinstance to compare - y
-
the second
Eagerinstance to compare
Attributes
- Returns
-
a
Try[Int]that contains the comparison result: -0ifxandyare equal, - a negative result ifxis less thany, - and a positive result ifxis greater thany. As the method is unimplemented, it will always return a failure with anAlgebraException. - Definition Classes
- Inherited from:
- Scalar
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
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
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
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
Scalarinstance to divide by. Must be a subtype ofScalar.
Attributes
- Returns
-
A
Trycontaining the result of the division as aScalar, or a failure if the division cannot be performed. - Inherited from:
- Scalar
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
Structureinstance 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
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
Eagerinstance 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
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
Eagerif the approximation is successful. - Inherited from:
- Eager
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
Eagerinstance to be compared - y
-
the second
Eagerinstance to be compared
Attributes
- Returns
-
a
Try[Int]representing the result of the comparison: - A negative integer ifxis less thany- Zero ifxis approximately equal toywithin the tolerancep- A positive integer ifxis greater thany- AFailure(AlgebraException)if the comparison cannot be performed - Inherited from:
- Eager
Performs a fuzzy equivalence comparison between this Number instance and another Eager instance.
Performs a fuzzy equivalence comparison between this Number instance and another Eager instance.
This method evaluates whether two instances are approximately equal within a given tolerance p. If both instances are of type Number, it converts them to Real for the comparison. If either of the approximations fails, or the comparison is not applicable, it delegates to the super implementation.
Value parameters
- confidence
-
the tolerance level for the fuzzy equality comparison. A higher value increases the permissible difference.
- that
-
the
Eagerinstance to compare thisNumberinstance against.
Attributes
- Returns
-
a
Try[Boolean]indicating whether the two instances are approximately equal (true) or not (false). ReturnsFailureif the comparison cannot be performed or encounters an error. - Definition Classes
- Inherited from:
- Number
Determines if the current instance of RationalNumber is represented exactly.
Determines if the current instance of RationalNumber is represented exactly.
Attributes
- Returns
-
true as the instance is always exact.
- Inherited from:
- ExactNumber
Determines whether this object represents unity.
Determines whether this object represents unity.
Attributes
- Returns
-
true if the object represents unity, false otherwise
- Inherited from:
- ExactNumber
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
- Inherited from:
- ExactNumber
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
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
Contextspecifies the criteria under which the factorization is valid.
Attributes
- Returns
-
an
Option[Factor]containing the factor if it can be determined, orNoneif no suitable factor exists within the providedContext. - Inherited from:
- Number
Attempts to retrieve an optional integer representation of the current exact number. The value is returned as an Option[Int] if the underlying rational number is a whole number and fits within the range of a 32-bit signed integer. Otherwise, None is returned.
Attempts to retrieve an optional integer representation of the current exact number. The value is returned as an Option[Int] if the underlying rational number is a whole number and fits within the range of a 32-bit signed integer. Otherwise, None is returned.
Attributes
- Returns
-
an optional integer representation of the number.
- Inherited from:
- ExactNumber
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
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
Scalarinstance to multiply with this instance. Must be a subtype ofScalar.
Attributes
- Returns
-
a
Try[Scalar]representing the product of the multiplication, or a failure if the operation is not possible. - Inherited from:
- Scalar
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
Structureoperand 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
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
Eagerinstance to multiply with thisEagerinstance
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
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
AdditiveCommutativeGroupfor the typeT, providing the necessary additive group operations.
Attributes
- Returns
-
the negated value of the current instance as an instance of type
T. - Inherited from:
- CanNegate
Returns a new instance of Structure that is the negation of the current instance. CONSIDER sorting out the use of CanNegate so that we can extend that for Structure.
Returns a new instance of Structure that is the negation of the current instance. CONSIDER sorting out the use of CanNegate so that we can extend that for Structure.
Attributes
- Returns
-
a
Structurerepresenting the negation of this instance - Inherited from:
- Scalar
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
Structureobject to be added to this object.
Attributes
- Returns
-
an
Optioncontaining the result of the addition if successful, orNoneif the operation cannot be completed. - Inherited from:
- CanAdd
Raises the current ExactNumber to the power of the given ExactNumber. The operation leverages the underlying rational representations of both numbers and computes the result exactly if possible.
Raises the current ExactNumber to the power of the given ExactNumber. The operation leverages the underlying rational representations of both numbers and computes the result exactly if possible.
Value parameters
- that
-
the exponent as an
ExactNumberto which the current number is raised
Attributes
- Returns
-
an
Option[ExactNumber]containing the resulting value if the power operation can be computed exactly, orNoneif it cannot - Inherited from:
- ExactNumber
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
Valuableinstance to compute the product with
Attributes
- Returns
-
a
Valuableinstance representing the product of this and the other instance - Note
-
throws AlgebraException if the computation involves unsupported
Valuabletypes - Inherited from:
- Valuable
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
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
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 providedMultiplicativeGroup[T] - Inherited from:
- CanMultiplyAndDivide
Scales the current WholeNumber by a given Rational multiplier and returns the result wrapped as an Option[Structure]. CONSIDER renaming as *
Scales the current WholeNumber by a given Rational multiplier and returns the result wrapped as an Option[Structure]. CONSIDER renaming as *
Value parameters
- scale
-
the Rational multiplier to scale the current
WholeNumber
Attributes
- Returns
-
an
Option[Structure]representing the scaled result - Inherited from:
- ExactNumber
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
Scalarinstance representing the scaled value - Inherited from:
- Scalar
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
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
Trycontaining the result of the subtraction as aNumber, or a failure if an error occurs - Inherited from:
- Number
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
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
Structureinstance 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
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
Eagerinstance to be subtracted from thisEagerinstance
Attributes
- Returns
-
a
Try[Eager]containing the result of the subtraction if successful, or a failure if the operation fails - Inherited from:
- Eager
Converts this ExactNumber into a RationalNumber representation.
Converts this ExactNumber into a RationalNumber representation.
Attributes
- Returns
-
A RationalNumber instance representing the current value.
- Inherited from:
- ExactNumber
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
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, otherwiseNone
Returns an Option containing this instance cast as type Q.
Returns an Option containing this instance cast as type Q.
Attributes
- Returns
-
an Option wrapping this instance as a type
Q
Computes the optional representation of this value as a Z (integer-like structure). Transforms the optional integer representation of the underlying number (maybeInt) into a corresponding Z instance, wrapped in Option.
Computes the optional representation of this value as a Z (integer-like structure). Transforms the optional integer representation of the underlying number (maybeInt) into a corresponding Z instance, wrapped in Option.
Attributes
- Returns
-
an
Option[Z]whereSome(Z)represents a valid integer-like structure derived from the current value, andNoneindicates that the value cannot be expressed as aZ(e.g., if the number is not a whole number or out of range).
Normalizes the current object to ensure it is represented in a simplified form. If the denominator (r.d) is 1, it represents the object as a WholeNumber. Otherwise, it returns the object as is.
Normalizes the current object to ensure it is represented in a simplified form. If the denominator (r.d) is 1, it represents the object as a WholeNumber. Otherwise, it returns the object as is.
Attributes
- Returns
-
a simplified version of the object as a
Valuable, either as aWholeNumberor the current object.
A constant that represents the identity element for multiplication within the field of RationalNumber.
A constant that represents the identity element for multiplication within the field of RationalNumber.
This value is provided by the implicit Field instance for RationalNumber and is equal to a RationalNumber representation of one.
Attributes
Renders the string representation of the current RationalNumber instance. Delegates the rendering logic to the associated r instance's render method.
Renders the string representation of the current RationalNumber instance. Delegates the rendering logic to the associated r instance's render method.
Attributes
- Returns
-
the string representation of this
RationalNumber.
Converts the current RationalNumber instance to a Rational representation.
Converts the current RationalNumber instance to a Rational representation.
Attributes
- Returns
-
the Rational representation of this RationalNumber.
Represents the zero value of the RationalNumber type within the field of rational numbers.
Represents the zero value of the RationalNumber type within the field of rational numbers.
This value is defined as the additive identity in the context of the Field type class, meaning any RationalNumber added to this value will result in the original RationalNumber.
Attributes
Inherited fields
Converts this WholeNumber instance to its Double representation.
Converts this WholeNumber instance to its Double representation.
Attributes
- Returns
-
the
Doublevalue obtained by converting thisWholeNumberto aRationaland then to aDouble. - Inherited from:
- ExactNumber
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
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
Optioncontaining the instance as aNumberif applicable, orNoneif not. - Inherited from:
- Valuable
Retrieves an optional fuzziness value associated with this instance.
Retrieves an optional fuzziness value associated with this instance.
The fuzziness value, if present, provides information about the level of uncertainty or imprecision, modeled as a Fuzziness[Double].
Attributes
- Returns
-
an
Optioncontaining theFuzziness[Double]value if defined, orNoneif no fuzziness is specified. - Inherited from:
- Exact
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
Eagerinstance representing the resolved value - Inherited from:
- Eager
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
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