# Using Replace for derivative

I have a small issue in understanding the workflow of Replace /. When I give this input:

(y''[x]+y[x]) /. y[x] -> 1


I am getting just 1+y''[x]. I can understand this but is there some special format so that it takes the constant value and gives the derivative as zero. For arbitrary function is there some special way of defining it?

• y[x] -> 1 only says to replace anything that looks like y[x], and y''[x] doesn't look like it at all (check with InputForm[] or FullForm[] to see). Try (y''[x] + y[x]) /. y -> (1 &). Commented May 26, 2020 at 14:49
• Thank you so much for clearing this. I used this method in my main problem and it works. Commented May 26, 2020 at 15:13

You can do as JM suggested

 (y''[x]+y[x]) /. y -> (1 &)


Or make it a little more explicit, which might make it more clear

  (y''[x] + y[x]) /. y -> Function[{x}, 1]


Both cases return 1

For example, if you want y=x^2 then

  (y''[x] + y[x]) /. y -> Function[{x}, x^2]


gives

   2 + x^2

• Thank you, this makes my problem much simpler. I had to substitute a solution to a differential equation and check it. Your and @JM method both work. Commented May 26, 2020 at 15:16
• @SyedNaqvi - when solving the differential equation, instead of using DSolve[eqn, y[x], x] which returns {{y[x] -> ...}}, use DSolve[eqn, y, x] which will return {{y -> Function[{x}, ...}}. Commented May 26, 2020 at 15:36