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 between sets and is a subset of the Cartesian product . If , we write .
A relation on set can be:
- Reflexive: .
- Symmetric: .
- Transitive: .
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 is a relation where every input has exactly one output.
- Injection (One-to-One): .
- Surjection (Onto): Range equals Codomain.
- 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 .
- Isomorphism: A bijective homomorphism.
A relation that is reflexive, symmetric, and transitive is known as what?
Pre-images and Images
For a subset , the Pre-image is .