为什么在证明基本情况后,Coq 会删除/清除我的证明中断言的引理?

发布于 2025-01-13 08:23:33 字数 1709 浏览 5 评论 0原文

我想在证明的顶部断言一些引理,并将它们重新用于每个未来的目标。我做到了:

  Theorem add_comm_eauto_using:
    forall n m: nat,
      n + m = m + n.
    Proof.
      intros. induction n.
      assert (H: forall n, n + 0 = n) by eauto using n_plus_zero_eq_n.
      assert (H': forall n m, S (n + m) = n + S m) by eauto using Sn_plus_m_eq_n_plus_Sm.
      - eauto with *.

但在我证明了基本情况之后,假设就从当地环境中消失了!

为什么会发生这种情况以及如何阻止 coq 删除我的本地引理并将它们永远保留在这个证明中的本地上下文中?最好在证明中。身体 Qed。 身体。


脚本:


  Theorem n_plus_zero_eq_n:
  forall n:nat,
    n + 0 = n.
  Proof.
    intros.
    induction n as [| n' IH].
    - simpl. reflexivity.
    - simpl. rewrite -> IH. reflexivity.
  Qed.

  Theorem Sn_plus_m_eq_n_plus_Sm:
  forall n m : nat,
    S (n + m) = n + (S m).
  Proof.
    intros n m.
    induction n as [| n' IH].
    - auto.
    - simpl. rewrite <- IH. reflexivity.  
  Qed.

  Theorem add_comm :
  forall n m : nat,
    n + m = m + n.
  Proof.
    intros.
    induction n as [| n' IH].
    - simpl. rewrite -> n_plus_zero_eq_n. reflexivity.
    - simpl. rewrite -> IH. rewrite -> Sn_plus_m_eq_n_plus_Sm. reflexivity. 
  Qed.

  (* auto using proof *)
  Theorem add_comm_eauto_using_auto_with_start:
  forall n m: nat,
    n + m = m + n.
  Proof.
    intros. induction n.
    Print Hint.
      - auto with *.
      - auto with *. 
    Qed.

  Theorem add_comm_eauto_using:
    forall n m: nat,
      n + m = m + n.
    Proof.
      intros. induction n.
      assert (H: forall n, n + 0 = n) by eauto using n_plus_zero_eq_n.
      assert (H': forall n m, S (n + m) = n + S m) by eauto using Sn_plus_m_eq_n_plus_Sm.
      - eauto with *.
      - eauto using IHn, H, H'. 

I want to assert some lemmas at the top of the proof and re-use them for every future goal. I did:

  Theorem add_comm_eauto_using:
    forall n m: nat,
      n + m = m + n.
    Proof.
      intros. induction n.
      assert (H: forall n, n + 0 = n) by eauto using n_plus_zero_eq_n.
      assert (H': forall n m, S (n + m) = n + S m) by eauto using Sn_plus_m_eq_n_plus_Sm.
      - eauto with *.

but after I prove the base case the hypothesis dispear from the local context!

Why does that happen and how to I stop coq removing my local lemmas and keeping them in the local context in this proof forever? Ideally inside the Proof. body Qed. body.


script:


  Theorem n_plus_zero_eq_n:
  forall n:nat,
    n + 0 = n.
  Proof.
    intros.
    induction n as [| n' IH].
    - simpl. reflexivity.
    - simpl. rewrite -> IH. reflexivity.
  Qed.

  Theorem Sn_plus_m_eq_n_plus_Sm:
  forall n m : nat,
    S (n + m) = n + (S m).
  Proof.
    intros n m.
    induction n as [| n' IH].
    - auto.
    - simpl. rewrite <- IH. reflexivity.  
  Qed.

  Theorem add_comm :
  forall n m : nat,
    n + m = m + n.
  Proof.
    intros.
    induction n as [| n' IH].
    - simpl. rewrite -> n_plus_zero_eq_n. reflexivity.
    - simpl. rewrite -> IH. rewrite -> Sn_plus_m_eq_n_plus_Sm. reflexivity. 
  Qed.

  (* auto using proof *)
  Theorem add_comm_eauto_using_auto_with_start:
  forall n m: nat,
    n + m = m + n.
  Proof.
    intros. induction n.
    Print Hint.
      - auto with *.
      - auto with *. 
    Qed.

  Theorem add_comm_eauto_using:
    forall n m: nat,
      n + m = m + n.
    Proof.
      intros. induction n.
      assert (H: forall n, n + 0 = n) by eauto using n_plus_zero_eq_n.
      assert (H': forall n m, S (n + m) = n + S m) by eauto using Sn_plus_m_eq_n_plus_Sm.
      - eauto with *.
      - eauto using IHn, H, H'. 

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

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

发布评论

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

评论(1

冷月断魂刀 2025-01-20 08:23:33

您在作为基本情况的证明部分中定义引理;因此,当此步骤完成时,它们将被丢弃。如果将它们放在归纳n之前,则在两种情况下都可以访问它们。

You define your lemmas in the part of the proof that is the base case; they are thus discarded when this step is completed. If you put them before the induction n, they will be accessible in both cases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文