Expand description
ยงSophy ๐งฎ
Sophy is a lightweight, efficient, and extensible mathematical library written in pure Rust. It provides numerical methods, mathematical functions, and number utilities for scientific computing, educational tools, and general-purpose applications.
ยงโจ Features
- ๐ข Numerical Methods: Newton-Raphson root finding, integration, interpolation
- ๐ Mathematical Functions: Exponential, logarithmic, trigonometric functions
- ๐งฎ Number Utilities: Base operations, number theory functions
- ๐ฆ Pure Rust: Memory-safe, zero-cost abstractions
- ๐ Well Documented: Comprehensive documentation with examples
- ๐งช Well Tested: Extensive test suite with high coverage
ยง๐ Quick Start
Add Sophy to your Cargo.toml:
[dependencies]
sophy = "0.1.23"ยง๐ Examples
ยงNewton-Raphson Root Finding
Find the square root of 2 using Newton-Raphson method:
use sophy::methods::raphson::raphson;
// Define the function f(x) = xยฒ - 2
let f = |x: f64| x * x - 2.0;
// Define its derivative f'(x) = 2x
let df = |x: f64| 2.0 * x;
// Find the root starting from xโ = 1.0
let root = raphson(1.0, f, df, 1e-10, 100);
println!("โ2 โ {:.10}", root); // Output: โ2 โ 1.4142135624
assert!((root - std::f64::consts::SQRT_2).abs() < 1e-10);ยงBase Number Operations
Work with mathematical constants and utilities:
use sophy::base::numbers::{PI, EULER, PHI};
println!("ฯ = {:.6}", PI); // ฯ = 3.141593
println!("e = {:.6}", EULER); // e = 2.718282
println!("ฯ = {:.6}", PHI); // ฯ = 1.618034ยงSpecial Mathematical Functions
Advanced mathematical functions for scientific computing:
use sophy::specials::{gamma, zeta, erf};
// Gamma function: ฮ(5) = 4! = 24
let factorial_4 = gamma(5.0);
// Riemann zeta function: ฮถ(2) = ฯยฒ/6
let zeta_2 = zeta(2.0);
// Error function for probability calculations
let error_val = erf(1.0);ยง๐๏ธ Architecture
Sophy is organized into focused modules:
methods: Numerical methods for solving mathematical problemsbase: Fundamental number operations and utilitiesspecials: Special mathematical functions (gamma, zeta, erf, etc.)
ยง๐ฌ Precision & Performance
Sophy uses f64 precision by default for optimal balance between accuracy and performance.
All algorithms are implemented with numerical stability in mind.
ยง๐ค Contributing
Contributions are welcome! Please see our contributing guide for details.
ยง๐ License
This project is dual-licensed under the MIT License or Apache License 2.0.