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.
Inputs
Result
—
Explain my result
Get a plain-English breakdown of your result with practical next steps.
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:
- Select the operator in the leading (prefix) position field — for example, * for multiplication.
- Enter the first operand (a) in the Operand A field — for example, 9.
- Enter the second operand (b) in the Operand B field — for example, 6.
- 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