AFTD Auto-Formalizing Theoretical Domains

quadratic_eval_complete_square

theoremverified

For any degree-2 integer polynomial $h$, $4 a h(x) = (2ax + b)^2 - \Delta$, where $a = h_2, b = h_1, c = h_0$ and $\Delta = b^2 - 4ac$ is the discriminant.

Statement

theorem quadratic_eval_complete_square (h : Polynomial ℤ) (hdeg : h.degree = 2) (x : ℤ) :
    4 * h.coeff 2 * h.eval x = (2 * h.coeff 2 * x + h.coeff 1) ^ 2 - discrim (h.coeff 2) (h.coeff 1) (h.coeff 0)
Source
step towards op_153_subexp_bound_intersective_quadratic
Verified
20 Oct 2026
Axioms
Classical.choiceQuot.soundpropext

The proof, explained

The proof first expresses the value h(x) of the degree-2 polynomial explicitly as ax² + bx + c, where a, b, c are its quadratic, linear, and constant coefficients. Substituting this expression into the goal and unfolding the definition of the discriminant Δ = b² - 4ac reduces the claim to the algebraic identity 4a(ax² + bx + c) = (2ax + b)² - (b² - 4ac). Both sides expand identically to 4a²x² + 4abx + 4ac, concluding the proof by ring arithmetic.

  1. The evaluation of h at x is given by h(x) = ax² + bx + c, where a = h₂, b = h₁, and c = h₀ are the coefficients of h.

    Because h has degree 2, its degree is at most 2, so by `Polynomial.eq_quadratic_of_degree_le_two` it can be written explicitly as C(a) * X² + C(b) * X + C(c). Applying evaluation at x to both sides via `congr_arg` and distributing the evaluation across addition, multiplication, constants, powers, and the indeterminate X (`Polynomial.eval_add`, `Polynomial.eval_mul`, `Polynomial.eval_C`, `Polynomial.eval_pow`, `Polynomial.eval_X`) reduces the right-hand side to ax² + bx + c.

    lines 4–7

    uses congr_arg, Polynomial.eq_quadratic_of_degree_le_two, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_X

      have h2 : h.eval x = h.coeff 2 * x ^ 2 + h.coeff 1 * x + h.coeff 0 := by
        have := congr_arg (Polynomial.eval x) (Polynomial.eq_quadratic_of_degree_le_two hdeg.le)
        simp only [Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_X] at this
        exact this
  2. 4a · h(x) = (2ax + b)² - Δ

    Rewriting h(x) with the expression ax² + bx + c and unfolding the definition of the discriminant Δ = b² - 4ac (`discrim`), the equation becomes 4a(ax² + bx + c) = (2ax + b)² - (b² - 4ac). Expanding both sides yields 4a²x² + 4abx + 4ac, so the equality holds by standard ring arithmetic.

    lines 8–10

    uses discrim

      rw [h2]
      unfold discrim
      ring
congr_arg
If two elements are equal, applying any function to both produces equal results: a₁ = a₂ implies f(a₁) = f(a₂).
discrim
The discriminant of a quadratic with coefficients a, b, and c is defined as b² - 4ac.
Polynomial.eq_quadratic_of_degree_le_two
Any polynomial of degree at most 2 equals C(a) * X² + C(b) * X + C(c), where a, b, c are its degree 2, 1, and 0 coefficients.
Polynomial.eval_add
Evaluating a sum of polynomials at x gives the sum of their evaluations at x: (p + q)(x) = p(x) + q(x).
Polynomial.eval_C
Evaluating a constant polynomial C(a) at x gives the constant a.
Polynomial.eval_mul
Evaluating a product of polynomials at x gives the product of their evaluations at x: (p * q)(x) = p(x) * q(x).
Polynomial.eval_pow
Evaluating a power of a polynomial at x gives the power of its evaluation: (pⁿ)(x) = (p(x))ⁿ.
Polynomial.eval_X
Evaluating the indeterminate X at x gives x.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

/-- For any degree-2 integer polynomial h, 4 * a * h(x) = (2 * a * x + b)^2 - discr(a, b, c), where a = h.coeff 2, b = h.coeff 1, c = h.coeff 0. -/theorem quadratic_eval_complete_square (h : Polynomial ℤ) (hdeg : h.degree = 2) (x : ℤ) :    4 * h.coeff 2 * h.eval x = (2 * h.coeff 2 * x + h.coeff 1) ^ 2 - discrim (h.coeff 2) (h.coeff 1) (h.coeff 0) := by  have h2 : h.eval x = h.coeff 2 * x ^ 2 + h.coeff 1 * x + h.coeff 0 := by    have := congr_arg (Polynomial.eval x) (Polynomial.eq_quadratic_of_degree_le_two hdeg.le)    simp only [Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_X] at this    exact this  rw [h2]  unfold discrim  ring
See it in the graphDiscuss this resultChallenge it