For example, imagine a function like this:
int solveSomeEquation(int y)
{
y = (int x) * 2;
return x;
}
Using symbolic algebra, the compiler would determine that x = y / 2. Even better, it would complain that int is not sufficient for storing the result of y / 2. Imagine this functionality extending to solving ODEs with constraints and/or boundary conditions, and integration using symbolic or numeric methods (at run time) where needed. I, for one, would love to see something like this:
int areaOfUnitSemiCircle()
{
auto semiCircleFunc = [](double x){ return abs((1 - x^2)^0.5); };
semiCircleFunc = (auto semiCircleIntegralFunc)'; // single quote means derivative
return semiCircleIntegralFunc(1) - semiCircleIntegralFunc(-1);
}
simplified to:
int areaOfUnitSemiCircle()
{
return Pi/2;
}
Furthermore, it would be able to not only simplify expressions locally inside a function, but perform whole program optimization. It could rearrange expressions to improve numerical stability (reduce the effect of floating point error) or even eliminate them entirely by using a different representation. BigInt, IEEE1394's quadruple-precision float, sets defined by a predicate, integration over piecewise functions. Probably loads more could be done.
Such a thing is possible, no? I know you can perform stuff like this using Mathematica's or MatLab's programming language functions, but they are called BY the source code. I want it to be applied TO the source code by the compiler. (Do these languages have this sort of thing? I don't know.) I love using Mathematica at work when I have an excuse, but then I end up with magical-looking functions in C++ that make no sense without referring to an external Mathematica notebook. I'd like to be able to be a mathematician and a programmer in one language, one environment. Does such a thing exist?