I know there is already an answer for this type of question given here: Computing the metric tensor under a coordinate transformation but the answer is not satisfactory as it is not clear to me how I could modify the existing code since I can not tell where the transformation laws are for the metric. For background, I know if I want to transform the metric tensor (and any rank-2 tensor for that manner), I use the following formula \begin{equation} g_{\mu\nu}' = \frac{\partial x^\alpha}{\partial x^{\mu '}}\frac{\partial x^\beta}{\partial x^{\nu '}}g_{\alpha\beta} \end{equation} where the initial metric is $g_{\alpha\beta}$ and the new metric is $g_{\mu\nu}'$. Now, for example, I wanted to transform the flat (Minkowski) metric from $(1,-1,-1,-1)$ to a spherically symmetric system $(t,r,\theta,\varphi)$ with the following transformation rules, $t = t'$, $x = r\sin(\theta)\cos(\varphi)$, $y = r\sin(\theta)\sin(\varphi)$, and $z = r\cos(\theta)$.How would I write this in Mathematica (or modify the linked question's code)? (I am very new to Mathematica...) The answer should be $\text{Diagonal}(1,-1,-r^2,-r^2\sin(\theta)^2)$ (in this metric signature).
This is my first step, since really I want to be able to do this for a metric with any components (in $d=4$ dimensions) that also has off-diagonal components. For example, if I had the metric that can be represented as the line element
for some functions (which I can specify if need be) $G(r)$, $F(r)$, and $C(r)$ (you can see why I want to transform this metric to spherical coordinates since the symmetry is manifest in the first term and I want to see if the second term simplifies greatly). This is also why I want to try to write code for the top example since the answer is well known (and I don't know the answer for the second one).
My trouble in writing the code is that there is two implicit sums in the tensor transformation rule that need to take all the possible combinations of derivatives of the transformation rules. So I could write something along the lines of using the sum, D, and define my coordinates with coord and with maybe the table function over all possible coordinates? (Like I said I am very new to Mathematica).
Thanks for any help (or even the code that could do this)!