Functions and operators

a mod na \bmod n Modulo

The remainder after division: 7 mod 3 = 1.

In ML papers

a mod na \bmod n is the remainder when aa is divided by nn, a whole number from 00 to n−1n - 1. It makes indices wrap around: position t mod Tt \bmod T in a cyclic buffer, the even and odd dimensions (i mod 2i \bmod 2) of a positional encoding, a hash into nn buckets.

Written as a≡b(modn)a \equiv b \pmod{n} it is a statement, not an operation: aa and bb leave the same remainder (see Identically equal).

How to type it

LaTeXShows
a \bmod n as an operationa mod na \bmod n
a \equiv b \pmod{n} as a congruencea≡b(modn)a \equiv b \pmod{n}
a \mod n with wider spacingamod  na \mod n

A worked example

7 mod 3=1,12 mod 4=0,17≡2(mod5)7 \bmod 3 = 1, \quad 12 \bmod 4 = 0, \quad 17 \equiv 2 \pmod{5}

17=3×5+217 = 3 \times 5 + 2, so 17 leaves remainder 2.

Common confusions

Related

f≡0f \equiv 0Identically equal⌊x⌋,  ⌈x⌉\lfloor x \rfloor, \; \lceil x \rceilFloor and ceilingPE(pos,2i)=sin⁡(pos100002i/d)PE_{(pos, 2i)} = \sin\left(\frac{pos}{10000^{2i/d}}\right)Sine

Decode this example →