3

I am trying to prove the following lemma in Coq:

Lemma not_eq_S2: forall m n, S m <> S n -> m <> n.

It seems easy but I do not find how to finish the proof. Can anybody help me please?

Thank you.

Martin Copes
  • 931
  • 1
  • 7
  • 14

2 Answers2

6

The thing to know is that in Coq, a negation is a function that implies False, so the S m <> S n is really S m = S n -> False. So instead of proving n <> m we can introduce the n = m (we can either unfold not or tell intros explicitly to do it) and get the goal False instead. But with n = m in the context we can rewrite HS: S n <> S m into HS: S n <> S n, which can be handled by auto, or many other tactics such as apply HS. reflexivity. or congruence. etc.

Lemma not_eq_S2: forall m n, S m <> S n -> m <> n.

Proof. intros m n HS HC. 
  rewrite HC in HS. auto.
Qed.
larsr
  • 5,447
  • 19
  • 38
  • This was helpful for me to prove Some x <> None. I was stumped because I didn't understand what the <> symbol actually meant. With your help I found that this worked: unfold not; intros; discriminate. – ldanilek May 26 '18 at 02:31
  • You might also want to checkout this comment about how such proofs work under-the-hood: https://stackoverflow.com/questions/29286679/how-to-prove-false-from-obviously-contradictory-assumptions/49730456#49730456 – larsr May 28 '18 at 07:09
2

It's really easy (but the negation makes it a bit confusing).

Lemma not_eq_S2: forall m n, S m <> S n -> m <> n.
Proof.
  unfold not.      (*                             |- ... -> False *)
  intros m n H C.  (* ..., H : S m = S n -> False |- False *)
  apply H.         (* ...                         |- S m = S n *)
  (* f_equal gets rid of functions applied on both sides of an equality,
     this is probably what you didn't find *)
  (* basically, f_equal turns a goal [f a = f b] into [a = b] *)
  f_equal.         (* ..., C : m = n              |- m = n *)
  exact C.
Qed.
nobody
  • 4,074
  • 1
  • 23
  • 33