1

I would like to prove that subtraction does not commute in Coq but I am stuck. I believe the that the statement I would like to prove in Coq would be written forall a b : nat, a <> b -> a - b <> b - a

Here is what I have for the proof so far.

Theorem subtraction_does_not_commute :
  forall a b : nat, a <> b -> a - b <> b - a.
Proof.
  intros a b C.
  unfold not; intro H.
  apply C.

I think I could use C : a <> b to contradict the goal a = b.

Mike Harris
  • 869
  • 9
  • 21

1 Answers1

2

One way to solve this is to use induction on a. However, if you start your proof with

intros a b C; induction a.

you will get stuck because the context will have the following hypotheses:

C : S a <> b
IHa : a <> b -> a - b <> b - a

You won't be able to use the induction hypothesis IHa because one cannot infer the premise of IHa (a <> b) from S a <> b: e.g. 1 <> 0 doesn't imply 0 <> 0.

But we can make the induction hypothesis stronger by not introducing the variables into the context prematurely:

Require Import Coq.Arith.Arith.

Lemma subtraction_does_not_commute :
  forall a b : nat, a <> b -> a - b <> b - a.
Proof.
  induction a; intros b C.
  - now rewrite Nat.sub_0_r.
  - destruct b.
    + trivial.
    + repeat rewrite Nat.sub_succ. auto.
Qed.

Or, alternatively, using the omega tactic, we get a one-line proof:

Require Import Omega.

Lemma subtraction_does_not_commute :
  forall a b : nat, a <> b -> a - b <> b - a.
Proof. intros; omega. Qed.
Anton Trunov
  • 15,074
  • 2
  • 23
  • 43
  • 2
    With `omega`, you do not need `induction` at all any more. – eponier May 18 '17 at 08:31
  • Sure, thanks! Forgot that we are in the realm of Presburger arithmetic in this case. – Anton Trunov May 18 '17 at 08:35
  • Thank you so much, works beautifully. Total noob question how do I find a list of definition and theorem that are avaible like Nat.sub_succ and Nat.sub_0_r? – Mike Harris May 18 '17 at 11:47
  • 2
    @MikeHarris `Require Import Coq.Arith.Arith.`, then `Search (S _ - S _).` or `Search (_ - 0).` respectively. Besides the wildcard `_`, Coq's search also understands `Search (?a + ?b = ?b + ?a).` -- this should find `Nat.add_comm`. See [here](https://coq.inria.fr/refman/Reference-Manual008.html#sec248) for more information. – Anton Trunov May 18 '17 at 11:57