Consider the following edited extract from Exercise 5.16 in Chapter 5:
The well known bill of materials application involves a relvar—PP, say—showing which parts contain which parts as immediate components. Of course, immediate components are themselves parts, and they can have further immediate components of their own.
PP: Part PX contains part PY as an immediate component.
TC: Part PX contains part PY as a component at some level (not necessarily immediate).
Figure 7-5. Relvars PP and TC (sample values)
Given a (relation) value pp for relvar PP, the relation tc that’s the transitive closure of pp can be defined as follows:
Definition: The pair (px,py) appears in tc if and only if:
It appears in pp, or
There exists some pz such that the pair (px,pz) appears in pp and the pair (pz,py) appears in tc.
In other words, if we think of pp as representing a directed graph, with a node for each part and an arc from each node to each corresponding immediate component node, then (px,py) appears in the transitive closure if and only if there’s a path in that graph from node px to node py. Observe that the definition involves a recursive reference to relation tc.
Aside: In practice relvar PP would probably have a QTY attribute as well (showing ...