我在归纳类型event上定义了三个相互递归函数,使用两种不同的方式:使用with 和fix关键字,但是,Coq 分别抱怨主要参数和The reference ... was not found in ...。函数的两种实现如下:
Require Import List.
Parameter max: list nat -> nat.
Inductive event : Type := node: list event -> event.
Parameter eventbool : forall (P:event->Prop) (e:event), {P e} + {~ P e}.
Definition event_sumbool_b (e: event) (p: event -> Prop) : bool :=
if eventbool p e then true else false.
Fixpoint parentround (e: event) : nat :=
match e with
| node l => max (rounds l)
end
with rounds l :=
match l with
| nil => 0::nil
| h::tl => round h:: rounds tl
end
with round e :=
if event_sumbool_b e roundinc then parentround e + 1 else parentround e
with roundinc e :=
exists S:list event, (forall y, List.In y S /\ round y = parentround e).
Coq 抱怨递归调用 round 的主要参数等于“h”而不是“tl”。尽管如此,呼叫回合中的h是e的子项。按照Recursive definitions over an inductive type中的想法,我将parentround替换为以下内容:
Fixpoint parentround (e: event) : nat :=
let round :=
( fix round (e: event) : nat :=
if event_sumbool_b e roundinc then parentround e + 1 else parentround e
) in
let roundinc :=
( fix roundinc (e: event) : Prop :=
exists S:list event, (forall y, List.In y S /\ round y = parentround e)
) in
match e with
| node l => max (rounds l)
end
with rounds l :=
match l with
| nil => 0::nil
| h::tl => round h:: rounds tl
end.
它现在抱怨缺少roundinc的定义。
请帮我定义这三个相互递归的函数parentround、round和roundinc。
编辑定义中有第四个函数轮次,但是到目前为止还没有问题。