Function and Relation Composition
Function composition
Given functions and , function composition is written . If and , then .
The domain of is those in the domain of for which lies in the domain of .
Relation composition
Given relations and , their composition is:
We read as ” after ”: first follow from to some , then follow from to . The intermediate element is existentially quantified and does not appear in the result.
Partial functions as relations
A relation defines a (partial) function when:
That is, each is related to at most one . This is the univalence (or functional) property.
A relation uniquely defines a total function if additionally every has some with (the relation is left-total).
When mathematicians say “function” they typically mean a total function. A relation may give multiple answers for the same input; a partial function may give at most one; a total function gives exactly one.
| Property | Relation | Partial function | Total function |
|---|---|---|---|
| Univalued (at most one output) | Not required | Required | Required |
| Left-total (at least one output) | Not required | Not required | Required |
Composition of functions is a special case
If and are functions (univalued and left-total), then as defined by relation composition coincides with ordinary function composition. The existential quantification is equivalent to function application because is uniquely determined.
Joins as generalised composition
If we write in join notation, identifying the -component as the join column:
We see that joins are a generalisation of function composition. The generalisation works in two directions:
- Functions to relations: joins cope with relations that are not univalued (multiple outputs per input) and not left-total (some inputs have no output).
- Equi-join to natural join: generalises from joining on a positional column to joining on named attributes.
Example
Let represent enrolment, and represent who teaches each course. Then gives pairs: students and the lecturers of courses they take.
In SQL:
SELECT R.student, Q.lecturer
FROM R
JOIN Q ON R.course = Q.course;
If a student takes multiple courses, they appear with multiple lecturers. If a course has no lecturer (not left-total), the student for that course contributes no row to the result under an inner join.
Summary
- Function composition: .
- Relation composition: .
- Functions are univalued relations; total functions are also left-total.
- Function composition is a special case of relation composition.
- Joins () are a generalisation of relation composition, further generalised by named attributes and outer join variants.