ArticleslgStudy

science

APL syntax and symbols

APL syntax and symbols is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand APL syntax and symbols rather than just read about it. In short: The programming language APL is distinctive in being symbolic rather than lexical: its primitives are denoted by symbols, not words. These symbols were originally devised as a mathematical notation to describe algorithms.

APL syntax and symbols — main illustration
APL syntax and symbols — illustration

Key takeaways

  • APL syntax and symbols belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect APL syntax and symbols to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of APL syntax and symbols from memory before moving on to harder problems.

Reference excerpt

The programming language APL is distinctive in being symbolic rather than lexical: its primitives are denoted by symbols, not words. These symbols were originally devised as a mathematical notation to describe algorithms. APL programmers often assign informal names when discussing functions and operators (for example, "product" for ×/) but the core functions and operators provided by the language are denoted by non-textual symbols.

Monadic and dyadic functions Most symbols denote functions or operators. A monadic function takes as its argument the result of evaluating everything to its right. (Moderated in the usual way by parentheses.) A dyadic function has another argument, the first item of data on its left. Many symbols denote both monadic and dyadic functions, interpreted according to use. For example, ⌊3.2 gives 3, the largest integer not above the argument, and 3⌊2 gives 2, the lower of the two arguments.

Functions and operators APL uses the term operator in Heaviside’s sense as a moderator of a function as opposed to some other programming language's use of the same term as something that operates on data, ref. relational operator and operators generally. Other programming languages also sometimes use this term interchangeably with function, however both terms are used in APL more precisely. Early definitions of APL symbols were very specific about how symbols were categorized. For example, the operator reduce is denoted by a forward slash and reduces an array along one axis by interposing its function operand. An example of reduce:

In the above case, the reduce or slash operator moderates the multiply function. The expression ×/2 3 4 evaluates to a scalar (1 element only) result through reducing an array by multiplication. The above case is simplified, imagine multiplying (adding, subtracting or dividing) more than just a few numbers together. (From a vector, ×/ returns the product of all its elements.)

The above dyadic functions examples [left and right examples] (using the same / symbol, right example) demonstrate how Boolean values (0s and 1s) can be used as left arguments for the \ expand and / replicate functions to produce exactly opposite results. On the left side, the 2-element vector {45 67} is expanded where Boolean 0s occur to result in a 3-element vector {45 0 67} — note how APL inserted a 0 into the vector. Conversely, the exact opposite occurs on the right side — where a 3-element vector becomes just 2-elements; Boolean 0s delete items using the dyadic / slash function. APL symbols also operate on lists (vector) of items using data types other than just numeric, for example a 2-element vector of character strings {"Apples" "Oranges"} could be substituted for numeric vector {45 67} above.

Syntax rules In APL the precedence hierarchy for functions or operators is strictly positional: expressions are evaluated right-to-left. APL does not follow the usual operator precedence of other programming languages; for example, × does not bind its operands any more "tightly" than +. Instead of operator precedence, APL defines a notion of scope. The scope of a function determines its arguments. Functions have long right scope: that is, they take as right arguments everything to their right. A dyadic function has short left scope: it takes as its left arguments the first piece of data to its left. For example, (leftmost column below is actual program code from an APL user session, indented = actual user input, not-indented = result returned by APL interpreter):

An operator may have function or data operands and evaluate to a dyadic or monadic function. Operators have long left scope. An operator takes as its left operand the longest function to its left. For example:

The left operand for the over-each operator ¨ is the index ⍳ function. The derived function ⍳¨ is used monadically and takes as its right operand the vector 3 3. The left scope of each is terminated by the reduce operator, denoted by the forward slash. Its left operand is the function expression to its left: the outer product of the equals function. The result of ∘.=/ is a monadic function. With a function's usual long right scope, it takes as its right argument the result of ⍳¨3 3. Thus

Monadic functions

Dyadic functions

Operators and axis indicator

Notes: The reduce and scan operators expect a dyadic function on their left, forming a monadic composite function applied to the vector on its right. The product operator "." expects a dyadic function on both its left and right, forming a dyadic composite function applied to the vectors on its left and right. If the function to the left of the dot is "∘" (signifying null) then the composite function is an outer product, otherwise it is an inner product. An inner product intended for conventional matrix multiplication uses the + and × functions, replacing these with other dyadic functions can result in useful alternative operations. Some functions can be followed by an axis indicator in (square) brackets, i.e., this appears between a function and an array and should not be confused with array subscripts written after an array. For example, given the ⌽ (reversal) function and a two-dimensional array, the function by default operates along the last axis but this can be changed using an axis indicator:

As a particular case, if the dyadic catenate "," function is followed by an axis indicator (or axis modifier to a symbol/function), it can be used to laminate (interpose) two arrays depending on whether the axis indicator is less than or greater than the index origin (index origin = 1 in illustration below):

Nested arrays Arrays are structures which have elements grouped linearly as vectors or in table form as matrices—and higher dimensions (3D or cubed, 4D or cubed over time, etc.). Arrays containing both characters and numbers are termed mixed arrays. Array structures containing elements which are also arrays are called nested arrays.

Flow control A user may define custom functions which, like variables, are identified by name rather than by a non-textual symbol. The function header defines whether a custom function is niladic (no arguments), monadic (one right argument) or dyadic (left and right arguments), the local name of the result (to the left of the ← assign arrow), and whether it has any local variables (each separated by semicolon ';').

… excerpt ends here. Continue reading the full article.

Illustrations

APL syntax and symbols: APL2 Keyboard
APL2 Keyboard

Worked examples

Example 1 — a first encounter with APL syntax and symbols

Start with the simplest possible case. Write down what APL syntax and symbols claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to APL syntax and symbols before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about APL syntax and symbols ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of APL syntax and symbols

In research
APL syntax and symbols appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses APL syntax and symbols in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
APL syntax and symbols is common in secondary-school and first-year university syllabi. It links to neighbouring topics APL programming language family, Programming language syntax, so understanding it makes those chapters shorter.
In everyday life
Look for APL syntax and symbols outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “APL syntax and symbols” →

How to study APL syntax and symbols in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what APL syntax and symbols means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain APL syntax and symbols out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is APL syntax and symbols in simple terms?

The programming language APL is distinctive in being symbolic rather than lexical: its primitives are denoted by symbols, not words. These symbols were originally devised as a mathematical notation to describe algorithms.

Why does APL syntax and symbols matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study APL syntax and symbols?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on APL syntax and symbols.

Tags

  • APL programming language family
  • Programming language syntax

Keep exploring