Contents
Sum , Product
Deep Breakdown
What it tells me (Situation Awareness): This is the generalization of Vieta's formulas to polynomials of any degree . For a degree- polynomial with roots , the sum of all roots equals and the product of all roots equals . This generalizes the quadratic Vieta formulas and is useful for verifying polynomial roots and building polynomials from constraints.
Flowchart
Real-world use
Where it is used
Polynomial regression root analysis, characteristic polynomial roots of matrices (eigenvalues in PCA/SVD), control theory (stability analysis), and verifying computed roots of higher-degree polynomials from numerical solvers.
Problem it solves
For degree polynomials, there is no general closed-form quadratic-style formula. Vieta's generalized formulas give coefficient-based constraints on the roots — useful for verification and for building polynomials from partial knowledge of their roots.
How it solves the problem
The polynomial can be factored as . Expanding and matching coefficients with yields the relationships between symmetric functions of roots and coefficients. The sum of roots comes from the term; the product from the (constant) term.
Example in a business
A cubic polynomial model has been solved numerically and gives roots . Quick verification: sum of roots should be ; product of roots should be . If the numerical solver returns roots that don't satisfy these, there's a numerical error to investigate.
The formula, piece by piece
For the polynomial: - : leading coefficient (coefficient of )
- : coefficient of (second-highest power)
- : constant term (coefficient of )
- : the roots (real or complex) Key Vieta formulas:
- Sum of all roots:
- Product of all roots: The in the product formula comes from the sign pattern when expanding .
The formula in words
"For any polynomial, the sum of all roots equals the negative of the second-highest coefficient divided by the leading coefficient. The product of all roots equals the constant term divided by the leading coefficient, with a sign that alternates by degree." Degree 2 (quadratic, ): sum , product . Matches Vieta's quadratic formulas exactly. Degree 3 (cubic, ): sum , product .
Critical Concepts
- Works for complex roots too. Even when roots are complex, the sum and product are determined by the (real) coefficients.
- "Counting multiplicity": a repeated root of multiplicity contributes times to the sum and to the product.
- Only sum and product are covered here. Full Vieta's formulas also give expressions for all elementary symmetric polynomials of the roots (e.g., ).
- Verification use: numerical root-finders can lose precision; Vieta's formulas provide a coefficient-based sanity check.
- Does not compute roots. These formulas relate coefficients to symmetric functions of roots — they do not solve the polynomial.
Step-by-step calculation (tiny example)
Step 1: Identify the degree, leading coefficient, second-to-leading coefficient, and constant term Polynomial: . Degree . , , .
Step 2: Compute sum of roots using Vieta's sum formula .
Step 3: Compute product of roots using Vieta's product formula . Numerical solver gives roots approximately , , . Sum and product (within numerical precision). Confirmed.
Code examples
Beginner example (Python)
import numpy as np
def vieta_sum_product(coefficients: list) -> dict:
""" Compute Vieta's sum and product of roots for a polynomial. Coefficients are given in descending order: [a_n, a_(n-1), ..., a_1, a_0] Args: coefficients: List of coefficients [a_n, a_(n-1), ..., a_0] Returns: Dictionary with sum_of_roots, product_of_roots, and degree """
n = len(coefficients) - 1 # degree
a_n = coefficients[0] # leading coefficient
a_n_minus_1 = coefficients[1] # second coefficient
a_0 = coefficients[-1] # constant term
sum_roots = -a_n_minus_1 / a_n
product_roots = ((-1)**n * a_0) / a_n
return { "degree": n, "sum_of_roots": sum_roots, "product_of_roots": product_roots, } # Example: 2x^3 - 6x^2 + 4x - 8 = 0
coeffs = [2, -6, 4, -8]
vieta = vieta_sum_product(coeffs)
print("Polynomial: 2x^3 - 6x^2 + 4x - 8 = 0")
print(f"Vieta's Sum of roots: {vieta['sum_of_roots']}")
print(f"Vieta's Product of roots: {vieta['product_of_roots']}") # Verify with numpy root finder
roots = np.roots(coeffs)
print(f"\nNumerical roots: {roots}")
print(f"Actual sum: {roots.sum().real:.6f}")
print(f"Actual product: {np.prod(roots).real:.6f}")Beginner example (R)
vieta_sum_product <- function(coefficients) { #' Compute Vieta's sum and product of roots. #' Coefficients in descending order: c(a_n, a_{n-1}, ..., a_0)
n <- length(coefficients) - 1
a_n <- coefficients[1]
a_nm1 <- coefficients[2]
a_0 <- coefficients[length(coefficients)] list( degree = n, sum_of_roots = -a_nm1 / a_n, product_of_roots = ((-1)^n * a_0) / a_n )
}
coeffs <- c(2, -6, 4, -8)
vieta <- vieta_sum_product(coeffs)
cat(sprintf("Degree: %d\n", vieta$degree))
cat(sprintf("Vieta's Sum of roots: %.4f\n", vieta$sum_of_roots))
cat(sprintf("Vieta's Product of roots: %.4f\n", vieta$product_of_roots)) # Verify with polyroot
roots <- polyroot(rev(coeffs)) # polyroot expects ascending order
cat(sprintf("\nActual sum: %.6f\n", Re(sum(roots))))
cat(sprintf("Actual product: %.6f\n", Re(prod(roots))))Professional example (Python)
import numpy as np
import pandas as pd # Scenario: validating polynomial roots returned by a numerical solver
# For each polynomial, compute Vieta's expected sum and product,
# then compare against the solver output to detect numerical errors
np.random.seed(42)
polynomials = [ {"label": "Quadratic", "coeffs": [1, -5, 6, 0 ][:3]}, # x^2 - 5x + 6
{"label": "Cubic", "coeffs": [2, -6, 4, -8 ]}, # 2x^3 - 6x^2 + 4x - 8
{"label": "Quartic", "coeffs": [1, -10, 35, -50, 24]}, # x^4 - 10x^3 + 35x^2 - 50x + 24
]
results = []
for poly in polynomials:
coeffs = poly["coeffs"]
n = len(coeffs) - 1 # Vieta's formulas
vieta_sum = -coeffs[1] / coeffs[0]
vieta_prod = ((-1)**n * coeffs[-1]) / coeffs[0] # Numerical roots
roots = np.roots(coeffs)
actual_sum = roots.sum().real
actual_prod = np.prod(roots).real
results.append({ "polynomial": poly["label"], "degree": n, "vieta_sum": round(vieta_sum, 6), "actual_sum": round(actual_sum, 6), "sum_ok": np.isclose(vieta_sum, actual_sum, atol=1e-6), "vieta_product": round(vieta_prod, 6), "actual_product": round(actual_prod, 6), "product_ok": np.isclose(vieta_prod, actual_prod, atol=1e-6), })
df = pd.DataFrame(results)
print("Vieta's Formula Verification for Polynomial Roots")
print()
print(df.to_string(index=False))
print(f"\nAll sums correct: {df['sum_ok'].all()}")
print(f"All products correct: {df['product_ok'].all()}")Professional example (R)
# Vieta verification for polynomial roots (polyroot)
polynomials <- list( list(label = "Quadratic", coeffs = c(1, -5, 6)), list(label = "Cubic", coeffs = c(2, -6, 4, -8)), list(label = "Quartic", coeffs = c(1, -10, 35, -50, 24))
)
results <- lapply(polynomials, function(p) { coeffs <- p$coeffs n <- length(coeffs) - 1 vieta_sum <- -coeffs[2] / coeffs[1] vieta_prod <- ((-1)^n * coeffs[length(coeffs)]) / coeffs[1] roots <- polyroot(rev(coeffs)) actual_sum <- Re(sum(roots)) actual_prod <- Re(prod(roots)) data.frame(polynomial = p$label, degree = n, vieta_sum = vieta_sum, actual_sum = actual_sum, sum_ok = isTRUE(all.equal(vieta_sum, actual_sum, tolerance = 1e-6)), vieta_product = vieta_prod, actual_product = actual_prod, product_ok = isTRUE(all.equal(vieta_prod, actual_prod, tolerance = 1e-6)))
})
df <- do.call(rbind, results)
cat("Vieta's Formula Verification\n")
print(df)
cat(sprintf("\nAll sums correct: %s All products correct: %s\n", all(df$sum_ok), all(df$product_ok)))Source: MFB p. 143