Revisiting my mathematical parser and pretty print code

First thing: Happy New Year all! I hope you had a nice break as well πŸ™‚

I decided to rewrite my own mathematical parser in order to adapt it to a project I have in the pipeline. At the moment I managed to keep out of the project quite some code thanks to one simplification that comes for free due to the recursive approach I followed.

Here’s a little example of what it is currently capable of doing:

parse "cos(1/sqrt((x^2+y^2/3)/3-x*y/48))^2+(x^2/2-y+e)/(x+2*y/-3+1)/pi"

answer (x=1.1, y=2.1) = 0.772024

                                     2
                                    x
                                   ---- - y + e
                                     2
                                 ---------------
                                       2*y
                                  x + ----- + 1
   2/           1          \            -3
cos |----------------------| + -------------------
    | /------------------- |            pi
    | |        2           |
    | |  2    y            |
    | | x  + ----          |
    | |        3      x*y  |
    | |----------- - ----- |
    \ V     3          48  /

Of course the output looks very basic on a console, but wait until I start using special characters in my upcoming project πŸ™‚

This entry was posted in Mathematical and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s