达芙妮展平套套

Dafny flatten set of sets

所以我试图从一组集合中获取所有元素,但出现错误:

"a set comprehension must produce a finite set, but Dafny's heuristics can't figure out how to produce a bounded set of values for 'x' "

我认为这可能与您无法获取集合的基数有关。

感谢所有帮助。

function flatten(nested: set<set<int>>) : set<int>
    { set x | forall y :: y in nested && x in y :: x }

也许以下内容会满足您的要求:

function flatten(nested: set<set<int>>) : set<int>
{
    set x, y | y in nested && x in y :: x
}

你的定义完全不同。它说的是 "the set of elements such that for all y at all of type set<int>, y is in nested and x is in y." 这通常是错误的(因此是无用的),因为它要求 nested 是一个包含 所有 类型集的有限集set<int>.

最后,还要注意您 可以 使用表达式 |S|.

获得集合 S 的基数