File FreshnessSubstitution

From MatchingLogic Require Export Substitution
                                  Freshness.

Import Substitution.Notations.

Section lemmas.
  Context {Σ : Signature}.
  Open Scope ml_scope.

  Lemma evar_is_fresh_in_free_evar_subst x phi psi:
    evar_is_fresh_in x psi
    evar_is_fresh_in x (phi^[[evar: xpsi]]).

  Lemma evar_is_fresh_in_evar_quantify x n phi:
    evar_is_fresh_in x (phi^{{evar: xn}}).

  Lemma svar_is_fresh_in_free_evar_subst X phi psi:
    svar_is_fresh_in X psi
    svar_is_fresh_in X (phi^[[svar: Xpsi]]).

  Lemma svar_is_fresh_in_svar_quantify X n phi:
    svar_is_fresh_in X (phi^{{svar: Xn}}).

  (*If phi is a closed body, then (ex, phi) is closed too*)
  Corollary wfc_body_to_wfc_ex phi:
    wfc_body_ex phi
    well_formed_closed (patt_exists phi) = true.

  (* Lemmas about wfc_ex and wfc_mu *)

  (* From https://www.chargueraud.org/research/2009/ln/main.pdf in 3.4 (lc_abs_iff_body) *)
  (*Conclusion*)
  Corollary wfc_body_wfc_ex_iff:
   phi,
    well_formed_closed (patt_exists phi) = truewfc_body_ex phi.

  (* TODO make a wrapper that does not have the 'sz' variable *)
  Lemma bevar_subst_fresh_notin:
     phi psi v,
      v ∉ (free_evars phi) →
      v ∉ (free_evars psi) →
       n,
        v ∉ (free_evars (phi^[evar: npsi])).

  Lemma bsvar_subst_fresh_notin:
     phi psi v,
      v ∉ (free_svars phi) →
      v ∉ (free_svars psi) →
       n,
        v ∉ (free_svars (phi^[svar: npsi])).

  Corollary evar_open_fresh_notin:
     phi v w,
      v ∉ (free_evars phi) →
      w ∉ (free_evars phi) →
      (vw) →
       n,
        v ∉ (free_evars (phi^{evar: nw})).

  Corollary svar_open_fresh_notin:
     phi v w,
      v ∉ (free_svars phi) →
      w ∉ (free_svars phi) →
      (vw) →
       n,
        v ∉ (free_svars (phi^{svar: nw})).

  Lemma free_evars_svar_open : (psi : Pattern) (dbi :db_index) (X : svar),
      free_evars (psi^{svar: dbiX}) = free_evars psi.

  Lemma fresh_evar_svar_open dbi X phi :
    fresh_evar (phi^{svar: dbiX}) = fresh_evar phi.

  Lemma fresh_svar_evar_open dbi x phi :
    fresh_svar (phi^{evar: dbix}) = fresh_svar phi.

  Corollary svar_is_fresh_in_svar_open X Y dbi ϕ:
    XY
    svar_is_fresh_in X ϕ
    svar_is_fresh_in X (ϕ^{svar: dbiY}).

  Corollary evar_is_fresh_in_evar_open x y dbi ϕ:
    xy
    evar_is_fresh_in x ϕ
    evar_is_fresh_in x (ϕ^{evar: dbiy}).

  Corollary evar_fresh_svar_open x X dbi ϕ:
    evar_is_fresh_in x ϕ
    evar_is_fresh_in x (ϕ^{svar: dbiX}).

  Corollary svar_fresh_evar_open x X dbi ϕ:
    svar_is_fresh_in X ϕ
    svar_is_fresh_in X (ϕ^{evar: dbix}).

  Lemma evar_open_inj : ∀ phi psi x n,
    evar_is_fresh_in x phievar_is_fresh_in x psi
    phi^{evar: nx} = psi^{evar: nx}
    → phi = psi.

  Lemma svar_open_inj : ∀ phi psi X n,
    svar_is_fresh_in X phisvar_is_fresh_in X psi
    phi^{svar: nX} = psi^{svar: nX}
    → phi = psi.

  Lemma evar_open_free_svar_subst_comm: ∀ phi psi fresh n X,
    (well_formed_closed_ex_aux psi 0) →
    evar_is_fresh_in fresh phi
    evar_is_fresh_in fresh (phi^[[svar: Xpsi]])
    →
    (phi^[[svar: Xpsi]])^{evar: nfresh} = (phi^{evar: nfresh})^[[svar:Xpsi]].

  Lemma svar_open_free_svar_subst_comm : ∀ phi psi fresh n X,
    (well_formed_closed_mu_aux psi 0) →
    svar_is_fresh_in fresh phisvar_is_fresh_in fresh (phi^[[svar: Xpsi]]) → (freshX)
    →
    phi^[[svar: Xpsi]]^{svar: nfresh} = phi^{svar: nfresh}^[[svar: Xpsi]].

  Lemma free_evar_subst_preserves_no_negative_occurrence x p q n:
    well_formed_closed_mu_aux q 0 = true
    no_negative_occurrence_db_b n p = true
    no_negative_occurrence_db_b n (p^[[evar: xq]]) = true
  with
    free_evar_subst_preserves_no_positive_occurrence x p q n:
    well_formed_closed_mu_aux q 0 = true
    no_positive_occurrence_db_b n p = true
    no_positive_occurrence_db_b n (p^[[evar: xq]]) = true
  .

  Lemma Private_well_formed_free_evar_subst x p q n1 n2:
    well_formed q
    well_formed_positive p && well_formed_closed_mu_aux p n2 && well_formed_closed_ex_aux p n1
    no_negative_occurrence_db_b n2 (p^[[evar: xq]])
    && no_positive_occurrence_db_b n2 (p^[[evar: xq]])
    && well_formed_positive (p^[[evar: xq]])
    && well_formed_closed_mu_aux (p^[[evar: xq]]) n2
    && well_formed_closed_ex_aux (p^[[evar: xq]]) n1
    = true.

  Lemma well_formed_free_evar_subst x p q:
    well_formed q = true
    well_formed p = true
    well_formed (p^[[evar: xq]]) = true.

  Lemma well_formed_xy_free_evar_subst x m n p q:
    well_formed q = true
    well_formed_xy m n p = true
    well_formed_xy m n (p^[[evar: xq]]) = true.

  Lemma well_formed_free_evar_subst_0 x p q:
    well_formed q = true
    well_formed p = true
    well_formed (p^[[evar: xq]]) = true.

  Lemma evar_quantify_fresh x n phi:
    evar_is_fresh_in x phi
    phi^{{evar: xn}} = phi.

  Lemma svar_quantify_fresh X n phi:
  svar_is_fresh_in X phi
  phi^{{svar: Xn}} = phi.

Lemma svar_hno_bsvar_subst X ϕ ψ dbi:
  (svar_has_negative_occurrence X ψ = trueno_positive_occurrence_db_b dbi ϕ = true) →
  (svar_has_positive_occurrence X ψ = trueno_negative_occurrence_db_b dbi ϕ = true) →
  svar_has_negative_occurrence X ϕ = false
  svar_has_negative_occurrence X (ϕ^[svar: dbi ↦ ψ]) = false
with svar_hpo_bsvar_subst X ϕ ψ dbi:
       (svar_has_negative_occurrence X ψ = trueno_negative_occurrence_db_b dbi ϕ = true) →
       (svar_has_positive_occurrence X ψ = trueno_positive_occurrence_db_b dbi ϕ = true) →
       svar_has_positive_occurrence X ϕ = false
       svar_has_positive_occurrence X (ϕ^[svar: dbi ↦ ψ]) = false.
Lemma svar_hno_false_if_fresh X ϕ:
  svar_is_fresh_in X ϕ
  svar_has_negative_occurrence X ϕ = false
with svar_hpo_false_if_fresh X ϕ:
       svar_is_fresh_in X ϕ
       svar_has_positive_occurrence X ϕ = false.

(* TODO remove the no-negative-ocurrence assumption from the svar version *)
Lemma wfp_free_evar_subst ϕ ψ x:
  well_formed_closed_mu_aux ψ 0 →
  well_formed_positive ψ = true
  well_formed_positive ϕ = true
  well_formed_positive (ϕ^[[evar: x ↦ ψ]]) = true
with wfp_neg_free_evar_subst ϕ ψ x:
  well_formed_closed_mu_aux ψ 0 →
  well_formed_positive ψ = true
  well_formed_positive ϕ = true
  well_formed_positive (ϕ^[[evar: x ↦ ψ]]) = true.

Lemma neg_occurrence_bevar_subst x ϕ y n :
  xy
  evar_has_negative_occurrence x ϕ =
  evar_has_negative_occurrence x ϕ^{evar:ny}
  with
  pos_occurrence_bevar_subst x ϕ y n :
  xy
  evar_has_positive_occurrence x ϕ =
  evar_has_positive_occurrence x ϕ^{evar:ny}.

Lemma neg_occurrence_bsvar_subst x ϕ X n :
  evar_has_negative_occurrence x ϕ =
  evar_has_negative_occurrence x ϕ^{svar:nX}
  with
  pos_occurrence_bsvar_subst x ϕ X n :
  evar_has_positive_occurrence x ϕ =
  evar_has_positive_occurrence x ϕ^{svar:nX}.

Lemma fresh_svar_no_neg X ϕ :
  svar_is_fresh_in X ϕ
  svar_has_negative_occurrence X ϕ = false
  with
  fresh_svar_no_pos X ϕ :
  svar_is_fresh_in X ϕ
  svar_has_positive_occurrence X ϕ = false.

End lemmas.

#[export]
 Hint Resolve wfp_free_evar_subst : core.

This page has been generated by coqdoc