小编Car*_*arl的帖子

使用 Dafny,验证函数来计算小于阈值的整数集元素

我对任何可验证的 CountLessThan 编写方式持开放态度。这是我所拥有的:

function SetLessThan(numbers: set<int>, threshold: int): set<int>
{
  set i | i in numbers && i < threshold
}
method CountLessThan(numbers: set<int>, threshold: int) returns (count: int)
  ensures count == |SetLessThan(numbers, threshold)|
{
  count := 0;
  var shrink := numbers;
  var grow := {};
  while |shrink | > 0
    decreases shrink
    invariant shrink + grow == numbers
    invariant count == |SetLessThan(grow, threshold)|
  {
    var i: int :| i in shrink;
    shrink := shrink - {i};
    grow := grow …
Run Code Online (Sandbox Code Playgroud)

formal-verification dafny

1
推荐指数
1
解决办法
91
查看次数

标签 统计

dafny ×1

formal-verification ×1