⍳4
⍳4ₓ0 1 2 3
[0 1 2 3]ₓ
Start with Basics. Each glyph below has a monadic form, with one argument, and a dyadic form, with arguments on both sides.
⍳ (iota)⍳ (index generator)A position is also called an index. ⍳ creates the positions of an array with the given shape. Positions start at 0. An exact input gives an exact array: compare ⍳4 with ⍳4ₓ.
For performance-sensitive indexing, use exact integer index arrays. They avoid the whole-number checks and float-to-integer conversions needed for float indices.
A matrix position has a row number and a column number. These are its coordinates. Giving ⍳ a shape vector makes a coordinate vector at each position.
┌→──────────────────┐
↓ ┌→──┐ ┌→──┐ ┌→──┐ │
│ │0 0│ │0 1│ │0 2│ │
│ └~──┘ └~──┘ └~──┘ │
│ ┌→──┐ ┌→──┐ ┌→──┐ │
│ │1 0│ │1 1│ │1 2│ │
│ └~──┘ └~──┘ └~──┘ │
└∊──────────────────┘
Combine ⍳ with ⍴ to arrange the positions in a matrix.
Arithmetic on the positions makes other patterns. This gives the first six odd numbers.
A length of 0 gives an empty vector.
⍳⁻¹ gives the generating shape as a vector. A vector of four positions gives [4]; a matrix of row-column coordinates gives its two lengths.
⍳ (index of)For vectors, X⍳Y gives the first position of each item of Y in X. An absent item gets the length of X.
A major cell is the part at one position along an array’s first axis, spanning all the remaining axes. A matrix’s major cells are its rows. ⍳ compares these whole cells. The last row of mat is 4 5, at position 2.
With the same search array on the left, ⍳⁻¹ gives the items at the positions. The positions must be valid results of Index Of.
↦ (Range)↦N counts from 1 through N. With two arguments it counts between the two ends, including both. It can count down too.
Each character has a numeric Unicode code. A character range counts through these codes.
= (Equal sign)= (Equal to)= compares values and returns a Boolean: true or false. BPL writes true as $t and false as $f.
= compares each pair of atoms. A single number compares with every item of a vector.
We can also compare characters.
┌→──────────────────────────────────────────────────────┐
│ ┌→────────────────┐ ┌→─────────────┐ ┌→─────────────┐ │
│ │$f $t $f $t $f $t│ │$f $f $f $f $f│ │$f $t $f $f $f│ │
│ └$────────────────┘ └$─────────────┘ └$─────────────┘ │
└∊──────────────────────────────────────────────────────┘
For Boolean arguments, inverse Equal finds the missing Boolean on the right. True equals false gives false, so $t=⁻¹$f gives $f.
= (Classify)With one argument, = makes a Boolean row for each distinct item, in order of first appearance. The columns correspond to the input items. In "aba", the first row marks the as and the second marks the b.
≠ (Not equal)≠ (Unique Mask)A Boolean array that marks which items to keep is called a mask. Monadic ≠ marks the first occurrence of each distinct item with $t. Later occurrences get $f.
≠ (Not Equal To)Dyadic ≠ gives $t where the atoms differ.
The number 7 and the character 7 are not equal.
Inverse Not Equal also solves for a Boolean right argument.
< (Less than sign)< (Sort up)With one argument, < sorts the major cells in ascending order.
< (Less than)> (Greater than sign)> (Sort down)> sorts in descending order.
> (Greater than)≤ (Less than or equal to sign)≤ (Decrement)With one argument, ≤ subtracts 1 from each number.
The inverse of Decrement adds 1.
≤ (Less than or equal to)≥ (Greater than or equal to sign)≥ (Increment)With one argument, ≥ adds 1 to each number.
The inverse of Increment decrements.
≥ (Greater than or equal to)≡ (Equal underbar)≡ (Depth)An array stored as an item of another array is nested. Depth counts the layers of arrays. An atom has depth 0.
An array of atoms has depth 1.
A vector whose items are vectors has depth 2.
Uneven nesting takes the depth of the deepest item, plus 1.
┌→────────────────────────┐
│ ┌→──┐ ┌→──┐ ┌→────────┐ │
│ │1 2│ │3 4│ │ 5 ┌→──┐ │ │
│ └~──┘ └~──┘ │ │6 7│ │ │
│ │ └~──┘ │ │
│ └∊────────┘ │
└∊────────────────────────┘
≡ (Match)Match compares the shape and contents of two whole values. Its result is one Boolean.
A number and a two-item vector have different shapes, even when every item of the vector equals the number.
≢ (Equal Underbar Slash)≢ (Tally)Tally counts the major cells of an array. For a vector it gives the length as an exact integer. Shape gives a vector containing that length.
For a matrix, tally counts the rows.
≢ (Not match)Not Match is the opposite of Match.
It compares whole values, just as ≡ does.
∨ (Vee)∨ (Real-imag)∨ separates a complex number into its real and imaginary parts. Each number gives a pair along a new last axis.
The inverse joins each real-imaginary pair back into a complex number.
∨ (Or / Greatest common divisor)With Boolean arguments, ∨ gives $t when either input is true.
With numbers, ∨ gives the greatest common divisor. For example, 5 is the largest number that divides both 15 and 35 without a remainder.
⊽ (Vee bar)⊽ (Double)The inverse of Double halves its argument.
⊽ (Nor)Nor gives $t only when neither input is true.
∧ (Wedge)∧ (Polar)∧ gives each number’s magnitude (distance from zero) and angle from the positive real axis. Angles are in radians, with π1 for a half-turn.
The inverse rebuilds a number from its magnitude-angle pair.
∧ (And / Least common multiple)With Boolean arguments, ∧ gives $t only when both inputs are true.
With numbers, ∧ gives the least common multiple. For example, 105 is the smallest positive multiple of both 15 and 35.
~ (Logical NOT)~ (Not)~ (Without)Without keeps the items from the left argument that are absent from the right.
It also compares strings as whole items.
┌→──────────┐
│ ┌→─┐ ┌→─┐ │
│ │aa│ │cc│ │
│ └──┘ └──┘ │
└∊──────────┘
The same rule works for other nested arrays.
⊼ (Wedge bar)⊼ (Square)Inverse Square takes a square root. For a positive real argument it chooses the positive root, even if the original number was negative.
⊼ (Nand)Nand gives $f only when both inputs are true.
Applying Not to the result of And gives the same result.
# (Hash)# (Replicate)The left argument gives a count for each major cell of the right argument. With a Boolean mask, Replicate keeps the cells marked $t. Here the unique mask keeps the first occurrence of each number.
Larger counts repeat each item.
For a matrix, the major cells are rows. The mask keeps the first row.
With the same counts on the left, #⁻¹ undoes Replicate. It keeps the first copy of each repeated cell. A count of zero gives a fill: the value used where data is absent, zero for numbers and a space for characters.
# (Runs)With one argument, # counts groups of adjacent equal major cells. It returns the group lengths and their values as two vectors.
With one argument, #⁻¹ rebuilds the array from the group lengths and values.
⍸ (iota underbar)⍸ (Where)On a Boolean array, Where gives the positions of the true items.
Nonnegative integer counts repeat the positions. The result contains position 0 once, position 1 twice and position 2 three times.
On a matrix, each position is a row-column coordinate pair.
┌→──────────────────┐
│ ┌→──┐ ┌→──┐ ┌→──┐ │
│ │0 1│ │1 0│ │1 2│ │
│ └ₓ──┘ └ₓ──┘ └ₓ──┘ │
└∊──────────────────┘
⍸ (Interval Index)X⍸Y counts how many boundaries in sorted X are less than or equal to each value of Y.
The boundaries 2 4 6 define four intervals, numbered from 0:
The values 2 and 3 both fall in interval 1. The value 4 falls in interval 2.
Character boundaries work in the same way. A and C are in interval 1, before the next boundary E. Y is beyond all five boundaries.
Interval index also compares major cells. Rows compare from left to right, at the first item that differs.
⌈ (Upstile)⌈ (Ceiling)Rounds up to an exact integer.
⌈ (Maximum)Takes the greater of each pair of numbers.
⌊ (Downstile)⌊ (Floor)Rounds down to an exact integer.
After a name or a computed expression, the suffix ₓ also means Floor. On a list of literals it marks exact numbers instead, as in Basics.
⌊ (Minimum)Takes the lesser of each pair of numbers.
Continue with Operators to combine these functions.
Not is its own inverse.
For a vector of positions, ⍸⁻¹ gives the count at each position through the last one present. It cannot recover trailing zero counts.