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

Factor a quadratic.

factor(x^2+5*x+6)
// → (3+x)*(2+x)
Open in Playground

The leading coefficient doesn't have to be 1.

factor(6*x^2+5*x-6)
// → (-2+3*x)*(3+2*x)
Open in Playground

Factors are split as far as rational coefficients allow.

factor(x^4-1)
// → (1+x)*(-1+x)*(1+x^2)
Open in Playground

x^2-2 would need irrational coefficients, so it stays as it is.

factor(x^2-2)
// → -2+x^2
Open in Playground

A repeated factor is written as a power.

factor(x^3+3*x^2+3*x+1)
// → (1+x)^3
Open in Playground

Common factors come out first, in several variables too.

factor(x^2*y+x*y^2)
// → y*x*(x+y)
Open in Playground

A rational constant comes out in front.

factor(1/3*x^2-1/3)
// → (1/3)*(1+x)*(-1+x)
Open in Playground

An integer is split into primes.

factor(4677271)
// → 2089*2239
Open in Playground

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

← Back to Function reference