# Replacement Rules and Function Definitions

I have this code currently:

ClearAll["Global*"]
f[ϕ[x, t]] = (1/4)*ϕ[x, t]^2*(1 - ϕ[x, t])^2;
Ephi = Derivative[1][f][ϕ[x, t]] - ϵ^2*
D[ϕ[x, t], {x, 2}];
u1 = (-(k + k0))*(D[p[x, t], x] - Ephi*D[ϕ[x, t], x]) -
k0*(1 - ϕ[x, t])*D[Ephi, x] - D[ψ[x, t], x];
u2 = (-(k + kw))*(D[p[x, t], x] - Ephi*D[ϕ[x, t], x]) +
kw*ϕ[x, t]*D[Ephi, x];
J = (-M)*ϕ[x, t]*D[Ephi, x];

eq1 = D[ϕ[x, t], t] + D[u1*ϕ[x, t], x] == -D[J, x]
eq2 = D[u1*ϕ[x, t] + u2*(1 - ϕ[x, t]), x] == 0;


The output when the line defining $$eq1$$ is not suppressed looks like: What I'm wondering is why this output doesn't automatically calculate the derivatives of $$f$$ based on the second line of my code? i.e. given that: $$f(\phi) =\frac{1}{4}\phi^2(1-\phi)^2 \implies f'(\phi)=\frac{1}{2}\left(2\phi^3-3\phi^2+\phi \right)$$ But why doesn't Mathematica replace $$f'(\phi(x,t)$$ in the output with this expression? It's not overly important and I know I can use a replacement rule to manually do this, but I am rather new to Mathematica and trying to figure what the program is actually doing.

• Your definition of f doesn't need to involve \phi. Try something like f[u_] := 1/4 (1 - u)^2 u^2 Aug 16, 2022 at 20:49
• Is that random Psi supposed to be in there with all those Phi's? Aug 16, 2022 at 23:03
• yes that's not a typo - it represents a force of an unknown form Aug 17, 2022 at 18:14

The comment by @mikado is a fine answer, and I am providing another one and a point of confusion that was not stressed in the original question explicitly.

The following

ClearAll["Global*"]
f[φ[x, t]] = (1/4)*φ[x, t]^2*(1 - φ[x, t])^2;
Expand@D[f[φ[x, t]], φ[x, t]]


returns

So, out of curiosity we can try

ClearAll["Global*"]
D[f[φ[x, t]], φ[x, t]] // InputForm


And hence, one would thing that in my proposed solution Derivative[1][f][φ[x, t]] would also give the right answer, but

ClearAll["Global*"]
f[φ[x, t]] = (1/4)*φ[x, t]^2*(1 - φ[x, t])^2;
Expand@Derivative[1][f][φ[x, t]]


returns

I know I am not the best and brightest and I have not been very active recently, but the above seems weird unless I am missing something very obvious.

• I haven't been very active recently, either. It seems that we have not followed the activity of the ten ways to solve something :). Aug 16, 2022 at 21:49
• @E.Chan-López I had to move and I have another one comping up. Hopefully, by the end of September I can be back more frequently. I hope you are doing well. Also hope to reinstate the tenfold/ten ways challenge :)
– bmf
Aug 16, 2022 at 21:53