#mathematics #science #physics #bessel

scilib

A scientific library for the Rust programming language

5 unstable releases

0.3.0 Oct 15, 2021
0.2.45 Oct 13, 2021
0.1.1 Oct 10, 2021
0.0.0 Oct 10, 2021

#68 in Math

43 downloads per month

GPL-3.0 license

100KB
1K SLoC

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; What's coming?

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

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

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


Signal function

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

No runtime deps