(* $Id: DecOTh.v,v 1.2 1999/10/05 10:35:35 boulme Exp $ *)
(* Some operations on lists for records *)

Set Implicit Arguments.
Unset Strict Implicit.
Require Export DecLists. 
Require Export OTheoryList.

Section DecOTh.

Variable A : Set.
Variable R : A -> A -> Prop.
Hypothesis R_dec : forall x y : A, {R x y} + {~ R x y}.
Hypothesis R_refl : forall x : A, R x x.
Hypothesis R_trans : forall x y z : A, R x y -> R y z -> R x z.
Hypothesis R_sym : forall x y : A, R x y -> R y x.

Lemma contO_cont : forall l1 l2 : list A, contO R l1 l2 -> cont R_dec l1 l2.
Proof.
  intros l1 l2 H; elim H; clear H l1 l2; auto with declists;
   try (intros; eapply cont_trans; eauto; fail); intros;
   do 2 try (apply cont_cons; auto with declists);
   do 2 try (apply cont_tl_l; eauto). 
Qed.
Hint Resolve contO_cont: declists.

Lemma contO_df : forall l m : list A, contO R l m -> df R_dec l -> df R_dec m.
Proof.
  intros l m H; elim H; auto with declists.
  intros a1 a2 l1 l2 H1 H2 HR H3; case (df_cons_inv H3); intros H4 H5;
   apply df_cons; auto.
  apply cont_incl2 with (l := l1); eauto with declists;
   apply ninD_R_stable with (a := a1); eauto.
  intros b l1 l2 H1 H2 H3; case (df_cons_inv H3); auto.
  intros a1 a2 l1 l2 H1 H2 H3; case (df_cons_inv H3); intros H4 H5;
   case (df_cons_inv H5); case (ninD_cons_inv H4); 
   clear H5 H4 H3; intros H3 H4 H5 H6.
  specialize (cont_incl2 R_trans (contO_cont H1) H4);
   specialize (cont_incl2 R_trans (contO_cont H1) H5); 
   intros; auto 10 with declists.
Qed.

Lemma df_extractO :
 forall (l m : list A) (H : contO R l m),
 df R_dec l -> df R_dec (extractO R_refl R_trans H).
  intros l m H1 H2; apply contO_df with (l := l); auto.
  apply contO_extractO; auto.
Qed.

Lemma disj_extractO :
 forall (l m : list A) (H : contO R l m),
 df R_dec l -> disj R_dec (extractO R_refl R_trans H) m.
  intros l m H1 H2; apply df_app_disj; auto; apply contO_df with (l := l);
   auto.
  apply contO_extractO_app; auto.
Qed.

End DecOTh.



