lawsynth/crates/lawsynth-symbolic/tests/population_integration.rs
caelum0x 6f38503ad2 feat(v2-A): units-in-discovery dimensional pruning + Koopman/DMD crate
Two top-ROI engine items from expansion-v2 / the competitive analysis:

Units-in-discovery (specs/dimensional-search) — wire lawsynth-units into discovery
to prune dimensionally-inconsistent candidate terms in-loop (à la PySR/SciML/
AI-Feynman). Wildcard-aware inference (free coefficients absorb residual units),
opt-in --units NAME=UNIT flag, exact-rational Buckingham-pi dimensionless-groups
helper. Demo: oscillator prunes 8/20 terms (dimensioned sin/cos), identical
recovery; default path byte-identical. 185 tests across 4 crates.

Koopman/DMD (crates/lawsynth-koopman, specs/koopman) — the linear-operator method
LawSynth lacked: DMD/DMDc/EDMD with hand-rolled deterministic SVD (one-sided
Jacobi) + eigendecomposition (Hessenberg->complex-QR->inverse-iteration), no
external crates. Recovers eigenvalues to ~2e-16, EDMD 100x better than raw DMD,
DMDc [A B] to <1e-8; 34 tests, bit-exact determinism.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-18 02:45:13 +03:00

18 lines
766 B
Rust

use lawsynth_core::Identifier;
use lawsynth_expr::Expr;
use lawsynth_symbolic::{Population, ScoredExpression, pareto_by_loss_and_complexity};
#[test]
fn population_canonicalizes_duplicates_before_pareto_ranking() {
let x = Identifier::new("x").unwrap();
let x_plus_zero = Expr::sum(Expr::symbol(x.clone()), Expr::constant(0.0));
let x_plain = Expr::symbol(x);
let population = Population::new([x_plus_zero, x_plain.clone(), Expr::constant(1.0)]);
assert_eq!(population.len(), 2);
let candidates = [
ScoredExpression { expression: x_plain, loss: 0.1, complexity: 1 },
ScoredExpression { expression: Expr::constant(1.0), loss: 1.0, complexity: 1 },
];
assert_eq!(pareto_by_loss_and_complexity(&candidates), vec![0]);
}