Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not regularly but I used it recently at work to compute symbolically the sum of a non-trivial series. Turned out the sum has a closed form, which allowed me to replace an O(n) for loop with an O(1) bunch of additions, multiplications and divisions. Felt nice.


Can you give an example?


Sure, here's one: given a list of n items, compute the sum of pairwise distances between every pair of items.

The first item has distance 1 from the second, 2 from the third, ..., n-1 from the last. Similarly, the second item has distance 1 from the third, 2 from the fourth, ..., n-1 from the last. And so on until the (n-1)-th item.

Expressed as a finite sum, this amounts to:

  sum (sum j, j=1 to n-i), i=1 to n-1
Paste this to Wolphram Alpha and you get the answer in a closed form: http://www.wolframalpha.com/input/?i=sum+%28sum+j%2C+j%3D1+t...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: