let rec fold f a acc =
match a with
| Term.App((Sym.Arith(op), _), al, _) ->
(match op, al with
| Sym.Num _, [] -> acc
| Sym.Multq _, [b] -> fold f b acc
| Sym.Add, bl -> List.fold_right (fold f) bl acc
| _ -> f a acc)
| _ ->
f a acc