and iter_term d = function
| B.Sort _ as t -> t
| B.GRef _ as t -> t
| B.LRef (a, i) as t -> if i < d then t else map d a i
| B.Cast (a, w, v) -> B.Cast (a, iter_term d w, iter_term d v)
| B.Appl (a, w, u) -> B.Appl (a, iter_term d w, iter_term d u)
and iter_term d = function
| B.Sort _ as t -> t
| B.GRef _ as t -> t
| B.LRef (a, i) as t -> if i < d then t else map d a i
| B.Cast (a, w, v) -> B.Cast (a, iter_term d w, iter_term d v)
| B.Appl (a, w, u) -> B.Appl (a, iter_term d w, iter_term d u)