简体   繁体   中英

Coq unable to unify -- how to change hypothesis?

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?

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 xyz, x + y + z = x + (y + z).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM