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

In Practal [1], you could declare the sum operator as

    \sum i. lower upper t[i]
and then write the above sum as

    \sum i. 1 100 2 * i + 1
(after * and + and numbers have been defined as well)

There is no reason why the above cannot work both as math notation and as code.

[1] https://practal.com



> There is no reason why the above cannot work both as math notation and as code.

\sum_{n=1}^{\infty} \frac{1}{n^2}


That would not be a problem in Practal. That just falls into the non-executable subset. And all that means is that you have not set up equations that are executable and that handle this case. Actually, you could set things up so that this evaluates up to a certain error bound based on a proof of monotone convergence. All without redefining \sum, but by proving additional equations for \sum.

Note that I am not saying that math is code. Practal is based on logic, and logic transcends code. What I am saying is that code is math. At least, that's obviously true for purely functional code. So there is no reason to write the subset of code which is purely functional not in math notation.


Unless the compiler or runtime is smart enough to recognize the limit of that series [1], the naive implementation is an infinite loop which will never terminate.

[1] https://www.youtube.com/watch?v=d-o3eB9sfls




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

Search: