let apply_subst subst =
let rec apply_subst_on_term = function
Pair(t1,t2) ->
Pair(apply_subst_on_term t1, apply_subst_on_term t2)
| Scrypt(t1,t2) ->
Scrypt(apply_subst_on_term t1, apply_subst_on_term t2)
| Crypt(t1,t2) ->
Crypt(apply_subst_on_term t1, apply_subst_on_term t2)
| Cons(t1,t2) ->
Cons(apply_subst_on_term t1, apply_subst_on_term t2)
| Delete(t1,t2) ->
Delete(apply_subst_on_term t1, apply_subst_on_term t2)
| Inv(t) ->
Inv(apply_subst_on_term t)
| Function(t1,l) ->
Function(apply_subst_on_term t1,
List.map apply_subst_on_term l)
| Set(l) ->
Set(List.map apply_subst_on_term l)
| Base(Var(x)) as t ->
if List.mem_assoc t subst then
List.assoc t subst
else t
| Prime(Var(x)) as t ->
if List.mem_assoc t subst then
List.assoc t subst
else t
| t -> t
in apply_subst_on_term