My background is not mathematics and I need to implement (in C++) the derivative of a binomial, with wxMaxima and wolfram.alpha as a helper. So far, the binomial can be written as: $$\binom x n = \frac 1 {n!}\prod_{k=1}^n (x-k+1)$$ This reduces to a continued convolution. For my specific needs, the binomial needs to be of the form: $$\binom{\frac{n+1}{2}x+\frac{n-1}{2}}{n}$$ But I also need the derivative of it, which wxMaxima solves as $$-\frac{1}{2}(n+1) \,\left( \psi_0\left( \frac{(n+1) x-n+1} 2 \right) -\psi_0 \left( \frac{(n+1) \,(x+1) }{2}\right) \right) \,\begin{pmatrix}\frac{( n+1) x+n-1}{2}\\ n \end{pmatrix}$$
while wolfram goes a bit further and, instead of $\psi_0$ gives $H_n$, which they call harmonic number. (this link). That $\psi$ seems to have quite an involved formula, but $H_n$,as functions.wolfram has it, is a simple $\sum_{k=1}^n 1/k$, which is a lot simpler in terms of C++.
Now, because I have trust issues, I went on to verify the answer given by wolfram, in wxMaxima, for $n=4$. Here's the code:
n:4$
g:diff(binomial((n+1)/2*(x+1)-1,n),x),expand,numer$
h:-(n+1)/2*binomial((n+1)/2*(x+1)-1,n)*(sum(1/k,k,1,(n+1)/2*(x-1))-sum(1/k,k,1,1/2*(n*(x+1)+x-1)));
wxplot2d([g,h],[x,0,1]);
and here's the output of it:
As you can see, they don't match; plotting wxMaxima's derivation is a match, but that involves $\psi$ as an infinite sum. So I'm left wondering what's wrong: is the implementation of the harmonic number? Is the derivation formula? Is it the way I transcribed it?
TL;DR: I need a derivation formula (not the actual code, that's up to me) for the binomial that is (fairly) simple to implement and doesn't take ages to compute, in C++, as the whole function will be called in a bracketed root-finding algorithm. And I'm also using GMP from gmplib dot org (need 10 rep to post more than 2 links).
Following G Cab's excellent post, and modifying the formulas according to my needs, I managed to come up (with a bit of hammering) to this formula:
$$\frac{d}{dx}\binom{\frac{n+1}{2}x+\frac{n-1}{2}}{n}=(-1)^n \frac{n+1}{2} \binom{\frac{n+1}{2}x + \frac{n-1}{2}}{n} \sum_{k=0}^{n-1} \frac{1}{\frac{n+1}{2}x +\frac{n-1}{2}-k}$$
The $(-1)^n$ takes care of odd $n$. Thank you very much everyone that answered.
For the purpose of computing the derivatives, you can also profitably make use of the expression of the binomials via the Stirling Numbers of 1st kind $$ \binom y n = \frac{y^{\,\underline {\,n\,} }}{n!} = \frac{1}{n!} \sum\limits_{0\, \leqslant \,k\, \leqslant \,n} (-1)^{n - k} \left[ \begin{gathered} n \\ k \end{gathered} \right]y^k $$ Now, to explain about the alternative formulas with $\psi$ and $H$, consider the binomial expressed in terms of the Gamma function $$ \binom y n = \frac{\Gamma (y + 1)}{\Gamma (n + 1)\Gamma (y - n + 1)} = \frac 1 {n!} \frac{\Gamma (y + 1)} {\Gamma (y - n + 1)} $$ then $$ \begin{gathered} \frac d {dy} \binom y n = - \frac 1 {n!} \frac{\Gamma '(y + 1)\Gamma (y - n + 1) - \Gamma (y + 1)\Gamma '(y - n + 1)} {\Gamma (y - n + 1)^2} = \hfill \\ = \frac 1 {n!} \left( {\frac{\Gamma (y + 1)}{{\Gamma (y - n + 1)}} \frac{{\Gamma '(y - n + 1)}} {\Gamma (y - n + 1)} - \frac{{\Gamma (y + 1)}} {\Gamma (y - n + 1)}\frac{\Gamma '(y + 1)} {\Gamma (y + 1)}} \right) = \hfill \\ = \binom y n (\psi _0 (y - n + 1) - \psi _0 (y + 1)) \hfill \\ \end{gathered} $$
Consider instead the binomial expressed in terms of the product,
$$ \binom y n = \frac{y^{\,\underline {\,n\,} }}{n!} = \frac 1 {n!} \prod\limits_{j = 0}^{n - 1} (y - j) $$ then for the derivative you have $$ \begin{gathered} \frac d {dy} \binom y n = \frac 1 {n!} \sum\limits_{0\, \leqslant \,k\, \leqslant \,n - 1} {\prod\limits_{\begin{array}{*{20}c} {j \ne k} \\ {j = 0} \\ \end{array} }^{n - 1} {(y - j)} } = \frac 1 {n!} \sum\limits_{0\, \leqslant \,k\, \leqslant \,n - 1} {\frac{1}{y - k} \prod\limits_{j = 0}^{n - 1} {\left( {y - j} \right)} = } \hfill \\ = \binom y n \sum\limits_{0\, \leqslant \,k\, \leqslant \,n - 1} {\frac{1} {{y - k}}} = \binom y n \sum\limits_{0\, \leqslant \,k\, \leqslant \,n - 1} \frac 1 {y - n + k} \hfill \\ \end{gathered} $$ and for computational purposes, this formula is already quite viable, and I think you do not need to consider the further expansion leading to: $$ \frac d {dy} \binom y n = \binom y n \sum\limits_{0\, \leqslant \,k\, \leqslant \,n - 1} \frac 1 {y - n + k} = \binom y n \sum_{y - n + 1\, \leqslant \,k\, \leqslant \,y} \frac 1 k = \binom y n (H_y - H_{y - n}) $$