# How to use PadeApproximant with a defined Derivative?

I need to generate a Pade approximant expansion in v of the following:

$$g(x,v)\equiv \ln\int_{-\infty}^{\infty}e^{-y\left(z\right)}N\left(x-z,v\right)\,\mathrm{d}z$$

where $y(x)\equiv\sum_{i=1}^{n}c_{i}x^{i}$, $n$ is even, and $c_{n}>0$ so the integral converges. $N(x,v)$ is the PDF of the Normal distribution in $x$ with variance $v$. I can generate derivatives of $g[x,v]$ wrt $v$ using the following relations, which arise from properties of the Normal:

$$\frac{dg[x,v]}{dv}=\frac{1}{2}\frac{d^{2}g}{dx^{2}}+\frac{1}{2}\left(\frac{dg}{dx}\right)^{2}$$

$$g[x,0]=y(x)$$

This code implements the above relations:

ord = 5;
Derivative[q_, 1][g][x_, v_] =
D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}]/2;
h = Table[D[g[x, v], {v, i}], {i, 0, ord - 1}];
y[x_] := Sum[c[i]*x^i, {i, 0, 4}];
dgdv =
Expand[h /. Derivative[q_, 0][g][x, v] -> D[y[x], {x, q}] /. g[x, v] -> y[x]]


But Series doesn't work:

Series[g[x, v], {v, 0, 2}]


$\qquad g(x,0)+v g^{(0,1)}(x,0)+\frac{1}{2} v^2 g^{(0,2)}(x,0)+O\left(v^3\right)$

and I couldn't figure out how to get pattern matching to complete the result:

Series[g[x, v], {v, 0, 2}] /.
Derivative[q_, r_][g][x, v] ->
D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}, {v, r - 1}]/2


gives the same result as the foregoing.

I can cope with Series not working because that's easy to hack around, but what I really want to generate is the Pade approximant of g[x, v] in v, but that's more complicated to hack around.

I realize I could just take the PadeApproximant of a Taylor series generated with my hack code, but that doesn't sound look good practice.

Any ideas?

### Edit

I think Series or PadeApproximant might work if I could create a definition of the derivative that works on 2nd derivative wrt v and higher. It's not an issue in my code above because Mathematica seems to just be applying my 1st derivative definition repeatedly. But Series doesn't seem to know to do that, and I can't figure out how to define the derivative w.r.t higher orders of v without causing a recursion problem. I'm posting that as a separate Question

• Your pattern is incomplete. Use Derivative[q_, 1][g][x_, v_] := D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}]/2; and it works. Note the change to SetDelayed, too, as it generally is what you want, but it makes no difference here. Oct 12, 2015 at 18:44
• @rcollyer No, doesn't fix the problem. Series still fails. Oct 12, 2015 at 18:49
• I get SeriesData[v, 0, { g[x, 0], Rational[1, 2] ( Derivative[1, 0][g][x, 0]^2 + Derivative[2, 0][g][x, 0]), Rational[1, 2] Derivative[0, 2][g][x, 0]}, 0, 3, 1] what do you get? Oct 12, 2015 at 18:55
• I just get the series left in terms of derivs wrt v. The result I want would be in terms of x and the c[i] coefficients. I can't make any sense of the result you got, but it's definitely not the answer. Oct 12, 2015 at 19:09
• plug that into mma and hit return. Barring that, using Normal on the SeriesData gives g[x, 0] + (1/2)*v^2*Derivative[0, 2][g][x, 0] + (1/2)*v*(Derivative[1, 0][g][x, 0]^2 + Derivative[2, 0][g][x, 0]) which means it did use the Derivative you specified. Oct 12, 2015 at 19:25

On the surface, this should work

Derivative[q_, 1][g][x_, v_] :=
D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}]/2;
Derivative[q_, n_][g][x_, v_] :=
D[D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}]/2, {v, n - 1}]


But, as we both discovered, it generates recursion errors when fed

Derivative[0, #][g][x, 0] & /@ Range[5]


So, we need to limit the one pattern, e.g.

Derivative[q_, n_?Positive][g][x_, v_] := ...


But, doing that we discover another issue: v is set to a value, so that

Derivative[1, 2][g][x, 0]


generates a General::ivar message stating 0 is not a variable. This takes a little more work,

Derivative[q_, n_?Positive][g][x_, v_] :=
Block[{a, b, res},
res = D[(D[g[a, b], {a, 2}] + D[g[a, b], a]^2), {b, n - 1}, {a, q}];
{a, b} = {x, v};
res
]


to replace both patterns. But, for some reason, this does not want to apply the derivative recursively, so we can force it to

Derivative[0, 2][g][x, 0] //.
Derivative[q_, n_?Positive][g][x_, v_] :>
Block[{a, b, res},
res = D[(D[g[a, b], {a, 2}] + D[g[a, b], a]^2), {b, n - 1}, {a, q}];
{a, b} = {x, v};
res
]
(*
2*Derivative[2, 0][g][x, 0]^2
+ 2*Derivative[1, 0][g][x, 0]*Derivative[3, 0][g][x, 0]
+ 2*Derivative[1, 0][g][x, 0]*(2*Derivative[1, 0][g][x, 0]*Derivative[2, 0][g][x, 0]
+ Derivative[3, 0][g][x, 0]) + Derivative[4, 0][g][x, 0]
*)


I'll post more later.