2.1 Binary Relations, Representations & Relational Matrix Algebra
π‘ Core Intuition: The 3-Second Mental Modelβ
π³ The Everyday Analogy: The Airline Flight Route Networkβ
Imagine an international airline operating flights between airports:
- The Cartesian Product (): If airport set contains departure cities
{London, Tokyo}and set contains arrivals{New York, Paris, Dubai}, the Cartesian product represents every theoretically imaginable flight path from any city in to any city in (all possible routes). - The Binary Relation (): The actual operating schedule of the airline is a subset of this theoretical maximum space. The airline might only fly
(London, New York)and(Tokyo, Paris). That scheduled subset is a binary relation! - The Inverse Relation (): The return flights! If an outbound flight flies from Tokyo to Paris, its inverse flies from Paris to Tokyo.
- Relational Composition (): Connecting flights with a layover! If flight takes you from London to New York, and domestic flight takes you from New York to San Francisco, the composite relation represents the end-to-end journey from London to San Francisco via the intermediate hub.
π» Bridging to Computer Science: Foreign Keys, Graph Databases & Adjacency Matricesβ
In computer science, relations are everywhere. In relational databases (RDBMS), tables model relations, and an INNER JOIN over primary-foreign key pairs is mathematically identical to relational composition. In graph databases and network routing protocols, relations are encoded as 0-1 Boolean adjacency matrices where matrix multiplication computes multi-hop reachability in time.
πTable of Contents
- π The Cartesian Product: Foundational Space of Ordered Pairs
- π Binary Relations: Subsets of the Cartesian Universe
- π Representations of Relations: Roster, Matrix & Digraph
- π Relation Complement, Inverse & Dual Invariants
- β‘ Composition of Relations & Boolean Matrix Multiplication
- π Real-World Engineering Context
- π Step-by-Step Worked Examples
- π― Exam & Interview Pitfall Check
π The Cartesian Product: Foundational Space of Ordered Pairsβ
Before defining a relation, we must define the combinatorial space from which relations are drawn: the Cartesian Product.
Let and be two arbitrary sets. The Cartesian product is the set of all ordered pairs such that the first coordinate belongs to and the second coordinate belongs to :
Foundational Properties of Cartesian Productsβ
- Non-Commutative Nature: In general, the Cartesian product is not commutative:
Concrete Witness: Let and .
- Since , .
- Distributivity over Union and Intersection:
- Monotonicity under Subsets:
π Binary Relations: Subsets of the Cartesian Universeβ
A binary relation from set to set is formally defined as any subset of their Cartesian product.
A relation from to is a subset of :
If , we write (read: " is related to by "). If , we write .
If and , the total number of distinct relations from to is:
Binary Relations on a Single Setβ
When , a subset is called a binary relation on set .
For a set containing elements:
- The Cartesian product has cardinality .
- The total number of possible binary relations on is:
- Smallest Relation: The empty relation ().
- Largest Relation: The universal relation ().
- Identity Relation: The diagonal relation ().
π Representations of Relations: Roster, Matrix & Digraphβ
To analyze and compute over relations efficiently, computer systems utilize three representations.
Matrix Representation (M_R) vs Directed Graph (Digraph)
Comparing computational bit-level matrix storage against visual structural graphs
0-1 Boolean Matrix (M_R)
- β’A binary matrix of size m Γ n where rows represent A and columns represent B.
- β’M_R[i, j] = 1 if (a_i, b_j) β R, and 0 if (a_i, b_j) β R.
- β’Enables O(1) membership lookup: check index M_R[i, j].
- β’Computes relational composition via hardware-accelerated Boolean matrix multiplication.
Directed Graph G = (V, E)
- β’Vertices V represent the elements of set A.
- β’A directed edge (arrow) extends from vertex a to vertex b if and only if (a, b) β R.
- β’Self-loops (a β a) immediately reveal diagonal reflexive pairs.
- β’Bidirectional arrows (a β b) visually expose symmetric pairings.
1. Roster Formβ
Explicit enumeration of all participating ordered pairs inside curly braces:
2. Zero-One Boolean Matrixβ
For and :
- The entry at Row 1, Column 3 is because .
- The entry at Row 2, Column 1 is because .
π Relation Complement, Inverse & Dual Invariantsβ
Like ordinary sets, relations support complementation and inversion operations.
Let . The complement of relation , denoted by or or , consists of all ordered pairs in that do not belong to :
In Boolean matrix form, the complement inverts every bit: .
Let . The inverse of relation , denoted by , is the relation from to formed by reversing the coordinates of every ordered pair in :
In Boolean matrix form, inversion corresponds exactly to the matrix transpose:
β‘ Composition of Relations & Boolean Matrix Multiplicationβ
The most powerful algebraic operation over relations is composition, which chains relationships across an intermediate bridge set.
Multi-Hop Relational Composition Pipeline (R β S)
Tracing path existence across intermediate set B to establish direct composite linkage
Relation R Linkage: (a, b) β R
Relation S Linkage: (b, c) β S
Composite Formation: (a, c) β (R β S)
Let and . The composite relation (also written in some functional notations; here we evaluate left-to-right: first, then ) is a relation from to defined by:
Computing Composition via Boolean Matrix Productβ
The matrix of the composite relation is the Boolean matrix product of and (denoted ). In Boolean matrix arithmetic, addition is logical OR () and multiplication is logical AND ():
An entry if and only if there exists at least one index such that row of and column of both have a .
Foundational Invariants of Relational Compositionβ
- Associativity:
- Non-Commutative: In general, .
- Reversal Law for Inverses:
π Real-World Engineering Contextβ
- Database Relational Calculus & SQL JOINs:
In SQL, an
INNER JOINmatches rows whereTableA.user_id = TableB.user_id. This query operation is literally computing the relational composition of two relations and . - Access Control Matrices (RBAC):
In cloud platforms, authorization uses composition:
- Relation : Maps Users to Roles (
User β Role). - Relation : Maps Roles to Permissions (
Role β Permission). - The composite relation computes effective user permissions (
User β Permission).
- Relation : Maps Users to Roles (
- Network Routing & Reachability: In IP networks, routing tables maintain binary adjacency relations. Squaring the adjacency matrix () yields all 2-hop reachable routers. Higher powers compute all -hop reachable nodes.
π Step-by-Step Worked Examplesβ
Example 1: Cartesian Product and Subset Countingβ
Problem Statement:
Let and .
- List all elements of in roster form.
- Determine the total number of binary relations from to .
- Determine how many of these relations contain exactly 3 ordered pairs.
Step-by-Step Solution:
- Constructing : Cardinality: .
- Total Number of Relations: Each relation is a subset of . By the power set formula:
- Relations Containing Exactly 3 Pairs: Selecting any 3 pairs out of the 6 available:
Key Takeaway:
Counting relations with specific cardinality bounds corresponds to choosing subsets of the Cartesian product using binomial coefficients .
Example 2: Matrix Representation and Inverse Derivationβ
Problem Statement:
Let and .
- Construct the 0-1 Boolean matrix .
- Derive the matrix and express in roster form.
- Compute the complement relation and state its cardinality.
Step-by-Step Solution:
- Constructing :
Rows and columns correspond to index order :
- Row 1: , ,
- Row 2: , ,
- Row 3: , ,
- Deriving via Transpose: Transposing rows into columns: Converting back to roster form:
- Computing the Complement : . Since , . Inverting the zeros in :
Key Takeaway:
The inverse relation corresponds directly to matrix transposition (), preserving cardinality while flipping directional flow.
Example 3: Relational Composition via Boolean Matrix Multiplicationβ
Problem Statement:
Let , and let relations and on be defined by:
Compute the composite relation using Boolean matrix multiplication.
Step-by-Step Solution:
- Construct Matrices and :
- Compute Boolean Matrix Product :
- Row 1:
- Col 1:
- Col 2:
- Col 3:
- Row 2:
- Col 1:
- Col 2:
- Col 3:
- Row 3:
- Col 1:
- Col 2:
- Col 3:
- Row 1:
- Convert Matrix to Roster Pairs:
Verification via direct chaining:
- and
- and
- and Both methods match.
Key Takeaway:
Boolean matrix multiplication implements relational composition without manual combinatorial backtracking across intermediate elements.
π― Exam & Interview Pitfall Checkβ
Question 1: "Why is the Cartesian product A Γ B not commutative, while |A Γ B| = |B Γ A| is commutative?"
Key Focus Points:
- Ordered Pair Asymmetry: The elements of are ordered pairs . In general, unless . Thus the set of ordered pairs is structurally distinct.
- Scalar Cardinality: The cardinality is the arithmetic product of two non-negative integers . Scalar multiplication over is commutative ().
- Implication: and are equivalent sets (), but not equal sets.
Question 2: "What is the reversal law for relational composition and why does it hold?"
Key Focus Points:
- Formula: . Notice the order of relations is reversed!
- Path Reversal Intuition: If a path goes from , then traveling backward from to requires first stepping backward through (), then stepping backward through ().
Trap 1: Is a relation from A to B the same as a relation from B to A?
Answer: No. A relation from to is a subset of , while a relation from to is a subset of . They represent completely different directional spaces unless .
Trap 2: Does an empty set have any relations?
Answer: Yes, exactly one! If , then . The number of relations on is . The only relation is the empty relation itself.