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_HC_occurs_in_trm hc (t : trm L')
: L.In (inr hc) (accum_hatom_in_trm t) <-> HC_occurs_in_trm hc t = true
with in_accum_hatom_in_trms_iff_HC_occurs_in_trms n hc (ts : trms L' n)
: L.In (inr hc) (accum_hatom_in_trms ts) <-> HC_occurs_in_trms hc ts = true.