ForHosting KIT · Math

Integration by completing the square

The integral of 1 over x² + 2x + 5 is 0.5 times the arctangent of (2x + 2)/4, plus C. Enter the three coefficients of the quadratic and see each step: the completed square, the shift, the remainder and the final antiderivative. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
A
1
B
2
C
5
You get
Discriminant
-16
H
-1
K
4
Completed square
((x + 1)^2 + 4)

arctangent antiderivative, free

Why completing the square turns this integral into arctangent

The integral of dx/(x²+1) is arctan(x), one of the first results in any calculus course. Completing the square is the algebraic move that reduces a whole family of integrals to that single known case. Any quadratic ax²+bx+c with a non-zero leading coefficient can be rewritten as a((x−h)²+k), where h = −b/(2a) is the horizontal shift and k = c − b²/(4a) is what remains after the shift.

When the discriminant b²−4ac is negative, k is strictly positive relative to a, so the denominator is a constant times a sum of squares, (x−h)²+k. Factoring k out of that sum produces the shape 1 + ((x−h)/√k)², and the substitution u = (x−h)/√k converts the integral directly into a multiple of ∫du/(u²+1). The result is an arctangent whose argument is linear in x and whose leading constant absorbs every scale factor introduced along the way.

What you get back and how to read it

You send the three coefficients a, b, and c of the denominator quadratic, plus an optional precision between 0 and 15 decimal places. The response starts by echoing the coefficients and reporting the discriminant d = b²−4ac, which must be negative for the arctangent form to exist. Every numeric field is rounded to your requested precision, and the same rounded values are the ones used inside the expression strings, so the text form and the numeric fields never disagree with each other.

If you differentiate the returned antiderivative symbolically, you recover 1/(ax²+bx+c) exactly; the derivation is documented in the source and in the formula field of every response, which states the identities used so a grader or a colleague can audit the method without reading any code.

Check calculus homework step by step

Compare your completed square, scale factor, and final arctangent expression against each intermediate field, not just a final answer.

Route integrals in a CAS pipeline

Use the discriminant check to send 1/quadratic integrals to the arctangent branch or the logarithmic branch automatically, with errors as the routing signal.

Generate antiderivatives for rational-function physics models

Damped and forced systems often produce 1/(ax²+bx+c) terms; get a closed-form antiderivative with controlled precision for downstream evaluation.

Which integrals does it handle?

Exactly ∫ dx/(ax²+bx+c) where the discriminant b²−4ac is negative. That is the family whose antiderivative is a constant times arctangent of a linear expression.

What do h and k mean in the response?

They are the completed-square parameters: ax²+bx+c = a((x−h)²+k), with h = −b/(2a) and k = c − b²/(4a).

How do I verify the result?

Differentiate (2/s)·arctan((2ax+b)/s) with s = √(4ac−b²); the chain rule gives 4a/(s²+(2ax+b)²), which simplifies back to 1/(ax²+bx+c). The formula field in each response states these identities.

What input formats are accepted for the coefficients?

Numbers or decimal strings, with optional scientific notation, up to a magnitude of 1e15. The precision option, 0 to 15 decimal places, controls rounding of every numeric field in the response.

What happens when the discriminant is zero or positive?

The arctangent form does not apply, so you get a clear message instead of a guessed answer. With real roots the denominator factors, and the integral belongs to the logarithmic form found through partial fractions.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/integration-by-completing-the-square

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/integration-by-completing-the-square \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":1,"b":2,"c":5}'
{
  "a": 1,
  "b": 2,
  "c": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.integration_by_completing_the_square",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs_coeff1000000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

The integration by completing the square API finds the antiderivative of one over a quadratic, 1/(ax²+bx+c), when the quadratic has no real roots. It rewrites the denominator as a completed square a((x−h)²+k), applies the standard arctangent identity, and returns the full result: the discriminant, the vertex shift h, the remainder k, the scale factor s, and the final antiderivative (2/s)·arctan((2ax+b)/s) + C as a readable expression. When the discriminant is zero or positive the arctangent form does not apply, and the API says so instead of guessing, because that case belongs to the logarithmic form with partial fractions.

Why completing the square turns this integral into arctangent

The integration by completing the square endpoint performs exactly this sequence and exposes each intermediate quantity, so you can check the algebra step by step rather than trusting a black box that returns only a final formula.

What the API returns and how to read it

It then gives h and k from the completed square a((x−h)²+k), rendered as a readable string in the completed_square field. The scale s = √(4ac−b²) and the coefficient 2/s follow, and finally the arctan_argument and the full antiderivative string, (2/s)·arctan((2ax+b)/s) + C.

When the answer is an error, and why that is correct

A negative discriminant is not a technicality; it is the dividing line between two different antiderivative families. When b²−4ac is positive, the quadratic has two distinct real roots, the denominator factors over the reals, and the integral splits by partial fractions into a sum of logarithms. When the discriminant is zero, the quadratic is a perfect square and the integral is a rational function, again with no arctangent involved. Returning an arctangent expression in either case would be silently wrong, so the API rejects both with a clear invalid_input error that states the discriminant value and explains which form actually applies. The same strictness covers a = 0, which makes the denominator linear and the integral a plain logarithm. This fail-closed behavior matters in automated pipelines: a solver chain that feeds coefficients into this endpoint gets an explicit, parseable signal to route the problem to the logarithmic branch instead of a plausible-looking but incorrect formula propagating downstream.

What does it cost?

$0.002 per request. It is also free to run in your browser on this page.

What happens when the discriminant is zero or positive?

The request fails with an invalid_input error naming the discriminant value. Those cases integrate to logarithms or rational functions via partial fractions, and returning an arctangent would be wrong.

Read the full KIT documentation →