A rust crate for mathematics and science

Overview

Scilib

A Rust crate for scientific processes


Overview

This crate is designed to help any mathematical or scientific processes for the Rust community. It compiles many useful concepts and items that are key in scientific applications, such as Bessel functions, statistical analysis, physical constants, etc...

The aim is to provide classical functions in pure Rust, for ease of operability.


Work in progress

As of the creation of this readme, I am working on this project alone which means a few things:

  1. The progression will be linked to my schedule
  2. I will work firsts on concept with which I am familiar with
  3. I am a self-taught developer, some solutions could be sub-optimal and thus improved

What's coming?

The schedule of the development of the crate is not clear, as I am for now writing this as a side project. I plan on adding many useful functions from a physics point of view, but will expand as I go. For now, my objectives are:

  • Astrophysics
  • Thermodynamics
  • Quantum mechanics
  • Electromagnetism

And hopefully more when this is done (statistics, integration tool, calculus, ...).


Contents

Useful mathematics function

The Rust library doesn't provide some functions that are quite common in scientific processes, and this crate attempts to provide as many as it can. Euler's Gamma and Beta function, Newton's binomial, factorial, the error functions (erf, erfc, erfi), ...

Some functions are still missing as of the writing of this document, but will be added later on.

// These functions can be found in the math crate
use scilib::math::basic::*;

let g = gamma(3.2);
let b = beta(-1.2, 2.5);

// The erf function can compute Complex numbers (erfc, erfi as well)
let c = Complex::from(-0.1, 0.7);
let e = erf(c);

Coordinate systems

This crate provides functionalities for coordinate systems, such as Cartesian and Spherical, with many standard operations, and conversions.

// They are found in the coordinate crate
use scilib::coordinate::*;

let c = cartesian::Cartesian::from(2.0, 1, 0.25);
let s = spherical::Spherical::from_degree(1.2, 30, 60.2);

Complex numbers

This crate provides basic functionalities for complex numbers, mainly to support its other goals. The implementation uses f64 for both the real and imaginary parts, to ensure precision in the computations.

Basic operations have been implemented to facilitate their use, and should be pretty easy to manipulate.

// They are found in the complex crate
use scilib::math::complex::Complex;

let c1 = Complex::from(2, 3.5);
let c2 = Complex::from(-1.2, 4) * 2;
println!("{}", c1 + c2);

More functionalities are on their way, they will be added as they are needed for other domains.


Bessel functions

Essential in many maths and physics domain, bessel function are solutions of Bessel's differential equation (Wiki page). This crate provides functions for both real and complex numbers, and for integer or real function order.

All functions are implemented:

  • J: First kind
  • Y: Second Kind
  • I: Modified first kind
  • K: Modified second kind
  • H1: Hankel first kind
  • H2: Hankel second kind
// Found in the math crate
use scilib::math::bessel;

// All functions support complex numbers, and real orders
let res = bessel::jf(-1.2, 2.3);        // Computes -1.2 with order 2.3 in J
let res = bessel::y(3.5, 1);            // Y computes the limit for integer order
let res = bessel::hankel_first(2, -2)   // Hankel first kind

Values are compared to known results (thanks, WolframAlpha), and the results are within small margins of error.


Typical polynomials

Useful polynomials will be implemented to facilitate their uses to everyone; as it stands, both the Legendre (Plm(x)) and Laguerre (Llm(x)) polynomials have been implemented, where -l <= m <= l.

// They are found in the polynomial crate
use scilib::math::polynomial;

// Legendre supports derivative (and negative m)
let leg = polynomial::Legendre::new(2, 1);  // l=2, m=1

// So does Laguerre
let lag = polynomial::Laguerre::new(3, -2); // l=3, m=-2

Quantum mechanics

The spherical harmonics Ylm(theta, phi) function has been added to the quantum section, and is valid for acoustics as well.

// Found in the quantum crate
use scilib::quantum::*;

// Computing Ylm for l=3, m=1, theta = 0.2 and phi = -0.3
let res = spherical_harmonics(3, 1, 0.2, -0.3);

Comments
  • Spherical Bessel functions added

    Spherical Bessel functions added

    I have added the first two kinds of spherical bessel functions (j and y). Miller's method is used with an upward reccurence (for y) and a downward reccurence (for j). It's just a draft with no comments : the code could definitely be improved.

    Note : sj_array - "s" for spherical - "j" for the first kind - "array" for the collection.

    opened by Gentil-N 8
  • Use num::Complex

    Use num::Complex

    Using this library in another library can be difficult since it defines its own complex type. Since Rust doesn't have a Complex<T> it the standard library, num::Complex is the closest we have a to universal vocabulary type.

    opened by JayKickliter 3
  • Added Summation&Product

    Added Summation&Product

    I have added two common operations : summation and product.

    Even if we can use iterators, it seems that Python sum doesn't have any equivalent in Rust.

    opened by Gentil-N 3
  • Scales added

    Scales added

    All common scales have been added in the "constants" file: it could be more friendly in a scientific code to have * NANO rather than something like * 1e-9.

    opened by Gentil-N 1
  • downward recurrence fixed

    downward recurrence fixed

    Hello there! Small fix on Bessel functions. It is an oversight when I transfered the algorithm into scilib. This bug was only visible for n > 50 with |z| < n/2 and in that case jn(z) has a tendency to be "small" so it was hard to detect it. I didn't add tests for that because it seems to be irrelevant (for my tested range, values are less than 10e-8). Otherwise, I can add some tests to be sure. Sorry for the bug...

    opened by Gentil-N 0
  • Add matrix manipulation to scilib ?

    Add matrix manipulation to scilib ?

    I am working on my pull request aiming to add the iterative solving method JFNK. However, it relies on a lot of upper triangular matrix manipulation. At the moment it is hardcoded in the solver itself. But it could be nice to begin to think of a way to implement matrixes in the crate. Here are some ideas of methods and structures to implement.

    • Matrix Vec<Vec<T>>
    • Upper Triangular matrix
    • Lower Triangular matrix
    • Matrix product
    • Matrix inversion (knowing there are efficient algorithms for upper and lower triangular matrix)
    • Adding column
    • Adding row
    opened by aschneeberger 2
  • Jacob Free Newton Krylov Resolution Method

    Jacob Free Newton Krylov Resolution Method

    I am currently writing a method to solve large sparse non-linear equation systems, such as partial differential equations or like in my case, large thermodynamical equilibrium systems. I am writing it in rust, to free myself from FORTRAN. It currently includes a draft for the GMRES-Given algorithm used to minimize residues, an upper triangular matrix inverse algorithm, an N-dim L2 norm computation function, all in the math/krylov.rs file.

    Road Map :

    • [ ] GMRES-Given
    • [ ] Non preconditionned JFNK
    • [ ] Preconditionning
    • [ ] Add Bounds in the solver
    documentation enhancement 
    opened by aschneeberger 0
  • integration module

    integration module

    Hi Vivien !

    I wrote a draft for the integration module. The global idea is:

    1. Create a chunk_xxx function to integrate with a certain method between two values.
    2. Apply this one to compute_fn and compute_dt.

    Details of these two functions:

    • compute_fn is designed for a function already implemented where we can take any value that we want: f(x) = y
    • compute_dt is designed for a bunch of data where we can take each value separately: (x1, y1), (x2, y2), ... (xn, yn)

    I don't know if I will implement other methods than quad & trapez (in 1D) however, basically, the idea is also to create routines for 2D, 3D and nD integration. Note: 1D integration = dx, 2D integration = dxy, 3D integration = dxyz and nD integration = dn. Perhaps, this naming is not really relevant... let me know.

    (You can also check some functions to see if it's properly working but I am confident in the trapez method because I am currently using it in my other project)

    documentation enhancement 
    opened by Gentil-N 4
Owner
H.G. Vivien
Astrophysics Master
H.G. Vivien
A STARK prover and verifier for arbitrary computations.

A STARK is a novel proof-of-computation scheme to create efficiently verifiable proofs of the correct execution of a computation. The scheme was developed by Eli Ben-Sasson, Michael Riabzev et al. at Technion - Israel Institute of Technology. STARKs do not require an initial trusted setup, and rely on very few cryptographic assumptions. See references for more info.

Novi 512 Jan 3, 2023
Neat 3D math and graphics library

Rust crate for plane-based projective geometric-algebra for 3D aka the Clifford Algebra with signature P(R*3,0,1).

null 25 Dec 14, 2022
Super-fast float parser in Rust

fast-float This crate provides a super-fast decimal number parser from strings into floats.

Ivan Smirnov 241 Dec 10, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
A linear algebra and mathematics library for computer graphics.

cgmath-rs A linear algebra and mathematics library for computer graphics. The library provides: vectors: Vector2, Vector3, Vector4 square matrices: Ma

rustgd 998 Jan 2, 2023
Library for abstract mathematics written by Rust. It is aiming to replace SageMath.

ankolib Roadmap Mathematical Structures Sets Monoids Groups Semirings Rings Algebras Basic Rings and Fields Integers and Rational Numbers Integer Rati

anko 6 Sep 3, 2022
A project management tool for data science and bioinformatics. If you want it, Kerblam it!

Warning kerblam run and kerblam package are complete but still untested. Please do use them, but be careful. Always have a backup of your data and cod

Luca 4 Dec 18, 2023
A Computer Science Wordle variant, where all solutions are related to computing

Csdle I decided to expand a previous project I made, Rdle, which was a plain wordle clone. Recently however, I have been getting very into Wordle vari

Daniel Kogan 2 Sep 8, 2022
A simple programming language, created for AP Computer Science

A simple programming language, created for AP Computer Science

Michelle S. 3 Sep 2, 2022
This is the repository for the group project assignment in the course "Project in Introduction to Computer Science" (DD1396), by the Inda21plusplus group.

Project-Delta This is the repository for the group project assignment in the course "Project in Introduction to Computer Science" (DD1396), by the Ind

null 9 May 24, 2022
📦 Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate.

?? Crate Protocol Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate. A Crate is alw

Crate Protocol 63 Oct 31, 2022
A fork of the abandoned ffmpeg-next crate which is a fork of the abandoned ffmpeg crate

This is a fork of the abandoned ffmpeg-next crate which is a fork of the abandoned ffmpeg crate. Currently supported FFmpeg versions: 4.x, 5.x. Build

Josh Holmer 4 Jan 26, 2023
Travis CI and AppVeyor template to test your Rust crate on 5 architectures and publish binary releases of it for Linux, macOS and Windows

trust Travis CI and AppVeyor template to test your Rust crate on 5 architectures and publish binary releases of it for Linux, macOS and Windows Featur

Jorge Aparicio 1.2k Dec 30, 2022
A Rust proc-macro crate which derives functions to compile and parse back enums and structs to and from a bytecode representation

Bytecode A simple way to derive bytecode for you Enums and Structs. What is this This is a crate that provides a proc macro which will derive bytecode

null 4 Sep 3, 2022
A crate to convert bytes to something more useable and the other way around in a way Compatible with the Confluent Schema Registry. Supporting Avro, Protobuf, Json schema, and both async and blocking.

#schema_registry_converter This library provides a way of using the Confluent Schema Registry in a way that is compliant with the Java client. The rel

Gerard Klijs 69 Dec 13, 2022
Omeglib, a portmanteau of "omegle" and "library", is a crate for interacting with omegle, simply and asynchronously

Omeglib, a portmanteau of "omegle" and "library", is a crate for interacting with omegle, simply and asynchronously. It is intended to suit one's every requirement regarding chat on omegle.

null 1 May 25, 2022
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ A program that lists statistics related to the usage of unsafe Rust code in a Rust crate and all its dependencies. This cargo plugin w

Rust Secure Code Working Group 1.1k Dec 26, 2022
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.

SQLx ?? The Rust SQL Toolkit Install | Usage | Docs Built with ❤️ by The LaunchBadge team SQLx is an async, pure Rust† SQL crate featuring compile-tim

launchbadge 7.6k Dec 31, 2022
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ A program that lists statistics related to the usage of unsafe Rust code in a Rust crate and all its dependencies. This cargo plugin w

Rust Secure Code Working Group 1.1k Jan 8, 2023
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ Looking for maintainer: https://github.com/rust-secure-code/cargo-geiger/issues/210 A program that lists statistics related to the usa

Rust Secure Code Working Group 1.1k Jan 4, 2023