Reverse Polish Notation in Calculators
Date: 09/17/2005 at 14:14:09 From: Varda Subject: What are stacks, pushing, and popping? "My first calculator used something called 'reverse Polish notation', which allowed you to do operations without using parentheses, but then you had to be very careful about the order in which you entered numbers and operators. You learned about stacks, and pushing and popping." I came across this quote in an email. I've never heard of "stacks," "pushing," or "popping" before in my life. Can you translate?
Date: 09/17/2005 at 22:55:54 From: Doctor Vogler Subject: Re: What are stacks, pushing, and popping? Hi Varda, Thanks for writing to Dr. Math. A stack is a way of organizing data, used frequently in computers. Think of it like a stack of dishes. You put dishes on the top of the stack, and then you take them off the top of the stack. Notice that the first one to come off is the last one that you put on. When you put something on the stack, you say that you "push" it on the stack. When you take something off, you say that you "pop" it off the stack. So "pop" takes one thing off the stack (and typically uses it in some way), while "push" puts something on. Hewlett Packard made a line of very nice calculators that confused a lot of people by using this "reverse Polish notation," which means that the operation comes after the number, instead of in between them: 5 7 + instead of 5 + 7. In these calculators, you might enter something like 5 3 4 * 8 + + to mean 5 + ((3 * 4) + 8). Each time you enter a new number, the calculator pushes it on the stack. Each time you enter an operation (like * or +), the calculator pops two numbers off the stack, does the operation, and then pushes the result on the stack. See for yourself what things go on the stack each time you enter a symbol from the above list, and see why it results in the computation I wrote. It takes some getting used to, but it can be really convenient if you are used to it. If you have any questions about this or need more help, please write back and show me what you have been able to do, and I will try to offer further suggestions. - Doctor Vogler, The Math Forum http://mathforum.org/dr.math/
Date: 09/18/2005 at 00:56:20 From: Varda Subject: Thank you (What are stacks, pushing, and popping?) Thank you so much! Your example was really clear and tied together your verbal explanation perfectly! You know, I think that, given practice, my math-disabled self would find the reverse Polish notation fairly intuitive. At least more so than trying to remember the standard order of operations.
Search the Dr. Math Library:
Ask Dr. MathTM
© 1994-2015 The Math Forum