This class represents a dyadic function of the two given expressions.
Value parameters
- a
-
the first expression being operated on.
- b
-
the second expression being operated on.
- f
-
the function to be applied to a and b.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass BinaryFunctiontrait Multipletrait CompositeExpressiontrait Expressiontrait Approximatetrait Lazytrait Valuabletrait TypeSafetrait Normalizable[Valuable]trait Exactitudetrait Unitarytrait Zeroabletrait Numerictrait Renderableclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
An equals method which considers two BiFunctions, which are non-identical but symmetric, to be equal.
An equals method which considers two BiFunctions, which are non-identical but symmetric, to be equal.
Value parameters
- obj
-
the other object.
Attributes
- Returns
-
true if the values of these two expressions would be the same (without any evaluation).
- Definition Classes
-
Equals -> Any
Determines whether to leave operands unchanged based on specific conditions.
Determines whether to leave operands unchanged based on specific conditions.
Attributes
- Returns
-
true if any of the operands match the conditions
IsCoshSquaredorIsSinhSquared, false otherwise. - Definition Classes
Inherited methods
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
Provides an approximation of this number, if applicable.
Provides an approximation of this number, if applicable.
This method attempts to compute an approximate representation of the number in the form of a Real, which encapsulates uncertainty or imprecision in its value. If no meaningful approximation is possible for the number, it returns None.
Attributes
- Returns
-
an
Option[Real]containing the approximate representation of thisNumber, orNoneif no approximation is available. - Inherited from:
- BinaryFunction
Attempts to compute an approximation of a complex operation defined by f using the approximations of components a and b. The operation can be a sum, product, power, or other types defined by f.
Attempts to compute an approximation of a complex operation defined by f using the approximations of components a and b. The operation can be a sum, product, power, or other types defined by f.
Value parameters
- force
-
A boolean flag indicating whether the approximation should forcibly be computed even if conditions might not favor it.
Attributes
- Returns
-
An
Optioncontaining the computedEagerresult if successful, orNoneif the approximation cannot be determined. - Definition Classes
- Inherited from:
- BinaryFunction
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
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
Action to simplify this Expression as a Field. NOTE that because we need to be able to evaluate this Expression exactly, we need to be sure that the Context passed in to f.evaluate is not None.
Action to simplify this Expression as a Field. NOTE that because we need to be able to evaluate this Expression exactly, we need to be sure that the Context passed in to f.evaluate is not None.
Attributes
- Returns
-
the materialized Field.
- Inherited from:
- BinaryFunction
Attempts to retrieve a factor based on the provided context. This method evaluates whether there is an applicable factor within the given context.
Attempts to retrieve a factor based on the provided context. This method evaluates whether there is an applicable factor within the given context.
Value parameters
- context
-
the context in which the factor is evaluated.
Attributes
- Returns
-
an optional
Factorif one qualifies under the provided context; otherwise,None. - Inherited from:
- BinaryFunction
Multiplies this Expression with another Lazy instance. If the other instance is of type Expression, a product operation is performed, and the result is simplified. If the other instance is not of type Expression, an ExpressionException is thrown.
Multiplies this Expression with another Lazy instance. If the other instance is of type Expression, a product operation is performed, and the result is simplified. If the other instance is not of type Expression, an ExpressionException is thrown.
Value parameters
- other
-
the
Lazyinstance to multiply with thisExpression
Attributes
- Returns
-
a new
Lazyinstance representing the product of thisExpressionand the suppliedLazyinstance - Throws
-
ExpressionException
if the provided
otheris not of typeExpression - Inherited from:
- Expression
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
Determines if all components within a given Expression are named.
Determines if all components within a given Expression are named.
TODO handle the specific cases at their proper level in the type hierarchy.
This method recursively checks whether each component of the provided Expression either has a name (in the case of a Nameable expression) or, if it is a composite expression (CompositeExpression), ensures that all of its terms also have names.
Attributes
- Returns
-
trueif all components of the expression are named, otherwisefalse. - Inherited from:
- CompositeExpression
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
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
Transforms an instance of the Eager type into a Lazy instance, allowing for deferred computation or evaluation. NOTE that this method ignores this.
Transforms an instance of the Eager type into a Lazy instance, allowing for deferred computation or evaluation. NOTE that this method ignores this.
Value parameters
- x
-
an instance of
Eagerthat is to be converted into aLazyrepresentation
Attributes
- Returns
-
a
Lazyinstance representing the deferred computation or evaluation of the input - Inherited from:
- Expression
Concrete fields
Regular hashCode method.
Regular hashCode method.
Attributes
- Returns
-
an Int depending on f, a, and b.
Simplifies a given BiFunction expression where trivial simplifications can be applied. This method identifies patterns in the expression that represent mathematical identities or redundancies and replaces them with their simplified form. Examples of such patterns include removing identities, handling zero and one in products or powers, and other basic algebraic simplifications.
Simplifies a given BiFunction expression where trivial simplifications can be applied. This method identifies patterns in the expression that represent mathematical identities or redundancies and replaces them with their simplified form. Examples of such patterns include removing identities, handling zero and one in products or powers, and other basic algebraic simplifications.
The simplifications include:
- Removing or simplifying identity elements (e.g.,
x * 1 = x,x + 0 = x). - Handling special cases like zeroes in products or powers.
- Applying reductions for specific constants or algebraic terms.
If no simplification can be applied, the method encapsulates this as a "miss" result. Implementations of this method aim to provide lightweight simplification logic, with more complex cases deferred to other parts of the system.
Attributes
- Returns
-
an
em.AutoMatcher[Expression]instance encapsulating the simplifiedExpressionif simplification was possible, or a "miss" if no trivial simplification could be applied.
Simplifies the components of a BiFunction expression by applying a matcher that reduces its constituent expressions (x and y), individually, to their simpler forms.
Simplifies the components of a BiFunction expression by applying a matcher that reduces its constituent expressions (x and y), individually, to their simpler forms.
Attributes
- Returns
-
An
AutoMatcherfor theExpressiontype that matches and simplifiesBiFunctionexpressions.
Renders the CompositeExpression as a string representation of the expression itself, typically in a structured or human-readable mathematical format.
Renders the CompositeExpression as a string representation of the expression itself, typically in a structured or human-readable mathematical format.
Attributes
- Returns
-
a string representation of the
CompositeExpressionas an expression.
Simplifies a CompositeExpression represented as a BiFunction by applying various matchers to identify opportunities for simplification. Specifically:
Simplifies a CompositeExpression represented as a BiFunction by applying various matchers to identify opportunities for simplification. Specifically:
- Converts the
BiFunctioninto anAggregatefor consistent simplification processing. - Attempts to simplify complementary terms within the
BiFunction. - Applies additional simplification logic as defined by
Expression.structuralMatcherandmatchSimpler.
TODO try to shorten this method.
If the expression cannot be simplified, the result will indicate the failure.
Attributes
- Returns
-
an
em.AutoMatcher[Expression]that encapsulates the logic for simplifying theBiFunction. It provides either the simplifiedExpressionor indicates that no simplification was possible.
Render this BiFunction for debugging purposes.
Render this BiFunction for debugging purposes.
Attributes
- Returns
-
a String showing a, f, and b in parentheses (or in braces if not exact).
Inherited fields
A lazily evaluated optional approximation of this Expression.
A lazily evaluated optional approximation of this Expression.
This field holds the result of simplifying the Expression with the approximation flag set to true. If the approximation is possible, it will store the approximated Real value; otherwise, it will remain None.
This approximation is computed based on the context of the simplify method, which determines how the expression should be approximated.
Attributes
- Inherited from:
- Expression
Represents the optional approximate evaluation of a complex Expression. The property retrieves the result of invoking the approximationComplex method on the simplify field, passing true as an argument to indicate that the result should be computed for complex approximations.
Represents the optional approximate evaluation of a complex Expression. The property retrieves the result of invoking the approximationComplex method on the simplify field, passing true as an argument to indicate that the result should be computed for complex approximations.
This lazy value ensures that the computation is deferred until accessed, and only computed once for performance optimization.
Attributes
- Returns
-
An
Optionof typeEager, containing the approximate complex representation of thisExpression, if available. Otherwise,None. - Inherited from:
- Expression
Method to determine if the materialized value of this Expression is defined and corresponds to a Number. If this expression is exact, then evaluate as is and convert the result to a Number. Otherwise, we simply materialize this expression and convert the result to a Number.
Method to determine if the materialized value of this Expression is defined and corresponds to a Number. If this expression is exact, then evaluate as is and convert the result to a Number. Otherwise, we simply materialize this expression and convert the result to a Number.
Attributes
- Returns
-
a
Some(x)if this materializes as aNumber; otherwiseNone. - Inherited from:
- Expression
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
Determines if the current Expression or any of its sub-expressions contains the constant I.
Determines if the current Expression or any of its sub-expressions contains the constant I.
For Expression instances:
- If the
Expressionis exactly the constantI, returnstrue. - If the
Expressionis a composite of other expressions (CompositeExpression), recursively searches through the terms to check if any of them contains the constantI. - For all other cases, returns
false.
Attributes
- Returns
-
trueif the constantIis present in theExpressionor its components,falseotherwise. - Inherited from:
- Expression
Method to use when debugging to know exactly what an Expression is in tree form. This is needed because toString and other renderers all use some sort of syntactic sugar to make things look nice for us humans.
Method to use when debugging to know exactly what an Expression is in tree form. This is needed because toString and other renderers all use some sort of syntactic sugar to make things look nice for us humans.
Creates a string representation of this Expression for debugging purposes. Depending on the type of this Expression, the output format varies:
- For atomic
Productinstances (arity 0), theproductPrefixis returned. - For non-atomic
Productinstances, theproductPrefixis combined with thedebugrepresentation of contained sub-expressions (if they areExpressions) or theirtoStringrepresentation otherwise. - For all other cases, the default
toStringimplementation is used.
Attributes
- Returns
-
a
Stringrepresentation useful for debugging. - Inherited from:
- Expression
Method to determine the depth of this Expression.
Method to determine the depth of this Expression.
Attributes
- Returns
-
the depth (an atomic expression has depth of 1).
- Inherited from:
- BinaryFunction
Evaluates this Expression in the context of AnyContext without simplification or factor-based conversion. This allows obtaining a direct evaluation of the Expression as a Eager, if possible. NOTE: no simplification or factor-based conversion occurs here.
Evaluates this Expression in the context of AnyContext without simplification or factor-based conversion. This allows obtaining a direct evaluation of the Expression as a Eager, if possible. NOTE: no simplification or factor-based conversion occurs here.
Attributes
- Returns
-
either a
Some[Eager]containing the value if evaluation is successful, orNoneotherwise. - Inherited from:
- Expression
Computes the fuzzy (approximate) value of this Expression. If the current Expression can be matched to a simpler form via matchSimpler, its fuzzy value is derived from the simplified expression. Otherwise, the fuzzy result is delegated to the superclass implementation.
Computes the fuzzy (approximate) value of this Expression. If the current Expression can be matched to a simpler form via matchSimpler, its fuzzy value is derived from the simplified expression. Otherwise, the fuzzy result is delegated to the superclass implementation.
Attributes
- Returns
-
an
eager.Realrepresenting the approximate value of thisExpression - Inherited from:
- Expression
Indicates whether this expression is atomic.
Indicates whether this expression is atomic.
Attributes
- Returns
-
false as the default value, indicating the expression is not atomic.
- Inherited from:
- CompositeExpression
Method to determine if this Expression can be evaluated as is. If so, then materialize will not lose any precision because no approximation will be required. NOTE that, it is conceivable that simplifying this Expression first might result in an eager value even though this method would return false.
Method to determine if this Expression can be evaluated as is. If so, then materialize will not lose any precision because no approximation will be required. NOTE that, it is conceivable that simplifying this Expression first might result in an eager value even though this method would return false.
Attributes
- Returns
-
true if evaluateAsIs is defined.
- Inherited from:
- Expression
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:
- BinaryFunction
Determines whether this object represents unity.
Determines whether this object represents unity.
Attributes
- Returns
-
true if the object represents unity, false otherwise
- Inherited from:
- CompositeExpression
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:
- CompositeExpression
Materializes this Expression into an Eager object by simplifying it, evaluating as-is, optionally approximating it, and recovering with a defined exception in case of failure.
Materializes this Expression into an Eager object by simplifying it, evaluating as-is, optionally approximating it, and recovering with a defined exception in case of failure.
This method should be the final step when dealing with an Expression. Do not materialize early because that defeats the entire purpose of lazy evaluation.
The method first simplifies the expression, attempts to evaluate it directly, and then tries an approximation if necessary. Ultimately, it ensures the resulting materialized object is an instance of Eager.
The Eager result will be normalized if appropriate.
Attributes
- Returns
-
an
Eagerrepresentation of thisExpressionachieved through evaluation and/or approximation. - Inherited from:
- Expression
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:
- CompositeExpression
Normalizes the current Lazy instance to its simplest Valuable equivalent. The method first attempts to simplify the instance using the simplify method. If the simplified result is exact, the method materializes it and normalizes the resulting value. Otherwise, the simplified value is returned as is.
Normalizes the current Lazy instance to its simplest Valuable equivalent. The method first attempts to simplify the instance using the simplify method. If the simplified result is exact, the method materializes it and normalizes the resulting value. Otherwise, the simplified value is returned as is.
Attributes
- Returns
-
the simplest
Valuablerepresentation of this value after normalization - Inherited from:
- Lazy
Provides a lazy string representation of the CompositeExpression, delegating the rendering logic to the renderAsExpression method.
Provides a lazy string representation of the CompositeExpression, delegating the rendering logic to the renderAsExpression method.
This value is computed only once, upon its first access, and caches the result for subsequent accesses. It is intended to present the CompositeExpression in a structured or human-readable mathematical format by reusing the string output generated by renderAsExpression.
Attributes
- Returns
-
the string representation of this
CompositeExpression. - Inherited from:
- CompositeExpression
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 from:
- CompositeExpression
Simplifies the current Expression instance. If a simpler representation of the Expression can be determined, it returns that representation. Otherwise, it returns the current Expression unchanged. NOTE: be careful not to invoke recursively.
Simplifies the current Expression instance. If a simpler representation of the Expression can be determined, it returns that representation. Otherwise, it returns the current Expression unchanged. NOTE: be careful not to invoke recursively.
Attributes
- Returns
-
the simplified
Expression, or the currentExpressionif no simplification is possible - Inherited from:
- Expression
Simplifies the exact form of a CompositeExpression by identifying and transforming sub-expressions into their precise, simplified forms. This method focuses on exact mathematical simplifications that can be performed without introducing approximations.
Simplifies the exact form of a CompositeExpression by identifying and transforming sub-expressions into their precise, simplified forms. This method focuses on exact mathematical simplifications that can be performed without introducing approximations.
TODO try to merge this method with Expression.simplifyByEvaluation.
Attributes
- Returns
-
an
em.AutoMatcher[Expression]that encapsulates the logic for simplifying exact expressions. The result contains the simplifiedExpressionif successful, or indicates no simplification was possible. - Inherited from:
- CompositeExpression
Provides the terms that comprise this CompositeExpression.
Provides the terms that comprise this CompositeExpression.
Attributes
- Returns
-
a sequence of
Expressionobjects representing the individual terms of thisCompositeExpression. - Inherited from:
- BinaryFunction
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