Search Knowledge

© 2026 LIBREUNI PROJECT

Relations, Functions, and Morphisms

Relations, Functions, and Morphisms

Mappings allow us to transition from static sets to dynamic interactions. They allow us to compare sets, group elements by shared properties, and transform data while preserving structure.

Binary Relations

A Binary Relation RR between sets AA and BB is a subset of the Cartesian product A×BA \times B. If (a,b)R(a, b) \in R, we write aRbaRb.

A relation RR on set AA can be:

  • Reflexive: aRaaRa.
  • Symmetric: aRb    bRaaRb \implies bRa.
  • Transitive: aRbbRc    aRcaRb \land bRc \implies aRc.
python
1def check_properties(elements, relation):
2 reflexive = all((e, e) in relation for e in elements)
3 symmetric = all((b, a) in relation for (a, b) in relation)
4 transitive = all((a, c) in relation
5 for (a, b1) in relation
6 for (b2, c) in relation if b1 == b2)
7 return {"Reflexive": reflexive, "Symmetric": symmetric, "Transitive": transitive}
8 
9S = {1, 2, 3}
10R = {(1, 1), (2, 2), (3, 3), (1, 2), (2, 1)}
11print(f"Set: {S}, Relation: {R}")
12print(f"Properties: {check_properties(S, R)}")

Equivalence Relations and Partitions

A relation that is reflexive, symmetric, and transitive is an Equivalence Relation. It partitions a set into disjoint Equivalence Classes.

python
1def get_equivalence_classes(elements, relation):
2 classes = []
3 seen = set()
4 for e in elements:
5 if e not in seen:
6 # Class [e] = {x | xRe}
7 cls = {x for x in elements if (x, e) in relation}
8 classes.append(cls)
9 seen.update(cls)
10 return classes
11 
12print(f"Equivalence Classes: {get_equivalence_classes(S, R)}")

Classification of Mappings

A function f:ABf: A \to B is a relation where every input has exactly one output.

  1. Injection (One-to-One): f(x)=f(y)    x=yf(x) = f(y) \implies x = y.
  2. Surjection (Onto): Range equals Codomain.
  3. Bijection: Both injective and surjective (invertible).
python
1def classify_function(domain, codomain, f_map):
2 # f_map is a dict {x: y}
3 injective = len(set(f_map.values())) == len(f_map)
4 surjective = set(f_map.values()) == codomain
5
6 if injective and surjective: return "Bijection"
7 if injective: return "Injection"
8 if surjective: return "Surjection"
9 return "General Function"
10 
11A = {1, 2, 3}
12B = {'a', 'b', 'c'}
13f = {1: 'a', 2: 'b', 3: 'c'}
14print(f"Function mapping: {f}")
15print(f"Classification: {classify_function(A, B, f)}")

Morphisms: Structural Preservation

In abstract algebra, we study functions that preserve operations:

  • Homomorphism: Preserves algebraic structure (f(ab)=f(a)f(b))(f(a \cdot b) = f(a) \cdot f(b)).
  • Isomorphism: A bijective homomorphism.

A relation that is reflexive, symmetric, and transitive is known as what?

Pre-images and Images

For a subset TBT \subseteq B, the Pre-image is f1(T)={xAf(x)T}f^{-1}(T) = \{x \in A \mid f(x) \in T\}.

If f: A -> B is an injection, and |A| = |B| is finite, what must f also be?

Next Module Graph Theory