caelum0x 2335e9556d feat: v2-A engine breadth — structural reductions, MDL/Pareto, differentiable export, SRBench families
Batch 3 of the expansion-v2 roadmap, all deterministic/offline/std-only with
honest capability boundaries.

crates/lawsynth-reduce (new): deterministic symmetry & separability detection.
Numerical-derivative probe (finite differences replace AI-Feynman's trained NN
gradients) over a reconstructed Cartesian grid; additive/multiplicative
separability + difference/sum/product/ratio symmetries. Every detection is a
HYPOTHESIS verified by reconstruction residual, never a proof; non-grid data is
honestly rejected (NotReconstructed). 17 tests.

crates/lawsynth-score: two-part MDL objective (L_data + L_model in nats) and
O(n log n) pareto_front_2d (sort-then-sweep), verified equal to the O(n^2)
front across 12 deterministic sets. +5 tests; crate fmt-normalized to config.

python/lawsynth export.py (new): to_sympy/to_torch/to_jax + dep-free
numeric_derivatives anchor. Constants+params hoisted into one trainable vector
so autograd reaches every coefficient (Neural-ODE vector field). Backends
absent here degrade gracefully (MissingDependencyError subclasses ImportError).
Faithful to native simulate at 1.1e-16. 10 tests + 6 honest skips.

benchmarks: SRBench Feynman (15: 12 static algebraic relations as honest
capability-boundaries, 3 dynamics-framed ODEs executed at R2~=1.0) and
black-box (4 systems, predictive R2 + parsimony, no ground truth) families.
Fixes a pre-existing _runner.py failure where Strogatz cases leaked into the
legacy contract suite. 31 benchmark tests.

specs/structural-reductions: boundary spec (detection-is-a-hypothesis contract).
2026-08-18 15:04:43 +03:00

56 lines
1.9 KiB
Rust

//! Honest gating: scattered (non-grid) data is reported as not reconstructed,
//! and error paths are surfaced rather than fabricating a reduction.
mod common;
use common::{axis, grid_dataset_2d};
use lawsynth_core::Identifier;
use lawsynth_data::{Dataset, NumericColumn, TimeAxis};
use lawsynth_reduce::{GridStatus, ReduceConfig, ReduceError, detect_reductions};
fn id(name: &str) -> Identifier {
Identifier::new(name).unwrap()
}
#[test]
fn scattered_samples_are_not_reconstructed() {
// x = t, y = t^2, f = arbitrary: not a Cartesian product of x and y.
let time: Vec<f64> = (0..24).map(|i| i as f64 * 0.1 + 0.1).collect();
let x = time.clone();
let y: Vec<f64> = time.iter().map(|t| t * t).collect();
let f: Vec<f64> = x.iter().zip(&y).map(|(a, b)| a + b).collect();
let dataset = Dataset::new(
TimeAxis::new(time).unwrap(),
[
NumericColumn::new(id("x"), x),
NumericColumn::new(id("y"), y),
NumericColumn::new(id("f"), f),
],
)
.unwrap();
let report = detect_reductions(&dataset, &ReduceConfig::with_target("f")).unwrap();
assert!(matches!(report.grid, GridStatus::NotReconstructed { .. }));
assert!(report.is_empty());
}
#[test]
fn unknown_target_is_rejected() {
let xs = axis(0.0, 0.25, 6);
let ys = axis(0.0, 0.25, 6);
let dataset = grid_dataset_2d(&xs, &ys, |x, y| x + y);
let err = detect_reductions(&dataset, &ReduceConfig::with_target("missing")).unwrap_err();
assert!(matches!(err, ReduceError::UnknownTarget { .. }));
}
#[test]
fn invalid_config_is_rejected() {
let xs = axis(0.0, 0.25, 6);
let ys = axis(0.0, 0.25, 6);
let dataset = grid_dataset_2d(&xs, &ys, |x, y| x + y);
let mut config = ReduceConfig::with_target("f");
config.additive_tol = -1.0;
let err = detect_reductions(&dataset, &config).unwrap_err();
assert!(matches!(err, ReduceError::InvalidConfig { field: "additive_tol" }));
}