Coq中的双向递归函数与终止检验
编辑Coq中的双向递归函数与终止检验,coq,totality,Coq,Totality,编辑 Require Import Bool List ZArith. Variable A: Type. Inductive error := | Todo. Inductive result (A : Type) : Type := Ok : A -> result A | Ko : error -> result A. Variable bool_of_result : result A -> bool. Var
Require Import Bool List ZArith.
Variable A: Type.
Inductive error :=
| Todo.
Inductive result (A : Type) : Type :=
Ok : A -> result A | Ko : error -> result A.
Variable bool_of_result : result A -> bool.
Variable rules : Type.
Variable boolean : Type.
Variable positiveInteger : Type.
Variable OK: result unit.
Definition dps := rules.
Inductive dpProof :=
| DpProof_depGraphProc : list
(dps * boolean * option (list positiveInteger) * option dpProof) -> dpProof.
Fixpoint dpProof' (R D: rules) (p: dpProof) {struct p}:=
match p with
| DpProof_depGraphProc cs => dpGraphProc R D cs
end
with dpGraphProc (R D: rules ) cs {struct cs} :=
match cs with
| nil => Ko unit Todo
| (_, _, _, op) :: cs' =>
match op with
| None => Ko unit Todo
| Some p2 => dpProof' R D p2
end
end.
我收到一条错误消息说:
对dpProof的递归调用的主参数等于
"p2" instead of "cs'".
Recursive definition is:
"fun (R D : rules)
(cs : list
(dps * boolean * option (list positiveInteger) *
option dpProof)) =>
match cs with
| nil => Ko unit Todo
| (_, _, _, Some p2) :: _ => dpProof' R D p2
| (_, _, _, None) :: _ => OK
end".
如果我不使用交互递归和嵌套不动点,它将合并并通过终止检查器。下面是成功组合的代码
Fixpoint dpProof' (R D: rules) (p: dpProof) {struct p}:=
match p with
| DpProof_depGraphProc cs =>
match cs with
| nil => Ko _ Todo
| (_, _, _, op) :: cs' =>
match op with
| None => Ko unit Todo
| Some p2 => dpProof' R D p2
end
end end.
我想更深入地了解它无法通过终止检查的原因?是不是因为他们猜不出论点在下降?是否有任何方法可以使用相互递归来表示我的函数dpGraphProc
另外,如何编写检查整个列表的函数
dpGraphProc
?在这里,我不知道如何使用参数cs'
相互递归既可以用于单个归纳数据类型,也可以用于在单个归纳定义中一起定义的不同归纳数据类型。在您的例子中,您使用的是多态数据类型prod(对的类型)、list和option,它们在dpProof之前已经定义
嵌套的固定点方法没有限制。代码段中有大量未声明的标识符,并且它不包含错误消息中提到的任何出现的
p2
。你能提供一个例子,确切地说,导致上述消息?这次我编辑和测试的代码组合,并提供错误。谢谢你的病人。