terican

Last verified · v1.0

Calculator · math

Polish Notation Calculator

Evaluate Polish (prefix) notation expressions instantly. Enter an operator and two operands to compute +, -, *, /, ^, or mod results.

FreeInstantNo signupOpen source

Inputs

Result

Explain my result

0/3 free

Get a plain-English breakdown of your result with practical next steps.

Result

The formula

How the
result is
computed.

What Is Polish Notation?

Polish notation — also called prefix notation — is a mathematical and logical notation system invented by Polish logician Jan Łukasiewicz in the 1920s. Unlike conventional infix notation, where operators appear between operands (e.g., 3 + 4), prefix notation places the operator before both operands: + 3 4. This design eliminates the need for parentheses entirely, because the operator position determines evaluation order without ambiguity.

According to the Stanford Encyclopedia of Philosophy, Łukasiewicz developed this parenthesis-free notation to simplify propositional logic calculus and strip all brackets from logical formulae. Computer scientists later adopted prefix notation as a natural model for stack-based expression evaluation in compilers, interpreters, and scientific calculators.

The Core Formula

Every Polish notation expression follows a single structural pattern:

∘ a b = a ∘ b

The symbol represents any binary operator placed in the prefix (leading) position, a is the first operand, and b is the second operand. Supported operators include:

  • + (addition): + a b = a + b — Example: + 7 3 = 10
  • - (subtraction): - a b = a − b — Example: - 10 4 = 6
  • * (multiplication): * a b = a × b — Example: * 6 7 = 42
  • / (division): / a b = a ÷ b (b ≠ 0) — Example: / 15 3 = 5
  • ^ (exponentiation): ^ a b = a^b — Example: ^ 2 8 = 256
  • mod (modulo): mod a b = a mod b (b ≠ 0) — Example: mod 17 5 = 2

Step-by-Step Evaluation

Evaluating any prefix expression with this calculator requires exactly three inputs: the operator, Operand A, and Operand B. The evaluation process follows these steps:

  1. Select the operator in the leading (prefix) position field — for example, * for multiplication.
  2. Enter the first operand (a) in the Operand A field — for example, 9.
  3. Enter the second operand (b) in the Operand B field — for example, 6.
  4. The calculator applies the formula ∘ a b and returns a ∘ b instantly: * 9 6 = 54.

Worked Examples

  • + 12 8 → 12 + 8 = 20
  • * 9 6 → 9 × 6 = 54
  • - 100 37 → 100 − 37 = 63
  • / 144 12 → 144 ÷ 12 = 12
  • ^ 3 4 → 3⁴ = 81
  • mod 29 7 → 29 mod 7 = 1

Why Prefix Notation Matters in Computing

Prefix notation maps directly onto recursive descent parsing and stack-based algorithms used in compilers and interpreters. When a parser encounters a prefix expression, it reads the operator first, then recursively evaluates the two operands — a structure that corresponds naturally to abstract syntax trees (ASTs). The GNU Bison parser generator documentation illustrates how both Polish (prefix) and Reverse Polish (postfix) notation simplify grammar rules for arithmetic parsers, reducing the complexity of operator-precedence handling to zero.

Real-world applications of Polish notation include:

  • LISP and Scheme programming languages — all function calls use prefix syntax: (+ 3 4) evaluates to 7 and (* 9 6) evaluates to 54
  • Computer algebra systems — expression trees are stored internally as prefix forms before rendering infix output for the user
  • Boolean algebra and formal logic — Łukasiewicz's original formalism remains in use for formal verification of digital circuits and propositional calculi
  • Scientific calculators — the HP 50g supports algebraic, RPN (postfix), and step-by-step entry modes, demonstrating the enduring value of flexible notation systems

Operator Precedence Without Parentheses

One of the most powerful properties of prefix notation is that it encodes operator precedence structurally rather than through memorized rules. The expression + * 2 3 4 is fully unambiguous: multiply 2 by 3 first, then add 4, yielding (2 × 3) + 4 = 10. No parentheses are needed because the operator position determines grouping at every level. For single binary operations evaluated by this calculator, simply enter the operator once and provide both operands — the result follows directly from ∘ a b = a ∘ b with no precedence rules to apply.

Reference

Frequently asked questions

What is Polish notation (prefix notation)?
Polish notation, also known as prefix notation, is a mathematical system where the operator appears before its two operands rather than between them. Invented by Jan Łukasiewicz in the 1920s, it writes addition as '+ 3 4' instead of '3 + 4'. The system requires no parentheses because the operator position alone defines evaluation order, making it ideal for computer parsing, compiler design, and formal logic systems.
How does the Polish notation calculator work?
The calculator takes three inputs: an operator (such as +, -, *, /, ^, or mod), Operand A, and Operand B. It applies the prefix formula ∘ a b = a ∘ b and returns the result instantly. For example, entering operator *, Operand A = 9, and Operand B = 6 computes * 9 6 = 54. Division and modulo operations require Operand B to be non-zero to avoid undefined results.
What is the difference between Polish notation and Reverse Polish Notation (RPN)?
Polish notation (prefix) places the operator before the operands: + 3 4 means 3 + 4. Reverse Polish Notation (RPN or postfix) places the operator after the operands: 3 4 + also means 3 + 4. Both systems eliminate parentheses entirely. RPN is used on HP scientific calculators and in the FORTH programming language, while prefix notation is used in LISP, Scheme, and formal logic systems derived from Łukasiewicz's original work.
Can Polish notation represent complex nested expressions?
Yes. Polish notation handles arbitrarily nested expressions without parentheses by reading operators recursively. The expression + * 2 3 4 means: first compute * 2 3 = 6, then compute + 6 4 = 10. Each operator claims the next two available values as its operands, and those values can themselves be entire sub-expressions. This recursive structure mirrors exactly how compilers build abstract syntax trees when evaluating arithmetic in source code.
Why must Operand B be non-zero for division and modulo?
Division (/ a b) and modulo (mod a b) are undefined when b equals zero because dividing any number by zero yields no finite result in standard arithmetic. The expression / 10 0 represents an undefined quantity, not a computable number. To prevent errors, this calculator requires b ≠ 0 for both operators, consistent with the mathematical definition of division and the IEEE 754 floating-point standard that governs how computers handle arithmetic operations.
Which programming languages and tools use Polish (prefix) notation?
LISP (1958) and Scheme use prefix notation for all expressions: (+ 3 4) and (* 9 6) are standard syntax. Clojure, a modern LISP dialect running on the JVM, follows the same convention. Formal logic and propositional calculus systems descended from Łukasiewicz's original work also use prefix operators. GNU Bison, a widely used parser generator, includes prefix-notation grammar examples for building calculators and interpreters, as documented in its official manual.