triggers - Dafny 没有条件可以触发谓词

标签 triggers verification dafny

我有以下用于 tic tac toe 游戏的 Dafny 代码片段,用于检查玩家 1 是否在棋盘上有获胜行:

predicate isWinRowForPlayer1(board: array2<int>)
  reads board
  requires board.Length0 == board.Length1 == 3 && isValidBoard(board)
{
  exists i :: 0 <= i < board.Length0 ==> (forall j :: 0 <= j < board.Length1 ==> board[i, j] == 1)
}

目前,我在该谓词主体以及我的程序中拥有的所有其他谓词(对于 winColumn、winDiag、...等)

如果有人能帮我解决这个问题,我将不胜感激

最佳答案

这是一种方法:引入一个辅助函数来保存 forall 量词。然后,Dafny 将使用此辅助函数作为外部 exists 量词的触发器,从而修复警告。

predicate RowIsWinRowForPlayer1(board: array2<int>, row: int)
    reads board
    requires 0 <= row < board.Length0
{
    forall j :: 0 <= j < board.Length1 ==> board[row, j] == 1
}

predicate isWinRowForPlayer1(board: array2<int>)
  reads board
  requires board.Length0 == board.Length1 == 3 && isValidBoard(board)
{
  exists i :: 0 <= i < board.Length0 ==> RowIsWinRowForPlayer1(board, i)
}

参见this answer有关触发器的更多信息。

关于triggers - Dafny 没有条件可以触发谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49649019/

相关文章:

javascript - 时间戳日期和时间格式 - Apps 脚本 - 格式化日期和时间

quantifiers - Dafny/Boogie 中的触发器是什么?

arrays - Dafny:将 "forall"量词与 "reads"或 "modifies"子句一起使用

arrays - Dafny:复制数组区域方法验证

php - 如何自动将(数据库上)的新更新反射(reflect)到用户页面

Mysql:使用 SUBSTRING 触发

mysql - 创建 mysql 触发器时出现 1064 错误

ssl - 仅允许客户端使用组织 CA 签名的证书进行连接

authentication - 双向 SSL 验证

verification - 现金契约(Contract)验证