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

So I copied and modified that start of schwarzschild.cnb to my own notebook which I'll call Laplacian.cnb

I modified the first code block to add some more coordinates vr, vtheta, vphi (intended to represent velocities -- I'm working in velocity phase space).

{t,r,\theta,\phi, vt, vr, vtheta, vphi}::Coordinate;
{\mu,\nu,\rho,\sigma,\lambda,\kappa,\chi,\gamma}::Indices(values={t,r,\phi,\theta}, position=fixed);
\partial{#}::PartialDerivative;
g_{\mu\nu}::Metric.
g^{\mu\nu}::InverseMetric.

Now I try to define a simple (scalar) function f, which is just f() = r + vtheta**2 and try to evaluate \partial_r f. My code block is

f::Depends(r,\theta,\phi, vr, vtheta, vphi);
exf:= { f = r + vtheta**2 } ;
exfr:= { fr = \partial_r{f} };
evaluate(exfr,exf);

The final line of output is just \partial_r f. I.e., it didn't perform the partial derivative. (The answer should have been 1.)

What am I doing wrong?

in General questions by (460 points)

1 Answer

+1 vote

The evaluate does not substitute scalar functions, only component values (which is arguably misleading, and will possibly change in the future). But you can easily work around this by first substituting and then evaluating:

substitute(exfr, exf);
evaluate(exfr);

In fact the 2nd line then only really calls simplify, so you may as well use that.

by (82.6k points)

This one is strange. When I first changed my "evaluate" to "simplify", it worked.

But now, after what "should" be trivial changes, it doesn't work anymore. But evaluate does work ok. My code block is:

exf:= { f = r + vtheta**2 + \sin{\theta} vphi**2 } ;
exfth:= { fth = \partial_{\theta}{f} };
exfvth:= { fvth = \partial_{vtheta}{f} };
exfr:= { fr = \partial_{r}{f} };
substitute(exfr, exf);
evaluate(exfr);

Your code works well on my machine.

...