13 ms·
Mastering Dyalog APL (2009) [pdf]
- conor_f 5y agoDyalog APL was my first exposure to functional programming outside of being in awe of Project Euler solutions in the forum back in the day. I spent a lot of time on https://tryapl.org/ https://tryapl.org/ before eventually moving on to running it on a raspberry pi ~10 years ago with my family TV as a monitor. A really great way to spend an evening or two. The syntax is wild in retrospect, and I cannot see where it could be used in a production environment today (if anyone knows, please tell me!) but it holds a nostalgic place for me :)
- jpf0 5y agoCompanies that use APL and other array languages in production: https://github.com/interregna/arraylanguage-companies https://github.com/interregna/arraylanguage-companies
- deleted 5y ago[deleted]
- protomyth 5y agoThe Feb 18, 2022 episode of The Array Cast interviews Morten Kromberg, CTO of Dyalog Ltd. https://www.arraycast.com/episodes/episode21-morten-kromberg https://www.arraycast.com/episodes/episode21-morten-kromberg - transcript: https://www.arraycast.com/episode-21-transcript https://www.arraycast.com/episode-21-transcript It is a great episode and talks a lot about some interesting history.
- raphlinus 5y agoI think APL has a lot to teach us about parallel (specifically GPU) programming. I've rewatched a few talks with Aaron Hsu and listened to his arraycast podcast[1]. In researching an upcoming blog post on monoids, I tried implementing the problem in Guy Steele's "Four Solutions to a Trivial Problem" talk[2] in APL (actually I tried GNU APL for this, because I didn't need anything fancy). This is what I came up with: +/((⌽⌈\⌽a)⌊⌈\a)-a That in turn should be fully parallelizable and run fast on the GPU, as it's based on a couple scan (generalized prefix sum) operations. There's a considerable amount of DNA from APL in modern compiler-based machine learning frameworks, mostly by way of numpy. Dr. Hsu makes a good case that APL has quite a bit of power which is considerably diluted in later spins such as numpy. I'm especially fond of the power (⍣) operator[3], which represents parallel iteration and I think can often be translated to a per-thread while or for loop in a compute shader. I don't believe numpy has anything quite like that (but feel free to correct me!). [1]: https://www.arraycast.com/episodes/episode19-aaron-hsu https://www.arraycast.com/episodes/episode19-aaron-hsu [2]: https://www.youtube.com/watch?v=ftcIcn8AmSY https://www.youtube.com/watch?v=ftcIcn8AmSY [3]: https://help.dyalog.com/15.0/Content/Language/Primitive%20Operators/Power%20Operator.htm https://help.dyalog.com/15.0/Content/Language/Primitive%20Op...
- moonchild 5y ago> power (⍣) operator[3], which represents parallel iteration and I think can often be translated to a per-thread while or for loop in a compute shader. Power is for sequential iteration. You may be thinking of rank (⍤).
- raphlinus 5y agoI spoke imprecisely. It is sequential iteration applied to each of the elements of an array, in parallel. That maps very well to compute shaders, but is hard to express in numpy because it's a higher-order operator, the right hand side is a function.
- moonchild 5y agoThat is incorrect. The function is applied to its argument in its entirety. We can see this by using a function such as ⊂: ]boxing on Was OFF (⊂⍣5) 2 3 4 ┌─────────────┐ │┌───────────┐│ ││┌─────────┐││ │││┌───────┐│││ ││││┌─────┐││││ │││││2 3 4│││││ ││││└─────┘││││ │││└───────┘│││ ││└─────────┘││ │└───────────┘│ └─────────────┘ (On GNU APL, it looks like the relevant formulation is ']boxing 3' rather than ']boxing on'; this simply affects the display of nested arrays.)
- raphlinus 5y agoOk, thanks for the correction. I think I understood where I went wrong - Dr. Hsu's algorithm for traversing up a tree to the root uses this, using = as the right argument so it's a fixpoint, but it only happens that in this case the left operand to the power operator is piecewise. So sometimes this can (at least in theory) be efficiently compiled to compute shader, in other cases not.
- moonchild 5y agoEven in the case where f has low rank, I do not think it is given that you would want to run multiple invocations of f in parallel in e.g. f⍣≡. Even though f has low rank, ≡ does not, and so gets applied to the entirety of the result. Meaning that you need a synchronization after every iteration; if f is cheap enough, that may not be worthwhile. (And low-rank g in f⍣g is meaningless, as it needs to produce a single boolean.) (You can do f⍣g⍤n, but then, again, that is rank doing the work of parallelization. And, performance considerations aside, I am no longer so convinced of the aesthetic utility of ⍤ as I once was. Wrt performance, when targeting CPUs, where branches are not so cheap, it might be worthwhile to design an f which can tolerate being called overly many times. Then give y an extraneous trailing axis the same size as a simd lane and do (f⍣g⍤1) y. That permits the whole computation to be vectorised, though it is also somewhat brittle.) (Note ≡ is not the same as =. 1 1 1 ←→ 1 2 3 = 1 2 3, but 1 ←→ 1 2 3 ≡ 1 2 3. f⍣≡ is an idiom. f⍣= is meaningless except at rank 0, where is behaves the same as f⍣≡.)
- mlochbaum 5y agoDyalog's working on a new version of this book that takes into account the many language changes since it was published. What's done so far is viewable online at https://mastering.dyalog.com/README.html https://mastering.dyalog.com/README.html.
- adregan 5y agoI tried APL out for the the most recent advent of code and had a lot of fun. The oddest thing about the language was that I started dreaming about it almost immediately after beginning to learn it. It really sticks in your mind.
- skruger 5y agoI have written a gentle intro to APL: https://xpqz.github.io/learnapl https://xpqz.github.io/learnapl