admin管理员组文章数量:1333428
Here's what I'm trying to prove: Theorem add_n_injective : forall n m p, n + m = n + p -> m = p.
I've tried Coq's built-in tactices, but they don't work. Is there an easy way to prove this? Here's what I've done:
Theorem plus_injective : forall n m, n + n = m + m -> n = m.
Proof. intros n m H.
induction n.
- simpl in H. induction m.
+ reflexivity.
+ rewrite H. discriminate.
- simpl in H. induction m.
+ simpl in H. rewrite <- H. discriminate.
+ rewrite <- H in IHn. rewrite IHn in IHm.
Qed.
and its got stuck with one subgoal
Here's what I'm trying to prove: Theorem add_n_injective : forall n m p, n + m = n + p -> m = p.
I've tried Coq's built-in tactices, but they don't work. Is there an easy way to prove this? Here's what I've done:
Theorem plus_injective : forall n m, n + n = m + m -> n = m.
Proof. intros n m H.
induction n.
- simpl in H. induction m.
+ reflexivity.
+ rewrite H. discriminate.
- simpl in H. induction m.
+ simpl in H. rewrite <- H. discriminate.
+ rewrite <- H in IHn. rewrite IHn in IHm.
Qed.
and its got stuck with one subgoal
Share Improve this question edited Nov 21, 2024 at 6:34 DarkBee 15.6k8 gold badges72 silver badges117 bronze badges asked Nov 21, 2024 at 6:33 wulalalawulalala 111 silver badge1 bronze badge 2- 1 2n = 2m -> n = m is not the injectivity of plus but that of twice ! – Dominique Larchey-Wendling Commented Nov 21, 2024 at 22:47
- 1 You need to show (S n) + (S n) = S (S (n+n)) to proceed by induction as you want. In turn, this means you need n+S m = S (n+m) which is part of the StdLib used to show that + is eg commutative. – Dominique Larchey-Wendling Commented Nov 21, 2024 at 22:50
2 Answers
Reset to default 3You can not use your induction hypothesis because H
simplifies to n + n = m + m
while IHn
expects n + n = S m + S m
. In other words, the argument m
you want to feed the induction hypothesis changed, which is a symptom that you need to generalize over m
(with revert m
) before doing induction n
(actually you can just not introduce m
and H
before doing induction n
). Besides, you can also destruct
m
instead of doing an induction on it, the induction hypothesis IHm
is useless.
How would you prove it on paper? I'd say probably not by induction. Maybe you already have the inverse of +n
?
Note that there is also the lia
tactic for solving linear integer arithmetic problems. You just need to import it with the following command.
From Coq Require Import Lia.
本文标签: coqHow can I prove the injectivity of plusStack Overflow
版权声明:本文标题:coq - How can I prove the injectivity of plus? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742309151a2450516.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论