iter-solver

Crates.ioiter-solver
lib.rsiter-solver
version0.2.1
created_at2025-08-24 17:36:32.508776+00
updated_at2025-09-04 10:04:47.883988+00
descriptionA rust crate provide flexible and general iterative algorithm framework.
homepage
repositoryhttps://github.com/Y-S-Xing/iter-solver
max_upload_size
id1808624
size27,562
(Y-S-Xing)

documentation

README

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 driver to your Cargo.toml dependencies:

[dependencies]
iter-solver = "0.2.0"

or add it directly from the terminal:

cargo add iter-solver

License

MIT License.

Commit count: 22

cargo fmt