QuadraticSolution

com.phasmidsoftware.number.algebra.eager.QuadraticSolution
See theQuadraticSolution companion object
case class QuadraticSolution(base: Structure, offset: Structure, coefficient: Int, imaginary: Boolean = ...)(maybeName: Option[String] = ...) extends Algebraic

Represents a solution to a quadratic equation in the context of a specific Factor.

Value parameters

base

The base Value component of the solution.

offset

The offset Value component of the solution, usually derived from the discriminant. QuadraticSolution models the structure of solutions to equations of the form: x^2 + px + q = 0. It encapsulates components necessary for representing and interpreting the result in terms of its base, the offset typically arising from the quadratic formula's discriminant, and any contextual modifications by a factor. Instances of this class are designed to interact with the Factor type in performing various operations such as evaluating, converting, or rendering the solution accurately in diverse contexts.

Attributes

Constructor

Creates a new instance of QuadraticSolution.

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Algebraic
trait Solution
trait Eager
trait DyadicOps
trait Approximate
trait Valuable
trait TypeSafe
trait Exactitude
trait Unitary
trait Zeroable
trait Numeric
trait Renderable
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def *(other: QuadraticSolution): Eager
def *(other: Algebraic): Algebraic

Multiplies this Algebraic by another Algebraic and returns the result.

Multiplies this Algebraic by another Algebraic and returns the result.

Value parameters

other

the other Algebraic to be multiplied with this

Attributes

Returns

a new Algebraic resulting from the multiplication

def *(r: Rational): Algebraic

Scales the quadratic solution using a given rational factor.

Scales the quadratic solution using a given rational factor.

This method computes a new quadratic solution by scaling the current solution's components (base and offset) with a specified rational multiplier. If any intermediate calculation fails, it returns None.

Value parameters

r

the scaling factor as a Rational value

Attributes

Returns

an Option containing the scaled quadratic solution if calculations succeed, otherwise None

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the scaling operation is not supported.

def *(other: Solution): Solution

Multiplies the current solution by another solution and returns the resulting solution.

Multiplies the current solution by another solution and returns the resulting solution.

Value parameters

other

the other solution to be multiplied with the current solution

Attributes

Returns

a new solution resulting from the multiplication

def +(other: Solution): Solution

Adds the specified solution to this quadratic solution, producing a new solution as a result.

Adds the specified solution to this quadratic solution, producing a new solution as a result.

This method supports the addition of solutions of type Algebraic. If the provided solution is of an unsupported type, an AlgebraException is thrown. When the solution is an instance of Algebraic, the addition is attempted using the add method, and any potential errors are recovered into an exception.

Value parameters

other

the solution to be added to this quadratic solution

Attributes

Returns

a new Solution representing the sum of this quadratic solution and the specified solution

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the addition with the specified solution is unsupported or leads to an error

def add(addend: Rational): Algebraic

Adds a Rational value to the current solution and returns a new Algebraic as the result. NOTE this only affects the base of this Algebraic.

Adds a Rational value to the current solution and returns a new Algebraic as the result. NOTE this only affects the base of this Algebraic.

Value parameters

addend

the Rational value to be added to the current solution

Attributes

Returns

a new Algebraic instance representing the sum of the current solution and the given addend

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the addition with the specified solution is unsupported or leads to an error

override def add(solution: Eager): Try[Algebraic]

Adds the specified solution to the current solution and returns an optional new solution that represents the result of the addition. The addition occurs only when the offset, factor, and negative properties of both solutions match the specified conditions.

Adds the specified solution to the current solution and returns an optional new solution that represents the result of the addition. The addition occurs only when the offset, factor, and negative properties of both solutions match the specified conditions.

CONSIDER rewriting this method in the style of its cousins.

Value parameters

solution

the solution to be added to the current solution

Attributes

Returns

an Option containing the resulting solution after the addition if the conditions are met, or None otherwise

Definition Classes
def approximation(force: Boolean): Option[Real]

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 Option containing the approximate value as a Real if available, or None if no approximation can be computed.

Computes the conjugate of the current quadratic solution.

Computes the conjugate of the current quadratic solution.

The conjugate is calculated by inverting the coefficient of the solution, effectively toggling between the two branches of the quadratic equation.

Attributes

Returns

a new QuadraticSolution instance representing the conjugate of the current solution

override def eqv(that: Eager): Try[Boolean]

Determines equivalence between the current Eager instance and another Eager instance.

Determines equivalence between the current Eager instance and another Eager instance.

This method checks if the current instance and the provided instance represent equivalent quadratic solutions. It performs a specific comparison for instances of QuadraticSolution, verifying equality of their base, offset, and coefficient components. For other cases, it delegates the equivalence check to the superclass implementation.

Value parameters

that

the other Eager instance to be compared for equivalence

Attributes

Returns

Try[Boolean] indicating either the result of the equivalence comparison or an error if the comparison cannot be performed

Definition Classes
override def fuzzyEqv(confidence: Double)(that: Eager): Try[Boolean]

Performs a fuzzy equivalence comparison between the current solution and another solution. The comparison allows for a degree of tolerance specified by the parameter p.

Performs a fuzzy equivalence comparison between the current solution and another solution. The comparison allows for a degree of tolerance specified by the parameter p.

Value parameters

confidence

the tolerance level for the fuzzy equivalence comparison; smaller values impose stricter equality conditions

that

the other solution to compare against, which must be of type Eager

Attributes

Returns

a Try[Boolean] indicating whether the two solutions are approximately equivalent within the specified tolerance, or an error if the comparison cannot be performed

Definition Classes
def multiply(solution: Algebraic): Option[Eager]

Scales the current solution by a given rational number. CONSIDER do we really need both * and scale?

Scales the current solution by a given rational number. CONSIDER do we really need both * and scale?

Value parameters

r

The rational number by which to scale the current solution.

Attributes

Returns

A new scaled solution.

def square: Eager

Computes the square of the current instance by multiplying it with itself.

Computes the square of the current instance by multiplying it with itself.

Attributes

Returns

The result of squaring the current instance.

def toMonotone: Option[Structure]

If this Solution can be represented as a Structure, return it wrapped in Some, otherwise return None.

If this Solution can be represented as a Structure, return it wrapped in Some, otherwise return None.

Attributes

Returns

an Option[Structure].

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the conversion is not supported.

Inherited methods

infix def *(factor: Int): Algebraic

Multiplies the current instance by the specified integer factor.

Multiplies the current instance by the specified integer factor.

Value parameters

factor

the integer value to multiply with the current instance

Attributes

Returns

a new instance of type T representing the result of the multiplication

Inherited from:
Scalable

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 Real if successful; throws an AlgebraException otherwise.

Inherited from:
Approximate
def approximationComplex(force: Boolean = ...): Option[Eager]

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 Option containing the approximate value as an Eager if successful, or None if no approximation is available.

Inherited from:
Approximate
def category: String

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
def compare(x: Eager, y: Eager): Try[Int]

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 Eager instance to compare

y

the second Eager instance to compare

Attributes

Returns

a Try[Int] that contains the comparison result: - 0 if x and y are equal, - a negative result if x is less than y, - and a positive result if x is greater than y. As the method is unimplemented, it will always return a failure with an AlgebraException.

Inherited from:
Eager
def describe: String

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
infix def divide(y: Eager): Try[Eager]

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 Eager instance 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
def fuzzy: Eager

Attempts to convert the current object to an instance of Eager using an approximation method. If the conversion fails, it recovers by throwing an AlgebraException with a descriptive error message.

Attempts to convert the current object to an instance of Eager using an approximation method. If the conversion fails, it recovers by throwing an AlgebraException with a descriptive error message.

Attributes

Returns

An instance of Eager if the approximation is successful.

Inherited from:
Eager
def fuzzyCompare(p: Double)(x: Eager, y: Eager): Try[Int]

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 Eager instance to be compared

y

the second Eager instance to be compared

Attributes

Returns

a Try[Int] representing the result of the comparison: - A negative integer if x is less than y - Zero if x is approximately equal to y within the tolerance p - A positive integer if x is greater than y - A Failure(AlgebraException) if the comparison cannot be performed

Inherited from:
Eager
def isExact: Boolean

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Attributes

Returns

true if this NumberLike object is exact in the context of No factor, else false.

Inherited from:
Algebraic
def maybeDouble: Option[Double]

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
def maybeFactor(context: Context): Option[Factor]

Determines the factor associated with this solution based on certain conditions. If the solution is a pure number, it returns Some(PureNumber). If the base value of the solution is zero, it returns Some(factor). Otherwise, it returns None.

Determines the factor associated with this solution based on certain conditions. If the solution is a pure number, it returns Some(PureNumber). If the base value of the solution is zero, it returns Some(factor). Otherwise, it returns None.

CONSIDER invoke normalize and then apply maybeFactor to the result.

Attributes

Returns

an Option of type Factor, where Some may contain the factor depending on the conditions, or None if no factor is applicable

Inherited from:
Algebraic
infix def multiply(y: Eager): Try[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.

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 Eager instance to multiply with this Eager instance

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
def product(other: Valuable): Valuable

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 Valuable instance to compute the product with

Attributes

Returns

a Valuable instance representing the product of this and the other instance

Note

throws AlgebraException if the computation involves unsupported Valuable types

Inherited from:
Valuable
def productElementNames: Iterator[String]

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
def productIterator: Iterator[Any]

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
def show: String

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
infix def subtract(y: Eager): Try[Eager]

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 Eager instance to be subtracted from this Eager instance

Attributes

Returns

a Try[Eager] containing the result of the subtraction if successful, or a failure if the operation fails

Inherited from:
Eager
def typeName: String

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

lazy val isPureNumber: Boolean

Determines if the current quadratic solution represents a pure number.

Determines if the current quadratic solution represents a pure number.

A solution is considered a pure number if its offset component is zero. This method relies on the Value.isZero utility to check whether the offset is zero.

Attributes

Returns

true if the offset of the solution is zero, otherwise false.

lazy val isUnity: Boolean

Determines if the current QuadraticSolution instance represents unity (1).

Determines if the current QuadraticSolution instance represents unity (1).

The solution is considered unity if its base component is equivalent to one (as verified by the conversion to a Rational) and its offset is zero.

Attributes

Returns

true if the solution represents unity, otherwise false.

lazy val isZero: Boolean

Checks if the solution represented by this instance is equivalent to zero.

Checks if the solution represented by this instance is equivalent to zero.

A solution is considered zero if both its base and offset components are zero values.

Attributes

Returns

true if both the base and offset are zero, otherwise false.

val maybeName: Option[String]

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, otherwise None

Negates the current quadratic solution by applying a negation operation to its offset component and then computing the conjugate.

Negates the current quadratic solution by applying a negation operation to its offset component and then computing the conjugate.

The negation is accomplished by using the Value.negate function on the solution's offset, and the resulting solution's conjugate is returned as a new instance of QuadraticSolution.

Attributes

Returns

a new QuadraticSolution instance that represents the negation and conjugation of the current quadratic solution

lazy val normalize: Eager

Normalizes this Valuable to its simplest equivalent form. This may change the type (e.g., RationalNumber → WholeNumber, Complex(5,0) → WholeNumber(5)).

Normalizes this Valuable to its simplest equivalent form. This may change the type (e.g., RationalNumber → WholeNumber, Complex(5,0) → WholeNumber(5)).

For Expression types, this will attempt to simplify and materialize if the result is exact. For Eager types, this will reduce to the simplest type representation.

Attributes

Returns

the simplest Valuable representation of this value

lazy val render: String

Method to render this NumberLike in a presentable manner. CONSIDER improve this in the event that offset itself is negative (as opposed to imaginary). However, that scenario is unlikely, I believe.

Method to render this NumberLike in a presentable manner. CONSIDER improve this in the event that offset itself is negative (as opposed to imaginary). However, that scenario is unlikely, I believe.

Attributes

Returns

a String

lazy val signum: Int

Determines the "sign" of the current quadratic solution.

Determines the "sign" of the current quadratic solution.

This method utilizes the signum method from the asField representation of the solution to evaluate its sign. The sign can indicate whether the solution is positive, negative, or zero based on its position relative to the origin in the Field domain.

Attributes

Returns

+1 if the solution is positive, -1 if negative, or 0 if it is at the origin.

Inherited fields

lazy val asMonotone: Structure

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
lazy val asNumber: Option[Number]

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 Option containing the instance as a Number if applicable, or None if not.

Inherited from:
Valuable
lazy val materialize: Eager

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 Eager instance representing the resolved value

Inherited from:
Eager
lazy val toDouble: Double

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