Re:A History of APL in Fifty Functions (2016)
by Y_Y on Thursday November 21, 2019 @05:45AM
(#21592925)
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.
[ Parent
| on HN ]
Re:A History of APL in Fifty Functions (2016)
by contravariant on Thursday November 21, 2019 @06:11AM
(#21593048)
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.
Re:A History of APL in Fifty Functions (2016)
by dubya on Thursday November 21, 2019 @10:11AM
(#21594796)
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.
Re:A History of APL in Fifty Functions (2016)
by david_draco on Thursday November 21, 2019 @06:00AM
(#21593004)
You can do that easily in numpy. ((x>0)-(x<0))*1 will give zeros and ones.