sqcomp
Rewrites a quadratic in completed-square form.
Use sqcomp(...) in Nerdamer Notation. In JavaScript or TypeScript, completeSquare(...) returns the completed-square expression together with the quadratic coefficient, shift, remainder, and selected variable.
The direct API is available from the root nerdamer export and from nerdamer/algebra.
Examples
These examples use Nerdamer Notation.
Rewrite a quadratic as a shifted square plus a constant.
sqcomp(x^2+6*x+1)
// → -8+(3+x)^2Interfaces
The same operation is available through the interfaces below.
Nerdamer Notation
Use this form inside input passed to nerdamer(...).
sqcomp(arg1, [arg2])
nerdamer.completeSquare
Call the operation through the default nerdamer import.
nerdamer.completeSquare(expr: ExpressionInput, variable?: string): CompleteSquareResult
Parameters
| Name | Type | Description |
|---|---|---|
expr | ExpressionInput | Quadratic expression to rewrite. |
variable | string | Variable to use. Defaults to the first variable in the expression. |
Returns
CompleteSquareResult — The quadratic coefficient, shift, remainder, selected variable, and rewritten expression.
Direct JavaScript / TypeScript API
Import the operation directly from its package entry point.
import { completeSquare } from 'nerdamer/algebra';
(expr: ExpressionInput, variable?: string): CompleteSquareResult
Parameters
| Name | Type | Description |
|---|---|---|
expr | ExpressionInput | Quadratic expression to rewrite. |
variable | string | Variable to use. Defaults to the first variable in the expression. |
Returns
CompleteSquareResult — The quadratic coefficient, shift, remainder, selected variable, and rewritten expression.
Notes
- The parser form returns the completed-square expression. The JavaScript / TypeScript completeSquare(...) helper returns a CompleteSquareResult object whose expression field contains that expression.
Related API names
completeSquare
