Lvc.RenamedApart

Require Import CSet Le.

Require Import Plus Util AllInRel Map.
Require Import Val Var Env EnvTy IL Annotation SetOperations MoreList.

Set Implicit Arguments.

Renamed-apart (formally)

Every subterm is annotated with two sets D and such that D contains all free variables of the subterm and is extactly the set of variables that occur in a binding position.
Inductive renamedApart : stmtann (set var × set var) → Prop :=
  | renamedApartExp x e s D D´´ an
    : x D
      → Exp.freeVars e D
      → renamedApart s an
      → pe (getAnn an) ({x; D}, )
      → D´´ [=] {x; }
      → renamedApart (stmtLet x e s) (ann1 (D, D´´) an)
  | renamedApartIf D Ds Dt e s t ans ant
    : Exp.freeVars e D
      → Ds Dt [=]
      → Ds Dt [=]
      → renamedApart s ans
      → renamedApart t ant
      → pe (getAnn ans) (D, Ds)
      → pe (getAnn ant) (D, Dt)
      → renamedApart (stmtIf e s t) (ann2 (D, ) ans ant)
  | renamedApartRet D e
    : Exp.freeVars e D
      → [=]
      → renamedApart (stmtReturn e) (ann0 (D, ))
  | renamedApartGoto D f Y
    : list_union (List.map Exp.freeVars Y) D
      → [=]
      → renamedApart (stmtApp f Y) (ann0 (D, ))
  | renamedApartExtern x f Y s D D´´ an
    : x D
      → list_union (List.map Exp.freeVars Y) D
      → renamedApart s an
      → pe (getAnn an) ({x; D}, )
      → D´´ [=] {x; }
      → renamedApart (stmtExtern x f Y s) (ann1 (D, D´´) an)
  | renamedApartLet D s t Ds Dt Z ans ant
    : of_list Z D [=]
      → (Ds ++ of_list Z) Dt [=]
      → Ds Dt of_list Z [=]
      → renamedApart s ans
      → pe (getAnn ans) (of_list Z D, Ds)
      → renamedApart t ant
      → pe (getAnn ant) (D, Dt)
      → unique Z
      → renamedApart (stmtFun Z s t) (ann2 (D,) ans ant).

Morphisms


Lemma renamedApart_ext s an an´
  : ann_R (@pe _ _) an an´
  → renamedApart s an
  → renamedApart s an´.

Instance renamedApart_morphism
: Proper (eq ==> (ann_R (@pe _ _)) ==> iff) renamedApart.

Relation to freeVars and occurVars

Lemma renamedApart_freeVars s an
  : renamedApart s anfreeVars s fst (getAnn an).

Lemma renamedApart_occurVars s an
  : renamedApart s andefinedVars s [=] snd (getAnn an).

Definition pminus (D´´:set var) (s:set var × set var) :=
  match s with
    | pair s (s \ D´´, )
  end.

Instance pminus_morphism
: Proper (Equal ==> (@pe _ _) ==> (@pe _ _) ) pminus.

Instance mapAnn_pminus_morphism
  : Proper (ann_R (@pe _ _) ==> ann_R (@pe _ _)) (mapAnn (pminus )).

Lemma not_in_minus X `{OrderedType X} (s t: set X) x
: x s
  → x s \ t.

Hint Resolve not_in_minus : cset.

Lemma not_incl_minus X `{OrderedType X} (s t u: set X)
: s t
  → disj s u
  → s t \ u.

Hint Resolve not_incl_minus : cset.
Hint Resolve disj_1_incl disj_2_incl : cset.

Hint Extern 20 (pe ?a ?a) ⇒ reflexivity.

Lemma renamedApart_minus D an an´ s
  : disj (occurVars s) D
    → renamedApart s an
    → ann_R (@pe _ _) an´ (mapAnn (pminus D) an)
    → renamedApart s an´.

The two annotated sets are disjoint.


Lemma renamedApart_disj s G
: renamedApart s G
  → disj (fst (getAnn G)) (snd (getAnn G)).