Questions tagged [rpn]

For questions relating to the Reverse Polish Notation, which is a notation for mathematical expressions where the operands precede the operator.

In computing, RPN is ideally suited for a stack-based implementation, and in hardware it has a long history with HP hand-held calculators.

E.g. 1 2 + means apply the + operator to the operands 1 and 2.

198 questions
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
10
votes
2 answers

handling unary minus for shunting-yard algorithm

Is there a better way to handle unary "-" in converting a infix expression to a postfix one? The obvious one would be prefix every unary "-" with a 0. Does anyone know better implementation? Thanks!
JASON
  • 7,371
  • 9
  • 27
  • 40
9
votes
7 answers

Converting Reverse Polish Notation

Is there any way to interpret Reverse Polish Notation into "normal" mathematical notation when using either C++ or C#? I work for an engineering firm, so they use RPN occasionally and we need a way to convert it. Any suggestions?
Iwasakabukiman
  • 1,453
  • 4
  • 15
  • 17
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
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
9 answers

Efficiency of stack-based expression evaluation for math parsing

I have to write, for academic purposes, an application that plots user-input expressions like: f(x) = 1 - exp(3^(5*ln(cosx)) + x) The approach I've chosen to write the parser is to convert the expression in RPN with the Shunting-Yard algorithm,…
Davide Valdo
  • 779
  • 8
  • 21
6
votes
1 answer

Can RPN (Reverse Polish Notation) or Postfix Notation be derived by Regular Expression

I was wondering if I can define a Regular Expression to check whether a given input matches the RPN expression , i.e. whether the given input is valuid or not? I am not very familiar with Regex unfortunately, so I was wondering if it is possible to…
6
votes
2 answers

How to evaluate Reverse polish notation using stacks

Can this postfix expression can be evaluated? 6 2 3 + - 3 8 2 / + * 2 5 3 +
Zeeshan Asif
  • 61
  • 1
  • 1
  • 3
6
votes
1 answer

Evaluation of Reverse Polish Notation in R

What is the most efficient algorithm to evaluate a RPN notation in R? Here is the question: suppose we have c("4", "13", "5", "/", "+") -> (4 + (13 / 5)) -> 6 How to write a general purpose function that evaluates any input RPN ? Does R have stack…
Sam
  • 4,357
  • 6
  • 36
  • 60
5
votes
1 answer

Evaluating expression from abstract syntax tree

I have an abstract syntax tree that I made from a reverse polish notation expression. The tree's nodes are all strings. #include #include #include #include struct snode { char *datum; struct snode*…
etorr96
  • 81
  • 9
4
votes
0 answers

Could an Applicative Language use Postfix Notation?

I've always found postfix languages like Factor to be far more readable than prefix (Lispy languages) and infix/postfix languages (all C-style languages, if we include both operators and functions). Unlike prefix languages, you don't need for…
Louis
  • 2,442
  • 1
  • 18
  • 15
4
votes
2 answers

Store contents of a file with both integers and characters in C

I have a text file input.txt whose contents are of the form: 12 3 / 2 3 - 3 4 * 1 2 4 + - 5 * 7 / My end goal is to read each line of the file and evaluate the given RPN expression. I have written the following code snippet to read the contents of…
user10216080
4
votes
2 answers

Get RPN tree size

I've implemented the following 'tree sizer' but it fails under certain conditions, the example below returns size 2 when it should return size 4, can anyone help me out. I've written this several times, to no avail, it keeps failing. def…
4
votes
1 answer

Trying to convert reverse polish notation to infix using an stack of strings, running into a small error and I don't know what's causing it

I've got a string stack implemented and I'm trying to convert rpn to infix using it. This is how the stack should look as the infix function works, for example if I entered 2 3 + 5 - 8 * : 2 //push 2 2,3 //push 3 (2+3) …
ccarlos999
  • 41
  • 3
4
votes
2 answers

Infix to Postfix and unary/binary operators

I have a piece of code that converts an infix expression to an expression tree in memory. This works just fine. There's just one small trouble. I just connect work out how to involve the unary operators correctly (the right associative ones). With…
Jaapjan
  • 3,365
  • 21
  • 25
1
2 3
13 14