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
pandq. - Companion
- object
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Equationtrait Renderabletrait Branched[Expression]class Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
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
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 for this instance.
Returns the number of branches for this instance.
Attributes
- Returns
-
an
Intrepresenting the number of branches, which is always 2.
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
Rationalvalue 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
Rationalvalue representing the sum of conjugates.
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 aQuadraticSolutionor does not meet the required conditions for evaluation, anAlgebraExceptionwill 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 anEager, or a derivedRationalNumber, 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
Rationalvalue used to determine the shift applied to the equation.
Attributes
- Returns
-
a new
Quadraticinstance with its origin shifted according to the transformations.
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], whereSome(solution)contains the solution for the specified branch, orNoneif 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
pcomponent. - fQ
-
a function that transforms the
qcomponent.
Attributes
- Returns
-
a new
Quadraticinstance withptransformed usingfPandqtransformed usingfQ.
Inherited methods
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
Trepresenting the result of the multiplication - Inherited from:
- Scalable
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
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
Intrepresenting the discriminant.
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