ForHosting KIT · Developer Utilities

Completing the square

The completing the square API takes the three coefficients of a quadratic expression — a, b and c in ax² + bx + c — and rewrites it in completed-square form, also called vertex form: a(x − h)² + k.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

It returns the two parameters that define the transformation, h and k, together with the vertex of the parabola. The whole rewrite is one deterministic pass of arithmetic: h = −b/(2a) and k = c − b²/(4a). There is no solving, no guessing and no approximation beyond the rounding precision you ask for, so the same coefficients always produce the same vertex form. Use it to read off a parabola's vertex directly, to prepare an equation for solving, or to normalize quadratic terms in a larger pipeline — one call instead of working the algebra by hand.

What completing the square actually means

A quadratic written as ax² + bx + c tells you its shape only indirectly. The same expression rewritten as a(x − h)² + k tells you the two things most people actually want: where the parabola's vertex sits, at the point (h, k), and whether it opens upward or downward, from the sign of a. The technique behind the rewrite — completing the square — takes the x² and x terms and adds and subtracts exactly the constant needed to turn them into a perfect square trinomial, which then collapses into the squared binomial. Nothing about the expression changes: substitute any value of x into either form and you get the same number. What changes is what you can read off at a glance. The coefficient a is carried through untouched, so the leading coefficient you send is the same one that multiplies the squared term in the answer. The endpoint performs the rearrangement symbolically over the three numeric coefficients, which means it works for integer, decimal and negative values alike, and it refuses the single degenerate case — a equal to zero — where the expression is really a line and the completed-square form has no meaning.

How h and k are computed

The two parameters come from two closed-form identities. The horizontal shift is h = −b/(2a), which is exactly the x-coordinate of the parabola's axis of symmetry. The vertical shift is k = c − b²/(4a), the value the quadratic takes at that axis — equivalently, what you get by evaluating the original expression at x = h. Because these are exact formulas rather than an iterative procedure, the result is deterministic: run it twice on the same coefficients and you receive byte-identical output, which is what makes the response safe to cache, compare and embed in tests. Rounding is the only place where choice enters. By default h and k are rounded to ten decimal places so the output is stable across machines and languages; you can ask for anywhere between zero and fifteen places with the optional precision field. Values that are exact integers stay integers regardless of precision, so 2x² − 8x + 5 returns h = 2 and k = −3, not 2.0000000000. Coefficients may be sent as numbers or as numeric strings, and every coefficient must be finite — Infinity and NaN are rejected with a clear error rather than silently producing nonsense.

Where it fits in practice

Completing the square is rarely the final goal; it is the step that unlocks the next one. It is the standard route to the quadratic formula, the fastest way to find a vertex without calculus, and the move that turns the equation of a circle or an ellipse into its center-radius form. In a teaching product it lets you show the vertex form alongside the standard form so students see the connection. In a graphics or physics pipeline it converts a fitted quadratic into a peak position and value directly: fit ax² + bx + c to your samples, send the three coefficients, and read the maximum or minimum off k. In an optimization service it normalizes quadratic penalty terms before handing them to a solver. The capability runs as pure arithmetic on our edge with nothing stored, and the same code runs free in your browser on this page — paste the three coefficients, see the vertex form, and pay only when you wire it into an automated flow at $0.002 per request.

Find a parabola's vertex without calculus

Send a, b and c and read the vertex (h, k) straight off the vertex form — no derivative, no graphing step.

Prepare an equation for solving

Convert ax²+bx+c to a(x−h)²+k so the roots fall out as x = h ± √(−k/a), the same route that derives the quadratic formula.

Extract a fitted peak in a data pipeline

Fit a quadratic to sampled measurements, then send its coefficients here to get the peak position h and peak value k as clean numbers.

What does it cost?

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

What exactly does it return?

The coefficient a unchanged, the vertex parameters h and k, the rewritten form as a string a(x−h)²+k, and the vertex as an (x, y) point.

Why does it reject a = 0?

Because with a zero leading coefficient the expression is linear, not quadratic, and the completed-square form is undefined — dividing by 2a would not make sense.

Can I send the coefficients as strings?

Yes. Numbers and numeric strings are both accepted, but every coefficient must be a finite number; Infinity and NaN are rejected.

How are the results rounded?

h and k are rounded to ten decimal places by default; you can set precision from 0 to 15. Exact integers are returned as integers at any precision.

Is anything stored?

No. The computation is pure arithmetic on the three coefficients you send; nothing is logged or kept.

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/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/completing-the-square \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":2,"b":-8,"c":5}'
{
  "a": 2,
  "b": -8,
  "c": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.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.

Read the full KIT documentation →