Add or subtract polynomials
(2x² − 5) + (x + 3) gives 2x² + x − 2. Type each polynomial's coefficients from the highest power down to the constant; polynomials of different degree are lined up from the constant term and missing terms count as zero. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- First text
- 2, 0, -5
- Second text
- 1, 3
- Op
- add
- Operation
- add
- Coefficients
- 2, 1, -2
- Degree
- 2
The two inputs do not need the same degree: missing terms are treated as zero and the arrays are aligned from the constant term. It is one deterministic call that replaces the error-prone step of lining up terms by hand, whether you are building a symbolic math tool, checking homework, or combining fitted models.
Coefficient arrays instead of strings
Parsing is where the bugs live: a missed caret, an implicit multiplication, a term written out of order. This capability skips the whole problem by accepting the polynomial in the form software already uses internally — a plain array of numbers, one coefficient per term, ordered from the highest degree down to the constant. The polynomial 3x^4 - 2x + 7 is simply [3, 0, -2, 7], where the zero keeps the missing cubic and quadratic terms honest.
Because the input is data rather than notation, there is nothing to misinterpret: element zero is always the leading coefficient, the last element is always the constant term, and the degree is always the array length minus one. That convention is the same one used by NumPy, MATLAB and most computer algebra systems, so arrays you already produce elsewhere drop straight in without a conversion layer or a regex.
How addition and subtraction are computed
Adding or subtracting polynomials is term-by-term arithmetic on matching degrees, and the only subtlety is alignment. The two input arrays may have different lengths because the polynomials have different degrees, so the algorithm aligns them from the right — from the constant term — and treats every missing term as zero. Sending [2, 0, -5] and [1, 3] with op set to subtract therefore means (2x² − 5) − (x + 3), which yields [2, -1, -8], not some left-aligned guess.
The result is returned with the operation that was applied, the resulting coefficient array in the same highest-degree-first convention, and the degree of the result, which may be lower than either input when the leading terms cancel — subtracting x² from x² + 1 leaves degree zero. Everything is deterministic: the same input always produces byte-identical output.
What you can do with it
Combine fitted curves
A regression pipeline returns two polynomial fits as coefficient vectors; add them to model the combined effect before evaluating or plotting the result.
Check algebra homework programmatically
A tutoring app verifies a student's answer to (2x² − 5) − (x + 3) by comparing coefficient arrays instead of parsing fragile free-text input.
Difference two calibration models
Subtract the coefficients of an old calibration polynomial from a new one to quantify exactly how much each term drifted between calibrations.
FAQ
What order are the coefficients in?
Highest degree first, constant term last: [2, 0, -5] means 2x² − 5. The output uses the same convention.
Do the two polynomials need the same degree?
No. Arrays of different lengths are aligned from the constant term and missing terms count as zero.
How do I subtract instead of add?
Set the op field to 'subtract' to compute a − b. It defaults to 'add'.
Is the input stored anywhere?
No. The arrays are processed in memory and discarded; only the resulting coefficients are returned.
What happens when the leading terms cancel out?
The result ends up with a lower degree than the inputs. Subtracting x² from x² + 1 leaves only the constant 1, so the result has degree zero, and the tool reports that lower degree together with the coefficients.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/add-subtract-polynomials \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":[2,0,-5],"b":[1,3]}'const res = await fetch("https://api.kit.forhosting.com/math/add-subtract-polynomials", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": [
2,
0,
-5
],
"b": [
1,
3
]
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/add-subtract-polynomials",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": [
2,
0,
-5
],
"b": [
1,
3
]
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/add-subtract-polynomials", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":[2,0,-5],"b":[1,3]}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":[2,0,-5],"b":[1,3]}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/add-subtract-polynomials", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"a": [
2,
0,
-5
],
"b": [
1,
3
]
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.add_subtract_polynomials",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_coefficients | 10000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The add subtract polynomials API takes two polynomials expressed as plain arrays of coefficients — highest degree first, so [2, 0, -5] means 2x² − 5 — and returns the coefficient array of their sum or their difference. The same code that answers paid API requests runs free in your browser on this page, so you can verify a result before you ever automate it.
Coefficient arrays instead of strings
Most people meet polynomials as text like 3x^4 - 2x + 7, and the first instinct is to send that string to an API and hope it parses.
How addition and subtraction are computed
Every element of both arrays must be a finite number: a string, a null, a NaN or an Infinity is rejected with an invalid_input error that names the offending array and index, and invalid requests are never charged.
Where it fits in a pipeline
Polynomial arithmetic sounds academic until you count how often it appears in ordinary engineering. Curve fitting libraries hand you coefficient vectors that need to be combined before evaluation; control systems add transfer-function numerators; error-correcting codes and signal processing chains operate on polynomials over real coefficients; and any symbolic math feature in a tutoring or assessment product needs this operation as a primitive before it can do anything more ambitious. The endpoint runs on our global edge with nothing persisted — the arrays are processed in memory and discarded — and the pricing is flat and boring on purpose: $0.002 per request regardless of degree, with the per-request result identical to what the free on-page calculator produces. That parity is what lets you prototype by hand on the page and ship the same call to production without a migration step.
Technical questions
What does it cost?
$0.002 per request. It is also free to run in your browser on this page, with identical results.
What happens with a non-numeric coefficient?
The request is rejected with an invalid_input error naming the array and index, and it is not charged.