geop_core_math/solvers/mod.rs
1//! Solvers: finding where functions vanish, and the constraint systems built
2//! on them.
3//!
4//! - [`linear`]: dense linear algebra in honest enclosures — the linear
5//! solves, eliminations, null spaces and inverses every other solver
6//! builds on.
7//! - [`iterate`]: fixed-point iteration from sharp seeds, keeping the
8//! honest answer beside the seed — the loop of every Newton-type method.
9//! - [`bisect`]: bisection of a bracket, in plain numbers or sharp scalars,
10//! and the scan of samples for the brackets of a sign change.
11//! - [`minimize`]: damped descent to a point that is a free choice.
12//! - [`probe`]: a sequence of trial values — a step halved, a reach
13//! doubled — probed until one decides.
14//! - [`refine`]: adaptive refinement, a resolution made finer until what is
15//! built at it is good enough.
16//! - [`subdivide`]: subdivision search, the global method that finds every
17//! solution in a region within a node budget.
18//! - [`repeat`]: a step repeated until it says it is done, within a
19//! budget — worklists rewritten until nothing is left to rewrite, marches
20//! stepped on until they arrive, passes until one changes nothing.
21//! - [`walk`]: a chain followed node by node until it closes, ends or runs
22//! into itself, and a graph flooded from some nodes to all it reaches.
23//! - [`newton`]: Newton refinement of a root a subdivision search has
24//! isolated, and Newton's method on one unknown from a seed.
25//! - [`least_squares`]: constrained Levenberg–Marquardt.
26//! - [`system`]: constraint systems on blocks of variables — numbers,
27//! poses — solved by the driver, checked, measured for freedom and
28//! conflicts, and their solution enclosed: the engine behind sketches and
29//! the state of programs alike. A solve holds the constraints exactly,
30//! and prefers pulls and staying put among where they hold.
31
32pub mod bisect;
33pub mod iterate;
34pub mod least_squares;
35pub mod linear;
36pub mod minimize;
37pub mod newton;
38pub mod probe;
39pub mod refine;
40pub mod repeat;
41pub mod subdivide;
42pub mod system;
43pub mod walk;
44
45thread_local! {
46 static WORK: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
47}
48
49/// How much dense linear algebra this thread has done, ever: per
50/// factorisation of a matrix of `rows` rows over `columns` unknowns — a
51/// step of [`least_squares::minimize`], an elimination of
52/// [`linear::eliminate`] — `rows × columns²`, what it costs. A test bounds
53/// the work of a solve by it, rather than timing it: a dense system grows
54/// as the cube of its size.
55pub fn work() -> u64 {
56 WORK.get()
57}
58
59/// Counts a factorisation of `rows` rows over `columns` unknowns (see
60/// [`work`]).
61fn factorised(rows: usize, columns: usize) {
62 let cost = (rows as u64).saturating_mul((columns as u64).saturating_pow(2));
63 WORK.set(WORK.get().saturating_add(cost));
64}