Integration is hard!

If integration seems hard to you, that’s because it really is! Integration is generally much harder than differentiation and this little demo illustrates that algorithmically.

The code below is written with SageMath - a full blown computer algebra system built on top of Python. When you hit the “Evaluate” button to evaluate the code, a random function will be generated. Sage will then differentiate the function and attempt to integrate it. The time taken to perform those computations will be reported as well. The function is generated using an iterative procedure and the number of iterations is controlled by the depth parameter. You can set the depth and, generally, the larger the depth, the more complicated the function. You can also specify your own function like f(x) = sin(x), if you like.

Sometimes, the integration computation will timeout and, if so, the random_function command will no longer be defined. Just hit the reload button and try again, in this case.