- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在和 Coq 鬼混。具体来说,我正在尝试实现合并排序,然后证明它是有效的。
我的实现尝试是:
Fixpoint sort ls :=
match ls with
| nil => nil
| cons x nil => cons x nil
| xs =>
let (left, right) := split xs nil nil
in merge (sort left) (sort right)
end.
因此我得到的错误是:
Error:
Recursive definition of sort is ill-formed.
In environment
sort : list nat -> list nat
ls : list nat
x : nat
l : list nat
y : nat
l0 : list nat
left : list nat
right : list nat
Recursive call to sort has principal argument equal to "left" instead of
one of the following variables: "l" "l0".
Recursive definition is:
"fun ls : list nat =>
match ls with
| nil => nil
| x :: nil => x :: nil
| x :: _ :: _ =>
let (left, right) := split ls nil nil in merge (sort left) (sort right)
end".
我对这些错误的解释是,l 和 l0 是没有头部的 ls,x,以及没有 x 和 x 之后的元素的 ls(我猜它决定称之为 y?)。令人生气的是我没有在这些列表之一上递归,而是在本地定义的列表上递归。
我是否只允许递归直接来自模式匹配的内容?如果是的话,这似乎是一个严重的限制。有办法解决吗?我猜测 Coq 无法判断该函数将终止。有什么方法可以证明 left 和 right 都小于 xs 吗?
最佳答案
事实证明,CPDT 关于一般递归的章节正好解决了这个特定问题:
http://adam.chlipala.net/cpdt/html/GeneralRec.html
阅读名为“Well-founded recursion”的部分,它使用“well-founded recursion”实现合并排序,以帮助 Coq 的终止检查器满意。
可能还有其他方法可以使用函数
或程序修复点
来解决该问题,但我认为阅读有根据的递归不会有什么坏处。
关于coq - Coq 中 Fixpoint 的局限性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13794916/
有没有办法强制 Fixpoint 隐式参数在证明模式下保持隐式? 例子: Fixpoint foo {a : Set} (l : list a) : nat := match l with |
我试图在 Coq 中定义一个固定点,其中一个函数定义通过参数引用另一个函数定义,但我遇到了一些令人困惑的错误。 我已将定义最小化为: Require Import Coq.Init.Notations
我正在尝试为 lambda 演算编写一个替换函数,并且在递归调用 e 上的替换之前,如果是 lambda 抽象 (\x.e),我必须重命名 e 中的变量。我如何在 Coq 中表示这种逻辑? 下面是一个
之前,我能够证明 forall nat1: Nat, Trim nat1 -> Trim (pred nat1) 对于 pred 的以下定义。 Fixpoint pred (nat1: Nat): N
我正在和 Coq 鬼混。具体来说,我正在尝试实现合并排序,然后证明它是有效的。 我的实现尝试是: Fixpoint sort ls := match ls with | nil => nil | co
我很难理解如何在证明中使用我在 Coq 中定义的一些东西。我有这个定义和函数片段: Inductive string : Set := | E : string | s : nat -> stri
我想使用 Program Fixpoint 定义以下函数或Function在 Coq 中: Require Import Coq.Lists.List. Import ListNotations. R
我试图在 Coq 中定义并证明正确的一个函数,它可以有效地区分两个排序列表。因为它并不总是在结构上较小的项上递归(第一个或第二个列表较小),Fixpoint不会接受它,所以我尝试使用 Program
遵循章节GeneralRec 中给出的示例在 Chlipala 书中,我正在尝试编写归并排序算法。 这是我的代码 Require Import Nat. Fixpoint insert (x:nat)
作为通过有充分基础的关系来理解递归的练习,我决定实现扩展欧几里得算法。 扩展欧几里得算法适用于整数,所以我需要一些整数上有充分根据的关系。我尝试使用 Zwf 中的关系,但没有成功(我需要查看更多示例)
我是一名优秀的程序员,十分优秀!