collapse collapse

* Who's Online

  • Dot Guests: 38
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11163
  • stats Total Topics: 1699
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 248

Author Topic: Math parsing engine  (Read 3268 times)

0 Members and 1 Guest are viewing this topic.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Math parsing engine
« on: January 11, 2014, 08:46:18 pm »
So... I've been in calculus for a while now (pre cal, calc 1, calc 2, etc...) and it is sort of killing me that I can't do anything programming related with the knowledge I have, or so I thought. The idea came to me recently when I was checking out online calculators such as wolfram, desmos, mathway, etc... These engines are amazing but they are all web based. There are, of course, libraries that can be used to interpret scripts and perform the math, however I've noticed that these are all severely limited in the features I am looking for. For example, almost all of the libraries currently out there will only return approximate answers. sqrt(2) for example will return a large decimal instead of simply sqrt(2) as the exact answer. Since we already have a math library in the works [ http://celestialcoding.com/evolutionary-code-zone/physics-class-evolutionary-introduction/ ], I figured I'd add to it and create a engine to walk beside it. This will be an opensource project as all my projects are and I intend to update it as I travel through my classes.

Any ideas would be appreciated.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline bacon

  • Newbie
  • *
  • Posts: 16
  • Reputation 2
  • Gender: Male
  • Clever text
    • View Profile
Re: Math parsing engine
« Reply #1 on: January 14, 2014, 06:07:54 pm »
The way Matlab/Octave do it is by using "symbols". Basically you have a base class "Sym" that you extend all your operators for but instead of returning floats, you return the appropriate symbol.

Also you may want to check out the GNU scientific library, https://www.gnu.org/software/gsl/ (and the documentation https://www.gnu.org/software/gsl/manual/html_node/). I need to learn it too but it looks pretty sweet.
to do: siggeh

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Math parsing engine
« Reply #2 on: March 08, 2014, 07:11:56 pm »
Well, I've pretty much given up on this. After multiple tries, I've come to the sad realization that sometimes humans can perform feats that computers just can't do well yet. During the course of my calc class, I attempted to replicate much of the math I was doing by hand with a parser. The conclusion I was, admittedly frustrated, to come upon was that Calculus requires extensive parsing and guesswork to come to a solution even close to what you are attempting to solve. Many easier problems are not a problem, but it appears VERY difficult to parse harder problems. I've attempted this for the past few weeks hoping for a break through, but it appears that the guess work is simply too much for me, so I simply abandoned it in favor of a new project. Soon I will be entering my physics class. I WILL create a parser for that one since it is pretty straight forward and I have experience from making them in the past. On the bright side though, I feel I have a replacement project that others may enjoy more. See the release area for more information.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline mager1794

  • Jr. Member
  • **
  • Posts: 91
  • Reputation 293
    • View Profile
    • My Game Challenge
Re: Math parsing engine
« Reply #3 on: March 13, 2014, 09:53:13 am »
Couldn't an effective method to complete this is to keep a list of all the calculations being done by the problem and then once your receive your decimal value begin working backwards to display the proper answer?

Simple Example.
sqrt(100 + 2/8);

2/8 = sqrt(100 + .25), division
100.25 = sqrt(100.25), addition
10.01249 = 10.01249, sqrt

now
apply the inverse of the function
and go back to sqrt(100.25)

check that there are no arithmetic functions left in your solution. and finished.  Just tossing ideas in case you wanted to pursue this challenge.
http://mygamechallenge.wordpress.com/2010/07/23/personal-game-challenge/ - My Personal Challenge To Finish My First C++ Game

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Math parsing engine
« Reply #4 on: March 13, 2014, 07:59:41 pm »
Couldn't an effective method to complete this is to keep a list of all the calculations being done by the problem and then once your receive your decimal value begin working backwards to display the proper answer?

Simple Example.
sqrt(100 + 2/8);

2/8 = sqrt(100 + .25), division
100.25 = sqrt(100.25), addition
10.01249 = 10.01249, sqrt

now
apply the inverse of the function
and go back to sqrt(100.25)

check that there are no arithmetic functions left in your solution. and finished.  Just tossing ideas in case you wanted to pursue this challenge.
This only works for basic math. Try doing advanced derivatives/anti derivatives like that. It is nearly impossible since there are hundreds of real solutions. For example, finding the antiderivative of
3x^2 = x^3+C

That constant can literally be ANY value. Although this isn't a problem for this simply one, once you start getting into using cosine, sine, tangents and so on, it becomes a huge hassle.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Math parsing engine
« Reply #5 on: March 13, 2014, 08:49:29 pm »
Couldn't an effective method to complete this is to keep a list of all the calculations being done by the problem and then once your receive your decimal value begin working backwards to display the proper answer?

Simple Example.
sqrt(100 + 2/8);

2/8 = sqrt(100 + .25), division
100.25 = sqrt(100.25), addition
10.01249 = 10.01249, sqrt

now
apply the inverse of the function
and go back to sqrt(100.25)

check that there are no arithmetic functions left in your solution. and finished.  Just tossing ideas in case you wanted to pursue this challenge.
This only works for basic math. Try doing advanced derivatives/anti derivatives like that. It is nearly impossible since there are hundreds of real solutions. For example, finding the antiderivative of
3x^2 = x^3+C

That constant can literally be ANY value. Although this isn't a problem for this simply one, once you start getting into using cosine, sine, tangents and so on, it becomes a huge hassle.

TI-89 has an engine for derivatives/anti derivatives/integrals it's pretty sweet. I believe those engines run off of lookup tables though - I don't believe there is a way to solve them "algorithmically" without a lookup table. See this youtube video: http://www.youtube.com/watch?v=l3Wrq_sVkCU

Obviously, you could create a formula that you couldn't possibly integrate I think that the calculator would just calculate an estimate using one of the algorithms.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

 

Donate


* Search


* Recent Posts

Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]


Re: Client-Server Messaging by Nathan
[October 25, 2015, 05:48:57 pm]