Skip to content

lamhoangtung/Simple-Calculator-using-Reverse-Polish-Notation

Repository files navigation

Simple-Calculator-using-Reverse-Polish-Notation

Simple Calculator using Reverse Polish Notation in Python

How to run

When main.py is running, you will be able to input your expression, the program will evaluate your expression and also plot an Expression Tree to the console and to a .dot file:

alt text

It's also can handle one variable function, when evaluate the expression, the program will ask you to input the value of the variable:

alt text

You can use dot tool from the graphviz package to render the expression tree into a .png image:

dot tree.dot -T png -o tree.png

You can also copy all content inside the tree.dot file and use Webgprahviz to plot the tree right inside your browser:

If the expression is an one variable function, this program can plot it to a .png file. It will ask you the range of the graph and how many point (how acurrate) you want the graph to be. Keep in mind, you shoudn't plot with too little points since it may lead to wrong graph:

Dependencies

The code was developed with the following configuration:

  • python 3.6.4
  • anytree 2.4.3
  • graphviz 0.8.4
  • numpy 1.14.2
  • pandas 0.22.0
  • matplotlib 2.2.2

Other configuration will reasonably work

Documentation

You can see the details documentation about how I make this calculator in the [notebook file](Simple Calculator using Reverse Polish Notation.ipynb).

Contributing

Please feels free to contribute to this project, there are a lot of room for improvement, my suggestion are:

  • Evaluate expression using expression tree and DFS
  • Making UI (currently running on console)
  • Add support for more variable (currently support only one variable)
  • Add more operator (currently support + - * / ^ and sqrt)
  • Better method for plotting function

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details