The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

APL unifies the notations for certain mathematical constructs, while having a more consistent syntax. Below are some examples comparing traditional mathematical notation (denoted TMN in this article) with the equivalent APL. Note that some of these examples only work in certain APL dialects.

## Similarities

APL developed from TMN, and much of APL will be immediately recognised by a mathematician. Interestingly, it seems that the look of the typeface and identifiers (names of variables etc.) used in APL makes a big difference in the reader's perception. A fixed-width typewriter-style font with long identifiers gives the impression of computer source code, while an italic serif typeface and single-letter identifiers gives the impression of scientific formulae. Compare the impression you get when reading the following two expressions which is both valid APL (though it has superfluous parentheses) and traditional mathematics:

((x + y) × (x - y)) = (f ∘ g)(x, y)

${\displaystyle ((x+y)\times (x-y))=(f\circ g)(x,y)}$

Now note that they are identical, letter for letter. Computer Scientists tend to have great difficulty in approaching APL until they let go of the notion that APL is just another programming language (despite its name!) and instead look at it as an executable mathematical notation.

It is notable that APL traditionally was written with a font wherein letters were always italicised, while everything else wasn't. Here is how it looks in the default font for SAX:

### Identical

For many basic operations, APL is identical to TMN:

${\displaystyle \sim q}$  ~ q Not
${\displaystyle p\vee q}$  p ∨ q Or
${\displaystyle p\wedge q}$  p ∧ q And
${\displaystyle a\times b}$  a × b Multiply
${\displaystyle a\div b}$  a ÷ b Divide
${\displaystyle a\in S}$  a ∊ S Membership
${\displaystyle A\cup B}$  A ∪ B Union
${\displaystyle A\cap B}$  A ∩ B Intersection

### Redundant brackets and parentheses

Often, the only difference is that APL allows omitting brackets or parenthesis. This is because the Iverson bracket is implied and functions have long right scope.

APL
Normal
APL
Article
${\displaystyle [a\equiv b]}$  (a ≡ b) a ≡ b Match
${\displaystyle [a=b]}$  (a = b) a = b Equal
${\displaystyle [a\neq b]}$  (a ≠ b) a ≠ b Not Equal
${\displaystyle [a\leq b]}$  (a ≤ b) a ≤ b Less Than or Equal
${\displaystyle (f\circ g)(x)}$  (f ∘ g)(x) f ∘ g x Bind
${\displaystyle f(g(x))}$  f(g(x)) f g x
${\displaystyle (f+g)(x)}$  (f+g)(x) (f+g) x Trains

## Differences

While based on TMN, APL goes a long way to harmonise and generalise its notation.

### Prefix

In APL, all functions that only take a single argument are placed to the immediate left of their argument. TMN uses prefix, omnifix, and suffix notations.

${\displaystyle n\pi }$  ○n Pi Times
${\displaystyle x!}$  !x Factorial
${\displaystyle |x|}$  |x Magnitude
${\displaystyle \lceil x\rceil }$  ⌈x Ceiling
${\displaystyle \lfloor x\rfloor }$  ⌊x Floor

### Explicitness

APL writes out all functions explicitly while TMN often implies functions by argument positioning without giving the function an explicit symbol.

${\displaystyle ab}$  a×b Multiply
${\displaystyle e^{x}}$  *x Exponential
${\displaystyle a^{b}}$  a*b Power
${\displaystyle {\sqrt[{a}]{b}}}$  a√b Root
${\displaystyle {\tbinom {n}{k}}}$  k!n Binomial
${\displaystyle f^{n}(x)}$  (f⍣n) x Power operator
${\displaystyle \sin ^{n}(x)}$  (1○x)*n Circle function
${\displaystyle a\cdot b}$  a+.×b Inner product

### Linearity

APL is strictly linear in the sense that it is written as single lines of uniformly sized and positioned characters, as opposed to TMN which often uses font size and/or position to give meaning.

${\displaystyle f^{n}(x)}$  (f⍣n) x Power operator
${\displaystyle \sin ^{n}(x)}$  (1○x)*n Circle function
${\displaystyle a\pm b}$  a(+,-)b Trains
${\displaystyle a\mp b}$  a(-,+)b Trains
${\displaystyle {\frac {a}{b}}}$  a÷b Divide
${\displaystyle e^{x}}$  *x Exponential
${\displaystyle a^{b}}$  a*b Power function
${\displaystyle \log _{a}{b}}$  a⍟b Logarithm
${\displaystyle {\sqrt[{a}]{b}}}$  a√b Root
${\displaystyle {\tbinom {n}{k}}}$  k!n Binomial
${\displaystyle \left\{{\begin{array}{rl}a,&{\text{if }}p(x)\\b,&{\text{if }}q(x)\end{array}}\right.}$
{p x: a
q x: b}

dfns
${\displaystyle \sum _{i=1}^{N}v_{i}}$  +/v Reduce
${\displaystyle \sum _{n=1}^{N}n}$  +/⍳N Reduce, Iota
${\displaystyle \prod _{n=1}^{N}n}$  ×/⍳N Reduce, Iota

### Named functions

APL has no reserved words, and user defined names can have multiple characters. TMN uses multi-character names for many functions and uses many ad-hoc control words.

${\displaystyle e^{x}}$  *x Exponential
${\displaystyle \ln {x}}$  ⍟b Natural Logarithm
${\displaystyle \log _{a}{b}}$  a⍟b Logarithm
${\displaystyle a{\bmod {b}}}$  b|a Modulus
${\displaystyle \left\{{\begin{array}{rl}a,&{\text{if }}p(x)\\b,&{\text{if }}q(x)\end{array}}\right.}$
{p x: a
q x: b}

dfns
${\displaystyle {\text{let }}n=42}$  n←42 Assignment

### Other differences

APL harmonises and generalises all folding and dispenses with TMN's counting variables. Every one of the following calculations is a reduction.

${\displaystyle \sum _{i=1}^{N}v_{i}}$  +/ v
${\displaystyle \sum _{n=1}^{N}n}$  +/ ⍳N
${\displaystyle \prod _{n=1}^{N}n}$  ×/ ⍳N
${\displaystyle \forall x,P(x)}$  ∧/P(x)
${\displaystyle \exists x,P(x)}$  ∨/P(x)

## Practical example

The steps to produce the component of a vector ${\displaystyle {\textbf {a}}}$  in the direction of another vector ${\displaystyle {\textbf {b}}}$  go as follows:

${\displaystyle |{\textbf {b}}|={\sqrt[{2}]{{\textbf {b}}\cdot {\textbf {b}}}}}$
bNorm ← 2 Root b +.× b

${\displaystyle {\hat {\textbf {b}}}={\textbf {b}}\div |{\textbf {b}}|}$
bHat ← b ÷ bNorm

${\displaystyle {\textbf {a}}_{\textbf {b}}=({\textbf {a}}\cdot {\hat {\textbf {b}}}){\hat {\textbf {b}}}}$
a_b ← (a +.× bHat) × bHat

APL syntax 
General Comparison with traditional mathematicsPrecedenceTacit programming (Train, Hook, Split composition)
Array Numeric literalStringStrand notationObject literalArray notation (design considerations)