Solution (source code)

= Solution

Substituting the <fixed-tension partition function of a one-dimensional chain> into the given free-energy definition gives
$$
\boxed{G=-k_BT\log Z=-nk_BT\log(2\cosh(\tau a)).}
$$
Differentiation with respect to the parameter conjugate to extension gives
$$
\frac{\partial G}{\partial\tau}
=-nk_BT\,a\tanh(\tau a).
$$
The same result follows directly from the <expected value> under $p_i=e^{\tau l_i}/Z$:
$$
L=\sum_i p_i l_i
=\frac1Z\frac{\partial Z}{\partial\tau}
=\frac{\partial\log Z}{\partial\tau}.
$$
Consequently
$$
\boxed{L=-\frac1{k_BT}\frac{\partial G}{\partial\tau}},
\qquad
\boxed{\tanh(\tau a)=\frac{L}{na}}.
$$