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

I start with a expression, for example where I have

ex := \eta^{\mu \nu}\partial_{\mu}{\phi} \partial_{\nu}{\phi};

then I do

substitute(ex, $\partial_{\mu}{\phi} -> -i*p_{\mu}*\phi$);

This command will change both terms $\partial_{\mu}\phi$, but I'd like to substitute just the first term, because the second term I'd like to substitute by $-i k_{\mu}$. How can I do this?

in General questions by (140 points)

1 Answer

0 votes

Currently not possible, but it's a good suggestion to include this feature. I'm thinking of adding a once flag to algorithms, which when True, will stop the algorithm as soon as it has applied somewhere once. That would be relatively quick to add.

A more powerful thing to have would be to allow a replacement list on the right-hand side of the substitution rule, such that subsequent replacements get handled differently. Something like

substitute(ex, $\partial_{\mu}{\phi} -> -i { p_{\mu}, k_{\mu } } \phi$);

Or something like that. This needs more thinking.

by (83.1k points)
...