Relational division (source code)

= Relational division

<Relational division> expresses an all-required-matches query. Let $R\subseteq X\times Y$ be a <database relation>, $S\subseteq Y$ the required values and $C\subseteq X$ an explicit candidate <database relation>. The desired result is
$$
D=\{x\in C:\forall y\in S,\ (x,y)\in R\}.
$$
It can be constructed using <Cartesian product>, <relational projection> and <relational difference>:
$$
D=C-\pi_X\bigl((C\times S)-R\bigr).
$$
The inner <relational difference> contains missing required pairs. Its <relational projection> identifies failing candidates; removing them from $C$ proves the formula.

For example, $R$ can record <scientific instrument>/test pairs and $S=\{\mathrm{heat},\mathrm{vibration}\}$ the required tests. An <scientific instrument> with both pairs passes; one with only the heat pair does not. This is a <universal quantifier> requirement, unlike an ordinary <relational join> asking for some match.

When $S$ is empty, <vacuous truth> gives $D=C$. Choosing $C=\pi_X(R)$ is conventional but cannot recover candidates absent from $R$; use an independently stored <scientific instrument> <database relation> if those candidates must be included. Stating the candidate universe makes this <edge> case unambiguous.