Questions tagged [postfix-notation]

Postfix notation (also known as Reverse Polish Notation, RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.

Postfix notation (also known as Reverse Polish Notation, RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.

Both and postfix notation have the advantage over infix notation that operator precedence is completely defined by the expression, without parentheses being required, which further implies that both can be evaluated linearly by machine instructions without parsing.

572 questions
20
votes
3 answers

C# generated IL for ++ operator - when and why prefix/postfix notation is faster

Since this question is about the increment operator and speed differences with prefix/postfix notation, I will describe the question very carefully lest Eric Lippert discover it and flame me! (further info and more detail on why I am asking can be…
Simon Hewitt
  • 1,391
  • 9
  • 24
12
votes
2 answers

Generating all possible "unique" RPN (Reverse Polish notation) expressions

I want to generate in Python all possible RPN (Reverse Polish notation) expressions, that use letters from an input list (such as ['a', 'b', 'c']) and contain operators ['+', '-', '*', '/']. My idea was that we can add elements to the current…
Dima
  • 257
  • 4
  • 11
11
votes
4 answers

Postfix notation validation?

What would be a good way to evaluate a string(array, something) that contains a postfix expression(ex: 3 5 +) to check for validity?
Matt
10
votes
2 answers

`defined?` and `unless` not working as expected

I was expecting the following snippet: var = "Not Empty" unless defined? var var # => nil to return "Not Empty", but I got nil. Any insight into why this is happening?
Noman Ur Rehman
  • 6,707
  • 3
  • 24
  • 39
10
votes
5 answers

Why postfix (rpn) notation is more used than prefix?

By use I mean its use in many calculators like HP35- My guesses (and confusions) are - postfix is actually more memory efficient -( SO post comments here ). (confusion - The evaluation algorithm of both are similar with a stack) keyboard input…
Amartya
  • 309
  • 4
  • 11
9
votes
6 answers

Convert from an infix expression to postfix (C++) using Stacks

My lecturer gave me an assignment to create a program to convert and infix expression to postfix using Stacks. I've made the stack classes and some functions to read the infix expression. But this one function, called convertToPostfix(char * const…
Reggie Escobar
  • 99
  • 1
  • 1
  • 3
8
votes
2 answers

How to put postfix expressions in a binary tree?

so i have a binary tree and a postfix expression "6 2 * 3 /" what is the algo to put it in a tree? like, [/] / \ [*] [3] / \ [6] [2]
Mudasir Soomro
  • 140
  • 1
  • 1
  • 9
8
votes
6 answers

May I write {x,a,b}//Do[...,#]& instead of Do[...,{x,a,b}]?

I'm in love with Ruby. In this language all core functions are actually methods. That's why I prefer postfix notation – when the data, which I want to process is placed left from the body of anonymous processing function, for example:…
Nakilon
  • 34,866
  • 14
  • 107
  • 142
7
votes
2 answers

Variable-Length Operators In Reverse Polish Notation (Postfix)

Background: In traditional Reverse Polish Notation, all operators must have fixed lengths, which allows RPN to be easily evaluated and manipulated by code because every token, expression, and subexpression are all "self-contained" such that one can…
Jack G
  • 4,553
  • 2
  • 41
  • 50
7
votes
1 answer

How to convert from infix to postfix/prefix using AST python module?

I'm trying to convert python math expressions to postfix notation using the AST python module. Here's what I got so far: import parser import ast from math import sin, cos, tan formulas = [ "1+2", "1+2*3", "1/2", "(1+2)*3", …
BPL
  • 9,632
  • 9
  • 59
  • 117
7
votes
3 answers

Can this Python postfix notation (reverse polish notation) interpreter be made more efficient and accurate?

Here is a Python postfix notation interpreter which utilizes a stack to evaluate the expressions. Is it possible to make this function more efficient and accurate? #!/usr/bin/env python import operator import doctest class Stack: """A…
simeonwillbanks
  • 1,459
  • 16
  • 18
7
votes
3 answers

Postfix Calculator Java

Ok so I have to read in a postfix expression from a file. The postfix expression must have spaces to separate each operator or operand. What I have so far works only if there is no spaces between the operators or operands in the input file. (i.e. if…
Jmamz06
  • 109
  • 2
  • 3
  • 5
6
votes
4 answers

Trouble understanding what to do with output of shunting-yard algorithm

I've been looking at the wiki page: http://en.wikipedia.org/wiki/Shunting-yard_algorithm I've used the code example to build the first part, basically I can currently turn : 3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3 into 3 4 2 * 1 5 − 2 3 ^ ^ / + But I don't…
Patrick Lorio
  • 5,520
  • 11
  • 45
  • 74
6
votes
5 answers

small language in python

I'm writing what might not even be called a language in python. I currently have several operators: +, -, *, ^, fac, @, !!. fac computes a factorial, @ returns the value of a variable, !! sets a variable. The code is below. How would I go about…
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
6
votes
2 answers

Possible Trees using translation scheme for post fix notation of 7-2+3

I was asked to convert 7-2+3 into post fix notation while no operator precedence or left to right or right to left was mentioned in the question and then I had to make tree using translation scheme of the post fix notion ed result. I found it…
1
2 3
38 39