APL Wiki logo

From APL Wiki
Revision as of 15:02, 1 November 2019 by Miraheze>Adám Brudzewsky (WIP)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The APL Wiki logo can be seen as the following numeric matrix, where each number indicates the circle size. This page will explain, step-by-step, an expression[1] for this matrix — an expression which demonstrates quite a few APL features:

APL Wiki logo
      ⎕IO←0
      ⌊∘.+⍨.5×4!⍨⍳5
1 2 3 2 1
2 4 5 4 2
3 5 6 5 3
2 4 5 4 2
1 2 3 2 1

We will follow APL's evaluation from right to left.

Counting from 0 or from 1

 
A computer console:

Whether to count from 0 or from 1 is an old disagreement among programmers. Many APLs let you choose whichever convention you want, but they tend to use 1 by default. To switch convention, we set the variable ⎕IO:

      ⎕IO←0

By the way, IO stands for Index Origin.

We can already now observe a couple of APL's characteristics:

  • The name ⎕IO begins with the special Quad character (a stylised console) which symbolises the computer system itself. APL has no reserved words. Rather, all built-in constants, variables, functions and operators have the prefix indicating that they are part of the system. Because of this, we call them quad names.
  • Assignment is not done with = like in many other programming languages, but rather with which also indicates the direction of the assignment: Whatever is on the right gets put into the name on the left.

Generating indices

The function takes a number N and generates indices until is has made N indices. Since we set ⎕IO to 0, we count from 0 until right before N:

      ⍳5
0 1 2 3 4

How many subsets?

Consider a bag with four distinct items. If you stick your hand into the bag and pick two items out, how many different possibilities are there for which pair you get out?  . APL can tell you this with the ! function:

      2!4
6

Notice how APL uses traditional mathematical symbols in a generalised way. The traditional post-fix (after its argument) symbol   is used with a syntax similar to how you'd normally use   or Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle ×} . In fact, all APL functions can be used infix, like   or prefix, like  .

Anyway, how many sets of four could you pick? Obviously, only one; all the items:

      4!4
1

And how about sets of five? Well, we only have for items, so there are no such sets:

      5!4
0

And how about picking out zero items? Since all empty hands are equal, there is exactly one such set — the empty set:

      0!4
1

This shows another tendency in APL; that to generalise common operations even to edge cases. Now we can ask

References

  1. "Bubbler", message "52389201" in The Nineteenth Byte chat room. Stack Exchange network, 2019-10-31 23:57