Skip to content

Commit

Permalink
prove map axioms
Browse files Browse the repository at this point in the history
  • Loading branch information
elaustell committed Jul 20, 2023
1 parent 90f7499 commit a6c72a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
22 changes: 15 additions & 7 deletions source/pervasive/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,23 +516,31 @@ pub proof fn axiom_map_remove_different<K, V>(m: Map<K, V>, key1: K, key2: K)
{
}

// TODO: might not have brought this over correctly
// Ported from Dafny prelude
#[verifier(external_body)]
//#[verifier(external_body)]
//#[verifier(broadcast_forall)]
pub proof fn axiom_map_new_domain<K,V>(fk: FnSpec(K) -> bool, fv: FnSpec(K) -> V)
ensures
#[trigger] Map::<K,V>::new(fk,fv).dom() == Set::<K>::new(|k: K| fk(k))
{}
{
assert(Set::new(fk) =~= Set::<K>::new(|k: K| fk(k)));
}

// TODO: might not have brought this over correctly
// Ported from Dafny prelude
#[verifier(external_body)]
//#[verifier(external_body)]
//#[verifier(broadcast_forall)]
pub proof fn axiom_map_new_values<K,V>(fk: FnSpec(K) -> bool, fv: FnSpec(K) -> V)
ensures
#[trigger] Map::<K,V>::new(fk,fv).values() == Set::<V>::new(|v: V| exists |k: K| #[trigger] fk(k) && #[trigger] fv(k) == v),
{}
#[trigger] Map::<K,V>::new(fk,fv).values() == Set::<V>::new(|v: V| (exists |k: K| #[trigger] fk(k) && #[trigger] fv(k) == v)),
{
let keys = Set::<K>::new(fk);
let values = Map::<K,V>::new(fk,fv).values();
let map = Map::<K,V>::new(fk,fv);

assert(map.dom() =~= keys);
assert(forall |k: K| #[trigger] fk(k) ==> keys.contains(k));
assert(values =~= Set::<V>::new(|v: V| (exists |k: K| #[trigger] fk(k) && #[trigger] fv(k) == v)));
}

#[verifier(external_body)]
#[verifier(broadcast_forall)]
Expand Down
3 changes: 3 additions & 0 deletions source/pervasive/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ macro_rules! seq {
};
}

//TODO: change all names from axiom to lemma
// change seq_magic to lemma_seq_properties or something
//TODO: move as much as you can to seq_lib
// auto style axiom bundle
pub proof fn seq_magic<A>()
ensures
Expand Down
6 changes: 6 additions & 0 deletions source/pervasive/set.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// TODO: make a table of every Dafny lemma/axiom and the verus equivalent
// include notes of any skipped lemmas
// include this in PR description

use core::marker;

#[allow(unused_imports)]
Expand Down Expand Up @@ -649,6 +653,8 @@ macro_rules! set {
};
}

//TODO: change all names from axiom to lemma (and magic to properties????)
//TODO: move as much as you can to set_lib
// auto style axiom bundle
pub proof fn set_magic<A>()
ensures
Expand Down

0 comments on commit a6c72a8

Please sign in to comment.