Logic Coq:在归纳类型上定义两个以上相互递归的函数
我用两种不同的方法定义了归纳类型事件上的三个相互递归函数:使用和关键字和修复关键字,但是,Coq抱怨主参数和参考。。。分别在…中找不到。 功能的两种实现方式如下所示:Logic Coq:在归纳类型上定义两个以上相互递归的函数,logic,coq,induction,mutual-recursion,Logic,Coq,Induction,Mutual Recursion,我用两种不同的方法定义了归纳类型事件上的三个相互递归函数:使用和关键字和修复关键字,但是,Coq抱怨主参数和参考。。。分别在…中找不到。 功能的两种实现方式如下所示: Require Import List. Parameter max: list nat -> nat. Inductive event : Type := node: list event -> event. Parameter eventbool : forall (P:event->Prop) (e:e
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).
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.
Coq抱怨对轮的递归调用的主参数等于“h”而不是“tl”。即使调用轮中的h是e的子项。按照中的想法,我用以下内容替换了parentround:
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).
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
编辑定义中有第四个函数对进行轮换,但到目前为止没有问题 根据我的经验,在类型
T
和列表T
上定义相互作用确实很困难。我记得在Coq俱乐部上有一篇关于这个主题的帖子,我必须再次找到它
“简单”的解决方案是定义一种相互感应类型,其中您可以同时定义
事件
和事件列表
。但是,您将无法使用列表库…对于我来说,计算出您想要计算的内容有点困难,我将从以下内容开始:
From mathcomp Require Import ssreflect ssrbool eqtype ssrnat seq choice fintype.
From mathcomp Require Import bigop.
Definition max_seq l := \max_(x <- l) x.
Inductive event : Type :=
node : seq event -> event.
Fixpoint round_lvl (e : event) : nat :=
(* XXX: Missing condition *)
let cond_inc x := round_lvl x in
match e with
| node l => max_seq (map cond_inc l)
end.
来自mathcomp的要求导入ssreflect ssrbool eqtype ssrnat seq choice fintype。
从mathcomp需要导入bigop。
定义max_seq l:=\max_x(事件)。
定点圆形(e:事件):nat:=
(*XXX:缺失条件*)
设cond_inc x:=圆形_lvl x in
匹配
|节点l=>最大顺序(映射条件)
结束。
但是我在解析存在条件的含义时遇到了困难。我建议您先尝试在不使用Coq代码的情况下表达问题,然后可能会出现一个解决方案。在文章的链接中有一个方法是共享的,但是,它适用于两个相互递归的函数。问题是,将其推广到两个以上的函数。您的建议方法将使证明变得困难,因为我们将无法使用库中与列表相关的引理。顺便说一句,您的
round
函数存在一个问题:它不会在e
的子项上调用parentround
,而是直接在e
上调用。我认为这是不允许的。此外,在roundinc
中,调用round y
不是递减的,它应该类似于round l
其中e=node l
@Vinz函数round
是从rounds
中调用的,其中e
的子项(即h
)被传递(在round
中重命名e
没有区别)当它从roundinc
内部调用时,正如您所指出的,y
并不是递减的。实际上,真正的函数是在y
和e
上使用复杂谓词stronglysee
,其中包括y
是e
的子事件。此外,现在的问题是:即使我们包含在roundinc
中,Coq并不自动理解y
确实是e
的一个子项。