2

What is the name of a notation that looks as follows:

"1 2 9 8 4 6 + * / + *"

But is evaluated as "1 + 2 * 9 / 8 + 4 * 6"

EDIT: I do think it's RPN now and my eval above is incorrect (as it's supposed to be evaluated in the stack on the first occurrence of an operator after the first operand).

JRN
  • 6,566
jsanc623
  • 123
  • 4
    I don't know, but I'd call it "terrible", because there is no way to order operations. How would you write the computation $(1+2)*(3+4)$, for example? – Thomas Andrews Jul 10 '14 at 20:54
  • Where did you come across it? That might help us figure out what it's called. – Ben Grossmann Jul 10 '14 at 20:57
  • My apologies. I was asked this during an interview a few years ago and wanted to recreate the function that parses this and calculates it, but I forgot what the name of the notation is. Also, @ThomasAndrews you might be able to do 1 2 3 4 ( + ) * ( + ), though I'm not sure. If this does have a name, I'd appreciate if anyone is able to locate it, and if not, its totally cool too :) – jsanc623 Jul 10 '14 at 21:00
  • 1
    Are you sure that is how it should be evaluated? If 1 2 9 8 4 6 + * / + * were Reverse Polish, it would mean $1\cdot(2+\frac{9}{8\cdot(4+6)})$. – hmakholm left over Monica Jul 10 '14 at 21:01
  • Yes, that is how it should be evaluated – jsanc623 Jul 10 '14 at 21:01
  • 1
    i suspect, but obviously can't prove, that you've forgotten the meaning of the notation, and that the interviewer actually was using Reverse Polish notation. This notation, as given, is not used anywhere, while RPN is quite common for a lot of computer science operations. – Thomas Andrews Jul 10 '14 at 21:03
  • (It's possible that the interviewer actually thought this was RPN. Interviewers are not flawless.) – Thomas Andrews Jul 10 '14 at 21:04
  • It may be RPN. I had not encountered it prior to that interview, nor anytime after - and considering it was quite a few years ago, my memory might be fuzzier than I thought :) – jsanc623 Jul 10 '14 at 21:05

3 Answers3

4

The most likely explanation seems to be that you're misremembering the meaning of the notation, and that the interviewer actually was using Reverse Polish notation. This notation, as given, is not used anywhere, while RPN is quite common for a lot of computer science operations.

In RPN, 1 2 9 8 4 6 + * / + * would mean $$1\cdot\left(2+\frac{9}{8\cdot(4+6)}\right)$$ rather than your $$1 + \frac{2 \cdot 9}{8} + 4\cdot6$$

2

This is almost a version of Polish notation called Reverse (or postfix) polish notation, but with the operators in inverted order.

jsanc623
  • 123
naslundx
  • 9,720
0

"Not practical " or "unusual", because that "all args first then all ops" notation would only work if the operators used all have a unique arity. So what about a - operator?

Also one would pile up much memory, no intermediate reductions.

mvw
  • 34,562