Algebra

Expression Calculator

The expression calculator parses what you type, applies the correct order of operations and shows each reduction. It supports +, −, ×, ÷, exponentiation with ^, modulo with %, parentheses, the constants pi and e, and the functions sqrt, cbrt, abs, sin, cos, tan, ln, log and exp.

Expression Calculator

Evaluate arithmetic with correct order of operations.

Try:
Answer29
  1. Apply -4 - 1 = 3
  2. Apply ^3 ^ 2 = 9
  3. Apply *3 * 9 = 27
  4. Apply +2 + 27 = 29

The order, made visible

Written mathematics is not read left to right. Multiplication binds more tightly than addition, exponentiation more tightly than either, and brackets override all of it — so 2 + 3 × 4 is 14, not 20. Those conventions make an expression unambiguous, and also make a long one easy to evaluate in the wrong order.

This calculator applies them exactly and shows its work. Each reduction is reported as its own line, so the result comes with the sequence of operations that produced it rather than as a single number.

Most calculators show only an answer, which is useless when it disagrees with yours. Here every reduction is listed in the order performed, so a disagreement traces to one operation instead of prompting a fresh attempt.

That makes the tool as useful for checking your understanding of precedence as for arithmetic. The sequence of steps is a direct readout of how the expression was grouped.

How to use this calculator

  1. Type the expression The four arithmetic operations, ^ for powers, % for modulo, and brackets. The constants pi and e are recognised by name, as are the functions sqrt, cbrt, abs, sin, cos, tan, asin, acos, atan, ln, log and exp.
  2. Use brackets wherever intent matters Precedence is applied strictly, so brackets are the only way to override it. They cost nothing and remove all ambiguity.
  3. Read the steps in order Each line names the operation applied and the two values it combined. Following them from top to bottom reconstructs the grouping the parser chose.

How the expression is evaluated

The input is first broken into tokens: numbers, operators, brackets, and names resolving to a constant or a function. Implicit multiplication is inserted during this pass, so 2(3 + 1) is understood as a product even though no operator was typed.

Those tokens are reordered by the shunting-yard algorithm into reverse Polish notation, a form in which each operator follows the values it acts on and no brackets are needed. This is where precedence — the convention taught as PEMDAS or BODMAS — is actually applied: an operator waits on a stack until it meets one that binds less tightly, then is emitted.

Associativity is handled at the same point, and it matters more than it looks. Addition and multiplication group to the left, so subtraction chains evaluate in the order written. Exponentiation groups to the right, which is why 2^3^2 is 2^(3^2) = 512 rather than (2^3)^2 = 64 — a difference the notation itself does not signal.

The reordered expression is then evaluated on a stack, one operator at a time, and each reduction is recorded as it happens. Division and modulo by zero are rejected explicitly rather than allowed to produce infinity, and a result that is not a number at all is reported as undefined rather than displayed.

What each input means

expr Expression — form field “Expression”
The arithmetic to evaluate. It must be constant: this tool has no variables, and an x in the input is rejected rather than treated as an unknown.
pi, e Constants
Recognised by name and substituted with their numeric values. Writing pi/2 is the intended way to express common angles.
% Modulo
The remainder after division, binding as tightly as multiplication and division. A zero right-hand side is rejected, as it is for division.

Worked examples

Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.

Precedence and brackets together

Evaluate 2 + 3 * (4 - 1)^2. Every level of precedence appears once, which makes the step order easy to follow.

Inputs Expression = 2 + 3 * (4 - 1)^2

  1. Apply - 4 - 1 = 3
  2. Apply ^ 3 ^ 2 = 9
  3. Apply * 3 * 9 = 27
  4. Apply + 2 + 27 = 29

Result 29

The bracket is reduced first, then the power, then the multiplication, and the addition last. Reading the four step lines in sequence is the clearest possible statement of what precedence means in practice.

Evaluating strictly left to right would give a very different number. The steps show why: the addition, written first, is performed last.

Functions and a named constant

Evaluate sqrt(144) + sin(pi/2). This mixes an exact square root with a trigonometric value, and uses pi rather than a decimal approximation.

Inputs Expression = sqrt(144) + sin(pi/2)

  1. sqrt sqrt(144) = 12
  2. Apply / 3.14159 / 2 = 1.5708
  3. sin sin(1.5708) = 1
  4. Apply + 12 + 1 = 13

Result 13

Each function application gets its own step, showing the argument it received. That is worth checking, because a misplaced bracket changes the argument without making the expression invalid.

The sine is taken in radians, and pi/2 is a quarter turn, so it evaluates to 1. Entering 90 instead would be read as 90 radians and return something quite different — with no warning, since 90 is a perfectly valid input.

A tower of exponents

Evaluate 2^3^2. There are no brackets, so the answer is decided entirely by which way exponentiation associates.

Inputs Expression = 2^3^2

  1. Apply ^ 3 ^ 2 = 9
  2. Apply ^ 2 ^ 9 = 512

Result 512

The result is 512, because the expression is read as 2^(3^2) = 2^9. Left-to-right grouping would give (2^3)^2 = 64, and both readings look equally plausible from the notation alone.

The step order makes the choice explicit: the upper power is reduced first. Where a stacked exponent appears in real work, adding brackets is worth the keystrokes.

Reading the result

Angles are in radians

Every trigonometric function takes and returns radians, with no degree mode. Use pi to express common angles — pi/6, pi/4, pi/2 — or multiply a degree figure by pi/180 before passing it in.

What the step list is showing

Each line is one binary operation or one function application, in the order performed. The list is a record of the evaluation, not a rearrangement of your input for display, so it is exactly what the parser did.

Precision of the result

Arithmetic is done in floating point and shown to six significant figures. Whole-number results from whole-number inputs are exact within that range, but a chain of divisions can leave a value slightly off a round number.

When you would use this

Checking a hand-evaluated expression

When your answer differs from an expected one, the step list identifies which operation diverged. That is usually faster than recomputing, and it distinguishes an arithmetic slip from a misread grouping.

Settling a precedence question

For an expression whose grouping is genuinely ambiguous to the eye — stacked exponents, a unary minus before a power, mixed division and multiplication — the steps show which reading the standard conventions give.

Assumptions and limitations

What this calculator assumes

  • The expression is constant: no variables, and no equation to solve.
  • Standard precedence applies, with brackets highest, then exponentiation, then multiplication, division and modulo, then addition and subtraction.
  • Exponentiation associates to the right; all other binary operators associate to the left.
  • Trigonometric functions work in radians.

Where it stops being the right tool

  • Numeric evaluation only. There is no algebra, no simplification and no symbolic result.
  • No degree mode for trigonometry, and no factorial, permutation or combination operators.
  • Division and modulo by zero are refused rather than returning infinity, so limiting behaviour cannot be explored here.

Common mistakes

Entering an angle in degrees

Why it happens. Degrees are the everyday unit, and sin(90) is accepted without complaint — it is read as 90 radians, a perfectly ordinary number to raise no objection to.

How to avoid it. Write pi/2 for a right angle, or multiply your degree figure by pi/180. The function step shows the argument received, which makes the unit mistake visible.

Assuming stacked exponents group leftwards

Why it happens. Most operators associate to the left, so it is natural to expect the same of ^. Exponentiation is the exception, and the notation gives no hint.

How to avoid it. Bracket the intended grouping. If your answer for 2^3^2 was 64 rather than 512, this is the reason.

Trusting implicit multiplication in a long expression

Why it happens. Writing 2(3 + 1) works, so it is tempting to lean on it. Combined with division, expressions such as 6/2(1 + 2) become ambiguous to a reader even when the parser is consistent.

How to avoid it. Write the multiplication operator explicitly and bracket anything a reader might group differently. The step list shows what the parser did, but an expression others have to read should not require it.

Frequently asked questions

Which operators and functions are supported?

The four arithmetic operations, modulo with %, exponentiation with ^, and brackets. The named functions are sqrt, cbrt, abs, sin, cos, tan, asin, acos, atan, ln, log and exp, and the constants pi and e are recognised by name.

Does it follow order of operations?

Yes, strictly. Brackets first, then exponents, then multiplication, division and modulo, then addition and subtraction, with each level evaluated left to right except exponentiation, which groups to the right.

Are angles in degrees or radians?

Radians, with no degree mode. Use pi to write common angles — sin(pi/2) for a right angle — or convert by multiplying a degree value by pi/180 inside the expression.

Can I use variables such as x?

No. This tool evaluates constant arithmetic only, and an x in the input is rejected with a message pointing to the calculus tools, which take a function of x rather than a fixed expression.