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

I have an expresssion like:

ex:= \int{ \partial_{0}{a} \partial_{0}{a} 
      +  a \partial_{0}{\partial_{0}{a}}}{x};

which I want to show is zero when either term is integrated by parts

However it seems the basic command does both terms

integrate_by_parts(_, $a$, deep=True);


\begin{equation}{}\int \left(-\partial_{0}\left(\partial_{0}{a}\right) a-\partial_{0}{a} \partial_{0}{a}\right){\rm d}x\end{equation}

Which is true, but not really want I want. Is there a way to choose a specific term to IBP.


in General questions by (520 points)
edited by

2 Answers

+2 votes
Best answer

I have pushed some changes to github to fix https://github.com/kpeeters/cadabra2/issues/71 and also make integrate_by_parts more consistent. That is, it will now always integrate by parts only once (even if there is a double derivative), and you have to give it the full argument of the derivative which you want to move away. Example:

ex:= \int{  a \partial_{0}{\partial_{0}{a} } }{x};

which represents

$$\int a \partial_{0 0}{a} {\rm d}x$$

The following

integrate_by_parts(_, $a$);

will not do anything (because \partial_{0} acts on \partial_{0}{a}, not on a). But

integrate_by_parts(_, $\partial_{0}{a}$);

will produce

$$-\int \partial_{0}{a} \partial_{0}{a} {\rm d}x$$

A few more examples of this are in tests/integrals.cdb

For your concrete case, a simple

integrate_by_parts(_, $a$);

will now produce zero because it will only act on the first term.

by (66.3k points)
+1 vote

(see my other answer for the current status)

Integrate away from $\partial_{0}{a}$ instead of $a$, so

integrate_by_parts(_, $\partial_{0}{a}$);

Note that integrate_by_parts has a bug with multiple PartialDerivatives, https://github.com/kpeeters/cadabra2/issues/71, but it works with Derivative.

It would probably make more sense if integrate_by_parts(_, $a$) would not touch the 2nd term at all.

by (66.3k points)

Thanks, that does work on the expression I provided.

Problem is, sometimes I have other additional terms like \partial_{0){a} h^{a b} in the expression as well.

I don't want the IBP to hit this term, just the \partial{0){a} \partial{0){a} term. I should have been more specific earlier.

Any trick to just pick out one term in an expression to act on.

Also, how do I make the Derivative property automatically commuting -- so it is just like a PartialDerivative.


The changes mentioned in my other answer do not yet give you the option to select single terms as in this comment of yours. The right approach to that is to use take_match to work on a sub-expression, do your work there, and then replace_match to put the result back into the original expression. Unfortunately, replace_match has a bug when putting integral expressions back. Will try to get that fixed soon as well.