Section Backward.
Definition decode_subst (sigma: fin -> exp ag) (N: forall x, normal (sigma x)) (x: fin) :=
match dec_enc (N (F x)) with
| inl  (exist _ n _) => n
| inr _ => 0
end.
End Backward.
Definition nileq: eq ag := (lambda lambda a, lambda lambda a).
Definition conseqs e1 e2 :=
match e1, e2 with
| (lambda lambda s1, lambda lambda t1), (lambda lambda s2, lambda lambda t2) => (lambda lambda g s1 s2, lambda lambda g t1 t2)
| _, _ => nileq
end.
Notation foldeqs := (fold_right conseqs nileq).

Lemma foldeqs_correct sigma E:
(forall s1 s2, (s1, s2) ∈ E -> (exists t, s1 = lambda lambda t) /\ (exists t, s2 = lambda lambda t)) ->
(sigma •₊ left_side E) ≡₊ (sigma •₊ right_side E) <->
(sigma • fst (foldeqs E) ≡ sigma • snd (foldeqs E)).