Fixpoint conv n s (e : BCI) : BC :=
match e with
| zeroI => comp n s zero nil nil
| projIn i => proj n s i
| projIs i => proj n s (n + i)
| succI b => comp n s (succ b) nil [proj n s n]
| predI => comp n s pred nil [proj n s n]
| condI => comp n s cond nil
[proj n s n; proj n s (S n); proj n s (S (S n)); proj n s (S (S (S n)))]
| recI g h0 h1 => rec (conv (n-1) s g)
(conv n (S s) h0)
(conv n (S s) h1)
| compI g ln ls =>
comp n s (conv (length ln) (length ls) g)
(map (conv n 0) ln) (map (conv n s) ls)
end.
Definition zeroI_e := compI zeroI nil nil.
Definition leftI (d:nat)(x:TypeI) : nat :=
match x with
| I n _ => n
| E _ => d
end.
Definition rightI (d:nat)(x:TypeI) : nat :=
match x with
| I _ n => n
| E _ => d
end.

Lemma inf_list_maxl_r : forall l n s,
inf_list l = I n s ->
s = maxl (map (rightI 0) l).