Skip to content
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

Add traits for generic norms and distances. #121

Open
Nuramon27 opened this issue Aug 9, 2019 · 3 comments
Open

Add traits for generic norms and distances. #121

Nuramon27 opened this issue Aug 9, 2019 · 3 comments

Comments

@Nuramon27
Copy link

In many iterative numerical algorithms, one has to calculate the distance between a solution candidate and a reference value in order to check for convergence. But currently there is no trait which would enable the computation of such a distance generically.

There is Signed which provides an abs function, but this trait can only be implemented for types with a notion of signedness. The correct mathematical concept, however, are norms and metrics, with the latter being reasonable for basically any numeric type.

So I propose adding two traits, Norm and Distance, each with one method of the same name. The norm-function of the Norm trait returns the norm of a single value, the distance-function of the Distance trait returns the distance between two values.

In my branch dist I have written a draft of these traits and implemented them for the primitive numeric types.

@cuviper
Copy link
Member

cuviper commented Aug 30, 2019

It's a reasonable idea. Can you open it as a PR for discussion?

One thing to consider is that there are multiple possible definitions of norm, especially when more dimensions are added like in Complex<T>. e.g. Euclidean norm vs. Manhattan norm.

@JohnScience
Copy link

It's a reasonable idea. Can you open it as a PR for discussion?

One thing to consider is that there are multiple possible definitions of norm, especially when more dimensions are added like in Complex<T>. e.g. Euclidean norm vs. Manhattan norm.

Are you sure that it must be the responsibility of num-traits?
Creating another managed crate (for example, "num-maths-traits") which would contain category-, group-, field-, ring-, space-, and other more general traits sounds a better idea. In this case, trait inheritance from more general traits can be an opt-in feature enabled by default.

The problem is not even that num-traits may end up becoming too of a heavy dependency in attempts to fit all needs but that num-traits' purpose statement ("Numeric traits for generic mathematics in Rust"), would, in this case, become unclear to me and, perhaps, someone else.

@cuviper
Copy link
Member

cuviper commented Apr 22, 2020

Are you sure that it must be the responsibility of num-traits?

Not at all. If there are interested parties like yourself who want to explore this in a new crate (and not get bogged down in num-traits' conservative API), then feel free!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants