Differentiating the sigmoid function using limits $$
f(x) =\dfrac{1}{1 + e^{-x}}
$$
The derivative of the above function is:
$$
{f}'(x) =\dfrac{e^{-x}}{(1 + e^{-x})^2}
$$
But when I try to use the definition of the derivative:
$$
h = \Delta x
$$
$$
{f}'(x) = \lim_{h \to 0} \dfrac{f(x + h) - f(x)}{h}
$$
My solution turned out this way:
$$
=\lim_{h \to 0} \dfrac{\dfrac{1}{1 + e^{-(x+h)}} - \dfrac{1}{1 + e^{-x}}}{h}
$$
$$
=\lim_{h \to 0} \dfrac{\dfrac{1 + e^{-x}-(1 + e^{-(x+h)})}{(1 + e^{-(x+h)})\cdot (1 + e^{-x}) }}{h}
$$
$$
=\lim_{h \to 0} \dfrac{\dfrac{1 + e^{-x}-1 - e^{-(x+h)})}{(1 + e^{-(x+h)})\cdot (1 + e^{-x}) }}{h}
$$
$$
=\lim_{h \to 0} \dfrac{\dfrac{e^{-x}- e^{-x-h}}{(1 + e^{-(x+h)})\cdot (1 + e^{-x}) }}{h}
$$
If $h \to 0$:
$$
=\lim_{h \to 0} \dfrac{0}{(1 + e^{-x})^2 } = 0
$$
Where am I making a mistake to get to the result
$$
{f}'(x) =\dfrac{e^{-x}}{(1 + e^{-x})^2}
$$
Could you help me?
 A: The answer step by step, the way was to use L'Hopital's rule when there is an indeterminacy in the limit like $$ \frac{0}{0}  or  \frac{\infty}{\infty} $$
step by step:
$$
f(x) =\dfrac{1}{1 + e^{-x}}
$$
$$
h = \Delta x
$$
$$
{f}'(x) = \lim_{h \to 0} \dfrac{f(x + h) - f(x)}{h}
$$
$$
=\lim_{h \to 0} \dfrac{\dfrac{1}{1 + e^{-(x+h)}} - \dfrac{1}{1 + e^{-x}}}{h}
$$
$$
=\lim_{h \to 0} \dfrac{\dfrac{1 + e^{-x}-(1 + e^{-(x+h)})}{(1 + e^{-(x+h)})\cdot (1 + e^{-x}) }}{h}
$$
$$
=\lim_{h \to 0} \dfrac{\dfrac{1 + e^{-x}-1 - e^{-(x+h)})}{(1 + e^{-(x+h)})\cdot (1 + e^{-x}) }}{h}
$$
$$
=\lim_{h \to 0} \dfrac{\dfrac{e^{-x}- e^{-x-h}}{(1 + e^{-(x+h)})\cdot (1 + e^{-x}) }}{h}
$$
$$
=\lim_{h \to 0}\dfrac{e^{-x}- e^{-x-h}}{(1 + e^{-(x+h)})\cdot (1 + e^{-x}) } \cdot\dfrac{1}{h}
$$
$$
=\lim_{h \to 0}\dfrac{e^{-x}- e^{-x-h}}{h} \cdot\dfrac{1}{(1 + e^{-(x+h)})\cdot (1 + e^{-x})}
$$
Here we have an indeterminacy:
$$
=\lim_{h \to 0}\dfrac{e^{-x}- e^{-x-h}}{h} = \dfrac{e^{-x}- e^{-x-0}}{0} =  \dfrac{0}{0}
$$
So we can use L'Hopital's rule differentiating each function:
$$
\dfrac{d}{dh} \left(e^{-x} - e^{-x-h}\right) = \dfrac{d}{dh} (e^{-x}) - \dfrac{d}{dh} (e^{-x-h}) = 0 + e^{-x-h} = e^{-x-h}
$$
$$
\dfrac{d}{dh} (h) = h = 1
$$
$$
\dfrac{\dfrac{d}{dh} \left(e^{-x} - e^{-x-h}\right)}{\dfrac{d}{dh} (h)} = \dfrac{e^{-x-h}}{1}
$$
Substitute by zero
$$
=\lim_{h \to 0}\dfrac{e^{-x}- e^{-x-h}}{h} =  \dfrac{e^{-x-0}}{1}
$$
$$
=\lim_{h \to 0}\dfrac{e^{-x}- e^{-x-h}}{h} =  e^{-x}
$$
We do the distributive on the denominator:
$$
=\lim_{h \to 0}\dfrac{1}{(1 + e^{-(x+h)})\cdot (1 + e^{-x})}
$$
$$
\lim_{h \to 0}\dfrac{1}{1 + e^{-x} + e^{-(x+h)} + e^{-(x+h)}\cdot e^{-x}}
$$
We simplify:
$$
\lim_{h \to 0} \dfrac{1}{1 + e^{-x} + e^{-x-h} + e^{-2x-h}}
$$
we can substitute for 0 that will not occur indetermination:
$$
\lim_{h \to 0} \dfrac{1}{1 + e^{-x} + e^{-x-0} + e^{-2x-0}}
$$
$$
\lim_{h \to 0} \dfrac{1}{1 + e^{-x} + e^{-x} + e^{-2x}}
$$
$$
\lim_{h \to 0} \dfrac{1}{1 + 2e^{-x} + e^{-2x}}
$$
Factoring the denominator
$$
\lim_{h \to 0} \dfrac{1}{(1 + e^{-x})^2}
$$
Conclusion:
$$
=\lim_{h \to 0}\dfrac{e^{-x}- e^{-x-h}}{h} \cdot\dfrac{1}{(1 + e^{-(x+h)})\cdot (1 + e^{-x})}
$$
$$
=\lim_{h \to 0} \dfrac{e^{-x}}{1} \cdot \dfrac{1}{(1 + e^{-x})^2}
$$
$$
\lim_{h \to 0} \dfrac{\dfrac{1}{1 + e^{-(x+h)}} - \dfrac{1}{1 + e^{-x}}}{h} = \dfrac{e^{-x}}{(1 + e^{-x})^2}
$$
