Polish Notation Converter

Convert expressions between infix, prefix Polish notation, and postfix Reverse Polish notation with an instant, readable result.

Convert expression notation
Enter an expression and choose the source and destination notation.

About Polish notation conversion

Polish notation is a way to write mathematical and logical expressions without relying on the usual placement of operators between values. In ordinary infix notation, an operator appears between its operands, as in A + B. Prefix notation places the operator first, producing + A B, while postfix notation places it last, producing A B +. Prefix form is often called Polish notation, and postfix form is known as Reverse Polish notation or RPN. Because an operator and its operands have an unambiguous order, prefix and postfix expressions generally do not need parentheses. This converter handles four common transformations: infix to prefix, infix to postfix, prefix to infix, and postfix to infix. For infix input, it recognizes identifiers, decimal numbers, parentheses, and the addition, subtraction, multiplication, division, and exponent operators. Standard precedence rules are applied: exponentiation is evaluated before multiplication and division, which are evaluated before addition and subtraction. Parentheses can explicitly change that order. Exponentiation is treated as right-associative, so a ^ b ^ c means a raised to the power of b raised to c. The infix conversions use the shunting-yard method to arrange tokens by precedence. A stack temporarily holds operators while values move directly to the output. Prefix output is then assembled from the resulting postfix sequence. Prefix-to-infix and postfix-to-infix conversions use a stack of partial expressions. Whenever an operator is encountered, the appropriate two operands are removed, combined, wrapped in parentheses, and returned to the stack. The final stack item is the complete infix expression. Token spacing matters for prefix and postfix input because spaces identify each operand and operator. Write * + A B C rather than *+ABC. Infix expressions may include or omit spaces because parentheses and operator characters separate the tokens. The converter preserves variable names and numeric values but adds spaces and parentheses to make the result easy to inspect. Notation conversion is useful when studying expression trees, compiler parsing, stack machines, calculators, and data structures. Postfix expressions can be evaluated from left to right with a simple stack, while prefix expressions can be processed similarly from right to left. Converting a familiar infix formula into either form makes operator precedence explicit and provides a practical way to check an expression-parsing exercise.

Polish notation examples

These examples show equivalent expressions in different notation systems.

InputOutputConversion
(A + B) * C - D- * + A B C DInfix to prefix
A + B * CA B C * +Infix to postfix
* + A B - C D((A + B) * (C - D))Prefix to infix
A B + C D - *((A + B) * (C - D))Postfix to infix

How to use the notation converter

  1. Choose one of the four conversion types to identify the notation you are entering and the notation you want.
  2. Enter the expression, using spaces between every token when the source is prefix or postfix notation.
  3. Select Convert to parse the expression and display its equivalent notation.
  4. Check the operator order in the result, or select Reset to clear the expression and begin again.

Polish notation converter FAQ

What is Polish notation?

Polish notation places each operator before its operands, so A + B becomes + A B. This arrangement removes the need for parentheses when every operator has a known number of operands.

What is Reverse Polish notation?

Reverse Polish notation places the operator after its operands, so A + B becomes A B +. It is also called postfix notation and is commonly evaluated with a stack.

Do prefix and postfix expressions need spaces?

Yes, this converter expects spaces between prefix or postfix tokens so multi-character values remain unambiguous. For example, write + total 25 rather than +total25.

How does the converter handle operator precedence?

In infix expressions, exponentiation has the highest precedence, followed by multiplication and division, then addition and subtraction. Parentheses override that normal order.

Can I use numbers and variable names together?

Yes, operands may be decimal numbers or identifiers made from letters, digits, and underscores. The converter rearranges tokens without evaluating their numeric value.