File ApplicationContext

From MatchingLogic Require Export Pattern.

Section with_signature.
    Context {Σ : Signature}.

    (* TODO make Set ? *)
  Inductive Application_context : Type :=
  | box
  | ctx_app_l (cc : Application_context) (p : Pattern) (Prf : well_formed p)
  | ctx_app_r (p : Pattern) (cc : Application_context) (Prf : well_formed p)
  .

  Fixpoint AC_free_evars (AC : Application_context) : EVarSet :=
    match AC with
    | box ⇒ ∅
    | @ctx_app_l cc p _free_evars pAC_free_evars cc
    | @ctx_app_r p cc _free_evars pAC_free_evars cc
    end.

  Fixpoint subst_ctx (C : Application_context) (p : Pattern)
    : Pattern :=
    match C with
    | boxp
    | @ctx_app_l C' p' prfpatt_app (subst_ctx C' p) p'
    | @ctx_app_r p' C' prfpatt_app p' (subst_ctx C' p)
    end.

  (* TODO rewrite using wc_sctx *)
  Lemma wf_sctx (C : Application_context) (A : Pattern) :
    well_formed A = truewell_formed (subst_ctx C A) = true.

  Lemma wp_sctx (C : Application_context) (A : Pattern) :
    well_formed_positive A = truewell_formed_positive (subst_ctx C A) = true.

  Lemma wcex_sctx (C : Application_context) (A : Pattern) idx1 :
    well_formed_closed_ex_aux A idx1 = truewell_formed_closed_ex_aux (subst_ctx C A) idx1 = true.

  Lemma wcmu_sctx (C : Application_context) (A : Pattern) idx1 :
    well_formed_closed_mu_aux A idx1 = truewell_formed_closed_mu_aux (subst_ctx C A) idx1 = true.

  Fixpoint free_evars_ctx (C : Application_context)
    : (EVarSet) :=
    match C with
    | boxempty
    | @ctx_app_l cc p prfunion (free_evars_ctx cc) (free_evars p)
    | @ctx_app_r p cc prfunion (free_evars p) (free_evars_ctx cc)
    end.

  Definition ApplicationContext2Pattern (boxvar : evar) (AC : Application_context) :=
    subst_ctx AC (patt_free_evar boxvar).

  Lemma ApplicationContext2Pattern_one_occ (AC : Application_context) (boxvar : evar):
    boxvarfree_evars_ctx AC
    count_evar_occurrences boxvar (ApplicationContext2Pattern boxvar AC) = 1.

  End with_signature.

Module Notations.

Notation "□" := box.
Notation "p '$ₗ' C" := (@ctx_app_l _ p C _) (at level 65).
Notation "C '$ᵣ' p" := (@ctx_app_r _ C p _) (at level 65).
Notation "C .[ □ ↦ p ]" := (subst_ctx C p)
   (at level 2, format "C .[ □ ↦ p ]").

End Notations.

Lemma free_evars_subst_ctx {Σ : Signature} AC ϕ:
  free_evars (subst_ctx AC ϕ) = AC_free_evars ACfree_evars ϕ.

This page has been generated by coqdoc