Sub topic 11
Sum and product of the roots
This chapter assumes you can use the quadratic formula, compute the discriminant, and expand a product such as (x − r)(x − s). It also assumes you have seen complex roots of the form p ± qi. The aim is to show how the roots of a quadratic relate to its coefficients, and how to use that relation to check answers and solve related problems.
The two relations
Take a quadratic in standard form, ax² + bx + c = 0 with a ≠ 0, and call its two roots r₁ and r₂. Then:
- Sum of the roots: r₁ + r₂ = −b/a
- Product of the roots: r₁ · r₂ = c/a
These relations are called Vieta's formulas. They hold whatever the sign of the discriminant. They give you two facts about the roots without solving anything.
| Equation | −b/a (sum) | c/a (product) | Roots |
|---|---|---|---|
| x² − 3x + 2 = 0 | 3 | 2 | 1, 2 |
| 2x² − 4x − 6 = 0 | 2 | −3 | −1, 3 |
| x² + 2x + 5 = 0 | −2 | 5 | −1 + 2i, −1 − 2i |
| x² − 6x + 9 = 0 | 6 | 9 | 3, 3 |
In the last row the root 3 is repeated, so it counts twice. Roots are always counted with multiplicity, which is why the relations hold when the discriminant is zero.
Why they are true
There are two short derivations. Each one shows something useful.
From the quadratic formula
Let d = b² − 4ac and let s be a square root of d. The roots are:
r₁ = (−b − s) / (2a) and r₂ = (−b + s) / (2a)
Adding them, the ±s terms cancel:
r₁ + r₂ = −2b / (2a) = −b/a
Multiplying them gives a difference of squares in the numerator:
r₁ · r₂ = (b² − s²) / (4a²) = (b² − (b² − 4ac)) / (4a²) = 4ac / (4a²) = c/a
Nothing here assumes d is positive. When d is negative, s is imaginary and s² is still d, so the same algebra works.
From factoring
If r₁ and r₂ are the roots, the quadratic factors as:
a(x − r₁)(x − r₂) = a(x² − (r₁ + r₂)x + r₁r₂) = ax² − a(r₁ + r₂)x + a·r₁r₂
Matching coefficients with ax² + bx + c gives b = −a(r₁ + r₂) and c = a·r₁r₂. These are the same two relations. This version also explains where they come from. The coefficients of a polynomial are determined by its roots.
Using the relations to check an answer
Suppose you solve 2x² − 4x − 6 = 0 and get x = −1 and x = 3.
- The sum should be −b/a = −(−4)/2 = 2. Indeed −1 + 3 = 2.
- The product should be c/a = −6/2 = −3. Indeed (−1)(3) = −3.
Both checks pass, so the roots are correct. This is faster than substituting each root into the original equation. It also works for complex roots. For x² + 2x + 5 = 0 with roots −1 ± 2i, the sum is (−1 + 2i) + (−1 − 2i) = −2, which equals −b/a. The product is (−1)² − (2i)² = 1 + 4 = 5, which equals c/a.
What each check actually tests
The sum and the product test different parts of the formula.
- The sum is −b/a whatever the discriminant is, because the ±√d terms cancel. A sum check therefore confirms the −b/(2a) part of your answer and says nothing about the radical. If you computed √d wrongly, the sum can still come out right.
- The product depends on d through b² − d. A product check tests the radical.
Always check both. A wrong radical passes the sum test and fails the product test. A sign error in −b fails both.
Together the two checks are conclusive. Only one pair of numbers has a given sum and product, apart from the order of the two numbers. If your pair matches both values, it is the pair of roots.
Checking in code
The function below solves a quadratic with cmath so it also handles negative discriminants, then tests both relations.
import cmath
def roots(a, b, c):
r = cmath.sqrt(b * b - 4 * a * c)
return (-b - r) / (2 * a), (-b + r) / (2 * a)
def check_roots(a, b, c, tol=1e-9):
r1, r2 = roots(a, b, c)
sum_ok = cmath.isclose(r1 + r2, -b / a, abs_tol=tol)
prod_ok = cmath.isclose(r1 * r2, c / a, abs_tol=tol)
return sum_ok, prod_ok
print(check_roots(2, -4, -6)) # (True, True)
print(check_roots(1, 2, 5)) # (True, True)The tolerance matters because floating-point arithmetic rarely gives an exact match. Comparing with == would sometimes fail on correct roots.
Building a quadratic from its roots
The relations also run in reverse. If you want roots r₁ and r₂, use the coefficients (a, −a(r₁ + r₂), a·r₁r₂). For a = 1 this is x² − (sum)x + (product).
def quadratic_from_roots(r1, r2, a=1):
return (a, -a * (r1 + r2), a * r1 * r2)
print(quadratic_from_roots(2, -5)) # (1, 3, -10)Check by hand: (x − 2)(x + 5) = x² + 3x − 10. The coefficients match.
Complex roots work the same way. Roots 3 + i and 3 − i have sum 6 and product 10, so the monic quadratic is x² − 6x + 10. For a quadratic with real coefficients, complex roots come as a conjugate pair, so the sum and product are real.
Reading the roots' signs without solving
Sometimes you only need to know whether the roots are positive or negative. The sum and product of the roots can tell you.
- If c/a < 0, the product is negative. Then ac < 0, so b² − 4ac > 0. The roots are real and have opposite signs. No other check is needed.
- If c/a > 0 and the discriminant is non-negative, the roots are real and have the same sign. Both are positive if −b/a > 0, and both are negative if −b/a < 0.
- If c/a > 0 and the discriminant is negative, the roots are complex, and the sign rules do not apply.
For example, x² − 7x + 3 = 0 has product 3 > 0 and sum 7 > 0. The discriminant is 49 − 12 = 37 > 0, so both roots are real and positive. The equation 5x² + x − 2 = 0 has product −2/5 < 0, so one root is positive and one is negative.
Sign arguments need real roots. Always confirm that the discriminant is non-negative before you conclude anything from the signs.
Finding integer roots by inspection
When a, b and c are integers and the roots are integers, the relations suggest a guess-and-check method. For x² − 7x + 12 = 0, look for two numbers with product 12 and sum 7. The factor pairs of 12 are 1·12, 2·6 and 3·4, and only 3 + 4 equals 7. So the roots are 3 and 4.
This is a fast shortcut when it works. It connects to the earlier chapter on perfect-square discriminants. If the discriminant is not a perfect square, the roots are irrational and no integer pair will match, so you should fall back on the quadratic formula.
Working with expressions in the roots
Many problems ask for an expression in r₁ and r₂ without asking for the roots themselves. The trick is to rewrite the expression using only r₁ + r₂ and r₁r₂.
- r₁² + r₂² = (r₁ + r₂)² − 2r₁r₂
- 1/r₁ + 1/r₂ = (r₁ + r₂) / (r₁r₂)
- (r₁ − r₂)² = (r₁ + r₂)² − 4r₁r₂
For x² − 3x + 1 = 0, the sum is 3 and the product is 1. Then r₁² + r₂² = 9 − 2 = 7, and 1/r₁ + 1/r₂ = 3/1 = 3. The roots here are (3 ± √5)/2, which are awkward to square directly, so the shortcut saves effort.
The third identity connects back to the discriminant. Since (r₁ − r₂)² = (−b/a)² − 4c/a = (b² − 4ac)/a², the discriminant satisfies b² − 4ac = a²(r₁ − r₂)². The discriminant measures how far apart the two roots are. It is zero exactly when the roots coincide.
A parameter problem
Find k so that one root of x² − 6x + k = 0 is twice the other.
- Call the roots r and 2r. The sum gives r + 2r = 6, so r = 2.
- The roots are 2 and 4. The product gives k = 2 · 4 = 8.
- Check the discriminant: 36 − 32 = 4 > 0, so the roots are real, as assumed.
Without the relations you would substitute the formula into the condition and solve a messier equation.
Common mistakes
- Forgetting the minus sign. The sum is −b/a, not b/a. For x² − 3x + 2, b = −3 and the sum is +3.
- Forgetting to divide by a. For 2x² − 4x − 6, the product is −6/2 = −3, not −6.
- Using the relations when the equation is not in standard form. Move every term to one side first.
- Treating the sum check as a full check. As shown above, it does not test the radical.
- Drawing sign conclusions when the roots might be complex.
A note on numerical computation
The product relation has a practical use in floating-point computation. When b² is much larger than 4ac, one of the two formula roots involves subtracting two nearly equal numbers, which loses accuracy. The stable method computes the larger-magnitude root first, then gets the other root from the product c/a.
import math
def stable_real_roots(a, b, c):
d = b * b - 4 * a * c
if a == 0 or d < 0:
raise ValueError("need a != 0 and a non-negative discriminant")
q = -(b + math.copysign(math.sqrt(d), b)) / 2
if q == 0:
return [0.0]
return [q / a, c / q]
print(stable_real_roots(1, -3, 2)) # [2.0, 1.0]Here q / a is one root, and c / q is the other, because (q/a) · (c/q) = c/a. The product relation produces the second root with no subtraction at all. The next chapter covers this problem in detail.
Exercises
Exercise
Without solving, find the sum and product of the roots of 3x² + 12x − 15 = 0. Then find the roots and verify both values.
Show answer
The sum is −b/a = −12/3 = −4 and the product is c/a = −15/3 = −5. Solving: d = 144 + 180 = 324, √d = 18, so x = (−12 ± 18)/6, giving 1 and −5. Check: 1 + (−5) = −4 and 1 · (−5) = −5. Both match.
Exercise
A quadratic with real coefficients has one root 2 − 3i and leading coefficient 1. Find the quadratic.
Show answer
The other root is the conjugate 2 + 3i. The sum is 4 and the product is 4 + 9 = 13. The quadratic is x² − 4x + 13.
Exercise
The roots of x² − 5x + 2 = 0 are r₁ and r₂. Find r₁² + r₂² and 1/r₁ + 1/r₂ without computing the roots.
Show answer
The sum is 5 and the product is 2. Then r₁² + r₂² = 5² − 2·2 = 21, and 1/r₁ + 1/r₂ = 5/2.
Exercise
A student solves x² − 4x + 1 = 0 and reports roots 2 + √5 and 2 − √5. The sum check passes. Does the product check pass? What does this show?
Show answer
The sum is 4, which equals −b/a, so it passes. The product is 4 − 5 = −1, but c/a = 1, so it fails. The correct roots are 2 ± √3, since d = 16 − 4 = 12. The wrong radical did not affect the sum, which shows that the sum check cannot detect a radical error.