Expand description
§polyzonotope-reach
Reachable-set over-approximation for dynamical systems, with the sparse polynomial zonotopes of polyzonotope.
Given a set of start states and a set of inputs, the crate computes flowpipes: for each time step, one set that holds every state at the end of the step and one that holds every state during it. LinearReach handles x' = A x + B u with a Taylor-series matrix exponential and an enclosed remainder; NonlinearReach handles x' = f(x, u) by conservative linearization or conservative polynomialization, with set splitting, merging and adaptive steps. A step it cannot prove is refused rather than returned, and with the sound feature the floating-point rounding is enclosed as well. The crate is no_std with alloc.
Part of the planning and search crates; see also this crate’s overview page.
§Who this is for
- Control and verification engineers who need to show that a vehicle, drone, pendulum or oscillator stays within bounds for every initial state and every input signal in a given range, not only for a handful of simulated runs.
- Researchers comparing reachability methods: both nonlinear abstractions run on the same
Dynamics, and the linear results are cross-checked against CORA. - Planners that need a reachable set per edge: robust-planning proves the edges of its trees and searches safe with a reachable-set model, which can be built on this crate.
- For the set types and operations alone (maps, sums, reductions, polytope checks) without any dynamics, polyzonotope is enough.
§Installation
[dependencies]
polyzonotope-reach = "0.1"§Linear systems
LinearReach propagates x' = A x + B u, where the input u(t) can be any integrable signal with values in a zonotope U. Each step [t_k, t_k + r] returns two sets:
time_pointholds every state att_k + r:e^{Ar} X ⊕ Γ(r) B c_u ⊕ R_p(B U_Δ).time_intervalholds every state at anytin the step. It is the hull ofXand its successor (Girard 2005), plus the curvature correctionsF XandF̃ B c_u, plusR_p.
The matrix exponential is a truncated Taylor series with its remainder E(r) carried as an interval matrix (Althoff 2010). c_u is the center of U, and R_p bounds the response to the varying part U_Δ.
use nalgebra::{DMatrix, DVector};
use polyzonotope::{SparsePolyZonotope, Zonotope};
use polyzonotope_reach::{LinearReach, LinearSystem};
// A damped oscillator pushed by an input in [0.9, 1.1].
let system = LinearSystem {
a: DMatrix::from_row_slice(2, 2, &[0.0, 1.0, -1.0, -0.2]),
b: DMatrix::from_row_slice(2, 1, &[0.0, 1.0]),
};
let reach = LinearReach::new(system, 0.1, 6)?;
let start = SparsePolyZonotope::from_zonotope(&Zonotope::new(
DVector::from_vec(vec![1.0, 0.0]),
DMatrix::from_diagonal_element(2, 2, 0.05),
));
let input = Zonotope::new(DVector::from_vec(vec![1.0]), DMatrix::from_element(1, 1, 0.1));
let step = reach.step(&start, &input);
let hull = step.time_interval.interval_hull();
assert!(hull.0[0].lo <= 0.95 && hull.0[0].hi >= 1.05);Sets grow by a few generators per step. Call reduce from polyzonotope between steps to keep them small.
§Nonlinear systems
NonlinearReach propagates x' = f(x, u) for any Dynamics: a type that encloses f, its Jacobian and its Hessians over boxes in interval arithmetic, and optionally its third derivatives. Polynomial implements it for polynomial vector fields and derives all of them itself. NonlinearSettings::method picks how each step abstracts f.
§Conservative linearization
Method::Linearization (Althoff, Stursberg & Buss 2008) is the default, since it needs the Hessians only:
- Linearize at
z* = (x*, c_u), wherex*is the middle of the set moved half a step alongf. This givesx' = A x + B u + w. - Run the linear step with the abstraction error as an extra input, bounded by a guessed box
Ψ̄. - Bound the true error over the time-interval set
R(τ)andU. By Taylor’s theorem with the Lagrange remainder, it isΔzᵀ Q Δzplus a remainder.Qis the center of½ Hover a box that holds every segment fromz*intoR(τ) × U. The quadratic part is a polynomial zonotope (quadratic_map), so its hull seesx₀²as non-negative. The spread of the Hessian and of the Jacobian go through intervals. - Accept the step if the error lies in
Ψ̄. Otherwise widenΨ̄and retry. Aftermax_iterationstries, refuse withReachError::AbstractionDiverged.
§Conservative polynomialization
Method::Polynomialization (Althoff 2013) keeps the second- and third-order error at the start set as a polynomial zonotope over the set’s factors. It needs Dynamics::third_derivatives, and refuses with ReachError::MissingDerivatives without them. With s = (x_k − x_m, 0) the start of a trajectory relative to the middle x_m of the set, and δ(t) = Δz(t) − s what changes during the step, the error splits exactly into:
- the static part
sᵀ Q s + P s³withQ = ½ H(z*)andP ≈ ⅙ ∂³f(z*). It depends onx_kalone, so it is computed once per step withquadratic_mapandcubic_mapover the factors ofX. It enters as the constant inputvof the augmented systemx' = A x + v, v' = 0, x₀' = 0, started from{ (x_k, ψ_s(x_k), x_k) }, and keeps its dependencies. - the dynamic part:
sᵀ (½H) δ + δᵀ (½H) s + δᵀ (½H) δ, the changeP (Δz³ − s³)of the cubic term during the step, the Lagrange remainder⅙ Σ (∂³f(ξ) − 6P) Δz Δz Δzover a box that holds every segment fromz*, and the rounding spreads ofJ(z*)andH(z*). For a field of degree 3 or less,∂³fis constant and that remainder comes from rounding only. All of it goes through interval arithmetic and into the guessed boxΨ̄. The state part ofδisx(t) − x_kminus the half step, withx(t) − x_kin both the flow box[0, r] f(□R(τ) × □U)and the hull ofx − x₀over the time-interval set of the augmented system, which carries a constant copyx₀ = x_kof the start state. In that difference the factors ofXcancel, so it does not grow with the set the way the flow box does.
The inputs are never static, since u(t) may jump inside U during the step: every term with u − u* is dynamic. The static error triples the degree of the set with each step, so monomials above max_degree (default 4) are enclosed as independent generators. The rustdoc of Method::Polynomialization has the full soundness argument.
§Keeping dependencies through reduction
The linear step and the order reduction make generators independent: the error box, the time-interval hull, and every dependent monomial that reduction encloses. In the next step’s quadratic map, products of independent generators are enclosed one by one, so a wide set loses its shape step by step. With Restructure::Lift, every independent generator of the time-point set becomes a dependent factor of its own after the Girard reduction. That is exact, and later quadratic maps then treat those factors as polynomials. Where nothing merges, it costs 1.5 to 1.7 times as much (40 steps of Van der Pol from ρ = 0.5), and gains little since the time-interval hull pairs the independent generators of X with their images: on Van der Pol from ρ = 0.5, polynomialization ends 3% narrower with lifting, and on the damped cubic of the tests 31% wider, with 6 pieces either way. Lifted pieces merge more readily, though: on the damped cubic they merge back to 3 and the run is a third faster. So the default is Restructure::Off, which keeps the generators independent.
§Adaptive steps
NonlinearSettings::adaptive takes an Adaptive with min_step and max_step. When a time step is refused, the whole time step is retried with a step shrink (default ½) times as long, and pieces are split only at min_step. After a time step whose pieces confirmed their error within easy_guesses (default 3) guesses, the next step is grow (default 1.25) times longer. Every Step records its duration, and reach_for runs until the durations add up to a horizon. Each step is sound for whatever length it uses, and refused attempts leave no set behind; the rustdoc of Adaptive has the argument.
Shorter steps are not always better. Each step adds a reduction, and on the damped cubic of the tests, steps of 0.05 diverge where steps of 0.1 do not. Growing steps also made Van der Pol’s sets wider. So set max_step to the step that works, and let Adaptive shrink only where that step fails.
§Van der Pol from wide boxes
From [1.4, 2.4] ± ρ over 0.8 s, with 12 Taylor terms, order 20 and up to 8 pieces, the width is the sum of the interval-hull widths of the widest time-point piece. “True” is the hull of a 41 × 41 grid of RK4 trajectories. “Proven” is the time up to which the sets are proven.
ρ | setting | linearization: proven, width at 0.16 s | polynomialization: proven, width at 0.16 s / 0.4 s / 0.8 s |
|---|---|---|---|
| 0.5 | Off, step 0.02 | 0.8 s, 3.51 | 0.8 s, 3.24 / 3.24 / 2.45 |
| 0.5 | Lift, step 0.02 | 0.8 s, 3.51 | 0.8 s, 3.24 / 3.21 / 2.37 |
| 0.5 | Off, step 0.01 | 0.8 s, 3.44 | 0.8 s, 3.13 / 2.94 / 1.84 |
| 0.5 | true | 2.74 / 2.30 / 1.09 | |
| 1 | Off, step 0.02 | 0.26 s, 13.9 | 0.50 s, 8.13 / 20.5 / — |
| 1 | Lift, step 0.02 | 0.26 s, 13.9 | 0.52 s, 8.06 / 16.8 / — |
| 1 | Off, step 0.02, adaptive down to 0.001 | 0.29 s, 13.9 | 0.53 s, 8.13 / 20.5 / — |
| 1 | Off, step 0.01 | 0.33 s, 11.3 | 0.67 s, 7.36 / 10.8 / — |
| 1 | Off, step 0.01, adaptive down to 0.001 | 0.33 s, 11.3 | 0.68 s, 7.36 / 10.8 / — |
| 1 | true | 5.34 / 4.66 / 2.47 |
From ρ = 1, neither method gets far: the error box of a set that wide feeds on itself. Shorter steps push the failure out from 0.50 s to 0.68 s with polynomialization, and from 0.26 s to 0.33 s with linearization; the width at 0.16 s is 7.36 against a true 5.34. From ρ = 0.5 with step 0.01, polynomialization’s set shrinks after 0.4 s, as the true set does, though at 1.7 times its width. From ρ = 0.2 the two methods end within 9% of each other.
§Splitting and merging
Both sets are reduced to the configured order after every step. reach runs a number of steps and reach_for a duration. A piece that diverges is split in two and retried, up to max_pieces pieces per step. The split cuts the factor of the piece, or the axis of its oriented box, whose halves have the smallest second-order error bound Σ_i |r|ᵀ |H_i| |r|. Factor splits keep the dependencies. The independent generators are boxed and turned into factors first, so that a factor split can reach the bulk of the set. Box splits halve the whole extent along an axis. On Van der Pol and the cubic drift, each kind wins about half of the splits. Splitting::Factors allows factor splits only, which keeps every dependency but needs more pieces: 4 instead of 2 for the cubic drift from radius 0.5 with linearization.
After each step, two pieces merge into one when the hull of their merged enclosure is at most merge_tolerance (default 10%) larger by volume than their two hulls together. The merged set is also never wider than half the narrowest piece that has diverged so far. The merge encloses λ a + (1 − λ) b as ½ (a + b) + ν ½ (a − b) with a fresh factor ν. The factors of the two pieces are paired, so two halves of a factor split merge back into their parent exactly.
use nalgebra::{DMatrix, DVector};
use polyzonotope::{SparsePolyZonotope, Zonotope};
use polyzonotope_reach::{Method, NonlinearReach, NonlinearSettings, Polynomial};
// Van der Pol: x₀' = x₁, x₁' = (1 − x₀²) x₁ − x₀.
let vdp = Polynomial::autonomous(2)
.term(0, 1.0, &[0, 1])
.term(1, 1.0, &[0, 1])
.term(1, -1.0, &[2, 1])
.term(1, -1.0, &[1, 0]);
let settings = NonlinearSettings {
method: Method::Polynomialization,
..NonlinearSettings::new(0.02)
};
let reach = NonlinearReach::new(vdp, settings);
let start = SparsePolyZonotope::from_zonotope(&Zonotope::new(
DVector::from_vec(vec![1.4, 2.4]),
DMatrix::from_diagonal_element(2, 2, 0.05),
));
let flowpipe = reach.reach_autonomous(&start, 50)?;
assert_eq!(flowpipe.len(), 50);A refusal means that no set was proven for that step. The crate does not hand back a set it could not confirm. reach returns a ReachFailure then, which holds the steps proven before the failing one and the ReachError that stopped it. ReachError is #[non_exhaustive].
§Soundness
The over-approximation is sound in real arithmetic. The Taylor remainder, the time-interval corrections and the input response are all enclosed, so the sets are larger than the true reachable set, never smaller.
For nonlinear systems, the argument is the usual one for the error check. If the error over R(τ) lies in Ψ̄, no trajectory can leave R(τ) during the step. So the linear model plus an input in Ψ̄ covers every trajectory. Polynomialization bounds x(t) − x_k by the flow over R(τ), which rests on the same hypothesis. Splits are exact, and a merge encloses the convex hull of both pieces.
With the sound feature, the rounding of the floating-point computation is covered as well. The series terms, the factorials and the remainder are computed in outward-rounded interval arithmetic, and every set operation tracks its own rounding errors. The nonlinear step evaluates f and its derivatives in interval arithmetic. The model offset and the error terms are also computed that way, so they are rounded outward too. The one exception is the coefficient i^{-i/(i-1)} − i^{-1/(i-1)} of the time-interval correction. It comes from libm::pow, which is not correctly rounded, so it is widened by a relative 1e-12 instead.
§Verification
The linear tests compare against reference trajectories: matrix exponentials of the augmented system, and inputs that jump inside U. They check the state at the end of each step and at sampled times inside it, against both the interval hull and the support function in random directions. Without inputs, the time-point set must equal e^{Ar} X at matching factor values. Removing the Taylor remainder, F, F̃ or R_p makes at least one test fail.
A cross-check against CORA: tests/cora/generate.m steps four linear systems with CORA’s linearSys/oneStep, ten steps each from the time-point set of the last, and writes the interval hulls to tests/cora/reference.txt, which tests/cora.rs compares against. The time-point hulls agree within 1e-5 of their width and the time-interval hulls within 1%. That gap is the state correction F X: under Octave, CORA cannot multiply an interval matrix with a zonotope and falls back to F times the interval hull of X, where LinearReach maps X by the center of F and boxes only the radius. Regenerate from the repository root with CORA_PATH=/path/to/CORA octave --no-gui --quiet crates/polyzonotope-reach/tests/cora/generate.m. Under Octave this needs the shims in tests/cora/octave of both crates. CORA itself is GPL-3.0 and is not part of this repository.
The nonlinear tests run every scenario with both methods: Van der Pol with an input, a pendulum with a torque input, a cubic drift that the linearization cannot see, Van der Pol from a single point, a spring whose stiffness is the input (∂²f/∂x∂u ≠ 0), and a damped cubic whose pieces split and later merge. Trajectories are integrated with a fine RK4 in f64. Every third holds the input at its upper end, every third at its lower end, and the rest jump every sub-step. They must stay inside the time-point set at every step end and inside the time-interval set at every sub-step. For linear dynamics, a step must give the same sets as LinearReach. Further tests check that an oversized set is refused, that a degree-9 field that overflows f64 is refused instead of panicking, that missing third derivatives are refused at once, that the degree stays capped over 60 steps, that splitting carries a set that one piece cannot, that a failed run keeps its proven steps, that lifting keeps a wide set narrow, and that adaptive steps shrink where a fixed step fails and grow after easy steps. The Monte Carlo checks integrate each step over its own duration.
In-crate mutation tests drop one error term at a time, each in a scenario built for it, and show a trajectory escaping: the quadratic error and the Hessian spread for linearization, and the static set, its cubic form, the cross term, δᵀ H δ, the change of the cubic term, the remainder and the input part of δ for polynomialization. The spreads of J(z*) and H(z*) come from rounding only, and no sampling can show them.
§Roadmap
- A tighter dynamic error for wide sets. From
ρ = 1, Van der Pol still fails after 0.5 s: the cross termsᵀ (½H) δmultiplies the boxes ofsandδand dominates the error box there. - A cross-check of the nonlinear reachable sets against CORA. Its generator needs MATLAB, because CORA’s symbolic derivatives do not run under Octave.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Re-exports§
pub use polyzonotope;
Structs§
- Adaptive
- Adaptive step lengths: shrink the step when a time step is refused, and grow it after easy ones.
- Interval
Tensor - A
d × d × darray of intervals: the set of all real arrays with each entry in its interval. - Linear
Reach - Precomputed one-step propagation of a
LinearSystemwith time stepr. - Linear
System x' = A x + B u.- Nonlinear
Reach - One-step and multi-step reachability of
Dynamics. - Nonlinear
Settings - How
NonlinearReachsteps through time. - Polynomial
- Polynomial dynamics: each
f_i(z)is a sum of termsc · Π_j z_j^{e_j}overz = (x, u). - Reach
Failure - A multi-step computation that stopped early, with everything it proved before the failing step.
- Step
- The reachable sets of one step
[t_k, t_k + r].
Enums§
- Method
- How
NonlinearReachabstracts the dynamics in each step. - Reach
Error - Why a reachability computation could not produce a sound result.
- Restructure
- What becomes of the generators that order reduction and the linear step make independent.
- Splitting
- How
NonlinearReach::reachsplits a piece whose step diverged.
Traits§
- Dynamics
- A vector field
x' = f(x, u)that can be enclosed over boxes.