let rec fold f a e = match a with | App(Pp(Mult), xl) -> List.fold_right (fold f) xl e | App(Pp(Expt(n)), [x]) -> f x n e | _ -> f a 1 e