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.
58 lines
2.1 KiB
Rust
58 lines
2.1 KiB
Rust
//! Determinism: trajectories are bit-identical and discovery is reproducible.
|
|
|
|
mod common;
|
|
|
|
use common::recovered_laws;
|
|
use lawsynth_domains::{all, preset};
|
|
|
|
/// Two trajectory generations of the same preset must be bit-for-bit identical
|
|
/// across every channel — the RK4 integrator reads no clock and no randomness.
|
|
#[test]
|
|
fn trajectories_are_bit_identical_across_calls() {
|
|
for preset in all() {
|
|
let first = preset.reference().trajectory();
|
|
let second = preset.reference().trajectory();
|
|
for state in preset.state_variables() {
|
|
let a = &first.columns()[state].values;
|
|
let b = &second.columns()[state].values;
|
|
assert_eq!(a.len(), b.len(), "channel length differs for {}", preset.name());
|
|
assert!(
|
|
a.iter().zip(b).all(|(left, right)| left.to_bits() == right.to_bits()),
|
|
"trajectory not bit-identical for {} channel {state}",
|
|
preset.name(),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The trajectory has exactly `steps + 1` samples with the expected uniform time
|
|
/// axis, independent of the domain.
|
|
#[test]
|
|
fn trajectory_length_matches_the_reference_schedule() {
|
|
let brusselator = preset("brusselator").unwrap();
|
|
let data = brusselator.reference().trajectory();
|
|
assert_eq!(data.time().len(), brusselator.reference().steps() + 1);
|
|
for state in brusselator.state_variables() {
|
|
assert_eq!(data.columns()[state].values.len(), brusselator.reference().steps() + 1);
|
|
}
|
|
}
|
|
|
|
/// Running discovery twice on the same preset yields identical recovered laws.
|
|
#[test]
|
|
fn discovery_is_reproducible() {
|
|
let lotka = preset("lotka-volterra").unwrap();
|
|
assert_eq!(recovered_laws(&lotka), recovered_laws(&lotka));
|
|
}
|
|
|
|
/// The reference initial condition seeds the very first trajectory sample.
|
|
#[test]
|
|
fn first_sample_is_the_initial_condition() {
|
|
for preset in all() {
|
|
let data = preset.reference().trajectory();
|
|
for (index, state) in preset.state_variables().iter().enumerate() {
|
|
let first = data.columns()[state].values[0];
|
|
assert_eq!(first.to_bits(), preset.reference().initial()[index].to_bits());
|
|
}
|
|
}
|
|
}
|