-
-
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
Is the Real trait is too broad? (or too specialized) #57
Comments
+1!!! This is related to my issue dimforge/nalgebra#503. I am trying to represent a qubit as a vector of 2 complex numbers, but that would mean that I can't use most functions, because almost all of them require passing a
This could be fixed by simply moving all but these 8 methods into a new trait However, I think that a better solution would be to group related methods into their own traits. For example, separate traits for trigonometry, hyperbolic trigonometry, logarithms, fractions/rounding, and sign. That way, library authors could require only the traits they use. For example: pub trait Complex:
...
+ Trigonometry # sin, cos, tan, plus reciprocals and inverses
+ HyperbolicTrigonometry # sinh, cosh, tanh, plus reciprocals and inverses
+ Logarighms # ln, log2, e, log2_e, ln_1p, etc.
{
... # Not much goes here (most is inherited)
}
pub trait Real:
...
+ Complex
+ Fractions # floor, ceil, round, etc.
+ Signed # signum, is_sign_positive, is_sign_negative
{
... # Not much goes here (most is inherited)
} (You would probably want to name the traits better than I have) The best part of this is that it would be 100% backwards compatible as the resulting interface for TL;DR Most methods of |
Actually I would even not have a specific number name. They could be arranged in whatever traits: transcendental, algebraic, ... (I am very bad at making this kind of naming and regrouping :-)). The vast majority of these functions which are applied to tuples of real numbers basically can implement all these functions (dual numbers or quaternions for example) so I would not have a naming for a specific kind of number. |
@mathintro I had considered that, but here's why I think it would be better to use separate traits. Let's say for example that I have a function that does some complex trigonometric operation using lots of The downside to this is that things might get a bit messy, though I'd want to look into how things would turn out in practice. Currently I'm experimenting with forking |
I completely agree. I was more thinking about not having explicitly a ComplexTrait because the name would be misleading. These operations can be applied on very different kind of numbers. |
Hey! Sorry for the late answer. I've not read this issue in-depth yet but I just wanted to tell that we agree this is an issue and that this is necessary for improving support of complex number in alga (and nalgebra). I will start studying the subject more closely next month. |
Hey! Just so you know, I've started working on better Complex support. Hopefully I'll have a PR open within the next few weeks. |
@sebcrozet Just curious, how do you plan to reconcile |
@Coder-256 Yes, this will be breaking change! I'm basically splitting the |
@sebcrozet You've got me interested now, I'm very curious to see what you're planning. Anyway here is my branch for now (in my own, separate project). I decided to fork into my own project because I plan to steer development away from just |
I think it would be beneficial to have traits for functions (exp, sin, pow, ...) that are separate from numbers (partialOrd, Signed, ...). For example, when one wants to use complex numbers (since ComplexNumbers are now implementing a lot of the alga traits now) it is not uniquely defined how to order them. Nevertheless it would be great to be able to have the exp, log, ... functions in a trait without requiring them to be ordered in any way. It would be an equivalent of the Num, NumOps trait of the num_trait crate.
What do you think?
The text was updated successfully, but these errors were encountered: