Fast.ai APL study session 12

While you’ve not really covered trains yet (though you’ve seen the mean←+⌿÷≢ example), sign←÷∘|⍨ can be written as the train (fork) sign←⊢÷| as follows.

Without going into all the details, think of the traditional mathematical notation (TMN) where (f+g)(x)=f(x)+g(x). Forks (3-trains) are just a generalisation of this pattern to all functions (though the middle one has to be dyadic). For n÷|n we have the + become a ÷, while g is |, but what is f‽ We just want n unmodified. This calls for an identity function à la f(x)=x, which is APL’s . So…
TMN: f(x)=x, g(x)=|x|, sgn(x)=(f÷g)(x)
APL: f←⊢ ⋄ g←| ⋄ sgn←f÷g or simply sgn←⊢÷|

2 Likes