+X +23 0 ¯31 1J1 ⇔ 23 0 ¯31 1J¯1 Add A+B 75 3 46 + 5 ¯2 8 ⇔ 80 1 54-X -1 ¯17 44.8 ⇔ ¯1 17 ¯44.8 Subtract A-B 75 3 46 - 5 ¯2 8 ⇔ 70 5 38×X ×56.2 ¯1.4 0 0J¯3 ⇔ 1 ¯1 0 0J¯1 Multiply A×B 75 3 46 × 5 ¯2 8 ⇔ 375 ¯6 368÷X ÷1 2 3 4 ⇔ 1 0.5 0.3333333333 0.25 Divide A÷B 75 3 46 ÷ 5 ¯2 8 ⇔ 15 ¯1.5 5.75|X |23 0 ¯31 1J1 ⇔ 23 0 31 1.414213562 Residue (Remainder) A|B 3|15.4 ¯21 ¯23 9 8 ⇔ 0.4 0 1 0 2*X *1 2 ⇔ 2.718281828 7.389056099 Power A*B 3 7 16 * 3 2 0.5 ⇔ 27 49 4⍟X ⍟2.718281828 10 ⇔ 1 2.302585093 Logarithm (Base A) A⍟B 2⍟1023 ⇔ 9.99859043⌈X ⌈ ¯2.8 ¯1.1 0 1.1 2.5 ⇔ ¯2 ¯1 0 2 3 Maximum A⌈B 4 17 ¯2 ⌈ 3 64.8 1 ⇔ 4 64.8 1⌊X ⌊ ¯2.8 ¯1.1 0 1.1 2.5 ⇔ ¯3 ¯2 0 1 2 Minimum A⌊B 4 17 ¯2 ⌊ 3 64.8 1 ⇔ 3 17 ¯2!X !14 ⇔ 87178291200 Binomial Coefficient A!B Number of combinations of B items taken A at a time○X ○÷180 ⇔ 0.01745329252 Circular Functions A○B See table below?X Randomly choose an item from ⍳X Deal A?B Randomly choose A items from ⍳B without replacementA⊥B 2⊥0 1 0 0 0 1 ⇔ 17A⊤B 2 2 2 2 2 2 ⊤ 17 ⇔ 0 1 0 0 0 1⍋X List of indices that will sort X in ascending order Grade Up A⍋B Alphabetic sort: A gives the collating sequence⍒X List of indices that will sort X in descending order Grade Down A⍒B Alphabetic sort: A gives the collating sequence⌹X Matrix Divide A⌹B Multiply A by the inverse of matrix B⍎X Evaluate APL2 expression given as character vector X ⍕X ⍕¯17.5 ⇔ '¯17.5' Format A⍕B 0 3 4 0 6 ¯2⍕ ¯12.14 30 17.1 ⇔ '¯12.140 30 1.7E1''06/06/0006' ⍕ 7 20 1969 ⇔ '07/20/1969'A\B 1 0 0 1 1 0 13円 1 4 2 ⇔ 3 0 0 1 4 0 2A⍀B Expand along the first axis of BA/B 2 0 ¯5 3 1/3 1 4 2 ⇔ 3 3 0 0 0 0 0 4 4 4 2A⌿B Replicate along the first axis of BA<B 1 2 3 < 3 2 1 ⇔ 1 0 0A≤B 1 2 3 ≤ 3 2 1 ⇔ 1 1 0A=B 1 2 3 = 3 2 1 ⇔ 0 1 0A≠B 1 2 3 ≠ 3 2 1 ⇔ 1 0 1A≥B 1 2 3 ≥ 3 2 1 ⇔ 0 1 1A>B 1 2 3 > 3 2 1 ⇔ 0 0 1~X ~0 1 ⇔ 1 0A∧B 1 1 0 0 ∧ 1 0 1 0 ⇔ 1 0 0 0A∨B 1 1 0 0 ∨ 1 0 1 0 ⇔ 1 1 1 0A⍲B 1 1 0 0 ⍲ 1 0 1 0 ⇔ 0 1 1 1A⍱B 1 1 0 0 ⍱ 1 0 1 0 ⇔ 0 0 0 1A≡B 1 if A and B have the same dimensions, nesting levels, and contents, 0 otherwiseA∈B 'ace'∈'A Programming Language' ⇔ 1 0 1A⍷B 'ISSI'⍷'MISSISSIPPI' ⇔ 0 1 0 0 1 0 0 0 0 0 00○X (1-X*2)*0.5 0○X (1-X*2)*0.51○X Sine ¯1○X Arcsine2○X Cosine ¯2○X Arccosine3○X Tangent ¯3○X Arctangent4○X (1+X*2)*0.5 ¯4○X (¯1+X*2)*0.55○X Hyperbolic Sine ¯5○X Inverse Hyperbolic Sine6○X Hyperbolic Cosine ¯6○X Inverse Hyperbolic Cosine7○X Hyperbolic Tangent ¯7○X Inverse Hyperbolic Tangent8○X (¯1-X*2)*0.5 for X<0-(¯1-X*2)*0.5 for X≥0 ¯8○X -8○X9○X Real part of X ¯9○X X10○X |X ¯10○X +X (complex conjugate)11○X Imaginary part of X ¯11○X 0J1×X12○X Phase of X ¯12○X *0J1×XNote: one way to get the arctangent of Y÷X in the proper quadrant (-π to +π) is 12○X+11○Y
A⌷B Select items from B using indices A⍳X ⍳8 ⇔ 1 2 3 4 5 6 7 8 Index Of A⍳B 'HELLO'⍳'ELP' ⇔ 2 3 6A~B (⍳8)~1 4 5 ⇔ 2 3 6 7 8ρX List of dimensions of X Reshape AρB 3 4ρ'ABCDEFGHIJKL' ⇔ ABCD
EFGH
IJKL⌽X ⌽⍳8 ⇔ 8 7 6 5 4 3 2 1 Rotate A⌽B 3⌽⍳8 ⇔ 4 5 6 7 8 1 2 3⊖X ⊖3 4ρ'ABCDEFGHIJKL' ⇔ IJKL
EFGH
ABCDA⊖B 1⊖3 4ρ'ABCDEFGHIJKL' ⇔ EFGH
IJKL
ABCD⍉X ⍉3 4ρ'ABCDEFGHIJKL' ⇔ AEI
BFJ
CGK
DHLA⍉B The elements of A give the new order for the axes of B↑X The first element of X Take A↑B ¯3↑⍳8 ⇔ 6 7 8A↓B 3↓⍳8 ⇔ 4 5 6 7 8⊂X Represent array X as a scalar Partition A⊂B 1 0 1 1 2 2 2 3 ⊂ 'ABCDEFGH' ⇔┌→─────────────────┐
│┌→┐ ┌→─┐ ┌→──┐ ┌→┐│
││A│ │CD│ │EFG│ │H││
│└─┘ └──┘ └───┘ └─┘│
└∊─────────────────┘⊃X Remove one level of nesting from X Pick A⊃B Indices A select an item from within nested array B≡X Deepest level of nesting in X Match (see Boolean Functions),X Change X to a vector, preserving depth Catenate A,B Connect two arrays along their last axis∈X Change X to a vector of depth 1 Membership (see Boolean Functions)f¨X Apply function f to each item of Xf/X Apply function f along the last axis (rows) of Xf⌿X Apply function f along the first axis of XA f/B Apply function f along the last axis (rows) of B with a moving window of size AA f⌿B Apply function f along the first axis of B with a moving window of size Af\X Apply function f along the last axis (rows) of X, displaying intermediate resultsf⍀X Apply function f along the first axis of X, displaying intermediate resultsA f.g B Apply function g between rows of A and corresponding columns of B, then apply f along each resultA ∘.f B Apply function f between every combination of one element from A and one element from BNote: A+.×B is the standard matrix multiplication operation for matrices A and B.
Scans of boolean vectors are often useful:
∧\X Make everything 0 after the first 0<\X Make everything 0 after the first 1≤\X Make everything 1 after the first 0∨\X Make everything 1 after the first 1X∨≠\X Make everything 1 between odd and even 1s