Batch 5 of expansion-v2. All deterministic/offline/std-only with honest specs.
crates/lawsynth-stability (new): fixed-point & linear-stability analysis of a
discovered autonomous field. Deterministic multivariate Newton (analytic
Jacobian + local Gaussian elimination) from a fixed seed lattice; classifies
each fixed point by Jacobian eigenvalues (reusing koopman::eigen) into stable
node/spiral, unstable, saddle, center, or an honest Marginal when linearization
is inconclusive. Recovers the pendulum's saddle/center/saddle and
Lotka-Volterra's saddle + interior center; reports non-convergence and no-root
boxes honestly. 40 tests.
crates/lawsynth-egraph: richer sound rewrite engine (identities, power/log/exp
laws, sin/cos parity, Pythagorean collapse, cost-reducing factoring, constant
folding) + public simplify_expr/simplify_law for cleaning discovered laws.
Priority soundness harness: 8,690 sampled value-agreement checks at 1e-12 over
a 36-expression battery. No pre-existing unsound rule found. 32 tests.
crates/lawsynth-control: forward RK4 simulation + R²/RMSE validation, closing
discover->simulate->score. Library terms evaluated structurally from a stored
FeatureLibrary (no string re-parsing); documented control interpolation
(linear, clamped). Closed-loop R²~=1.0; zeroing the control coefficient
collapses R² to 0.11 (score discriminates). 38 tests (25 prior + 13 new).
crates/lawsynth-domains (new): three self-validated presets — damped-oscillator,
Lotka-Volterra (with a polynomial-kinds template prior), Brusselator — each
proven by round-trip recovery of its own reference law (coef error <=1.3e-4).
The full pendulum was deliberately dropped (near-degenerate sin under STLSQ)
rather than faked. 24 tests.
specs/{stability-analysis,egraph-simplification,domain-packs}: boundary specs;
controlled-discovery spec extended with the simulation/validation contract.
45 lines
1.7 KiB
Rust
45 lines
1.7 KiB
Rust
//! The heart of the crate: each preset recovers its own reference law.
|
|
//!
|
|
//! For every preset we synthesize the reference trajectory, run discovery with
|
|
//! the preset's configuration and prior, and assert the discovered law matches
|
|
//! the reference law exactly in structure and to a tight coefficient tolerance.
|
|
//! The tolerance is deliberately far below the coefficient magnitudes (≈1) and
|
|
//! comfortably above the observed finite-difference error (≤1.3e-4), so a genuine
|
|
//! structural miss cannot slip through.
|
|
|
|
mod common;
|
|
|
|
use common::assert_round_trip;
|
|
use lawsynth_domains::preset;
|
|
|
|
/// Coefficient tolerance shared by every preset. The largest observed error is
|
|
/// ~1.3e-4 (the Lotka-Volterra prey growth term), so 1e-3 is tight yet honest.
|
|
const COEFFICIENT_TOLERANCE: f64 = 1e-3;
|
|
|
|
#[test]
|
|
fn damped_oscillator_recovers_its_reference_law() {
|
|
// dx/dt = v ; dv/dt = -x - 0.5 v
|
|
assert_round_trip(&preset("damped-oscillator").unwrap(), COEFFICIENT_TOLERANCE);
|
|
}
|
|
|
|
#[test]
|
|
fn lotka_volterra_recovers_its_reference_law() {
|
|
// dprey/dt = 1.5 prey - prey predator ; dpredator/dt = 0.75 prey predator - predator
|
|
assert_round_trip(&preset("lotka-volterra").unwrap(), COEFFICIENT_TOLERANCE);
|
|
}
|
|
|
|
#[test]
|
|
fn brusselator_recovers_its_reference_law() {
|
|
// dx/dt = 1 - 4 x + x^2 y ; dy/dt = 3 x - x^2 y
|
|
assert_round_trip(&preset("brusselator").unwrap(), COEFFICIENT_TOLERANCE);
|
|
}
|
|
|
|
#[test]
|
|
fn every_registered_preset_round_trips() {
|
|
// Guards against a future preset being added to the registry without a
|
|
// validating round-trip: this iterates the whole catalog.
|
|
for preset in lawsynth_domains::all() {
|
|
assert_round_trip(&preset, COEFFICIENT_TOLERANCE);
|
|
}
|
|
}
|