Skip to content

Commit be579b5

Browse files
authored
vst/resource: Add bounded_with proof helper to show sum of Frac <= 1.0 (#2700)
1 parent 53af027 commit be579b5

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

source/vstd/resource/combinators/frac.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,17 @@ impl<T> FracGhost<T> {
325325
self.r.validate()
326326
}
327327

328+
/// Allowed values for a token's quantity when there is another token.
329+
pub proof fn bounded_with(tracked &mut self, tracked other: &Self)
330+
requires
331+
self.id() == other.id(),
332+
ensures
333+
0.0real < (old(self).frac() + other.frac()) <= 1.0real,
334+
*old(self) == *final(self),
335+
{
336+
self.r.validate_2(&other.r);
337+
}
338+
328339
/// Obtain an arbitrary resource with no information about it.
329340
/// Useful if you need a well-typed placeholder.
330341
pub proof fn dummy() -> (tracked result: Self) {

source/vstd/resource/impls/frac_opt.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ impl<T> Frac<T> {
245245
let (x, _) = self.r.validate();
246246
}
247247

248+
/// Allowed values for a token's quantity when there is another token.
249+
pub proof fn bounded_with(tracked &mut self, tracked other: &Self)
250+
requires
251+
self.id() == other.id(),
252+
ensures
253+
0.0real < (old(self).frac() + other.frac()) <= 1.0real,
254+
*old(self) == *final(self),
255+
{
256+
use_type_invariant(&*self);
257+
use_type_invariant(other);
258+
self.r.validate_with_shared(&other.r);
259+
}
260+
248261
/// Obtain shared access to the underlying resource.
249262
pub proof fn borrow(tracked &self) -> (tracked ret: &T)
250263
ensures

0 commit comments

Comments
 (0)