Questions tagged [math-expression-eval]

Questions related to the parsing (and possibly the evaluation) of free-form mathematical expressions in strings, lists, or streams

Filter by
Sorted by
Tagged with
2 votes
1 answer
79 views

Boolean evaluation

Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the number of ways ...
user avatar
0 votes
1 answer
61 views

Function to perform a logical NOT in a string

I am using "tinyexpr", a cute library that can solve mathematical formulas in a string and I extended it such that it does logical operations with two operands as well. However I wasn't sure ...
user avatar
  • 1,375
1 vote
1 answer
66 views

Infix calculator programming challenge Kattis.com

I'm working on this C++ coding problem: Input is a sequence of up to commands, one per line, ending at end of file. Each command is a definition, a calculation, or a clear. All tokens within a ...
user avatar
11 votes
2 answers
628 views

Calculator using variable names

I've recently been assigned an assignment to create a word calculator, and given my knowledge in python is still quite lacking, I want to ask if anybody has any better ideas for any possible solutions....
user avatar
4 votes
2 answers
141 views

C++ calculator supporting five operators

Recently I started learning c++ and I had an idea to make a calculator, that can take any imaginable number and I wrote this code: ...
user avatar
  • 105
2 votes
2 answers
87 views

Shunting Yard Calculator - Extended to negative, complex, etc

This project is based off the shunting yard algorithm and has additional features such as negative value parsing. It's like a scientific calculator. I am looking to improve this project by getting rid ...
user avatar
  • 31
1 vote
1 answer
132 views

Evaluating infix expression with brackets

My assignment was to write a function that computes the value of an expression written in infix notation. We assume that we are using the four classical arithmetic operations +, -, * and / and that ...
user avatar
4 votes
2 answers
73 views

Formula filler and calculator

So I made this script for my calculator, so that I can just write whatever formula I want and the calculator would just ask for the missing pieces to do the calculations. I made it so that it would be ...
user avatar
5 votes
1 answer
118 views

Security of CS50 Calculator code (eval)

This is my first question on Code Review, so please let me know if I botched anything. After working for quite a while on my CS50 calculator, it has finally reached the point where I am completely ...
user avatar
  • 143
2 votes
2 answers
165 views

A postfix (a.k.a. Reverse-Polish Notation - RPN) calculator

As an exercise, I put together a postfix calculator using modern Fortran. Language apart, I am interested in knowing your take on the algorithm. As far as I remember from my freshman year (chemistry - ...
user avatar
0 votes
1 answer
167 views

Factoring the powers of 2 in Python

The powers of 2 are trivial to factor because all powers of 2 have one 1-bit and the rest 0-bits. Just iterate minus one 0-bit as follows: 10000,1000,100,10,1. And then convert the binary strings into ...
user avatar
1 vote
0 answers
111 views

A math parser written in Python and using infix to postfix conversion

Ive written this code over the course of the last days and it seems to work. However I'm not an experienced Coder so I don't know if my code is efficient enough. Any advice for improvements or nez ...
user avatar
2 votes
0 answers
89 views

Solving Exact Cover by Three Products in Python

I'm a computer-science hobbyist and found an NP-complete problem that is similar to both subset-product and Exact Cover by 3-sets. Here is a Reduction of Exact-Cover into my problem. I am multiplying ...
user avatar
3 votes
1 answer
787 views

Sequence and Series Solver

I made a sequence and series solver just for helping me solve homework, and I'm in dire need of ways to make it further compact and efficient, since I used brute force. If you want to see what this ...
user avatar
  • 1,180
5 votes
2 answers
345 views

Evaluating arithmetic expressions and plotting graphs

I just got started with Python. I created some code, and I want to know what more experienced devs think about it. What can I do better? What to avoid? ...
user avatar
  • 55
2 votes
1 answer
454 views

Verifying Mathematical Expressions

This is a part of my calculator program. I have to check if the input entered by the user is a valid mathematical expression. The first check is performed by another program, where the program checks ...
user avatar
  • 360
4 votes
1 answer
373 views

Evaluate mathematical expression in reverse Polish notation in C

This is a program exercise from The C Programming Language by Kernighan and Ritchie (Chap 5). It is based on my earlier question here on Stack Overflow. One user suggested to submit my code here, ...
user avatar
8 votes
3 answers
388 views

JavaRPN calculator

I have found that there is a distinct lack of an RPN calculator available to me, so I decided to make my own. I am still adding new functions to it, but as of now, I would like to refactor my code. ...
user avatar
8 votes
2 answers
239 views

Arithmetic/Geometric series calculator

I've written a small program that calculates Arithmetic and Geometric Partial Sums. I'd like feedback on anything possible, since I intend on writing a cheatsheet that encapsulates all PreCalculus ...
user avatar
  • 9,587
10 votes
2 answers
625 views

Synthetic division calculator

I've written a python program do perform synthetic division on a polynomial. There are a few constraints (listed in the module docstring of the program) on the polynomial, mainly because I haven't had ...
user avatar
  • 9,587
7 votes
1 answer
520 views

Infix to postfix conversion in C++

Here is a program for conversion of an infix expression to a postfix expression using a stack. I would like to know how I could improve my checking for invalid input, make my code more expressive, and ...
user avatar
  • 163
6 votes
1 answer
516 views

Shunting-yard Algorithm, implemented based on reference pseudocode

I have a lot of problems making this code look more elegant or to reduce its size. The algorithm is mostly copied from the pseudocode of wikipedia page. The difference is I prepare my string with the <...
user avatar
6 votes
3 answers
10k views

Evaluating a math expression given in string format

I am currently working on building a calculator using Java and JavaFX to practice my coding skills. I wrote the following methods to evaluate a given expression. What can I improve? Is there ...
user avatar
  • 61
4 votes
1 answer
3k views

Python Calculator using Postfix Expressions

Improved upon my previous calculator program. This program has the following features: Gives information using session prompts. Supports all common operators. Follows operator precedence. Use of ...
user avatar
  • 360
2 votes
2 answers
2k views

Simple calculator in Object-oriented JavaScript

There is a simple form which takes two numbers num1, num2 and an operation op. After ...
user avatar
6 votes
3 answers
4k views

Postfix calculator in Java

I made a postfix calculator in Java. The code performs the functions I planned without problems, However, I'm not satisfied with it, because it's too verbose and I couldn't split it up into methods ...
user avatar
1 vote
1 answer
96 views

Calculator for any number of inputs

The "nasty implementation" I mentioned is within the void calculator() inside of calculator.cpp. Everything goes well as long as ...
user avatar
  • 111
5 votes
2 answers
600 views

Parsing infix expressions in Clojure

I'm trying to teach myself Clojure by reading the Brave Clojure book online, and at the end of Chapter 7 there is an exercise to parse a mathematical expression written as a list in infix notation to ...
user avatar
0 votes
1 answer
51 views

Convert natural input into Python executable function

I have been developing a graphical calculator, and to allow for natural user input I have written a function which converts their input into a python readable form. This is my first time using regex, ...
user avatar
1 vote
1 answer
290 views

Evaluating an arithmetic expression from a binary tree

Let's say I have a Binary Tree that looks like + 2 * 5 8 I've written a function to traverse inorder to solve it as 2+5*8 Is ...
user avatar
  • 203
6 votes
1 answer
1k views

Writing monadic Haskell to evaluate arithmetic expression

I have been studying Haskell by myself for about a little over a year. And I have been stuck at monad/monad transformers for quite a while until recently some examples I read online enlightened me. So ...
user avatar
  • 327
3 votes
1 answer
147 views

Python implementation of Conway's chained arrow notation

A year ago, I implemented an evaluation algorithm for Conway's chained arrow notation in Python. I'd like to get a review on my code, especially about readability and if it is pythonic. I'd also like ...
user avatar
  • 690
3 votes
1 answer
729 views

Infix to postfix notation in Haskell (Shunting-yard algorithm)

I've written an infix to postfix converter in Haskell using the Shunting-yard algorithm. Example of how it works: ...
user avatar
1 vote
1 answer
463 views

Reverse Polish Notation evaluator in Haskell

I've created an RPN evaluator in Haskell, as an exercise because I'm new to this language. It runs well: $ ./rpn 2 3 4 5 + - + -4 And the source code: ...
user avatar
1 vote
1 answer
752 views

Calculate simple arithmetic string in Scala

Problem Given an arithmetic string like 2+2*3 calculate result 8. Assumptions you can make string will be always well formed (no error checking needs to be done) only operators passed in string ...
user avatar
  • 345
4 votes
2 answers
2k views

Calculate arithmetic expression represented by a string, in Java

I saw that interview question online and gave it a try: Implement a function that gets a string which represents an arithmethic expression: contains only numbers or the the operators: '+', '-', '*', '/...
user avatar
  • 213
4 votes
1 answer
141 views

RPN calculator in Chicken Scheme

My first attempt at Scheme (Chicken Scheme) - a simple RPN calculator. Please comment on exception handling as well as the general coding style. Here is the code: ...
user avatar
2 votes
2 answers
1k views

JS calculator, respecting order of operations

I have a function that receives an array of numbers and operations Ex: userEntry = [3,+,3,x,3] -> returns 12 It is a calculator that adheres to the proper ...
user avatar
  • 75
5 votes
1 answer
433 views

Recursive descent parser for simple arithmetic expressions grammar

What I'd like to see in your review, in order of relevance: Is there any bugs? (I see none, but...) Is the code efficient? (by whatever metric you'd like to use) Is the code easy to understand? ...
user avatar
  • 993
7 votes
2 answers
2k views

Basic arithmetic calculator with float, parentheses and operator priority support

Summary: The basic calculator which allows the end-user to calculate the value by evaluating the math expression string. It supports all the main arithmetic operators, also extended by modulo and ...
user avatar
4 votes
0 answers
451 views

Python expression calculator [closed]

This is a calculator I created. It can take all basic operators, including brackets. I am a beginner with Python so I want to know what can I do better next time I write something similar. ...
user avatar
  • 141
5 votes
2 answers
572 views

Converting Reverse Polish to Infix Notation in Java

I am trying to solve a programming challange that involves converting reverse polish notation to infix notation. For example: 1 3 + 2 4 5 - + / would be: ((1+3)/(2+(4-5))) My solution so far does work,...
user avatar
  • 151
2 votes
0 answers
972 views

Binary Expression Tree

I implemented a binary expression tree, I've used my previous shunting-yard parser to provide it the post-fix expression. I have a few specific questions outside of just comments about making it ...
user avatar
  • 113
5 votes
1 answer
7k views

Use Infix expression to construct a binary expression tree

Problem statement Construct a binary expression using infix expression. The infix expression uses extra parenthesis to enforce the priority of operators. For example, infix expression ...
user avatar
  • 2,386
5 votes
1 answer
2k views

Shunting-yard algorithm

I implemented the Shunting-yard algorithm in Python, I have experience in C# but I'm looking for comments making this more pythonic. I'm also be interested if these methods would be better as ...
user avatar
  • 113
6 votes
3 answers
3k views

Reverse Polish Notation calculator with unit tests

I had an interview with a global company yesterday. They had given me a programming assignment. I shared my screen and I must have finished the task in 1.5 hours. Task was programming Reverse Polish ...
user avatar
  • 173
7 votes
3 answers
11k views

Console calculator, takes a string as input (like: 2+3*4-1+3) and outputs the result

I am a beginner programmer(solo learning). I know the basics of c/c++, but I would not consider myself too experienced. Recently I decided to make this calculator which takes an array of characters as ...
user avatar
10 votes
4 answers
3k views

Validator for mathematical expression in infix form

This program will validate whether a mathematical expression entered by the user is a valid expression based off whether the expression itself has been entered with the correct scope openers and scope ...
user avatar
  • 181
14 votes
3 answers
2k views

Equation Evaluator

I am currently applying to many Software Engineer positions, and have been asked to complete several coding challenges. The most recent was an equation evaluator, written in C++, that was supposed to ...
user avatar
  • 143
6 votes
2 answers
14k views

Expression calculator in Python

This calculator accepts four operators: +, -, *, /, and works with parentheses. Feedback on how I could make it easier to read and or more effective would be much appreciated. This is the first time ...
user avatar