NoScalar
NoScalar is a singleton object representing a special case of a Scalar that does not conform to standard scalar operations. It serves as a placeholder or non-standard entity in the scalar hierarchy, and most of its operations are unsupported or return default values.
This object extends both the Scalar and Exact traits, adhering to their respective contracts while providing specific overrides and limitations.
Attributes
- Graph
-
- Supertypes
-
trait Singletontrait Producttrait Mirrortrait Serializabletrait Producttrait Equalstrait Exacttrait Scalartrait Structuretrait WithFuzzinesstrait Eagertrait DyadicOpstrait Approximatetrait Valuabletrait TypeSafetrait Normalizable[Valuable]trait Exactitudetrait Unitarytrait Zeroabletrait Numerictrait Renderableclass Objecttrait Matchableclass AnyShow all
- Self type
-
NoScalar.type
Members list
Type members
Inherited types
The names of the product elements.
The names of the product elements.
Attributes
- Inherited from:
- Singleton
Attributes
- Inherited from:
- Singleton
The mirrored *-type.
The mirrored *-type.
Attributes
- Inherited from:
- Singleton
Attributes
- Inherited from:
- Singleton
Inherited and Abstract types
The name of the type.
The name of the type.
Attributes
- Inherited from:
- Mirror
Value members
Concrete methods
Compares this Scalar with another Scalar for exact equivalence. This method checks if both instances can be compared exactly.
Compares this Scalar with another Scalar for exact equivalence. This method checks if both instances can be compared exactly.
CONSIDER moving this up into Structure and having that be a Structure
Value parameters
- that
-
the
Scalarinstance to compare against
Attributes
- Returns
-
an
Option[Int]value: -Some(-1)if thisScalaris less thanthat-Some(0)if thisScalaris equal tothat-Some(1)if thisScalaris greater thanthat-Noneif the exact comparison is not possible - - Note
-
Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if called
Converts the given Structure object to an optional instance of the same type.
Converts the given Structure object to an optional instance of the same type.
Value parameters
- t
-
the input object of type
Twhich is a subtype ofStructure.
Attributes
- Returns
-
an
Optioncontaining a transformed instance of typeTif the conversion is successful, orNoneotherwise.
Determines whether this object is exact, i.e., is not any kind of approximation.
Determines whether this object is exact, i.e., is not any kind of approximation.
CONSIDER it may be possible that there are non-approximatable entities that are not exact either.
The method returns true if the value is represented exactly in IEEE 754 format, or Two's complement or the exact value must be represented symbolically. Examples of the first type include the number one (represented here as either WholeNumber(1) or Succ(NatZero). Examples of the second type include 1.5 or the square root of two (represented here as InversePower(2,2)).
When we are forced to approximate a value, for example when we want to print the decimal value of 𝛗, the Golden Ratio, then we mark such a representation as approximate, i.e., this method returns false.
Attributes
- Returns
-
a
Booleanindicating whether the entity is exact (true) or is an approximation (false).
Determines whether this object represents unity.
Determines whether this object represents unity.
Attributes
- Returns
-
true if the object represents unity, false otherwise
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
If this 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.
Attempts to yield a factor for the instance, if available.
Attempts to yield a factor for the instance, if available.
A Factor is a representation of the underlying numerical domain, for example, PureNumber, Radian, etc.
Attributes
- Returns
-
an
Option[Factor]containing the factor representation of this object, orNoneif factorization is not applicable or unavailable.
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
Scales the current scalar instance by the specified rational factor.
Scales the current scalar instance by the specified rational factor.
Value parameters
- r
-
the
Rationalfactor by which to scale the scalar
Attributes
- Returns
-
a new
Scalarinstance representing the scaled value - Note
-
Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if called
Represents the scaleFactor of a scalar value as a Double. This value indicates the magnitude by which a scalar is scaled, and the conversion factor to yield a PureNumber.
Represents the scaleFactor of a scalar value as a Double. This value indicates the magnitude by which a scalar is scaled, and the conversion factor to yield a PureNumber.
Attributes
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
- Note
-
Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if called
Inherited methods
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
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 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
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 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
Compares this Eager instance with another Eager instance for equality. This method is unimplemented and currently returns a failure with an AlgebraException.
Compares this Eager instance with another Eager instance for equality. This method is unimplemented and currently returns a failure with an AlgebraException.
Value parameters
- that
-
the
Eagerinstance to compare against
Attributes
- Returns
-
a
Try[Boolean]indicating whether the two instances are equal. As the method is unimplemented, it always returns a failure containing anAlgebraException. - Inherited from:
- Eager
Creates a new instance of type T with elements taken from product p.
Creates a new instance of type T with elements taken from product p.
Attributes
- Inherited from:
- Singleton
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 equality comparison between the current Structure instance and another Eager instance. The comparison is based on a specified tolerance level.
Performs a fuzzy equality comparison between the current Structure instance and another Eager instance. The comparison is based on a specified tolerance level.
If both instances are of type Structure, this method attempts to convert them to Real and performs a fuzzy equality check with the specified tolerance. If the conversion or comparison fails, a failure with an appropriate AlgebraException is returned.
If either of the instances is not of type Structure, a failure with an AlgebraException is returned.
Value parameters
- confidence
-
the tolerance level (as a
Double) to be used for the fuzzy equality comparison. - that
-
the
Eagerinstance to compare against the current instance.
Attributes
- Returns
-
a
Try[Boolean]indicating whether the two instances are fuzzy equal within the specified tolerance. Returns aSuccess(true)orSuccess(false)if the comparison completes successfully, or aFailure(AlgebraException)if an error occurs. - Definition Classes
- Inherited from:
- Structure
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
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
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
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 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
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
Normalizes this NoScalar instance to its simplest equivalent form.
Normalizes this NoScalar instance to its simplest equivalent form.
This operation ensures that the NoScalar object is in its most reduced or canonical representation. If no changes are required to achieve normalization, the instance itself is returned.
Attributes
- Returns
-
the normalized
Valuablerepresentation of this instance
Method to render this Valuable for presentation to the user.
Method to render this Valuable for presentation to the user.
Attributes
- Returns
-
a String
Inherited fields
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
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