Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

Hi,

I'm trying to write a code to derive the equations of motion for the electromagnetic Lagrangian. I have the following:

{\mu,\nu,\rho,\sigma}::Indices(position=free).
\partial{#}::Derivative.
FieldStrength := F_{\mu\nu} -> \partial_{\mu}{A_\nu} - \partial_{\nu}{A_\mu};
Lagrangian := L -> -(1/4)F_{\mu\nu}F^{\mu\nu};
S := \int{L}{x}:
substitute(S,Lagrangian);
substitute(S,FieldStrength)
distribute(S)
vary(S, $A_{\mu} -> \delta{A_{\mu}}$);
integrate_by_parts(S, $\delta{A_{\mu}}$);
    factor_out(S, $\delta{A_{\nu}}$);

Everything works until I get to the integration by parts, when I get

RuntimeError: Free indices in different terms in a sum do not match.

If I change \nu to \mu in integratebyparts command it sometimes works, but then I get the same error message on factor_out. I suspect I'm just not understanding something simple about how indices work, but I can't figure out what it is.

Thanks!

asked in General questions by

1 Answer

+1 vote

The reason for that error message is that, as it stands in your code, the object
$\delta(A_{\mu})$ does not have any free indices. That is because Cadabra by default 'absorbs' indices when you apply a function to a tensor. So $\delta(...)$ is seen as a function applied to $A_{\mu}$ and that has no indices.

To make $\delta(...)$ show these indices, you need to give it a property IndexInherit (or if you want to inherit other properties, like dependence on coordinates, you may want to use the catch-all Accent property instead).

With that, your example becomes

{\mu,\nu,\rho,\sigma}::Indices(position=free).
\partial{#}::Derivative.
\delta{#}::Accent.
FieldStrength := F_{\mu\nu} -> \partial_{\mu}{A_\nu} - \partial_{\nu}{A_\mu};
Lagrangian := L -> -(1/4)F_{\mu\nu}F^{\mu\nu};

S := \int{L}{x}:
substitute(S,Lagrangian);
substitute(S,FieldStrength);
distribute(S);

vary(S, $A_{\mu} -> \delta{A_{\mu}}$);
integrate_by_parts(S, $\delta{A_{\mu}}$);
sort_product(_);
canonicalise(_);
factor_out(S, $\delta{A^{\mu}}$);

to produce

$$- \frac{1}{4}\int \delta\left(A^{\mu}\right) \left(-4\partial^{\nu}\left(\partial_{\nu}{A_{\mu}}\right)+4\partial^{\nu}\left(\partial_{\mu}{A_{\nu}}\right)\right) {\rm d}x$$

answered by (54.1k points)
...