Fixpoint cache_lookup (C: cache) (t: term) : term :=
match t with
| var _       => t
| capply c lt => capply c (map (cache_lookup C) lt)
| fapply f lt => match assoc_cache (fapply f (map (cache_lookup C) lt)) C with
| Some v => @term_from_value _ _ _ v
| None   => t
end
end.

(* Specifications: *)
Lemma cache_lookup_value (C: cache) (v: value):
let t := @term_from_value _ _ _ v in cache_lookup C t = t.
Lemma map_cache_lookup_value (C: cache) (lv: list value):
let lt := map (@term_from_value _ _ _) lv in map (cache_lookup C) lt = lt.