A relation from A to B is nothing more than a selection of cells from the rectangular grid A \times B. The definition is that compact: pick any subset of the pairs, and that subset is a valid relation. This article gives you a live grid where you can watch relations come into existence, one pair at a time.

What the grid shows

Take A = \{1, 2, 3, 4\} on the vertical axis and B = \{p, q, r, s, t\} on the horizontal axis. The 4 \times 5 = 20 cells cover every possible ordered pair from A to B. A relation is any subset — you pick which cells are filled and which are empty.

Interactive relation-number slider with gridA horizontal slider from 0 to 20 controls how many ordered pairs are present in a displayed relation. Above the slider, a grid with 4 rows labelled 1 through 4 and 5 columns labelled p, q, r, s, t shows 20 cells. As the slider moves, a readout reports the number of pairs selected and the total 20 cells available. The caption explains that every such choice is a valid relation from A to B. 0 10 20 drag to change how many pairs are in the relation each of 2²⁰ = 1,048,576 possible relations from {1,2,3,4} to {p,q,r,s,t} p q r s t 1 2 3 4
A sample relation $R = \{(1, p), (1, r), (2, s), (2, t), (3, q), (4, p), (4, s), (4, t)\}$ with $8$ pairs drawn on the $A \times B$ grid. Drag the slider to scan through relation sizes from $0$ (empty) to $20$ (full product). Every single cell-selection is a distinct relation — there are $2^{20} = 1{,}048{,}576$ of them on this grid.

Reading the grid

The row tells you the first coordinate (from A); the column tells you the second (from B). A filled cell at row 2, column s means the ordered pair (2, s) belongs to the relation. An empty cell means it does not.

The eight filled cells in the figure correspond to the relation

R = \{(1, p),\, (1, r),\, (2, s),\, (2, t),\, (3, q),\, (4, p),\, (4, s),\, (4, t)\}

You could pick any other eight cells and get a completely different relation. The total number of possible relations from A to B equals the number of subsets of the grid: 2^{|A| \cdot |B|} = 2^{20}. The slider position gives a sense of how many pairs are involved for a given size, not which specific pairs (that is a separate choice).

Reading the row and column projections

The grid picture also lets you read off the domain and range at a glance.

If you shrink the relation by dragging the slider left, rows and columns start going empty — and the domain and range shrink with them. An empty row means that first-coordinate is not in the domain. An empty column means that second-coordinate is not in the range.

What the grid is not

Why: a relation is a set of pairs, not a rule. The grid enumerates every possible pair and lets you tick off which ones are in. That distinction matters — many textbooks introduce relations via a rule ("a divides b"), but the rule is just a shorthand for "these are the cells I ticked."

Three instructive relations

The empty relation. Zero dots. Slider at 0. No element is related to anything. Domain and range are both empty.

The full product A \times B. All 20 dots. Slider at 20. Every element of A is related to every element of B. Domain = A, range = B.

The diagonal. When A = B, the dots \{(1,1), (2,2), (3,3), (4,4)\} form the identity relation — every element related to itself and nothing else. This is the smallest reflexive relation and the simplest non-empty equivalence relation.

The link to the formal definition

Every formal fact about relations is visible on the grid:

Grid observation Formal statement
The row for a has a dot in column b (a, b) \in R
The row for a is entirely empty a \notin \text{dom}(R)
The column for b is entirely empty b \notin \text{range}(R)
Total number of dots $
Total number of cells $
Number of distinct dot-patterns $2^{

The grid is not just a pretty picture — it is a literal drawing of the definition. A relation is a subset of cells, and the picture is the set. Train your eye to read the domain off the non-empty rows and the range off the non-empty columns, and every relation problem becomes a visual one.

Related: Relations · Set Operations · Cartesian Product Grid · Cardinality of A × B