!?|⌈⌊⊥⊤⊣⊢#

Factorial, binomial !#

Monadic ! is factorial. Note that it goes on the left (like all other monadic APL functions) as opposed to mathematics’ \(!\).

Dyadic A!B is binomial. It is the number of ways to take A items from a bag of B items, generalised to be the binomial function.

!12         ⍝ 12 factorial
2!8         ⍝ how many ways can we select 2 from 8?
479001600
28

Roll, deal ?#

Monadic ?B is roll. It returns a random integer among the first B integers. ?0 returns a random float between (but not including) 0 and 1:

?6 6 6     ⍝ roll three six-sided dice
?0         ⍝ random float between 0-1, excluding 0 and 1
4 3 4
0.3205466592

Dyadic A?B is deal. It returns a random one of the ways A!B counted. I.e. it returns A random numbers among the B first integers.

10?10       ⍝ 1-10 in random order
1 6 9 2 4 7 8 3 5 10

Note that it deals from the set ⍳B, so it’s dependent on your ⎕IO setting:

10?10  ⎕IO0     ⍝ Now we should get 0-9
⎕IO1             ⍝ Reset ⎕IO to default
8 0 3 6 5 2 7 9 4 1

Magnitude, residue |#

Monadic | is magnitude, also called the absolute value, \(|x|\):

|¯97
|3 5 ¯7 ¯8 7 ¯2
97
3 5 7 8 7 2

Dyadic A|B is residue, also known as the division remainder (“mod”) when B is divided by A. Note the reversed order of arguments. “normal” mod is |⍨.

2|⍳10     ⍝ odd numbers in 1-10
1 0 1 0 1 0 1 0 1 0

Ceiling, maximum #

Monadic is ceiling, \(⌈x⌉\),

3.14159256
4

Dyadic A⌈B is maximum:

1523
23

Floor, minimum #

Monadic is floor, and the dyadic is minimum,

3.14159256
1523
3
15

Decode #

A⊥B is decode. It evaluates digits B as (mixed) base A, e.g,

21 0 1 0 1 0   ⍝ decode binary to decimal
42

Encode #

A⊤B, or encode, is the inverse of , turning B into a list(s) of digits in (mixed) base A,

24 60 6010000  ⍝ seconds to hour, minutes, seconds
2 46 40

Ten thousand seconds is the same as 2 hours, 46 minutes and 40 seconds.

Left, right ⊣⊢#

Dyadic is the left argument unmodified. Monadically, it just returns its sole argument. Dyadic is the right argument unmodified. Monadically, it just returns its sole argument.