569 questions
2
votes
0
answers
160
views
Simplify a prime factorization-like expression with optimal performance [closed]
I am working with a situation in which I need to turn an arithmetic string expression (e.g. (3/2) * (3**4 / (20 * 4))**(-1/4)) into the following prime factorization form: $\prod_{p:\text{prime}}p_i^{...
-1
votes
2
answers
259
views
Algorithm for converting infix to postfix with Python
I am attempting to write up the following algorithm (provided in ordinary English) in Python for converting simple mathematical expressions from infix form to postfix form:
Create a new empty list, '...
1
vote
1
answer
135
views
Infix to postfix left one parentheses at the end when expression is fully enclosed
I'm working on a problem in my data structures class and I've managed to do most it in terms of implementing the algorithm and getting the core logic sorted. But one problem that I keep running into ...
1
vote
1
answer
45
views
Why is my postfix evalutation function not working?
This is what I have so far, this is a continutation of some pythoncode my classmate wrote and we keep getting lots of errors.
I think the errors lie somewhere in the if and for loop but I am fairly ...
1
vote
1
answer
556
views
Infix to postfix in c
I am trying to convert a given infix expression to prefix expression in c. But i am encountering a problem in it. The value in postfix is not getting updated. Please help me understand what the issue ...
1
vote
0
answers
106
views
Ruby infix to postfix math expression converter (to RPN)
First of all, I started learning Ruby only 2 weeks ago, so please do not judge too harshly.
I wrote a script that does not work correctly with mathematical expressions containing parentheses. The ...
1
vote
2
answers
109
views
Unary negation ignored in user input in my pemdas calculator using python
I'm having issues with my PEMDAS calculator built in python. The issue that I'm encountering is mainly that I can't find a way to make my code recognize the "-" sign at the beginning of the ...
1
vote
1
answer
181
views
Postfix to Infix notation conversion in C
I am having a problem converting from postfix to infix in C.
I know where the problem is, but I don't know how to fix it.
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
...
0
votes
1
answer
193
views
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 ...
-1
votes
1
answer
59
views
my python code corrupts '*' into '(' when pushed to a Stack class
If I push a character to the Stack and peek at it, it gives me different characters even when no interaction was made after the push.
The relevant class and functions look like this:
class Stack:
...
1
vote
0
answers
39
views
switch-statement gives correct output but if-else doesn't [duplicate]
I was solving a question where the task is to evaluate the postfix expression and find the final value.
this is my solution code
public static int evaluatePostFix(String S)
Stack<Integer> s = ...
0
votes
0
answers
97
views
Infix to postfix assignment
I've been stuck on this program for about a week and I can't see what I'm doing wrong. I can't get the operands and operators to print in the proper spot and the '(' ')' won't delete. Here's what I ...
0
votes
2
answers
98
views
how to add together the values from the RPN algorithm
I’m writing calculator that calculates values from expressions:
3+(23/24)*34/24
I used RPN algorithm: https://en.wikipedia.org/wiki/Reverse_Polish_notation
I have now sorted expression in String:
...
0
votes
1
answer
113
views
postfix evaluation calculated result is wrong
I'm trying to implement postfix evaluation using stack, but the result after calculation is not correct, I cannot figure out which part makes the calculation wrong, thanks a lot.
import java.util....
-1
votes
1
answer
770
views
How to fix 'NoneType' has no attribute 'key', when trying to compare a key value to a string
I am writing a program where the user inputs a postfix expression and it outputs the answer. Current I am stuck when Using my 'evaluate' function within my for loop.
Inside my For loop Main.py:
else:
...
-1
votes
1
answer
229
views
Infix -> postfix translator in antlr4
I need to define the semantic actions required to translate infix notation to postfix notation by embedding semantic actions as Java code in the g4 grammar file.
For example, when I try to input "...
-2
votes
1
answer
64
views
A program which evaluates a mathematical expression by first converting it into RPN and evaluating the result using precedence of operators
#include <stdio.h>
char infix[200];
char stack[200];
char queue[200];
int count_stack = 0;
int count_queue = 0;
int precedence(char x)
{
switch (x)
{
case '^':
return 2;
...
0
votes
0
answers
139
views
Made an infix to postfix converter and calculator using an array based stack in c++. The calculations don't work. Only returns the top of the stack
My problem is that my evaluatePostfix() function is not calculating operands. It only returns the top of the stack in the converted postfix expression.
So for example, my output is:
Enter a infix ...
-1
votes
1
answer
620
views
I have written this code to convert an infix expression to a postfix expression using Stacks in CPP
#include<bits/stdc++.h>
using namespace std;
int prec(char c){
if(c=='^'){
return 3;
}else if(c=='*' || c=='/'){
return 2;
}else if(c=='+' || c=='-'){
return ...
1
vote
1
answer
388
views
Code to convert infix to postfix is not working in case of a+(b-c)*d$e/f+g$(h-i) as input
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n;
int stackfull(int top)
{
if(top==n)
{
return 1;
}
else
{
return 0;
}
}
int ...
0
votes
2
answers
481
views
Generate random postfix expressions of an arbitrary length without producing duplicate expressions
For a research project, we are currently using the Gamblers Ruin Algorithm to produce random postfix expressions (terms) using term variables "x", "y", and "z" and an ...
1
vote
0
answers
212
views
RPN to infix with both numbers and pronumerals in Python
I am making a Python program where I get an RPN expression separated by spaces and convert it to infix.
It should work like this:
Input RPN: x 2 ^ 3 - 1 2 x * - *
Output : -2x^3 + x^2 + 6x - 3
However,...
0
votes
1
answer
91
views
Problems about Scheme with postfix
Here is my code about postfix in scheme:
(define (stackupdate e s)
(if (number? e)
(cons e s)
(cons (eval '(e (car s) (cadr s))) (cddr s))))
(define (postfixhelper lst s)
(if (null? lst)
...
0
votes
0
answers
77
views
How can I fix my scheme code to solve the postfix problems?
Here is the code(Helped with https://stackoverflow.com/a/73017526/19567940) :
(define (update-s object stack)
(if (number? object)
(cons object stack)
(cons ((eval object (scheme-report-...
0
votes
1
answer
212
views
Scheme with postfix
Does anyone can help me to deal with the problem?
I tried for many times, but it still has the error information.
This is my code(scheme)
Thanks!!!
(define (postfix l s)
(cond(
((null? l)(...
1
vote
1
answer
289
views
Android Studio Java infix to postfix calculations decimal point gives crash
I was trying to make a calculator for my university homework. to calculate the results I use infix to postfix convention. but this code doesn't take only decimal point (.) as a result, it crashes ...
1
vote
0
answers
402
views
Convert infix to postfix which make use of user defined functions
What would be a good algorithm to convert infix to postfix of an expression which uses user-defined functions:
For example:
def get_random_integer(a, b, c):
import random
return random.choice([...
0
votes
1
answer
170
views
SPOJ ONP - Transform the Expression. Wrong Solution but all test cases given on the website work
It works for all the test cases as long as the input string has "()" in it. If I input let's say (2+3) or even 2+3) it will print my the correct solution which is 23+. But if I input 2+3 ...
-3
votes
1
answer
301
views
Postfix to Infix conversion in C++. "Process returned -1073740940 (0xC0000374) execution time : 5.538 s". No clue why [closed]
The question is to convert a postfix expression to an infix expression using stacks and without stack library.
Im getting a statement after i run it and enter my postfix expression saying : "...
-1
votes
2
answers
126
views
Why does my shunting yard implementation mix operator order?
I have been trying to implement the shunting yard algorithm, but the output of my parser is incorrect.
let mut stack: Vec<String> = vec![];
let mut op_stack: Vec<String> = vec![];
for ...
1
vote
1
answer
232
views
infix to postfix conversion using stack shows an infinite loop
below is the code of infix to postfix conversion using stack.The code executes an infinite loop printing stack underflow in one of the pop function ,i have tried commenting pop function call in right ...
0
votes
0
answers
126
views
Implement the max operator in RPN (postfix) calculator
I try to implement a RPN (postfix) calculator but a requirement for this is use the MAX operator such in the following examples
input: 5 2 "MAX" 2 1 "MAX" "*"
output: 10
...
0
votes
1
answer
198
views
Recursive function variable problems
My recursive function accepts a String prefix and an int index of this string (0 initially).
Depending on the index calculates a postfix string.
Storage is a class that holds the postfix string and ...
1
vote
0
answers
342
views
How to convert from infix to postfix without using any methods
We are supposed to write a program using the stack class that converts a string from infix to postfix using JOptionPane as the input method. We are supposed to do it all in one big for loop and one ...
0
votes
0
answers
42
views
SIGSEGV Fault in infix to postfix using stack
When I tried making if condition to while loop to remove more than one operator from stack in bracket (f+g/h) here output should be (fgh/+) but i am not able to run the code with while loop my output ...
0
votes
1
answer
1k
views
Evaluate multi digit expression
I wrote this code to evaluate postfix expressions, but in this code I can only evaluate an expression with only single-digit numbers. I want to edit this code for it to evaluate multi-digit numbers. ...
4
votes
3
answers
2k
views
Can you implement arithmetic operator as variables in C?
I'm trying to program a reverse polish calculator and I didn't wanted to write switches for every single arithmetic operator inputted. Is it possible to input an arithmetic operator and use it as such ...
0
votes
0
answers
47
views
Better approach for this function that calculates a mathematical expression from a string? [duplicate]
The problematic to resolve:
Given a string that contains a mathematical expression, I need a function on C# language that receives that string and returns its decimal result that respects the ...
0
votes
1
answer
145
views
Postfix evaluating incorrectly
-2^2 (infix notation) should translate to -2 2 ^ (postfix notation). It does as expected however when evaluating that postfix it evaluates to 4 not -4 which is what is expected.
I'm using Lua and here'...
0
votes
1
answer
95
views
I am writing a program to solve reverse polish expression but getting error
I am getting error for no operator "==" matches these operands -- operand types are: info == charC/C++(349)
I guess this is due to the fact im using couston data type
I making program to ...
0
votes
3
answers
570
views
If you have 4+3*2, is there an algorithm to calculate this in one pass?
So I implemented this before in JavaScript as a little practice and was sure I found a Wiki page for an algorithm that both converted a typical infix expression to post fix AND calculated the answer ...
0
votes
1
answer
116
views
python list append is not working in python evaluate reverse polish notation
class Solution:
def evalRPN(self, tokens: List[str]) -> int:
surya = []
x = 0
y = 0
res = 0
for i in range(len(tokens)):
if tokens[i]....
0
votes
1
answer
282
views
What would this postfix expression be in infix?
First time here, anyone know what this postfix expression would be in infix?
s s * x y z * * sqrt s t - / s t * +
Where sqrt is square rooting.
My current guess is:
(sqrt ((s * s) (x * y * z))) / (s - ...
0
votes
2
answers
585
views
Evaluate String to Double (Postfix-notation)
I wanted to create a method, that interprets this List (The method "words" splits a String into a list of words, that are seperated by \s.) in postfix-notation. This is what I got, by I am ...
-1
votes
1
answer
119
views
read-syntax function for postfix interpreter in racket
I write a read-syntax function but ı get this error. my read-syntax function is this:
(define (read-syntax path port)
(for([line (port->lines port)])
(parse-line line)))
The error is this:
...
1
vote
1
answer
16k
views
Postfix to Infix conversion in C
Can anyone help me with Postfix to Infix conversion in C?
I know the algorithm, it's something like:
Take the expression as input
if the char is an operand, then push it into the stack
if the char is ...
0
votes
0
answers
99
views
transforming postfix expression to expression tree C
I tried making a function which transforms a string in postfix notation to an expression tree. But i cant figure out what is wrong with it.
node_t* expressionTree(char *str,stack_t *p2)
{
int i;
...
-1
votes
1
answer
57
views
My functions have return statements, so why am I getting this error? TypeError: can only concatenate str (not "NoneType") to str
This method is part of a class that converts inputs from infix to postfix. An example input would be: "11.897/3.4+9.2-0.4*6.9/12.6-16.7="
I have some helper methods below the main method (...
-1
votes
1
answer
31
views
Iterating over a single string with no spaces and identifying floats and ints in python
I am trying to build an algorithm that converts infix to postfix. Here are the sample inputs below. You can see that it is all one string without spaces. Also, the inputs can have floats or integers ...
0
votes
0
answers
82
views
Runtime Error: Segmentation Fault (SIGSEGV)
I am trying to write a program to convert infix expression to postfix expression. But I am getting the error
Runtime Error: Segmentation Fault (SIGSEGV)
I know that
SIGSEGV is an error caused by an ...