I was given a solution to the following theorem as shown below:
Require Import Coq.Lists.List.
Import ListNotations.
Inductive suffix {X : Type} : list X -> list X -> Prop :=
| suffix_end : forall xs,
suffix xs xs
| suffix_step : forall x xs ys,
suffix xs ys ->
suffix (x :: xs) ys.
Theorem suffix_app (X: Type) (xs ys: list X) :
suffix xs ys -> exists ws, xs = ws ++ ys.
Proof.
induction 1 as [|x xsp ysp hs [zs zeq]].
- exists []. reflexivity.
- now exists (x :: zs); rewrite zeq.
Qed.
I was trying to quickly replicate it on another machine and attempted it thus:
Theorem suffix_app (X: Type) (xs ys: list X) :
suffix xs ys -> exists ws, xs = ws ++ ys.
Proof.
induction 1.
- exists []. reflexivity.
- (* Stuck here! *)
Abort.
i.e. without the "as" clause. However, I get stuck due to the auto-named equivalent of "zeq" not being generated for reasons that I can't work out. Why isn't the (automatically named) equivalent of "zeq" generated by Coq in the second case here?
destruct
in the pattern. Thusdestruct IHsuffix as [zs zeq].
will get you back in game.intros
can also do rewrites (->
):induction 1 as [|x ? ? ? [zs ->]]; [exists [] | exists (x :: zs)]; trivial.