Theory MSOinHOL_subst_extras

theory MSOinHOL_subst_extras
  imports MSOinHOL_deep_subst_lemma
begin

text ‹Explicit rename-evaluation lemmas: renaming a bound variable to a
  fresh f› and updating the assignment preserves truth---the semantic
  core behind L21› / N21›.›

text ‹First-order: rename y› to a fresh f›, then evaluate.›

lemma rename_eval:
  assumes "fresh φ  f" and "y < f"
  shows "(I,D,E⟩,g[fd],G d [yf](φ)) = (I,D,E⟩,g[yd],G d φ)"
proof -
  let ?g' = "g[fd]"
  have fy: "f  y" using assms(2) by simp
  have nf: "f not_free_in φ" using assms(1) by (meson L6 leD)
  have "f not_in φ" using assms(1) by (meson L5 L6 leD)
  hence sub: "f is_subst_for y in φ" by (rule L18)
  have swap: "?g'[yd] = (g[yd])[fd]"
    using fy by (rule L2)
  have "(I,D,E⟩,?g',G d [yf](φ)) = (I,D,E⟩,?g'[y(?g' f)],G d φ)"
    using sub by (rule SubstitutionLemma)
  also have " = (I,D,E⟩,?g'[yd],G d φ)" by simp
  also have " = (I,D,E⟩,(g[yd])[fd],G d φ)"
    using swap by simp
  also have " = (I,D,E⟩,g[yd],G d φ)"
    using nf by (simp add: L12)
  finally show ?thesis .
qed

text ‹Second-order: rename Y› to a fresh f›, then evaluate.  (The
  monadic-set twin of rename_eval›.)›

lemma rename_eval2:
  assumes "fresh2 φ  f" and "Y < f"
  shows "(I,D,E⟩,g,GfS d [Y2f](φ)) = (I,D,E⟩,g,GYS d φ)"
proof -
  let ?G' = "GfS"
  have fy: "f  Y" using assms(2) by simp
  have nf: "f not_free2_in φ" using assms(1) by (meson N6 leD)
  have "f not2_in φ" using assms(1) by (meson N5 N6 leD)
  hence sub: "f is_subst2_for Y in φ" by (rule N18)
  have swap: "?G'YS = GYSfS"
    using fy by (rule M2)
  have "(I,D,E⟩,g,?G' d [Y2f](φ)) = (I,D,E⟩,g,?G'Y(?G' f) d φ)"
    using sub by (rule SubstitutionLemma2)
  also have " = (I,D,E⟩,g,?G'YS d φ)" by simp
  also have " = (I,D,E⟩,g,(GYS)fS d φ)"
    using swap by simp
  also have " = (I,D,E⟩,g,GYS d φ)"
    using nf by (simp add: N12)
  finally show ?thesis .
qed

end