I would like to redefine a function
f(x)=1+2x^2 to a new function
g(y)=1+2y by using the replacement
x^2 -> y. However, in the MWE below, only
Method 1 gives me the correct one.
What's wrong with the other two methods? Can they be repaired? I am asking because
it may not always be possible to write the replacement in terms of
x (e.g. say,
3x^2-4x+2 -> y).
f[x_] := 1 + 2 x^2; g[y_] = f[y /. y -> Sqrt[y]]; Print["Method 1: g(y)=", g[y]]; g[y_] := Replace[f[y], y^2 -> y]; Print["Method 2: g(y)=", g[y]]; g[y_] = f[y /. y^2 -> y]; Print["Method 3: g(y)=", g[y]];