by civilized · 5y ago · 0 comments
This will be a controversial statement to devotees, but there's a simple argument that should clarify why this is true:
1. APL's inventor claims that APL is a tool of thought. Specifically, it is designed to facilitate the development of algorithms.
2. Tools of thought, like mathematical notation or writing in general, are used wherever people think.
3. When people think about algorithms, they write code or pseudo-code.
4. Thus, if APL were truly a tool of thought, it would be adopted as a pseudo-code. Academics would use it to more easily, concisely, and precisely express algorithms and programs. Software engineers would use it in their whiteboard planning. Etc.
5. In reality, essentially no one uses APL as a pseudo-code. Even by its devotees, it used exclusively as a programming language. The process of coding something into APL's idiosyncratic logography can only happen after the idea is already clear by other means. And virtually no one finds themselves understanding an algorithm via APL code which they did not already understand via more accessible languages or pseudo-code.
6. Therefore APL is not a tool of thought. On the contrary, it is what its notation indicates to virtually everyone who sees it: a write-only language.
Admittedly, there's some appeal in this idea that a super-concise notation might be a sort of life-hack for thinking about algorithms. If you could just get your brain to think in this notation, all sorts of new concepts would be accessible to you! But that's just not how reality has unfolded, at least in the case of APL. Perhaps there is a yet-undiscovered notation that truly realizes the promise of a Tool of Thought about algorithms. But I have no idea what it would be.
This letter from Dijkstra and the discussion underneath it [2] further strengthens the argument above. Note how APL is marketed as a tool of thought, but those who would teach it are distressed at the idea of teaching it without a terminal to execute it on. As Dijkstra notes, this is inconsistent with what we'd expect from a true tool of thought. Such a thing should have no trouble expressing its appeal through writing.
[0] https://aplwiki.com/wiki/Edsger_W._Dijkstra#APL_by_Dijkstra....
I would be interested in your response to this post [1], which is on that point.
I noted the Ackermann function and inverted index results in Hui's response to Dijkstra. I can't understand the APL so can't be sure how novel or significant these results are, but I would predict that such properties of the Ackermann function and inverted tables/indices would have been known long before these derivations. These may just be examples of pre-existing knowledge being encoded into APL logography.
APL has not to my knowledge been used to prove novel mathematical results. Has any programming language? It's not very interesting to note that a language that's unknown to working mathematicians doesn't find much use in cutting-edge mathematics. However, APL is closer to the notation that is used for these discoveries than nearly any other programming language (Mathematica is the exception that comes to mind).
There are some historical APL successes to point to. It was used to design IBM's highly-regarded system/360[0]; as the first APL implementation ran on the 360 this was of course done entirely on paper. I believe some early time-sharing systems were written in APL as well, though I don't have a source. STSC's Mailbox[1] was one of the earliest email systems[2]. More recently Aaron Hsu has used APL to create what seems to be the first data-parallel compiler[3]. While data-parallel is rigorously defined (polylogarithmic time given infinite processors), the vagueness of "compiler" means this isn't a result of interest to mathematicians.
I myself have used APL to make what I consider to be a significant discovery about sequences of natural numbers[4]. It unifies methods that I've come up with ad-hoc in the past, and I've now used this framework dozens of times to more quickly solve a variety of problems. I don't expect you to understand the APL-heavy description, but isn't that what you asked for? I and many others think in APL. It just seems natural to us. Here's a quote along those lines[5]:
> And I looked at the code that I’d written, and it’s about 150 lines or so, and it was complicated, complicated stuff. I went to sleep, and I had a dream, and in the dream, it told me how to approach this in a whole different way that I had done before. So I woke up, I sat down at the computer at six o’clock in the morning, and by noon I’d rewritten the whole thing from scratch, pretty much. I kept 7 lines of code that were tangential to that, and it was all correct. It passed the QAs like that. So sure, you can write for loops in your sleep, but I can write entire correct programs in my sleep!
[0] https://dl.acm.org/doi/10.1147/sj.32.0198
[1] https://forums.dyalog.com/viewtopic.php?f=30&t=1629&p=6415
[2] https://en.wikipedia.org/wiki/History_of_email
[3] https://scholarworks.iu.edu/dspace/bitstream/handle/2022/247...
[4] https://aplwiki.com/wiki/Partition_representations#Unificati...
'The process of coding something into APL's idiosyncratic logography can only happen after the idea is already clear by other means.'
In fact, often I will write something in APL before translating it to other languages, not the other way round. When I was a beginner, I did translate things as I hadn't learned to properly 'think' in APL yet. Perhaps you have tried it, and not got past that initial barrier? In which case, my advice would be to stick with it for a bit.
'And virtually no one finds themselves understanding an algorithm via APL code which they did not already understand via more accessible languages or pseudo-code.' is also untrue.
An example of a time APL like notation has helped me to understand an algorithm is Kadane's algorithm for a maximum subarray sum. There are probably hundreds of articles and videos out there explaining it, suggesting that it's probably something quite a few people find unintuitive.
However, in k, an APL descendant, the entire algorithm is expressible as |/0(0|+)\
To anyone who knows APL/k this is instantly readable and intuitive. This was the first thing that really made it 'click' for me.
Ok, APL hasn't been widely adopted and there are definitely some downsides and problems with it, but it's still useful and definitely not write-only.
The conclusion notwithstanding, an ability to concisely express the algorithm doesn't relate to an ability to actually understand it. Personally I found Kadane's algorithm intuitive as is and the concept of partial sum seems more important for the intuitive understanding of the algorithm. Array languages are surely benefited from built-in partial sum, but that'd be arguably same for any other language with readily accessible partial sum.
Exactly! Computationally, Kahane's algorithm is only a few simple steps. It's easy to write the steps down in a few lines of any language, and equally easy to understand what the individual steps are doing. The hard part about it isn't that it's too long and needs to be compressed into 8 symbols to be understood. The hard part is understanding why it is correct.
Kadane's algorithm was a simple example, and sure, it's not hard to understand in any language. My point was that the K version for me is the clearest and most obvious I've seen, and that understanding why it's correct is much easier starting from that than from the equivalent in say, Python or C++.
I've never seen an argument against APL that wouldn't also apply to Kanji and Chinese script - notations with billions of readers.
See also the 1964 IBM Systems Journal document in Volume 3, Number 3, "A Formal Description of System/360" with Iverson, Falkoff and Sussenguth as authors.
It's like if an important human rights document was written in Esperanto. The document might be indisputably important, while its language and the intentions behind it are an incidental historical detail.
in fact, i regularly _think_ about problems in an array-programming fashion, heavily inspired by K. when jotting them down, i often use K. when turning them into actual code to run, it's mostly immaterial if i then use K, J, numpy, julia, etc. the general approach translates well into a multitude of array programming varieties.
as such, i don't believe your point 5 holds. this way of thinking is certainly off mainstream, as is, e.g constraint programming, but there are niches where people use it highly productively. you won't necessarily glean that from the output coming from those niches, though.
In some areas, if you're familiar with the language, it's much more readable than other languages due to being more concise.
For example, if you wanted to calculate the sample standard deviation
```
mean =: +/ % #
sum_of_squares =: +/@:*:@:(] - mean)
stdev =: %: @: (sum_of_squares % <:@:#)
```
Is pretty readable, I think. Of course, of you don't know the primitives, then it doesn't look like it's readable.
(I'm on my phone, so I may have typed something wrong.)
__mean =: +/ % #
Becomes: mean =: +/ % #
Don't use the surrounding ```...``` because it just becomes noise, and you don't need extra newlines, two lines of code can be adjacent to each other if you prefix each with two spaces: line 1
line 2, no extra newline was used
https://news.ycombinator.com/formatdoc - a very short document describing all the formatting options for HN comments. There aren't many.I also disagree about not using ```. It's useful when writing markdown in an interface that swallows whitespace.
```
foo
bar
baz
```
```
note all the
extra
vertical
whitespace because regular paragraphs get a slight
gap
```
```
let's
throw
in a
third block
for some reason
```
As code blocks:
foo
bar
baz
note all the
extra
vertical
whitespace because regular paragraphs get a slight
gap
let's
throw
in a
third block
for some reason
The former becomes a problem in the discussion because it clutters the space and is harder to read than the latter, especially when you have multiple blocks around the discussion (in one comment or spread out across comments). You may not care, but using code blocks that offer a more compact and clear expression is certainly more courteous.There isn't a single markdown. There are many different flavors, and all of them are markdown. Many include ``` (GitHub, Kdoc, pandoc, reddit, commonmark), especially as it allows you to specify the language if you want. I actually don't know if any tool I use that doesn't support them.
Or draw boxes and arrows on a whiteboard or pieces of paper. But I agree, they usually don't write APL or anything like it.
Whenever people claim that APL is write-only they give some convoluted example with a bunch of obscure APL operators that are seldom used, so even for APL users it might be difficult to remember what they do.
For the majority of the problems that a programmer might need to solve every day, only a small fraction of APL might be needed, which is simple to understand, learn and remember.
As an unfamiliar notation, you might need to learn 5 or 6 extra operators at most and for the rest you need just use the same that you use in any programming language only with additional rules that allow more freedom than in the popular programming languages.
The main difference between APL and conventional languages is that you no longer have to write "for" loops, you just write the same expressions that you would write for scalar variables.
I cannot see how one would claim that omitting all the redundant boilerplate code needed by "for" loops or "map" functions decreases the readability of a program.
If you do not want to learn 20 new operators, there is no need for that, the base APL language does not need them. There are only very few operators that are strictly needed, e.g. reduction, inner product, outer product, rank, index.
If you like verbose identifiers you could use names for them, the symbols are not the essence of APL, only its rules for writing expressions.
The 3 simplest rules are:
1. a function of 1 argument applied to an array is the array of the values obtained by applying the function to the array elements.
2. a function of 2 arguments applied to a scalar and to an array is the array of the values obtained by applying the function to the scalar and to each array element.
3. a function of 2 arguments applied to 2 arrays of identical ranks and dimensions is the array of the values obtained by applying the function to each pair of corresponding array elements.
I do not see anything obscure and unintuitive in such simple rules. (It should be obvious that these are particular cases of a general rule that in a function of N scalar arguments, you should be able to replace 1 or more of the scalars with arrays of the same rank and dimensions and then the function result shall also be an array of the same rank and dimensions.)
On the contrary I find it hard to understand why these rules are not valid in any programming language and you are forced in most of them to write loops for such trivial operations.
There is only one real barrier for using the APL notation, but in my opinion those who surpass it are rewarded.
The order of evaluation for APL expressions is different from the order learned in school, which is then extended in various way in the programming languages.
In APL there are no precedence levels. The right operand of an operator is everything that is to the right, until the end of the expression.
So the operators are evaluated from the right to the left (i.e. in reverse order compared to the traditional order for e.g. addition), unless you use parentheses. This order is frequently more readable than the traditional, because usually when browsing a program you do not need to read the expressions until their end. The important parts are at the left end and it is normally enough to read only those. With the traditional order you might need to scan the line much farther to the right to be sure that you did not miss something important.
This obstacle of the different evaluation order discourages many of those who could benefit by using APL as a pseudo-code, but once you understand that this modified order can really simplify most expressions and you become adept at reading it as easily as the traditional order, you can use APL as a pseudo-code with good results.
Could you then say that one of the big ideas of APL is to define a canonical way of extending functions of scalars f(x, y, ...) to take one or more array arguments, and then baking those ways into the syntax, so you don't have to use zip and map?
I agree there's something to that. It seems like a feature that other languages could benefit from. Maybe a decorator symbol could be used to tell the language when you want to do this, or a setting so it's turned on by default in a particular module. We probably wouldn't want it as an immutable universal language rule, since entering an array to scalar argument is a common programming mistake that you could want your compiler or runtime to throw an error for.
You can replace one scalar with an array by rule 2 and both scalars with arrays by rule 3. This should be extended to an arbitrary number of scalar arguments, where you should be able to replace any scalar with an array whose elements have the same type as the scalar and any combination of scalar and array arguments should be valid.
This is the first step in using APL, by defining only scalar functions, but using them also with array arguments.
This only works with arrays of the same dimensions, where the function arguments are elements in the same positions, i.e. which would have had the same indices in a "for" loop.
This already covers the most frequent uses.
Only when you need more complex ways of combining arrays, you begin to need specific APL operators, e.g. reduction which transforms an array into an array whose rank is 1 less, e.g. like when you sum the elements of a vector into a scalar value, but the APL operators are completely general, so with the reduction operator you can apply any function of 2 arguments to a vector or to the subvectors of a larger array.
Reduction operations are one of the places where it is obvious that the APL order of evaluation is better than the traditional, because it provides useful operations for the non-commutative functions, e.g. reduction with subtraction is the sum with alternate signs and reduction with division is the product of the fractions obtained from pairs of consecutive elements. Both operations are frequently useful, unlike to what would have been obtained with the traditional order of evaluation.
The same happens with the other APL operators, they are generalized versions of the traditional operations, e.g. the inner product operator can do dot products or matrix multiplications, but it can be used with any pair of functions, not only with addition and multiplication.
Like any use of overloaded functions, you are right that this would no longer flag as an error when you use an array of e.g. int instead of an int, but usually this would be caught eventually, e.g. if you try to assign the result to a scalar, unless you do this in an initialization with auto inference of the declared type, which would probably still give a type conflict later.
I agree that this is a possible disadvantage, but I have never encountered an error of this kind, with overloaded functions or operators, that was not flagged eventually as a type error, even if possibly not in the first place where the error was introduced.
As I said, if this were really true, there would be evidence of people using it to express thoughts that are too hard to express by other means. But in reality, people who think in APL just don't seem to be on the forefront of published algorithmic thought.
It might be helpful to contrast APL with nonstandard analysis, a mathematical tool of thought for doing rigorous real analysis more easily. People have proved new and useful results in nonstandard analysis, and the fact that these results were first proved in nonstandard analysis is at least some evidence that nonstandard analysis served as a real tool of thought to produce those results. (To be fair, the idea that nonstandard analysis was an essentially tool in these proofs is controversial among mathematicians. But there is at least the hard fact of the results being proved first by this means.)
So, if smart people are able to use APL to push the boundaries of algorithmic thought, we'd expect APL-ers to have that sort of achievement to show for it. But we don't see that. After pre-existing thoughts are translated into APL's logography, there does not seem to be any demonstrable enhancement of the ability to reason about algorithms. Or maybe there is some enhancement for that individual person, relative to their abilities without APL, but it does not seem to cause that person to rise above the general human level of algorithmic ability.
"APL as a tool of thought" seems to be a beautiful theory whose predictions have not met with reality.
APL doesn't magically double your ability to think though. Pushing boundaries takes a lot more than raw thought power. And APL is used so little that you couldn't make any correlations even if APL increased thinking ability tenfold anyways. But it still is a very useful tool (among many other tools) from time to time.
I personally don't see myself using any array language as a general purpose language for everything though. They're useful (extremely useful!) for things that map well to array operations or benefit from terseness, and anything from "meh" to awful for other things.
Like Arthur Whitney you mean?
5. In reality, essentially no one uses APL.
and your reasoning flys out the window as a result.