Giter Club home page Giter Club logo

math-expression-evaluator's Introduction

Math expression evaluator

Program logic and limitations

  • The main algorithms used in the program are the Shunting yard and Reverse Polish Notation/AST evaluation to transform the mathematical infix expression into a postfix notation, making easier for computers to work with
  • I split the expression given by the user into many tokens - pass those to my infix to postfix function, then evaluate the AST
  • Taylor series was used to approximate the values of the trig functions

Limitations

  • one limitation is the need for spaces between numbers, functions and operators in your expression (see example below)

Dependencies

  • the github.com/golang-collections/collection repo is used for the Stack and Queue Data Structure

How to Build the program

clone the repo

git clone https://github.com/nizarbenalla/Math-Expression-Evaluator.git 

cd into the repo

cd MathExpressionEvaluator 

build the program

go build

Running the Program

the `-math` option is necessary

./MathExpressionEvaluator_ -math <expression>

Examples

./MathExpressionEvaluator_ -math "( cos ( 1 ) + 3 ) * ( 10 - 1 + 1 ) "
Your answer is :
35.4030230586814

./MathExpressionEvaluator_ -math "( 1 - 8 ) + ( 5 / 2 )"
Enter the expression you want to compute
-4.5

./MathExpressionEvaluator_ -math " cos ( 1 ) "
Your answer is :
0.5403023058681397

math-expression-evaluator's People

Contributors

nizarbenalla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.