12–15 min read Relations, Mappings & Databases Lesson 9 / 32
Part 2 — Discrete Mathematics

Lesson 14.09 — Relations and Mappings

The Mathematical Foundation of Data Linkage & Transformation: Ordered Pairs, Cartesian Products, 4 Core Relation Properties, Equivalence & Posets, Injective/Surjective/Bijective Mappings, Inverse Functions, and Real-World Applications in Databases & AI

What We Will Master

The complete mathematical architecture powering relational databases (SQL joins), graph network routing, functional composition pipelines, and neural network layer transformations:

  • How relationships form between data entities & the student-course enrollment model
  • Ordered Pairs (a, b) and their critical contrast with unordered Sets
  • Cartesian Product (A × B) & cardinality calculation rules
  • Formal definition of Relations: R ⊆ A × B
  • Precise boundaries of Domain, Codomain, and Range
  • 4 primary representations: Ordered Pairs, Tables, Arrow Diagrams, and Matrices
  • Relations vs. Functions: Exact conditions that elevate a relation to a function
  • 4 fundamental relation properties: Reflexive, Symmetric, Antisymmetric, and Transitive
  • Equivalence Relations & modular congruence partitioning into Equivalence Classes
  • Partial Orders (Posets): Task dependencies and topological sorting in build systems
  • Taxonomy of Mappings: Injective (One-to-One), Surjective (Onto), and Bijective
  • Inverse Relations, Inverse Functions, and Function Composition (g ∘ f)
1

Introduction: How Relationships Form in Data

Imagine you are architecting a university-scale learning management system. Your platform hosts thousands of registered students and hundreds of specialized course modules. In real life, an individual student may enroll in multiple courses, and conversely, a single course inevitably contains multiple participating students.

This many-to-many relationship between students and courses is naturally represented in a relational table:

Student (Entity A) Enrolled Course (Entity B) Mathematical Ordered Pair
Rahim Python Programming (Rahim, Python)
Rahim Discrete Mathematics (Rahim, Mathematics)
Karim Python Programming (Karim, Python)
Salma Web Development (Salma, Web Development)
Salma Discrete Mathematics (Salma, Mathematics)

Here, a definitive linkage connects elements of the Student set to elements of the Course set. In mathematics, any such collection of associations between sets is formally termed a Relation. When a relation strictly adheres to the rule that every single input maps to exactly one deterministic output, it is called a Mapping or Function.

Foundational Role in Computer Science

Relational databases (SQL joins and relational algebra), Graph Theory (directed networks and reachability), Object-Oriented associations, build-system dependency graphs (DAGs), and Machine Learning transformation pipelines are all direct structural applications of mathematical relations and mappings.

2

Ordered Pairs

Before defining relations, we must establish the concept of an Ordered Pair. In ordinary set theory, the sequence of elements inside a set is completely irrelevant. In an Ordered Pair, however, the specific position or order of elements is paramount.

Standard Structure of an Ordered Pair: (a, b)

Here, a denotes the first coordinate (Abscissa / Domain element) and b denotes the second coordinate (Ordinate / Codomain element).

For instance, in the 2D Cartesian coordinate plane, the coordinate points (2, 5) and (5, 2) represent two entirely different spatial locations:

Unordered Set — Sequence is Arbitrary:
{ 2, 5 } = { 5, 2 }
Order of listing does not change set identity.
Ordered Pair — Sequence is Invariant:
( 2, 5 ) ≠ ( 5, 2 )
Swapping coordinates creates a distinct mathematical pair.

Equality Condition for Ordered Pairs:

(a, b) = (c, d)  ⇔  a = c  and  b = d

Two ordered pairs are equal if and only if their respective first components match and their second components match.

3

Cartesian Products

The universal set of all possible ordered pairs formed by taking the first element from set $A$ and the second element from set $B$ is termed the Cartesian Product, denoted $A imes B$.

A × B = { (a, b) ∣ a ∈ A, b ∈ B } Every element in A paired exhaustively with every element in B.

Concrete Example:

Let $A = \{1, 2\}$ and $B = \{a, b, c\}$. Then:

A × B = { (1, a), (1, b), (1, c), (2, a), (2, b), (2, c) }
B × A = { (a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2) }

Clearly, A × B ≠ B × A! The Cartesian product is non-commutative.

Cardinality Calculation Rule:

|A × B| = |A| × |B|

If set $A$ has $m$ elements and set $B$ has $n$ elements, their Cartesian product contains exactly $m \cdot n$ ordered pairs. Here, $|A|=2, |B|=3 \implies |A imes B| = 2 imes 3 = 6$.

4

What is a Relation?

While the Cartesian product $A imes B$ enumerates every theoretical link, real-world systems only exhibit specific meaningful connections. When a subset of these potential pairs satisfies a specific condition, it constitutes a Relation.

Formal Mathematical Definition
R ⊆ A × B

Any relation R from set A to set B is formally a subset of the Cartesian product A × B.

Mathematical Example:

Let $A = \{1, 2, 3\}$ and $B = \{2, 4, 6\}$. Define condition: “The second element is twice the first ($b = 2a$)”.

// Condition: b = 2a
R = { (1, 2), (2, 4), (3, 6) }

Here, $(1, 2) \in R$ because $2 = 2(1)$; but $(1, 4) otin R$. In general relations, an input may map to multiple outputs (e.g. $(1, a), (1, b)$) or may have no mapped output at all.

5

Domain, Codomain & Range

Rigorous analysis of any relation demands clear demarcation between three related sets:

Domain
{ a ∣ (a, b) ∈ R }

The set of all first coordinates actually participating in R.

Codomain
Designated Target Set B

The entire target set into which the relation maps, whether hit or not.

Range
{ b ∣ (a, b) ∈ R }

The set of all second coordinates actually mapped to in R (Range ⊆ Codomain).

Concrete Breakdown:
A = { 1, 2, 3, 4 },   B = { a, b, c, d }
R = { (1, a), (2, b), (2, c), (4, c) }
• Domain(R) = { 1, 2, 4 }  (3 omitted; not participating)
• Codomain(R) = { a, b, c, d }  (Entire set B)
• Range(R) = { a, b, c }  (d omitted; no incoming link)
6

4 Primary Representations of Relations

1. Ordered Pairs (Roster Form)

Direct set enumeration:

R = { (1, 2), (2, 4), (3, 6) }
2. Table (Database Relation)

Relational rows and foreign key columns:

col_A: [1, 2, 3] | col_B: [2, 4, 6]
3. Arrow Diagram (Mapping Visualizer)

Directed arrows linking Domain elements to Codomain elements, clearly illustrating many-to-one or one-to-many topologies.

4. Binary Relation Matrix (MR)

Bitmatrix memory layout where $M_R[i][j] = 1$ if $(i, j) \in R$ else $0$, foundational to graph algorithms.

7

Relations vs. Functions

The universal axiom of discrete mathematics is: “Every Function is a Relation, but not every Relation is a Function!” For a general relation to qualify as a valid function, it must satisfy two strict conditions:

Condition 1 (Total Domain Coverage): Every single element in Domain A must have at least one mapped output.
Condition 2 (Determinism / Single Output): No input can ever map to more than one output.
Property Relation Function
Multiple outputs for one input? ✓ Permitted (One-to-Many) ✗ Strictly forbidden
Unmapped input elements? ✓ Permitted (Partial relations) ✗ Forbidden on designated Domain
Multiple inputs sharing an output? ✓ Permitted ✓ Permitted (Many-to-One)
Subset of Cartesian Product? ✓ Yes (R ⊆ A × B) ✓ Yes (f ⊆ A × B)
8

Relations on a Set & 4 Core Relation Properties

When both coordinates of all ordered pairs originate from the identical set $A$ ($R \subseteq A imes A$), we term it a Relation on a Set. In discrete mathematics, four fundamental algebraic properties classify these relations:

1 Reflexive Property ∀a ∈ A, (a, a) ∈ R

Every element in set $A$ is related to itself. For $A=\{1, 2, 3\}$, relation $R$ must contain $(1,1), (2,2),$ and $(3,3)$.
Real-world examples: Equality ($a=a$), subset inclusion ($A \subseteq A$), parallel geometric lines.

2 Symmetric Property (a, b) ∈ R ⇒ (b, a) ∈ R

Whenever element $a$ relates to $b$, $b$ must symmetrically relate back to $a$ (two-way highway).
Real-world examples: Sibling relationships, mutual Facebook friends, undirected graph edges.

3 Antisymmetric Property (a, b) ∈ R ∧ (b, a) ∈ R ⇒ a = b

Two distinct elements can never relate bidirectionally. Mutual links are permitted only when elements are identical ($a=b$).
Real-world examples: Number ordering $a \le b$ ($a \le b \land b \le a \implies a=b$), subset inclusion ($A \subseteq B \land B \subseteq A \implies A=B$).

4 Transitive Property (a, b) ∈ R ∧ (b, c) ∈ R ⇒ (a, c) ∈ R

If a path leads from $a$ to $b$ and from $b$ to $c$, a direct transitive shortcut $(a, c)$ must exist.
Real-world examples: Ancestry trees, ordering inequalities ($a < b \land b < c \implies a < c$), transitive network reachability.

9

Equivalence Relations and Partial Orders (Posets)

Equivalence Relation

R + S + T

A relation satisfying Reflexive, Symmetric, and Transitive properties simultaneously.

Modulo Congruence: a ≡ b (mod 3)
[0] = { ..., -6, -3, 0, 3, 6, 9, ... }
[1] = { ..., -5, -2, 1, 4, 7, 10, ... }
[2] = { ..., -4, -1, 2, 5, 8, 11, ... }

Key insight: An Equivalence relation strictly partitions the underlying universe into mutually disjoint Equivalence Classes.

Partial Order (Poset)

R + AS + T

A relation satisfying Reflexive, Antisymmetric, and Transitive properties simultaneously.

Hierarchy & Dependency Lattices:
• ⊆ (Subset relation on Power Set)
• ≤ (Less than or equal on Real Numbers)
• Task Dependency DAGs in Build Systems

Key insight: Package managers (npm, pip, cargo) use Posets and topological sorting to resolve non-circular dependency build orders.

10

The 3 Primary Types of Mappings

When analyzing functions $f: A o B$, their structural linkage patterns categorize them into three fundamental classes:

Injective (One-to-One) Injective
f(a) = f(b) ⇒ a = b

Distinct domain inputs strictly produce distinct outputs. Collisions never occur.

Surjective (Onto) Surjective
Range(f) = Codomain(B)

Every element in the Codomain has at least one matching preimage. No output element is left unmapped.

Bijective (One-to-One & Onto) Bijective
Perfect Isomorphism

Both Injective and Surjective simultaneously. Creates a perfect bidirectional pairing, guaranteeing an Inverse Function ($f^{-1}$).

11

Inverse Functions and Function Composition

Inverse Functions

If $f: A o B$ is bijective, its unique inverse $f^{-1}: B o A$ reverses the mapping, retrieving the original input.

Original: f(x) = 2x + 3
Let y = 2x + 3 ⇒ x = (y - 3) / 2
Inverse: f-1(x) = (x - 3) / 2
Proof: f-1(f(x)) = ((2x+3)-3)/2 = x
Function Composition (g ∘ f)

Pipelining functions where the output of $f$ feeds as input to $g$: (g ∘ f)(x) = g(f(x)).

f(x) = 2x + 1,   g(x) = x2
(g ∘ f)(x) = g(2x + 1) = (2x + 1)2
(f ∘ g)(x) = f(x2) = 2x2 + 1
Caution: g ∘ f ≠ f ∘ g (Non-commutative)
12

Real-World Applications in Computer Science & AI

Relational Databases (RDBMS)

Codd's relational algebra implements mathematical relations. Foreign keys and Junction Tables model 1:1, 1:N, and M:N relationship subsets.

Graph Theory & Network Routing

Directed graphs $G = (V, E)$ are binary relations $E \subseteq V imes V$. Adjacency matrices, social network connections, and PageRank link graphs reflect binary relations.

Functional Programming & Pipelines

Python, JavaScript, and Rust map() functions implement mathematical mappings, and function composition forms Unix pipes (|).

AI & Deep Neural Networks

Multi-layer perceptrons are composite mappings: $y = f_L(\dots f_2(f_1(x))\dots)$. Knowledge graphs represent multi-relational entity embeddings.

13

Common Pitfalls in Relations & Mappings

Pitfall 1: Ignoring Order in Pairs

(1, 2) ≠ (2, 1). Directionality and set origin matter.

Pitfall 2: Equating Cartesian Products with Relations

Cartesian products include all possible pairs; relations are a selected subset.

Pitfall 3: Confusing Antisymmetry with Asymmetry

Antisymmetry does not forbid symmetric pairs—it mandates that if $(a,b)$ and $(b,a)$ exist, then $a$ must equal $b$.

Pitfall 4: Equating Codomain with Range

The Codomain is the entire target set $B$; Range consists strictly of output elements actually linked.

Pitfall 5: Assuming All Functions Have Inverses

Only bijective functions possess mathematically valid inverse functions.

Pitfall 6: Commuting Composition Order

(g ∘ f)(x) ≠ (f ∘ g)(x) in general. Function pipelines evaluate right-to-left.

14

Interactive Hands-on Workbench

Test relation properties in real-time, inspect mapping arrow diagrams, and simulate relational database joins across 3 dedicated interactive labs:

Relation on Set A = { 1, 2, 3 }

Click matrix cells to toggle (a, b) pairs or choose an axiomatic preset.

Binary Relation Matrix (MR)
b=1
b=2
b=3
a=1
a=2
a=3
R = { (1,1), (2,2), (3,3) }
Reflexive: All diagonal pairs (a, a) present
Yes ✓
Symmetric: Every (a, b) has matching (b, a)
Yes ✓
Antisymmetric: No symmetric links between distinct elements
Yes ✓
Transitive: (a, b) and (b, c) implies (a, c)
Yes ✓
Mathematical Classification: Equivalence Relation & Partial Order (Trivial Identity Poset)
15

Key Takeaways

Ordered Pair (a, b)

Order matters: (a, b) ≠ (b, a) unless components are identical.

Cartesian Product

A × B is the universal set of all pairs; size |A| × |B|.

Relation

R ⊆ A × B; any subset of the Cartesian product.

Domain & Range

Domain is active first components; Range is active second components.

Function Rule

Every domain element must map to exactly one deterministic output.

Equivalence Relation

Reflexive, Symmetric, and Transitive — partitions sets into equivalence classes.

Partial Order (Poset)

Reflexive, Antisymmetric, and Transitive — models dependency orderings.

Bijective & Inverses

Only mappings that are simultaneously Injective and Surjective have valid inverse functions.

Function Composition

(g ∘ f)(x) = g(f(x)); non-commutative execution pipelining.