J Language Cheatsheet

The table is largely based on NuVoc (accessed around April 2021). It contains all J primitives with short descriptions, links to NuVoc and some examples. The order and the background colors are the same as in NuVoc table. The source of the table is on GitHub.

Types:

Self-Classify          = y _ compare unique items against all items; consider using i.~ y
Equal      0 x = y 0 compare corresponding atoms, 1 if equal, 0 if not; to compare two entire nouns for equality, use Match -:
Is (Local)          =. private assignment, supports unpacking
Is (Global)          =: public assignment, supports unpacking
Box          < y _ convert to boxed form, useful for heterogeneous arrays
Less Than      0 A < B 0 compare corresponding atoms, wherever A is less than B, return 1, else 0
Floor          <. B 0 largest integer less than or equal to B
Complex Floor          <. D 0 see docs for the description
Lesser Of (Min)      0 A <. B 0 the lesser atoms of arguments
Decrement          <: B 0 equivalent to B - 1
Less Or Equal      0 A <: B 0 compare corresponding atoms, wherever A is less than, or equal to, B, return 1, else 0
Open          > y 0 open boxed elements
Larger Than      0 A > B 0 compare corresponding atoms, wherever A is greater than B, return 1, else 0
Ceiling          >. B 0 smallest integer greater than or equal to B, equivalent to - <. - B
Complex Ceiling          >. D 0 see Complex Floor docs for the description
Larger Of (Max)      0 A >. B 0 the larger atoms of arguments
Increment          >: B 0 equivalent to B + 1
Larger Or Equal      0 A >: B 0 compare corresponding atoms, wherever A is greater than, or equal to, B, return 1, else 0
Negative Sign          _ as the first character of a numeric constant, acts as a negative sign
Infinity          _ standing by itself, represents the value Infinity
Indeterminate          _. a placeholder broadly comparable with NaN (not a number)
Infinite    _ [x] _: y _ Infinity (_), whatever the arguments happen to be
Conjugate          + B 0 complex conjugate of the number
Plus      0 A + B 0 add two numeric nouns
Real / Imag          +. B 0 decompose complex number into real and imaginary parts
GCD (Or)      0 A +. B 0 logical OR (disjunction) between Booleans, no short-circuit; Greatest Common Divisor
Double          +: B 0 equivalent to 2 * B
Not-Or      0 G +: H 0 logical NOR (Peirce's arrow), equivalent to -. G +. H
Signum          * B 0 sign of the number; a point on the unit circle for complex numbers B % | B
Times      0 A * B 0 product of two numeric nouns
Length / Angle          *. B 0 convert a complex number to polar coordinates
LCM (And)      0 A *. B 0 logical AND; Least Common Multiple in general
Square          *: B 0 square of numeric noun
Not-And      0 G *: H 0 logical NAND, equivalent to -. G *. H
Negate          - B 0 negate; don't confuse it with Negative Sign (_)
Minus      0 A - B 0 subtract B from A
Not          -. B 0 equivalent to 1 - B; logical NOT for Booleans, complementary probability for interval [0, 1]
Less      _ x -. y _ set difference; all atoms of x that are not in y
Halve          -: B 0 equivalent to B % 2
Match      _ x -: y _ 1 if entire nouns are the same in shape and elements (but not necessarily type), 0 otherwise
Reciprocal          % B 0 equivalent to 1 % B
Divide      0 A % B 0 A divided by B (note, that (0 % 0) = 0)
Matrix Inverse          %. B 2 inverse matrix of square matrix B or left inverse, if B is not square
Matrix Divide      _ A %. B 2 equivalent to (%. B) mux A, where mux is +/ . * (see Matrix Product)
Square Root          %: B 0 square root
Root      _ A %: B _ the A-th root of B
Exponential          ^ B 0 the B-th power of e; the antilogarithm of a natural logarithm
Power      0 A ^ B 0 the B-th power of A (0^0, _^0, 1^_ are equal to 1)
Stope Function      0 A ^ !.p B 0 equivalent to */A + p * i. B; the falling factorial when p = _1; see Stopes and Power in Dictionary
Natural Log          ^. y 0 natural logarithm
Logarithm      0 A ^. B 0 logarithm of B to the base A
Fixed Power  _ [x] u ^: n y _ apply verb u (or x&u, if dyadic) to y, n times
Fixed Power  _ [x] u ^: <n y _ apply verb u (or x&u, if dyadic) to y, (<n)-1 times, collecting results into a list
If  _ [x] u ^: h y _ conditionally execute a verb
Inverse, aka Obverse  _ [x] u ^: _1 y _ execute the obverse (usually the inverse) of a verb, "undo the effect of applying the verb"
Converge  _ [x] u ^: a: y _ apply the verb until the result stops changing
Converge  _ [x] u ^: _ y _ apply the verb until the result stops changing
Dynamic Power  _ [x] u ^: v y _ equivalent to (x&u)^:(x v y) or u^:(v y)
Do-While  _ [x] u ^: v^:_ y _ execute u repeatedly until v^:_ returns 0 or u returns its argument unchanged
Shape Of          $ y _ shape of the noun
Shape      1 x $ y _ reshape, return an array of items of y whose frame is x (if 1 < #$y, consider $,)
Sparse          $. B _ convert a dense array to sparse (see Dictionary)
Sparse      _ a $. B _ a collection of functions for creating and handling sparse arrays
Self-Reference    _ [x] $: y _ recursion, denotes the longest verb that contains it (within a sentence); provide default value
Reflex        u ~ y _ execute as a dyad with x=y, equivalent to y u y
Passive   ru x u ~ y lu swap the arguments of a dyad, equivalent to y u x
Evoke        m ~ the value of the name m; works for non-nouns, in contast to ". m
Nub          ~. y _ remove duplicates items, return only distinct items; order preserved
Nub Sieve          ~: y _ boolean vector, 1 at positions of distinct items; ~. y is equivalent to (~: y) # y
Not-Equal      0 x ~: y 0 compare corresponding atoms, 0 if equal, 1 if not; use Not Match -.@-: to compare two entire nouns
Magnitude          | B 0 absolute value; magnitude, if the argument is complex
Residue      0 a | B 0 the remainder when dividing a given number B by another given number a
Reverse          |. y _ rearrange the items in reverse order
Rotate      _ A |. y _ rotates successive axes of y by successive elements of A (positive - to left, negative - to right)
Shift      _ A |. !.f y _ like Rotate, but use fill atom f to replace shifted out items
Shift Right 1          |. !.f y _ equivalent to _1 |.!.f y
Transpose          |: y _ reverse the axes (not the items!)
Rearrange Axes      1 A |: y _ the axes having indices A become the new last axes
Extract Diagonal  1 (< A) |: y _ extract a diagonal of the array
Determinant        u . v B 2 -/ . * B is the determinant of the square matrix B (space before . is required)
Matrix Product    _ A u . v B _ A +/ . * B is the inner product or matrix product; dot product of two vectors
Def        m : n define entities of all types (verbs, adverbs, conjunctions, nouns); see Direct Definition
Def        0 : 0 define a multiline noun (can be used as a multiline comment), a table
Def        1 : 0 define a multiline adverb
Def        2 : 0 define a multiline conjunction
Def        3 : 0 define a multiline monadic or dual-valence verb
Def        4 : 0 define a multiline dyadic verb
Monad-Dyad        u : v derive a dual-valence verb: verb u if called monadically, verb v if called dyadically
Obverse        u :. v new verb that behaves as u, but its obverse is v
Adverse        u :: v run v if u fails (space after u is required)
Ravel          , y _ flatten; a list of all atoms in y, in the display order of y
Append      _ x , y _ an array containing the items of x followed by the items of y
Ravel Items          ,. y _ a table where each row of the table comes from an item of y (no-op for tables)
Stitch      _ x ,. y _ join each item of x to the corresponding item of y; equivalent to x ,"_1 y
Itemize          ,: y _ an array of shape 1, $y with a single item y
Laminate      _ x ,: y _ a 2-item array with reshaped and itemized x as the first and y as the second item
Raze          ; y _ remove one level of boxing, concatenate the contents of the boxes into one long array
Link      _ x ; y _ build up a list of boxed items (don't box y if it's already boxed); heterogeneous arrays
Reversed        u ;. 0 y _ reverse y along all its axes, apply u
Subarray    2 x u ;. 0 y _ extract subarray of y, described by x, apply u (];.0 extracts w/o overtaking, unlike {.); substring
SelfIntervals        u ;. 1 y _ split y, include frets (= first item, start of an interval), apply u on each interval
SelfIntervals        u ;. _1 y _ split y, remove frets (= first item, start of an interval), apply u on each interval
SelfIntervals        u ;. 2 y _ split y, include frets (= last item, end of an interval), apply u on each interval
SelfIntervals        u ;. _2 y _ split y, remove frets (= last item, end of an interval), apply u on each interval
Intervals    1 G u ;. 1 y _ split y, include frets (where G=1, start of an interval), apply u on each interval
Intervals    1 G u ;. _1 y _ split y, remove frets (where G=1, start of an interval), apply u on each interval
Intervals    1 G u ;. 2 y _ split y, include frets (where G=1, end of an interval), apply u on each interval
Intervals    1 G u ;. _2 y _ split y, remove frets (where G=1, end of an interval), apply u on each interval
Subarrays    2 x u ;. _3 y _ apply u to each tile of a regular tiling of y specified by x
Subarrays    2 x u ;. 3 y _ like u;._3, except that the results from uncompleted tiles are not discarded
Max Cubes        u ;. _3 y _ special case of ;._3, where x holds the same size for all dimensions, given by (#$y) $ <./ $y
Max Cubes        u ;. 3 y _ special case of ;.3, where x holds the same size for all dimensions, given by (#$y) $ <./ $y
Words          ;: y 1 partition a string into boxed words according to J's rules for word formation; tokenize; split
Sequential Machine      _ x ;: y _ partition a string y according to the rules of a given finite-state machine defined by x
Tally          # y _ count the items
Copy      1 A # y _ A controls how many times a corresponding item of y appears in a new array
Base Two          #. G 1 convert a binary list to an integer 5 -: #. 1 0 1
Base      1 A #. B 1 generalized #.B to bases other than 2 (including mixed bases); weighted sum
Antibase Two          #: B _ binary expansion of B as a Boolean list (two's complement form for negative numbers)
Antibase      1 A #: B 0 generalized #:B to bases other than 2 (including mixed bases); modulo; quotient/remainder; whole/fractional
Base Inverse      _ a #. ^:_1 B _ convert B to fixed base a (finds out length of the result automatically, unlike #:)
Factorial          ! B 0 factorial; generally, compute the Gamma function of 1+B
Out Of      0 A ! B 0 B-Combinations-A; number of ways to choose A items from B; binomial coefficients; Pascal's triangle
Fit (Customize)     lu u !. n ru variants of primitive verb: adjust comparison tolerance, fill atom, print precision, compensated sum, etc
Foreign      0 m !: n 0 system functions
Insert        u / y _ inserts (dyad) u between the items of y; reduce
Table    _ x u / y _ a table (if 0 = #$u) having entries a u b for every a in x and b in y; equivalent to x u"(lu,_) y
Oblique        u /. y _ apply u to the oblique diagonals of table y
Key    _ x u /. y _ apply u to each partition of y, based on keys from x; group by
Grade Up          /: y _ permutation that sorts the items of y into ascending order (stable sort)
Sort Up [Using]      _ x /: y _ apply to list x the permutation that sorts list y into ascending order; equivalent to (/: y) { x; sort /:~y
Prefix        u \ y _ apply u to successive prefixes of y of increasing length (the main use is in u/\, e.g. cumulative sum)
Infix    0 a u \ y _ apply u to successive (overlapping if a > 0) parts of y; sliding window
Suffix        u \. y _ apply u to successive suffixes of y of decreasing length (the main use is in u/\., calculated in reverse order)
Outfix    _ x u \. y _ apply u to y with successive (overlapping if x > 0) parts removed
Grade Down          \: y _ permutation that sorts the items of y into descending order (stable sort)
Sort Down [Using]      _ x \: y _ apply to list x the permutation that sorts list y into descending order; equivalent to (\: y) { x; sort \:~y
Same          [ y _ return y unchanged; equivalent to y and to ] y
Left      _ x [ y _ return x; separate assignments on the same line; useful in tacit verbs to get the value of x
Cap    _ [x] [: y _ in tacit phrase [: f g equivalent to g@:h; domain error as monad or dyad
Same          ] y _ return y unchanged; equivalent to y and to [ y; useful to display assignment as in ] z =: i:2
Right      _ x ] y _ return y; useful to separate two numeric atoms to prevent J treating them as a single list i."0 ] 3 4 5
Catalogue          { y 1 combine items from the atoms inside a boxed list to form a catalogue; Cartesian product
From      0 A { y _ select the item with index A from y; index along multiple axes, select subarrays, etc with boxed A
Head          {. y _ the first item of y; convert a single-item list into an atom
Take      1 A {. y _ the first (last if A is negative) A items of y; if A > #y, the result will have A items (fill atoms added)
Tail          {: y _ the last item of y
Map          {:: y _ a map of a boxed noun y (same box structure, but leafs replaced with paths); not the Lisp map!
Fetch      1 x {:: y _ a list of the contents of selected boxes in a boxed noun y; select from a deep structure (a tree)
Composite Item        m } y _ m (of the same shape as an item of y) selects atoms from the corresponding positions of the items of a list y
Amend    _ x m } y _ a copy of y with the locations m replaced by new values x; modify positions
Behead          }. y _ drop the first item
Drop      1 x }. y _ drop the first (the last, if x is negative) x items
Curtail          }: y 0 drop the last item; equivalent to _1 }. y
DirectDefinition          {{ }} shorthand for writing [multiline] [nested] explicit definitions (verbs, adverbs, conjunctions, nouns)
Assign Rank        u " n apply u to each n-cell (corresponding n-cells, if dyadic); the most-used modifier in J (like a [nested] loop)
Constant Verb        m " n a verb with rank n, that produces m for each n-cell of its argument(s)
Copy Rank        u " v u"v and m"v are equivalent to u"n and m"n respectively, where n is the list of ranks of v
Do          ". S 1 execute the sentence S, return the result; string to number (not safe, use the dyad)
Numbers      _ a ". S _ convert a byte array S (a string) into numbers with ill-formed numbers replaced by a
Default Format          ": y _ convert y to a byte array (a string)
Format      1 x ": y _ convert y (numeric or boxed) to a byte array (a string) formatted according to the specification x
Tie (Gerund)        u ` v combine verbs into a single noun to be used as an operand to a modifier (commonly used with / and @.)
Evoke Gerund      _ m `: n _ turn a gerund into verb; n=0, apply each verb separately; n=3, equivalent to m/; n=6, verb train
Atop lv [x] u @ v y rv composition: apply u monad on the result of each application of v to each cell of the argument(s)
Agenda        m @. n a verb defined by the n-th atom from gerund m; a train of verbs, if n is a list; boxes indicate parentheses
Agenda lv [x] m @. v y rv result of [x] v y used to select a verb w from m, then [x] w y; e.g. if-statement per cell
At  _ [x] u @: v y _ equivalent to u [x] v y; u is executed on the entire result of v
Bond        m & v _ make a monad out of a dyad v by supplying the noun value m as the left argument of v
Bond        u & n _ make a monad out of a dyad u by supplying the noun value n as the right argument of u
Bond    0 x m & v y _ apply m&v to y repeatedly x times; equivalent to x (m&v @ ] ^: [) y
Bond    0 x u & n y _ apply u&n to y repeatedly x times; equivalent to x (u&n @ ] ^: [) y
Compose mv [x] u & v y mv apply v to each cell of each argument, then apply u to the results for each cell separately
Under (Dual) mv [x] u &. v y mv on each cell apply v, u, the obverse of v; e.g. u&.> to apply u inside each box
Semidual   mv x u &. (a:`v) y mv same as u&.(a:`v), but apply (a:`v) only to y
Semidual   mv x u &. (v`a:) y mv same as u&.(v`a:), but apply (v`a:) only to x
Appose  _ [x] u &: v y _ apply v monad to each argument in its entirety, apply u to the results
Under  _ [x] u &.: v y _ apply v, u, the obvserse of v; supports Semiduals; equivalent to v^:_1 [(v x)] u (v y)
Roll          ? B 0 a random number uniformly distributed in a range determined by B; B=0 for floats in (0, 1); B>1 for integers
Deal      0 A ? B 0 select A items at random (without repetition) from the list i.B; be careful if using it with explicit-to-tacit translator
Roll / fixed seed          ?. y _ like Roll, but the random-number generator is reset each time ?. is executed; useful for reproducible samples
Deal / fixed seed      0 x ?. y 0 like Deal, but the random-number generator is reset each time ?. is executed; useful for reproducible samples
Alphabet          a. a built-in list of all bytes; ASCII characters
Ace (Boxed Empty)          a: an atom consisting of the boxed empty list <0$0
Anagram Index          A. B 1 convert the permutation B into its permutation number (anagram index)
Anagram      0 a A. y _ reorder items of y by applying the permutation of length #y with anagram index a
Boolean  _ [x] m b. y _ a verb to perform logic on the bit(s) of y (and x, if present); m selects the logic to apply
Boolean  _ [x] m b. y _ m 0 to 15 (same for _16 to _1): logical function, truth table encoded by m, e.g. 1 for AND, 6 for XOR, 7 for OR
Bitwise  _ [x] m b. y _ m 16 to 31: bitwise logical function, truth table encoded by m, e.g. 17 for AND, 22 for XOR, 23 for OR
Bitwise Rotate _ [x] 32 b. y _ left-rotate bits of y by x positions; use negative x to right-rotate
Unsigned Bitwise Shift _ [x] 33 b. y _ unsigned left-shift bits of y by x positions; use negative x to right-shift
Signed Bitwise Shift _ [x] 34 b. y _ signed left-shift bits of y by x positions; use negative x to right-shift
Verb Information        u b. _1 linear representation of the obvserse of u
Verb Information        u b. 0 ranks of u
Verb Information        u b. _1 linear representation of the identity function of u
Cycle-Direct          C. B 1 convert the permutation B between direct and cycle representations
Permutation Parity          C. !.2 y 1 the Levi-Civita symbol (ε) of y
Permute      1 x C. y _ apply the permutation x to the items of x
Raze In          e. y _ a Boolean table comparing each box of y (a list of boxed items) against each atom in ;y (the Raze of y)
Member (In)      _ x e. y _ return 1 if item y is in array y, otherwise 0; contains/includes
Find Matches      _ x E. y _ a Boolean array (shape of y) indicating starting points in y of subarrays equal to x; matching substrings
Fix        u f. _ replace each name in u with a fixed value without name dependencies; doesn't work with explicit definitions
Fold Multiple Forward    [x] u F:. v y process y left-to-right with v (a recurrence relation), apply u on each item, return all; x is initial arg to v
Fold Multiple Reverse    [x] u F:: v y process y right-to-left with v (a recurrence relation), apply u on each item, return all; x is initial arg to v
Fold Multiple    [x] u F: v y v (a recurrence relation) builds a sequence, apply u on each item, halt with Z:, return all; x is arg to v
Fold Single Forward    [x] u F.. v y process y left-to-right with v (a recurrence relation), apply u on each item, return last; x is initial arg to v
Fold Single Reverse    [x] u F.: v y process y right-to-left with v (a recurrence relation), apply u on each item, return last; x is initial arg to v
Fold Single    [x] u F. v y v (a recurrence relation) builds a sequence, apply u on each item, halt with Z:, return last; x is arg to v
Hypergeometric  0 [x] m H. n y 0 sum x terms of a generalized hypergeometric series; m and n describe the series
Integers          i. y 1 an ascending sequence of integers; shape is |y; a negative atom in y reverses along corresponding dimension
Index Of      _ x i. y _ find the first occurence of y in x; return #x, if not found; for sorted lists of integers i.!.1 is faster
Steps          i: B 0 a sequence of integers from -B to +B; b in a complex number (a j. b) gives the number of steps between
Index Of Last      _ x i: y _ find the last occurence of y in x; return #x, if not found (same as for i.)
Indices          I. H 1 indexes of all 1's in H; equivalent to H # i. # H; if an atom of H is greater than 1, the index is repeated
Interval Index      _ A I. y _ binary search; A should be sorted (either in ascending or descending order)
Imaginary          j. y 0 multiply y by 0j1, which represents the imaginary unit i; equivalent to 0j1 * y
Complex      0 x j. y 0 combine x and y into a complex number; equivalent to x + 0j1 * y
Level Of          L. y _ the greatest level of nesting of a boxed noun, or 0 if unboxed
Level At  _ [x] u L: n y _ the same box structure but contents of each box on level n (0 for leaves) modified by u
Memo lu [x] u M. y ru memoization; records only atomic arguments; user can't control the size of the table
Comment          NB. everything from NB. to the end-of-line (LF) will be ignored by the interpreter
Pi Times          o. y 0 π times y given any number y; 1p1 = o. 1
Circle Function      0 x o. y 0 trigonometric and hyperbolic functions, their inverses; The Story of ○
Roots          p. y 1 convert the polynomial y between coefficient and multiplier-and-roots form
Polynomial      1 x p. y 0 evaluate polynomial x for given value(s) of y
Polynomial Derivative          p.. y 1 the first derivative of a given polynomial y
Polynomial Integral      0 x p.. y 1 the integral of a given polynomial y; x is the constant of integration that will be added to the result
Primes          p: y 0 the y-th prime (starting with 2 as the 0-th prime); the inverse p:^:_1 y tells the number of primes less than y
Primes      _ x p: y _ a collection of prime-related functions of integer y, with x selecting the function
Primes     _ _4 p: y _ the largest prime smaller than y
Primes     _ _1 p: y _ π(y), the number of primes less than y (same as p:^:_1)
Primes      _ 0 p: y _ 1 if y is not prime
Primes      _ 1 p: y _ 1 if y is prime
Primes      _ 2 p: y _ a 2-row table of the prime factors and exponents in the factorization of y (same as __ q: y)
Primes      _ 3 p: y _ the list of primes whose product is equal to y (same as q: y)
Primes      _ 4 p: y _ the smallest prime larger than y
Primes      _ 5 p: y _ the number of integers less than or equal to y that are relatively prime to y (Euler's totient function φ(y))
Prime Factors          q: y 0 the prime factorization of integer y, listed in ascending order; same as 3 p: y
Prime Exponents      0 x q: y 0 primes and exponentes in the factorization of y; x>0, the leading exponents; x<0, table, trailing, zeros excluded
Angle          r. y 0 angle y (in radians), expressed as a unit vector in the complex plane
Polar      0 x r. y 0 like monadic (r.), but with a scaling factor x; equivalent to x * (r. y)
Symbol          s: y _ intern a boxed string; some operations on symbols are faster, than on boxed strings (search, comparison)
Symbol      _ x s: y _ verbs for working with symbol sets: table of symbols, store/restore the global symbols data, etc
Spread  _ [x] u S: n y _ apply u to contents of each box on level n (0 for leaves), collect results into an array (compare with L:)
Unicode          u: y _ convert an integer y to the unicode character having y as its code point; convert a character to unicode precision
Unicode      _ x u: y _ convert between numbers, character precisions and encodings according to the Unicode and UTF-8 standards
Extended Precision          x: y _ convert a number y to extended precision, either extended integer or rational
Num/Denom      _ x x: y _ convert a number y of any precision to a precision chosen by x
Terminate Fold      _ x Z: y _ terminate Fold, in whole or part
Constant Function    _ [x] 0: y _ the value 0, whatever the arguments happen to be; has sister-primitives _:, 1:, ..., 9: and _1:, ..., _9:
Enhanced Operand          u. _ find the value of u in current namespace, switch to a previous namespace, execute the value there
Enhanced Operand          v. _ find the value of v in current namespace, switch to a previous namespace, execute the value there