1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Nonlinear dynamics `x' = f(x, u)` with their first, second and
//! (optionally) third derivatives, all enclosed in interval arithmetic.
use Vec;
use ;
pub use Polynomial;
pub use IntervalTensor;
/// A vector field `x' = f(x, u)` that can be enclosed over boxes.
///
/// Every method takes `z = (x, u)`: first the `states()` state intervals,
/// then the `inputs()` input intervals. Each result must contain the exact
/// value for every point of the box `z`. A point interval asks for the value
/// at that point; the enclosure then only has to cover rounding. When a
/// bound overflows, return an infinite one instead of panicking: the step
/// then refuses with [`ReachError::AbstractionDiverged`](crate::ReachError::AbstractionDiverged).
/// Under `sound`, the interval operations of `polyzonotope` panic when an
/// operand is infinite, so check before adding to an overflowed value.
///
/// [`Polynomial`] implements this for polynomial dynamics. For other
/// functions, implement it with interval extensions of the elementary
/// functions; a loose enclosure stays sound, it only makes the sets larger.
///
/// # Examples
///
/// The undamped Duffing oscillator `x₀' = x₁, x₁' = −x₀³`, by hand:
///
/// ```
/// use polyzonotope_reach::Dynamics;
/// use polyzonotope_reach::polyzonotope::{Interval, IntervalMatrix};
///
/// struct Duffing;
///
/// impl Dynamics for Duffing {
/// fn states(&self) -> usize { 2 }
/// fn inputs(&self) -> usize { 0 }
/// fn flow(&self, z: &[Interval]) -> Vec<Interval> {
/// vec![z[1], -(z[0] * z[0] * z[0])]
/// }
/// fn jacobian(&self, z: &[Interval]) -> IntervalMatrix {
/// let mut j = IntervalMatrix::zeros(2, 2);
/// j.0[(0, 1)] = Interval::point(1.0);
/// j.0[(1, 0)] = Interval::point(-3.0) * z[0] * z[0];
/// j
/// }
/// fn hessians(&self, z: &[Interval]) -> Vec<IntervalMatrix> {
/// let mut h = IntervalMatrix::zeros(2, 2);
/// h.0[(0, 0)] = Interval::point(-6.0) * z[0];
/// vec![IntervalMatrix::zeros(2, 2), h]
/// }
/// }
///
/// let f = Duffing.flow(&[Interval::point(2.0), Interval::point(1.0)]);
/// assert_eq!(f[1], Interval::point(-8.0));
/// ```