在Coq中进行验证时,如何在支柱上进行模式匹配,而无需消除类型

在Coq中进行验证时,如何在支柱上进行模式匹配,而无需消除类型,coq,dependent-type,theorem-proving,type-theory,lean,Coq,Dependent Type,Theorem Proving,Type Theory,Lean,我试图证明排序列表的尾部是在Coq中排序的,使用模式匹配而不是策略: Require Import Coq.Sorting.Sorted. Definition tail_also_sorted {A : Prop} {R : relation A} {h : A} {t : list A} (H: Sorted R (h::t)) : Sorted R t := match H in Sorted _ (h::t) return So

我试图证明排序列表的尾部是在Coq中排序的,使用模式匹配而不是策略:

Require Import Coq.Sorting.Sorted.

Definition tail_also_sorted {A : Prop} {R : relation A} {h : A} {t : list A} 
                            (H: Sorted R (h::t)) : Sorted R t :=
match H in Sorted _ (h::t) return Sorted _ t with
  | Sorted_nil _ => Sorted_nil R
  | Sorted_cons rest_sorted _ => rest_sorted
end.
但是,这种方法失败了,因为:

Error:
Incorrect elimination of "H" in the inductive type "Sorted":
the return type has sort "Type" while it should be "Prop".
Elimination of an inductive object of sort Prop
is not allowed on a predicate in sort Type
because proofs can be eliminated only to build proofs.
我怀疑这在底层演算中是可能的,因为下面是精益代码类型检查,精益也是基于CIC构建的:

inductive is_sorted {α: Type} [decidable_linear_order α] : list α -> Prop
| is_sorted_zero : is_sorted []
| is_sorted_one : ∀ (x: α), is_sorted [x]
| is_sorted_many : ∀ {x y: α} {ys: list α}, x < y -> is_sorted (y::ys) -> is_sorted (x::y::ys)

lemma tail_also_sorted {α: Type} [decidable_linear_order α] : ∀ {h: α} {t: list α}, 
                                 is_sorted (h::t) -> is_sorted t
| _ [] _ := is_sorted.is_sorted_zero
| _ (y::ys) (is_sorted.is_sorted_many _ rest_sorted) := rest_sorted
inductive is_sorted{α:Type}[可判定的线性顺序α]:listα->Prop
|是否已排序\u零:是否已排序[]
|是否已排序∀ (x:α),是_排序的[x]
|排序是否很多:∀ {xy:α}{ys:listα},xis_sorted(y::ys)->is_sorted(x::y::ys)
引理尾_也_排序{α:类型}[可判定_线性_顺序α]:∀ {h:α}{t:listα},
是否排序(h::t)->是否排序t
|_[].:=已排序。已排序吗
|(y::ys)(is_sorted.is_sorted_many_rest_sorted):=rest_sorted

这似乎是一个bug。我认为问题在于以下几点:

in Sorted _ (h::t)
在纯CIC中,不允许对
match
表达式进行此类注释。相反,您需要编写如下内容:

Definition tail_also_sorted {A : Prop} {R : relation A} {h : A} {t : list A}
                            (H: Sorted R (h::t)) : Sorted R t :=
match H in Sorted _ t'
        return match t' return Prop with
               | [] => True
               | h :: t => Sorted R t
               end with
| Sorted_nil _ => I
| Sorted_cons rest_sorted _ => rest_sorted
end.
不同之处在于,
in
子句中的索引现在是一个新变量,绑定在
return
子句中。为了使您不必编写如此糟糕的程序,Coq允许您在子句中的中放入比通用变量稍微复杂的表达式,就像您使用的那样。为了避免损害可靠性,此扩展实际上被编译为核心CIC术语。我想在某个地方有一个bug,这个翻译产生了以下术语:

Definition tail_also_sorted {A : Prop} {R : relation A} {h : A} {t : list A}
                            (H: Sorted R (h::t)) : Sorted R t :=
match H in Sorted _ t'
        return match t' return Type with
               | [] => True
               | h :: t => Sorted R t
               end with
| Sorted_nil _ => I
| Sorted_cons rest_sorted _ => rest_sorted
end.

请注意
返回类型
注释。事实上,如果您尝试在Coq中输入此代码段,您会收到与您看到的完全相同的错误消息。

报告此问题的最佳位置是哪里?