ι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. With an exact input, ι returns an exact array: compare ι4 with ι4ₓ.
For performance-sensitive indexing, use exact integer index arrays, because float indices require whole-number checks and float-to-integer conversions.
A matrix position has two coordinates: a row number and a column number. Given a shape vector, ι gives an array with 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.
With a length of 0, ι returns an empty vector.
ι⁻ takes an array of positions and gives the shape that ι generated it from, as a vector. For a vector of four positions it gives [4], and for a matrix of row-column coordinates it gives the two lengths.
ι (index of)For vectors, XιY gives the first position of each item of Y in X. For an item absent from X, the result is 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. Each position must be one that Index Of can return for that array: the first position of an item, or the array’s length, for which ι⁻ gives a fill. For any other position, ι⁻ raises a DOMAIN error.
↦ (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. With characters as its arguments, ↦ 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 is compared 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, X=⁻Y finds the Boolean Z for which X=Z is Y. $t=$f is $f, 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. It marks later occurrences with $f.
≠ (Not Equal To)Dyadic ≠ gives $t where the atoms differ.
The number 7 and the character 7 are not equal.
X≠⁻Y likewise finds the Boolean Z for which X≠Z is Y.
< (Less than sign)< (Sort up)With one argument, < sorts the major cells in ascending order.
< (Less than)> (Greater than sign)> (Sort down)With one argument, > sorts the major cells 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.
An unevenly nested array has the depth of its 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. ρ 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. ∨ puts each number’s 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 and angle from the positive real axis. The magnitude is the distance from zero. 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)Not is its own inverse.
~ (Without)Without keeps the items from the left argument that are absent from the right.
It also compares strings as whole items.
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 argument was obtained by squaring a negative number.
⊼ (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 Replicate uses the unique mask to keep the first occurrence of each number.
With larger counts, Replicate repeats each item.
Because a matrix’s major cells are its rows, [$t $f]# keeps the first row.
With the same counts on the left, #⁻ undoes Replicate. It keeps the first copy of each repeated cell. For 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, # groups adjacent equal major cells and returns two vectors: the group lengths and their values.
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.
When given nonnegative whole counts, ⍸ repeats each position that many times. In ⍸[1 2 3], 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│ │
│ └ₓ──┘ └ₓ──┘ └ₓ──┘ │
└∊──────────────────┘
┌→────────────────────────────────────┐
│ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ │
│ │0 1│ │0 1│ │1 0│ │1 0│ │1 2│ │1 2│ │
│ └ₓ──┘ └ₓ──┘ └ₓ──┘ └ₓ──┘ └ₓ──┘ └ₓ──┘ │
└∊────────────────────────────────────┘
For a vector of positions, ⍸⁻ counts the occurrences of each position, from 0 through the last position present. It cannot recover trailing zero counts.
⍸ (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 are compared from left to right, by 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.