Section HSUBST.
#[local] Open Scope list_scope.
Definition to_hsubst (s : subst L') : hsubst :=
fun z : hatom =>
match z with
| inl x => s x
| inr c => @Con_trm L' (inr c)
end.
Definition from_hsubst (sigma : hsubst) : subst L' :=
fun z : ivar => sigma (inl z).
Fixpoint accum_hatom_in_trm (t : trm L') : list hatom :=
match t with
| Var_trm x => [inl x]
| Fun_trm f ts => accum_hatom_in_trms ts
| Con_trm c =>
match c with
| inl cc => []
| inr hc => [inr hc]
end
end
with accum_hatom_in_trms {n : nat} (ts : trms L' n) : list hatom :=
match ts with
| O_trms => []
| S_trms n t ts => accum_hatom_in_trm t ++ accum_hatom_in_trms ts
end.

Lemma in_accum_hatom_in_trm_iff_is_free_in_trm x (t : trm L')
: L.In (inl x) (accum_hatom_in_trm t) <-> is_free_in_trm x t = true
with in_accum_hatom_in_trms_iff_is_free_in_trms n x (ts : trms L' n)
: L.In (inl x) (accum_hatom_in_trms ts) <-> is_free_in_trms x ts = true.