Understanding Polish notation
Mar 18, 2020 12:27 · 362 words · 2 minute read
Usually, we write mathematical expressions in “infix notation”. This means that operations involving two numbers are written as the first number, followed by the operator, followed by the second number. Polish notation is an alternative to infix notation. In Polish notation, the operator is put up front. It’s also called prefix notation, or forward Polish notation (in contrast to reverse Polish notation, which puts the operator at the end).
00:28 - One of the advantages of Polish notation is that it eliminates the need for brackets. For instance, 5(1 + 2) is written as “X 5 + 1 2”, without any brackets. Let’s evaluate a few Polish notation expressions to get a feel for how it works. Since we’re expecting to get a single number from evaluating these, we’re going to start with a box that’s expecting a single number. If we were to end up with multiple numbers from evaluating a whole expression, then that would mean that something is wrong with that expression.
01:00 - For this expression, we start with multiplication. Since multiplication isn’t a number, we can’t put it in that box. Instead, we will need to multiply two other expressions to get our final answer. The first of those expressions is just the number five. To get the second one, we need to add. The first number to add is one. The second is two. Now we can resolve the bottom value of the multiplication to 3.
01:29 - Let’s try another, more complicated, expression, “÷ - 5 8 X 3 ÷ 5 10” It starts with division, so we need to figure out what two numbers to divide. Next we encounter a minus sign, so let’s figure out what to subtract. Five and eight. Five minus eight equals negative three, so that’s the first number to divide. To determine the second number, we need to multiply. Three and another number. We need to divide to get the second number. Five and ten divide to get zero point five. Next, we multiply 3 and zero point five to get one point five. Divide those two numbers to get negative two, our end result. Thanks for watching! .