1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! # Core Definitions for Mathematical Spaces
//!
//! This module lays the groundwork for representing various mathematical spaces
//! by defining a set of core traits. These traits abstract fundamental properties
//! and operations associated with topological spaces, metric spaces, normed spaces,
//! and inner product spaces. The hierarchy of these traits reflects the way these
//! mathematical structures build upon one another.
//!
//! ## Trait Hierarchy and Concepts
//!
//! 1. **[`Collection`]**: (Defined in `crate::set`) At the base, any space is a collection of items
//! (points). This trait provides basic operations like checking for containment and emptiness.
//!
//! 2. **[`Topology`]**: Extends [`Collection`]. A topological space is a set of points endowed with
//! a structure, called a topology, which allows defining concepts such as continuity,
//! connectedness, and convergence. This trait focuses on operations like finding neighborhoods
//! and computing boundaries of items within the space, crucial for algebraic topology operations
//! like homology (which uses [`Chain`]).
//!
//! 3. **[`MetricSpace`]**: Extends [`Collection`]. A metric space formalizes the concept of
//! distance between points. It introduces a `distance` function. Every metric space can induce a
//! topology (the metric topology), where open sets are defined using open balls.
//!
//! 4. **[`NormedSpace`]**: Extends [`MetricSpace`]. A normed space is a vector space where each
//! vector is assigned a length or "norm." The norm induces a metric, making every normed space a
//! metric space ($d(x,y) = ||x-y||$).
//!
//! 5. **[`InnerProductSpace`]**: Extends [`NormedSpace`]. An inner product space is a vector space
//! equipped with an inner product (or scalar product), which allows defining geometric notions
//! like angles and orthogonality. The inner product induces a norm ($||x|| = \sqrt{\langle x, x
//! \rangle}$), making every inner product space a normed space.
//!
//! ## Usage
//!
//! These traits are intended to be implemented by specific data structures that model these
//! mathematical spaces. For example, a struct representing a simplicial complex might implement
//! `Topology`, while a struct for Euclidean vectors might implement `InnerProductSpace`.
//! By programming against these traits, algorithms in geometry, topology, and related fields
//! can be written more generically.
//!
//! ## Future Considerations
//!
//! - The relationship between `MetricSpace` and `Topology` (a metric induces a topology) could be
//! further formalized, perhaps through blanket implementations or associated functions if a
//! `MetricSpace` is also to be treated as a `Topology` directly through its induced structure.
//! - Default implementations for relationships, e.g., a `MetricSpace` deriving its `Topology` from
//! its metric, or a `NormedSpace` deriving its `distance` function from its `norm`.
use Ring;
use crate::;
/// Defines the properties and operations of a topological space.
///
/// A topological space consists of a set of points (items) along with a topology,
/// which is a set of open sets satisfying certain axioms. This trait abstracts
/// operations on such spaces, particularly those relevant for constructing
/// chain complexes and computing homology.
///
/// It extends [`Collection`], indicating that a topological space is fundamentally
/// a collection of items.
///
/// # Type Parameters
///
/// The type implementing `Topology` is `Self`, representing the specific topological space.
/// `Self::Item` is the type of points or fundamental components (e.g., cells, simplices)
/// within the space.
// TODO: If a metric space is also a normed space, then it should implement both traits and have a
// default way to compute the distance between two points using the norm.
// TODO: Previously I had a trait for metric spaces that extended `TopologicalSpace`, but this
// was problematic because you really get a topology from the metric.
/// A trait for metric spaces.
///
/// A metric space is a set together with a notion of distance between points.
/// This trait extends `TopologicalSpace` by adding a distance function.
///
/// # Type Parameters
/// * `Distance` - The type used to represent distances between points
/// A trait for normed spaces.
///
/// A normed space is a vector space equipped with a norm function that assigns
/// a size to each vector. This trait extends `MetricSpace` by adding a norm function.
///
/// # Type Parameters
/// * `Norm` - The type used to represent the norm of a vector
/// A trait for inner product spaces.
///
/// An inner product space is a vector space equipped with an inner product operation
/// that allows for notions of angle and orthogonality. This trait extends `NormedSpace`
/// by adding an inner product function.
///
/// # Type Parameters
/// * `InnerProduct` - The type used to represent inner products