Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+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!

in General questions by (240 points)
edited by

1 Answer

+1 vote
Best answer

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:


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);


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

In your case, I'd follow Kasper's (usual) advise, and use the substitution the other way around,

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

The whole notebook (MWE) would be:


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 (12.5k points)
selected by

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).

Please check the section in the book: https://cadabra.science/notebooks/ref_patterns.html

Thanks for that.

This does not work for my specific question... The main subtlety of my question is the extra factor of 2 in front of one of the terms

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.

Thanks very much! It works perfectly!

Excellent! Nice to hear that.