Section TWILIGHT.
Definition twilight (sigma : hsubst) : subst L' :=
fun z : ivar => sigma (enum (isEnumerable := @sum_isEnumerable ivar Henkin_constants nat_isEnumerable nat_isEnumerable) z).
Fixpoint twilight_trm (t : trm L') : trm L' :=
match t with
| Var_trm x => Var_trm (x * 2)
| Fun_trm f ts => Fun_trm f (twilight_trms ts)
| Con_trm c =>
match c with
| inl cc => Con_trm c
| inr hc => Var_trm (hc * 2 + 1)
end
end
with twilight_trms {n : nat} (ts : trms L' n) : trms L' n :=
match ts with
| O_trms => O_trms
| S_trms n t ts => S_trms n (twilight_trm t) (twilight_trms ts)
end.
Fixpoint twilight_frm (p : frm L') : frm L' :=
match p with
| Rel_frm R ts => Rel_frm R (twilight_trms ts)
| Eqn_frm t1 t2 => Eqn_frm (twilight_trm t1) (twilight_trm t2)
| Neg_frm p1 => Neg_frm (twilight_frm p1)
| Imp_frm p1 p2 => Imp_frm (twilight_frm p1) (twilight_frm p2)
| All_frm y p1 => All_frm (2 * y) (twilight_frm p1)
end.
#[local] Hint Rewrite twilight_trm_spec twilight_trms_spec : simplication_hints.
#[local] Hint Constructors alpha_equiv : core.

Lemma twilight_frm_one_hsubst (x : ivar) (t : trm L') (p : frm L')
: twilight_frm (hsubst_frm (one_hsubst (inl x) t) p) ≡ subst_frm (one_subst (2 * x) (twilight_trm t)) (twilight_frm p).