(* This code is copyrighted by its authors; it is distributed under  *)
(* the terms of the LGPL license (see LICENSE and description files) *)
Definition Pred (A : Set) := A -> Prop.
Definition Rel (A : Set) := A -> A -> Prop.
Inductive ExistsL (A : Set) (P : Pred A) : list A -> Set :=
| FoundE : forall (a : A) (l : list A), P a -> ExistsL A P (a :: l)
| SearchE :
forall (a : A) (l : list A), ExistsL A P l -> ExistsL A P (a :: l).
Hint Resolve FoundE SearchE.
intros A P xs; elim xs; simpl in |- *; auto.
Qed.
Hint Resolve monExistsL1.
intros A P xs; elim xs; simpl in |- *; auto.
intros a l H' bs cs H'0; inversion H'0; auto.
Qed.
Hint Resolve monExistsL.
Inductive GoodR (A : Set) (R : Rel A) : list A -> Set :=
| FoundG :
forall (a : A) (l : list A),
ExistsL A (fun x : A => R x a) l -> GoodR A R (a :: l)
| SearchG : forall (a : A) (l : list A), GoodR A R l -> GoodR A R (a :: l).
Hint Resolve FoundG SearchG.
intros A R xs; elim xs; simpl in |- *; auto.
Qed.
Hint Resolve monGoodR1.
intros A R xs bs cs; elim xs; simpl in |- *; auto.
intros a l H' H'0; inversion H'0; simpl in |- *; auto.
Qed.
Hint Resolve monGoodR.
intros A B P S f H' l H'0; elim H'0; simpl in |- *; auto.
Qed.
intros A B R S f H' l H'0; elim H'0; simpl in |- *; auto.
intros a l0 H'1; apply FoundG; auto.
apply subPredExistsL with (P := fun x : A => R x a); auto.
Qed.
Inductive Bar (A : Set) (P : list A -> Set) : list A -> Set :=
| Base : forall l : list A, P l -> Bar A P l
| Ind : forall l : list A, (forall a : A, Bar A P (a :: l)) -> Bar A P l.
Hint Resolve Base Ind.
Definition GRBar (A : Set) (R : Rel A) := Bar A (GoodR A R).
Definition WR (A : Set) (R : Rel A) := GRBar A R nil.
Hint Unfold GRBar WR.
intros A B R S f H' H'0 l H'1; elim H'1; simpl in |- *; auto.
intros l0 H'2.
red in |- *; apply Base; auto.
unfold GRBar in |- *.
apply subRelGoodR with (R := R); auto.
intros l0 H'2 H'3; red in |- *; apply Ind; auto.
intros a; case (H'0 a); auto.
intros x H'4; rewrite H'4; auto.
unfold GRBar in H'3; apply H'3; auto.
Qed.
intros A R l H'; elim H'; auto.
Qed.
Hint Resolve consGRBar.
intros A R H' l; elim l; auto.
Qed.

Lemma monGRBarAux :
forall (A : Set) (R : Rel A) (l : list A),
GRBar A R l ->
forall xs bs cs : list A, l = xs ++ cs -> GRBar A R (xs ++ bs ++ cs).