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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//! Foundational carrier, scalar, interval, and metric abstractions.
//!
//! [`Point`] is the bare carrier beneath every structure. [`Real`] and
//! [`ExactCmp`] describe analytical scalar behavior, while [`Interval`] and
//! [`Metric`] distinguish signed pseudo-Riemannian separation from genuine
//! metric-space distance.
use Zero;
use crate::;
use ;
/// An element of the carrier set of a manifold, group, or metric space.
///
/// The space of all values of a type `P: Point` is interpreted as a bare
/// set ā the underlying collection of elements on which the library's other
/// traits impose structure. `Point` itself asserts *only* set membership:
/// the ability to hold and duplicate an element. It makes no claim of
/// topology, smoothness, or dimension; those arrive (if at all) through
/// [`Chart`], [`Metric`], [`Group`], and their refinements.
///
/// The name reflects the common case ā points of a manifold ā but nothing
/// requires a `Point` type to be a manifold. A group with no compatible
/// manifold structure (the p-adic integers ā¤_p, say) is a perfectly good
/// `Point` type that implements [`Group`] but not [`Chart`]: an element of
/// a set carrying algebraic but not differential structure.
///
/// Equality is the only *meaningful* operation on a bare element ā whether
/// two elements are the same ā and it is mathematically an [`Eq`] relation.
/// The library nonetheless does not require `Eq` (or even `PartialEq`) as a
/// bound, because for the scalar types in practical use that equality is not
/// computably decidable; see [`Real`]. Equality is required only in the
/// `#[cfg(feature = "testing")]` certification layer, never for use.
///
/// [`Chart`]: crate::traits::Chart
/// [`Group`]: crate::traits::Group
/// [`Real`]: crate::traits::Real
/// A scalar field for use as the coordinate type of a Euclidean space.
///
/// Bundles the requirements that a scalar must satisfy to be usable
/// throughout diffable ā real arithmetic and debuggability.
///
/// # Note on equality
/// Mathematically the scalars model the real numbers, which have genuine
/// equality. Computationally they do not: any finite representation that
/// is also fast (`f64`, `f32`) cannot satisfy the field axioms exactly,
/// and its `PartialEq` is therefore necessarily a *tolerance relation* ā
/// see [`R64`]/[`R32`], which report equality up to a relative-or-absolute
/// epsilon. Such a relation is reflexive and symmetric but **not
/// transitive**: `a == b` and `b == c` do not imply `a == c`.
///
/// The library accommodates this rather than fighting it. Two consequences
/// an implementor should know:
///
/// - **The `check_*` invariants never chain equalities.** Every property
/// test performs a single comparison between a computed value and an
/// expected one; none relies on transitivity, so a tolerance-based
/// `PartialEq` is sound to use with them. Do not add checks that compare
/// `a` to `b`, then `b` to `c`, and infer `a` to `c` ā that inference is
/// invalid for the scalars this library is designed to run on.
///
/// - **Exact scalars get exact semantics for free.** A symbolic real, an
/// arbitrary-precision rational, or any type whose `PartialEq` is true
/// equality satisfies everything above trivially (a transitive relation
/// is in particular a non-chained one), and runs the same invariants with
/// genuine equality. Approximation is a property of the scalar you choose,
/// not an assumption baked into the trait hierarchy.
///
/// This is why equality is required only where it is actually exercised ā
/// in the `#[cfg(feature = "testing")]` invariants, via `PartialEq` bounds
/// on those methods ā and is deliberately **not** a structural bound on
/// [`Point`]. Points have mathematical equality; the library declines to
/// require a *computable* witness of it, because for the reals no faithful
/// one exists.
///
/// [`R64`]: crate::epsilon_metric::R64
/// [`R32`]: crate::epsilon_metric::R32
// Real multiplication is commutative
/// A real-number field: totally ordered, and its own involution fixed field
/// (`Fixed = Self`, so `conj = id`).
///
/// Implementors (`R64`, `R32`) carry a **tolerance** in their `PartialEq`/
/// `PartialOrd`: two values within a relative epsilon compare equal, so that
/// floating-point round-off doesn't fracture geometric equality. That tolerance
/// is deliberately **not transitive** (`a ā b` and `b ā c` does not give
/// `a ā c`), which is fine for equality testing but wrong for the strict,
/// transitive order an iterative algorithm needs to decide convergence ā hence
/// [`ExactCmp`], which recovers the genuine order from the sign bit instead of
/// the tolerant comparison.
// A real scalar is admitted once at its richest reflected scalar context.
// Weaker models (for example as a field) are selected from this
// closed graph rather than by reflecting the same Rust type under competing
// category labels.
/// The genuine, transitive ordering on a real-number type, independent of
/// whatever tolerance its `PartialOrd` may carry for equality testing ā
/// see [`Real`]'s doc comment on why that tolerance exists and why it is
/// deliberately not transitive. An iterative numerical algorithm's
/// convergence check needs the former: comparing against a
/// tolerance-relation order can report "not less than" forever once both
/// sides fall inside the tolerance band, regardless of which is truly
/// smaller.
///
/// Built entirely from operations `Real` already guarantees ā `Sub` and
/// `is_sign_negative` (via `num_traits::Float`, already required through
/// `RealNum`) ā with the same formula for every implementor, no
/// per-type override. `is_sign_negative` reads the sign bit directly
/// rather than going through `PartialEq`, exactly the same reasoning
/// `Complex::real_sqrt`'s branch relies on ā so it never sees `R64`/`R32`'s
/// deliberately fuzzy comparison, and the blanket below is sound for
/// every `Real` type without exception, including any brought in from
/// outside this crate.
///
/// [`Real`]: crate::traits::Real
/// A notion of distance on a manifold.
///
/// The space of all values of a type `P: Metric<R>` is interpreted as
/// a metric space ā a set `M` equipped with a distance function
/// `d: M Ć M ā R` satisfying:
/// - **Non-negativity**: `d(a, b) >= 0`
/// - **Identity of indiscernibles**: `d(a, a) = 0`
/// - **Symmetry**: `d(a, b) = d(b, a)`
/// - **Triangle inequality**: `d(a, c) <= d(a, b) + d(b, c)`
///
/// These are not enforced by the type system but are certified by
/// implementing this trait. The first three are verified empirically by
/// the `test_metric!` macro; the triangle inequality is omitted from
/// automated testing since it is numerically fragile to check near-degenerate,
/// nearly-collinear triples without a carefully tuned tolerance.
///
/// A metric is independent of any coordinate structure ā it requires
/// neither a [`Chart`] nor a [`Euclidean`] tangent space, only the ability
/// to measure distance between two points directly.
///
/// [`Chart`]: crate::traits::Chart
/// [`Euclidean`]: crate::traits::Euclidean
/// Embeds an [`Interval::R`] value into the interval-bearing scalar type.
///
/// Fields whose fixed field is real receive the canonical implementation via
/// [`Field::from_fixed`](crate::traits::Field::from_fixed).
/// A signed interval on a manifold ā the pseudo-Riemannian analogue of
/// [`Metric`]. Where `Metric` returns a non-negative distance, `Interval`
/// returns the *signed* squared interval s²(a,b): negative timelike,
/// zero null, positive spacelike (or your sign convention). No metric-space
/// axioms are claimed ā this is not a distance, it is the value of the
/// line element between two points along the connecting geodesic.