Polynomial composition calculator
Substitute one polynomial into another and get the expanded result: with f(x) = x² and g(x) = 1 + x, f(g(x)) is 1 + 2x + x², of degree 2. Each step is shown. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Runs in your browser. Free, unlimited — your data never leaves this page.
A polynomial composition calculator builds the expanded composite f(g(x)) from two coefficient lists. Enter the outer polynomial f and the inner polynomial g with the constant term first—so [1, 2, 1] means 1 + 2x + x squared and [0, 1] means x—and the tool returns the composition coefficients after substituting g into f, combining like terms, human-readable polynomial strings, formal degrees of f, g, and the composite, plus step-by-step Horner notes. Homework checks, exam prep, coding kata expected values, and change-of-variable demos all need the same substitution expansion without opening a computer-algebra system.
What f(g(x)) means and how coefficients are ordered
Function composition for polynomials means substitution: if f maps a value u to a0 plus a1 times u plus a2 times u squared and higher powers, and g maps x to b0 plus b1 times x and higher, then f of g of x is the polynomial you get by replacing every occurrence of u in f with the entire expression for g of x, expanding products of powers of g, and collecting like powers of x.
The result is again a univariate polynomial whose formal degree is the product of the formal degrees of f and g whenever both degrees are positive, or zero when f is a non-zero constant, or minus one for the zero polynomial. This tool uses the constant-term-first convention that dominates programming and numerical libraries: the array [a0, a1, a2, …, am] stands for a0 plus a1 times x plus a2 times x squared, up to am times x to the m.
The same convention applies to g and to the returned composition array. The algebraic expansion is performed with Horner's nested form a0 plus g times (a1 plus g times (a2 plus …)), so each step multiplies the running polynomial by g and adds the next outer coefficient—equivalent to expanding f of g and combining like terms, but with fewer intermediate multiplications. An all-zero coefficient list is valid and represents the zero polynomial with degree minus one.
Practical tips, limits, and related searches
Keep coefficient magnitudes inside the published absolute range and prefer modest degrees so the product of degrees stays well below the result length cap. Classic classroom checks include f equals x squared with g equals one plus x giving one plus two x plus x squared, f equals two plus three x with g equals one minus x giving five minus three x, and composing with the identity g equals x leaving f unchanged.
Prefer this capability when you already have both coefficient vectors and only need the expanded composite; if your source is a written expression, parse coefficients first. When you only need a product of two polynomials without substitution, use a dedicated multiplication tool instead. Round-trip checks are easy: recompute a few composition coefficients by hand from Horner or from expanding powers of g and confirm they match the published composition array within the same twelve-decimal rounding.
What you can do with it
Homework checks for f(g(x)) expansion
Students enter outer and inner coefficient lists from textbook composition problems and compare hand-expanded composites, degrees, and readable strings against a deterministic result before submitting.
Change-of-variable demos in calculus prep
Pipelines substitute a linear or quadratic change of variable into a higher-degree outer polynomial to build exam examples without a computer-algebra dependency.
FAQ
How are coefficients ordered?
Constant term first: [a0, a1, a2] means a0 + a1·x + a2·x². The composition uses the same low-to-high order.
Is the result f(g(x)) or g(f(x))?
Always f(g(x)): g is substituted into f. Swap the two arrays if you need the other order.
What happens if either list is empty?
An empty array is missing data, not the zero polynomial.
What is the degree of the composition?
When both formal degrees are positive, deg(f∘g) equals deg(f)·deg(g). Constants and the zero polynomial follow the usual algebra rules.
Is the polynomial composition calculator free?
The browser tool is free and runs locally.
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/algebra/polynomial-composition \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"f":[1,2,1],"g":[0,1]}'const res = await fetch("https://api.kit.forhosting.com/algebra/polynomial-composition", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"f": [
1,
2,
1
],
"g": [
0,
1
]
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/algebra/polynomial-composition",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"f": [
1,
2,
1
],
"g": [
0,
1
]
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/algebra/polynomial-composition", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"f":[1,2,1],"g":[0,1]}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"f":[1,2,1],"g":[0,1]}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/algebra/polynomial-composition", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"f": [
1,
2,
1
],
"g": [
0,
1
]
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "algebra.polynomial_composition",
"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_coeffs | 64 |
max_result_coeffs | 1025 |
max_abs | 1000000000000 |
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
Empty lists are rejected with a clear invalid_input error instead of inventing a zero polynomial by silence.
What f(g(x)) means and how coefficients are ordered
Empty coefficient arrays are not allowed: empty is missing data, not the zero polynomial, and the API returns invalid_input so homework scripts and grading pipelines fail loudly.
How to call the API and what comes back
The expanded composite may hold at most one thousand twenty-five coefficients; compositions whose degree product would exceed that bound are rejected before work starts. Send a JSON body with two required non-empty arrays of finite numbers: f (aliases outer, p, poly_f) for the outer polynomial and g (aliases inner, q, poly_g) for the inner polynomial that is substituted into f. Each array may hold at most sixty-four coefficients, and every absolute coefficient value must stay within one trillion so intermediate products remain finite in IEEE double precision on the Worker and in the browser. String numbers are accepted when they match a strict finite numeric pattern; JSON-encoded array strings are also accepted for clients that only send text fields. On success the response echoes rounded f and g, sets composition to the full expanded coefficient list (constant first), degree_f, degree_g, and degree to the formal degrees of the factors and the composite, f_str, g_str, and composition_str to compact human-readable polynomials with sensible signs and omitted unit coefficients, formula to a short English description of Horner composition, message to a one-line degree summary, and steps to an ordered array of substitution lines you can assert in tests. Failed validation—missing fields, empty arrays, non-arrays, non-finite entries, lists longer than the published maximum, values outside absolute limits, oversized results, or non-finite intermediates—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item.
Practical tips, limits, and related searches
Prefer sending genuine JSON arrays rather than pre-formatted strings when you control the client. Pair those successes with an empty f or empty g to document the hard invalid_input path. This landing targets people searching for a polynomial composition calculator, compose two polynomials online, expand f of g of x, or substitute one polynomial into another; it is not a multivariate composer, not a factorizer, and not a root finder. Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when learners deliberately send empty lists.
Integration use cases
Unit tests for student polynomial libraries
Generate known-good composition cases plus deliberate empty-list rejections for coding kata expected values and continuous integration fixtures.