2 ms·
It's an interesting exercise to think about why the performance of Sum[i, {i, 1, 100000}] differs between Mathics and MMA. Mathics just calls down to sympy, whi
by nxobject 2y ago
It's an interesting exercise to think about why the performance of Sum[i, {i, 1, 100000}] differs between Mathics and MMA. Mathics just calls down to sympy, which I think just does the sum in Python [1]. Mthematica (likely) identifies your sum as the 100000th triangular number, and computes it directly in native code, since I know Mathematica relies heavily on standard tables of summations/integrals/etc. [2]
[1] https://github.com/sympy/sympy/blob/master/sympy/concrete/summations.py https://github.com/sympy/sympy/blob/master/sympy/concrete/su....
[2] See Sum's Method option.
- williamstein 2y agoPure Python is on the order of 1000x faster at computing that sum by brute force than Mathics. This suggests that perhaps some of the basic optimizations one does when implementing a language, to get even the most minimal level of performance, haven't yet happened with Mathics. For example, when we added asymptotically fast arbitrary precision integers to SageMath (by wrapping GMP, then later MPIR), we had to implement an "integer pool" since otherwise a lot of everyday microbenchmarks were far too slow.