General Topology
Topology is the study of properties that are preserved under continuous deformations, such as stretching and bending, but not tearing or gluing.
Metric Spaces
A metric space is a set with a distance function satisfying:
- Positivity: , and .
- Symmetry: .
- Triangle Inequality: .
python
1def check_metric_axioms(X, d):
2 for x in X:
3 for y in X:
4 # Positivity
5 if d(x, y) < 0: return False, "Negative distance"
6 if x != y and d(x, y) == 0: return False, "Zero distance for distinct points"
7 # Symmetry
8 if d(x, y) != d(y, x): return False, "Symmetry failed"
9 for z in X:
10 # Triangle Inequality
11 if d(x, z) > d(x, y) + d(y, z) + 1e-9:
12 return False, f"Triangle inequality failed for {x}, {y}, {z}"
13 return True, "Valid Metric"
14
15# Manhattan Distance
16def taxicab(p1, p2):
17 return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
18
19points = [(0,0), (1,1), (2,3), (10, 0)]
20print(f"Taxicab metric: {check_metric_axioms(points, taxicab)}")
21
22# Discrete Metric
23def discrete(p1, p2):
24 return 0 if p1 == p2 else 1
25
26print(f"Discrete metric: {check_metric_axioms(points, discrete)}")
Topological Spaces
A topological space is a set with a collection of subsets (the open sets) such that:
- and .
- Arbitrary unions of sets in are in .
- Finite intersections of sets in are in .
python
1def is_topology(X, tau):
2 X_set = set(X)
3 tau_sets = [set(s) for s in tau]
4
5 # Empty set and X
6 if set() not in tau_sets or X_set not in tau_sets:
7 return False, "Missing empty set or X"
8
9 # Finite Intersections
10 import itertools
11 for s1, s2 in itertools.combinations(tau_sets, 2):
12 if s1.intersection(s2) not in tau_sets:
13 return False, f"Intersection of {s1} and {s2} not in tau"
14
15 # Binary Unions (covers arbitrary unions for finite sets)
16 for s1, s2 in itertools.combinations(tau_sets, 2):
17 if s1.union(s2) not in tau_sets:
18 return False, f"Union of {s1} and {s2} not in tau"
19
20 return True, "Valid Topology"
21
22X = [1, 2, 3]
23indiscrete = [[], [1, 2, 3]]
24print(f"Indiscrete Topology: {is_topology(X, indiscrete)}")
25
26overlap = [[], [1], [2], [1, 2, 3]]
27print(f"Partial Overlap: {is_topology(X, overlap)}")
Continuity
A function is continuous if the preimage of every open set in is open in .
- Formally: is continuous if .
In a Metric Space, this is equivalent to the definition: is continuous at if:
In a discrete metric space, which sets are open?
Compactness and Connectedness
A space is compact if every open cover has a finite subcover. A space is connected if it cannot be partitioned into two disjoint non-empty open sets.