The Polish Notation Converter, provided by Hesapstan, converts mathematical expressions between infix, prefix (Polish), and postfix (Reverse Polish / RPN) notation.
What does this converter do?
This tool converts an expression between infix, prefix, and postfix notation; it does not evaluate the expression numerically. In other words, it changes how the expression is written, not the value of the expression.
The converter supports all six directions: infix to prefix, infix to postfix, prefix to infix, prefix to postfix, postfix to infix, and postfix to prefix. The supported operators are +, -, *, /, and ^.
The tool converts notation only. It does not calculate the numeric result and it does not support functions such as sin, cos, sqrt, or log.
What are infix, prefix and postfix notation?
Infix notation places the operator between two operands, which is the usual form in school mathematics. For example, A + B is an infix expression.
- Infix: the operator is in the middle, such as A + B.
- Prefix / Polish notation: the operator comes first, such as + A B.
- Postfix / Reverse Polish / RPN: the operator comes last, such as A B +.
Prefix and postfix notation make the expression structure clear from token order. That is why they appear in algorithms, compiler design, data structures, and stack-based calculations.
Why is it called Polish notation?
The name Polish notation is associated with the Polish logician Jan Łukasiewicz. In prefix notation, the operator is written before its operands, so many expressions can be represented without ordinary infix parentheses.
Postfix notation is called Reverse Polish Notation, or RPN. In RPN, the operator follows the operands and the expression can be processed naturally with a stack.
How to use the converter
Choose the source notation and the target notation, then enter the expression according to the rules of the source notation. The source and target notation should be different.
- For infix, use ordinary mathematical writing and parentheses when needed: (A + B) * C.
- For prefix, separate tokens with spaces: * + A B C.
- For postfix, separate tokens with spaces: A B + C *.
- After conversion, check both the detected token list and the converted target expression.
A token is one meaningful part of an expression: a number, a variable name, an operator, or a parenthesis. This converter supports numbers and single- or multi-character variable names such as A, B, x, or abc.
How are precedence and parentheses handled?
In infix notation, operation order is determined by operator precedence and parentheses. In this converter, the precedence order is ^ > * and / > + and -.
The ^ operator is treated as right-associative, while +, -, *, and / are treated as left-associative. Parentheses in infix input can override the usual order.
The converter uses the standard precedence and associativity rules described here. It does not let you define a custom precedence table.
Why is unary minus not supported?
Unary minus is the single minus sign placed before a value, such as -x or -3. This converter does not support unary minus directly because the same '-' symbol is also used for binary subtraction.
If you need to enter a negative constant, use the contract-supported workaround: (-3). This helps the parser treat the value as a negative constant token instead of a standalone unary operation.
Bare unary-minus input such as -3 is not supported. Use (-3) for a negative constant; expressions that apply unary minus to variables are outside this converter’s scope.
Examples for all six conversion directions
The same expression can be written in different notation orders while preserving the same expression structure. These examples show the supported conversion directions.
Infix → Prefix
Input: (A + B) * C
Output: * + A B C
The grouped expression A + B is multiplied by C; prefix notation moves each operator before the operands it applies to.
Infix → Postfix
Input: (A + B) * C
Output: A B + C *
In postfix notation, operands come first and the operator is written after the values it combines.
Prefix → Infix
Input: * + A B C
Output: (A + B) * C
The prefix form is parsed by matching each operator with its operands, then writing the same structure in ordinary infix form.
Prefix → Postfix
Input: * + A B C
Output: A B + C *
The converter preserves the expression tree and rewrites it in postfix order.
Postfix → Infix
Input: A B + C *
Output: (A + B) * C
The postfix form is resolved with stack logic: each operator combines the correct preceding operands.
Postfix → Prefix
Input: 3 4 + 2 *
Output: * + 3 4 2
This expression groups 3 + 4 first, then multiplies the result by 2. The converter does not simplify it to 14; it only changes notation.
Why is postfix / RPN useful?
Postfix notation, or RPN, is useful because it can reduce the need for parentheses and can be processed cleanly with a stack. This is why it appears in calculators, compilers, and algorithm courses.
A postfix expression can be read from left to right: operands are pushed onto a stack, and when an operator appears, it combines the necessary previous operands. The visible token list helps make that structure easier to understand.
Common errors and validation messages
Most conversion errors come from token order, parentheses, or an invalid number of operands.
- An opened parenthesis in infix input must be closed.
- Prefix and postfix tokens should be separated by spaces.
- The number of operators and operands must match the notation rules.
- Unsupported characters or function names are invalid tokens.
- Bare unary-minus input such as -3 is not supported.
What are the limitations of this converter?
This converter is designed for notation conversion in computer science and discrete mathematics contexts. Its limits should be understood before interpreting the output.
- It does not evaluate expressions numerically.
- It supports only +, -, *, /, and ^ operators.
- It does not support functions such as sin, cos, sqrt, or log.
- Unary minus is not supported; use (-3) for a negative constant.
- Operator precedence and associativity rules cannot be customized.
Which related calculator should I use next?
This page is about formal expression notation. If your goal is direct arithmetic or another notation topic, a different calculator may be more useful.
- Use the multiplication calculator when you want to multiply numbers directly.
- Use the integer calculator for integer arithmetic and signed-number operations.
- Use the set-builder notation calculator when you need another formal mathematical notation tool for sets.
Frequently Asked Questions
What is Polish notation?
Polish notation is prefix notation: the operator is written before its operands. For example, A + B becomes + A B.
What is the difference between prefix and postfix notation?
Prefix notation puts the operator before the operands, such as + A B. Postfix notation puts the operator after the operands, such as A B +.
What does RPN mean?
RPN means Reverse Polish Notation. It is another name for postfix notation.
Does this tool calculate the result of the expression?
No. It converts notation only. It does not evaluate the expression numerically.
How do I enter a negative number?
Unary minus is not supported directly. For a negative constant, use the parenthesized form (-3).
Do prefix and postfix inputs need spaces?
Yes. Prefix and postfix input should use spaces between tokens, such as * + A B C or A B + C *.
Which operators are supported?
The supported operators are +, -, *, /, and ^. Mathematical functions and custom operators are not supported.
How does the converter handle parentheses?
Parentheses are used in infix input to control operation order. Prefix and postfix notation usually express structure through token order instead.