Section Streams.
Variable A : Type.
Notation Stream := (Stream A).
Definition hd (x:Stream) := match x with
| Cons a _ => a
end.
Definition tl (x:Stream) := match x with
| Cons _ s => s
end.
Fixpoint Str_nth_tl (n:nat) (s:Stream) : Stream :=
match n with
| O => s
| S m => Str_nth_tl m (tl s)
end.
Definition Str_nth (n:nat) (s:Stream) : A := hd (Str_nth_tl n s).
Hint Resolve tl_nth_tl: datatypes.
simple induction n; simpl; intros; auto with datatypes.
rewrite <- H.
rewrite tl_nth_tl; trivial with datatypes.
Qed.
intros; unfold Str_nth; rewrite Str_nth_tl_plus;
trivial with datatypes.
Qed.
(** Extensional Equality between two streams  *)
CoInductive EqSt (s1 s2: Stream) : Prop :=
eqst :
hd s1 = hd s2 -> EqSt (tl s1) (tl s2) -> EqSt s1 s2.
(** A coinduction principle *)
Ltac coinduction proof :=
cofix proof; intros; constructor;
[ clear proof | try (apply proof; clear proof) ].
(** Extensional equality is an equivalence relation *)
coinduction EqSt_reflex.
reflexivity.
Qed.
coinduction Eq_sym.
+ case H; intros; symmetry ; assumption.
+ case H; intros; assumption.
Qed.

Theorem trans_EqSt :
forall s1 s2 s3:Stream, EqSt s1 s2 -> EqSt s2 s3 -> EqSt s1 s3.