Although Noung's writeup shows a good way for a human to factor a trinomial, trying to program an algorithm using that method would be horribly inefficient. It would have to first factor a and c, and then test every possible combination of factors until it finds the correct one. Luckily, there is another method that is much more efficient:
Start with
ax²+bx+c
as before, but first split the x
term into 2 parts, so that the
product of those two
coefficients equals the product of a and c. An easy way to do this would be to
iterate through the
integers between either ±
sqrt(ac) or ±b, whichever is greater, since this will cover all possible values. If none fits this, its
factorization is
irrational or
imaginary, and
another method will be necessary to factor it. If a number is found, however, the result will look like this:
(ax²+b
1x)+(b
2x+c)
where b
1b
2=ac. Next, factor out everything possible from both sets of
parentheses. The
binomials left inside each set of parentheses will be the same:
px(rx+s)+q(rx+s)
where pr=a, ps=b
1, qr=b
2, and qs=c. Finally, the
distributive property gives you
(px+q)(rx+s)
Example:
6x²+5x-4
First, find 2 numbers with a
sum of 5 and a
product of -24. They happen to be 8 and -3. So split the x
term up like this:
(6x²+8x)+(-3x-4)
Then, factor a 2x out of the first
binomial, and a -1 out of the second:
2x(3x+4)-1(3x+4)
Now, use the
distributive property to
factor it:
(2x-1)(3x+4)
Using this method, you don't need to factor any numbers, as you do in the normal method, and the amount of numbers you need to test to find the correct ones is also much smaller.