How would you feel about a general purpose/science math library

I was thinking of creating some library that would include a large amount of math objects, and a bunch of helper functions to use them together. It would contain for example : geometry-related objects (points, lines, polygons, planes), but also other stuff, like stuff from set theory, graph theory, etc...

Would that be a good idea ?

That is quite a broad scope…

existing crates: and

I took a look at those, but as you said, those don't have a scope this broad

I personally don't need one. Using many smaller crates works fine for me.


How I would go about developping such a library is that I would wait for users to request the feature they want (for example, someone asks for me to add quaternions, and I would do it for the next update)

You are aware of nalgebra?

If I had to assemble a team for the task of writing a science library, i'd start by collecting all things that it needs to cover.
Then figure out how to group and connect all of it.

Once that is figured out, writing can begin.

1 Like

hm nalgebra only seems to do stuff related to, well, algebra

It sounds like you want to create a "standard library" for doing mathematics. We already have crates which do a lot of the individual bits, but there's definitely value in combining their functionality all under one project.

Some solid crates I can think of:

  • petgraph for working with graphs
  • euclid for anything related to geometry, with a strong graphics influence
  • ndarray for a general-purpose matrix type (think numpy from Python)
  • csv for importing data from CSVs
  • plotters for data visualisation
  • nalgebra for linear algebra

This would be no small undertaking. Do you have any examples of what you're trying to achieve (possibly already implemented for other languages)? As far as I know, even languages that are used extensively for data science like Python don't have everything within a single library.


I don't have any other example of such a library (even though I'm sure there is). Yeah it would "kinda" be like a standard library, but it would also include some more obscure stuff like gyrovectors

You’d probably want to structure it as a set of interoperable crates, perhaps reexported by a wrapper crate for easy inclusion. That way you can pull in the efforts of existing, narrower projects. I think this is roughly how numpy/scipy are organized, for instance.


What about features ? one features for graphs, one for sets, one for algebra, one for non euclidean geometry, one for groups, etc...

There is maths-traits.

The most interoperable is to use traits instead of structs, and generics instead of standard types. This way anyone can use these traits for their structs or in addition to another crate...

Well maths-traits looks good but I've got some nice ideas it doesn't have

I've created a git repo for it in case anyone wants to join me on this

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.