I'm interested in writing a program in Python that can parse a mathematical expression and carry out operations on it in algebraic form. Most of these will be pretty easy, something like 2x+5x+xy
. My program would take this and return the simplified 7x+xy
. However I'd also like to eventually extend it's functionality to calculus as well, so if it's given something like integrate: 5x
it should be able to return (5x^2)/2 + c
. I'm aware that for this the sympy library can be used, but I'm interested in implementing it myself as a learning process. Are there any algorithims that exist to carry out algebraic calculus for any arbitrary integral/differential I could implement, or is this a more daunting task I've set for myself here? Any reasources would be appreciated.

- 9,280
- 9
- 43
- 57

- 306
- 2
- 11
-
1Integrating any function? This is already hard to do by hand. Many functions do not even have a closed-form anti-derivative. Not speaking about all the parsing hassle. – Nico Schertler Jun 07 '19 at 19:20
-
Of course, but several implementations of analytical calculus do exist none the less. What's the method being used in those cases? Where can I learn about it? – muke Jun 07 '19 at 19:21
-
Reading the sympy codebase might help you getting started – Reblochon Masque Jun 07 '19 at 19:24
1 Answers
It might be worthwhile to ask why you're looking at doing this, and understanding the sorts of things that you want to be able to integrate, because I think you might not know that you've actually stumbled onto a very difficult question.
If you are looking for an exercise to learn about simple low level polynomial integration and python - ie. something of the form x^2 + 2x + 7 - and the idea is to learn about string manipulation and simple math, then by all means I think you should attempt to do this and see how far you can get. Look at the various math related libaries (like Sympy or Numpy) and see what you can get.
If you are looking to produce a powerful tool to be used for Calculus, then I think you should rethink your idea and consider using something like Wolfram Alpha. A project like this could take years and you might not get a good result from it.

- 51
- 4
-
Alright, I'll stick to using sympy to cover this part of my program then. I had just thought there might be some kind of set method to follow, but it seems I underestimated the scale of this problem. Thanks. – muke Jun 07 '19 at 19:35