# How can I invert the product rule nicely [where there are extra numerical factors]?

+1 vote

I am trying to invert the product rule in the following situation:

ex := \partial_{a}{A} B + 2 A \partial_{a}{B}

(update: here I stress the extra factor of 2 in front of the last term)

and I tried the command

substitute(ex, $\partial_{a?}{A??} B?? + A?? \partial_{a?}{B??} -> \partial_{a?}{A?? B??}$);

but it does not work. I don't want to do this one by one as there are many terms like this in my calculation.

I wonder if there's a method that I can unwrap

2 A \partial_{a}{B} -> A \partial_{a}{B} + A \partial_{a}{B}

so that these can be tackled individually?

Thanks very much!

edited

+1 vote

I could factor the terms as you wanted.

The behaviour of your session might be due to the properties of your objects.

I took your (incomplete) example, and re-ensembled it like this:

{a,b}::Indices.
\partial{#}::PartialDerivative.
{A,B,C,D}::Depends(\partial{#}).

ex := \partial_{a}{A} B + A \partial_{a}{B};

rule := \partial_{b?}{C??} D?? + C?? \partial_{b?}{D??}
-> \partial_{b?}{C?? D??};

substitute(ex, rule);

Update

Physics Cat thank you for highlighting that the extra factor of 2 was not a typo.

rule2 := \partial_{b?}{C??} D?? -> - C?? \partial_{b?}{D??}
+ \partial_{b?}{C?? D??};

The whole notebook (MWE) would be:

{a,b}::Indices.
\partial{#}::PartialDerivative.
{A,B,C,D}::NonCommuting.
{A,B,C,D}::Depends(\partial{#}).

ex1 := \partial_{a}{A} B + A \partial_{a}{B};
rule := \partial_{b?}{C??} D?? + C?? \partial_{b?}{D??}
-> \partial_{b?}{C?? D??};
substitute(ex1, rule);

ex2 := \partial_{a}{A} B + 2 A \partial_{a}{B};
rule2 := \partial_{b?}{C??} D?? -> - C?? \partial_{b?}{D??}
+ \partial_{b?}{C?? D??};
substitute(ex2, rule2);

Hope this could be of use!

by (14.9k points)
selected

What is the purpose or meaning of the question marks (and double question marks) in your rule?

Those question marks are for pattern matching (like a kind of regular expression).

A \partial_{a}{B} + 2 \partial_{a}{A} B
Hi Physics Cat I've updated the answer to your question. Hope this could be useful.