Function Calculator

A function calculator with four modes sharing one symbolic engine: evaluate f(x) at any value (exactly, in fractions, whenever the expression allows it), compose f(g(x)) and g(f(x)) by real substitution with domain conditions tracked through the composition, evaluate a piecewise-defined function piece by piece, and classify a function as linear or nonlinear from the structure of its expression, never from sampling points. Every mode plots what it computed.

Syntax: powers as x^2, multiplication as * or by juxtaposition (2x, 2(x+1)), and the functions sin, cos, tan, asin, acos, atan, exp, ln, log (base 10), sqrt and abs, plus pi and e. For composition, f(g(x)) means g is applied first; the tool always shows the order it used.

How to use this calculator

  1. Evaluate: type f(x) and a value (whole, decimal or fraction). The result is exact, as a fraction or simplified expression value, whenever the expression is built from arithmetic alone; values involving sin, sqrt of non-squares and the like come out as decimals, labelled as such by their form.
  2. Compose: type f and g; the tool substitutes one expression into the other both ways, prints the composed expressions, tracks the domain conditions the composition inherits, and evaluates both at your chosen x with the intermediate step shown.
  3. Piecewise: give each piece its expression and the condition under which it applies (or “otherwise”). At your x, the tool reports which piece fired, why, and its value, and shows every piece’s condition verdict in a table.
  4. Classify: the verdict (constant, linear, polynomial of a named degree, rational, or other nonlinear) is read off the expression’s structure, with the deciding feature named.

The method

Expressions are trees, and everything follows from that

Each expression is parsed into a tree once, and every mode works on that tree: evaluation walks it with your value; composition builds a new tree by substituting g’s tree for every x in f’s tree; domain analysis walks it collecting the conditions each operation imposes (denominators nonzero, logarithm arguments positive, square roots of non-negative values, inverse-trig arguments within [−1, 1]); and the linearity verdict reads the degree structure of the tree.

Why linearity is never judged from points

f is linear exactly when its expression reduces to a·x + b. Any two sample points lie on some line, so sampling can never prove linearity; only the structure can.

f(x) = x² passes through (0, 0), (1, 1) and (2, 4); the first two suggest the line y = x and the third refutes it, but a tool that “checks linearity” by sampling will believe whatever its samples suggest. The structural test here is immune: x² has degree 2, so it is nonlinear, full stop. The same structural reading names the degree of any polynomial and spots the common nonlinear culprits: a variable in a denominator (rational), under a root, inside a trig or exponential function, or raised to a variable or fractional power.

Composition and its domain

f(g(x)) inherits two layers of conditions: g must be defined at x, and f must be defined at g(x). Substituting g into f’s domain conditions produces the composed conditions directly: for f = √(x) composed with g = x − 3, the condition is x − 3 ≥ 0. The tool lists the conditions of the final composed expression, which is exactly that substitution carried out.

Worked examples

Example 1: the preloaded evaluation

f(x) = x² − 3x + 2 at x = 4: 16 − 12 + 2 = 6, exact. At x = 3/2 the same function gives 9/4 − 9/2 + 2 = −1/4, printed as the fraction it is.

Example 2: the preloaded composition

f(x) = x² − 1 with g(x) = 2x + 1: f(g(x)) substitutes to (2x + 1)² − 1, while g(f(x)) gives 2(x² − 1) + 1. At x = 1 the steps show g(1) = 3 then f(3) = 8, matching the composed expression evaluated directly: composition is not commutative, and the two directions are genuinely different functions.

Example 3: the preloaded piecewise function

x² when x < 0, and 2x + 1 when x ≥ 0: at x = −2 the first piece fires and gives 4; at x = 3 the second fires and gives 7; at the boundary x = 0 the second piece owns the point (its condition is ≥), giving 1, while the first piece’s formula would have given 0: at a boundary, the conditions, not the formulas, decide.

Example 4: classifications

3x − 7 is linear (degree 1, nothing else present). x² is nonlinear, a polynomial of degree 2. 1/x is nonlinear and rational (x in a denominator). sin(x) is nonlinear (x inside a trigonometric function). 5 is a constant function, the degree-0 edge case that is linear only under conventions that count it separately.

Reading your results

Exact first, decimal second. When a value prints as a fraction, that is the value; decimals shown for transcendental results are approximations and are formatted to six significant figures accordingly.

Domain conditions are part of the answer. Reporting f(−1) for √(x) as an error is not the tool failing; it is the function having no value there. The conditions listed with each result are the rules the function actually lives by, and any further work with the expression inherits them.

A composition’s steps are its proof. The intermediate line (g(1) = 3, then f(3) = 8) is not decoration: it is how a composition is checked by hand, and when the direct evaluation of the composed expression agrees with the stepped evaluation, the substitution is verified twice over.

Common mistakes

  • Reversing a composition. f(g(x)) applies g first. Reading it left to right applies f first and computes g(f(x)) instead, a different function with a different answer (Example 2’s two results differ for most inputs).
  • Judging linearity from a table of values. Any finite table can be fitted by a line through two of its points and by a curve through all of them. Linearity is a property of the expression, decided structurally, as the method section explains.
  • Evaluating outside the domain and blaming the tool. ln of a negative, a zero denominator, a root of a negative: undefined is the mathematically correct output. The conditions shown with the result say exactly which rule fired.
  • Forgetting the boundary owner in a piecewise function. At x = 0 exactly one piece applies, and it is the one whose condition includes the boundary. Overlapping or gappy condition sets answer wrongly or not at all; the verdicts table shows each piece’s status at your x so gaps and overlaps are visible.
  • Simplifying (2x + 1)² to 4x² + 1. Powers do not distribute over sums: (2x + 1)² = 4x² + 4x + 1. The composed expressions here keep (2x + 1)² unexpanded precisely so that step is never faked; expand it by hand if a polynomial form is needed.
  • Assuming composition inherits only the outer domain. Both layers bind: g must accept x and f must accept g(x). The printed conditions cover both, because they are read from the fully substituted expression.

Limitations

  • One variable, x. Functions of several variables, and equations relating x and y implicitly, belong to other tools.
  • Exact evaluation covers arithmetic expressions (powers with whole-number exponents and rational points); anything involving trig, roots of non-squares, logarithms or pi/e evaluates numerically to six significant figures.
  • Composed expressions are printed in substituted, structurally simplified form (collected constants and cancelled factors), not fully expanded into polynomial normal form; (2x + 1)² − 1 stays factored, by design, as the mistakes section notes.
  • Piecewise definitions accept up to three pieces with threshold conditions on x; conditions comparing expressions (x > y, |x| < 2 as a typed condition) are not part of the model, though |x| inside a piece’s expression works.
  • The plot shows the computed object over a standard window with an automatic vertical scale; sharp features between samples can be smoothed over, so treat the graph as orientation and the numbers as the result.

Frequently asked questions

What does f(g(x)) actually mean?

Apply g first, then apply f to g’s output. The notation (f ∘ g)(x) means the same. The order matters: with f = squaring-minus-1 and g = 2x + 1, f(g(1)) = f(3) = 8 while g(f(1)) = g(0) = 1. The composition mode always evaluates with the intermediate value shown, so the order in use is never ambiguous.

Why does the tool refuse to call x² linear when two of its points fit a line?

Because two points always fit a line, including points from circles, parabolas and sine waves. Linearity means the expression itself is a·x + b, a structural fact about the formula. Checking points can disprove linearity (a third point off the line) but can never prove it; the structural read here settles it directly.

When is an evaluation exact, and when is it a decimal?

Exact whenever the computation stays inside arithmetic: sums, products, quotients and whole-number powers of fractions stay fractions. The moment a transcendental step enters (a sine, a logarithm, a root of a non-square), the value is a decimal approximation, shown to six significant figures. The form of the printed answer tells you which kind you are holding.

What happens at a piecewise boundary?

The piece whose condition includes the boundary owns it. With x² for x < 0 and 2x + 1 for x ≥ 0, the value at 0 is 1, not 0, and the results table shows both pieces’ verdicts at your x so the ownership is explicit. If your conditions leave a gap, the tool says the function is undefined there rather than guessing; if they overlap, the first matching piece wins and the table shows that too.

Why is the composed expression not expanded into a polynomial?

Because the substituted form is the honest intermediate: (2x + 1)² − 1 shows exactly what substitution produced, and expanding it by hand is safe, while an automatic expansion invites the classic error of distributing a power over a sum. Constants are collected and factors cancelled during substitution, so the printed form is simplified, just not forcibly expanded.

Can it handle functions like √(x − 3) or ln(x)?

Yes: they parse, evaluate where defined, report as undefined outside their domains, and their conditions (x − 3 ≥ 0, x > 0) appear in the domain list. Composing them carries the conditions through the substitution, which is where such conditions are easiest to lose by hand.

Related calculators

Method: expressions are parsed into a tree (never evaluated as code) over exact fractions. Evaluation is exact for arithmetic expressions and floating point otherwise (six significant figures shown). Composition is tree substitution with domain conditions collected from the substituted result. Linearity and degree are read from the tree’s structure, never from sampled points. Last reviewed: 21 October 2026.

Disclaimer: This calculator gives estimates for general information only. It is not financial, medical or other professional advice.