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.


Contents

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... ```


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); ```


Bessel functions

Essential in many maths and physics domain, the bessel functions are solutions of Bessel's differential equation. 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: - Basic Bessel functions: J, Y, I, K - Spherical Bessel functions: j, y - Hankel functions (and there spherical counterparts): H1, H2, h1, h2 - Riccati-Bessel functions: S, C, Xi, Zeta

```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 // And so forth... ```


Typical polynomials

A dedicated method for polynomial is implemented in the module math::polynomial as Poly. Many useful polynomials have also been implemented.

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

let mut p = Poly::from([(2, 1.0), (1, 2.0), (0, -1.0)]); // x² + 2x - 1 p.derive(1); // Derivative

let leg = Poly::gen_legendre(2, -1); // n=2, l=-1 let mut lag = Poly::laguerre(3, 2.78); // n=3, l=2.78 leg.integrate(1, &[3.2]); // Integration let res = p * lag; // Standard operations ```


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); ```


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); ```


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);

// And other practical function let mag = apparentmag(cst::SUNL, cst::LY); // Apparent mag of the Sun at 1 ly let hill = hillradius(mass, massstar, distance, e); // Hill radius let b = impactparameter(a, rstar, i, e, w); // Transit impact parameter ```


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); ```