Evauate the Polish notation expression. Please help

1. + / 42 + 56

2. * + - + 43628

wilj 0 Newbie Poster

Evauate the Polish notation expression. Please help

1. + / 42 + 56

2. * + - + 43628

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

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

wilj 0 Newbie Poster

it is 42 and 56

joshSCH 1,062 Industrious Poster Banned

what is "Polish notation expression"

jbarry315 16 Light Poster

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

wilj 0 Newbie Poster

Wow thanks for the info!!!!

tgreer 189 Made Her Cry Team Colleague

Rashakil Fol 978 Super Senior Demiposter Team Colleague

tgreer 189 Made Her Cry Team Colleague

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`

wilj 0 Newbie Poster

wilj 0 Newbie Poster

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.

tgreer 189 Made Her Cry Team Colleague

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.

wilj 0 Newbie Poster

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

* + - + 43628

Rashakil Fol 978 Super Senior Demiposter Team Colleague

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

wilj 0 Newbie Poster

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.