(* Require Export LNat LOptions LTactics.  Section PartialFunctions.  Variable F : term. Hypothesis proc_F : proc F.  Variable X : Type. Variable in_enc : X -> term.  Variable Y : Type. Variable out_enc : Y -> term.  Hypothesis in_enc_proc : forall x, proc (in_enc x). Hypothesis out_enc_proc : forall x, proc (out_enc x).  Hint Resolve in_enc_proc out_enc_proc: LProc.  Hypothesis total_F : forall t n, (exists v, F (enc n) (in_enc t) == oenc out_enc (Some v)) \/ F (enc n) (in_enc t) == (none out_enc).  Definition S' := rho (.\"S'", "n", "F", "t"; ("F" "n" "t") !K ((.\"Sn","x"; "S'" "Sn" "F" "x") (!Succ "n")) "t").  Lemma S'_proc : recProc S'. cLproc. Qed.  Hint Resolve S'_proc : LProc.  Hint Unfold S' : cbv. (* Lemma S'_rec n t : S' (enc n) F (tenc t) ==  (F (enc n) (tenc t)) K (lam ( S' (Succ (enc n)) F (tenc t))) I.   Hypothesis mono_F : forall n t v, F (enc n) (in_enc t) == oenc out_enc (Some v) -> F (enc (S n)) (in_enc t) == oenc out_enc (Some v).  Lemma S'_n_Sn n t : S' (enc n) F (in_enc t)  == S' (enc (S n)) F (in_enc t).  Lemma S'_n_Sn_none n t : F (enc n) (in_enc t) == oenc out_enc None ->( lam (S' (enc n) F 0)) (in_enc t)  >* (lam (S' (enc (S n)) F 0) )(in_enc t).  Definition Se F :term := .\"x"; !(S' (enc 0)) !F "x".  Lemma Se_proc : proc (Se F). unfold Se;simpl. wLproc. Qed.  Hint Resolve Se_proc : LProc.  Lemma S'_0_n n t : Se F (in_enc t) == S' (enc n) F (in_enc t).  Lemma Se_converges t v : Se F (in_enc t) == lam v -> closed (lam v).  Lemma Se_correct' t (v : term) : proc v -> ( Se F (in_enc t) == v <-> exists n, F (enc n) (in_enc t) == some v ).  (* TODO *)
Ltac standardizeHypo _n:=
match goal with
| eq : ?s == ?t |- _=>
revert eq;try standardizeHypo _n; intros eq;
try (progress (let R:= fresh "R" in
standardize R _n s;apply (stHypo R) in eq;clear R ));
try (progress (let R':= fresh "R'" in
symmetry;standardize R' _n s;
apply (stHypo R') in eq;symmetry;clear R' ))
end.

Corollary Se_correct t (v : term) : lambda v -> (Se F (in_enc t) == v <-> exists n, F (enc n) (in_enc t) == some v).