0
$\begingroup$

For example :

a + b - c = abc-+ 

Why is this correct ?

xy - z+ = xyz--

as I understand, it has to be :

xy - z+ = xyz+-
$\endgroup$
  • $\begingroup$ $xyz--=x(yz-)-=x-(y-z)=x-y+z=[(xy)-]+z=xy-z+$. $\endgroup$ – Nishant Oct 8 '14 at 4:11
  • 2
    $\begingroup$ Why would you want to learn reverse polish notation. Did you lose a bet? $\endgroup$ – Pedro Tamaroff Oct 8 '14 at 4:23
  • $\begingroup$ @PedroTamaroff no I'm studying for an exam and RPN is a part of the subjects $\endgroup$ – f855a864 Oct 8 '14 at 4:25
3
$\begingroup$

Because RPN performs the specified operation immediately with the most recent two numbers in the stack.

$$xy - z + = (x-y) + z$$

$$xyz-- = x-(y-z)$$

because in the second sequence, the $x$ gets pushed up higher into the stack once you enter the $y$ and the $z$. Then you execute the subtraction operation. Finally, the result of that subtraction is subtracted again from the first value entered ($x$) as the stack gets pushed down.

Algebraically, they give identical results because $x - (y-z) = x - y + z = (x-y) + z$.

Your proposed $xyz+-$ would give:

$$x - (y+z) = x - y - z$$

which is clearly not the same thing as the above.

$\endgroup$
1
$\begingroup$

$xy - z + = (x-y)+z$, (first $x$,$y$ on the stack, handle the minus, put the result on the stack, put $z$ on the stack, take their sum finally) while $xyz-- = x - (y - z) = x - y + z$ ($y$ and $z$ are highest on the stack when we meet the first minus) , so indeed the same.

$\endgroup$
0
$\begingroup$

xyz--=xy-zNN+, where "N" indicates the negative of a number. In other words, for any x, y, z, the difference of x and the difference of y and z, equals the sum of the difference of x and y and the negative of the negative of z. Since zNN=z, we thus obtain

xyz--=xy-z+. In infix notation this looks like this:

[x-(y-z)]=[(x-y)+(N(N(z))], which you might more ambiguously write:

[x-(y-z)]=[(x-y)+-(-(z))].

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.