为什么在证明基本情况后,Coq 会删除/清除我的证明中断言的引理?
我想在证明的顶部断言一些引理,并将它们重新用于每个未来的目标。我做到了:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在作为基本情况的证明部分中定义引理;因此,当此步骤完成时,它们将被丢弃。如果将它们放在
归纳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.