1

我正在尝试在 ACL2(特别是 ACL2s)中编写一个函数,该函数接受一个列表和一个自然数,并在给定索引处返回列表中的项目。所以 (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))

任何帮助深表感谢!

4

1 回答 1

1

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

基于此参考,似乎first需要一个非空列表,而当您的输入为 时car返回。nilnil

nil您可以通过测试明确处理该案例,endp或者使用car而不是first.

于 2016-01-25T19:51:57.147 回答