Closed life-elixir closed 4 years ago
Something like
from cadabra2 import *
Indices(Ex(r'a,b,c,d'),Ex('position=fixed'))
ex = Ex(r'A_{a b} B_{b c}')
The general pattern is that you assign a property to symbols by using the name of the property and then an 'Ex' object containing the symbol list (the 2nd Ex
is there for any arguments of the property; if there are none you still need to pass Ex('')
as 2nd argument).
Hope this helps; if not, ask again.
Hmmm very interesting. Python doesn't return as beautiful annotation as Jupyter though which is sad but is better because I can link it with other programs.
I am sorry for asking again how does this one work then? Is there a manual for this?
substitute(_, $B_{a b} -> C_{a b c} D_{c}$ )
You don't have access to the _
symbol in pure Python, and any mathematical expression in $
signs needs to be written using an Ex
. So
substitute(ex, Ex(r' B_{a b} -> C_{a b c} D_{c} ') )
There is no real manual for this anywhere, as this functionality is essentially a lucky spin-off (Cadabra's origin has nothing to do with Python; the Python wrapper was only introduced in the 2.x series, and most users use the Cadabra pre-processor).
But please just keep asking here, then I may collect these things into a manual at some point.
Another useful one (but maybe you figured that out already) is that the output becomes a lot better by using str
, so
str(ex)
displays a nicer result than the standard output. You can also get other forms, e.g.
ex._latex_() # latex notation
ex.sympy_form() # sympy notation
ex.mma_form() # mathematica notation
In that case, I will build my dissipative quantum field theory app using Cadabra 2 then. Thanks, @kpeeters I will keep you posted.
Yes please, am very curious.
what is the del_superscript symbol (reverse triangle) stand for? I get it that when it has like del_subscribe_mn means the differentiation with respect to n and then with respect to m. What about when the m and n are on the superscript of the triangle? Is that the degree of the differentiation (that doesn't make sense because mn would be a large number like 23). So what is it really? The subscript goes to superscript with unwrap function. What happens in unwrap?
Not entirely sure what you are referring to. Can you give a minimal example that shows what you mean?
The example listed here:
Oh, those indices are raised with the metric. So
\nabla^{m}(...) = \eta^{m n} \nabla_{n}(...)
If you don't like canonicalise
to do that when it feels like doing it, declare your indices with the position=independent
argument.
The unwrap
function takes objects out of the derivative if they do not 'depend' on them (are independent of the coordinate with respect to which the derivative is taken). See https://cadabra.science/manual/unwrap.html .
what does \nabla^{m} do? Is that to the power of m?
No, \nabla_{m}
is the covariant derivative in the x^m
direction, and nabla^{m}
is what I wrote above. Has nothing to do with powers.
Thanks @kpeeters . I still don't follow what nabla^{m} means even with the description above. Could you please elaborate?
I came to the conclusion that the ^ is a form of a tensor notation same as can be seen in quantum field theory.
Hi, @kpeeters, I was wondering how I can run a simple command like this in python:
{ a, b, c, d }::Indices; ex:= A{a b} B{b c};
I know how to from cadabre2 import * but not the rest. :) Thank you.