7 releases
Uses new Rust 2024
| new 0.3.0 | Mar 2, 2026 |
|---|---|
| 0.2.1 | Sep 4, 2025 |
| 0.2.0 | Aug 28, 2025 |
| 0.1.3 | Aug 26, 2025 |
#1078 in Algorithms
26KB
453 lines
A General Iterative Algorithm Framework
iter-solver is a flexible and general iterative algorithm framework that allows users to customize iteration logic and termination conditions, providing a unified abstraction for different problems and algorithms.
Example
The following program defines a simple Newton iterative solver to compute ln(1.5):
use iter_solver::Solver;
fn f_and_df(x: f64) -> (f64, f64) {
let fx = x.exp() - 1.5;
let dfx = x.exp();
(fx, dfx)
}
fn main() {
let iter_fn = |state: &f64, problem: &fn(f64) -> (f64, f64)| {
let x_n = *state;
let (fx, dfx) = problem(x_n);
x_n - (fx / dfx)
};
let term_cond = |state: &f64, problem: &fn(f64) -> (f64, f64)| {
let (fx, _) = problem(*state);
fx.abs() < 1e-6
};
let solver = Solver::new(iter_fn, term_cond);
let solution = solver.solve(1.5, &(f_and_df as fn(f64) -> (f64, f64)));
println!("solver's solution: {}", solution);
println!("use std function ln: {}", 1.5_f64.ln());
}
Installation
Add the following to your Cargo.toml dependencies:
[dependencies]
iter-solver = "0.3"
or add it directly from the terminal:
cargo add iter-solver
License
Dependencies
~140–530KB
~12K SLoC