(* File: NSound.v  (last edited on 27/10/2000) (c) Klaus Weich  *)
Require Export Le_Ks.
Require Export Derivable_Tools.
Definition nsound (work : nf_list) (ds : disjs) (ni : nested_imps)
(ai : atomic_imps) (a : atoms) (context : flist) :=
forall c : normal_form,
in_ngamma work ds ni ai a c -> Derivable context (nf2form c).
intros work ds ni1 ni2 ai a context eq12 sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_eqv with ni2.
apply eqv_sym; assumption.
assumption.
Qed.
intros work ds ni1 ni2 ai a context le sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_ge with ni2; assumption.
Qed.
intros work ds ni1 ni2 ai a context le sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_le with ni2; assumption.
Qed.
(***********************************************************************)
intros i j work ds ni ai a context sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_shift_ds_work; assumption.
Qed.
intros x work ds ni ai a context sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_shift_ni_work; assumption.
Qed.
intros i b work ds ni ai ai' a context equiv_ins sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_shift_ai_work with ai'; assumption.
Qed.
intros i work ds ni ai a a' context equiv_ins sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_shift_a_work with a'; assumption.
Qed.
intros x work ds ni1 ni2 ai a context sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_shift_ni_x_ni_work; assumption.
Qed.
intros x work ds ni1 ni2 ai a context sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_shift_work_ni_x_ni; assumption.
Qed.
(***********************************************************************)
Remark nsound_app_work :
forall (bs work : nf_list) (ds : disjs) (ni : nested_imps)
(ai : atomic_imps) (a : atoms) (context : flist),
(forall (n : nat) (b : normal_form),
my_nth normal_form n bs b -> Derivable context (nf2form b)) ->
nsound work ds ni ai a context -> nsound (bs ++ work) ds ni ai a context.
intros bs work ds ni ai a context der_bs sound.
unfold nsound in |- *.
intros c in_ngamma.
elim (in_ngamma_work_app_rev bs work ds ni ai a c in_ngamma); clear in_ngamma.
intros in_ngamma.
apply sound; assumption.
intros nth; elim nth; clear nth.
intros n nth.
apply der_bs with n; assumption.
Qed.
intros work i j ds ni ai a context sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_cons_ds_tail; assumption.
Qed.
Remark nsound_del_ai :
forall (i : Int) (work : nf_list) (ds : disjs) (ni : nested_imps)
(ai ai' : atomic_imps) (a : atoms) (context : flist),
EQUIV_DEL nf_list i ai ai' ->
nsound work ds ni ai a context -> nsound work ds ni ai' a context.
intros i work ds ni ai ai' a context equiv_del sound.
unfold nsound in |- *.
intros c in_ngamma.
apply sound.
apply in_ngamma_del_ai_tail with i ai'; assumption.
Qed.
(***********************************************************************)
intros c work ds ni ai a context sound.
unfold nsound in |- *.
intros c0 in_gamma.
elim (in_ngamma_cons_work_rev c work ds ni ai a c0 in_gamma); clear in_gamma.
intros in_gamma.
apply derivable_weak.
apply sound; assumption.
intros eq;  rewrite eq; clear eq.
apply Derivable_Intro with (Var 0).
apply ByAssumption.
apply My_NthO.
Qed.
(**********************************************************************)

Lemma nsound_cons_work_weak :
forall (b c : normal_form) (work : nf_list) (ds : disjs)
(ni : nested_imps) (ai : atomic_imps) (a : atoms)
(context : flist),
(Derivable context (nf2form b) -> Derivable context (nf2form c)) ->
nsound (b :: work) ds ni ai a context ->
nsound (c :: work) ds ni ai a context.