(* File: NRules.v  (last edited on 27/10/2000) (c) Klaus Weich  *)
Require Export Cons_Counter_Model.
Require Export NSound.
Inductive nsearch_spec_result_aux (goal : Int) (work : nf_list)
(ds : disjs) (ni : nested_imps) (ai : atomic_imps)
(a : atoms) (context : flist) : Set :=
| NDerivable :
Derivable context (Atom goal) ->
nsearch_spec_result_aux goal work ds ni ai a context
| NRefutable :
forall k : kripke_tree,
Is_Monotone_kripke_tree k ->
forces_ngamma work ds ni ai a k ->
(forces_t k (Atom goal) -> False) ->
nsearch_spec_result_aux goal work ds ni ai a context.
Inductive nsearch_spec_result (goal : Int) (work : nf_list)
(ds : disjs) (ni : nested_imps) (ai : atomic_imps)
(a : atoms) (context : flist) : Set :=
NSearch_Res :
forall ni1 : nested_imps,
le_ni ni1 ni ->
deco_sound work ds ni1 ai a ->
nsearch_spec_result_aux goal work ds ni1 ai a context ->
nsearch_spec_result goal work ds ni ai a context.
Definition nsearch_spec (goal : Int) (work : nf_list)
(ds : disjs) (ni : nested_imps) (ai : atomic_imps)
(a : atoms) (context : flist) :=
deco_sound work ds ni ai a ->
nsound work ds ni ai a context ->
nminimal work ds ni ai a context ->
nsearch_spec_result goal work ds ni ai a context.
(**********************************************************************)
unfold nsearch_spec in |- *.
intros i dni ai a context a_ai_disjunct goal_a_disj complete sound mon.
apply NSearch_Res with (rev_app dni NNil); try assumption.
apply le_ni_refl.
elim (cons_counter_model i dni ai a); try assumption.
intros k k_is_mon k_forces_ngamma k_notforces_goal.
apply NRefutable with k; assumption.
Qed.
(**********************************************************************)
intros goal i j work ds ni ai a context premiss.
unfold nsearch_spec in |- *; intros complete sound mon.
elim premiss; clear premiss.
intros ni1 less1 complete1 spec1.
apply NSearch_Res with ni1.
assumption.
apply deco_sound_shift_ds_work; assumption.
elim spec1; clear spec1.
intros derivable_goal; apply NDerivable; assumption.
intros k k_is_mon k_forces_ngamma k_nonforces_goal.
apply NRefutable with k; try assumption.
apply forces_ngamma_shift_ds_work; assumption.
(* side premisses: Elim premiss. *)
apply deco_sound_shift_work_ds; assumption.
apply nsound_shift_work_ds; assumption.
apply nminimal_shift_work_ds; assumption.
Qed.
intros goal x work ds ni ai a context premiss.
unfold nsearch_spec in |- *; intros complete sound mon.
elim premiss; clear premiss.
intros ni1 less1 complete1 spec1.
apply NSearch_Res with (tail ni1).
inversion_clear less1; assumption.
generalize complete1; clear spec1 complete1.
inversion_clear less1; intros.
apply deco_sound_shift_ni_work with (x := Undecorated x); assumption.
apply deco_sound_shift_ni_work with (x := Decorated x k); assumption.
elim spec1; clear spec1.
intros derivable_goal; apply NDerivable; assumption.
intros k k_is_mon k_forces_ngamma k_nonforces_goal.
apply NRefutable with k; try assumption.
generalize k_forces_ngamma; clear complete1 k_forces_ngamma.
inversion_clear less1; intros.
apply forces_ngamma_shift_ni_work with (x := Undecorated x); assumption.
apply forces_ngamma_shift_ni_work with (x := Decorated x k0); assumption.
(* side premisses: Elim premiss.  *)
apply deco_sound_shift_work_ni0; assumption.
apply nsound_shift_work_ni; assumption.
apply nminimal_shift_work_ni; assumption.
Qed.
intros goal i b work ds ni ai ai' a context notlookup_i notlookup_bs
equiv_ins premiss.
unfold nsearch_spec in |- *; intros complete sound mon.
elim premiss; clear premiss.
intros ni1 less1 complete1 spec1.
apply NSearch_Res with ni1.
assumption.
apply deco_sound_shift_ai_work_new with ai'; assumption.
elim spec1; clear spec1.
intros derivable_goal; apply NDerivable; assumption.
intros k k_is_mon k_forces_ngamma k_nonforces_goal.
apply NRefutable with k; try assumption.
apply forces_ngamma_shift_ai_work_new with ai'; assumption.
(* side premisses: Elim premiss.  *)
apply deco_sound_shift_work_ai with i b ai; assumption.
apply nsound_shift_work_ai with i b ai; assumption.
apply nminimal_shift_work_ai_new with i b ai; assumption.
Qed.
intros goal i b work ds ni bs ai ai' a context notlookup_i lookup_bs
equiv_ins premiss.
unfold nsearch_spec in |- *; intros complete sound mon.
elim premiss; clear premiss.
intros ni1 less1 complete1 spec1.
apply NSearch_Res with ni1.
assumption.
apply deco_sound_shift_ai_work_old with bs ai'; assumption.
elim spec1; clear spec1.
intros derivable_goal; apply NDerivable; assumption.
intros k k_is_mon k_forces_ngamma k_nonforces_goal.
apply NRefutable with k; try assumption.
apply forces_ngamma_shift_ai_work_old with bs ai'; assumption.
(* side premisses: Elim premiss.  *)
apply deco_sound_shift_work_ai with i b ai; assumption.
apply nsound_shift_work_ai with i b ai; assumption.
apply nminimal_shift_work_ai_old with i b bs ai; assumption.
Qed.
intros goal i work ds ni ai a a' context notlookup_bs notlookup_i equiv_ins
premiss.
unfold nsearch_spec in |- *; intros complete sound mon.
elim premiss; clear premiss.
intros ni1 less1 complete1 spec1.
apply NSearch_Res with ni1.
assumption.
apply deco_sound_shift_a_work with a'; assumption.
elim spec1; clear spec1.
intros derivable_goal; apply NDerivable; assumption.
intros k k_is_mon k_forces_ngamma k_nonforces_goal.
apply NRefutable with k; try assumption.
apply forces_ngamma_shift_a_work with a'; assumption.
(* side premisses: Elim premiss.  *)
apply deco_sound_shift_work_a with i a; assumption.
apply nsound_shift_work_a with i a; assumption.
apply nminimal_shift_work_a with i a; assumption.
Qed.
intros; assumption.
Qed.
(*************************************************************************)
unfold nsearch_spec in |- *.
intros goal work ds ni ai a context in_ngamma complete sound mon.
apply NSearch_Res with ni; try assumption.
apply le_ni_refl.
apply NDerivable.
apply sound with (c := NAtom goal); assumption.
Qed.
(**********************************************************************)
unfold nsearch_spec in |- *.
intros goal work ds ni ai a context complete sound mon.
apply NSearch_Res with ni; try assumption.
apply le_ni_refl.
apply NDerivable.
elim (sound NFalsum).
intros t der_t.
apply Derivable_Intro with (Efq t (Atom goal)).
apply ByAbsurdity; assumption.
apply in_ngamma_cons_work_head.
Qed.
intros goal i work ds ni ai a context in_atoms premiss.
unfold nsearch_spec in |- *; intros complete sound mon.
cut (EQUIV_INS unit i (fun _ => tt) tt a a).
intros equiv_ins.
elim premiss; clear premiss.
clear mon sound complete.
intros ni1 le1 complete1 spec1.
apply NSearch_Res with ni1; try assumption.
apply deco_sound_shift_a_work with a; assumption.
elim spec1; clear spec1.
intros der_goal; apply NDerivable; assumption.
intros k k_is_mon k_forces_ngamma k_notforces_goal.
apply NRefutable with k; try assumption.
apply forces_ngamma_shift_a_work with a; assumption.
(* side premisses: (Elim spec ..)  *)
apply deco_sound_shift_work_a with i a; assumption.
apply nsound_shift_work_a with i a; assumption.
apply nminimal_shift_work_a with i a; assumption.
(* side premiss (Cut (EQUIV_INS ....))  *)
clear complete sound mon premiss context ai ni ds work goal.
generalize in_atoms; clear in_atoms.
elim a; clear a; intros t avl_t.
unfold LOOKUP in |- *.
unfold EQUIV_INS in |- *.
intros lookup.
apply equiv_ins_intro.
intros k d eq_k lookup0.
rewrite (equal_eq k i eq_k); assumption.
intros k eq_k notlookup0.
rewrite (equal_eq k i eq_k); assumption.
intros; assumption.
intros; assumption.
Qed.
(**************************************************************************)

Lemma left_p_imp_work :
forall (goal i : Int) (b : normal_form) (work : nf_list)
(ds : disjs) (ni : nested_imps) (ai : atomic_imps)
(a : atoms) (context : flist),
forces0_t a i ->
nsearch_spec goal (b :: work) ds ni ai a context ->
nsearch_spec goal (AImp i b :: work) ds ni ai a context.