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

Hi,

As a part of a calculation, I have an expression such as

\partial_i {x^j f(r)} where r=\sqrt{x^i x^i} and f is a scalar function of r.

Is it possible to implement such calculations in the current version of Cadabra?

Regards

in General questions by (1.1k points)

1 Answer

+1 vote
 
Best answer

It's not ideal at the moment, but you can do something like

\partial{#}::PartialDerivative;
r::Symbol;
r::Depends(\partial{#});
ex:=\partial_{i}{x^j f(r)};

This makes product_rule work as required,

product_rule(_);

gives $\partial_{i}{x^{j}} f(r) + x^{j} \partial_{i}{ f(r)}$. You then have to help it a bit with the chain rule, e.g.

chainrule:= \partial_{i}{A?(r)} = \partial_{r}{A?(r)} \partial_{i}{r};
substitute(ex, chainrule );

will apply the chain rule on any function of r and in your case gives $\partial_{i}{x^j}f(r) + x^j \partial_{r}{f(r)} \partial_{i}{r}$.

Facilities for these kind of computations are relatively new and there's plenty of space for improvement; I hope to get back to this in fall when I'll have some more manpower to work on Cadabra.

by (83.8k points)
selected by

Thanks for your answer. I wasn't aware of the Symbol property. It is not in the Manual page. I would like ask some questions about your response. In your answer you wrote:

chainrule:= \partial_{i}{A?(r)} = \partial_{r}{A?(r)} \partial_{i}{r};

In the above expression of was expected to use "->" instead of "=". What is the difference between them? As another question, when we define an object as Symbol, can we define an internal structure for it? I mean, define {i,j}::Indices then x^i::Coordinate and r:=x_i x^i and then apply the \partial_{x^i} on it. Is it will return 2x^i? ( I tried but I couldn't!)

I, personally, am anxiously waiting for your new PhD student to boost the development of Cadabra! :)

Regards

Symbol now has a manual page (though it needs extending).

There is no difference between -> and = in a substitution rule; sometimes one reads more naturally, sometimes the other.

For your last question, you need to do that explicitly, e.g.

{i,j,k}::Indices(position=free);
substitute(ex, $\partial_{i}{r} = \partial_{i}{x_j x^j}$);
product_rule(_);
sort_product(_);
canonicalise(_);

Indeed thanks very much for your help. I would like to bother you with another question. In the final result of the above calculation there are some terms like \partial_i x^j. How I can tell to Cadabra that this term is equal to the Kronecker Delta. I know how to do this via the substitute command but I would like to know if there is a more natural way.

...