| Crates.io | iter-solver |
| lib.rs | iter-solver |
| version | 0.2.1 |
| created_at | 2025-08-24 17:36:32.508776+00 |
| updated_at | 2025-09-04 10:04:47.883988+00 |
| description | A rust crate provide flexible and general iterative algorithm framework. |
| homepage | |
| repository | https://github.com/Y-S-Xing/iter-solver |
| max_upload_size | |
| id | 1808624 |
| size | 27,562 |
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.
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());
}
Add the driver to your Cargo.toml dependencies:
[dependencies]
iter-solver = "0.2.0"
or add it directly from the terminal:
cargo add iter-solver