The authors of the book have provided proofs for some unit tests for nostutter exercise. Unfortunately, they didn't provide explanations how they work. I was able to understand all the proofs but one:
Inductive nostutter {X:Type} : list X -> Prop :=
| ns_nil : nostutter []
| ns_one : forall (x : X), nostutter [x]
| ns_cons: forall (x : X) (h : X) (t : list X), nostutter (h::t) -> x <> h -> nostutter (x::h::t).
Example test_nostutter_4: not (nostutter [3;1;1;4]).
Proof.
intro.
repeat match goal with
h: nostutter _ |- _ => inversion h; clear h; subst
end.
contradiction.
Qed.
After intro we have the following:
1 subgoal (ID 454)
H : nostutter [3; 1; 1; 4]
============================
False
When I remove repeat
and run match once, I get this:
1 subgoal (ID 519)
H2 : nostutter [1; 1; 4]
H4 : 3 <> 1
============================
False
So it tries to recursively find, where the list in H2 doesn't match any of nostutter constructors.
Can somebody explain me, how does this match work step by step? What is goal
variable and |-
symbol?