pub struct Dbm { /* private fields */ }Expand description
A canonical difference-bound matrix representing a set of clock valuations.
Each actual clock has a nonnegative real value; clock zero is the fixed reference clock. Each matrix entry bounds the difference between two clocks. A canonical matrix records the tightest implied bounds, while an empty DBM represents no possible valuations.
Construct with Dbm::zero, Dbm::universe, Dbm::empty, or
Dbm::try_from_constraints. Every successful transformation returns a
canonical zone or an explicit empty zone. The number of actual clocks
remains fixed; the reference clock has index 0 and is not counted in
Dbm::variables.
Two DBMs compare equal when they have the same number of clocks and represent the same zone, even if constructed from different constraints. Hashing is consistent with that equality.
§Example
use clock_dbm::{Clock, Constraint, Dbm};
let x = Clock::new(1).unwrap();
let z = Dbm::universe(1)?
.try_constrain(Constraint::le(x, Clock::ZERO, 4)?)?;
assert!(!z.is_empty());
assert_eq!(z.variables(), 1);
assert_eq!(z.dimension(), 2);Implementations§
Source§impl Dbm
impl Dbm
Sourcepub fn zero(variables: usize) -> Result<Dbm, Error>
pub fn zero(variables: usize) -> Result<Dbm, Error>
Constructs the zone containing only the all-zero clock valuation.
Each of the variables actual clocks is exactly zero.
§Errors
Error::TooManyVariables if variables exceeds MAX_VARIABLES.
§Complexity
Constructing the matrix takes O(d²) time and space, where
d = variables + 1 includes the reference clock.
Sourcepub fn universe(variables: usize) -> Result<Dbm, Error>
pub fn universe(variables: usize) -> Result<Dbm, Error>
Constructs the zone of all nonnegative-real valuations of the specified number of actual clocks, without any other constraints.
§Errors
Error::TooManyVariables if variables exceeds MAX_VARIABLES.
§Complexity
Constructing the matrix takes O(d²) time and space, where
d = variables + 1 includes the reference clock.
Sourcepub fn empty(variables: usize) -> Result<Dbm, Error>
pub fn empty(variables: usize) -> Result<Dbm, Error>
Constructs an empty zone with the specified number of actual clocks.
The empty zone contains no clock valuations but remembers its clock count. Empty zones with different clock counts are distinct.
§Errors
Error::TooManyVariables if variables exceeds MAX_VARIABLES.
§Complexity
O(1) time and no matrix allocation; the empty zone retains its
clock count.
Source§impl Dbm
impl Dbm
Sourcepub fn try_constrain(self, c: Constraint) -> Result<Dbm, Error>
pub fn try_constrain(self, c: Constraint) -> Result<Dbm, Error>
Restricts this zone by a difference constraint c.
The result contains exactly those valuations of this zone that
satisfy c. It is canonical or empty on success. Inconsistent
constraints produce a successful empty zone, not an error.
§Errors
Error::ClockOutOfRangeif either clock incis outside this zone’s clock range, including when the zone is empty;Error::Rangeif an exact finite bound needed for the result lies outside the representable integer range. Such a bound is never saturated, and no partially updated zone is returned.
§Complexity
For d = self.dimension(), an implied or directly contradictory
constraint is handled in O(1) time. Otherwise the worst-case cost
is O(d²).
Sourcepub fn try_constrain_all(
self,
cs: &[Constraint],
ws: &mut Workspace,
) -> Result<Dbm, Error>
pub fn try_constrain_all( self, cs: &[Constraint], ws: &mut Workspace, ) -> Result<Dbm, Error>
Restricts this zone by the conjunction of all constraints in cs.
The result contains exactly those valuations of this zone that
satisfy every constraint in cs. An inconsistent conjunction
produces a successful empty zone, not an error. When successful,
the resulting zone is independent of the order and repetition of
the constraints.
All clock indices are checked before modification. Intermediate
Error::Range results can depend on the computation order even
when the final mathematical zone would be the same. No partial
result is returned. ws does not affect the result.
§Errors
Error::ClockOutOfRangeif any constraint names a clock outside this zone, even if the zone is empty;Error::Rangeif an exact intermediate finite bound cannot be represented.
§Complexity
For k = cs.len() and d = self.dimension(), checking arguments
and immediate contradictions costs O(k). The selected strategy then
takes at most O(k d²) for k <= 4d, or O(k + d³) for
larger batches. ws is currently unused.
Sourcepub fn try_from_constraints(
variables: usize,
cs: &[Constraint],
ws: &mut Workspace,
) -> Result<Dbm, Error>
pub fn try_from_constraints( variables: usize, cs: &[Constraint], ws: &mut Workspace, ) -> Result<Dbm, Error>
Constructs the zone of all nonnegative-real clock valuations
satisfying every constraint in cs.
The new zone has variables actual clocks plus the fixed
reference clock at zero. With no constraints, it is the universe
of all nonnegative valuations. An inconsistent set of constraints
gives a successful empty zone. The result is canonical or empty.
ws is used as temporary workspace; it has no semantic effect.
§Errors
Error::TooManyVariablesifvariablesexceedsMAX_VARIABLES;Error::ClockOutOfRangeif a constraint refers to a clock outside the new zone;Error::Rangeif exact closure requires an unrepresentable finite intermediate bound.
§Complexity
For d = variables + 1 and k = cs.len(), allocating the
initial universe takes O(d²). Applying the constraints costs at
most O(k d²) for k <= 4d, or O(k + d³) for larger batches.
Source§impl Dbm
impl Dbm
Sourcepub fn try_extrapolate_max(
self,
bounds: &MaxBounds,
ws: &mut Workspace,
) -> Result<Dbm, Error>
pub fn try_extrapolate_max( self, bounds: &MaxBounds, ws: &mut Workspace, ) -> Result<Dbm, Error>
Computes ExtraM, a maximal-constant overapproximation of this zone.
bounds supplies a nonnegative integer ceiling for each actual
clock, in clock-index order. The reference clock (index zero) has
ceiling zero. The operation relaxes difference bounds using these
ceilings and returns the canonical zone represented by the result.
More precisely, let D[i][j] be the stored bound on
clock i - clock j, and let k(i) be clock i’s ceiling,
with k(0) = 0. For each off-diagonal entry e = D[i][j]:
e' = if Le(k(i)) ≺ e then ∞ else e
normalized[i][j] = if e' ≺ Lt(-k(j)) then Lt(-k(j)) else e'Le(c) means <= c, Lt(c) means < c, ∞ means no
restriction, and a ≺ b means bound a is strictly tighter
than bound b. On a nonempty input the diagonal remains <= 0.
The result is the canonical closure of this normalized matrix.
Every valuation of the original zone remains in the result, although the result may contain additional valuations. It is always canonical or empty on success; an empty input stays empty.
This overapproximation does not, by itself, guarantee timed-automata reachability preservation. Standard applications require suitable ceilings and restrictions on guards, invariants and resets; diagonal constraints are not covered. Idempotence is not claimed. LU-bound and other advanced abstractions are not implemented.
The ws parameter does not affect the result.
§Errors
Error::DimensionMismatchifboundsdescribes a different number of clocks, including when this zone is empty;Error::Rangeif closure of a changed matrix requires a finite bound outside the supported range. This is not an empty result, and no partially updated zone is returned.
§Complexity
Normalization takes O(d²) for d = self.dimension(). If
an entry changes, canonicalization can take O(d³) in the worst
case. Otherwise the operation takes O(d²).
Source§impl Dbm
impl Dbm
Sourcepub fn try_intersect(
self,
other: &Dbm,
ws: &mut Workspace,
) -> Result<Dbm, Error>
pub fn try_intersect( self, other: &Dbm, ws: &mut Workspace, ) -> Result<Dbm, Error>
Returns the zone of valuations that belong to both input zones.
The inputs must have the same number of actual clocks. An empty intersection is a successful empty zone, not an error. On success the result is canonical or empty, and no partial update becomes visible.
When either input is empty, the result is empty. The ws
parameter does not affect the result.
§Errors
Error::DimensionMismatchifotherhas a different clock count, even if either zone is empty;Error::Rangeif closure needs a finite bound beyond the supported integer range. This is not an empty-zone result.
§Complexity
O(d³) time in the worst case for matrix dimension
d = self.dimension(). An empty operand returns immediately.
The workspace reuses scratch storage across calls.
Source§impl Dbm
impl Dbm
Sourcepub fn is_subset_of(&self, other: &Dbm) -> Result<bool, Error>
pub fn is_subset_of(&self, other: &Dbm) -> Result<bool, Error>
Tests whether every valuation of this zone also belongs to
other.
An empty zone is a subset of every zone of the same clock count; a nonempty zone is not a subset of an empty zone.
§Errors
Error::DimensionMismatch if the two zones have different
numbers of actual clocks, even when either zone is empty.
§Complexity
O(d²) time in the worst case for matrix dimension
d = self.dimension(); empty-zone cases take O(1).
Sourcepub fn entails(&self, c: &Constraint) -> Result<bool, Error>
pub fn entails(&self, c: &Constraint) -> Result<bool, Error>
Returns whether every valuation in this zone satisfies c.
The result is true precisely when all nonnegative-real clock
valuations allowed by this zone satisfy c. This is different
from asking whether some valuation satisfies it; for that,
use Dbm::intersects_constraint. An empty zone entails every
well-formed constraint (vacuously).
§Example
use clock_dbm::{Clock, Constraint, Dbm};
let x = Clock::new(1).unwrap();
let z = Dbm::universe(1)?
.try_constrain(Constraint::le(x, Clock::ZERO, 10)?)?;
let x_below_five = Constraint::lt(x, Clock::ZERO, 5)?;
assert!(!z.entails(&x_below_five)?);
assert!(z.intersects_constraint(&x_below_five)?);
assert!(z.entails(&Constraint::le(x, Clock::ZERO, 10)?)?);§Errors
Error::ClockOutOfRange if a clock of c is not a clock of this
DBM, also when the DBM is empty.
§Complexity
O(1) time; the query does not build a new zone.
Sourcepub fn intersects_constraint(&self, c: &Constraint) -> Result<bool, Error>
pub fn intersects_constraint(&self, c: &Constraint) -> Result<bool, Error>
Tests whether at least one valuation in this zone satisfies
the difference constraint c.
Equivalently, this asks whether restricting the zone by c would
produce a nonempty result. Unlike Dbm::entails, which checks
every valuation, this returns false on an empty zone.
§Errors
Error::ClockOutOfRange if a clock in c is not among this
zone’s clocks, even when the zone is empty.
§Complexity
O(1) time; the query does not build a new zone.
Sourcepub fn difference_bound(
&self,
i: Clock,
j: Clock,
) -> Result<Option<Bound>, Error>
pub fn difference_bound( &self, i: Clock, j: Clock, ) -> Result<Option<Bound>, Error>
Returns the tightest bound on clock i - clock j that holds for
every valuation of this zone.
On a nonempty canonical zone this returns the corresponding
stored difference bound. Bound::INFINITY means that the
difference has no finite upper bound. For an empty zone, this
returns None, since every bound is vacuously satisfied.
§Errors
Error::ClockOutOfRange if i or j is outside this
zone’s clock range (checking i first), even for an empty zone.
§Complexity
O(1) time.
Source§impl Dbm
impl Dbm
Sourcepub fn future(self) -> Dbm
pub fn future(self) -> Dbm
Computes the future of this zone by allowing time to elapse.
The result contains exactly those valuations obtained by taking a valuation of this zone and advancing all actual clocks by the same nonnegative real delay. The reference clock remains zero. Differences between actual clocks are preserved; individual upper bounds on clocks are removed.
The clock count is unchanged. An empty zone remains empty, and this operation cannot fail.
§Complexity
O(d) time, where d is the number of actual clocks plus the
reference clock. The owned matrix is updated without allocation.
Sourcepub fn past(self) -> Dbm
pub fn past(self) -> Dbm
Computes the past of this zone: every valuation from which this zone can be reached by letting time elapse.
For a zone Z over n clocks the result is
past(Z) = { v ∈ (ℝ≥0)ⁿ | there is a real t ≥ 0 with v + t ∈ Z },where v + t advances all actual clocks by the same delay t
(the reference clock stays zero). Upper bounds on clocks and all
differences between actual clocks are kept. Lower bounds on single
clocks are relaxed, but only as far as nonnegativity and the
difference constraints allow: the past of {x − y ≥ 5, y ≥ 3} is
{x − y ≥ 5}, in which x ≥ 5 still holds because y ≥ 0.
The clock count is unchanged and Z ⊆ past(Z). An empty zone stays
empty with the same clock count, and this operation cannot fail.
§Complexity
O(d²) time, where d is the number of actual clocks plus the
reference clock. The owned matrix is updated without allocation.
§Examples
use clock_dbm::{Clock, Constraint, Dbm};
let x = Clock::new(1).unwrap();
let y = Clock::new(2).unwrap();
// { x − y ≥ 5, 3 ≤ y ≤ 4 }
let z = Dbm::universe(2)?
.try_constrain(Constraint::le(y, x, -5)?)?
.try_constrain(Constraint::le(Clock::ZERO, y, -3)?)?
.try_constrain(Constraint::le(y, Clock::ZERO, 4)?)?;
let p = z.clone().past();
assert!(z.is_subset_of(&p)?);
// The past keeps x − y ≥ 5 and y ≤ 4, so x ≥ 5 still holds.
let expected = Dbm::universe(2)?
.try_constrain(Constraint::le(y, x, -5)?)?
.try_constrain(Constraint::le(y, Clock::ZERO, 4)?)?;
assert_eq!(p, expected);
let x_ge_5 = Dbm::universe(2)?.try_constrain(Constraint::le(Clock::ZERO, x, -5)?)?;
assert!(p.is_subset_of(&x_ge_5)?);Sourcepub fn try_reset_zero(self, x: Variable) -> Result<Dbm, Error>
pub fn try_reset_zero(self, x: Variable) -> Result<Dbm, Error>
Resets actual clock x to zero in every valuation of this zone.
All other clock values are preserved. This is equivalent to
Dbm::try_reset with value = 0. It preserves the clock count
and leaves an empty zone empty.
§Errors
Error::ClockOutOfRange if x is not one of this zone’s actual
clocks, even when the zone is empty. No arithmetic range error occurs.
§Complexity
O(d) time, where d includes the reference clock.
Sourcepub fn try_reset(self, x: Variable, value: i32) -> Result<Dbm, Error>
pub fn try_reset(self, x: Variable, value: i32) -> Result<Dbm, Error>
Resets actual clock x to the specified nonnegative integer.
Each valuation of the result is obtained from a valuation of this
zone by setting x = value and leaving every other clock unchanged.
The clock count is unchanged; an empty zone stays empty after
argument validation.
§Errors
In the following order:
Error::ClockOutOfRangeifxis not an actual clock of this zone;Error::NegativeConstantifvalueis negative;Error::Rangeif the input zone is nonempty andvalueexceedscrate::MAX_CONSTANT.
Clock and negativity checks also apply to empty zones, but an
empty zone accepts an otherwise valid value above MAX_CONSTANT
because no bound needs to be stored.
§Complexity
O(d) time, where d includes the reference clock.
Sourcepub fn try_free(self, x: Variable) -> Result<Dbm, Error>
pub fn try_free(self, x: Variable) -> Result<Dbm, Error>
Forgets the constraints on actual clock x while retaining it.
The result contains exactly those valuations obtained by taking a
valuation of this zone, leaving the other clocks unchanged, and
choosing any nonnegative real value for x. Unlike resetting,
this does not fix x to a constant or remove it from the zone.
The clock count is unchanged, and an empty zone stays empty.
§Errors
Error::ClockOutOfRange if x is not an actual clock of this
zone, even when the zone is empty.
§Complexity
O(d) time, where d includes the reference clock.