Cannot rewrite goal with assertion?
Question
I am not sure I understand why in some cases rewriting H works, and in some it doesnt. Here for example:
Require Import PeanoNat.forall n m : nat, n + m = m + nforall n m : nat, n + m = m + nn, m: natn + m = m + nreflexivity. Qed.n, m: natm + n = m + nforall n m p : nat, nat -> n + n * p + m + m * p = n + m + n * p + m * pforall n m p : nat, nat -> n + n * p + m + m * p = n + m + n * p + m * pn, m, p, q: natn + n * p + m + m * p = n + m + n * p + m * pn, m, p, q: natn * p + m = m + n * pn, m, p, q: nat
H: n * p + m = m + n * pn + n * p + m + m * p = n + m + n * p + m * pn, m, p, q: natn * p + m = m + n * preflexivity.n, m, p, q: natm + n * p = m + n * pn, m, p, q: nat
H: n * p + m = m + n * pn + n * p + m + m * p = n + m + n * p + m * pn, m, p, q: nat
H: n * p + m = m + n * pn + n * p + m + m * p = n + m + n * p + m * p
Gives:
But Coq complains:
I clearly see one, on the left side. When using induction, rewriting with IHn doesn't pose any problem, even if there are some other terms in front of rewriteable expression.
Answer
You can "see" a subterm n * p + m, but this is misleading: Coq doesn't show you the implicit parentheses around all the + expressions.
Use
Set Printing Parentheses.
to make them visible. Your proof state is really:
Coq was right that there is no subterm that matches H's left hand side expression ((n * p) + m). You need to rewrite using some associativity lemmas to shift the parentheses around.
Also, add_assoc2 is not a good name for a lemma forall n m : nat, n + m = m + n. This is a commutativity property, not associativity.