Skip to content

Items of Map #5674

Answered by stefan-aws
dreamqin68 asked this question in Q&A
Aug 7, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

This verifies with Dafny 4.8.1:

lemma mapTest()
{
    var map1: map<char, int> := map['a' := 0, 'b':= 6];
    assert map1.Items == {('a', 0), ('b', 6)} by {
      forall x ensures x in map1.Items <==> x in {('a', 0), ('b', 6)} {
        if x in map1.Items {
          assert exists k :: k in map1.Keys && x.0 == k && x.1 == map1[k];
        }
      }
      SetEquality(map1.Items, {('a', 0), ('b', 6)});   
    }
} 

lemma SetEquality<T>(s: set<T>, t: set<T>)
  requires forall x :: x in s <==> x in t
  ensures s == t
{}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dreamqin68
Comment options

Answer selected by dreamqin68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants