arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2501.06084cs.CR
收藏

在Dafny中验证Fisher-Yates洗牌算法

Verifying the Fisher-Yates Shuffle Algorithm in Dafny

Stefan Zetzsche, Jean-Baptiste Tristan, Tancrede Lepoint, Mikael Mayer

AI总结:

针对Fisher-Yates洗牌算法易出现实现偏差的问题,研究人员在Dafny中通过构建函数式模型、验证分布特性、证明命令式实现与模型等价三步完成算法正确性验证,为复杂算法验证提供参考。

摘要:

Fisher-Yates洗牌是一种用于打乱有限序列的知名算法,可使每种排列的出现概率均等。尽管该算法原理简单,但其实现容易出错,可能会给生成的排列引入偏差。我们按以下步骤在Dafny中验证其正确性:首先,我们定义了一个作用于序列和随机比特流的函数式模型;其次,我们证明该函数式模型具备期望的分布特性;第三,我们定义了一个作用于数组的可执行命令式实现,并证明其与函数式模型等价。该方法可作为更复杂算法验证的参考蓝图。

英文摘要:

The Fisher-Yates shuffle is a well-known algorithm for shuffling a finite sequence, such that every permutation is equally likely. Despite its simplicity, it is prone to implementation errors that can introduce bias into the generated permutations. We verify its correctness in Dafny as follows. First, we define a functional model that operates on sequences and streams of random bits. Second, we establish that the functional model has the desired distribution. Third, we define an executable imperative implementation that operates on arrays and prove it equivalent to the functional model. The approach may serve as a blueprint for the verification of more complex algorithms.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑