Binary Relations Problems
Representing the Same Relation Three Ways
The same relation can be presented as a set of ordered pairs, as an arrow diagram, or as a relation matrix. In the matrix picture, rows are indexed by , columns by , and the entry in row column is 1 when and 0 otherwise. For with and , the matrix is a diagonal of ones marching one step above the main diagonal โ every row has a single 1, and every column has a single 1. That visual signature already tells you is a function (no repeated first components) and that its inverse is also a function (no repeated second components). Switching between representations is the fastest route to an answer: pairs for algebra, arrows for injectivity intuition, matrices for counting and composition.
Domain, Range and Codomain: Watch the Codomain
The example hides an exam trap worth naming. If the problem declares " is a relation on " with , then , so cannot be a subset of and is therefore not a relation on at all โ it is a relation from to a larger codomain such as . The domain is always a subset of the source set, but the range is a subset of the codomain, not of the source. Read the declared codomain before asserting anything about membership.
When Is the Inverse a Function?
The decision rule generalises cleanly. A relation is a function from to exactly when every element of appears as a first component of exactly one pair โ existence and uniqueness together, so the relation must be defined on all of and never split one input across two outputs. The inverse inherits the same test with the roles swapped: is a function precisely when no two pairs of share the same second component, which is the definition of injectivity wearing a different hat.
| Situation in | Is a function? | Is a function? |
|---|---|---|
| every appears once as a first component | yes | only if second components never repeat |
| some missing from all pairs | no โ not defined everywhere | depends on the second components alone |
| one paired with two different 's | no โ multiple outputs | automatically no, because the pairs collapse |
| second components all distinct | yes (if domain covered) | yes |
Counting Relations Without Listing Them
The exponent comes from independence: each of the candidate pairs is either in the relation or out, with no further constraints, so the subsets of โ and relations are exactly subsets โ number . Imposing properties shrinks the count in predictable ways. On an -element set, reflexivity forces all diagonal pairs in, leaving free choices: reflexive relations. Symmetry forces each off-diagonal pair to match its mirror, leaving one free choice per unordered pair plus the diagonal: symmetric relations. For both formulas give , while the count of relations that are reflexive and symmetric collapses to โ the three unordered off-diagonal pairs decide everything.
Composition of Relations Step by Step
Composition chains relations the way function composition chains functions, and it is associative: , because both sides record "follow a path of three edges". It is not commutative โ the example above gives while is empty, since no second component of matches a first component of . Domain and range also shift predictably: and , with equality holding when the middle sets line up completely.
R = {(1, 2), (2, 3), (3, 4), (4, 5)}
S = {(1, 2), (1, 3), (2, 4)}
def domain(rel):
return sorted({a for a, _ in rel})
def rng(rel):
return sorted({b for _, b in rel})
def inverse(rel):
return {(b, a) for a, b in rel}
def compose(first, second):
lookup = {}
for y, z in second:
lookup.setdefault(y, set()).add(z)
return {(x, z) for x, y in first for z in lookup.get(y, ())}
def is_function(rel, dom):
seen = {}
for a, b in rel:
if a in seen and seen[a] != b:
return False # one input, two outputs
seen[a] = b
return all(a in seen for a in dom) # every input must appear
print(domain(R), rng(R)) # [1, 2, 3, 4] [2, 3, 4, 5]
print(is_function(R, {1, 2, 3, 4})) # True
print(is_function(S, {1, 2})) # False: 1 maps to both 2 and 3
print(sorted(compose(R, inverse(R)))) # [(1, 1), (2, 2), (3, 3), (4, 4)]
The last line is instructive: composing with its own inverse lands on pairs for every in the domain of โ the relation behaves like a partial identity, exactly as the function-composition analogy predicts.
Properties Checklist: Reflexive, Symmetric, Transitive
Most exam problems on a finite relation ask for a property verdict. Reflexive means for every in the underlying set โ missing even one diagonal pair destroys it. Symmetric means implies , for every pair, checked by flipping each pair you have. Transitive means and in force ; the efficient test chains every second component back into the first-component lookup and confirms the shortcut pair exists. A relation that satisfies all three on a nonempty set is an equivalence relation, and the reflexive-and-symmetric count of 8 on a 3-set from the counting section lists precisely the seeds of the equivalence relations on that set.
def reflexive(rel, A):
return all((x, x) in rel for x in A)
def symmetric(rel):
return all((y, x) in rel for x, y in rel)
def transitive(rel):
pairs = set(rel)
lookup = {}
for x, y in rel:
lookup.setdefault(x, set()).add(y)
return all((x, z) in pairs
for x, y in rel for z in lookup.get(y, ()))
A = {1, 2, 3}
# reflexive and symmetric, but (1,2) chains with (2,3) while (1,3) is withheld
Rt = {(1, 1), (2, 2), (3, 3), (1, 2), (2, 1), (2, 3), (3, 2)}
print(reflexive(Rt, A), symmetric(Rt), transitive(Rt)) # True True False
full = {(i, j) for i in A for j in A}
print(reflexive(full, A), symmetric(full), transitive(full)) # True True True
The first verdict is the instructive one: carries every diagonal pair and mirrors every off-diagonal pair it contains, yet the chain followed by demands , which is absent. One missing shortcut pair is enough to destroy transitivity, and the checker's job is to name that witnessing chain.
Common Mistakes
Declaring a relation reflexive after spotting only the diagonal pairs that happen to be listed
Fix: Reflexivity quantifies over the entire underlying set: every single element needs its (a, a) pair, including ones that appear nowhere else in R.
Checking symmetry only on pairs you added deliberately, ignoring pairs produced by earlier steps
Fix: Flip every pair in the relation โ all of them โ and confirm the mirror is present; one unflipped pair breaks symmetry.
Reporting transitivity without producing the chain that fails it
Fix: Name the two pairs (a, b) and (b, c) and show the missing (a, c); if you cannot exhibit the chain, the relation is transitive on the given set.
Key Takeaways
- A relation is any subset of A times B; the domain collects first components, the range collects second components, and the range lives inside the codomain.
- R inverse simply swaps every pair; it is a function exactly when no two pairs of R share a second component.
- Relations count as subsets: 2 to the power |A||B| total, with reflexive, symmetric, and transitive constraints cutting the count in formulaic ways.
- Composition chains pairs through a shared middle element โ associative like function composition, never commutative, with domain and range inherited from the outer relations.