# xAct/xCoba and DSolve Don't Work Together

Context

I'm trying to derive the Reissner-Nordstrom metric for a charged nonrotating black hole using xAct. The idea is to first have a metric of form

$$ds^2 = e^{2\alpha(r)}dt^2-e^{2\beta(r)}dr^2-r^2d\Omega^2$$

then to write the energy momentum tensor as $$T_{\mu\nu} = -F_{\mu\rho}F_\nu^\rho+g_{\mu\nu}F_{\rho\sigma}F^{\rho\sigma}/4$$

Finally, write the Einstein Equations $$G_{\mu\nu} = 8\pi T_{\mu\nu}$$ and solve for $$\alpha(r)$$ and $$\beta(r)$$ using the differential equations you get.

Getting to the Einstein Equations was relatively straightforward, and I was able to get a system of differential equations.

Unfortunately, the problem is that $$r$$ in this case is represented by xAct by r[], but Mathematica does not allow DSolve to work with differential equations where the independent variable (in this case, $$r$$, since we're trying to solve for $$\alpha$$ and $$\beta$$ as functions of $$r$$) is itself a function. So In order to solve, I had to undefine everything and copy the equations and manipulate them that way.

I was then able to solve for the metric correctly, after an argument that $$\alpha = -\beta$$. The constant $$c_1$$ you see gives us the correct form when we force the metric to be the same as Schwarzchild for $$Q=0$$

Questions

I have two main questions:

(1) Is it possible to have xAct/xCoba work with DSolve directly, without having to undefine everything? Are there packages that work with xCoba that allow for these sorts of differential equation calculations for the metric? It's a bit annoying to have to undefine everything and copy/rewrite the expressions to not include these r[] terms, just to have Mathematica work with it well.

(2) (Less Important) I had a system of 4 differential equations - Certainly some of them are not independent of each other - for example the $$\theta\theta$$ and $$\phi\phi$$ components of the Einstein EQ are not independent. Is there any way I could've avoided the manual argument that $$\alpha = -\beta$$ and had Mathematica show me directly? If I try to put the 4 equations in, Mathematica's DSolve defaults to telling me the EQ are overdetermined. Trying to put any of the 2 equations in that seem independent, say with the $$rr$$ and $$\theta\theta$$ components doesn't have DSolve return anything. Is there any way I could've done this problem completely in Mathematica?

I've put some of my code below - up to where I found the Einstein EQ.

Needs["xActxCoba"]
DefManifold[M, 4, {\[Lambda], \[Mu], \[Nu], \[Rho], \[Sigma], \[Gamma], \[Delta]}];
coords = {t[], r[], \[Theta][], \[Phi][]}; (*Define Manifold*)
DefScalarFunction[alpha,
PrintAs -> "\[Alpha]"]; DefScalarFunction[beta,
PrintAs -> "\[Beta]"]; (*Define Alpha and Beta Functions*)
DefChart[ch, M, {0, 1, 2, 3}, coords, ChartColor -> Blue];
gmatrix = DiagonalMatrix[{Exp[2*alpha[r[]]], -Exp[2*beta[r[]]], -(r[])^2, -r[]^2*(Sin[\[Theta][]])^2}];
g = CTensor[gmatrix, {-ch, -ch}]; (*Define Metric*)
SetCMetric[g, ch, SignatureOfMetric -> {1, 3, 0}];
CD = CovDOfMetric[g];
DefConstantSymbol[Q];
Fmatrix = {{0, -Q/(4 \[Pi]*r[]^2), 0, 0}, {Q/(4 \[Pi]*r[]^2), 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
F = CTensor[Fmatrix, {-ch, -ch}]; (*Define Field Strength Tensor*)
Tmatrix = ComponentArray[-F[{-\[Mu], -ch}, {-\[Rho], -ch}]*F[{-\[Nu], -ch}, {\[Rho], ch}] + g[{-\[Mu], -ch}, {-\[Nu], -ch}]*F[{-\[Rho], -ch}, {-\[Sigma], -ch}]*F[{\[Rho], ch}, {\[Sigma], ch}]/4] // ContractBasis; (*Define Energy Momentum Tensor*)
T = CTensor[Tmatrix, {-ch, -ch}];
EinsteinEQ = {};
For[i = 0, i <= 3, i++,
AppendTo[EinsteinEQ,
FullSimplify[
Einstein[CD][{i, -ch}, {i, -ch}] -
8*\[Pi]*GNewton*T[{i, -ch}, {i, -ch}]] == 0]] (*Build Einstein EQ*)


DSolve[Take[EinsteinEQ, 2], {alpha, beta}, r[]] works fine. It does throw some errors but it still gives the correct result:
Alternately, you can use DSolve[Take[EinsteinEQ, 2] /. {r[] -> r}, {alpha, beta}, r]. This replaces the "function with no argument" r[] with the "atomic symbol" r, which is more what DSolve is expecting. Doing this which solves the equations without throwing any errors (except for the one about inverse functions, but I think that's unavoidable.)
As far as "which equations to use", note that I used the $$tt$$ and $$rr$$ components of the Einstein equation to solve this. There is something of an art to knowing which equations to use when you have symmetries (such as time-invariance here) along with diffeomorphism invariance. This would be off-topic here, but free to as a question over on Physics about this and I'll try to put together an answer on that site.