QuadraticEquation

com.phasmidsoftware.number.expression.algebraic.QuadraticEquation
See theQuadraticEquation companion object
case class QuadraticEquation(p: Rational, q: Rational) extends Equation

Represents a (monic) equation of the form x² + p*x + q = 0, where p and q are rational coefficients. A graph of this equation appears as follows: an upright parabola (where p and q are both positive and (½p)⋏2 > q):

        x                        |              x
         x                       |             x
           x                     |            x
              x              > ½p <         x
     -------------x----------+---|-------x------------------ v
                       x         |  x                        q
     - - - - - - - - - - - - x - + - - - - - - - - - - - - - ⋏
                                 |

The roots of the equation (if such exist) are at -w ± √(w∧2-q) where w = ½p For more information regarding quadratic equations, see: https://en.wikipedia.org/wiki/Quadratic_equation

Value parameters

p

the coefficient of the linear term (x).

q

the constant term of the equation.

Attributes

Constructor

Creates an instance of the equation with coefficients p and q.

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Equation
trait Renderable
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

infix def *(x: Rational): Equation

Scales the current instance by the given factor.

Scales the current instance by the given factor.

This method applies a scaling operation on the instance using the provided rational factor and returns the resulting scaled instance.

Value parameters

x

the rational number representing the scale factor

Attributes

Returns

the scaled instance of type T

def branched(index: Int): Expression

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 T at the specified branch index. If the index is out of range, the behavior is implementation-specific.

def branches: Int

Returns the number of branches for this instance.

Returns the number of branches for this instance.

Attributes

Returns

an Int representing the number of branches, which is always 2.

def canEqual(other: Any): Boolean

Determines if the given object can be considered equal to this instance. This method is used to support the implementation of the equality operation.

Determines if the given object can be considered equal to this instance. This method is used to support the implementation of the equality operation.

Value parameters

other

the object to be compared against this instance

Attributes

Returns

true if the given object is an instance of Algebraic_Quadratic; false otherwise

Computes the product of the conjugate roots of the quadratic equation represented by this instance. The product of the conjugates is determined directly from the coefficients of the quadratic equation and is equivalent to the constant term divided by the leading coefficient.

Computes the product of the conjugate roots of the quadratic equation represented by this instance. The product of the conjugates is determined directly from the coefficients of the quadratic equation and is equivalent to the constant term divided by the leading coefficient.

This is a special case of Vieta's formula for the product of the roots of a polynomial.

Attributes

Returns

a Rational value representing the product of the conjugate roots of the quadratic equation.

Computes the sum of the conjugates for this instance of Quadratic. The sum of conjugates is mathematically derived as the negation of the p coefficient in a quadratic equation of the form x∧2 + p*x + q = 0.

Computes the sum of the conjugates for this instance of Quadratic. The sum of conjugates is mathematically derived as the negation of the p coefficient in a quadratic equation of the form x∧2 + p*x + q = 0.

Attributes

Returns

a Rational value representing the sum of conjugates.

def evaluate(solution: Solution): Eager

Evaluates the provided solution to compute the corresponding eager result. The solution must conform to specific constraints based on its classification (e.g., being a QuadraticSolution and Algebraic). The computation involves operations such as multiplication, scaling, addition, and normalization, with specific handling of quadratic and algebraic results.

Evaluates the provided solution to compute the corresponding eager result. The solution must conform to specific constraints based on its classification (e.g., being a QuadraticSolution and Algebraic). The computation involves operations such as multiplication, scaling, addition, and normalization, with specific handling of quadratic and algebraic results.

Value parameters

solution

the solution to be evaluated. Must be an instance of Solution. If the solution is not a QuadraticSolution or does not meet the required conditions for evaluation, an AlgebraException will be thrown.

Attributes

Returns

the resultant eager value of the evaluation. The result could be a solution in the form of a QuadraticSolution, a numerical result as an Eager, or a derived RationalNumber, depending on the computation path.

Note

Throws AlgebraException if the provided solution cannot be evaluated due to missing conditions, non-conformance to required types, or other incompatible states during evaluation.

Yields the inverse of this Equation. CONSIDER Does this make sense?? CONSIDER should we make it an abstract method on Equation?

Yields the inverse of this Equation. CONSIDER Does this make sense?? CONSIDER should we make it an abstract method on Equation?

Attributes

Shifts the origin of the equation by transforming its p and q components based on the provided transformation functions dependent on the parameter c.

Shifts the origin of the equation by transforming its p and q components based on the provided transformation functions dependent on the parameter c.

Value parameters

c

the Rational value used to determine the shift applied to the equation.

Attributes

Returns

a new Quadratic instance with its origin shifted according to the transformations.

def solve(branch: Int): Solution

Attempts to find a solution for a mathematical equation corresponding to the given branch. Solutions are represented as an instance of the Algebraic class. If appropriate, an Algebraic can be converted into Complex form.

Attempts to find a solution for a mathematical equation corresponding to the given branch. Solutions are represented as an instance of the Algebraic class. If appropriate, an Algebraic can be converted into Complex form.

Value parameters

branch

the branch index for which the solution is being sought. The branch index identifies specific solutions for equations that may have multiple solutions.

Attributes

Returns

an Option[Algebraic], where Some(solution) contains the solution for the specified branch, or None if no solution exists for the given branch.

Transforms the current instance of Quadratic by applying provided functions to the p and q components.

Transforms the current instance of Quadratic by applying provided functions to the p and q components.

Value parameters

fP

a function that transforms the p component.

fQ

a function that transforms the q component.

Attributes

Returns

a new Quadratic instance with p transformed using fP and q transformed using fQ.

Inherited methods

infix def *(factor: Int): Equation

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
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

Concrete fields

Computes the discriminant of a quadratic equation based on the formula p∧2 - 4 * q. The discriminant is a critical component in determining the nature of the roots of a quadratic equation. If the discriminant is positive, then there are two distinct roots; if negative, then there are no real roots; if zero, then there's a double root.

Computes the discriminant of a quadratic equation based on the formula p∧2 - 4 * q. The discriminant is a critical component in determining the nature of the roots of a quadratic equation. If the discriminant is positive, then there are two distinct roots; if negative, then there are no real roots; if zero, then there's a double root.

Attributes

Returns

an Int representing the discriminant.

lazy val render: String

Method to render this Valuable for presentation to the user. NOTE to implementors: never ever invoke this.toString in your implementation lest you get a StackOverflow.

Method to render this Valuable for presentation to the user. NOTE to implementors: never ever invoke this.toString in your implementation lest you get a StackOverflow.

Attributes

Returns

a String