4.22 How to differentiate treating a combined expression as single variable?

Problem: Differentiate

\[ e^{\frac {2 r}{\sqrt {a}}} + 3 \left ( \frac {r}{\sqrt {a}} \right )+ \left ( \frac {r}{\sqrt {a}} \right )^2 \]

w.r.t \(\frac {r}{\sqrt {a}}\) to produce \[ 2 e^{\frac {2 r}{\sqrt {a}}} + 3 + 2 \frac {r}{\sqrt {a}} \]

In other words, we want to treat \(\frac {r}{\sqrt {a}}\) as \(x\) in the expression

\[ e^{2 x} + 3 x+ x^2 \]

Mathematica

Clear[p, x, r, a] 
p[x_] := Exp[2 x] + x^2 + 3*x; 
v = r/Sqrt[a]; 
With[{v = x}, Inactive[D][p[v], v]]; 
Activate[%]; 
% /. x -> v
 

\(\frac {2 r}{\sqrt {a}}+2 e^{\frac {2 r}{\sqrt {a}}}+3\)

 

Maple

Credit for the Maple answer goes to an internet post by Carl Love

restart; 
D(x->exp(2*x)+3*x+x^2) (r/sqrt(a));
 

\(2\,{{\rm e}^{2\,{\frac {r}{\sqrt {a}}}}}+3+2\,{\frac {r}{\sqrt {a}}}\)