savage
savage copied to clipboard
Potential improvements
Look into number-theory for faster primality and more number-theorectic functions (fastest in Rust as far as I know, the only short-coming is that it doesn't have sieving yet, although there are much faster ways to count primes).
List some of the functions/functionality you are looking for below. I've done a little bit of work in this, so there is a good chance I've already written it before or have some familiarity with it.
It looks like you implemented your own multi-precision arithmetic system. That's cool, but why didn't you use num
? All numbers in Savage are stored as num
types, so different base types don't really work for me.
I also care a lot about code quality and reliability. Looking at the number-theory
codebase in its current form, there are far too few tests considering the breadth of functionality it implements, no benchmarks (despite making strong claims about its performance), no CI, meaningless commit messages, missing documentation, and the code isn't even formatted properly. That's a non-starter for me. By contrast, num
has thousands of tests, benchmarks, fuzzing, sophisticated CI, and highly detailed documentation. Those things are much, much more important to me than having cutting-edge performance, or algorithms implementing the latest advances from theoretical research.
I suspect we simply have different philosophical approaches to the systems we are building, which was already evident from our exchange on Reddit yesterday. And that's fine. And to be clear, I believe there is a lot of value in software that focuses on the fastest and most optimal way of doing something. But Savage isn't that kind of software. It aims to be a better calculator, perhaps a better Python for some tasks, a tool for doing everyday math, targeting engineers, students, and scientists – not research mathematicians pushing the boundaries of what computers can compute.
I have created several crates based on num
, namely num-prime
, num-modular
and num-irrational
. Although they are not heavily tested, most major functionalities are working. If you're interested, you can browse their documentations for the details.
I'm personally working on a CAS system as well, but my target is to build it as a rust powered Python package, and it's mainly for number theoretic calculations. It will be wonderful if these packages can help your awesome work on a standalone CAS system :)
(BTW, I'm also quite confident that the primality check function (is_prime64) in num-prime
is among the fastest implementations in any language, although the factorization performance needs to be improved yet)
@cmpute
Your crates look very promising! I'm surprised I didn't notice those until now, since I have done a very thorough survey of math crates on crates.io, and have looked at almost every crate that depends on num
. Somehow, your crates didn't show up, or maybe they did and I overlooked them.
I've filed a few issues against num_prime
based on reviewing the docs. My gut feeling is that the crates are perhaps split too finely, that is, instead of having num_prime
, num_modular
, num_irrational
etc., you might be better off with just a single crate integrating all number-theoretic functionality. The reason is that I expect a lot of helper functions will be used by all crates, so you are faced with the choice of either code duplication, or creating yet more helper crates, or exporting functions that shouldn't really be part of the public API for third-party crates.
But either way, I will probably use all of those crates eventually! They are quite well documented and I like the number of tests they already have.
Are you planning to add more number-theoretic functionality? GCD, LCM, Euler's totient function etc.?
I'm personally working on a CAS system as well, but my target is to build it as a rust powered Python package, and it's mainly for number theoretic calculations.
That's interesting, what is your motivation? Are existing packages with Python bindings not fast enough? And how will your CAS work exactly – standalone REPL, integration into Sage, library-only?
:) Thanks for your interest. I guess you didn't notice these crates because they are not directly dependent on num
, but on sub crates like num-integer
, etc. I'm still actively developing these crates, until I'm satisfied with the functionalities.
you might be better off with just a single crate integrating all number-theoretic functionality.
The number theoretic functions are mainly contained in num-prime
, with only few exceptions in num-modular
. I separated them since I think there are other applications that only requires modular operations rather than a whole bunch of number theoretic functions.
Are you planning to add more number-theoretic functionality? GCD, LCM, Euler's totient function etc.?
I have no plan to implement GCD/LCM since they are already available for integer types. I will implement Euler's totient function and other functions in future, as the functionality of the crate num-prime
is still growing.
what is your motivation?
The main motivation is quite personal. I want a tool in Python for Project Euler puzzles, but I usually suffer from the speed of Python. The existing Python CAS systems like mpmath and Sagemath are overkill for this purpose, and there are still some missing features I need (like APIs for efficient modular arithmetic). I could use Python binding to GMP, but I prefer a small self-contained tool.
My current plan is to build a Python library, that provides easy access to number-theoretic functions and modular arithmetic. I don't bother to design and write a syntax analyzer, so I will integrate the operations with Python syntax. It will also support standalone execution, but with the help of Python (so the final executable will be the size of a Python distro + my rust library)
another library you might be interested in is https://crates.io/crates/algebraics it implements real algebraic numbers (e.g. it can represent 3^(4/7) + sqrt(5)
), and can represent exactly the value of the real roots of any polynomials with rational coefficients. it also implements polynomial factorization for both integer coefficients and some finite fields. (it took me 3 months to figure out all the finite field math needed to factorize polynomials using modern algorithms...it's complex).
unfortunately, i don't have a lot of spare time to maintain algebraics, but will happily accept PRs and help figure stuff out if it doesn't take too much time.