gpt4 book ai didi

functional-programming - 在 ACL2 中编写 select() 函数

转载 作者:太空宇宙 更新时间:2023-11-03 18:54:35 25 4
gpt4 key购买 nike

我正在尝试在 ACL2(特别是 ACL2)中编写一个函数,它接受一个列表和一个自然数,并返回列表中给定索引处的项目。所以 (select (list 1 2 3) 2) 会返回 3。

这是我的代码:

;; select: List x Nat -> All
(defunc select (l n)
:input-contract (and (listp l) (natp n))
:output-contract t
(if (equal 0 n)
(first l)
(select (rest l) (- n 1))))

我收到以下错误:

Query: Testing body contracts ... 

**Summary of Cgen/testing**
We tested 50 examples across 1 subgoals, of which 48 (48 unique) satisfied
the hypotheses, and found 1 counterexamples and 47 witnesses.

We falsified the conjecture. Here are counterexamples:
[found in : "top"]
-- ((L NIL) (N 0))

Test? found a counterexample.
Body contract falsified in:
-- (ACL2::EXTRA-INFO '(:GUARD (:BODY SELECT)) '(FIRST L))

非常感谢任何帮助!

最佳答案

消息对我来说似乎很清楚:您正在尝试获取空列表的第一个元素,这与您的规范冲突。

基于 this reference ,似乎 first 需要一个非空列表,而当您的输入为 nil 时,car 返回 nil

要么使用 endp 测试明确处理 nil 情况,要么使用 car 而不是 first

关于functional-programming - 在 ACL2 中编写 select() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34999601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com