# Replacement of terms/Pattern matching involving products of derivatives of a function

In delving into Ramanujan summation, I'm trying to get a hold of the relations of the form

$$\sum_{n=0}^\infty f(n)=\dfrac{h\frac{d}{dx}}{{\mathrm{e}^{h\frac{d}{dx}}}-1}\int_{0}^\infty f(x)\,{\mathrm{d}x}.$$

To express the right hand side in Mathematica, I might introduce an auxillary parameter in place of $\frac{d}{dx}$ and then do pattern to find the powers $\frac{d^k}{dx^k}f(x)$.

But it appears to me that I can actually avoid the shift operation $\mathrm{e}^{h\frac{d}{dx}}$ by expanding the quotient of infinitesimal vs. finite difference and do pattern matching for the result. So I'd like to the result of

Df = f'[x];
Dhf = (f[x + h] - f[x])/h;

Series[-Df/Dhf, {h, 0, 3}]


and replace each factor of $\dfrac{\prod_i f^{(a_i)}(x)^{b_i}}{f'(x)^c}$ with $\left(\frac{d}{dx}\right)^{\sum_ia_i\cdot b_i-c-1}$. For example,

• The expression in the first coefficient $\dfrac{f^{(2)}(x)^1}{f'(x)^1}$ becomes $f^{(2\cdot 1-1-1)}(x)=f(x)$.

• The expression $\dfrac{f'(x)\,f^{(3)}(x)}{f'(x)^2}$, which is part of the second coefficient becomes $f^{(1\cdot 1+3\cdot 1-2-1)}(x)=f'(x)$.

What happens is that the individual $f$-fraction in the term coefficient of $h^n$ are substituted with $f^{(n-1)}$. But it's relevant to keep all right the numerical coeffients, $\frac{1}{2}, -\frac{1}{12}$, etc.

(In the end I want to plug in $f(n):=n$, remove the leading coeffient by adding $1$ to the expression, evaluate at $n=0$ and obtain $1+2+3+\dots=-\frac{1}{12}$.)

I'm experimenting with the replace function, but I'm getting Tag-messages and I'm not sure if I need to order the terms for Mathematica to see what I want. How do I perform the above replacement of terms? This is the technique I want to learn here.

What I do can do is use

$\frac{1}{a}=\frac{1}{1-(1-a)}=1+(1-a)+(1-a)^2+\dots$

and obtain

 -Sum[
(1 - Series[f[x + h] - f[x], {h, 0, 3}]/h)^k,
{k, 0, 2}]

% /. {D[f[x], {x, n_}] -> 1}


but this is only an approximation and the expansion mixes up the orders of differentiation.

This might be along the lines of what you want. I expand the terms before trying the replacement, and do that in two steps so I don't have to deal separately with all manner of products.

Df = f'[x];
Dhf = (f[x + h] - f[x])/h;
ss = Expand[Normal[Series[-Df/Dhf, {h, 0, 3}]]]

(* Out[79]= -1 + (h*Derivative[2][f][x])/(2*Derivative[1][f][x]) -
(h^2*Derivative[2][f][x]^2)/(4*Derivative[1][f][x]^2) +
(h^3*Derivative[2][f][x]^3)/(8*Derivative[1][f][x]^3) +
(h^2*Derivative[3][f][x])/(6*Derivative[1][f][x]) -
(h^3*Derivative[2][f][x]*Derivative[3][f][x])/
(6*Derivative[1][f][x]^2) + (h^3*Derivative[4][f][x])/
(24*Derivative[1][f][x]) *)
ss /. Derivative[n1_][f][x]^(e1_.) :> ddx^n1*e1 /.
ddx^(n_.) :> D[f[x], {x, n - 1}]

(* Out[83]= -1 - (1/2)*h*Derivative[2][f][x] +
h^2*Derivative[2][f][x] -
(9/8)*h^3*Derivative[2][f][x] - (1/6)*h^2*Derivative[3][f][x] -
(1/24)*h^3*Derivative[4][f][x] + (1/3)*h^3*Derivative[5][f][x] *)