Coq 在术语中抽象。。。导致一个术语。。。哪个打字不好

Coq 在术语中抽象。。。导致一个术语。。。哪个打字不好,coq,Coq,以下是我试图证明的: A : Type i : nat index_f : nat → nat n : nat ip : n < i partial_index_f : nat → option nat L : partial_index_f (index_f n) ≡ Some n V : ∀ i0 : nat, i0 < i → option A l : ∀ z : nat, partial_index_f (index_f n) ≡ Some

以下是我试图证明的:

  A : Type
  i : nat
  index_f : nat → nat
  n : nat
  ip : n < i
  partial_index_f : nat → option nat
  L : partial_index_f (index_f n) ≡ Some n
  V : ∀ i0 : nat, i0 < i → option A
  l : ∀ z : nat, partial_index_f (index_f n) ≡ Some z → z < i
  ============================
   V n ip
   ≡ match
       partial_index_f (index_f n) as fn
       return (partial_index_f (index_f n) ≡ fn → option A)
     with
     | Some z => λ p : partial_index_f (index_f n) ≡ Some z, V z (l z p)
     | None => λ _ : partial_index_f (index_f n) ≡ None, None
     end eq_refl
我不明白是什么导致了这个问题。我还想了解我一般如何处理它

我通过以下步骤证明了这一点,但我不确定这是最好的方法:

  destruct (partial_index_f (index_f n)).
  inversion L.
  generalize (l n0 eq_refl).
  intros. subst n0.
  replace l0 with ip by apply proof_irrelevance.
  reflexivity.
  congruence.

在Coq的理论中,当你用一个方程进行重写时,你必须对你想要替换的方程进行概括。在您的例子中,您希望替换
部分索引(index\u f n)
,因此Coq尝试概括这一点,您可以从收到的错误消息中看出这一点

现在,如果您的目标包含的内容的类型提到了您要替换的内容,那么您可能会遇到麻烦,因为这种泛化可能会使目标变得类型错误。(请注意,该类型并不完全出现在目标中,因此Coq不会试图像在目标中发生某些事情时那样处理它。)回到您的情况,您的
l
函数具有类型
∀ z:nat,部分索引(索引n)≡ 一些z→ z
,它提到了要替换的术语
部分索引(index\f n)
。在
match
的第一个分支中,将此函数应用于您抽象出来的
o=Some z
假设。在最初的目标上,
o
是您想要替换的东西,但是当Coq尝试概括时,两者不再匹配,因此出现错误消息


我不能试图自己解决这个问题,但是你可以解决这样的问题,通常通过在你的上下文中泛化提到你要替换的术语,因为这样它的类型将显示在目标中,与一个普遍量化的变量相关联。如果您的术语是全局定义的,并且您需要它在重写后具有特定的形状,以便能够执行额外的推理步骤,那么这可能不会有帮助。在这种情况下,您可能还需要对所需的引理进行泛化。

您是否尝试过
依赖销毁
  destruct (partial_index_f (index_f n)).
  inversion L.
  generalize (l n0 eq_refl).
  intros. subst n0.
  replace l0 with ip by apply proof_irrelevance.
  reflexivity.
  congruence.