Questions tagged [prefix-notation]

Prefix notation (also known as normal Polish Notation (NPN) or Łukasiewicz notation) is a mathematical notation wherein every operator precedes all of its operands, in contrast to Reverse Polish notation, which puts the operator in the postfix position.

Prefix notation (also known as normal Polish Notation (NPN) or Łukasiewicz notation) is a mathematical notation wherein every operator precedes all of its operands, in contrast to Reverse Polish notation, which puts the operator in the postfix position.

Both prefix and 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.

21 questions
5
votes
4 answers

Simplification of prefix notation

I am working on a Kattis problem, where I am supposed to take the input in prefix notation, simplify it and return it in prefix notation as well. These are the examples of inputs and outputs: Sample Input 1 Sample Output 1 + 3 4 …
Leff
  • 1,968
  • 24
  • 97
  • 201
4
votes
4 answers

Prefix notation to infix notation in Python

I am writing a small calculator (with prefix notation) and I'm curious how I'd convert prefix notation to infix notation. I currently have a function, but it's being weird, and I'm not sure how to fix it. By being weird, I mean that if given ['+',…
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
3
votes
3 answers

Postfix and prefix increment that causes an error

Why does that code does not compile due to an error: #include using namespace std; int main() { int i = 0; cout << ++(i++) << " " << i << endl; return 0; } While that code does compile: #include using namespace…
Yaroslav
  • 1,325
  • 1
  • 11
  • 23
2
votes
2 answers

How can I check whether the given expression is an infix expression, postfix expression or prefix expression?

I need algorithms that will check whether given expression is infix, postfix or prefix expression. I have tried a method by checking first or last 2 terms of the string e.g. +AB if there is an operator in the very first index of string then its a…
Ahsan
  • 412
  • 5
  • 17
2
votes
1 answer

Pseudo code into logical steps?

I am trying to solve the coin-change problem: Given a list of number , k , how many ways are there to give change to a given amount m. As one of the resource I have the following pseudo code: (define (count-change amount) (cc amount 5)) (define…
Bula
  • 2,398
  • 5
  • 28
  • 54
1
vote
1 answer

reversed string not being returned in a c function in program of infix to prefix

Below is the code for infix to prefix conversion. My code works fine until the use of reverse function where it does not print any string after copying. I have tried using a for loop to copy the reversed string but the outcome remains the same and…
1
vote
1 answer

Match two nested logical AND OR expression tree objects

I need to compare a given logical expression with another in java, to identify if both are the same. For example, consider an expression as ((a&b)&(c|d)&(e&f)) and other as ((a&e)&(c|d)&(b&f)), they both are equivalent. Consider (a&(f&(b&e))&(c|d)):…
user7630232
  • 135
  • 1
  • 3
  • 16
0
votes
2 answers

How to use integer methods using `method`, not their infix form, in Ruby

I am looking to programmatically apply a typically infixed operation (eg: +, -, *, /) on two integers, where the operation is specified via a string. I have had success accessing the method itself using .method This is a pattern that works, 1.+(2)…
0
votes
1 answer

How to extend the postfix(or prefix) notation to support functions with arbitrary parameters?

I need to implement an expression evaluator with some custom types, it is easy to evaluate expressions with only numbers or variables with the help of postfix (or prefix) notation but how to extend the postfix (or prefix) form to support functions…
0
votes
1 answer

Why popular programming languages like c, c++, java, python, PHP doesn't support postfix (Reverse Polish Notation) or prefix expressions?

Note:- I'm not talking about Increment & Decrement Operator. I'm talking about prefix & postfix expressions. Example in python:- def calculate(a, b, c, d): return a * ( b + c ) / d calculate(1,2,3,4) I know that python doesn't support prefix…
Frank David
  • 187
  • 1
  • 3
  • 9
0
votes
1 answer

how to write in reverse direction in c

This is my first question so pardon for non technical language I am making a program to convert infix to prefix and postfix. I made infix to postfix which is working. Now when I want to infix to prefix we need to reverse the expression. So I thought…
Parnaval
  • 1
  • 2
0
votes
0 answers

Prefix/Polish notation for propositional and temporal logic expressions?

I have propositional and temporal logic expressions like: "phi1 => phi2"; "phi1 U phi2"; "X phi1". I would like to represent them using prefix notation, i.e, "phi1 U phi2" would be represented as "U phi1 phi2". Any ideas on which data type to use…
0
votes
1 answer

Double '+' signs messing with !NaN in JS

Working a evaluator for Polish Notation and I was adding a way to distinguish if the string I got was a number or not using the isNaN function. This works fine, until you add + + to the string. function cuttingString(list) { let adjustArr =…
4156
  • 380
  • 4
  • 17
0
votes
0 answers

Problem in converting infix expression to a prefix one

Here I am converting an infix expression to a prefix expression. For some test cases my result is perfect. But for certain test cases I get an output which is correct according to some sites but wrong according to other sites. So I am in a dilemma…
Umang
  • 109
  • 2
  • 10
0
votes
2 answers

Is it possible to call the << operator using prefix notation?

I am wondering if I could write, for instance: <<(object, cout); or <<(cout,object); where object is a user defined class which has the << operator overloaded, just as one could write: int a = +(2,3); and obtain the expected result, as in int a = 2…
M.Ionut
  • 187
  • 1
  • 3
  • 15
1
2