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

Hi all. I'm trying to calculate some Poisson brackets and I'm running into the following issue:

I have two equations $ G = \int{g \mathrm{d} x}$ and $H = \int{h \mathrm{d} x}$ and I want to extract their integrands in order to manipulate $P = \int{g h \mathrm{d}x}$. Aside from just copy-pasting $g$ and $h$ from the TeX file, what is the best way to go about this? I want to write $P$ as something like \int{G[0] H[0]}{x}, but this obviously doesn't work.

asked in General questions by

1 Answer

+1 vote

You are on the right track. If you do

G := \int{ g(x) }{x};
H := \int{ h(x) }{x};
iG = G[0];
iH = H[0];
P := \int{ @(iG) @(iH) }{x};

it works as expected. The key is to first assign the integrand to a separate expression (and give it a new python name, like the iG above), and then pull that expression into the expression for P. It would be nice if you could skip line 3 & 4 and write instead

G := \int{ g(x) }{x};
H := \int{ h(x) }{x};
P := \int{ @(G[0]) @(H[0]) }{x};

but the '@' operator only accepts simple python variable names at the moment, so this will not work.

If you are confused by this all, note that when you write

\int{G[0] H[0]}{x}

then G[0] and H[0] are viewed as maths, not python. If you want to pull an expression, which you have previously given a python name (like the 'G' and 'H' above) into a maths expression, you need to use the @(...) operator.

Please ask again if it is still confusing. Cadabra makes a distinction between 'maths expressions' and 'python expressions', and that can be a bit daunting in the beginning.

answered by (56.4k points)
...