简体   繁体   English

Coq中的永远平等

[英]forall equality in Coq

I am trying to prove the following equality: 我试图证明以下相等性:

Lemma Foo (A : Type) (n : nat) (gen : forall p : nat, p < S n -> A)
(ic0 : 0 < S n) (ic1 : 0 mod S n < S n):
  gen (n - n) ic1 = gen 0 ic0.

The nn is 0 by Nat.sub_diag and 0 mod S n is also 0 by Nat.mod_0_l . nn是0通过Nat.sub_diag0 mod S n也为0通过Nat.mod_0_l However I could not easily apply these lemmas to types. 但是,我不能轻易将这些引理应用于类型。 I tried usual trick of remember/rewrite/subst but subst part fails: 我尝试了remember/rewrite/subst通常技巧,但是subst部分失败了:

   remember (gen (n-n)) as Q.
   remember (n-n) as Q1.
   rewrite Nat.sub_diag in HeqQ1.
   subst.

PS This question may use a better title. PS此问题可能使用更好的标题。 Please suggest. 请提出建议。

The subst tactic fails because remember is buggy; subst策略失败了,因为remember是越野车。 I have reported this bug here . 在这里报告了这个错误。 (As a sanity, check, finishing a goal with abstract admit , where admit comes from Coq.Compat.AdmitAxiom , should never fail with a type error. If it does, that means there's a bug in Coq (or a plugin you're using).) Coq.Compat.AdmitAxiom理智,请使用abstract admit完成目标,其中admit来自Coq.Compat.AdmitAxiom ,绝不应该因类型错误而失败。如果确实如此,则意味着Coq中存在错误(或您在使用的插件使用)。)

Here is a working proof (tested in 8.6.1 and 8.7+beta2): 这是一个有效的证明(在8.6.1和8.7 + beta2中测试):

Require Import Coq.Arith.Arith.

Lemma Foo (A : Type) (n : nat) (gen : forall p : nat, p < S n -> A)
      (ic0 : 0 < S n) (ic1 : 0 mod S n < S n):
  gen (n - n) ic1 = gen 0 ic0.
Proof.
  revert ic0 ic1; simpl; rewrite Nat.sub_diag; intros ic0 ic1.
  apply f_equal, le_unique.
Qed.

Note that you got lucky, in some sense, that n - n and 0 mod S n are judgmentally equal. 请注意,从某种意义上来说,您很幸运, n - n0 mod S n在判断上是相等的。 Using simpl exposes this fact, and allows rewrite to work. 使用simpl揭示这一事实,并允许rewrite工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM