Function reference · Algebra
factor
Factors a polynomial or an integer.
Notation
factor(expression)
Write it in an expression: nerdamer('factor(x^2+5*x+6)'), or in the Playground.
nerdamer.factor
nerdamer.factor(expression: ExpressionInput): Expression
A method on the default import. Arguments can be strings, as in Notation.
import { factor }
import { factor } from 'nerdamer/algebra';
factor(expression: ExpressionInput): Expression
Import only this function, from nerdamer/algebra.
Parameters
expression- A polynomial in one or more variables, or an integer.
Returns
The factored expression. A polynomial that can't be factored over the rationals comes back unchanged.
Examples
The leading coefficient doesn't have to be 1.
factor(6*x^2+5*x-6)
// → (-2+3*x)*(3+2*x)Open in PlaygroundFactors are split as far as rational coefficients allow.
factor(x^4-1)
// → (1+x)*(-1+x)*(1+x^2)Open in Playgroundx^2-2 would need irrational coefficients, so it stays as it is.
factor(x^2-2)
// → -2+x^2Open in PlaygroundCommon factors come out first, in several variables too.
factor(x^2*y+x*y^2)
// → y*x*(x+y)Open in PlaygroundA rational constant comes out in front.
factor(1/3*x^2-1/3)
// → (1/3)*(1+x)*(-1+x)Open in PlaygroundGood to know
- The order of the factors isn't fixed and can change between versions. To compare results, compare them with
expand, not as text. - To get the prime factors of an integer as a list, use
pfactor:pfactor(12)gives[2, 2, 3].
JavaScript examples
nerdamer.factor('x^2+5*x+6').text()
// → (3+x)*(2+x)