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 many scientific domains. The aim of the crate is to provide these functions in pure Rust, to avoid any dependencies.


Work in progress; What's coming?

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

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

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 long term objectives are: Astrophysics, Thermodynamics, Quantum mechanics, Electromagnetism.

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


Contents

Useful mathematical functions

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), ...

```rust // 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 = Complex64::new(-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.

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

let car = cartesian::Cartesian::from(2.0, 1, 0.25); let sph = spherical::Spherical::fromdegree(1.2, 30, 60.2); let cyl = spherical::Cylindrical::fromdegree(1.2, 30, -2.55); ```


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. It covers standard Bessel functions, the spherical Bessel functions, and the Riccati-Bessel functions.

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 - j: Spherical first kind - y: Spherical second kind - h1: Spherical hankel first kind - h2: Spherical hankel second kind - S: Riccati-Bessel first kind - C: Riccati-Bessel Second kind - Xi: Riccati-Bessel Third kind - Zeta: Riccati-Bessel Fourth kind

```rust // Found in the math crate use scilib::math::bessel;

// All functions support complex numbers, and real orders let resj = bessel::jf(-1.2, -2.3); // J function; works for any input and order let resy = bessel::y(3.5, 1); // Y function; computes the limit for integer order let resi = bessel::i(7.2, 2.25); // I function; similar to J let resk = bessel::k(-1.1, 0.5); // K function; computes the limit for integer order let res1 = bessel::hankelfirst(2, -2); // Hankel first kind let res2 = bessel::hankelsecond(1, -1.32); // Hankel first kind let ressj = bessel::sj(4.4, 2); // Spherical first kind let ressy = bessel::sy(-1.54, 3); // Spherical second kind let ress1 = bessel::shfirst(2.11, 4); // Spherical hankel first kind let ress2 = bessel::shsecond(0.253, 0); // Spherical hankel second kind ```

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

Thanks to Neven for adding the Spherical versions.


Signal functions

Support to conduct both fast Fourier transform (fft) and the inverse fast Fourier transform (ifft) is available. Computations are done using Bluestein's algorithm. Convolution is also possible, with any two vector sizes.

```rust // Found in the fourier crate use scilib::signal::*

// Computing values of the sinus let r = range::linear(0.0, 10.0, 15); let s: Vec = r.iter().map(|val| val.sin()).collect();

let res = fft(&s); let res2 = ifft(&res); let res3 = convolve(&r, &s); ```


Typical polynomials

Useful polynomials will be implemented to facilitate their uses to everyone; currently the Legendre, Laguerre, Bernoulli and Euler polynomials have been implemented.

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

// Legendre and Laguerre have their generalized versions let leg = Legendre::new(2, -1); // l=2, m=-1 let lag = Laguerre::new(3, 2); // l=3, m=2

// Standard support for Bernoulli and Euler (numbers and polynomials) let ber = Bernoulli::new(3); // n=3 let eul = Euler::new(5); // n=5 ```


Astronomy and astrophysics

We provide practical functions for astronomy and astrophysics applications, from a Radec coordinate system to equilibrium temperature computation and a magnitude calculator.

```rust // Found in the astronomy crate use scilib::astronomy::*; use scilib::constant as cst;

// Creating a Radec system let coord: Radec = Radec::from_degree(32, 21.22534);

// Apparent magnitude of the Sun at a light year distance let mag = apparentmag(cst::SUNL, cst::LY); ```


Quantum mechanics

Both the radial wave function Rnl(r) and the spherical harmonics Ylm(theta, phi) have been added to the quantum section. The Ylm is also valid for acoustics as well.

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

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

// Computing the Rnl for n=4, l=2 let rad = radial_wavefunction(4, 2, 1.3e-12); ```


Constants

Many useful constants have been added, comprising many different fields, from astrophysics to quantum mechanics, but also mathematics, thermodynamics, electromagnetism, etc... They're listed in the constant module. Note that all constants are provided with a link to the source.

```rust use scilib::constant;

println!("{}", constant::SUNRADIUS); // Solar radius println!("{}", constant::HBAR); // H bar println!("{}", constant::KB); // Boltzmann constant println!("{}", constant::BOHRMAG); // Bohr magneton // And many more... ```