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

Hi!

Thanks for Cadabra! I just started playing around. I'm using the Fedora 40 package of Version 2.5.10 (build private dated 2024-12-24).

I'm trying the following:

\partial{#}::PartialDerivative;
t::Coordinate;
O::Depends(t);
{H,O_0}::NonCommuting;

ex := O = \exp(i*H*t) O_0 \exp(-i*H*t);
ex2 := \partial_t{O};

substitute(ex2, ex);

So far so good. However

evaluate(_);

yiels 0 which should not be because H and O_0 are not commuting.

I've read that simplify should not be used (https://cadabra.science/qa/798/simple-commutator-in-quantum-mechanics?show=798#q798) but is this true for evaluate as well?

Thanks in advance,

Sebastian

in General questions by (130 points)

1 Answer

+1 vote

Evaluate calls simplify under the hood. You can turn this off by using

evaluate(_, simplify=False);

However, I think you probably want

product_rule(_);

instead (evaluate is for evaluating components of a tensor expression, but yours is a scalar, so it is already 'evaluated' for that purpose; see the docs for more detail and ask again if it's not clear).

by (84.8k points)

A somewhat more cadabra-esque way of doing this is as follows (a regression in 2.5.10 prevents this from completing but 2.5.12 will roll out soon). First, setup the computation:

\partial{#}::PartialDerivative.
t::Coordinate.
O::Depends(t).

# R = O(t=0)
{H,R}::NonCommuting.

# time-evolution of operator O
exO := O = \exp{i H t} R \exp{-i H t}:

dOdt := \partial_{t}{ @(exO) };

This makes dOdt contain the full equation (not just the right-hand side); note how you can take a partial derivative of an equation and it will apply that on both sides. Then

product_rule(dOdt)
evaluate_derivatives = join($\partial_{t}{R} -> 0 $,
                            $\partial_{t}{\exp{A??}} -> \partial_{t}{A??} \exp{A??}$,
                            $\partial_{t}{i H t} = i H$)

substitute(_, evaluate_derivatives, repeat=True)
factor_out(dOdt, $i$)

Now re-insert the original identity (which you can do using builtin functionality, you don't have to do the swapping of lhs/rhs yourself):

from cdb.core.manip import *
substitute(dOdt, swap_sides(exO))
substitute(dOdt, $A?? B?? - B?? A?? -> \commutator{A??}{B??}$);

This is still not completely optimal in my opinion; more improvements to come over time.

Thanks a lot! If you like, I can work out your version into a tutorial or example. What do you say?

sbstnschmtt: Would you say that I should always evaluate derivatives by explicit substitution?

Would you be so kind to comment on this?

Best,

Sebastian

You don't have much choice at the moment: except for product_rule and distribute, there is no functionality to 'work out' derivatives. Until this is implemented you would need the route through sympy, which is fine for expressions with commuting symbols only.

Examples/tutorials are always welcome, so yes please!

The development branch now has some safeguards which will throw an exception if you attempt to use the sympy bridge with an expression containing non-commuting or anti-commuting objects. This will go into 2.5.12.

...