Section EncodingLemmas.
Variable (C: list X) (n: nat).
Hypothesis (O: ord' (map (ctype X) C) < n).
Global Instance enc_proper:
Proper (equiv (@step X) ++> equiv (@step Y)) (enc_term C).
Global Instance inv_proper:
Proper (equiv (@step Y) ++> equiv (@step X)) (inv_term C).
End EncodingLemmas.
Definition iConsts {n} (I: orduni n X) :=
filter (fun x => if R' x == None then true else false)
(Consts [s₀; t₀]).
Program Instance remove_constants n (I: orduni n X)
(H: ord' (map (ctype X) (iConsts I)) < n) : orduni n Y :=
{
s₀ := enc_term (iConsts I) s₀;
t₀ := enc_term (iConsts I) t₀;
A₀ := enc_type (iConsts I) A₀;
Gamma₀ := enc_ctx (iConsts I) Gamma₀;
}.
Next Obligation.
eapply remove_constants_ordertyping; eauto using H1₀.
cbn; simplify; intuition.
eapply filter_In; destruct eq_dec; intuition.
Qed.
Next Obligation.
eapply remove_constants_ordertyping; eauto using H2₀.
cbn; simplify; intuition.
eapply filter_In; destruct eq_dec; intuition.
Qed.

Lemma remove_constants_backward n (I: orduni n X)
(H: ord' (map (ctype X) (iConsts I)) < n):
OU n Y (remove_constants n I H) -> OU n X I.