为什么我的本地 coq 的行为与标准 coq(例如 JsCoq)不同?

发布于 2025-01-12 15:45:36 字数 1212 浏览 7 评论 0原文

我正在经历这个问题中的简单示例 如何在 Coq 中将“+ 1”(加一)重写为“S”(succ)? 但是该证明在我的本地计算机上不起作用,尽管它在 jscoq 上工作。这就是我的证明陷入困境的地方:

Lemma s_is_plus_one: 
  forall n:nat, 
    S n = n + 1.
Proof.
  intros.
  induction n.
  - by reflexivity.
  - simpl. rewrite -> IHn. (* reflexivity. Qed. *)

在那之后,自反性应该得出证明,但在我的情况下,它没有,但进入了这种奇怪的状态:

n: nat
IHn: n.+1 = n + 1
1/1
(n + 1).+1 = n + 1 + 1

而不是

1 goal

n ℕ 
IHn S n = n + 1 
S (n + 1) = S (n + 1)

Jscoq 有版本:

jsCoq (0.14.2), Coq 8.14.1/81400
OCaml 4.12.0, Js_of_ocaml 3.11.0

而我的计算机有

(meta_learning) brandomiranda~/coq4brando ❯ coqc -v
The Coq Proof Assistant, version 8.14.1
compiled with OCaml 4.10.2

我没想到的差异但确实有。

到底是怎么回事?为什么 Coq 在两者中的表现不一样?

另外, Print Nat.add_comm. 由于某种原因而失败,我认为是相同的原因:

Nat.add_comm not a defined object.
Not in proof mode.

请注意,我知道也许仅在 lhs 上的 S n 上使用归纳假设进行重写可能会工作后是一个简单的...但我不知道该怎么做(我很好奇学习),但我的问题的重点不是如何让它在我的 Coq 上工作,而是为什么我的 coq 没有表现出与“标准 coq”相同。

I was going through the trivial example in this question How can I rewrite "+ 1" (plus one) to "S" (succ) in Coq? but the proof does not work in my local computer despite it working on jscoq. This is where my proof gets stuck:

Lemma s_is_plus_one: 
  forall n:nat, 
    S n = n + 1.
Proof.
  intros.
  induction n.
  - by reflexivity.
  - simpl. rewrite -> IHn. (* reflexivity. Qed. *)

after that a reflexivity should conclude the proof but in my case it doesn't but gets into this weird state:

n: nat
IHn: n.+1 = n + 1
1/1
(n + 1).+1 = n + 1 + 1

instead of

1 goal

n ℕ 
IHn S n = n + 1 
S (n + 1) = S (n + 1)

Jscoq has version:

jsCoq (0.14.2), Coq 8.14.1/81400
OCaml 4.12.0, Js_of_ocaml 3.11.0

and my computer has

(meta_learning) brandomiranda~/coq4brando ❯ coqc -v
The Coq Proof Assistant, version 8.14.1
compiled with OCaml 4.10.2

which I wouldn't have expected a difference but there is.

What is going on? Why is Coq not acting the same in both?

Also, Print Nat.add_comm. is failing for some reason that I assume is the same reason:

Nat.add_comm not a defined object.
Not in proof mode.

Note I am aware that perhaps doing a rewrite with the induction hypothesis only on the S n on the lhs might have worked followed by a simpl...but I don't know how to do that (which I am curious to learn) but the point of my question is not how to make it work on my Coq but why my coq is not acting the same as the "standard coq".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫思念不要吵 2025-01-19 15:45:36

鉴于您的目标提到了 .+1,我怀疑您正在使用自然数的 SSReflect 库。 SSReflect 的加法定义并未通过 simpl 策略进行简化,因此 simpl 在这里不会执行任何操作。

您可以通过显式展开 SSReflect 定义来修复此行为,如下所示:

From mathcomp Require Import all_ssreflect.

Goal forall n, n.+1 = n + 1.
Proof.
rewrite addnE. intros n.
induction n as [|n IH].
- reflexivity.
- simpl. rewrite IH. reflexivity.
Qed.

Given that your goal mentions the .+1, I suspect that you are using the SSReflect library of natural numbers. The SSReflect definition of addition is not simplified by the simpl tactic, hence simpl would not do anything here.

You can fix this behavior by explicity unfolding the SSReflect definition as follows:

From mathcomp Require Import all_ssreflect.

Goal forall n, n.+1 = n + 1.
Proof.
rewrite addnE. intros n.
induction n as [|n IH].
- reflexivity.
- simpl. rewrite IH. reflexivity.
Qed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文