Fundamental Issue With calcagebra

calcagebra currently acts great as a powerful calculator however its supposed to do much much more, like take derivatives, integrate of course solve equations. The math behind derivatives is not particularly difficult by itself, it is simply following a set of rules until I have no more expressions to derive.

There is currently a function in the standard library to do this called differentiate which takes in a function and then returns the resultant expression.

A long time ago …

When differentiate was not a function in the standard library, Matrix was the newest addition to the data types, Integer and Real had just been merged with Complex Numbers. Times were simple, almost all functions would take in a number and return a number.

This was done by evaluating every expression before sending it as an argument to the functions.

Except for graph which took in an expression so it could read the Expression::Identifier(ident) to get the name of the function for graphing. Not the best solution but it worked for a single function. After this there were some complications with accuracies and so Decimal was introduced but everything was going well.

Sum function

Until I thought of adding the sum function to the standard library. The sum function was essentially supposed to be Σi=knf(i)\Sigma_{i = k}^{n} f(i).

Now simply iterating from k to n is the first idea that may come to mind, but this is a really bad idea from the performance point of view. And it does not give me a way to calculate series which converge such as limnΣi=1n12i\lim_{n \to \infty} \Sigma_{i = 1}^{n} \frac{1}{2^i}.

Though there was these issues I still went down the route thinking I would change the code later (never do this).

There are ways to know if a series will converge when summed to \infty, and ways to calculate summations without going through all the terms.

Some common ones are Σi=1n1=n\Sigma_{i = 1}^{n} 1 = n, Σi=1ni=n(n+1)2\Sigma_{i = 1}^{n} i = \frac{n(n+1)}{2}, Σi=1ni2=n(n+1)(2n+1)6\Sigma_{i = 1}^{n} i^2 = \frac{n(n+1)(2n+1)}{6}, Σi=1ni3=[n(n+1)2]2\Sigma_{i = 1}^{n} i^3 = [\frac{n(n+1)}{2}]^2. Apart from these, arithematic, geometric and even the arithemtico geometric series have formulas for calculation.

So now the only thing left to do is to check if any of these cases hit and then calculate them seperately and for the case that we cannot to iterate, still not the best solution but certainly better.

However actually implementing this turned out to be immediately a bit difficult.