Coq 具有允许义务和嵌套递归的程序不动点错误

Coq 具有允许义务和嵌套递归的程序不动点错误,coq,Coq,我试图使用程序Fixpoint定义一个函数,该程序在其主体中使用另一个匿名递归函数。我当时试着使用“承认义务”,看看其他的东西是否有意义,但我犯了一个错误 这是一个简单的例子,显示了相同的错误,也许有一个更简单的错误 Require Import List. Import ListNotations. Require Import Program. Section Test. Inductive FType : Type := | Base : RType -> FType

我试图使用程序Fixpoint定义一个函数,该程序在其主体中使用另一个匿名递归函数。我当时试着使用“承认义务”,看看其他的东西是否有意义,但我犯了一个错误

这是一个简单的例子,显示了相同的错误,也许有一个更简单的错误

Require Import List.
Import ListNotations.
Require Import Program.

Section Test.

  Inductive FType : Type :=
  | Base : RType -> FType
  | Cons : RType -> FType -> FType
  with RType : Type :=
  | Empty : RType  
  | Nested : nat -> FType -> RType
  | NestedList : nat -> list FType -> RType.


  Variable ftype_size : FType -> nat.


  Program Fixpoint failing (ft : FType) {measure (ftype_size ft)} : FType :=
    match ft with
    | Base _ => ft
    | Cons hd tl =>
      match hd with
      | NestedList l rs =>
        let fix loop (rs : list FType) (i : nat) : list FType :=
            match rs with
            | [] => []
            | r' :: rs' => (failing r') :: (loop rs' (i + 1))
            end
        in
        Base (NestedList l (loop rs 0))                                  
      | _ => ft
      end
    end.
  Admit Obligations.

End Test.
所以,当运行这个函数时,它表示对循环的递归调用没有足够的参数。。我想知道为什么会这样?是否与此有关

另外,如果我定义一个索引映射并重复这个操作,我不会得到任何错误

 Section Map.
        Variables (T1 T2 : Type) (f : nat -> T1 -> T2).

Definition indexed_map (s : list T1) :=
  let fix imap s index : list T2 :=
      match s with
      | [] => []
      | hd :: tl =>  (f index hd) :: imap tl (index + 1)
      end
  in
  imap s 0.
  End Map.

  Arguments indexed_map [T1 T2].

  Program Fixpoint failing (ft : FType) {measure (ftype_size ft)} : FType :=
    match ft with
    | Base _ => ft
    | Cons hd tl =>
      match hd with
      | NestedList l rs => Base (NestedList l (indexed_map (fun i r' => (failing r')) rs))                             
      | _ => ft
      end
    end.
  Admit Obligations.

我可能可以用不同的方式定义它,但我仍然想知道为什么会发生这种情况。

进一步阅读错误消息,请注意,在printed函数中循环出现两次。第二个例子是你写的,但第一个问题是承认义务产生的公理的论点

为了避免这种情况,您可以手动完成相应的义务,并将自己的公理放在不依赖于循环的地方

Recursive call to loop has not enough arguments.
Recursive definition is:
"fun (rs0 : list FType) (i : nat) =>
 let program_branch_0 := fun _ : [] = rs0 => [] in
 let program_branch_1 :=
   fun (r' : FType) (rs' : list FType) (Heq_rs : r' :: rs' = rs0) =>
   failing r'
     (failing_obligation_1 ft failing hd tl Heq_ft l rs Heq_hd loop
        rs0 i r' rs' Heq_rs) :: loop rs' (i + 1) in
 match rs0 as rs' return (rs' = rs0 -> list FType) with
 | [] => program_branch_0
 | r' :: rs' => program_branch_1 r' rs'
 end eq_refl".
Parameter TODO : forall {A : Prop}, A.

Program Fixpoint failing ... (* Your definition *)

Next Obligation.
  apply TODO.
Qed.

(* Now the rest can still be Admitted. *)
Admit Obligations.