I need to convert derivatives of g[x,v] wrt v into derivatives wrt x using this relation:
$$\frac{dg[x,v]}{dv}=\frac{1}{2}\frac{d^{2}g}{dx^{2}}+\frac{1}{2}\left(\frac{dg}{dx}\right)^{2}$$
This code converts the 0-4th derivatives perfectly:
ord = 5;
Derivative[q_, 1][g][x, v] = D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}]/2;
dgdv = Table[D[g[x, v], {v, i}], {i, 0, ord - 1}];
Notice that I only defined the 1st deriv of g wrt v, but MMa was smart enough to just apply the relation repeated. However, Series[] doesn't figure that out, for example it just leaves the 2nd derivative wrt v in that form:
Series[g[x, v], {v, 0, 2}]
$g(x,0)+v g^{(0,1)}(x,0)+\frac{1}{2} v^2 g^{(0,2)}(x,0)+O\left(v^3\right)$
I attempted to fix my definition to cover higher derivatives wrt v explicitly, but then I ran into recursion problems, which I tried and failed to fix as follows:
Derivative[q_, Except[0, n_]][g][x, v] = D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}, {v, n - 1}]/2;
This also failed:
Derivative[q_, 0][g][x_, v_] := D[g[x, v], {x, q}];
Derivative[q_, r_][g][x_, v_] :=
If[r > 1,
D[D[g[x, v], {x, q}, {v, r - 1}], v],
D[(D[g[x, v], {x, 2}] + D[g[x, v], x]^2), {x, q}]/2];
I know that's an ugly solution, but I don't know why it didn't work. Help?