coq - 如何通过等式证明进行推理?

标签 coq

假设我对加法的定义略有不同,对向量附加的定义也略有不同:

From Coq Require Import Vector.

Definition myAddNat a b := nat_rect _ b (fun _ p => S p) a.

Theorem rewrite_myAddNat a b : myAddNat a b = (a + b)%nat.
Proof.
  induction a.
  { reflexivity. }
  {
    simpl.
    congruence.
  }
Defined.

Definition myAppend T m n : Vector.t T m -> Vector.t T n -> Vector.t T (myAddNat m n).
  rewrite rewrite_myAddNat.
  apply Vector.append.
Defined.

我希望能够证明以下内容:


Theorem myAppend_cons_1 T m n h a b :
    myAppend T (S m) n (cons T h m a) b =
    cons T h (myAddNat m n) (myAppend T m n a b).
Proof.
  induction a.
  { reflexivity. }
  {
    simpl.
    unfold myAppend.
    (* stuck! *)
  }
Abort.

我最终陷入了两个非常接近的术语上,除了它们各自在不同的位置上有一个相等的转换,我不知道如何处理。

我考虑将定理陈述更改为:

Theorem myAppend_cons T m n h a b :
    existT _ _ (myAppend T (S m) n (cons T h m a) b) =
    existT _ _ (cons T h (myAddNat m n) (myAppend T m n a b)).

以便能够暂时让方程两边有不同的类型,但一直没能在证明上取得更大的进展。

所以:

1)有没有一个好方法来证明任一定理

或者,

2) 我应该以不同的方式编写 myAppend 以使我的生活更轻松吗?

最佳答案

这是一个快速回答:

Theorem myAppend_cons_1 T m n h a b :
    myAppend T (S m) n (cons T h m a) b =
    cons T h (myAddNat m n) (myAppend T m n a b).
Proof.
  unfold myAppend, eq_rect_r; simpl.
  rewrite !eq_trans_refl_l, !eq_sym_map_distr.
  now destruct (eq_sym _).
Qed.

关于coq - 如何通过等式证明进行推理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57296362/

相关文章:

coq - 如何实现 Coq?

coq - 如何让 Coq 接受以下 Fixpoint?

logic - 如何在 coq 中向后使用引理 a=b ?

dictionary - 在 Coq 中创建字典/ map

functional-programming - Coq 通过两种实现对阶乘程序进行验证

coq - 如何证明(2^2)%R = 4%R

abstract-syntax-tree - 如何在抽象树中表示替换的 kleisli 组合

logic - 如何证明排中律在 Coq 中是无可辩驳的?

coq proof : tactic absurd, 它是如何工作的?

list - Coq:依赖列表上的类型不匹配可以通过证明来解决