LinearRoot
Represents the linear root of a given equation. A LinearRoot is an extension of the AbstractRoot class, specialized for cases where the root corresponds to a degree-1 (linear) polynomial equation.
This implementation assumes the linear root is unique and thus corresponds to the only solution available for a first-degree equation.
Value parameters
- equ
-
the
Equationinstance associated with this root. Assumes the equation is linear (degree 1).
Attributes
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass AbstractRoottrait Roottrait AtomicExpressiontrait Nameabletrait Expressiontrait Approximatetrait Lazytrait Valuabletrait TypeSafetrait Normalizable[Valuable]trait Exactitudetrait Unitarytrait Zeroabletrait Numerictrait Renderableclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Adds another Root to this Root, resulting in a new Root that represents the sum of the two roots. If the addition is not valid or cannot be performed, returns None.
Adds another Root to this Root, resulting in a new Root that represents the sum of the two roots. If the addition is not valid or cannot be performed, returns None.
Value parameters
- other
-
the
Rootto be added to the currentRoot. This parameter represents another mathematical root to combine with the currentRoot.
Attributes
- Returns
-
an
Option[Root]containing the resultingRootif the addition is successful, orNoneif the addition is not valid.
Attributes
- Returns
-
Retrieves the branch at the specified index.
Retrieves the branch at the specified index.
Value parameters
- index
-
the index of the branch to retrieve, where the index starts from 0.
Attributes
- Returns
-
the element of type
Tat the specified branch index. If the index is out of range, the behavior is implementation-specific.
Returns the number of branches in this.
Returns the number of branches in this.
branches corresponds to the number of possible solutions to some equation.
Attributes
- Returns
-
the number of branches as an integer.
Retrieves the LinearEquation associated with this Root.
Retrieves the LinearEquation associated with this Root.
Attributes
- Returns
-
an
Equation, which represents a mathematical relationship, typically defined by a monic polynomial and may have multiple branches of solutions.
Creates a new root instance corresponding to the specified equation and branch. This method is used to produce a mathematical solution associated with the given input parameters.
Creates a new root instance corresponding to the specified equation and branch. This method is used to produce a mathematical solution associated with the given input parameters.
Value parameters
- branch
-
the branch index associated with this root. It specifies a particular solution for the equation if multiple solutions exist.
- equ
-
the equation from which the root is derived. The equation represents a mathematical relationship, typically a monic polynomial.
Attributes
- Returns
-
a new
Rootinstance corresponding to the provided equation and branch.
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:
- AbstractRoot
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
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
Compares this AbstractRoot instance with another object for equality. The method checks if the other object is of a compatible type and whether all relevant Valuables of both objects are equal.
Compares this AbstractRoot instance with another object for equality. The method checks if the other object is of a compatible type and whether all relevant Valuables of both objects are equal.
Value parameters
- other
-
the object to compare for equality with this instance
Attributes
- Returns
-
true if the given object is an instance of
AbstractRoot, hascanEqualcompatibility with this instance, and if all relevant Valuables are equal; otherwise, false - Definition Classes
-
AbstractRoot -> Any
- Inherited from:
- AbstractRoot
Action to evaluate this Expression as a Valuable, if possible. NOTE: no simplification or factor-based conversion occurs here.
Action to evaluate this Expression as a Valuable, if possible. NOTE: no simplification or factor-based conversion occurs here.
Evaluation only occurs if the solution is exact and it has a factor that qualifies in the given context.
Attributes
- Returns
-
an optional
Valuable. - Inherited from:
- AbstractRoot
Generates a hash code for the instance based on its equ and branch Valuables.
Generates a hash code for the instance based on its equ and branch Valuables.
Attributes
- Returns
-
an integer hash code value obtained by hashing the
equandbranchValuables. - Definition Classes
-
AbstractRoot -> Any
- Inherited from:
- AbstractRoot
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:
- Root
Determines whether this object represents unity.
Determines whether this object represents unity.
Attributes
- Returns
-
true if the object represents unity, false otherwise
- Inherited from:
- AbstractRoot
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:
- AbstractRoot
Method to determine what Factor, if there is such, this Structure object is based on.
Method to determine what Factor, if there is such, this Structure object is based on.
Attributes
- Returns
-
an optional
Factor. - Inherited from:
- AbstractRoot
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
Creates a new Expression that represents the negation of the current Expression. This operation is equivalent to multiplying the current Expression by -1.
Creates a new Expression that represents the negation of the current Expression. This operation is equivalent to multiplying the current Expression by -1.
Attributes
- Returns
-
an
Expressionrepresenting the negation of the currentExpression. - Inherited from:
- AbstractRoot
Computes the power of the current Expression raised to the specified Rational exponent.
Computes the power of the current Expression raised to the specified Rational exponent.
Value parameters
- r
-
the
Rationalexponent to which the currentExpressionis to be raised. If the exponent is negative, the method computes the reciprocal of the positive power. If the exponent is zero, the result is the identityOne. Otherwise, the computation involves recursive calls to this method.
Attributes
- Returns
-
an
Expressionrepresenting the result of raising the currentExpressionto the power ofr. - Inherited from:
- AbstractRoot
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
Computes the reciprocal of the current Expression.
Computes the reciprocal of the current Expression.
For a quadratic equation in the form Quadratic(p, q), the reciprocal is computed as: (this / Literal(-q)) + Literal(-p / q). Otherwise, the reciprocal is calculated as One / this.
Attributes
- Returns
-
an
Expressionrepresenting the reciprocal of the currentExpression. - Inherited from:
- AbstractRoot
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
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:
- AbstractRoot
Attempts to simplify an atomic expression, for example, we replace Literal(Eager.pi) with Pi.
Attempts to simplify an atomic expression, for example, we replace Literal(Eager.pi) with Pi.
Attributes
- Returns
-
an
em.AutoMatcher[Expression]representing the process of handling or matching the atomic expression. - Inherited from:
- AbstractRoot
Computes the square of the current Expression. This method raises the current Root to the power of 2, which is equivalent to squaring it.
Computes the square of the current Expression. This method raises the current Root to the power of 2, which is equivalent to squaring it.
Attributes
- Returns
-
an
Expressionrepresenting the square of the currentRoot. - Inherited from:
- Root
Computes the square root of this Root. For a Quadratic equation, this method calculates one of its roots based on the specified parameter. If the Expression is not quadratic, an ExpressionException is thrown.
Computes the square root of this Root. For a Quadratic equation, this method calculates one of its roots based on the specified parameter. If the Expression is not quadratic, an ExpressionException is thrown.
Value parameters
- plus
-
a boolean value that determines which square root (positive or negative root) to compute: if true, compute the positive root; if false, compute the negative root.
Attributes
- Returns
-
an
Expressionrepresenting the computed square root of the currentExpression. - Note
-
Throws com.phasmidsoftware.number.expression.expr.ExpressionException if the square root computation is not supported for the current
Expression. - Inherited from:
- AbstractRoot
Computes the square of the current Expression. If the current equation is quadratic, it computes the result of the operation: this * -p + q. If the current equation is linear, it computes the result of the operation: this * -r. Otherwise, it returns the square of this expression by performing this * this.
Computes the square of the current Expression. If the current equation is quadratic, it computes the result of the operation: this * -p + q. If the current equation is linear, it computes the result of the operation: this * -r. Otherwise, it returns the square of this expression by performing this * this.
Attributes
- Returns
-
the result of squaring the current
Expression, evaluated according to the type of the equation. - Inherited from:
- AbstractRoot
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
Retrieves an optional name associated with the implementing class.
Retrieves an optional name associated with the implementing class.
The method returns an Option wrapping a String. If a name is available, it will be contained within the Option as Some(name). If no name is present, the method will return None.
Attributes
- Returns
-
an
Option[String]representing the optional name
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
Attributes
- Returns
-
- Inherited from:
- AtomicExpression
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 Field, 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 Field, if possible. NOTE: no simplification or factor-based conversion occurs here.
Attributes
- Returns
-
an
Option[Eager]containing the evaluated value if evaluation is successful, orNoneotherwise. - Inherited from:
- AbstractRoot
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 the expression is atomic.
Indicates whether the expression is atomic.
Attributes
- Returns
-
true, as this expression is atomic and cannot be further simplified.
- Inherited from:
- AtomicExpression
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
Indicates whether symbolic names are preserved.
Indicates whether symbolic names are preserved.
This method determines if symbolic representation should be retained when working with names in entities implementing the Nameable trait.
Attributes
- Returns
-
trueif symbolic names are kept, otherwisefalse - Inherited from:
- Nameable
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
Represents an optional value for the current AbstractRoot instance, resulting from a numerical transformation of its associated solution if the solution is exact.
Represents an optional value for the current AbstractRoot instance, resulting from a numerical transformation of its associated solution if the solution is exact.
The value is computed by invoking the whenever method with a predicate that checks whether the associated solution is exact (solution.isExact). If the predicate is true, the asField method of the solution is accessed, and its value is converted to a real number and subsequently mapped to a Double. If the predicate is false
Attributes
- Inherited from:
- AbstractRoot
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
This indicates whether this Root is protected from evaluation during simplification. Such roots as the golden ratio are kept as is during simplification. A Root instance is only protected if it also has a defined name.
This indicates whether this Root is protected from evaluation during simplification. Such roots as the golden ratio are kept as is during simplification. A Root instance is only protected if it also has a defined name.
Attributes
- Inherited from:
- AbstractRoot
Method to render this Structure in a presentable manner.
Method to render this Structure in a presentable manner.
Attributes
- Returns
-
a String
- Inherited from:
- AbstractRoot
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
Represents the solution of an equation for a specific branch in the context of a mathematical expression. The solution is computed by invoking the solve method of the equation with the provided branch index. The resulting solution is exact and adheres to the constraints described in the Algebraic trait.
Represents the solution of an equation for a specific branch in the context of a mathematical expression. The solution is computed by invoking the solve method of the equation with the provided branch index. The resulting solution is exact and adheres to the constraints described in the Algebraic trait.
Attributes
- Inherited from:
- AbstractRoot
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