Expression Notation Generator
Infix notation needs brackets and precedence rules to be unambiguous. Prefix and postfix need neither: the order of the operators alone fixes the grouping, which is why calculators and virtual machines work in postfix internally. This generates an expression, writes it all three ways, and evaluates each form with its own separate routine — so a conversion that quietly changed the grouping shows up as a different answer rather than passing unnoticed.
What this generator does
Builds a random expression tree, writes it out in all three notations, and then evaluates each written form with its own parser — recursive descent for infix, a stack for postfix, and a reversed stack for prefix.
How to use this tool
- Choose how deeply nested the expression should be.
- Read the same expression in all three notations.
- Try evaluating the postfix form yourself with a stack.
- Check your answer against the value shown.
Understanding the controls
- Expression depth
- How deeply the expression may nest. Depth 1 is a single operation; depth 4 produces something genuinely awkward to read in infix, which is rather the point.
- Seed
- Reproduces the same expression, which is useful when setting the same exercise twice.
Common use cases
- Practising reverse Polish notation with fresh expressions
- Teaching why prefix and postfix need no brackets
- Producing conversion exercises with verified answers
- Generating test input for an expression evaluator
- Showing how a stack machine evaluates arithmetic
How this generator works
An expression tree is built with numbers at the leaves and operators at the branches. Infix walks it adding brackets around every operation, prefix writes the operator before its operands, and postfix after them. Each written form is then evaluated by a separate routine rather than by walking the tree again: infix by recursive descent, postfix by pushing numbers and applying operators to the top of the stack, prefix by doing the same in reverse. All three results must equal the value the tree itself produces.
Randomness and fairness
Uses your browser's cryptographic random source to build the expression by default. A seed switches to a reproducible sequence, which is deterministic and not cryptographically secure.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Only addition, subtraction and multiplication appear, so division and its awkward cases are left out.
- The infix form is fully parenthesised, which sidesteps precedence entirely — real infix has to resolve it.
- Operands are small positive integers, so no negative literals or decimals appear.
- Expression trees are binary, so no unary operators are represented.
Privacy and your data
Expressions are generated and evaluated in your browser and never transmitted, stored or included in analytics.
Related generators
- Order of Operations Question GeneratorBODMAS/PEMDAS questions built so the order genuinely changes the answer, with worked steps.
- Decimal Arithmetic Question GeneratorDecimal addition, subtraction and multiplication questions with worked steps and an answer key.
- Binary Search Scenario GeneratorSorted lists with the full binary search trace, every step's range shown, and the logarithmic bound as the check.
- Algebra Substitution Question GeneratorSubstitution questions built to order — one letter, two letters, squares, brackets and division, all evaluating to whole numbers.