Here’s one way:

```
rules = CoefficientRules(P, {x, y})
newrules = MapAt(f, #, 2) & /@ rules
FromCoefficientRules(newrules, {x, y})
```

Or, in general,

```
CoefficientMap(f_, P_) := FromCoefficientRules(
MapAt(f, #, 2) & /@ CoefficientRules(P, Variables(P)), Variables(P))
CoefficientMap(f_, P_, vars_) := FromCoefficientRules(
MapAt(f, #, 2) & /@ CoefficientRules(P, vars), vars)
```

In general, if you replace `MapAt(f, #, 2) &`

with a function which takes `Rule(powerlist, coeff)`

to `Rule(newpowerlist, newcoeff)`

, you could build more general maps on polynomials! (Currently, `MapAt(f, #, 2) &(Rule(p, c))`

yields `Rule(p, f(c))`

.)

For the application you mention later on, though, where you change `Sin(2 x)`

to `Sin(4 x)`

it sounds like you might want to build your own version of `Variables`

or `CoefficientRules`

for that situation which would extract and encode Fourier coefficients of finite Fourier series (or something like that)—possibly by converting them into polynomial variables in their own right.