load("diag");

/* real spatial metric \tilde{\gamma}_ij */
g : matrix(
    [g_xx, g_xy, g_xz],
    [g_xy, g_yy, g_yz],
    [g_xz, g_yz, g_zz]);

/* real spatial metric determinant \tilde{\gamma} = det(\tilde{\gamma}_{ij}) */
determinant(g)$ expand(%);

/* spatial metric inverse times determinant: \tilde{\gamma} \tilde{\gamma}^{ij} */
invert(g) * determinant(g)$
ratsimp(%);

/* complex metric 
\gamma_{ij} = \tilde{\gamma}_{ij} - i \tilde{\epsilon}_{ijk} B^k
\gamma_{ij} = \tilde{\gamma}_{ij} - i \sqrt{\tilde{\gamma}} [ijk] B^k
so 'd' in Maxima is equal to 'determinant(g)' */
g2 : g - %i * sqrt(d) * matrix(
    [0, Bz, -By],
    [-Bz, 0, Bx],
    [By, -Bx, 0]);

/* complex metric determinant \gamma = det(\gamma_{ij}) */
determinant(g2)$ expand(%);

/* difference between complex and real metric:
\gamma - \tilde{\gamma} = -\tilde{\gamma} \tilde{\gamma}_{ij} B^i B^j
\gamma - \tilde{\gamma} (1 - \tilde{\gamma}_{ij} B^i B^j) = 0
\gamma = \tilde{\gamma} (1 - \tilde{\gamma}_{ij} B^i B^j)
*/
determinant(g2) - determinant(g)$ expand(%);

/*
\gamma^{ij} \gamma - \tilde{\gamma}^{ij} \tilde{\gamma} = -\tilde{\gamma} B^i B^j + i \sqrt{\tilde{\gamma}} [ijk] \tilde{\gamma}_{kl} B^l
\gamma^{ij} \tilde{\gamma} (1 - \tilde{\gamma}_{ij} B^i B^j) = \tilde{\gamma} (\tilde{\gamma}^{ij} - B^i B^j + i 1/\sqrt{\tilde{\gamma}} [ijk] \tilde{\gamma}_{kl} B^l)
\gamma^{ij} = (\tilde{\gamma}^{ij} - B^i B^j + i 1/\sqrt{\tilde{\gamma}} [ijk] \tilde{\gamma}_{kl} B^l) / (1 - \tilde{\gamma}_{ij} B^i B^j)
\gamma^{ij} = (\tilde{\gamma}^{ij} - B^i B^j + i \tilde{\epsilon}^{ijk} \tilde{\gamma}_{kl} B^l) / (1 - \tilde{\gamma}_{ij} B^i B^j)
*/
invert(g2) * determinant(g2) - invert(g) * determinant(g)$
ratsimp(%);

invert(g2) * determinant(g2) - invert(g) * determinant(g) + d * transpose(matrix([Bx, By, Bz])) . (matrix([Bx, By, Bz]))$
ratsimp(%);