For anyone looking for a similar solution, here's how I solved the problem.
First solution
Define a inductive predicate Exists2
as suggested by @Pierre Castéran, and then prove that forall P s, Exists P s <-> Exists2 P s
.
Inductive Exists2 (P: Stream A -> Prop) : Stream A -> Prop:=
| Here2 : forall s, P s -> Exists2 P s
| There2 : forall x s, P s -> Exists2 P (Cons x s)
| Further2 : forall x y s, Exists2 P s -> Exists2 P (Cons x (Cons y s)).
Lemma Exists_iff_Exists2 : forall (P : Stream A -> Prop) (s : Stream A), Exists P s <-> Exists2 P s.
Proof.
intros P s. split; intro H.
- enough (Exists2 P s /\ forall x, Exists2 P (Cons x s)) by easy.
induction H as [s H | s H IHExists].
+ split.
* apply Here2. apply H.
* intro x. apply There2. apply H.
+ destruct s as [y s]. split.
* apply IHExists.
* intro x. apply Further2. apply IHExists.
- induction H as [s H | x s H | x y s H IHExists2].
+ apply Here. apply H.
+ apply Further. apply Here. apply H.
+ apply Further. apply Further. apply IHExists2.
Qed.
When an two-step induction on some H : Exists P s
, it's sufficient to apply Exists_iff_Exists2 in H. induction H.
Second solution
Prove the following lemma:
Lemma Exists_ind2:
forall (A : Type) (P P0 : Stream A -> Prop),
(forall s : Stream A, P s -> P0 s) ->
(forall (x : A) (s : Stream A), P s -> P0 (Cons x s)) ->
(forall (x y : A) (s : Stream A), Exists P s -> P0 s -> P0 (Cons x (Cons y s))) ->
forall s : Stream A, Exists P s -> P0 s.
Proof.
intros A P P0 Hbase Hbase' Hstep s H.
enough (P0 s /\ forall a, P0 (Cons a s)) by easy.
induction H as [s H | s H IHExists].
+ split.
* apply Hbase. apply H.
* intro x. apply Hbase'. apply H.
+ destruct s as [y s]. replace (tl (Cons y s)) with s by reflexivity. split.
* apply IHExists.
* intro x. apply Hstep.
-- apply H.
-- apply IHExists.
Qed.
This lemma is indeed identical to the Exists2_ind
that is generated by the inductive definition of Exists2
of the previous solution, with the only difference that all occurrences of Exists2
are replaced with Exists
.
The proof itself is identical to the one of the lemma of the first solution, with the difference that instead of applying Exists2
's constructors we apply inductive hypothesis.
Maybe this problem is trivial for many, don't bash me.