1

Coq beginner here.

I have the following silly theorems:

  Theorem plus_same : forall a b c : nat,
      a+b=a+c -> b=c.
  Proof. Admitted.

  Theorem advanced_commutivity:
    forall x y z w : nat, x + y + (z+w) = x + z + (y + w).
  Proof.
    intros x y z w.
    apply (plus_same x (y + (z+w)) (z + (y + w))).

However, when I try to run the apply line, I get an error:

Unable to unify "y + (z + w) = z + (y + w)" with
 "x + y + (z + w) = x + z + (y + w)".

Do I need to change my hypothesis here? How can I apply plus_same here to the arguments in advanced_commutivity proof?

gust
  • 878
  • 9
  • 23

1 Answers1

2

You are misreading your goal: x + y + (z + w) stands for (x + y) + (z + w), because + is registered as left-associative, which is different from x + (y + (z + w)).

So in order to apply your lemma, you should first reassociate your + by rewriting with another Lemma plus_assoc : forall x y z, x + y + z = x + (y + z).

kyo dralliam
  • 1,197
  • 5
  • 6
  • 3
    True, but there is another problem. The `plus_same` theorem says that if you have `x + ...`, then you can get rid of the `x`. In this case you want to end up with `x + ...`, so actually you need the oposite implication of `plus_same`: `Theorem same_plus (a b c : nat) : b = c -> a + b = a + c.` – Ana Borges Oct 17 '20 at 22:06