Crates.io | scilib |
lib.rs | scilib |
version | 1.0.0 |
source | src |
created_at | 2021-10-10 09:51:49.867643 |
updated_at | 2023-09-13 14:45:58.174449 |
description | A scientific library for the Rust programming language. |
homepage | |
repository | https://github.com/At0micBee/scilib |
max_upload_size | |
id | 463074 |
size | 3,774,943 |
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.
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::SUN_RADIUS); // Solar radius
println!("{}", constant::H_BAR); // H bar
println!("{}", constant::K_B); // Boltzmann constant
println!("{}", constant::BOHR_MAG); // Bohr magneton
// And many more...
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);
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:
// 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...
A dedicated method for polynomial is implemented in the module math::polynomial
as Poly
.
Many useful polynomials have also been implemented.
L(n,l)
generalized with with n
positive integer and l
positive or negative integer such that -n <= l <= n
L(n,l)
generalized with n
positive integer and l
a real numberB(n)
with n
positive integerE(n)
with n
positive integery(n)
with n
positive integerH(n)
with n
positive integern
positive integern
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
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);
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);
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;
// Creating a Radec system
let coord: Radec = Radec::from_degree(32, 21.22534);
// And other practical function
let mag = apparent_mag(cst::SUN_L, cst::LY); // Apparent mag of the Sun at 1 ly
let hill = hill_radius(mass, mass_star, distance, e); // Hill radius
let b = impact_parameter(a, r_star, i, e, w); // Transit impact parameter
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
let rad = radial_wavefunction(4, 2, 1.3e-12);