Lvc.Equiv.CtxEq

Require Import List.
Require Export Util Var Val Exp Env Map CSet AutoIndTac IL AllInRel Bisim.

Set Implicit Arguments.

Instance SR : ProofRelation (params) := {
   ParamRel G Z := Z = Z = G;
   ArgRel V V G VL VL´ := VL = VL´ length VL = length G;
   BlockRel := fun Z b length (F.block_Z b) = length Z
                            length (F.block_Z ) = length Z
}.
Defined.

Definition bisimeq s :=
   ZL L E, simL´ _ bot2 SR ZL L bisim (L, E, s) (, E, ).

Definition bisimeqid s :=
   (L:F.labenv) E, bisim (L, E, s) (L, E, ).

Definition bisimeq´ r s :=
   ZL L E, simL´ _ r SR ZL L bisim´r r (L, E, s) (, E, ).

Ltac pone_step := pfold; eapply bisim´Silent; [ eapply plus2O; single_step
                              | eapply plus2O; single_step
                              | left ].

Ltac pone_step´ := pfold; eapply bisim´Silent; [ eapply plus2O; single_step
                              | eapply plus2O; single_step
                              | right ].

Ltac pno_step := pfold; eapply bisim´Term;
               try eapply star2_refl; try get_functional; try subst;
                [ try reflexivity
                | stuck2
                | stuck2 ].

Ltac pextern_step :=
  let STEP := fresh "STEP" in
  pfold; eapply bisim´Extern;
    [ eapply star2_refl
    | eapply star2_refl
    | try step_activated
    | try step_activated
    | intros ? ? STEP; inv STEP
    | intros ? ? STEP; inv STEP
    ].

Lemma bisimeq´_refl s
: ZL L E r,
    simL´ _ r SR ZL L
    → bisim´r r (L, E, s) (, E, s).

Lemma bisimeq_refl s
: bisimeq s s.

Lemma bisimeq´_bisimeqid s
: bisimeqid s
  → bisimeq s .

Lemma simL´_refl r L
: AIR5 (simB bisim_progeq r SR) L L (List.map F.block_Z L) L L.

Contextual Equivalence


Inductive stmtCtx : Type :=
| ctxExp (x : var) (e: exp) (C : stmtCtx) : stmtCtx
| ctxIfS (e : exp) (C : stmtCtx) (t : stmt) : stmtCtx
| ctxIfT (e : exp) (s : stmt) (C : stmtCtx) : stmtCtx

| ctxLetS (Z:params) (C : stmtCtx) (t : stmt) : stmtCtx
| ctxLetT (Z:params) (s : stmt) (C : stmtCtx) : stmtCtx
| ctxExtern (x : var) (f:external) (e:args) (C:stmtCtx) : stmtCtx
| ctxHole.

Fixpoint fill (ctx:stmtCtx) (:stmt) : stmt :=
  match ctx with
    | ctxExp x e ctxstmtLet x e (fill ctx )
    | ctxIfS e ctx tstmtIf e (fill ctx ) t
    | ctxIfT e s ctxstmtIf e s (fill ctx )
    | ctxLetS Z ctx tstmtFun Z (fill ctx ) t
    | ctxLetT Z s ctxstmtFun Z s (fill ctx )
    | ctxExtern x f e ctxstmtExtern x f e (fill ctx )
    | ctxHole
  end.

Fixpoint fillC (ctx:stmtCtx) (:stmtCtx) : stmtCtx :=
  match ctx with
    | ctxExp x e ctxctxExp x e (fillC ctx )
    | ctxIfS e ctx tctxIfS e (fillC ctx ) t
    | ctxIfT e s ctxctxIfT e s (fillC ctx )
    | ctxLetS Z ctx tctxLetS Z (fillC ctx ) t
    | ctxLetT Z s ctxctxLetT Z s (fillC ctx )
    | ctxExtern x f e ctxctxExtern x f e (fillC ctx )
    | ctxHole
  end.

Lemma simeq_contextual´ s ctx r
: ( r, bisimeq´ r s )
  → bisimeq´ r (fill ctx s) (fill ctx ).

Lemma fill_fillC C s
  : fill (fillC C ) s = fill C (fill s).