July 16 2013
Kalkyl getting some help from Sage
Kalkyl is the module in Continuous that takes care of symbolic math operations. Why does Continuous need to handle symbolic math? Well, it would be possible to create visualizations with only numerical calculations, but the whole application would become much less flexible.
How about numerical calculations using eval?
But then let's say that we want to visualize the partial x derivative by applying a color gradient to the surface, where red means large positive derivative and blue means large negative derivative. Of course we would need to calculate the derivative in every point. We could calculate a numerical approxiamation, but come on! The results would be inaccurate, and if we wanted to show a mathematical expression of the derivative to the user, it would be impossible.
Hello, expression trees
What Kalkyl does is that it parses input from the user and builds up data structures called expression trees. Finding the derivative of an expression is just a matter of traversing the tree and applying differentiation rules from calculus. These trees also make some simplification of expressions possible by searching the trees for known patterns that can be rewritten in a simpler way.
Symbolic integration and solving equations?
The open source community comes to the rescue, I hope.
I found an open source alternative to Mathematica and Maple, written in Python and published under the GPL license. Sage is capable of integrating expressions, solving equations and much more. My plan right now is to get Sage running on a web server, and let Continuous ask Sage for help when Kalkyl is not smart enough to do the math.
As some of the computation moves from the browser to a server, the application has to be designed to be much more async in its nature. It will be a real challenge to avoid callback soup. This article seems to explain some common ways to tackle this challenge, so I suppose reading it thoroughly will help me on my quest.