polish calculator

Polish Notation Calculator (Prefix & Postfix)

Evaluate expressions written in Polish notation (prefix) or Reverse Polish notation (postfix). Use spaces between tokens.

Supported operators: +, -, *, /, ^, %, neg, sqrt, abs, sin, cos, tan, ln, log. Constants: pi, e.
Enter an expression and click Calculate.

Evaluation Steps

  • No steps yet.

What Is a Polish Calculator?

A polish calculator evaluates math expressions written in Polish notation. In this format, the operator appears before its operands. For example, the infix expression (3 + 4) becomes + 3 4. A related style, Reverse Polish Notation (RPN), places the operator after operands, such as 3 4 +.

These notations are popular in computer science, compilers, stack-based languages, and classic scientific calculators because they remove ambiguity and reduce the need for parentheses.

Prefix vs Postfix: Quick Comparison

Prefix (Polish)

  • Operator comes first: * + 2 3 4
  • Represents (2 + 3) * 4
  • Useful in parsing and symbolic processing

Postfix (Reverse Polish)

  • Operator comes last: 2 3 + 4 *
  • Also represents (2 + 3) * 4
  • Very efficient for stack-based evaluation

How to Use This Polish Calculator

  1. Select Prefix or Postfix.
  2. Type tokens separated by spaces.
  3. Click Calculate.
  4. Read the result and step-by-step stack operations.

If you receive an error, it usually means there is an unsupported token, insufficient operands, or an incomplete expression.

Operator Reference

  • Binary: +, -, *, /, ^, %
  • Unary: neg (negation), sqrt, abs, sin, cos, tan, ln, log
  • Constants: pi, e

Trigonometric functions use radians. For example, sin pi in prefix returns approximately zero.

Why Polish Notation Matters

Polish notation is more than a classroom concept. It appears in:

  • Expression parsers and interpreters
  • Compiler internals
  • Stack machines and virtual machines
  • Embedded systems with limited resources

Because operator precedence is encoded by position, evaluation can happen in a single pass with a stack. That makes implementations clean, fast, and reliable.

Common Mistakes and Fixes

1) Missing spaces

Write + 2 3, not +2 3. Tokens must be separated clearly.

2) Too few operands

For *, you need two numbers. For sqrt, one number is enough.

3) Wrong notation mode

2 3 + should run in Postfix mode, not Prefix mode.

4) Invalid domains

sqrt of a negative number or ln of zero/negative values is undefined in real numbers and will return an error.

Practice Expressions

  • Prefix: - * 10 5 12 → 38
  • Postfix: 10 5 * 12 - → 38
  • Prefix: + ^ 2 3 7 → 15
  • Postfix: 2 3 ^ 7 + → 15

Use the built-in examples above to test quickly, then create your own expressions.

🔗 Related Calculators