I'm confused with a really stupid issue, namely computing by hand the first derivative of a Gaussian
$\displaystyle f{{\left({x}\right)}}={e}^{{-{\left(\frac{x}{{{x}_{{0}}}}\right)}^{{{2}{n}}}}}$
The n in the exponent is included, because I actually need a super-Gaussian for approximating a blurred rectangle function. Depending on how I write down the function, I'm getting three different results, which obviously cannot be correct:
1.: $\displaystyle f{{\left({x}\right)}}={e}^{{-{\left(\frac{x}{{{x}_{{0}}}}\right)}^{{{2}{n}}}}}\Rightarrow{f}'{\left({x}\right)}=\frac{d}{{\left.{d}{x}\right.}}{e}^{{-{\left(\frac{x}{{{x}_{{0}}}}\right)}^{{{2}{n}}}}}=-{2}{n}{\left(\frac{x}{{x}_{{0}}}\right)}^{{{2}{n}}}\frac{1}{{x}}{e}^{{-{\left(\frac{x}{{{x}_{{0}}}}\right)}^{{{2}{n}}}}}$
2.: $\displaystyle f{{\left({z}\right)}}={e}^{{-{z}^{{{2}{n}}}}}\Rightarrow{f}'{\left({z}\right)}=-{2}{n}{z}^{{{2}{n}-{1}}}{e}^{{-{z}^{{{2}{n}}}}}=-{2}{n}{\left(\frac{x}{{{x}_{{0}}}}\right)}^{{{2}{n}-{1}}}{e}^{{-{\left(\frac{x}{{{x}_{{0}}}}\right)}^{{{2}{n}}}}}$
3.: $\displaystyle f{{\left({x}\right)}}={\left({e}^{{{x}^{{{2}{n}}}}}\right)}^{{-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}}}\Rightarrow{f}'{\left({x}\right)}=\frac{d}{{\left.{d}{x}\right.}}{\left({e}^{{{x}^{{{2}{n}}}}}\right)}^{{-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}}}\\=\frac{d}{{{d}{\left(-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}\right)}}}{\left[\frac{d}{{{d}{\left(\frac{d}{{\left.{d}{x}\right.}}{x}^{{{2}{n}}}\right)}}}{e}^{{\frac{d}{{\left.{d}{x}\right.}}{x}^{{{2}{n}}}}}\right]}^{{-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}}}\\=\frac{d}{{{d}{\left(-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}\right)}}}{\left[\frac{d}{{{d}{\left({2}{n}{x}^{{{2}{n}-{1}}}\right)}}}{e}^{{{2}{n}{x}^{{{2}{n}-{1}}}}}\right]}^{{-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}}}\\=\frac{d}{{{d}{\left(-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}\right)}}}{\left({e}^{{{2}{n}{x}^{{{2}{n}-{1}}}}}\right)}^{{-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}}}\\={\left({e}^{{{2}{n}{x}^{{{2}{n}-{1}}}}}\right)}^{{-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}}}\\={\left({e}^{{{2}{n}{x}^{{{2}{n}-{1}}}}}\right)}^{{-\frac{1}{{{{x}_{{0}}^{{{2}{n}}}}}}}}\\={e}^{{-{2}{n}{\left(\frac{x}{{{x}_{{0}}}}\right)}^{{{2}{n}}}\frac{1}{{x}}}}$
In the first case, I immediately applied d/dx.
In the second case, I substituted x/x0 =: z and applied d/dz.
In the third case, I explicitly expanded the expression as nested derivates to show the chain rule, then computed the partial derivations starting from the innermost bracket and progressing outwards - that should be exactly the same as in the first case, it's just written out explicitly what one does mentally.
What is the issue here? I was surprised to get an additional factor of 1/x in the first case, but the third case looks completely different.
For your second working, we have $z=\frac{x}{x_0}$,
$$\frac{dz}{dx}=\frac1{x_0}$$
Hence \begin{align} f'(x) &= f'(z)\cdot \color{red}{\frac{dz}{dx}}\\&=\frac{1}{x_0}\left( -2n\left( \frac{x}{x_0}\right)^{2n-1}\right)e^{-\left(\frac{x}{x_0} \right)^{2n}} \\&=\frac{1}{x_0}\left(\frac{x}{x} \right)\left( -2n\left( \frac{x}{x_0}\right)^{2n-1}\right)e^{-\left(\frac{x}{x_0} \right)^{2n}}\\ \\&=\frac{1}{x}\left( -2n\left( \frac{x}{x_0}\right)^{2n}\right)e^{-\left(\frac{x}{x_0} \right)^{2n}} \end{align}
hence, the result is consistent.
I can't follow the logic of the third working. I can't understand why do we have $\frac{d}{d\left(-\frac1{x^{2n}} \right)}$