Succ
Represents the successor of a natural number in Peano arithmetic.
The Succ class is a case class that extends the Nat trait and signifies the successor of another natural number.
Value parameters
- pred
-
The predecessor of this natural number, which is also a
Nat.
Attributes
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Nattrait Ntrait Ztrait Qtrait Rtrait Eagertrait DyadicOpstrait Approximatetrait Valuabletrait TypeSafetrait Normalizable[Valuable]trait Exactitudetrait Unitarytrait Zeroabletrait Numerictrait Renderableclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Adds the specified natural number to this natural number.
Adds the specified natural number to this natural number.
This method leverages the natIsSemiring.plus implementation, which defines addition for natural numbers recursively using Peano arithmetic.
Value parameters
- that
-
the natural number to be added to this instance
Attributes
- Returns
-
a new natural number representing the sum of this instance and the specified natural number
Compares this Succ instance for equality with another object.
Compares this Succ instance for equality with another object.
This method determines whether the current Succ instance represents the same natural number as another object, based on their predecessors. Only instances of type Succ are eligible for comparison.
Value parameters
- obj
-
the object to compare to this instance
Attributes
- Returns
-
true if the specified object is a
Succinstance and represents the same natural number as this instance; false otherwise - Definition Classes
-
Equals -> Any
Determines if the current number is equal to one.
Determines if the current number is equal to one.
This method establishes whether the numerical value of the current instance represents the first natural number (unity) based on its predecessor.
Attributes
- Returns
-
true if the current number is one, false otherwise
- Definition Classes
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
Determines the sign of the Structure value represented by this instance. Returns an integer indicating whether the value is positive, negative, or zero.
Determines the sign of the Structure value represented by this instance. Returns an integer indicating whether the value is positive, negative, or zero.
Attributes
- Returns
-
1 if the value is positive, -1 if the value is negative, and 0 if the value is zero
Inherited methods
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 compute an approximate representation of the current value.
Attempts to compute an approximate representation of the current value.
This method provides an optional approximation of the value represented by the implementing class. The approximation may account for uncertainties or computational limitations. By default, this method does not force computation of the approximation unless explicitly requested.
Value parameters
- force
-
a boolean flag indicating whether to force computation of the approximation. If
true, the method will attempt to generate an approximation even if such computation is resource-intensive or not strictly necessary.
Attributes
- Returns
-
an
Optioncontaining the approximate value as aRealif available, orNoneif no approximation can be computed. - Inherited from:
- Nat
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
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. - Inherited from:
- Eager
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
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. - Definition Classes
- Inherited from:
- Nat
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 Eager instance and another Eager instance. The comparison is based on a specified tolerance level. This method is unimplemented and currently returns a failure containing an AlgebraException.
Performs a fuzzy equality comparison between the current Eager instance and another Eager instance. The comparison is based on a specified tolerance level. This method is unimplemented and currently returns a failure containing an AlgebraException.
Value parameters
- confidence
-
the tolerance level (as a
Double) to be used for the fuzzy equality comparison - that
-
the
Eagerinstance to compare against this instance
Attributes
- Returns
-
a
Try[Boolean]indicating whether the two instances are fuzzy equal. As the method is unimplemented, it always returns a failure containing anAlgebraException. - Inherited from:
- Eager
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:
- Nat
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 - Inherited from:
- Nat
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
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
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 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
Converts this natural number into an integer.
Converts this natural number into an integer.
We should CONSIDER making this either a BigInt or an Option[Long] or perhaps a SafeLong.
Attributes
- Returns
-
the integer value corresponding to this natural number
Inherited fields
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
- Inherited from:
- Nat
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
Increments this natural number by one.
Increments this natural number by one.
Attributes
- Returns
-
a new natural number representing the successor of the current instance.
- Inherited from:
- Nat
Determines whether this Valuable is exact, i.e., has no approximation.
Determines whether this Valuable is exact, i.e., has no approximation.
CONSIDER it may be possible that there are non-approximatable entities that are not exact either.
The method returns true if there is no approximate representation available (i.e., approximation is None), indicating that the entity is exact. Otherwise, it returns false.
Attributes
- Returns
-
a
Booleanindicating whether the entity is exact (true) or has an approximation (false). - Inherited from:
- Nat
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
Constructs an optional instance of Q for this Nat. The Q instance is derived from the rational representation of the Nat itself.
Constructs an optional instance of Q for this Nat. The Q instance is derived from the rational representation of the Nat itself.
Attributes
- Returns
-
an
Option[Q]that contains theQinstance built from the rational value of the currentNat, orNoneif the representation cannot be determined. - Inherited from:
- Nat
Computes a potential representation of this Nat instance as Z.
Computes a potential representation of this Nat instance as Z.
Attributes
- Returns
-
an
Option[Z]containing a corresponding instance ofZif available; otherwise,None. - Inherited from:
- Nat
Normalizes this Nat instance to its simplest equivalent form. This operation does not modify the original instance but may return an adjusted Valuable representation that is equivalent to the original value but simpler.
Normalizes this Nat instance to its simplest equivalent form. This operation does not modify the original instance but may return an adjusted Valuable representation that is equivalent to the original value but simpler.
For instance, the normalization process might reduce complex expressions or structures to their minimal form where possible. In this specific implementation, it directly returns the current instance.
Attributes
- Returns
-
the simplest
Valuablerepresentation of thisNatinstance, which in this case isthis. - Inherited from:
- Nat
Method to render this Renderable for presentation to the user.
Method to render this Renderable for presentation to the user.
Attributes
- Returns
-
a String
- Inherited from:
- Nat
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
Converts this instance of Q to its corresponding rational representation.
Converts this instance of Q to its corresponding rational representation.
Attributes
- Returns
-
a Rational instance representing the current value
- Inherited from:
- Nat