# Relation composition

In logic and mathematics, the composition of relations is the generalization of the composition of functions. Formally, composition of relations is the fiber product; in relational algebra, it is called the join.

## Preliminaries

The first order of business is to define the operation on relations that is variously known as the composition of relations, relational composition, or relative multiplication. In approaching the more general constructions, it pays to begin with the composition of 2-adic and 3-adic relations.

As an incidental observation on usage, there are many different conventions of syntax for denoting the application and composition of relations, with perhaps even more options in general use than are common for the application and composition of functions. In this case there is little chance of standardization, since the convenience of conventions is relative to the context of use, and the same writers use different styles of syntax in different settings, depending on the ease of analysis and computation.

• The first dimension of variation in syntax has to do with the correspondence between the order of operation and the linear order of terms on the page.
• The second dimension of variation in syntax has to do with the automatic assumptions in place about the associations of terms in the absence of associations marked by parentheses. This becomes a significant factor with relations in general because the usual property of associativity is lost as both the complexities of compositions and the dimensions of relations increase.
• These two factors together generate the following four styles of syntax:
• LALA = left application, left association.
• LARA = left application, right association.
• RALA = right application, left association.
• RARA = right application, right association.

## Definition

A notion of relational composition is to be defined that generalizes the usual notion of functional composition :

• Composing on the right, ${\displaystyle f:X\to Y}$ followed by ${\displaystyle g:Y\to Z}$ results in a composite function formulated as ${\displaystyle fg:X\to Z.}$
• Composing on the left, ${\displaystyle f:X\to Y}$ followed by ${\displaystyle g:Y\to Z}$ results in a composite function formulated as ${\displaystyle gf:X\to Z.}$

Note on notation. The ordinary symbol for functional composition is the composition sign, a small circle "ο" written between the names of the functions being composed, as f ο g, but the sign is often omitted if there is no risk of confusing the composition of functions with their algebraic product. In contexts where both compositions and products occur, either the composition is marked on each occasion or else the product is marked by means of a raised dot sign "${\displaystyle \cdot }$", as f${\displaystyle \cdot }$g.

Generalizing the paradigm along parallel lines, the composition of a pair of 2-adic relations is formulated in the following two ways:

• Composing on the right, ${\displaystyle P\subseteq X\times Y}$ followed by ${\displaystyle Q\subseteq Y\times Z}$ results in a composite relation formulated as ${\displaystyle PQ\subseteq X\times Z.}$
• Composing on the left, ${\displaystyle P\subseteq X\times Y}$ followed by ${\displaystyle Q\subseteq Y\times Z}$ results in a composite relation formulated as ${\displaystyle QP\subseteq X\times Z.}$

## Geometric construction

There is a neat way of defining relational compositions in geometric terms, not only showing their relationship to the projection operations that come with any cartesian product, but also suggesting natural directions for generalizing relational compositions beyond the 2-adic case, and even beyond relations that have any fixed arity, in effect, to the general case of formal languages as generalized relations.

This way of looking at relational compositions is sometimes referred to as Tarski's Trick (${\displaystyle {\mbox{T}}^{2}}$), on account of his having put it to especially good use in his work (Ulam and Bednarek, 1977). It supplies the imagination with a geometric way of visualizing the relational composition of a pair of 2-adic relations, doing this by attaching concrete imagery to the basic set-theoretic operations, namely, intersections, projections, and a certain class of operations inverse to projections, here called 'tacit extensions'.

The stage is set for Tarski's trick by highlighting the links between two topics that are likely to appear wholly unrelated at first, namely:

• The use of logical conjunction, as denoted by the symbol  "∧"  in expressions of the form F(x, y, z) = G(x, y) ∧ H(y, z), to define a 3-adic relation F in terms of a pair of 2-adic relations G and H.
• The concepts of 2-adic projection and projective determination, that are invoked in the 'weak' notion of projective reducibility.

The relational composition G ο H of a pair of 2-adic relations G and H will be constructed in three stages, first, by taking the tacit extensions of G and H to 3-adic relations that reside in the same space, next, by taking the intersection of these extensions, tantamount to the maximal 3-adic relation that is consistent with the prima facie 2-adic relation data, finally, by projecting this intersection on a suitable plane to form a third 2-adic relation, constituting in fact the relational composition G ο H of the relations G and H.

The construction of a relational composition in a specifically mathematical setting normally begins with mathematical relations at a higher level of abstraction than the corresponding objects in linguistic or logical settings. This is due to the fact that mathematical objects are typically specified only 'up to isomorphism' as the conventional saying goes, that is, any objects that have the 'same form' are generally regarded as the being the same thing, for most all intents and mathematical purposes. Thus, the mathematical construction of a relational composition begins by default with a pair of 2-adic relations that reside, without loss of generality, in the same plane, say, G, HX × Y, as depicted in Figure 1.

o-------------------------------------------------o
|                                                 |
|        o                       o                |
|        |\                      |\               |
|        | \                     | \              |
|        |  \                    |  \             |
|        |   \                   |   \            |
|        |    \                  |    \           |
|        |     \                 |     \          |
|        |   *  \                |   *  \         |
|        X   *   Y               X   *   Y        |
|         \  *   |                \  *   |        |
|          \ G   |                 \ H   |        |
|           \    |                  \    |        |
|            \   |                   \   |        |
|             \  |                    \  |        |
|              \ |                     \ |        |
|               \|                      \|        |
|                o                       o        |
|                                                 |
o-------------------------------------------------o
Figure 1.  Dyadic Relations G, H c X x Y


The 2-adic relations G and H cannot be composed at all at this point, not without additional information or further stipulation. In order for their relational composition to be possible, one of two types of cases has to happen:

• The first type of case occurs when X = Y. In this case, both of the compositions G ο H and H ο G are defined.
• The second type of case occurs when X and Y are distinct, but when it nevertheless makes sense to speak of a 2-adic relation Ĥ that is 'just like' H, but living in the plane YZ, that is, in the space of the cartesian product Y × Z, for some set Z.

Whether you view isomorphic things to be the same things or not, you still have to specify the exact isomorphisms that are needed to transform any given representation of a thing into a required representation of the same thing. Let us imagine that we have done this, and say how later:

o-------------------------------------------------o
|                                                 |
|        o                               o        |
|        |\                             /|        |
|        | \                           / |        |
|        |  \                         /  |        |
|        |   \                       /   |        |
|        |    \                     /    |        |
|        |     \                   /     |        |
|        |   *  \                 /  *   |        |
|        X   *   Y               Y   *   Z        |
|         \  *   |               |   *  /         |
|          \ G   |               |   Ĥ /          |
|           \    |               |    /           |
|            \   |               |   /            |
|             \  |               |  /             |
|              \ |               | /              |
|               \|               |/               |
|                o               o                |
|                                                 |
o-------------------------------------------------o
Figure 2.  Dyadic Relations G c X x Y and Ĥ c Y x Z


With the required spaces carefully swept out, the stage is set for the presentation of Tarski's trick, and the invocation of the following symbolic formula, claimed to be a definition of the relational composition P ο Q of a pair of 2-adic relations P, QX × X.

Definition. P ο Q = proj13 (P × XX × Q).

To get this drift of this definition, one needs to understand that it's written within a school of thought that holds that all 2-adic relations are, 'without loss of generality', covered well enough, 'for all practical purposes', under the aegis of subsets of a suitable cartesian square, and thus of the form LX × X. So, if one has started out with a 2-adic relation of the shape LU × V, one merely lets X = UV, trading in the initial L for a new LX × X as need be.

The projection proj13 is just the projection of the cartesian cube X × X × X on the space of shape X × X that is spanned by the first and the third domains, but since they now have the same names and the same contents it is necessary to distinguish them by numbering their relational places.

Finally, the notation of the cartesian product sign  "×"  is abused, or extended, depending on your point of view, to signify a couple of other 'products' with respect to a 2-adic relation LX × X and a subset WX, like so:

Definition. ${\displaystyle L\times W=\{(x,y,z)\in X^{3}:(x,y)\in L\land z\in W\}.}$
Definition. ${\displaystyle W\times L=\{(x,y,z)\in X^{3}:x\in W\land (y,z)\in L\}.}$

Applying these definitions to the case P, Q c X x X, the two 2-adic relations whose relational composition P o Q c X x X is about to be defined, one finds:

${\displaystyle P\times X=\{(x,y,z)\in X^{3}:(x,y)\in P\land z\in X\},}$
${\displaystyle X\times Q=\{(x,y,z)\in X^{3}:x\in X\land (y,z)\in Q\}.}$

These are just the appropriate special cases of the tacit extensions already defined.

${\displaystyle P\times X=te_{12}^{3}(P),}$
${\displaystyle X\times Q=te_{23}^{1}(Q).}$

In summary, then, the expression:

${\displaystyle proj_{13}(P\times X\cap X\times Q)}$

is equivalent to the expression:

${\displaystyle proj_{13}(te_{12}^{3}(P)\cap te_{23}^{1}(Q))}$

and this form is generalized — although, relative to one's school of thought, perhaps inessentially so — by the form that was given above as follows:

Definition. ${\displaystyle P\circ Q=proj_{XZ}(te_{XY}^{Z}(P)\cap te_{YZ}^{X}(Q)).}$

Figure 3 presents a geometric picture of what is involved in formulating a definition of the 3-adic relation FX × Y × Z by way of a conjunction of the 2-adic relation GX × Y and the 2-adic relation H ⊆ Y × Z, as done for example by means of an expression of the following form:

• ${\displaystyle F(x,y,z)=G(x,y)\land H(y,z).}$
o-------------------------------------------------o
|                                                 |
|                        o                        |
|                       /|\                       |
|                      / | \                      |
|                     /  |  \                     |
|                    /   |   \                    |
|                   /    |    \                   |
|                  /     |     \                  |
|                 /      |      \                 |
|                o       o       o                |
|                |\     / \     /|                |
|                | \   / F \   / |                |
|                |  \ /  *  \ /  |                |
|                |   \  /*\  /   |                |
|                |  / \//*\\/ \  |                |
|                | /  /\/ \/\  \ |                |
|                |/  ///\ /\\\  \|                |
|        o       X  ///  Y  \\\  Z       o        |
|        |\       \///   |   \\\/       /|        |
|        | \      ///    |    \\\      / |        |
|        |  \    ///\    |    /\\\    /  |        |
|        |   \  ///  \   |   /  \\\  /   |        |
|        |    \///    \  |  /    \\\/    |        |
|        |    /\/      \ | /      \/\    |        |
|        |   *//\       \|/       /\\*   |        |
|        X   */  Y       o       Y  \*   Z        |
|         \  *   |               |   *  /         |
|          \ G   |               |   H /          |
|           \    |               |    /           |
|            \   |               |   /            |
|             \  |               |  /             |
|              \ |               | /              |
|               \|               |/               |
|                o               o                |
|                                                 |
o-------------------------------------------------o
Figure 3.  Projections of F onto G and H


To interpret the Figure, visualize the 3-adic relation FX × Y × Z as a body in XYZ-space, while G is a figure in XY-space and H is a figure in YZ-space.

The 2-adic projections that accompany a 3-adic relation over X, Y, Z are defined as follows:

• ${\displaystyle proj_{XY}(L)=\{(x,y)\in X\times Y:(\exists z\in Z)(x,y,z)\in L\},}$
• ${\displaystyle proj_{XZ}(L)=\{(x,z)\in X\times Z:(\exists y\in Y)(x,y,z)\in L\},}$
• ${\displaystyle proj_{YZ}(L)=\{(y,z)\in Y\times Z:(\exists x\in X)(x,y,z)\in L\}.}$

For many purposes it suffices to indicate the 2-adic projections of a 3-adic relation L by means of the briefer equivalents listed here:

• ${\displaystyle L_{XY}\ =\ proj_{XY}(L),}$
• ${\displaystyle L_{XZ}\ =\ proj_{XZ}(L),}$
• ${\displaystyle L_{YZ}\ =\ proj_{YZ}(L).}$

In light of these definitions, ${\displaystyle proj_{XY}\!}$ is a mapping from the set ${\displaystyle {\mathcal {L}}_{XYZ}}$ of 3-adic relations over X, Y, Z to the set ${\displaystyle {\mathcal {L}}_{XY}}$ of 2-adic relations over X and Y, with similar relationships holding for the other projections. To formalize these relationships in a concise but explicit manner, it serves to add a few more definitions.

The set ${\displaystyle {\mathcal {L}}_{XYZ}}$, whose membership is just the 3-adic relations over X, Y, Z, can be recognized as the 'set of all subsets' of the cartesian product X × Y × Z, also known as the power set of X × Y × Z, and notated here as Pow(X × Y × Z).

• ${\displaystyle {\mathcal {L}}_{XYZ}=\{L:L\subseteq X\times Y\times Z\}=Pow(X\times Y\times Z).}$

Likewise, the power sets of the pairwise cartesian products encompass all of the 2-adic relations on pairs of distinct domains that can be chosen from {X, Y, Z}.

• ${\displaystyle {\mathcal {L}}_{XY}=\{L:L\subseteq X\times Y\}=Pow(X\times Y),}$
• ${\displaystyle {\mathcal {L}}_{XZ}=\{L:L\subseteq X\times Z\}=Pow(X\times Z),}$
• ${\displaystyle {\mathcal {L}}_{YZ}=\{L:L\subseteq Y\times Z\}=Pow(Y\times Z).}$

In mathematics, the inverse relation corresponding to a projection map is usually called an extension. To avoid confusion with other senses of the word, however, it is probably best for the sake of this discussion to stick with the more specific term tacit extension.

The tacit extensions ${\displaystyle te_{XY}^{Z}}$, ${\displaystyle te_{XZ}^{Y}}$, ${\displaystyle te_{YZ}^{X}}$, of the 2-adic relations UX × Y, VX × Z, WY × Z, respectively, are defined in the following way:

• ${\displaystyle te_{XY}^{Z}(U)\ =\ \{(x,y,z):(x,y)\in U\}}$
• ${\displaystyle te_{XZ}^{Y}(V)\ =\ \{(x,y,z):(x,z)\in V\}}$
• ${\displaystyle te_{YZ}^{X}(W)\,=\ \{(x,y,z):(y,z)\in W\}}$

So long as the intended indices attaching to the tacit extensions can be gathered from context, it is usually clear enough to use the abbreviated forms, te(U), te(V), te(W).

The definition and illustration of relational composition presently under way makes use of the tacit extension of G ⊆ X × Y to te(G) ⊆ X × Y × Z and the tacit extension of H ⊆ Y × Z to te(H) ⊆ X × Y × Z, only.

Geometric illustrations of te(G) and te(H) are afforded by Figures 4 and 5, respectively.

o-------------------------------------------------o
|                                                 |
|                        o                        |
|                       /|\                       |
|                      / | \                      |
|                     /  |  \                     |
|                    /   |   \                    |
|                   /    |    \                   |
|                  /     |     \                  |
|                 /      |   *  \                 |
|                o       o  **   o                |
|                |\     / \***  /|                |
|                | \   /  ***  / |                |
|                |  \ /  ***\ /  |                |
|                |   \  ***  /   |                |
|                |  / \***  / \  |                |
|                | /  ***  /   \ |                |
|                |/  ***\ /     \|                |
|        o       X  /**  Y       Z       o        |
|        |\       \//*   |      /       /|        |
|        | \      ///    |     /       / |        |
|        |  \    ///\    |    /       /  |        |
|        |   \  ///  \   |   /       /   |        |
|        |    \///    \  |  /       /    |        |
|        |    /\/      \ | /       /     |        |
|        |   *//\       \|/       /  *   |        |
|        X   */  Y       o       Y   *   Z        |
|         \  *   |               |   *  /         |
|          \ G   |               |   H /          |
|           \    |               |    /           |
|            \   |               |   /            |
|             \  |               |  /             |
|              \ |               | /              |
|               \|               |/               |
|                o               o                |
|                                                 |
o-------------------------------------------------o
Figure 4.  Tacit Extension of G to X x Y x Z

o-------------------------------------------------o
|                                                 |
|                        o                        |
|                       /|\                       |
|                      / | \                      |
|                     /  |  \                     |
|                    /   |   \                    |
|                   /    |    \                   |
|                  /     |     \                  |
|                 /  *   |      \                 |
|                o   **  o       o                |
|                |\  ***/ \     /|                |
|                | \  ***  \   / |                |
|                |  \ /***  \ /  |                |
|                |   \  ***  /   |                |
|                |  / \  ***/ \  |                |
|                | /   \  ***  \ |                |
|                |/     \ /***  \|                |
|        o       X       Y  **\  Z       o        |
|        |\       \      |   *\\/       /|        |
|        | \       \     |    \\\      / |        |
|        |  \       \    |    /\\\    /  |        |
|        |   \       \   |   /  \\\  /   |        |
|        |    \       \  |  /    \\\/    |        |
|        |     \       \ | /      \/\    |        |
|        |   *  \       \|/       /\\*   |        |
|        X   *   Y       o       Y  \*   Z        |
|         \  *   |               |   *  /         |
|          \ G   |               |   H /          |
|           \    |               |    /           |
|            \   |               |   /            |
|             \  |               |  /             |
|              \ |               | /              |
|               \|               |/               |
|                o               o                |
|                                                 |
o-------------------------------------------------o
Figure 5.  Tacit Extension of H to X x Y x Z


A geometric interpretation can now be given that fleshes out in graphic form the meaning of a formula like the following:

• ${\displaystyle F(x,y,z)=G(x,y)\land H(y,z).}$

The conjunction that is indicated by "${\displaystyle \land }$" corresponds as usual to an intersection of two sets, however, in this case it is the intersection of the tacit extensions te(G) and te(H).

o-------------------------------------------------o
|                                                 |
|                        o                        |
|                       /|\                       |
|                      / | \                      |
|                     /  |  \                     |
|                    /   |   \                    |
|                   /    |    \                   |
|                  /     |     \                  |
|                 /      |      \                 |
|                o       o       o                |
|                |\     / \     /|                |
|                | \   / F \   / |                |
|                |  \ /  *  \ /  |                |
|                |   \  /*\  /   |                |
|                |  / \//*\\/ \  |                |
|                | /  /\/ \/\  \ |                |
|                |/  ///\ /\\\  \|                |
|        o       X  ///  Y  \\\  Z       o        |
|        |\       \///   |   \\\/       /|        |
|        | \      ///    |    \\\      / |        |
|        |  \    ///\    |    /\\\    /  |        |
|        |   \  ///  \   |   /  \\\  /   |        |
|        |    \///    \  |  /    \\\/    |        |
|        |    /\/      \ | /      \/\    |        |
|        |   *//\       \|/       /\\*   |        |
|        X   */  Y       o       Y  \*   Z        |
|         \  *   |               |   *  /         |
|          \ G   |               |   H /          |
|           \    |               |    /           |
|            \   |               |   /            |
|             \  |               |  /             |
|              \ |               | /              |
|               \|               |/               |
|                o               o                |
|                                                 |
o-------------------------------------------------o
Figure 6.  F as the Intersection of te(G) and te(H)


## Algebraic construction

The transition from a geometric picture of relation composition to an algebraic formulation is accomplished through the introduction of coordinates, in other words, identifiable names for the objects that are related through the various forms of relations, 2-adic and 3-adic in the present case. Adding coordinates to the running Example produces the following Figure:

o-------------------------------------------------o
|                                                 |
|                        o                        |
|                       /|\                       |
|                      / | \                      |
|                     /  |  \                     |
|                    /   |   \                    |
|                   /    |    \                   |
|                  /     |     \                  |
|                 /      |      \                 |
|                o       o       o                |
|                |\     / \     /|                |
|                | \   / F \   / |                |
|                |  \ /  *  \ /  |                |
|                |   \  /*\  /   |                |
|                |  / \//*\\/ \  |                |
|                | /  /\/ \/\  \ |                |
|                |/  ///\ /\\\  \|                |
|        o       X  ///  Y  \\\  Z       o        |
|        |\      7\///   |   \\\/7      /|        |
|        | \      6//    |    \\6      / |        |
|        |  \    //5\    |    /5\\    /  |        |
|        |   \  /// 4\   |   /4 \\\  /   |        |
|        |    \///   3\  |  /3   \\\/    |        |
|        |   G/\/     2\ | /2     \/\H   |        |
|        |   *//\      1\|/1      /\\*   |        |
|        X   *\  Y       o       Y  /*   Z        |
|        7\  *\\ |7             7| //*  /7        |
|         6\ |\\\|6             6|///| /6         |
|          5\| \\@5             5@// |/5          |
|           4@  \@4             4@/  @4           |
|            3\  @3             3@  /3            |
|             2\ |2             2| /2             |
|              1\|1             1|/1              |
|                o               o                |
|                                                 |
o-------------------------------------------------o
Figure 7.  F as the Intersection of te(G) and te(H)


Thinking of relations in operational terms is facilitated by using a variant notation for tuples and sets of tuples, namely, the ordered pair (xy) is written x:y, the ordered triple (xyz) is written x:y:z, and so on, and a set of tuples is conceived as a logical-algebraic sum, which can be written out in the smaller finite cases in forms like a:b + b:c + c:d and so on.

For example, translating the relations F ⊆ X × Y × Z, G ⊆ X × Y, H ⊆ Y × Z into this notation produces the following summary of the data:

${\displaystyle {\begin{matrix}F&=&4:3:4&+&4:4:4&+&4:5:4\\G&=&4:3&+&4:4&+&4:5\\H&=&3:4&+&4:4&+&5:4\end{matrix}}}$

As often happens with abstract notations for functions and relations, the type information, in this case, the fact that G and H live in different spaces, is left implicit in the context of use.

Let us now verify that all of the proposed definitions, formulas, and other relationships check out against the concrete data of the current composition example. The ultimate goal is to develop a clearer picture of what is going on in the formula that expresses the relational composition of a couple of 2-adic relations in terms of the medial projection of the intersection of their tacit extensions:

${\displaystyle G\circ H=proj_{XZ}(te_{XY}^{Z}(G)\cap te_{YZ}^{X}(H)).}$

Here is the big picture, with all of the pieces in place:

o-------------------------------------------------o
|                                                 |
|                        o                        |
|                       / \                       |
|                      /   \                      |
|                     /     \                     |
|                    /       \                    |
|                   /         \                   |
|                  /           \                  |
|                 /    G o H    \                 |
|                X       *       Z                |
|                7\     /|\     /7                |
|                 6\   / | \   /6                 |
|                  5\ /  |  \ /5                  |
|                   4@   |   @4                   |
|                    3\  |  /3                    |
|                     2\ | /2                     |
|                      1\|/1                      |
|                        |                        |
|                        |                        |
|                        |                        |
|                       /|\                       |
|                      / | \                      |
|                     /  |  \                     |
|                    /   |   \                    |
|                   /    |    \                   |
|                  /     |     \                  |
|                 /      |      \                 |
|                o       |       o                |
|                |\     /|\     /|                |
|                | \   / F \   / |                |
|                |  \ /  *  \ /  |                |
|                |   \  /*\  /   |                |
|                |  / \//*\\/ \  |                |
|                | /  /\/ \/\  \ |                |
|                |/  ///\ /\\\  \|                |
|        o       X  ///  Y  \\\  Z       o        |
|        |\       \///   |   \\\/       /|        |
|        | \      ///    |    \\\      / |        |
|        |  \    ///\    |    /\\\    /  |        |
|        |   \  ///  \   |   /  \\\  /   |        |
|        |    \///    \  |  /    \\\/    |        |
|        |   G/\/      \ | /      \/\H   |        |
|        |   *//\       \|/       /\\*   |        |
|        X   *\  Y       o       Y  /*   Z        |
|        7\  *\\ |7             7| //*  /7        |
|         6\ |\\\|6             6|///| /6         |
|          5\| \\@5             5@// |/5          |
|           4@  \@4             4@/  @4           |
|            3\  @3             3@  /3            |
|             2\ |2             2| /2             |
|              1\|1             1|/1              |
|                o               o                |
|                                                 |
o-------------------------------------------------o
Figure 8.  G o H  =  proj_XZ (te(G) |^| te(H))


All that remains is to check the following collection of data and derivations against the situation represented in Figure 8.

${\displaystyle {\begin{matrix}F&=&4:3:4&+&4:4:4&+&4:5:4\\G&=&4:3&+&4:4&+&4:5\\H&=&3:4&+&4:4&+&5:4\end{matrix}}}$
${\displaystyle {\begin{matrix}G\circ H&=&(4:3+4:4+4:5)(3:4+4:4+5:4)\\\ &=&4:4\end{matrix}}}$
${\displaystyle {\begin{matrix}te(G)&=&te_{XY}^{Z}(G)\\\ &=&\sum _{z=1}^{7}(4:3:z+4:4:z+4:5:z)\end{matrix}}}$
${\displaystyle {\begin{matrix}te(G)&=&4:3:1&+&4:4:1&+&4:5:1&+\\\ &&4:3:2&+&4:4:2&+&4:5:2&+\\\ &&4:3:3&+&4:4:3&+&4:5:3&+\\\ &&4:3:4&+&4:4:4&+&4:5:4&+\\\ &&4:3:5&+&4:4:5&+&4:5:5&+\\\ &&4:3:6&+&4:4:6&+&4:5:6&+\\\ &&4:3:7&+&4:4:7&+&4:5:7\end{matrix}}}$
${\displaystyle {\begin{matrix}te(H)&=&te_{YZ}^{X}(H)\\\ &=&\sum _{x=1}^{7}(x:3:4+x:4:4+x:5:4)\end{matrix}}}$
${\displaystyle {\begin{matrix}te(H)&=&1:3:4&+&1:4:4&+&1:5:4&+\\\ &&2:3:4&+&2:4:4&+&2:5:4&+\\\ &&3:3:4&+&3:4:4&+&3:5:4&+\\\ &&4:3:4&+&4:4:4&+&4:5:4&+\\\ &&5:3:4&+&5:4:4&+&5:5:4&+\\\ &&6:3:4&+&6:4:4&+&6:5:4&+\\\ &&7:3:4&+&7:4:4&+&7:5:4\end{matrix}}}$
 ${\displaystyle te(G)\cap te(H)}$ ${\displaystyle =\;}$ ${\displaystyle 4:3:4\ +\ 4:4:4\ +\ 4:5:4}$ ${\displaystyle G\circ H}$ ${\displaystyle =\;}$ ${\displaystyle proj_{XZ}(te(G)\cap te(H))}$ ${\displaystyle =\;}$ ${\displaystyle proj_{XZ}(4:3:4\ +\ 4:4:4\ +\ 4:5:4)}$ ${\displaystyle =\;}$ ${\displaystyle 4:4\;}$

## Matrix representation

We have it within our reach to pick up another way of representing 2-adic relations, namely, the representation as logical matrices, and also to grasp the analogy between relational composition and ordinary matrix multiplication as it appears in linear algebra.

First of all, while we still have the data of a very simple concrete case in mind, let us reflect on what we did in our last Example in order to find the composition G o H of the 2-adic relations G and H.

Here is the setup that we had before:

${\displaystyle {\begin{matrix}X&=&\{1,\ 2,\ 3,\ 4,\ 5,\ 6,\ 7\}\end{matrix}}}$
${\displaystyle {\begin{matrix}G&=&4:3&+&4:4&+&4:5&\subseteq &X\times X\\H&=&3:4&+&4:4&+&5:4&\subseteq &X\times X\end{matrix}}}$

Let us recall the rule for finding the relational composition of a pair of 2-adic relations. Given the 2-adic relations P ⊆ X × Y, Q ⊆ Y × Z, the relational composition of P and Q, in that order, is written as P o Q or more simply as PQ and obtained as follows:

To compute PQ, in general, where P and Q are 2-adic relations, simply multiply out the two sums in the ordinary distributive algebraic way, but subject to the following rule for finding the product of two elementary relations of shapes a:b and c:d.

${\displaystyle {\begin{matrix}(a:b)(c:d)&=&(a:d)&{\mbox{if }}b=c\\(a:b)(c:d)&=&0&{\mbox{otherwise}}\end{matrix}}}$

To find the relational composition G o H, we write it as a quasi-algebraic product:

${\displaystyle {\begin{matrix}G\circ H&=&(4:3+4:4+4:5)(3:4+4:4+5:4)\end{matrix}}}$

Multiplying this out in accord with the applicable form of distributive law one obtains the following expansion:

${\displaystyle {\begin{matrix}G\circ H&=&(4:3)(3:4)&+&(4:3)(4:4)&+&(4:3)(5:4)&+\\\ &&(4:4)(3:4)&+&(4:4)(4:4)&+&(4:4)(5:4)&+\\\ &&(4:5)(3:4)&+&(4:5)(4:4)&+&(4:5)(5:4)\end{matrix}}}$

Applying the rule that determines the product of elementary relations produces the following array:

${\displaystyle {\begin{matrix}G\circ H&=&(4:4)&+&0&+&0&+\\\ &&0&+&(4:4)&+&0&+\\\ &&0&+&0&+&(4:4)\\\end{matrix}}}$

Since the plus sign in this context represents an operation of logical disjunction or set-theoretic aggregation, all of the positive multiplicites count as one, and this gives the ultimate result:

${\displaystyle {\begin{matrix}G\circ H&=&4:4\end{matrix}}}$

With an eye toward extracting a general formula for relation composition, viewed here on analogy to algebraic multiplication, let us examine what we did in multiplying the 2-adic relations G and H together to obtain their relational composite G o H.

Given the space X = {1, 2, 3, 4, 5, 6, 7}, whose cardinality |X| is 7, we naturally observe that there are |X × X| = |X| · |X| = 7 · 7 = 49 elementary relations of the form i:j, where i and j range over the space X. Although they might be organized in many different ways, it is convenient to regard the collection of elementary relations as being arranged in a lexicographic block of the following form:

${\displaystyle {\begin{matrix}1:1&1:2&1:3&1:4&1:5&1:6&1:7\\2:1&2:2&2:3&2:4&2:5&2:6&2:7\\3:1&3:2&3:3&3:4&3:5&3:6&3:7\\4:1&4:2&4:3&4:4&4:5&4:6&4:7\\5:1&5:2&5:3&5:4&5:5&5:6&5:7\\6:1&6:2&6:3&6:4&6:5&6:6&6:7\\7:1&7:2&7:3&7:4&7:5&7:6&7:7\end{matrix}}}$

The relations G and H may then be regarded as logical sums of the following forms:

${\displaystyle G=\sum _{ij}G_{ij}(i:j)\!}$
${\displaystyle H=\sum _{ij}H_{ij}(i:j)\!}$

The notation ${\displaystyle {\begin{matrix}\sum _{ij}\end{matrix}}}$ indicates a logical sum over the collection of elementary relations ${\displaystyle i:j\!}$, while the factors ${\displaystyle G_{ij}\!}$ and ${\displaystyle H_{ij}\!}$ are values in the boolean domain B = {0, 1} that are known as the coefficients of the relations G and H, respectively, with regard to the corresponding elementary relations ${\displaystyle i:j\!}$.

In general, for a 2-adic relation L, the coefficient Lij of the elementary relation i:j in the relation L will be 0 or 1, respectively, as i:j is excluded from or included in L.

With these conventions in place, the expansions of G and H may be written out as follows:

${\displaystyle G\ =\ 4:3\ +\ 4:4\ +\ 4:5\ =}$
 0(1:1) + 0(1:2) + 0(1:3) + 0(1:4) + 0(1:5) + 0(1:6) + 0(1:7) + 0(2:1) + 0(2:2) + 0(2:3) + 0(2:4) + 0(2:5) + 0(2:6) + 0(2:7) + 0(3:1) + 0(3:2) + 0(3:3) + 0(3:4) + 0(3:5) + 0(3:6) + 0(3:7) + 0(4:1) + 0(4:2) + 1(4:3) + 1(4:4) + 1(4:5) + 0(4:6) + 0(4:7) + 0(5:1) + 0(5:2) + 0(5:3) + 0(5:4) + 0(5:5) + 0(5:6) + 0(5:7) + 0(6:1) + 0(6:2) + 0(6:3) + 0(6:4) + 0(6:5) + 0(6:6) + 0(6:7) + 0(7:1) + 0(7:2) + 0(7:3) + 0(7:4) + 0(7:5) + 0(7:6) + 0(7:7)
${\displaystyle H\ =\ 3:4\ +\ 4:4\ +\ 5:4\ =}$
 0(1:1) + 0(1:2) + 0(1:3) + 0(1:4) + 0(1:5) + 0(1:6) + 0(1:7) + 0(2:1) + 0(2:2) + 0(2:3) + 0(2:4) + 0(2:5) + 0(2:6) + 0(2:7) + 0(3:1) + 0(3:2) + 0(3:3) + 1(3:4) + 0(3:5) + 0(3:6) + 0(3:7) + 0(4:1) + 0(4:2) + 0(4:3) + 1(4:4) + 0(4:5) + 0(4:6) + 0(4:7) + 0(5:1) + 0(5:2) + 0(5:3) + 1(5:4) + 0(5:5) + 0(5:6) + 0(5:7) + 0(6:1) + 0(6:2) + 0(6:3) + 0(6:4) + 0(6:5) + 0(6:6) + 0(6:7) + 0(7:1) + 0(7:2) + 0(7:3) + 0(7:4) + 0(7:5) + 0(7:6) + 0(7:7)

Stripping down to the bare essentials, one obtains the matrices of coefficients for the relations G and H:

${\displaystyle G\ =\!}$
${\displaystyle {\begin{matrix}0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&1&1&1&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\end{matrix}}}$
${\displaystyle H\ =\!}$
${\displaystyle {\begin{matrix}0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&1&0&0&0\\0&0&0&1&0&0&0\\0&0&0&1&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\end{matrix}}}$

These are the logical matrix representations of the 2-adic relations G and H.

If the 2-adic relations G and H are viewed as logical sums, then their relational composition G o H can be regarded as a product of sums, a fact that can be indicated as follows:

${\displaystyle G\circ H=(\sum _{ij}G_{ij}(i:j))(\sum _{ij}H_{ij}(i:j)).}$

The composite relation G o H is itself a 2-adic relation over the same space X, in other words, G o H ⊆ X × X, and this means that G o H must be amenable to being written as a logical sum of the following form:

${\displaystyle G\circ H=\sum _{ij}(G\circ H)_{ij}(i:j).}$

In this formula, ${\displaystyle (G\circ H)_{ij}}$ is the coefficient of ${\displaystyle G\circ H}$ with respect to the elementary relation ${\displaystyle i:j\!}$.

One of the best ways to reason out what ${\displaystyle G\circ H}$ should be is to ask oneself what its coefficient ${\displaystyle (G\circ H)_{ij}}$ should be for each of the elementary relations ${\displaystyle i:j\!}$ in turn.

So let us pose the question:

${\displaystyle (G\circ H)_{ij}\ =\ ?}$

In order to answer this question, it helps to realize that the indicated product given above can be written in the following equivalent form:

${\displaystyle G\circ H=(\sum _{ik}G_{ik}(i:k))(\sum _{kj}H_{kj}(k:j)).}$

A moment's thought will tell us that ${\displaystyle (G\circ H)_{ij}}$ = 1 if and only if there is an element k in X such that ${\displaystyle G_{ik}=1{\mbox{ and }}H_{kj}=1}$.

Consequently, we have the result:

${\displaystyle (G\circ H)_{ij}=\sum _{k}(G_{ik}H_{kj}).}$

This follows from the properties of boolean arithmetic, specifically, from the fact that the product ${\displaystyle G_{ik}H_{kj}}$ is 1 if and only if both ${\displaystyle G_{ik}}$ and ${\displaystyle H_{kj}}$ are 1, and from the fact that ${\displaystyle {\begin{matrix}\sum _{k}F_{k}\end{matrix}}}$ is equal to 1 just in case some ${\displaystyle F_{k}}$ is 1.

All that remains in order to obtain a computational formula for the relational composite ${\displaystyle G\circ H}$ of the 2-adic relations G and H is to collect the coefficients ${\displaystyle (G\circ H)_{ij}}$ over the appropriate basis of elementary relations ${\displaystyle i:j}$, as i and j range through X.

${\displaystyle G\circ H=\sum _{ij}(G\circ H)_{ij}(i:j)=\sum _{ij}(\sum _{k}(G_{ik}H_{kj}))(i:j).}$

This is the logical analogue of matrix multiplication in linear algebra, the difference in the logical setting being that all of the operations performed on coefficients take place in a system of boolean arithmetic where summation corresponds to logical disjunction and multiplication corresponds to logical conjunction.

By way of disentangling this formula, one may notice that the form Sum_k (G_ik H_kj) is what is usually called a "scalar product". In this case it is the scalar product of the i^th row of G with the j^th column of H.

To make this statement more concrete, let us go back to the particular examples of G and H that we came in with:

${\displaystyle G\ =\!}$
${\displaystyle {\begin{matrix}0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&1&1&1&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\end{matrix}}}$
${\displaystyle H\ =\!}$
${\displaystyle {\begin{matrix}0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&1&0&0&0\\0&0&0&1&0&0&0\\0&0&0&1&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\end{matrix}}}$

The formula for computing G o H says the following:

 ${\displaystyle (G\circ H)_{ij}}$ ${\displaystyle =\!}$ the ${\displaystyle ij}$th entry in the matrix representation for ${\displaystyle G\circ H}$ ${\displaystyle =\!}$ the entry in the ${\displaystyle i}$th row and the ${\displaystyle j}$th column of ${\displaystyle G\circ H}$ ${\displaystyle =\!}$ the scalar product of the ${\displaystyle i}$th row of ${\displaystyle G\!}$ with the ${\displaystyle j}$th column of ${\displaystyle H\!}$ ${\displaystyle =\!}$ ${\displaystyle {\begin{matrix}\sum _{k}(G_{ik}H_{kj})\end{matrix}}}$

As it happens, it is possible to make exceedingly light work of this example, since there is only one row of G and one column of H that are not all zeroes. Taking the scalar product, in a logical way, of the fourth row of G with the fourth column of H produces the sole non-zero entry for the matrix of G o H.

${\displaystyle G\circ H\ =}$
${\displaystyle {\begin{matrix}0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&1&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\\0&0&0&0&0&0&0\end{matrix}}}$

## Graph-theoretic picture

There is another form of representation for 2-adic relations that is useful to keep in mind, especially for its ability to render the logic of many complex formulas almost instantly understandable to the mind's eye. This is the representation in terms of bipartite graphs, or bigraphs for short.

Here is what G and H look like in the bigraph picture:

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|                /|\                    |
|               / | \              G    |
|              /  |  \                  |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 9.  G = 4:3 + 4:4 + 4:5

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|              \  |  /                  |
|               \ | /              H    |
|                \|/                    |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 10.  H = 3:4 + 4:4 + 5:4


These graphs may be read to say:

• G puts 4 in relation to 3, 4, 5.
• H puts 3, 4, 5 in relation to 4.

To form the composite relation G o H, one simply follows the bigraph for G by the bigraph for H, here arranging the bigraphs in order down the page, and then treats any non-empty set of paths of length two between two nodes as being equivalent to a single directed edge between those nodes in the composite bigraph for G o H.

Here's how it looks in pictures:

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|                /|\                    |
|               / | \              G    |
|              /  |  \                  |
|     o   o   o   o   o   o   o    X    |
|              \  |  /                  |
|               \ | /              H    |
|                \|/                    |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 11.  G Followed By H

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|                 |                     |
|                 |              G o H  |
|                 |                     |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 12.  G Composed With H


Once again we find that G o H = 4:4.

We have now seen three different representations of 2-adic relations. If one has a strong preference for letters, or numbers, or pictures, then one may be tempted to take one or another of these as being canonical, but each of them will be found to have its peculiar advantages and disadvantages in any given application, and the maximum advantage is therefore approached by keeping all three of them in mind.

To see the promised utility of the bigraph picture of 2-adic relations, let us devise a slightly more complex example of a composition problem, and use it to illustrate the logic of the matrix multiplication formula.

Keeping to the same space ${\displaystyle X=\{1,\ 2,\ 3,\ 4,\ 5,\ 6,\ 7\},}$ define the 2-adic relations ${\displaystyle M,N\subseteq X\times X}$ as follows:

 M = 2:1 + 2:2 + 2:3 + 4:3 + 4:4 + 4:5 + 6:5 + 6:6 + 6:7 N = 1:1 + 2:1 + 3:3 + 4:3 + 4:5 + 5:5 + 6:7 + 7:7

Here are the bigraph pictures:

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|        /|\     /|\     /|\            |
|       / | \   / | \   / | \      M    |
|      /  |  \ /  |  \ /  |  \          |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|     |  /    |  / \  |    \  |         |
|     | /     | /   \ |     \ |    N    |
|     |/      |/     \|      \|         |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o


To form the composite relation M o N, one simply follows the bigraph for M by the bigraph for N, here arranging the bigraphs in order down the page, and then counts any non-empty set of paths of length two between two nodes as being equivalent to a single directed edge between those two nodes in the composite bigraph for M o N.

Here's how it looks in pictures:

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|        /|\     /|\     /|\            |
|       / | \   / | \   / | \      M    |
|      /  |  \ /  |  \ /  |  \          |
|     o   o   o   o   o   o   o    X    |
|     |  /    |  / \  |    \  |         |
|     | /     | /   \ |     \ |    N    |
|     |/      |/     \|      \|         |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 15.  M Followed By N

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|        / \     / \     / \            |
|       /   \   /   \   /   \    M o N  |
|      /     \ /     \ /     \          |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 16.  M Composed With N


Let us hark back to that mysterious matrix multiplication formula, and see how it appears in the light of the bigraph representation.

The coefficient of the composition M o N between i and j in X is given as follows:

${\displaystyle (M\circ N)_{ij}=\sum _{k}(M_{ik}N_{kj})}$

Graphically interpreted, this is a sum over paths. Starting at the node i, Mik being 1 indicates that there is an edge in the bigraph of M from node i to node k, and Nkj being 1 indicates that there is an edge in the bigraph of N from node k to node j. So the ${\displaystyle {\begin{matrix}\sum _{k}\end{matrix}}}$ ranges over all possible intermediaries k, ascending from 0 to 1 just as soon as there happens to be some path of length two between nodes i and j.

It is instructive at this point to compute the other possible composition that can be formed from M and N, namely, the composition N o M, that takes M and N in the opposite order. Here is the graphic computation:

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|     |  /    |  / \  |    \  |         |
|     | /     | /   \ |     \ |    N    |
|     |/      |/     \|      \|         |
|     o   o   o   o   o   o   o    X    |
|        /|\     /|\     /|\            |
|       / | \   / | \   / | \      M    |
|      /  |  \ /  |  \ /  |  \          |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 17.  N Followed By M

o---------------------------------------o
|                                       |
|     1   2   3   4   5   6   7         |
|     o   o   o   o   o   o   o    X    |
|                                       |
|                                N o M  |
|                                       |
|     o   o   o   o   o   o   o    X    |
|     1   2   3   4   5   6   7         |
|                                       |
o---------------------------------------o
Figure 18.  N Composed With M


This example affords sufficient evidence that relational composition, just like its kindred, matrix multiplication, constitutes a non-commutative algebraic operation.

## References

• Ulam, S.M. and Bednarek, A.R., "On the Theory of Relational Structures and Schemata for Parallel Computation" (1977), pp. 477-508 in A.R. Bednarek and Françoise Ulam (eds.), Analogies Between Analogies: The Mathematical Reports of S.M. Ulam and His Los Alamos Collaborators, University of California Press, Berkeley, CA, 1990.

## Bibliography

• Mili, A., Desharnais, J., Mili, F., with Frappier, M., Computer Program Construction, Oxford University Press, New York, NY, 1994. — Introduction to Tarskian relation theory and its applications within the relational programming paradigm.
• Ulam, S.M., Analogies Between Analogies: The Mathematical Reports of S.M. Ulam and His Los Alamos Collaborators, A.R. Bednarek and Françoise Ulam (eds.), University of California Press, Berkeley, CA, 1990.