-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are the real numbers a normed space? #89
Comments
There should be implementation of |
And yes real numbers form a normed space over multiple different norms. (I wouldn't call floating point numbers real numbers, but it is what it is.) |
Thanks for the answer, I'm glad that my question wasn't complete nonsense ... It turns out that the implementation in question was added in #86, only 13 days ago! Using the And since |
I believe this would prevent implementation for, e.g., |
Sorry for the late response! I came up with a simplified example where I think the aforementioned blanket implementation is missing: use alga::general::RealField;
use alga::linear::VectorSpace;
struct SomeStruct<S: RealField, V: VectorSpace<Field = S>> {
s: S,
v: V,
}
struct LimitedStruct<S: RealField> {
inner: SomeStruct<S, S>,
} This fails to compile:
I don't know how this could be implemented, but I think theoretically this should work, because anything that is a How could I make this work? In case you are wondering what my concrete application is, you can have a look at /~https://github.com/AudioSceneDescriptionFormat/asdfspline-rust/blob/master/src/monotonecubicspline.rs. |
I still think a blanket implementation would make sense (if it would be possible), but in the meantime, there is a work-around for my example above, just adding the "vector" requirement to the "scalar" type: struct LimitedStruct<S: RealField + VectorSpace<Field = S>> {
inner: SomeStruct<S, S>,
} To me, this looks a bit recursive ( In my actual use case this got a bit too complicated (I've not fully implemented it, so I don't know whether it would have actually worked), so I came up with an alternative approach: I just added a new type parameter |
Sorry for the comment-spam, but just after posting my previous comment, I've read https://blog.mgattozzi.dev/orphan-rules/, which explains a nice work-around to avoid the limitations of Rust's orphan rule. I've implemented this in my project and it works very well, for details see this commit: AudioSceneDescriptionFormat/asdfspline-rust@c75463a. Instead of providing a function multiple times (as in my above-mentioned work-around), the user creates a dummy struct (to have something to implement a trait on) and implements a trait (involving their dummy struct) for the type in question that should get a pub struct DummyVec3;
impl NormWrapper<DummyVec3> for Vec3 {
type Norm = f32;
fn norm(&self) -> Self::Norm {
self.norm()
}
} I think in my case this work-around is nicer than the function-passing work-around. There are very few situations where the dummy struct has to be specified with a turbofish (which is a little ugly), but most of the times, everything is deduced automatically. |
I'm very much not a mathematician, nor am I a Rust expert, so please forgive me if this is a silly question.
I'm working on a spline implementation which I will mostly use for 3D curves, but I would also like it to work for 2D curves and for 1D (I don't know if those can still be called "curves").
For 2D and 3D I'm using vector types from the
nalgebra
crate (which implement severalalga
traits).Since my implementation is supposed to work on any vector space that has a norm, I think it would make sense to use the
alga::linear::NormedSpace
trait bound.For the 1D case I could of course use a 1D vector from
nalgebra
, but I think it would be much nicer if I could also use a "normal" scalar type, like e.g.f64
.This doesn't work though, because
NormedSpace
doesn't seem to be implemented forf64
(it looks like it's only implemented forComplex<N>
).Now my question: are real numbers a normed space?
I would think so, but what do I know ...
If that makes at least some mathematical sense, would it be possible to implement
NormedSpace
for scalars?I'm thinking about something like this:
Or probably this should use
ComplexField
instead?The text was updated successfully, but these errors were encountered: