kpeeters / cadabra2

A field-theory motivated approach to computer algebra.
https://cadabra.science/
GNU General Public License v3.0
223 stars 37 forks source link

Non-linear action principles #60

Open supercuerda opened 6 years ago

supercuerda commented 6 years ago

Suppose you want to compute the equations of motion of a non-linear action principle, such as the Sine-Gordon model:

S:= \int { (\partial_t \phi)^2-(\partial_x \phi)^2 -2 + 2 \cos(\phi) }{x};

Can you compute the equations of motion? I tried using

vary(S, $\phi -> \delta{\phi}$)

But is seems not to work, as it keeps computing forever...

Is Cadabra equipped to deal with non-linear potentials? It seems to me that it only admits polynomial terms.

kpeeters commented 6 years ago

This is somewhat related to https://cadabra.science/qa/79/error-in-using-vary . The problem is that it requires knowing the derivative of the cosine, and I would really like to avoid adding all that logic into cadabra itself (sympy should be taking care of that). At the moment, the way to solve this is to help cadabra a bit: if you start from

{t,x}::Coordinate;
\partial{#}::PartialDerivative;
\phi::Depends(\partial{#});
S:= \int{ (\partial_{t}{\phi})**2-(\partial_{x}{\phi})**2 -2 + 2 \cos(\phi) }{x};

just do the variation with

vary(S, $\cos(\phi) -> -\sin(\phi)\delta{\phi}, \phi -> \delta{\phi}$);
supercuerda commented 6 years ago

Yes, I was hopping sympy would understand that. I will use your approach. Thanks!