-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it more pleasant to write a proof-by-computation over a range of…
… values (#1338)
- Loading branch information
Showing
4 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use super::prelude::*; | ||
use core::ops::Range; | ||
|
||
verus! { | ||
|
||
/// Simplify proofs-by-computation for ranges of values | ||
pub trait RangeAll where Self: Sized { | ||
spec fn all_spec(self, p: spec_fn(int) -> bool) -> bool; | ||
} | ||
|
||
pub open spec fn range_all_spec_rec(r: Range<int>, p: spec_fn(int) -> bool) -> bool | ||
decreases r.end - r.start, | ||
{ | ||
if r.start >= r.end { | ||
true | ||
} else { | ||
p(r.start) && range_all_spec_rec(r.start + 1..r.end, p) | ||
} | ||
} | ||
|
||
impl RangeAll for Range<int> { | ||
open spec fn all_spec(self, p: spec_fn(int) -> bool) -> bool { | ||
range_all_spec_rec(self, p) | ||
} | ||
} | ||
|
||
pub broadcast proof fn all_spec_implies(r: Range<int>, p: spec_fn(int) -> bool) | ||
ensures | ||
#[trigger] r.all_spec(p) ==> (forall|i| r.start <= i < r.end ==> #[trigger] p(i)), | ||
decreases r.end - r.start, | ||
{ | ||
if r.start >= r.end { | ||
} else { | ||
all_spec_implies(r.start + 1..r.end, p); | ||
} | ||
} | ||
|
||
} // verus! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters