Batch 6 of expansion-v2. Makes the new engine reachable from the CLI and adds
the dynamics analysis layer on top of it. Deterministic/offline/std-only.
lawsynth-cli: exposes the just-built engine crates as real, tested commands.
- `lawsynth stability WORLD --box LOW:HIGH` — fixed points + eigenvalues +
classification (honest marginal/no-root/seed accounting).
- `lawsynth control OBS.csv --state.. --control.. [--validate]` — SINDYc
controlled discovery + in-sample R²/RMSE (dedicated subcommand so
discover's .lsworld contract stays clean).
- `lawsynth domains [show|run NAME]` — list/inspect/round-trip presets.
- `discover` template-prior flags (--max-degree/--allow-vars/--allow-kinds/
--forbid-interactions/--max-active/--require-kind) with honest drop report.
- `simplify` upgraded to the egraph simplify_law pass.
101 unit + 8 new end-to-end integration tests.
crates/lawsynth-bifurcation (new): parameter continuation + bifurcation
detection on a discovered field f(x;μ). Deterministic grid sweep, proximity
branch matching, eigenvalue-crossing detection with bisection localization.
Detects saddle-node/transcritical/pitchfork (generic Fold) and Hopf at μ*≈0 on
the textbook normal forms. 32 tests.
crates/lawsynth-feedback (new): linear feedback design from a discovered
linearization (A,B). Ackermann SISO pole placement (double integrator → exact
K, poles matched <1e-10) and LQR via Kleinman/Bass Riccati iteration
(analytic K=[1,√3], CARE residual ~4e-16). Closed-loop poles verified through
koopman::eigen. 28 tests.
crates/lawsynth-uncertainty: deterministic bootstrap for discovered
coefficients — per-term CIs + inclusion probability. True terms hit inclusion
1.0 with covering CIs, spurious 0.0; CI width shrinks ~4x with n. Reuses the
crate's SplitMix64, seeded per replicate by (seed,b). 24 tests.
specs/{bifurcation-analysis,control-design,coefficient-uncertainty}: boundary
specs with honest limits (grid-bounded continuation, SISO/continuous-time
feedback, approximate bootstrap CIs under time correlation).
54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
//! Bit-for-bit determinism of both design methods.
|
|
|
|
mod common;
|
|
|
|
use common::matrix;
|
|
use lawsynth_feedback::{Complex, Matrix, lqr, place_poles};
|
|
|
|
/// Compares two matrices by raw `f64` bit patterns.
|
|
fn bits_equal(a: &Matrix, b: &Matrix) -> bool {
|
|
if (a.rows(), a.cols()) != (b.rows(), b.cols()) {
|
|
return false;
|
|
}
|
|
for i in 0..a.rows() {
|
|
for j in 0..a.cols() {
|
|
if a.get(i, j).to_bits() != b.get(i, j).to_bits() {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
true
|
|
}
|
|
|
|
/// Compares two pole lists by raw `f64` bit patterns, in order.
|
|
fn poles_bits_equal(a: &[Complex], b: &[Complex]) -> bool {
|
|
a.len() == b.len()
|
|
&& a.iter()
|
|
.zip(b)
|
|
.all(|(x, y)| x.re.to_bits() == y.re.to_bits() && x.im.to_bits() == y.im.to_bits())
|
|
}
|
|
|
|
#[test]
|
|
fn pole_placement_is_bit_identical() {
|
|
let a = matrix(vec![vec![0.0, 1.0], vec![0.0, 0.0]]);
|
|
let b = matrix(vec![vec![0.0], vec![1.0]]);
|
|
let desired = [Complex::new(-1.0, 2.0), Complex::new(-1.0, -2.0)];
|
|
let first = place_poles(&a, &b, &desired).unwrap();
|
|
let second = place_poles(&a, &b, &desired).unwrap();
|
|
assert!(bits_equal(&first.k, &second.k));
|
|
assert!(poles_bits_equal(&first.achieved_poles, &second.achieved_poles));
|
|
}
|
|
|
|
#[test]
|
|
fn lqr_is_bit_identical() {
|
|
let a = matrix(vec![vec![0.0, 1.0], vec![0.0, 0.0]]);
|
|
let b = matrix(vec![vec![0.0], vec![1.0]]);
|
|
let q = Matrix::identity(2);
|
|
let r = matrix(vec![vec![1.0]]);
|
|
let first = lqr(&a, &b, &q, &r).unwrap();
|
|
let second = lqr(&a, &b, &q, &r).unwrap();
|
|
assert!(bits_equal(&first.k, &second.k));
|
|
assert!(bits_equal(first.p.as_ref().unwrap(), second.p.as_ref().unwrap()));
|
|
assert!(poles_bits_equal(&first.achieved_poles, &second.achieved_poles));
|
|
}
|