Coq 应用程序定义失败,返回“0”;无法将道具与[目标]统一”;

Coq 应用程序定义失败,返回“0”;无法将道具与[目标]统一”;,coq,proof,Coq,Proof,在Coq中,我使用以下方法显示了向量上append的关联性: 需要导入Coq.Vectors.VectorDef Omega。 节目定义电视节目助理节目主持人(a:TVP)(b:TVQ)(c:TVR):= 追加(追加a b)c=追加a(追加b c)。 下一项义务。欧米茄。Qed。 现在我想在证明中应用这个等式。下面是我希望通过t\u app\u assoc可以证明的最简单的目标。当然,它可以通过siml来证明——这只是一个例子 Goal(追加(追加(nil-nat)(nil)))(nil) =

在Coq中,我使用以下方法显示了向量上
append
的关联性:

需要导入Coq.Vectors.VectorDef Omega。
节目定义电视节目助理节目主持人(a:TVP)(b:TVQ)(c:TVR):=
追加(追加a b)c=追加a(追加b c)。
下一项义务。欧米茄。Qed。
现在我想在证明中应用这个等式。下面是我希望通过
t\u app\u assoc
可以证明的最简单的目标。当然,它可以通过
siml
来证明——这只是一个例子

Goal(追加(追加(nil-nat)(nil)))(nil)
=追加(nil)(追加(nil))(nil)))。
应用t_app_assoc。
应用
失败,原因如下:

错误:无法将“道具”与
“附加(附加(nil-nat)(nil-nat))(nil-nat)=
附加(无nat)(附加(无nat)(无nat))”

我如何申请应用程序协会?还是有更好的方法来定义它?我想我需要一个
程序定义
,因为简单地使用
引理
会导致类型错误,因为
tv(p+(q+r))
tv(p+q+r)
与Coq不一样。

序言 我想你想证明的是向量连接是相联的,然后用这个事实作为引理

但是
t_app_assoc
根据您的定义,它具有以下类型:

t_app_assoc
     : forall (v : Type) (p q r : nat), t v p -> t v q -> t v r -> Prop
Check append (append a b) c : t A (p + q + r).
cast :
  forall (A : Type) (m : nat),
  Vector.t A m -> forall n : nat, m = n -> Vector.t A n
您基本上希望使用
而不是
:=
,如下所示

From Coq Require Import Vector Arith.
Import VectorNotations.
Import EqNotations.  (* rew notation, see below *)

Section Append.

Variable A : Type.
Variable p q r : nat.
Variables (a : t A p) (b : t A q) (c : t A r).

Fail Lemma t_app_assoc :
  append (append a b) c = append a (append b c).
不幸的是,我们甚至不能用通常的齐次等式来表示这样的引理

左侧具有以下类型:

t_app_assoc
     : forall (v : Type) (p q r : nat), t v p -> t v q -> t v r -> Prop
Check append (append a b) c : t A (p + q + r).
cast :
  forall (A : Type) (m : nat),
  Vector.t A m -> forall n : nat, m = n -> Vector.t A n
而右边是

Check append a (append b c) : t A (p + (q + r)).
由于
ta(p+q+r)
ta(p+(q+r))
不同,我们不能用
=
来说明上述引理

让我描述一些解决这个问题的方法:

rew
符号 在这里,我们只使用自然数加法的结合性法则将RHS类型转换为
ta(p+q+r)

要使其正常工作,需要先导入EqNotations.

cast
功能 这是一个常见问题,因此
Vector
库的作者决定提供具有以下类型的
cast
函数:

t_app_assoc
     : forall (v : Type) (p q r : nat), t v p -> t v q -> t v r -> Prop
Check append (append a b) c : t A (p + q + r).
cast :
  forall (A : Type) (m : nat),
  Vector.t A m -> forall n : nat, m = n -> Vector.t A n
让我来说明如何用它来证明向量的结合定律。但是让我们先证明下面的辅助引理:

Lemma uncast {X n} {v : Vector.t X n} e :
  cast v e = v.
Proof. induction v as [|??? IH]; simpl; rewrite ?IH; reflexivity. Qed.
现在我们都准备好了:

Lemma t_app_assoc_cast (a : t A p) (b : t A q) (c : t A r) :
  append (append a b) c = cast (append a (append b c)) (plus_assoc _ _ _).
Proof.
  generalize (Nat.add_assoc p q r).
  induction a as [|h p' a' IH]; intros e.
  - now rewrite uncast.
  - simpl; f_equal. apply IH.
Qed.
异质平等(又称约翰·梅杰平等) 如果比较齐次等式的定义

Inductive eq (A : Type) (x : A) : A -> Prop :=
  eq_refl : x = x.
Inductive JMeq (A : Type) (x : A) : forall B : Type, B -> Prop :=
  JMeq_refl : x ~= x.
以及异质平等的定义

Inductive eq (A : Type) (x : A) : A -> Prop :=
  eq_refl : x = x.
Inductive JMeq (A : Type) (x : A) : forall B : Type, B -> Prop :=
  JMeq_refl : x ~= x.
您将看到,使用
JMeq
时,LHS和RHS不必是相同的类型,这就是为什么
t_app_assoc_JMeq
的语句看起来比前面的语句简单一些的原因

向量的其他方法 见例。 及; 我也发现
也非常有用。

这非常有用,谢谢!只是,我没能证明rew/cast引理(也没发现有人使用它…)。我真的不知道从哪里开始;“展开投射”不会产生任何有用的结果。