Section sec_exteq_congruence.
Variable T: Type.
(* All useful predicates are extensional in the following sense *)
Definition extensional (P: infseq T -> Prop) :=
forall s1 s2, exteq s1 s2 -> P s1 -> P s2.
Proof using.
intros s1 s2 eq; auto.
Qed.
Proof using.
intros s1 s2 eq; auto.
Qed.
Proof using.
intros P Q eP eQ s1 s2 e. destruct e; simpl. unfold and_tl. intuition.
- apply eP with (Cons x s1); [constructor; assumption | assumption].
- apply eQ with (Cons x s1); [constructor; assumption | assumption].
Qed.
Proof using.
intros P Q eP eQ s1 s2 e. destruct e; simpl. unfold or_tl. intuition.
- left; apply eP with (Cons x s1); [constructor; assumption | assumption].
- right; apply eQ with (Cons x s1); [constructor; assumption | assumption].
Qed.
Proof using.
intros P Q eP eQ s1 s2 e. destruct e; simpl. unfold impl_tl.
intros PQ1 P2.
apply eQ with (Cons x s1); [constructor; assumption | idtac].
apply PQ1. apply eP with (Cons x s2).
- constructor. apply exteq_sym. assumption.
- assumption.
Qed.
Proof using.
intros P eP s1 s2 e; destruct e; simpl. unfold not_tl.
intros P1 nP2.
contradict P1.
apply eP with (Cons x s2); trivial.
apply exteq_sym.
apply exteq_intro.
assumption.
Qed.
Proof using.
intros P s1 s2 e. destruct e; simpl. trivial.
Qed.
Proof using.
intros P eP s1 s2 exP; destruct exP; simpl.
apply eP; assumption.
Qed.
Proof using.
intros P s1 s2 e. do 2 destruct e; simpl. trivial.
Qed.
Proof using.
intros P eP. cofix cf.
intros (x1, s1) (x2, s2) e al1. case (always_Cons al1); intros Px1s1 als1. constructor.
- eapply eP; eassumption.
- simpl. apply cf with s1; try assumption. case (exteq_inversion e); trivial.
Qed.

Lemma extensional_weak_until :
forall (P Q: infseq T -> Prop),
extensional P -> extensional Q -> extensional (weak_until P Q).