Skip to main content

Dbm

Struct Dbm 

Source
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

Source

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.

Source

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.

Source

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

pub fn variables(&self) -> usize

Returns the number of actual clocks (excluding the reference clock).

§Complexity

O(1) time.

Source

pub fn dimension(&self) -> usize

Returns the matrix dimension: the actual clock count plus one for the reference clock.

§Complexity

O(1) time.

Source

pub fn is_empty(&self) -> bool

Whether the zone is empty.

§Complexity

O(1) time.

Source§

impl Dbm

Source

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::ClockOutOfRange if either clock in c is outside this zone’s clock range, including when the zone is empty;
  • Error::Range if 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²).

Source

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::ClockOutOfRange if any constraint names a clock outside this zone, even if the zone is empty;
  • Error::Range if 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.

Source

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
§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

Source

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::DimensionMismatch if bounds describes a different number of clocks, including when this zone is empty;
  • Error::Range if 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

Source

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::DimensionMismatch if other has a different clock count, even if either zone is empty;
  • Error::Range if 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

Source

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).

Source

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.

Source

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.

Source

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

Source

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.

Source

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)?);
Source

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.

Source

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:

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.

Source

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.

Trait Implementations§

Source§

impl AsRef<Dbm> for SharedDbm

Source§

fn as_ref(&self) -> &Dbm

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Dbm

Source§

fn clone(&self) -> Dbm

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dbm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DeepModel for Dbm

Source§

impl Eq for Dbm

Source§

impl From<Dbm> for SharedDbm

Source§

fn from(z: Dbm) -> SharedDbm

Wraps z without copying its matrix.

Source§

impl Hash for Dbm

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Invariant for Dbm

Source§

impl PartialEq for Dbm

Source§

fn eq(&self, other: &Dbm) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Forget for Dbm

§

impl Freeze for Dbm

§

impl Move for Dbm

§

impl RefUnwindSafe for Dbm

§

impl Send for Dbm

§

impl Sync for Dbm

§

impl Unpin for Dbm

§

impl UnsafeUnpin for Dbm

§

impl UnwindSafe for Dbm

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<F> FnGhost for F

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.