## scilib

A scientific library for the Rust programming language

### 15 unstable releases(6 breaking)

 0.7.0 Feb 21, 2023 Jan 21, 2023 Jun 2, 2022 Mar 28, 2022 Oct 15, 2021

#47 in Math

2.5MB
2.5K SLoC # 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.

``````use scilib::constant;

println!("{}", constant::H_BAR);        // H bar
println!("{}", constant::K_B);          // Boltzmann constant
println!("{}", constant::BOHR_MAG);     // 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), ...

``````// 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
``````// Found in the math crate
use scilib::math::bessel;

// All functions support complex numbers, and real orders
let res_j = bessel::jf(-1.2, -2.3);             // J function; works for any input and order
let res_y = bessel::y(3.5, 1);                  // Y function; computes the limit for integer order
let res_i = bessel::i(7.2, 2.25);               // I function; similar to J
let res_k = bessel::k(-1.1, 0.5);               // K function; computes the limit for integer order
let res_1 = bessel::hankel_first(2, -2);        // Hankel first kind
let res_2 = bessel::hankel_second(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.

• Legendre: `L(n,l)` generalized with with `n` positive integer and `l` positive or negative integer such that `-n <= l <= n`
• Laguerre: `L(n,l)` generalized with `n` positive integer and `l` a real number
• Bernoulli: `B(n)` with `n` positive integer
• Euler: `E(n)` with `n` positive integer
• Bessel: `y(n)` with `n` positive integer
• Hermite: `H(n)` with `n` positive integer
• Rising factorial: the polynomial associated to the rising factorial function, with `n` positive integer
• Falling factorial: the polynomial associated to the falling factorial function, with `n` positive integer
``````// 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.

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

let car = cartesian::Cartesian::from(2.0, 1, 0.25);
let sph = spherical::Spherical::from_degree(1.2, 30, 60.2);
let cyl = spherical::Cylindrical::from_degree(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.

``````// 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<Complex64> = 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.

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

// And other practical function
let mag = apparent_mag(cst::SUN_L, cst::LY);            // Apparent mag of the Sun at 1 ly
let b = impact_parameter(a, r_star, 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.

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