coq - 错误 : Cannot guess decreasing argument of fix. Coq

标签 coq totality

I have the following definition for terms :

Require Import Coq.Arith.Arith.
Require Import Coq.Lists.List.
Require Import Coq.Strings.String.
Import ListNotations.

Definition VarIndex:Type := nat.


Inductive Term : Type :=
   |Var : VarIndex -> Term
   |Comb: string   -> (list Term) -> Term.


 (*compare two list *)
Fixpoint beq_list {X:Type} (l l' :list X) (EqX :X -> X -> bool): bool :=
     match l with
       | [] => match l' with
                | []  => true
                | a   => false
              end
       | (x::xs) => 
              match l' with
                |[]      => false
                |(y::ys) => if (EqX x y) then beq_list xs ys EqX else false 
              end
     end.


Fixpoint length {X : Type} (l : list X) : nat :=
  match l with
  | nil       => 0
  | cons _ l' => S (length l')
  end. 

和一个函数beq_term来比较两个术语,定义如下:

Fixpoint beq_term (t1:Term)  (t2:Term) : bool :=
   match t1, t2 with
    | Var i, Var j             => beq_nat i j
    | Var _, Comb _ _           => false
    |Comb _ _, Var _            => false
    |(Comb s1 ts1), Comb s2 ts2 => if(beq_nat (length ts1) (length ts2)) 
                                   then beq_list ts1 ts2 beq_term
                                   else false
  end.

函数 beq_term 的定义产生错误消息:

Error: Cannot guess decreasing argument of fix.

所以我感兴趣的是如何说服 Coq 终止。

最佳答案

如果您希望能够在这个简单的示例中使用 Coq 的语法检查,那么将 beq_listbeq_term 写入单个函数就足够了。

Fixpoint beq_list (l l' :list Term) : bool :=
  match l, l' with
  | [], [] => true
  | (Var i)::xs, (Var j)::ys => beq_nat i j && beq_list xs ys
  | (Comb s1 ts1)::xs, (Comb s2 ts2)::ys => beq_list xs ys
  | _,_ => false
  end.

关于coq - 错误 : Cannot guess decreasing argument of fix. Coq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44097422/

相关文章:

coq - 在 Coq 中定义 Ackermann 时出错

comparison - 如何指示两种 Coq 电感类型尺寸的减小

idris - 为什么这个 'with' block 会破坏这个函数的完整性?

functional-programming - 无法猜测 Coq 中嵌套匹配修复的递减参数

emacs - 无法使用依赖类型设置认证编程

c - VSTforward_call 在非标准调用约定上失败

coq - 如何在 Coq 中编译 Logic.v

coq - 在 Coq 中重写匹配

coq - 找到一个成立良好的关系来证明函数在某个点停止减少的终止

coq - info_auto 策略在 Coq8.5 中不再打印痕迹?