Evauate the Polish notation expression. Please help

1. + / 42 + 56

2. * + - + 43628

1. is that 4 and 2 and 5 and 6, or 42 and 56?

it is 42 and 56

what is "Polish notation expression"

wilj;
I'm gonna take a stab at this from the example I found referencing the notation. It seems that the operands are all considered binary expressions; therefore, in context, what you're looking at is a string of individual number values. That makes the 42 and 56 two sets of two integers each. The first set of two consists of the numerical values 4 and 2 rather than components of the expression forty-two. The same goes for the next set of integers, 5 and 6, which should not be construed as anything like 56.
The sequence in which the operators are to be applied to the individual operands relies upon proximity. The equations, as written, are + / 4 2 + 5 6 ... In this type of notation, the operators are put ahead of the operands. That is, the action to take is put ahead of the things acted upon. This means that what is closest to being resolvable gets evaluated first. What is seen of what's written, when observed closely, is + 5 6.
This means add 5 and 6. The result is 11. The expression then looks like this:
+ / 4 2 11...
The next decipherable equation that you can see is / 4 2... That means divide 4 by 2. You are now left with an equation that looks like this: + 2 11... This is the last expression to be seen in the lot, and just means "add two to eleven". The answer should be thirteen..
.............+ / 4 2 + 5 6 .........................
.............+ / 4 2 ....11 .........................
.............+.....2......11 .........................
....................13..................................
This type of logic is supposed to be related to the way stacks are utilized, and is taught in order to familiarize people to the concept, judging from what I read... Hope it helps... You try the second one, and see if you can apply it... Have fun... jb

Wow thanks for the info!!!!

Why is that page named ReversePolishNotation.htm? That's not reverse Polish notation; it's Polish notation.

Good catch, but too late to edit it, so it has to stay as is. I was just playing around with Macromedia Captivate, my new toy.

I use stack notation every day as a PostScript developer. Everything goes on the stack. Operands precede operators. To add 5 plus 3 (giving 8) and divide by 2 (giving 4): 5 3 add 2 div

It is known as reverse Polish notation or postfix form, introduced by Lukasiewicz. Unlike the Polish notation, in which the operation sign precedes the operands, in reverse Polish the operation sign follows the operands.

example problem - 234* - 482/++

234 * - 482/++ (first 3 4 * is evaluated)
2 12 - 482/++ (next 2 12 - is evaluated)
-10482/++ (then 82 / is evaluated and replaced)
-1044 + + (next 4 4 + is evaluated)
-10 8 + (finally we evaluate -10 8 to obtain the final result)

-2

I am still trying to understand this one.

1. 2 3 4 * - 4 8 2 / + +
2. 2 12 - 4 8 2 / + +
3. -10 4 8 2 / + +
4. -10 4 4 + +
5. -10 8 +
6. -2

In RPN, an operator is "Executed". So 2, 3, 4 all go on the "stack". When "*" is encountered it is executed. It consumes the two topmost operators and replaces them with the value. You just pile up values until an operator encounters, and then you execute the operator immediately. It helps to draw a picture:

| * |
| 4 |
| 3 |
| 2 |
-----

|   |
| - |
|12 |
| 2 |
-----
 

|   |
|   |
|   |
|-10|
-----

The stack works like cafeteria trays (if you have those, or remember them). You add a new tray to the stack, it pushes the rest of the stack "down". You can only grab the top tray.

That is correct so back to the original problem, which is a little different.

* + - + 43628

Really, you should write that as * + - + 4 3 6 2 8. And do it yourself, for crying out loud.

I am not crying, thanks for your reply. It really helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.