Category

Polish Notation Converter — Infix, Prefix & Postfix (RPN)

Convert expressions between infix, Polish (prefix) and reverse Polish (postfix / RPN) notation online. Type any expression, pick its notation, and instantly get all three forms plus the evaluated result, with correct operator precedence and associativity.

0 calculations

Calculation Parameters

Prefix (Polish)
—
Postfix (Reverse Polish)
—

Enter Parameters

Fill in the form on the left and click "Calculate"

There are other ways to write operations than the standard "symbols-between-numbers" fashion: with our Polish notation converter, you'll learn all about them! Type any expression on the left, tell the tool whether you wrote it in infix, prefix, or postfix, and instantly see it rewritten in every notation — plus its numerical value when the operands are numbers.

Mathematics is a matter of notations and conventions, symbols, and representations of abstract concepts. The order in which we write every operation is one of these conventions: the one everyone knows is called infix notation. But are you sure that's the best way to write equations? Keep on reading to learn about Polish notation and reverse Polish notation.

Arithmetical and logical notations

To write, compute, or communicate mathematical operations, we need to introduce their building blocks:

  • Operands — numbers (e.g., 11, 137, e, π) or letters representing unknowns (e.g., x, a, n).
  • Operators — everything that acts on operands (e.g., +, −, ×, ÷, ^).

Operators follow specific rules that let us use them in the correct order:

  • Precedence indicates which operator has to be applied first.
  • Grouping uses brackets to indicate that certain operations must be performed directly, without following precedence.
  • Associativity determines the direction in which operators act in case of equal precedence and absence of brackets.

Multiplication has higher precedence than addition. It means that in the operation 3 + 8 × 2, we must compute the multiplication first: 3 + 8 × 2 = 3 + 16 = 19. The precedence of the basic arithmetic operators, from the highest to the lowest, is:

  1. Exponentiation and root extraction;
  2. Multiplication and quotient; and
  3. Addition and subtraction.

Brackets prioritize certain parts of the operation, insulating them from the standard precedence order. For example, following the standard rules 8 × 4 + 2 = 32 + 2 = 34, but if we need the addition first we add brackets: 8 × (4 + 2) = 8 × 6 = 48.

Finally, associativity resolves ties. Take 7 − 4 + 2: depending on how we place brackets we get (7 − 4) + 2 = 5 or 7 − (4 + 2) = 1. Traditionally, binary operators are left-associative (grouped from the left), while exponentiation is right-associative.

What is the infix notation?

The traditional way to write operations is called infix notation. The operators lie between the operands, like in 4 + 1, where the + sits between the 4 and the 1. To understand which operand belongs to which operator, it is necessary to use associativity and precedence rules, and brackets are often necessary to ensure the correct evaluation of the operation.

What is the Polish notation?

Polish notation (PN), introduced by the Polish logician Jan Łukasiewicz in 1924, places the operator before its operands. That's why it is also called prefix notation. The genius of the idea is that precedence and brackets become completely unnecessary: the position of each operator alone tells you the order of evaluation.

For example, the infix expression 3 + 4 becomes + 3 4. The infix 3 + 4 × 2 becomes + 3 × 4 2 — no parentheses required, and there is only one correct reading.

Types of Polish notation

There are two flavors, and this converter handles both:

  • Prefix (Polish) notation — the operator comes before the operands: operator operand₁ operand₂.
  • Postfix (Reverse Polish, RPN) notation — the operator comes after the operands: operand₁ operand₂ operator. This is the notation used inside many calculators, compilers, and stack machines because it is trivial to evaluate with a single stack.

Some examples of Polish notation expressions

Infix Prefix (Polish) Postfix (RPN)
3 + 4 × 2+ 3 × 4 23 4 2 × +
(3 + 4) × 2× + 3 4 23 4 + 2 ×
a × (b + c)× a + b ca b c + ×
8 − 4 − 2− − 8 4 28 4 − 2 −

How to convert from and to the prefix and postfix notations

The classic algorithm for infix → postfix is Dijkstra's shunting-yard method:

  1. Read the infix expression left to right.
  2. Send operands straight to the output.
  3. Push operators onto a stack, but first pop off any stacked operators with higher (or equal, for left-associative) precedence.
  4. Brackets are pushed when opened and pop everything back to the matching open bracket when closed.
  5. At the end, pop the remaining operators to the output.

To go the other way — reading a prefix or postfix string back into infix — you scan the expression and use a stack of sub-expressions, combining two operands each time you meet an operator. Internally, our converter builds an expression tree from whatever you type, then re-serializes that tree into all three notations, guaranteeing consistent, minimally-parenthesized results.

Examples of conversion from infix to the Polish notations (and vice-versa)

Take 2 ^ 3 ^ 2. Because exponentiation is right-associative, it reads as 2 ^ (3 ^ 2) = 2 ^ 9 = 512. Its prefix form is ^ 2 ^ 3 2 and its postfix form is 2 3 2 ^ ^. By contrast, (2 ^ 3) ^ 2 = 64 gives prefix ^ ^ 2 3 2 and postfix 2 3 ^ 2 ^ — the notations themselves make the grouping unambiguous, with no brackets at all.

How to use our Polish notation converter?

  1. Choose the input notation of your expression: infix, prefix (Polish), or postfix (RPN).
  2. Type the expression. In prefix and postfix modes, separate every token with a space (e.g., + 3 4 or 3 4 +). Infix mode accepts brackets and spaces are optional.
  3. Read off the equivalent prefix, postfix, and infix forms, plus the evaluated value when every operand is a number.

Supported operators are +, −, × (*), ÷ (/), ^ (power), and % (modulo). Operands may be non-negative numbers or letter variables such as a, b, x.

Why use our Polish notation converter?

  • It converts in every direction — not just infix → postfix, but prefix and postfix back to infix too.
  • It evaluates the expression instantly when the operands are numeric.
  • It produces clean, minimally-bracketed infix output and honors correct precedence and associativity (including right-associative exponentiation).
  • A live preview updates as you type, so you can learn the pattern by experimenting.

FAQs

What is Polish notation used for?

Prefix and postfix notations remove the need for brackets and precedence rules, which makes expressions unambiguous and very easy for machines to parse. Reverse Polish notation (postfix) in particular is used by stack-based calculators, virtual machines, and compilers to evaluate expressions with a single pass over a stack.

What is the difference between Polish and reverse Polish notation?

In Polish (prefix) notation the operator is written before its operands, e.g., + 3 4. In reverse Polish (postfix) notation the operator comes after the operands, e.g., 3 4 +. Both avoid brackets entirely.

How do I read a prefix expression?

Scan from right to left, pushing operands onto a stack. Whenever you meet an operator, pop the two most recent operands, apply the operator, and push the result back. For postfix, do the same but scan left to right.

Does the converter handle variables?

Yes. You can mix letters and numbers — for example, a × (b + c). When any operand is a variable, the tool still shows all three notations but cannot compute a numerical value.

Calculation History

Loading...