Polish Notation Calculator - Infix, Prefix, and Postfix

Use this polish notation calculator to convert arithmetic expressions between infix, prefix, and postfix, and to evaluate them on a stack-based engine.

Updated: June 16, 2026 • Free Tool

Polish Notation Calculator

Pick what you want the calculator to do with the expression below.

Use numbers, single letters, and the operators + - * / ^. Add spaces between tokens for prefix or postfix modes.

Results

Result
0
Token list 0
Stack trace 0
Steps 0

What Is the Polish Notation Calculator?

A polish notation calculator is a tool that converts arithmetic expressions between the three common notations - infix (3 + 4), prefix (+ 3 4, also called Polish), and postfix (3 4 +, also called Reverse Polish or RPN) - and evaluates any of them on a stack-based engine. You paste an expression, pick a mode, and read the converted form or the numeric result, with the token list and a stack trace shown alongside. Practical contexts include computer science coursework on expression parsing, exam preparation for stack-based calculators like vintage HP RPN models, compiler design exercises that use Dijkstra's shunting-yard algorithm, and quick verification when hand-converting expressions during a math or logic class. The polish notation calculator is the single page that handles all three of these notations, so the rest of this guide focuses on when each form is the right tool for the job.

  • Compiler and parser coursework: Convert infix to postfix and confirm the output of a hand-written shunting-yard implementation.
  • RPN calculator practice: Evaluate 3 4 + 7 2 - * style expressions used on stack-based calculators.
  • Reverse-engineering older calculators: Translate postfix keystrokes from vintage HP calculators into infix to understand what they did.
  • Logic and discrete-math teaching: Demonstrate prefix and postfix variants of propositional logic formulas without precedence rules.

Polish notation was introduced in the 1920s by the Polish logician Jan Łukasiewicz as a way to write logical formulas without brackets; the reverse (postfix) form later became popular for stack-based calculators and compilers because each operator is applied to the values already on the stack. According to the Stanford Encyclopedia of Philosophy - Jan Łukasiewicz, Łukasiewicz designed what he called "parenthesis-free notation" in 1924 to keep propositional logic from being obscured by grouping symbols, which is why the prefix form still carries his name today.

When your expression mixes ^ with very large or very small numbers, Exponential Notation Calculator handles the scientific-notation formatting once the conversion is finished.

How the Polish Notation Calculator Works

The calculator first splits the input into tokens, then runs the matching algorithm: Dijkstra's shunting-yard for infix-to-postfix, a modified shunting-yard with strict-greater precedence for infix-to-prefix, and a simple stack walk for the two evaluation modes. Every step records the current output queue and operator stack so you can see why each token went where it did.

shunting-yard: output = []; opStack = []; for each token, push operands to output, pop higher-or-equal-precedence operators to output, push the new operator; left brackets push, right brackets flush to the matching left bracket; at end, drain opStack to output.
  • expression: Numbers, single letters, and the five operators + - * / ^ with optional parentheses; tokens are separated by spaces in prefix or postfix modes.
  • mode: One of infix-to-postfix, infix-to-prefix, postfix-to-infix, prefix-to-infix, evaluate-postfix, evaluate-prefix.
  • operator precedence: Exponentiation (^) binds tightest, then * and /, then + and -; left parentheses are a stack marker only.

The same shunting-yard engine drives both infix-to-postfix and infix-to-prefix; for prefix the tokens are first reversed, parentheses are swapped, and the pop condition changes from greater-or-equal precedence to strictly greater precedence. According to Wikipedia, this small change in the comparison operator is what differentiates the prefix and postfix outputs from the same infix source, which is why the calculator exposes it as a single mode toggle rather than two separate engines.

Worked example: convert (3+4)*(7-2) to postfix

Input: (3+4)*(7-2) | Mode: Infix to postfix

Shunting-yard pushes numbers to output, holds operators on the stack, and flushes the stack when a right bracket appears; the final drain of * writes it after the two bracketed results.

Output: 3 4 + 7 2 - *

You can re-evaluate this on paper by reading left to right: push 3, push 4, + pops both and pushes 7, push 7, push 2, - pops 2 and 7 to push 5, * pops 5 and 7 to push 35.

Worked example: evaluate 3 4 + 7 2 - * (RPN)

Input: 3 4 + 7 2 - * | Mode: Evaluate postfix

A stack starts empty; each number is pushed, each operator pops the two most recent values and pushes the result.

Output: 35

The same value as 3+4 = 7, then 7-2 = 5, then 7 * 5 = 35, but the calculator reaches it without ever reading a precedence rule or a bracket.

According to GeeksforGeeks - Shunting Yard Algorithm, the shunting-yard algorithm, invented by Edsger W. Dijkstra in 1961, parses expressions with operator precedence and parentheses by walking each token once and dispatching it to one of two structures: an output queue for the eventual RPN string, and an operator stack that defers higher-precedence work until a lower-precedence operator or a right bracket triggers a flush.

To sanity-check the ^ step in any converted expression, Exponent Calculator can evaluate the base and exponent separately before re-running the polish notation engine.

Key Concepts Explained

Four ideas cover almost everything the calculator does; learning them once is enough to predict the result of any mode.

Infix, prefix, and postfix

Infix puts the operator between operands (3 + 4), prefix puts it before them (+ 3 4, the original Polish form), and postfix puts it after them (3 4 +, reverse Polish). All three describe the same arithmetic; only the placement rule changes.

Operator precedence and associativity

Exponentiation (^) binds tightest, then multiplication and division, then addition and subtraction; exponentiation is right-associative, the rest are left-associative. These levels control when an operator on the stack should be flushed to the output before pushing a new one.

Stack-based evaluation

A stack is a last-in, first-out container; numbers are pushed onto it, and each operator pops the top two values, applies the operation, and pushes the result back. This single rule handles RPN evaluation, prefix evaluation, and the infix-to-infix reconstruction from RPN.

Shunting-yard algorithm

Dijkstra's 1961 algorithm parses infix expressions into postfix using two structures: an output queue and an operator stack. Operators are pushed onto the stack and only flushed to the output when a lower-precedence operator arrives, when a right bracket appears, or at the end of the input.

Once these four ideas are clear, the calculator's six modes are just different ways of combining them: infix to postfix is shunting-yard; infix to prefix is reversed shunting-yard with strict-greater precedence; postfix evaluation is a single stack walk; postfix-to-infix is the same walk with the result written as a string and re-bracketed at every operator.

Boolean expressions follow the same prefix rule for connectives like AND, OR, and NOT, so Boolean Algebra Calculator lets you test the same stack-based evaluation on logical formulas once the arithmetic versions feel natural.

How to Use This Calculator

Run any of the six modes with the same two controls.

  1. 1 Choose a mode: Pick infix-to-postfix, infix-to-prefix, postfix-to-infix, prefix-to-infix, evaluate-postfix, or evaluate-prefix from the conversion mode dropdown.
  2. 2 Type the expression: Enter numbers, single-letter variables, and the operators + - * / ^; for prefix and postfix modes, leave a single space between every token.
  3. 3 Read the result: Watch the result, token list, and stack trace update in real time as you type. The result shows the converted expression or the numeric evaluation.
  4. 4 Verify the trace: If a value is wrong, scan the stack trace to find the line where the output queue and operator stack diverged from what you expected.
  5. 5 Switch to round-trip check: After converting to postfix, paste the output back into the expression box in evaluate-postfix mode to confirm the numeric value matches the original infix expression.

Practical example: type 3+2-7*1 in infix-to-prefix mode to see - + 3 2 * 7 1, then switch to evaluate-prefix and paste the prefix back to confirm the value is -2, matching the original infix expression evaluated left-to-right with standard precedence.

When the polish notation engine returns a numeric value for a single expression, System of Equations Calculator extends that numeric verification to a set of constraints at once, so the same evaluated result can be checked against a 2x2 or 3x3 linear system.

Benefits of Using This Calculator

The calculator is useful well beyond a quick numeric answer.

  • Verifies shunting-yard homework: Compare your hand-converted output against the calculator's result when you are learning Dijkstra's algorithm in a compilers or data structures class.
  • Decodes RPN keystrokes: Paste a stack of values and operators from an older HP calculator and the calculator returns the infix expression they represent, including the brackets the RPN form skips.
  • Catches precedence mistakes: When an infix expression gives a different value than the prefix or postfix form, the trace shows exactly which operator fired in the wrong order.
  • Works with letters or numbers: Single-letter variables such as a, b, or x are accepted everywhere; they are treated as placeholder operands so you can test the notation on algebraic expressions.
  • Self-contained reference: The same page shows the formula, the variable definitions, the worked example, and the step-by-step trace, so you do not need to flip between a tutorial and a tool.

For scientific-notation constants that show up once the polish notation value is computed, Scientific Notation Equation Calculator performs the cross-checks with the right number of significant figures.

Factors That Affect Your Results

A few conventions and limits affect every result the calculator produces.

Operator set

Only the five operators + - * / ^ are recognised. Anything else (such as %, &, |) returns a parse error so the conversion does not silently drop a token.

Whitespace in prefix and postfix

Prefix and postfix modes require a single space between tokens; without it, multi-digit numbers and letters can be confused with operators and the result becomes meaningless.

Variable defaults

Single-letter variables are accepted in every mode but are evaluated as 0 in the two evaluate modes, which is the convention used in propositional logic exercises where the value of the variable is not yet bound.

  • The calculator does not support unary minus; write -3 as 0-3 or wrap a negative number in parentheses such as 0-3 inside a larger expression.
  • Exponentiation is right-associative as in standard math, but the modified shunting-yard for prefix still applies a strict-greater precedence rule, which can differ from textbook examples for chains of ^; verify multi-step exponent expressions with the evaluate modes.
  • Floating-point results from ^, /, and large numbers are rounded to six decimal places to keep the displayed value readable; use the raw token list if you need the exact form for an exam or homework.

These limits match the rules used by the source calculators, and keeping the same rules means the prefix, postfix, and infix forms always agree on the value they should produce.

According to GeeksforGeeks - Convert Infix Expression to Prefix Expression, the infix-to-prefix variant of the shunting-yard algorithm reverses the token stream, swaps the roles of left and right parentheses, and only flushes an operator from the stack when the incoming operator's precedence is strictly greater, which is what reverses the associativity of the original scan.

Polish notation calculator converting infix to prefix and postfix expressions with a stack-based evaluator
Polish notation calculator converting infix to prefix and postfix expressions with a stack-based evaluator

Frequently Asked Questions

Q: What is the polish notation calculator used for?

A: It converts arithmetic expressions between infix (3 + 4), prefix or Polish (+ 3 4), and postfix or reverse Polish (3 4 +) and evaluates any of these forms. It is useful for compiler coursework, RPN calculator practice, and verifying shunting-yard conversions.

Q: How do I convert an infix expression to postfix (RPN)?

A: Pick the 'Infix to postfix (RPN)' mode, type an expression like (3+4)*(7-2), and the calculator runs Dijkstra's shunting-yard algorithm to produce 3 4 + 7 2 - *. The same engine is used in many compilers to turn source code into a form a stack machine can evaluate.

Q: What is the difference between prefix and postfix notation?

A: Prefix (Polish) notation places each operator before its operands, as in + 3 4. Postfix (reverse Polish, or RPN) places the operator after its operands, as in 3 4 +. Both avoid brackets and precedence rules; postfix is the form used by stack-based calculators.

Q: How do I evaluate a reverse Polish notation expression?

A: Choose the 'Evaluate postfix (RPN)' mode and type the expression with spaces between tokens, such as 3 4 + 7 2 - *. The calculator pushes numbers onto a stack, and each operator pops the top two values, applies the operation, and pushes the result back, ending with a single number on the stack.

Q: Why does RPN not need brackets?

A: Because every operator is applied to the values already on the stack, the order of operations is fully determined by the position of each token, so brackets and precedence tables are unnecessary. This is why RPN keyboards were popular on early HP calculators.

Q: What operators does this polish notation calculator support?

A: The calculator supports the five basic operators +, -, *, /, and ^, plus parentheses for grouping infix expressions. Single-letter variables such as a, b, or x are also accepted and evaluated as 0 in the evaluate modes.