Use pattern to replace \(x^n\) by \(f(n)\)
restart; expr:=1 + x^2 + x^4; F:=proc(X::anything,x::symbol) local la,y,n; if patmatch(X, (y::anything)^(n::'nonunit'(anything)) ,'la') then if eval(y,la)=1 then #bug in maple? X; else f(eval(n,la)); fi; else X; fi; end proc; map(X->F(X,x), expr); f(4) + f(2) + 1
In Mathematica
1 + x^2 + x^4 /. x^p_ :> f[p] 1 + f[2] + f[4]