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

I wish the "Iverson bracket" (number 0 in this list) had caught on in a bigger way. It can really simplify writing conditional expressions, as opposed to e.g. a case expression.


It's also an exceptionally useful technique in mathematics if you've got a few nested sums with dependend indices. By writing the condition in an Iverson bracket it becomes trivial to change the order of summation or change one of the variables.


I don't know if Knuth popularized it, but it's somewhat common in combinatorics. Similar idea to using indicator functions when doing change of variables in calculus.

https://arxiv.org/abs/math/9205211


You can do that easily in numpy. ((x>0)-(x<0))*1 will give zeros and ones.




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

Search: